comparison framework/SVFileReader.cpp @ 350:aebee52e86b3

Merge from branch tony_integration
author Chris Cannam
date Wed, 14 May 2014 09:54:46 +0100
parents a93802543a5a
children 2da91cceed64 0876ea394902
comparison
equal deleted inserted replaced
330:46b24009ce7a 350:aebee52e86b3
29 #include "data/model/WaveFileModel.h" 29 #include "data/model/WaveFileModel.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"
34 #include "data/model/RegionModel.h" 35 #include "data/model/RegionModel.h"
35 #include "data/model/TextModel.h" 36 #include "data/model/TextModel.h"
36 #include "data/model/ImageModel.h" 37 #include "data/model/ImageModel.h"
37 #include "data/model/AlignmentModel.h" 38 #include "data/model/AlignmentModel.h"
38 39
323 m_currentTransform.getIdentifier(), 324 m_currentTransform.getIdentifier(),
324 message); 325 message);
325 } 326 }
326 } 327 }
327 } else { 328 } else {
328 m_document->addDerivedModel 329 m_document->addAlreadyDerivedModel
329 (m_currentTransform, 330 (m_currentTransform,
330 ModelTransformer::Input(m_currentTransformSource, 331 ModelTransformer::Input(m_currentTransformSource,
331 m_currentTransformChannel), 332 m_currentTransformChannel),
332 m_currentDerivedModel); 333 m_currentDerivedModel);
333 } 334 }
622 } 623 }
623 model->setValueQuantization(valueQuantization); 624 model->setValueQuantization(valueQuantization);
624 model->setScaleUnits(units); 625 model->setScaleUnits(units);
625 model->setObjectName(name); 626 model->setObjectName(name);
626 m_models[id] = model; 627 m_models[id] = model;
628 } else if (attributes.value("subtype") == "flexinote") {
629 FlexiNoteModel *model;
630 if (haveMinMax) {
631 model = new FlexiNoteModel
632 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
633 } else {
634 model = new FlexiNoteModel
635 (sampleRate, resolution, notifyOnAdd);
636 }
637 model->setValueQuantization(valueQuantization);
638 model->setScaleUnits(units);
639 model->setObjectName(name);
640 m_models[id] = model;
627 } else { 641 } else {
628 // note models written out by SV 1.3 and earlier 642 // note models written out by SV 1.3 and earlier
629 // have no subtype, so we can't test that 643 // have no subtype, so we can't test that
630 NoteModel *model; 644 NoteModel *model;
631 if (haveMinMax) { 645 if (haveMinMax) {
724 return false; 738 return false;
725 } 739 }
726 740
727 m_currentPane = m_paneCallback.addPane(); 741 m_currentPane = m_paneCallback.addPane();
728 742
743 cerr << "SVFileReader::addPane: pane is " << m_currentPane << endl;
744
729 if (!m_currentPane) { 745 if (!m_currentPane) {
730 cerr << "WARNING: SV-XML: Internal error: Failed to add pane!" 746 cerr << "WARNING: SV-XML: Internal error: Failed to add pane!"
731 << endl; 747 << endl;
732 return false; 748 return false;
733 } 749 }
930 else if (dynamic_cast<PathModel *>(model)) good = true; 946 else if (dynamic_cast<PathModel *>(model)) good = true;
931 break; 947 break;
932 948
933 case 3: 949 case 3:
934 if (dynamic_cast<NoteModel *>(model)) good = true; 950 if (dynamic_cast<NoteModel *>(model)) good = true;
951 else if (dynamic_cast<FlexiNoteModel *>(model)) good = true;
935 else if (dynamic_cast<RegionModel *>(model)) good = true; 952 else if (dynamic_cast<RegionModel *>(model)) good = true;
936 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) { 953 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) {
937 m_datasetSeparator = attributes.value("separator"); 954 m_datasetSeparator = attributes.value("separator");
938 good = true; 955 good = true;
939 } 956 }
971 988
972 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *> 989 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>
973 (m_currentDataset); 990 (m_currentDataset);
974 991
975 if (stvm) { 992 if (stvm) {
976 // cerr << "Current dataset is a sparse time-value model" << endl; 993 cerr << "Current dataset is a sparse time-value model" << endl;
977 float value = 0.0; 994 float value = 0.0;
978 value = attributes.value("value").trimmed().toFloat(&ok); 995 value = attributes.value("value").trimmed().toFloat(&ok);
979 QString label = attributes.value("label"); 996 QString label = attributes.value("label");
980 stvm->addPoint(SparseTimeValueModel::Point(frame, value, label)); 997 stvm->addPoint(SparseTimeValueModel::Point(frame, value, label));
981 return ok; 998 return ok;
982 } 999 }
983 1000
984 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset); 1001 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset);
985 1002
986 if (nm) { 1003 if (nm) {
987 // cerr << "Current dataset is a note model" << endl; 1004 cerr << "Current dataset is a note model" << endl;
988 float value = 0.0; 1005 float value = 0.0;
989 value = attributes.value("value").trimmed().toFloat(&ok); 1006 value = attributes.value("value").trimmed().toFloat(&ok);
990 size_t duration = 0; 1007 size_t duration = 0;
991 duration = attributes.value("duration").trimmed().toUInt(&ok); 1008 duration = attributes.value("duration").trimmed().toUInt(&ok);
992 QString label = attributes.value("label"); 1009 QString label = attributes.value("label");
997 } 1014 }
998 nm->addPoint(NoteModel::Point(frame, value, duration, level, label)); 1015 nm->addPoint(NoteModel::Point(frame, value, duration, level, label));
999 return ok; 1016 return ok;
1000 } 1017 }
1001 1018
1019 FlexiNoteModel *fnm = dynamic_cast<FlexiNoteModel *>(m_currentDataset);
1020
1021 if (fnm) {
1022 cerr << "Current dataset is a flexinote model" << endl;
1023 float value = 0.0;
1024 value = attributes.value("value").trimmed().toFloat(&ok);
1025 size_t duration = 0;
1026 duration = attributes.value("duration").trimmed().toUInt(&ok);
1027 QString label = attributes.value("label");
1028 float level = attributes.value("level").trimmed().toFloat(&ok);
1029 if (!ok) { // level is optional
1030 level = 1.f;
1031 ok = true;
1032 }
1033 fnm->addPoint(FlexiNoteModel::Point(frame, value, duration, level, label));
1034 return ok;
1035 }
1036
1002 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset); 1037 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset);
1003 1038
1004 if (rm) { 1039 if (rm) {
1005 // cerr << "Current dataset is a note model" << endl; 1040 cerr << "Current dataset is a region model" << endl;
1006 float value = 0.0; 1041 float value = 0.0;
1007 value = attributes.value("value").trimmed().toFloat(&ok); 1042 value = attributes.value("value").trimmed().toFloat(&ok);
1008 size_t duration = 0; 1043 size_t duration = 0;
1009 duration = attributes.value("duration").trimmed().toUInt(&ok); 1044 duration = attributes.value("duration").trimmed().toUInt(&ok);
1010 QString label = attributes.value("label"); 1045 QString label = attributes.value("label");
1269 if (ok) parameters->setPlayPan(pan); 1304 if (ok) parameters->setPlayPan(pan);
1270 1305
1271 float gain = attributes.value("gain").toFloat(&ok); 1306 float gain = attributes.value("gain").toFloat(&ok);
1272 if (ok) parameters->setPlayGain(gain); 1307 if (ok) parameters->setPlayGain(gain);
1273 1308
1274 QString pluginId = attributes.value("pluginId"); 1309 QString clipId = attributes.value("clipId");
1275 if (pluginId != "") parameters->setPlayPluginId(pluginId); 1310 if (clipId != "") parameters->setPlayClipId(clipId);
1276 1311
1277 m_currentPlayParameters = parameters; 1312 m_currentPlayParameters = parameters;
1278 1313
1279 // cerr << "Current play parameters for model: " << m_models[modelId] << ": " << m_currentPlayParameters << endl; 1314 // cerr << "Current play parameters for model: " << m_models[modelId] << ": " << m_currentPlayParameters << endl;
1280 1315
1289 } 1324 }
1290 1325
1291 bool 1326 bool
1292 SVFileReader::readPlugin(const QXmlAttributes &attributes) 1327 SVFileReader::readPlugin(const QXmlAttributes &attributes)
1293 { 1328 {
1294 if (m_currentDerivedModelId < 0 && !m_currentPlayParameters) { 1329 if (m_currentDerivedModelId >= 0) {
1330 return readPluginForTransform(attributes);
1331 } else if (m_currentPlayParameters) {
1332 return readPluginForPlayback(attributes);
1333 } else {
1295 cerr << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << endl; 1334 cerr << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << endl;
1296 return false; 1335 return false;
1297 } 1336 }
1298 1337 }
1299 if (!m_currentPlayParameters && m_currentTransformIsNewStyle) { 1338
1339 bool
1340 SVFileReader::readPluginForTransform(const QXmlAttributes &attributes)
1341 {
1342 if (m_currentTransformIsNewStyle) {
1343 // Not needed, we have the transform element instead
1300 return true; 1344 return true;
1301 } 1345 }
1302 1346
1303 QString configurationXml = "<plugin"; 1347 QString configurationXml = "<plugin";
1304 1348
1305 for (int i = 0; i < attributes.length(); ++i) { 1349 for (int i = 0; i < attributes.length(); ++i) {
1306 configurationXml += QString(" %1=\"%2\"") 1350 configurationXml += QString(" %1=\"%2\"")
1307 .arg(attributes.qName(i)) 1351 .arg(attributes.qName(i))
1308 .arg(XmlExportable::encodeEntities(attributes.value(i))); 1352 .arg(XmlExportable::encodeEntities(attributes.value(i)));
1309 } 1353 }
1310 1354
1311 configurationXml += "/>"; 1355 configurationXml += "/>";
1312 1356
1313 if (m_currentPlayParameters) { 1357 TransformFactory::getInstance()->
1314 m_currentPlayParameters->setPlayPluginConfiguration(configurationXml); 1358 setParametersFromPluginConfigurationXml(m_currentTransform,
1315 } else { 1359 configurationXml);
1316 TransformFactory::getInstance()-> 1360 return true;
1317 setParametersFromPluginConfigurationXml(m_currentTransform, 1361 }
1318 configurationXml); 1362
1363 bool
1364 SVFileReader::readPluginForPlayback(const QXmlAttributes &attributes)
1365 {
1366 // Obsolete but supported for compatibility
1367
1368 QString ident = attributes.value("identifier");
1369 if (ident == "sample_player") {
1370 QString clipId = attributes.value("program");
1371 if (clipId != "") m_currentPlayParameters->setPlayClipId(clipId);
1319 } 1372 }
1320 1373
1321 return true; 1374 return true;
1322 } 1375 }
1323 1376