changeset 709:dde6ff56a84b

Add support for time-frequency box layer
author Chris Cannam
date Fri, 20 Sep 2019 14:19:49 +0100
parents 721eb532840d
children 3e930ea94db6
files framework/SVFileReader.cpp
diffstat 1 files changed, 22 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/framework/SVFileReader.cpp	Mon Sep 16 13:28:40 2019 +0100
+++ b/framework/SVFileReader.cpp	Fri Sep 20 14:19:49 2019 +0100
@@ -34,6 +34,7 @@
 #include "data/model/RegionModel.h"
 #include "data/model/TextModel.h"
 #include "data/model/ImageModel.h"
+#include "data/model/TimeFrequencyBoxModel.h"
 #include "data/model/AlignmentModel.h"
 #include "data/model/AggregateWaveModel.h"
 
@@ -686,6 +687,11 @@
                     // Paths are no longer actually models
                     Path *path = new Path(sampleRate, resolution);
                     m_paths[id] = path;
+                } else if (attributes.value("subtype") == "timefrequencybox") {
+                    auto model = std::make_shared<TimeFrequencyBoxModel>
+                        (sampleRate, resolution, notifyOnAdd);
+                    model->setObjectName(name);
+                    m_models[id] = ModelById::add(model);
                 } else {
                     std::shared_ptr<SparseTimeValueModel> model;
                     if (haveMinMax) {
@@ -1057,6 +1063,7 @@
         good =
             (ModelById::isa<SparseTimeValueModel>(modelId) ||
              ModelById::isa<TextModel>(modelId) ||
+             ModelById::isa<TimeFrequencyBoxModel>(modelId) ||
              path);
         break;
 
@@ -1111,18 +1118,15 @@
     }
 
     if (auto stvm = ModelById::getAs<SparseTimeValueModel>(modelId)) {
-        float value = 0.0;
-        value = attributes.value("value").trimmed().toFloat(&ok);
+        float value = attributes.value("value").trimmed().toFloat(&ok);
         QString label = attributes.value("label");
         stvm->add(Event(frame, value, label));
         return ok;
     }
         
     if (auto nm = ModelById::getAs<NoteModel>(modelId)) {
-        float value = 0.0;
-        value = attributes.value("value").trimmed().toFloat(&ok);
-        int duration = 0;
-        duration = attributes.value("duration").trimmed().toInt(&ok);
+        float value = attributes.value("value").trimmed().toFloat(&ok);
+        int duration = attributes.value("duration").trimmed().toInt(&ok);
         QString label = attributes.value("label");
         float level = attributes.value("level").trimmed().toFloat(&ok);
         if (!ok) { // level is optional
@@ -1134,23 +1138,29 @@
     }
 
     if (auto rm = ModelById::getAs<RegionModel>(modelId)) {
-        float value = 0.0;
-        value = attributes.value("value").trimmed().toFloat(&ok);
-        int duration = 0;
-        duration = attributes.value("duration").trimmed().toInt(&ok);
+        float value = attributes.value("value").trimmed().toFloat(&ok);
+        int duration = attributes.value("duration").trimmed().toInt(&ok);
         QString label = attributes.value("label");
         rm->add(Event(frame, value, duration, label));
         return ok;
     }
 
     if (auto tm = ModelById::getAs<TextModel>(modelId)) {
-        float height = 0.0;
-        height = attributes.value("height").trimmed().toFloat(&ok);
+        float height = attributes.value("height").trimmed().toFloat(&ok);
         QString label = attributes.value("label");
         tm->add(Event(frame, height, label));
         return ok;
     }
 
+    if (auto bm = ModelById::getAs<TimeFrequencyBoxModel>(modelId)) {
+        float frequency = attributes.value("frequency").trimmed().toFloat(&ok);
+        float extent = attributes.value("extent").trimmed().toFloat(&ok);
+        int duration = attributes.value("duration").trimmed().toInt(&ok);
+        QString label = attributes.value("label");
+        bm->add(Event(frame, frequency, duration, extent, label));
+        return ok;
+    }
+
     if (auto im = ModelById::getAs<ImageModel>(modelId)) {
         QString image = attributes.value("image");
         QString label = attributes.value("label");