comparison framework/SVFileReader.cpp @ 137:e2aec1708a2c

* Save/load of region models
author Chris Cannam
date Thu, 09 Oct 2008 12:04:22 +0000
parents 9554c19c42fd
children 9ccaa8fd9b9f
comparison
equal deleted inserted replaced
136:6d2e49c59b3b 137:e2aec1708a2c
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/RegionModel.h"
34 #include "data/model/TextModel.h" 35 #include "data/model/TextModel.h"
35 #include "data/model/ImageModel.h" 36 #include "data/model/ImageModel.h"
36 #include "data/model/AlignmentModel.h" 37 #include "data/model/AlignmentModel.h"
37 38
38 #include "transform/TransformFactory.h" 39 #include "transform/TransformFactory.h"
591 model->setScaleUnits(units); 592 model->setScaleUnits(units);
592 model->setObjectName(name); 593 model->setObjectName(name);
593 m_models[id] = model; 594 m_models[id] = model;
594 } 595 }
595 } else { 596 } else {
596 NoteModel *model; 597 if (attributes.value("subtype") == "region") {
597 if (haveMinMax) { 598 RegionModel *model;
598 model = new NoteModel 599 if (haveMinMax) {
599 (sampleRate, resolution, minimum, maximum, notifyOnAdd); 600 model = new RegionModel
601 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
602 } else {
603 model = new RegionModel
604 (sampleRate, resolution, notifyOnAdd);
605 }
606 model->setValueQuantization(valueQuantization);
607 model->setScaleUnits(units);
608 model->setObjectName(name);
609 m_models[id] = model;
600 } else { 610 } else {
601 model = new NoteModel 611 // note models written out by SV 1.3 and earlier
602 (sampleRate, resolution, notifyOnAdd); 612 // have no subtype, so we can't test that
613 NoteModel *model;
614 if (haveMinMax) {
615 model = new NoteModel
616 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
617 } else {
618 model = new NoteModel
619 (sampleRate, resolution, notifyOnAdd);
620 }
621 model->setValueQuantization(valueQuantization);
622 model->setScaleUnits(units);
623 model->setObjectName(name);
624 m_models[id] = model;
603 } 625 }
604 model->setValueQuantization(valueQuantization); 626 }
605 model->setScaleUnits(units);
606 model->setObjectName(name);
607 m_models[id] = model;
608 }
609 627
610 int dataset = attributes.value("dataset").trimmed().toInt(&ok); 628 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
611 if (ok) m_awaitingDatasets[dataset] = id; 629 if (ok) m_awaitingDatasets[dataset] = id;
612 630
613 return true; 631 return true;
895 else if (dynamic_cast<PathModel *>(model)) good = true; 913 else if (dynamic_cast<PathModel *>(model)) good = true;
896 break; 914 break;
897 915
898 case 3: 916 case 3:
899 if (dynamic_cast<NoteModel *>(model)) good = true; 917 if (dynamic_cast<NoteModel *>(model)) good = true;
918 else if (dynamic_cast<RegionModel *>(model)) good = true;
900 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) { 919 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) {
901 m_datasetSeparator = attributes.value("separator"); 920 m_datasetSeparator = attributes.value("separator");
902 good = true; 921 good = true;
903 } 922 }
904 break; 923 break;
958 if (!ok) { // level is optional 977 if (!ok) { // level is optional
959 level = 1.f; 978 level = 1.f;
960 ok = true; 979 ok = true;
961 } 980 }
962 nm->addPoint(NoteModel::Point(frame, value, duration, level, label)); 981 nm->addPoint(NoteModel::Point(frame, value, duration, level, label));
982 return ok;
983 }
984
985 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset);
986
987 if (rm) {
988 // std::cerr << "Current dataset is a note model" << std::endl;
989 float value = 0.0;
990 value = attributes.value("value").trimmed().toFloat(&ok);
991 size_t duration = 0;
992 duration = attributes.value("duration").trimmed().toUInt(&ok);
993 QString label = attributes.value("label");
994 rm->addPoint(RegionModel::Point(frame, value, duration, label));
963 return ok; 995 return ok;
964 } 996 }
965 997
966 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset); 998 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset);
967 999