Mercurial > hg > svapp
comparison framework/SVFileReader.cpp @ 673:d62fd61082a1
Merge from branch tuning-difference
author | Chris Cannam |
---|---|
date | Fri, 17 May 2019 09:46:22 +0100 |
parents | 21673429dba5 |
children | c7406ebcd51c |
comparison
equal
deleted
inserted
replaced
665:e19c609a7bec | 673:d62fd61082a1 |
---|---|
29 #include "data/model/ReadOnlyWaveFileModel.h" | 29 #include "data/model/ReadOnlyWaveFileModel.h" |
30 #include "data/model/EditableDenseThreeDimensionalModel.h" | 30 #include "data/model/EditableDenseThreeDimensionalModel.h" |
31 #include "data/model/SparseOneDimensionalModel.h" | 31 #include "data/model/SparseOneDimensionalModel.h" |
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/FlexiNoteModel.h" | |
35 #include "data/model/RegionModel.h" | 34 #include "data/model/RegionModel.h" |
36 #include "data/model/TextModel.h" | 35 #include "data/model/TextModel.h" |
37 #include "data/model/ImageModel.h" | 36 #include "data/model/ImageModel.h" |
38 #include "data/model/AlignmentModel.h" | 37 #include "data/model/AlignmentModel.h" |
39 #include "data/model/AggregateWaveModel.h" | 38 #include "data/model/AggregateWaveModel.h" |
457 void | 456 void |
458 SVFileReader::addUnaddedModels() | 457 SVFileReader::addUnaddedModels() |
459 { | 458 { |
460 makeAggregateModels(); | 459 makeAggregateModels(); |
461 | 460 |
462 std::set<Model *> unaddedModels; | |
463 | |
464 for (std::map<int, Model *>::iterator i = m_models.begin(); | 461 for (std::map<int, Model *>::iterator i = m_models.begin(); |
465 i != m_models.end(); ++i) { | 462 i != m_models.end(); ++i) { |
466 if (m_addedModels.find(i->second) == m_addedModels.end()) { | 463 |
467 unaddedModels.insert(i->second); | 464 Model *model = i->second; |
468 } | 465 |
469 } | 466 if (m_addedModels.find(model) != m_addedModels.end()) { |
470 | 467 // already added this one |
471 for (std::set<Model *>::iterator i = unaddedModels.begin(); | 468 continue; |
472 i != unaddedModels.end(); ++i) { | 469 } |
473 Model *model = *i; | 470 |
474 // don't want to add these models, because their lifespans | 471 // don't want to add path and alignment models to the |
475 // are entirely dictated by the models that "own" them even | 472 // document, because their lifespans are entirely dictated by |
476 // though they were read independently from the .sv file. | 473 // the models that "own" them even though they were read |
477 // (pity we don't have a nicer way) | 474 // independently from the .sv file. (pity we don't have a |
475 // nicer way to handle this) | |
478 if (!dynamic_cast<PathModel *>(model) && | 476 if (!dynamic_cast<PathModel *>(model) && |
479 !dynamic_cast<AlignmentModel *>(model)) { | 477 !dynamic_cast<AlignmentModel *>(model)) { |
478 | |
480 m_document->addImportedModel(model); | 479 m_document->addImportedModel(model); |
481 } | 480 } |
482 // but we add all models here, so they don't get deleted | 481 |
483 // when the file loader is destroyed | 482 // but we add all models including path and alignment ones to |
483 // the added set, so they don't get deleted from our own | |
484 // destructor | |
484 m_addedModels.insert(model); | 485 m_addedModels.insert(model); |
485 } | 486 } |
486 } | 487 } |
487 | 488 |
488 bool | 489 bool |
711 model->setValueQuantization(valueQuantization); | 712 model->setValueQuantization(valueQuantization); |
712 model->setScaleUnits(units); | 713 model->setScaleUnits(units); |
713 model->setObjectName(name); | 714 model->setObjectName(name); |
714 m_models[id] = model; | 715 m_models[id] = model; |
715 } else if (attributes.value("subtype") == "flexinote") { | 716 } else if (attributes.value("subtype") == "flexinote") { |
716 FlexiNoteModel *model; | 717 NoteModel *model; |
717 if (haveMinMax) { | 718 if (haveMinMax) { |
718 model = new FlexiNoteModel | 719 model = new NoteModel |
719 (sampleRate, resolution, minimum, maximum, notifyOnAdd); | 720 (sampleRate, resolution, minimum, maximum, |
721 notifyOnAdd, | |
722 NoteModel::FLEXI_NOTE); | |
720 } else { | 723 } else { |
721 model = new FlexiNoteModel | 724 model = new NoteModel |
722 (sampleRate, resolution, notifyOnAdd); | 725 (sampleRate, resolution, notifyOnAdd, |
726 NoteModel::FLEXI_NOTE); | |
723 } | 727 } |
724 model->setValueQuantization(valueQuantization); | 728 model->setValueQuantization(valueQuantization); |
725 model->setScaleUnits(units); | 729 model->setScaleUnits(units); |
726 model->setObjectName(name); | 730 model->setObjectName(name); |
727 m_models[id] = model; | 731 m_models[id] = model; |
1049 else if (dynamic_cast<PathModel *>(model)) good = true; | 1053 else if (dynamic_cast<PathModel *>(model)) good = true; |
1050 break; | 1054 break; |
1051 | 1055 |
1052 case 3: | 1056 case 3: |
1053 if (dynamic_cast<NoteModel *>(model)) good = true; | 1057 if (dynamic_cast<NoteModel *>(model)) good = true; |
1054 else if (dynamic_cast<FlexiNoteModel *>(model)) good = true; | |
1055 else if (dynamic_cast<RegionModel *>(model)) good = true; | 1058 else if (dynamic_cast<RegionModel *>(model)) good = true; |
1056 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) { | 1059 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) { |
1057 m_datasetSeparator = attributes.value("separator"); | 1060 m_datasetSeparator = attributes.value("separator"); |
1058 good = true; | 1061 good = true; |
1059 } | 1062 } |
1083 (m_currentDataset); | 1086 (m_currentDataset); |
1084 | 1087 |
1085 if (sodm) { | 1088 if (sodm) { |
1086 // SVCERR << "Current dataset is a sparse one dimensional model" << endl; | 1089 // SVCERR << "Current dataset is a sparse one dimensional model" << endl; |
1087 QString label = attributes.value("label"); | 1090 QString label = attributes.value("label"); |
1088 sodm->addPoint(SparseOneDimensionalModel::Point(frame, label)); | 1091 sodm->add(Event(frame, label)); |
1089 return true; | 1092 return true; |
1090 } | 1093 } |
1091 | 1094 |
1092 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *> | 1095 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *> |
1093 (m_currentDataset); | 1096 (m_currentDataset); |
1095 if (stvm) { | 1098 if (stvm) { |
1096 // SVCERR << "Current dataset is a sparse time-value model" << endl; | 1099 // SVCERR << "Current dataset is a sparse time-value model" << endl; |
1097 float value = 0.0; | 1100 float value = 0.0; |
1098 value = attributes.value("value").trimmed().toFloat(&ok); | 1101 value = attributes.value("value").trimmed().toFloat(&ok); |
1099 QString label = attributes.value("label"); | 1102 QString label = attributes.value("label"); |
1100 stvm->addPoint(SparseTimeValueModel::Point(frame, value, label)); | 1103 stvm->add(Event(frame, value, label)); |
1101 return ok; | 1104 return ok; |
1102 } | 1105 } |
1103 | 1106 |
1104 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset); | 1107 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset); |
1105 | 1108 |
1113 float level = attributes.value("level").trimmed().toFloat(&ok); | 1116 float level = attributes.value("level").trimmed().toFloat(&ok); |
1114 if (!ok) { // level is optional | 1117 if (!ok) { // level is optional |
1115 level = 1.f; | 1118 level = 1.f; |
1116 ok = true; | 1119 ok = true; |
1117 } | 1120 } |
1118 nm->addPoint(NoteModel::Point(frame, value, duration, level, label)); | 1121 nm->add(Event(frame, value, duration, level, label)); |
1119 return ok; | |
1120 } | |
1121 | |
1122 FlexiNoteModel *fnm = dynamic_cast<FlexiNoteModel *>(m_currentDataset); | |
1123 | |
1124 if (fnm) { | |
1125 // SVCERR << "Current dataset is a flexinote model" << endl; | |
1126 float value = 0.0; | |
1127 value = attributes.value("value").trimmed().toFloat(&ok); | |
1128 int duration = 0; | |
1129 duration = attributes.value("duration").trimmed().toInt(&ok); | |
1130 QString label = attributes.value("label"); | |
1131 float level = attributes.value("level").trimmed().toFloat(&ok); | |
1132 if (!ok) { // level is optional | |
1133 level = 1.f; | |
1134 ok = true; | |
1135 } | |
1136 fnm->addPoint(FlexiNoteModel::Point(frame, value, duration, level, label)); | |
1137 return ok; | 1122 return ok; |
1138 } | 1123 } |
1139 | 1124 |
1140 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset); | 1125 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset); |
1141 | 1126 |
1144 float value = 0.0; | 1129 float value = 0.0; |
1145 value = attributes.value("value").trimmed().toFloat(&ok); | 1130 value = attributes.value("value").trimmed().toFloat(&ok); |
1146 int duration = 0; | 1131 int duration = 0; |
1147 duration = attributes.value("duration").trimmed().toInt(&ok); | 1132 duration = attributes.value("duration").trimmed().toInt(&ok); |
1148 QString label = attributes.value("label"); | 1133 QString label = attributes.value("label"); |
1149 rm->addPoint(RegionModel::Point(frame, value, duration, label)); | 1134 rm->add(Event(frame, value, duration, label)); |
1150 return ok; | 1135 return ok; |
1151 } | 1136 } |
1152 | 1137 |
1153 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset); | 1138 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset); |
1154 | 1139 |
1156 // SVCERR << "Current dataset is a text model" << endl; | 1141 // SVCERR << "Current dataset is a text model" << endl; |
1157 float height = 0.0; | 1142 float height = 0.0; |
1158 height = attributes.value("height").trimmed().toFloat(&ok); | 1143 height = attributes.value("height").trimmed().toFloat(&ok); |
1159 QString label = attributes.value("label"); | 1144 QString label = attributes.value("label"); |
1160 // SVDEBUG << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label << ", ok = " << ok << endl; | 1145 // SVDEBUG << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label << ", ok = " << ok << endl; |
1161 tm->addPoint(TextModel::Point(frame, height, label)); | 1146 tm->add(Event(frame, height, label)); |
1162 return ok; | 1147 return ok; |
1163 } | 1148 } |
1164 | 1149 |
1165 PathModel *pm = dynamic_cast<PathModel *>(m_currentDataset); | 1150 PathModel *pm = dynamic_cast<PathModel *>(m_currentDataset); |
1166 | 1151 |
1167 if (pm) { | 1152 if (pm) { |
1168 // SVCERR << "Current dataset is a path model" << endl; | 1153 // SVCERR << "Current dataset is a path model" << endl; |
1169 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok); | 1154 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok); |
1170 // SVDEBUG << "SVFileReader::addPointToDataset: PathModel: frame = " << frame << ", mapframe = " << mapframe << ", ok = " << ok << endl; | 1155 // SVDEBUG << "SVFileReader::addPointToDataset: PathModel: frame = " << frame << ", mapframe = " << mapframe << ", ok = " << ok << endl; |
1171 pm->addPoint(PathModel::Point(frame, mapframe)); | 1156 pm->add(PathPoint(frame, mapframe)); |
1172 return ok; | 1157 return ok; |
1173 } | 1158 } |
1174 | 1159 |
1175 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset); | 1160 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset); |
1176 | 1161 |
1177 if (im) { | 1162 if (im) { |
1178 // SVCERR << "Current dataset is an image model" << endl; | 1163 // SVCERR << "Current dataset is an image model" << endl; |
1179 QString image = attributes.value("image"); | 1164 QString image = attributes.value("image"); |
1180 QString label = attributes.value("label"); | 1165 QString label = attributes.value("label"); |
1181 // SVDEBUG << "SVFileReader::addPointToDataset: ImageModel: frame = " << frame << ", image = " << image << ", label = " << label << ", ok = " << ok << endl; | 1166 // SVDEBUG << "SVFileReader::addPointToDataset: ImageModel: frame = " << frame << ", image = " << image << ", label = " << label << ", ok = " << ok << endl; |
1182 im->addPoint(ImageModel::Point(frame, image, label)); | 1167 im->add(Event(frame).withURI(image).withLabel(label)); |
1183 return ok; | 1168 return ok; |
1184 } | 1169 } |
1185 | 1170 |
1186 SVCERR << "WARNING: SV-XML: Point element found in non-point dataset" << endl; | 1171 SVCERR << "WARNING: SV-XML: Point element found in non-point dataset" << endl; |
1187 | 1172 |