Mercurial > hg > svapp
changeset 137:e2aec1708a2c
* Save/load of region models
author | Chris Cannam |
---|---|
date | Thu, 09 Oct 2008 12:04:22 +0000 |
parents | 6d2e49c59b3b |
children | c0b176d86be7 |
files | framework/Document.cpp framework/SVFileReader.cpp |
diffstat | 2 files changed, 98 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/framework/Document.cpp Thu Sep 18 16:08:14 2008 +0000 +++ b/framework/Document.cpp Thu Oct 09 12:04:22 2008 +0000 @@ -37,7 +37,7 @@ #include "data/model/SparseTimeValueModel.h" #include "data/model/AlignmentModel.h" -//#define DEBUG_DOCUMENT 1 +#define DEBUG_DOCUMENT 1 //!!! still need to handle command history, documentRestored/documentModified @@ -278,6 +278,11 @@ #ifdef DEBUG_DOCUMENT std::cerr << "Document::setMainModel: Have " << m_layers.size() << " layers" << std::endl; + std::cerr << "Models now: "; + for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { + std::cerr << i->first << " "; + } + std::cerr << std::endl; #endif for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { @@ -299,10 +304,18 @@ continue; } - if (model && (m_models.find(model) == m_models.end())) { + if (!model) { + std::cerr << "WARNING: Document::setMainModel: Null model in layer " + << layer << std::endl; + // get rid of this hideous degenerate + obsoleteLayers.push_back(layer); + continue; + } + + if (m_models.find(model) == m_models.end()) { std::cerr << "WARNING: Document::setMainModel: Unknown model " << model << " in layer " << layer << std::endl; - // get rid of this hideous degenerate + // and this one obsoleteLayers.push_back(layer); continue; } @@ -361,7 +374,7 @@ if (rm) { std::cerr << "new model has " << rm->getChannelCount() << " channels " << std::endl; } else { - std::cerr << "new model is not a RangeSummarisableTimeValueModel!" << std::endl; + std::cerr << "new model " << replacementModel << " is not a RangeSummarisableTimeValueModel!" << std::endl; } #endif setModel(layer, replacementModel); @@ -375,14 +388,21 @@ for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { + Model *m = i->first; + +#ifdef DEBUG_DOCUMENT + std::cerr << "considering alignment for model " << m << " (name \"" + << m->objectName().toStdString() << "\")" << std::endl; +#endif + if (m_autoAlignment) { - alignModel(i->first); + alignModel(m); } else if (oldMainModel && - (i->first->getAlignmentReference() == oldMainModel)) { + (m->getAlignmentReference() == oldMainModel)) { - alignModel(i->first); + alignModel(m); } } @@ -425,6 +445,15 @@ m_models[outputModelToAdd] = rec; +#ifdef DEBUG_DOCUMENT + std::cerr << "Document::addDerivedModel: Added model " << outputModelToAdd << std::endl; + std::cerr << "Models now: "; + for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { + std::cerr << i->first << " "; + } + std::cerr << std::endl; +#endif + emit modelAdded(outputModelToAdd); } @@ -444,6 +473,15 @@ m_models[model] = rec; +#ifdef DEBUG_DOCUMENT + std::cerr << "Document::addImportedModel: Added model " << model << std::endl; + std::cerr << "Models now: "; + for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { + std::cerr << i->first << " "; + } + std::cerr << std::endl; +#endif + if (m_autoAlignment) alignModel(model); emit modelAdded(model); @@ -540,6 +578,16 @@ model->aboutToDelete(); emit modelAboutToBeDeleted(model); m_models.erase(model); + +#ifdef DEBUG_DOCUMENT + std::cerr << "Document::releaseModel: Deleted model " << model << std::endl; + std::cerr << "Models now: "; + for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { + std::cerr << i->first << " "; + } + std::cerr << std::endl; +#endif + delete model; } }
--- a/framework/SVFileReader.cpp Thu Sep 18 16:08:14 2008 +0000 +++ b/framework/SVFileReader.cpp Thu Oct 09 12:04:22 2008 +0000 @@ -31,6 +31,7 @@ #include "data/model/SparseOneDimensionalModel.h" #include "data/model/SparseTimeValueModel.h" #include "data/model/NoteModel.h" +#include "data/model/RegionModel.h" #include "data/model/TextModel.h" #include "data/model/ImageModel.h" #include "data/model/AlignmentModel.h" @@ -593,19 +594,36 @@ m_models[id] = model; } } else { - NoteModel *model; - if (haveMinMax) { - model = new NoteModel - (sampleRate, resolution, minimum, maximum, notifyOnAdd); + if (attributes.value("subtype") == "region") { + RegionModel *model; + if (haveMinMax) { + model = new RegionModel + (sampleRate, resolution, minimum, maximum, notifyOnAdd); + } else { + model = new RegionModel + (sampleRate, resolution, notifyOnAdd); + } + model->setValueQuantization(valueQuantization); + model->setScaleUnits(units); + model->setObjectName(name); + m_models[id] = model; } else { - model = new NoteModel - (sampleRate, resolution, notifyOnAdd); + // note models written out by SV 1.3 and earlier + // have no subtype, so we can't test that + NoteModel *model; + if (haveMinMax) { + model = new NoteModel + (sampleRate, resolution, minimum, maximum, notifyOnAdd); + } else { + model = new NoteModel + (sampleRate, resolution, notifyOnAdd); + } + model->setValueQuantization(valueQuantization); + model->setScaleUnits(units); + model->setObjectName(name); + m_models[id] = model; } - model->setValueQuantization(valueQuantization); - model->setScaleUnits(units); - model->setObjectName(name); - m_models[id] = model; - } + } int dataset = attributes.value("dataset").trimmed().toInt(&ok); if (ok) m_awaitingDatasets[dataset] = id; @@ -897,6 +915,7 @@ case 3: if (dynamic_cast<NoteModel *>(model)) good = true; + else if (dynamic_cast<RegionModel *>(model)) good = true; else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) { m_datasetSeparator = attributes.value("separator"); good = true; @@ -963,6 +982,19 @@ return ok; } + RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset); + + if (rm) { +// std::cerr << "Current dataset is a note model" << std::endl; + float value = 0.0; + value = attributes.value("value").trimmed().toFloat(&ok); + size_t duration = 0; + duration = attributes.value("duration").trimmed().toUInt(&ok); + QString label = attributes.value("label"); + rm->addPoint(RegionModel::Point(frame, value, duration, label)); + return ok; + } + TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset); if (tm) {