Mercurial > hg > svapp
comparison framework/Document.cpp @ 270:776e1aae635a tonioni
fixed flexi note layer and propagated model selection to analyser
author | gyorgyf |
---|---|
date | Sat, 13 Apr 2013 13:39:17 +0100 |
parents | 40a0fa9af6b4 |
children | 94bf7d7f2d6f |
comparison
equal
deleted
inserted
replaced
269:40a0fa9af6b4 | 270:776e1aae635a |
---|---|
17 | 17 |
18 #include "data/model/WaveFileModel.h" | 18 #include "data/model/WaveFileModel.h" |
19 #include "data/model/WritableWaveFileModel.h" | 19 #include "data/model/WritableWaveFileModel.h" |
20 #include "data/model/DenseThreeDimensionalModel.h" | 20 #include "data/model/DenseThreeDimensionalModel.h" |
21 #include "data/model/DenseTimeValueModel.h" | 21 #include "data/model/DenseTimeValueModel.h" |
22 #include "data/model/FlexiNoteModel.h" | |
23 | |
22 #include "layer/Layer.h" | 24 #include "layer/Layer.h" |
23 #include "widgets/CommandHistory.h" | 25 #include "widgets/CommandHistory.h" |
24 #include "base/Command.h" | 26 #include "base/Command.h" |
25 #include "view/View.h" | 27 #include "view/View.h" |
26 #include "base/PlayParameterRepository.h" | 28 #include "base/PlayParameterRepository.h" |
27 #include "base/PlayParameters.h" | 29 #include "base/PlayParameters.h" |
28 #include "transform/TransformFactory.h" | 30 #include "transform/TransformFactory.h" |
29 #include "transform/ModelTransformerFactory.h" | 31 #include "transform/ModelTransformerFactory.h" |
32 #include "transform/FeatureExtractionModelTransformer.h" | |
30 #include <QApplication> | 33 #include <QApplication> |
31 #include <QTextStream> | 34 #include <QTextStream> |
32 #include <QSettings> | 35 #include <QSettings> |
33 #include <iostream> | 36 #include <iostream> |
34 #include <typeinfo> | 37 #include <typeinfo> |
115 | 118 |
116 #ifdef DEBUG_DOCUMENT | 119 #ifdef DEBUG_DOCUMENT |
117 SVDEBUG << "Document::createLayer: Added layer of type " << type | 120 SVDEBUG << "Document::createLayer: Added layer of type " << type |
118 << ", now have " << m_layers.size() << " layers" << endl; | 121 << ", now have " << m_layers.size() << " layers" << endl; |
119 #endif | 122 #endif |
123 | |
124 std::cerr << "Document::createLayer: Added layer of type " << type | |
125 << ", now have " << m_layers.size() << " layers" << endl; | |
120 | 126 |
121 emit layerAdded(newLayer); | 127 emit layerAdded(newLayer); |
122 | 128 |
123 return newLayer; | 129 return newLayer; |
124 } | 130 } |
259 } | 265 } |
260 | 266 |
261 Layer * | 267 Layer * |
262 Document::createDerivedLayer(const Transform &transform, | 268 Document::createDerivedLayer(const Transform &transform, |
263 const ModelTransformer::Input &input, | 269 const ModelTransformer::Input &input, |
264 const LayerFactory::LayerType type) | 270 const LayerFactory::LayerType type, |
271 const FeatureExtractionModelTransformer::PreferredOutputModel outputmodel) | |
265 { | 272 { |
266 // !!! THIS IS TOTALLY REDUNDANT CODE, EXCEPT FOR THE type SETTING | 273 // !!! THIS IS TOTALLY REDUNDANT CODE, EXCEPT FOR THE type SETTING |
267 | 274 |
268 QString message; | 275 QString message; |
269 Model *newModel = addDerivedModel(transform, input, message); | 276 Model *newModel = addDerivedModel(transform, input, message, outputmodel); |
270 if (!newModel) { | 277 if (!newModel) { |
271 emit modelGenerationFailed(transform.getIdentifier(), message); | 278 emit modelGenerationFailed(transform.getIdentifier(), message); |
272 return 0; | 279 return 0; |
273 } else if (message != "") { | 280 } else if (message != "") { |
274 emit modelGenerationWarning(transform.getIdentifier(), message); | 281 emit modelGenerationWarning(transform.getIdentifier(), message); |
275 } | 282 } |
276 | 283 |
277 LayerFactory::LayerTypeSet types = | 284 LayerFactory::LayerTypeSet types = |
278 LayerFactory::getInstance()->getValidLayerTypes(newModel); | 285 LayerFactory::getInstance()->getValidLayerTypes(newModel); |
279 | 286 |
280 if (types.empty()) { | 287 if (types.empty()) { |
281 std::cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << std::endl; | 288 std::cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << std::endl; |
282 newModel->aboutToDelete(); | 289 newModel->aboutToDelete(); |
283 emit modelAboutToBeDeleted(newModel); | 290 emit modelAboutToBeDeleted(newModel); |
284 m_models.erase(newModel); | 291 m_models.erase(newModel); |
285 delete newModel; | 292 delete newModel; |
286 return 0; | 293 return 0; |
287 } | 294 } |
288 | 295 |
289 //!!! for now, just use the first suitable layer type | 296 //!!! creating layer with the specified type |
290 | 297 |
291 Layer *newLayer = createLayer(type); | 298 Layer *newLayer = createLayer(type); |
299 std::cerr << " NOTE: Created layer " << newLayer << " calling Document::setModel() " << std::endl; | |
292 setModel(newLayer, newModel); | 300 setModel(newLayer, newModel); |
293 | 301 |
294 //!!! We need to clone the model when adding the layer, so that it | 302 //!!! We need to clone the model when adding the layer, so that it |
295 //can be edited without affecting other layers that are based on | 303 //can be edited without affecting other layers that are based on |
296 //the same model. Unfortunately we can't just clone it now, | 304 //the same model. Unfortunately we can't just clone it now, |
558 } | 566 } |
559 | 567 |
560 Model * | 568 Model * |
561 Document::addDerivedModel(const Transform &transform, | 569 Document::addDerivedModel(const Transform &transform, |
562 const ModelTransformer::Input &input, | 570 const ModelTransformer::Input &input, |
563 QString &message) | 571 QString &message, |
572 const FeatureExtractionModelTransformer::PreferredOutputModel outputmodel) | |
564 { | 573 { |
565 Model *model = 0; | 574 Model *model = 0; |
575 // model = (Model) new FlexiNoteModel(); | |
576 // return model; | |
566 | 577 |
567 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { | 578 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { |
568 if (i->second.transform == transform && | 579 if (i->second.transform == transform && |
569 i->second.source == input.getModel() && | 580 i->second.source == input.getModel() && |
570 i->second.channel == input.getChannel()) { | 581 i->second.channel == input.getChannel()) { |
582 std::cerr << "derived model taken from map " << std::endl; | |
571 return i->first; | 583 return i->first; |
572 } | 584 } |
573 } | 585 } |
574 | 586 |
587 // GF: TODO: propagate preferredOutputModelSelection (done) | |
575 model = ModelTransformerFactory::getInstance()->transform | 588 model = ModelTransformerFactory::getInstance()->transform |
576 (transform, input, message); | 589 (transform, input, message, outputmodel); //e.g. FeatureExtractionModelTransformer::FlexiNoteOutputModel |
577 | 590 |
578 // The transform we actually used was presumably identical to the | 591 // The transform we actually used was presumably identical to the |
579 // one asked for, except that the version of the plugin may | 592 // one asked for, except that the version of the plugin may |
580 // differ. It's possible that the returned message contains a | 593 // differ. It's possible that the returned message contains a |
581 // warning about this; that doesn't concern us here, but we do | 594 // warning about this; that doesn't concern us here, but we do |
592 if (!model) { | 605 if (!model) { |
593 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.getIdentifier() << std::endl; | 606 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.getIdentifier() << std::endl; |
594 } else { | 607 } else { |
595 addDerivedModel(applied, input, model); | 608 addDerivedModel(applied, input, model); |
596 } | 609 } |
597 | 610 std::cerr << "derived model from ModelTransformerFactory::getInstance()->transform " << std::endl; |
611 std::cerr << "derived model name: " << model->getTypeName() << std::endl; | |
612 | |
598 return model; | 613 return model; |
599 } | 614 } |
600 | 615 |
601 void | 616 void |
602 Document::releaseModel(Model *model) // Will _not_ release main model! | 617 Document::releaseModel(Model *model) // Will _not_ release main model! |
715 } | 730 } |
716 | 731 |
717 void | 732 void |
718 Document::setModel(Layer *layer, Model *model) | 733 Document::setModel(Layer *layer, Model *model) |
719 { | 734 { |
735 std::cerr << "Document::setModel: setting model " << std::endl; | |
720 if (model && | 736 if (model && |
721 model != m_mainModel && | 737 model != m_mainModel && |
722 m_models.find(model) == m_models.end()) { | 738 m_models.find(model) == m_models.end()) { |
723 std::cerr << "ERROR: Document::setModel: Layer " << layer | 739 std::cerr << "ERROR: Document::setModel: Layer " << layer |
724 << " (\"" << layer->objectName().toStdString() | 740 << " (\"" << layer->objectName().toStdString() |
746 if (model && previousModel) { | 762 if (model && previousModel) { |
747 PlayParameterRepository::getInstance()->copyParameters | 763 PlayParameterRepository::getInstance()->copyParameters |
748 (previousModel, model); | 764 (previousModel, model); |
749 } | 765 } |
750 | 766 |
767 std::cerr << "Document::setModel: calling layer->setModel() " << std::endl; | |
768 std::cerr << "Document::setModel: getInstance: " << LayerFactory::getInstance() << std::endl; | |
769 std::cerr << "model: " << model << std::endl; | |
770 std::cerr << "layer: " << layer << std::endl; | |
751 LayerFactory::getInstance()->setModel(layer, model); | 771 LayerFactory::getInstance()->setModel(layer, model); |
772 std::cerr << "layer type: " << LayerFactory::getInstance()->getLayerTypeName(LayerFactory::getInstance()->getLayerType(layer)) << std::endl; | |
773 std::cerr << "Document::setModel: done. " << std::endl; | |
752 | 774 |
753 if (previousModel) { | 775 if (previousModel) { |
754 releaseModel(previousModel); | 776 releaseModel(previousModel); |
755 } | 777 } |
756 } | 778 } |