changeset 1793:f0ffc88a36b3 time-frequency-boxes

Add duration-and-extent type, which corresponds to a box model
author Chris Cannam
date Wed, 25 Sep 2019 11:06:59 +0100
parents cb45c0a1dfe1
children 71e97de5053f
files data/fileio/CSVFileReader.cpp data/fileio/CSVFormat.h
diffstat 2 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp	Wed Sep 25 11:06:39 2019 +0100
+++ b/data/fileio/CSVFileReader.cpp	Wed Sep 25 11:06:59 2019 +0100
@@ -25,6 +25,7 @@
 #include "model/EditableDenseThreeDimensionalModel.h"
 #include "model/RegionModel.h"
 #include "model/NoteModel.h"
+#include "model/BoxModel.h"
 #include "model/WritableWaveFileModel.h"
 #include "DataFileReaderFactory.h"
 
@@ -201,6 +202,7 @@
     SparseTimeValueModel *model2 = nullptr;
     RegionModel *model2a = nullptr;
     NoteModel *model2b = nullptr;
+    BoxModel *model2c = nullptr;
     EditableDenseThreeDimensionalModel *model3 = nullptr;
     WritableWaveFileModel *modelW = nullptr;
     Model *model = nullptr;
@@ -333,6 +335,11 @@
                     model = model2b;
                     break;
                 
+                case CSVFormat::TwoDimensionalModelWithDurationAndExtent:
+                    model2c = new BoxModel(sampleRate, windowSize, false);
+                    model = model2c;
+                    break;
+                
                 case CSVFormat::ThreeDimensionalModel:
                     model3 = new EditableDenseThreeDimensionalModel
                         (sampleRate, windowSize, valueColumns);
@@ -368,7 +375,8 @@
                 if (model) {
                     delete model;
                     model = nullptr;
-                    model1 = nullptr; model2 = nullptr; model2a = nullptr; model2b = nullptr;
+                    model1 = nullptr; model2 = nullptr;
+                    model2a = nullptr; model2b = nullptr; model2c = nullptr;
                     model3 = nullptr; modelW = nullptr;
                 }
                 abandoned = true;
@@ -376,6 +384,7 @@
             }
             
             float value = 0.f;
+            float otherValue = 0.f;
             float pitch = 0.f;
             QString label = "";
 
@@ -407,6 +416,9 @@
                     break;
 
                 case CSVFormat::ColumnValue:
+                    if (haveAnyValue) {
+                        otherValue = value;
+                    }
                     value = s.toFloat();
                     haveAnyValue = true;
                     break;
@@ -453,6 +465,18 @@
                 Event note(frameNo, pitch, duration, level, label);
                 model2b->add(note);
 
+            } else if (modelType == CSVFormat::TwoDimensionalModelWithDurationAndExtent) {
+
+                float level = 0.f;
+                if (value > otherValue) {
+                    level = value - otherValue;
+                    value = otherValue;
+                } else {
+                    level = otherValue - value;
+                }
+                Event box(frameNo, value, duration, level, label);
+                model2c->add(box);
+
             } else if (modelType == CSVFormat::ThreeDimensionalModel) {
 
                 DenseThreeDimensionalModel::Column values;
--- a/data/fileio/CSVFormat.h	Wed Sep 25 11:06:39 2019 +0100
+++ b/data/fileio/CSVFormat.h	Wed Sep 25 11:06:59 2019 +0100
@@ -31,6 +31,7 @@
         TwoDimensionalModel,
         TwoDimensionalModelWithDuration,
         TwoDimensionalModelWithDurationAndPitch,
+        TwoDimensionalModelWithDurationAndExtent,
         ThreeDimensionalModel,
         WaveFileModel
     };