comparison framework/SVFileReader.cpp @ 709:dde6ff56a84b

Add support for time-frequency box layer
author Chris Cannam
date Fri, 20 Sep 2019 14:19:49 +0100
parents 94ca0ade69b6
children 3e930ea94db6
comparison
equal deleted inserted replaced
708:721eb532840d 709:dde6ff56a84b
32 #include "data/model/SparseTimeValueModel.h" 32 #include "data/model/SparseTimeValueModel.h"
33 #include "data/model/NoteModel.h" 33 #include "data/model/NoteModel.h"
34 #include "data/model/RegionModel.h" 34 #include "data/model/RegionModel.h"
35 #include "data/model/TextModel.h" 35 #include "data/model/TextModel.h"
36 #include "data/model/ImageModel.h" 36 #include "data/model/ImageModel.h"
37 #include "data/model/TimeFrequencyBoxModel.h"
37 #include "data/model/AlignmentModel.h" 38 #include "data/model/AlignmentModel.h"
38 #include "data/model/AggregateWaveModel.h" 39 #include "data/model/AggregateWaveModel.h"
39 40
40 #include "transform/TransformFactory.h" 41 #include "transform/TransformFactory.h"
41 42
684 m_models[id] = ModelById::add(model); 685 m_models[id] = ModelById::add(model);
685 } else if (attributes.value("subtype") == "path") { 686 } else if (attributes.value("subtype") == "path") {
686 // Paths are no longer actually models 687 // Paths are no longer actually models
687 Path *path = new Path(sampleRate, resolution); 688 Path *path = new Path(sampleRate, resolution);
688 m_paths[id] = path; 689 m_paths[id] = path;
690 } else if (attributes.value("subtype") == "timefrequencybox") {
691 auto model = std::make_shared<TimeFrequencyBoxModel>
692 (sampleRate, resolution, notifyOnAdd);
693 model->setObjectName(name);
694 m_models[id] = ModelById::add(model);
689 } else { 695 } else {
690 std::shared_ptr<SparseTimeValueModel> model; 696 std::shared_ptr<SparseTimeValueModel> model;
691 if (haveMinMax) { 697 if (haveMinMax) {
692 model = std::make_shared<SparseTimeValueModel> 698 model = std::make_shared<SparseTimeValueModel>
693 (sampleRate, resolution, minimum, maximum, 699 (sampleRate, resolution, minimum, maximum,
1055 1061
1056 case 2: 1062 case 2:
1057 good = 1063 good =
1058 (ModelById::isa<SparseTimeValueModel>(modelId) || 1064 (ModelById::isa<SparseTimeValueModel>(modelId) ||
1059 ModelById::isa<TextModel>(modelId) || 1065 ModelById::isa<TextModel>(modelId) ||
1066 ModelById::isa<TimeFrequencyBoxModel>(modelId) ||
1060 path); 1067 path);
1061 break; 1068 break;
1062 1069
1063 case 3: 1070 case 3:
1064 if (ModelById::isa<EditableDenseThreeDimensionalModel>(modelId)) { 1071 if (ModelById::isa<EditableDenseThreeDimensionalModel>(modelId)) {
1109 sodm->add(Event(frame, label)); 1116 sodm->add(Event(frame, label));
1110 return true; 1117 return true;
1111 } 1118 }
1112 1119
1113 if (auto stvm = ModelById::getAs<SparseTimeValueModel>(modelId)) { 1120 if (auto stvm = ModelById::getAs<SparseTimeValueModel>(modelId)) {
1114 float value = 0.0; 1121 float value = attributes.value("value").trimmed().toFloat(&ok);
1115 value = attributes.value("value").trimmed().toFloat(&ok);
1116 QString label = attributes.value("label"); 1122 QString label = attributes.value("label");
1117 stvm->add(Event(frame, value, label)); 1123 stvm->add(Event(frame, value, label));
1118 return ok; 1124 return ok;
1119 } 1125 }
1120 1126
1121 if (auto nm = ModelById::getAs<NoteModel>(modelId)) { 1127 if (auto nm = ModelById::getAs<NoteModel>(modelId)) {
1122 float value = 0.0; 1128 float value = attributes.value("value").trimmed().toFloat(&ok);
1123 value = attributes.value("value").trimmed().toFloat(&ok); 1129 int duration = attributes.value("duration").trimmed().toInt(&ok);
1124 int duration = 0;
1125 duration = attributes.value("duration").trimmed().toInt(&ok);
1126 QString label = attributes.value("label"); 1130 QString label = attributes.value("label");
1127 float level = attributes.value("level").trimmed().toFloat(&ok); 1131 float level = attributes.value("level").trimmed().toFloat(&ok);
1128 if (!ok) { // level is optional 1132 if (!ok) { // level is optional
1129 level = 1.f; 1133 level = 1.f;
1130 ok = true; 1134 ok = true;
1132 nm->add(Event(frame, value, duration, level, label)); 1136 nm->add(Event(frame, value, duration, level, label));
1133 return ok; 1137 return ok;
1134 } 1138 }
1135 1139
1136 if (auto rm = ModelById::getAs<RegionModel>(modelId)) { 1140 if (auto rm = ModelById::getAs<RegionModel>(modelId)) {
1137 float value = 0.0; 1141 float value = attributes.value("value").trimmed().toFloat(&ok);
1138 value = attributes.value("value").trimmed().toFloat(&ok); 1142 int duration = attributes.value("duration").trimmed().toInt(&ok);
1139 int duration = 0;
1140 duration = attributes.value("duration").trimmed().toInt(&ok);
1141 QString label = attributes.value("label"); 1143 QString label = attributes.value("label");
1142 rm->add(Event(frame, value, duration, label)); 1144 rm->add(Event(frame, value, duration, label));
1143 return ok; 1145 return ok;
1144 } 1146 }
1145 1147
1146 if (auto tm = ModelById::getAs<TextModel>(modelId)) { 1148 if (auto tm = ModelById::getAs<TextModel>(modelId)) {
1147 float height = 0.0; 1149 float height = attributes.value("height").trimmed().toFloat(&ok);
1148 height = attributes.value("height").trimmed().toFloat(&ok);
1149 QString label = attributes.value("label"); 1150 QString label = attributes.value("label");
1150 tm->add(Event(frame, height, label)); 1151 tm->add(Event(frame, height, label));
1152 return ok;
1153 }
1154
1155 if (auto bm = ModelById::getAs<TimeFrequencyBoxModel>(modelId)) {
1156 float frequency = attributes.value("frequency").trimmed().toFloat(&ok);
1157 float extent = attributes.value("extent").trimmed().toFloat(&ok);
1158 int duration = attributes.value("duration").trimmed().toInt(&ok);
1159 QString label = attributes.value("label");
1160 bm->add(Event(frame, frequency, duration, extent, label));
1151 return ok; 1161 return ok;
1152 } 1162 }
1153 1163
1154 if (auto im = ModelById::getAs<ImageModel>(modelId)) { 1164 if (auto im = ModelById::getAs<ImageModel>(modelId)) {
1155 QString image = attributes.value("image"); 1165 QString image = attributes.value("image");