diff data/fileio/CSVFileReader.cpp @ 1794:71e97de5053f

Merge from branch time-frequency-boxes
author Chris Cannam
date Wed, 25 Sep 2019 13:47:46 +0100
parents f0ffc88a36b3
children 2654bf447a84
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp	Fri Sep 20 11:35:14 2019 +0100
+++ b/data/fileio/CSVFileReader.cpp	Wed Sep 25 13:47:46 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;