Mercurial > hg > svapp
comparison framework/Document.cpp @ 328:28c17ce7a6e9 tony_integration
Merge from tonioni branch
author | Chris Cannam |
---|---|
date | Tue, 28 Jan 2014 15:02:15 +0000 |
parents | 1e61f0c26593 |
children | f72d58d1ccb0 |
comparison
equal
deleted
inserted
replaced
304:c837368b1faf | 328:28c17ce7a6e9 |
---|---|
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> |
35 | 38 |
36 // For alignment: | 39 // For alignment: |
37 #include "data/model/AggregateWaveModel.h" | 40 #include "data/model/AggregateWaveModel.h" |
38 #include "data/model/SparseTimeValueModel.h" | 41 #include "data/model/SparseTimeValueModel.h" |
39 #include "data/model/AlignmentModel.h" | 42 #include "data/model/AlignmentModel.h" |
43 | |
44 using std::vector; | |
40 | 45 |
41 //#define DEBUG_DOCUMENT 1 | 46 //#define DEBUG_DOCUMENT 1 |
42 | 47 |
43 //!!! still need to handle command history, documentRestored/documentModified | 48 //!!! still need to handle command history, documentRestored/documentModified |
44 | 49 |
205 | 210 |
206 Layer * | 211 Layer * |
207 Document::createDerivedLayer(const Transform &transform, | 212 Document::createDerivedLayer(const Transform &transform, |
208 const ModelTransformer::Input &input) | 213 const ModelTransformer::Input &input) |
209 { | 214 { |
215 Transforms transforms; | |
216 transforms.push_back(transform); | |
217 vector<Layer *> layers = createDerivedLayers(transforms, input); | |
218 if (layers.empty()) return 0; | |
219 else return layers[0]; | |
220 } | |
221 | |
222 vector<Layer *> | |
223 Document::createDerivedLayers(const Transforms &transforms, | |
224 const ModelTransformer::Input &input) | |
225 { | |
210 QString message; | 226 QString message; |
211 Model *newModel = addDerivedModel(transform, input, message); | 227 vector<Model *> newModels = addDerivedModels(transforms, input, message); |
212 if (!newModel) { | 228 |
213 emit modelGenerationFailed(transform.getIdentifier(), message); | 229 if (newModels.empty()) { |
214 return 0; | 230 //!!! This identifier may be wrong! |
231 emit modelGenerationFailed(transforms[0].getIdentifier(), message); | |
232 return vector<Layer *>(); | |
215 } else if (message != "") { | 233 } else if (message != "") { |
216 emit modelGenerationWarning(transform.getIdentifier(), message); | 234 //!!! This identifier may be wrong! |
217 } | 235 emit modelGenerationWarning(transforms[0].getIdentifier(), message); |
218 | 236 } |
219 LayerFactory::LayerTypeSet types = | 237 |
220 LayerFactory::getInstance()->getValidLayerTypes(newModel); | 238 vector<Layer *> layers; |
221 | 239 |
222 if (types.empty()) { | 240 for (int i = 0; i < (int)newModels.size(); ++i) { |
223 cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << endl; | 241 |
224 newModel->aboutToDelete(); | 242 Model *newModel = newModels[i]; |
225 emit modelAboutToBeDeleted(newModel); | 243 |
226 m_models.erase(newModel); | 244 LayerFactory::LayerTypeSet types = |
227 delete newModel; | 245 LayerFactory::getInstance()->getValidLayerTypes(newModel); |
228 return 0; | 246 |
229 } | 247 if (types.empty()) { |
230 | 248 cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transforms[i].getIdentifier() << endl; |
231 //!!! for now, just use the first suitable layer type | 249 //!!! inadequate cleanup: |
232 | 250 newModel->aboutToDelete(); |
233 Layer *newLayer = createLayer(*types.begin()); | 251 emit modelAboutToBeDeleted(newModel); |
234 setModel(newLayer, newModel); | 252 m_models.erase(newModel); |
235 | 253 delete newModel; |
236 //!!! We need to clone the model when adding the layer, so that it | 254 return vector<Layer *>(); |
237 //can be edited without affecting other layers that are based on | 255 } |
238 //the same model. Unfortunately we can't just clone it now, | 256 |
239 //because it probably hasn't been completed yet -- the transform | 257 //!!! for now, just use the first suitable layer type |
240 //runs in the background. Maybe the transform has to handle | 258 |
241 //cloning and cacheing models itself. | 259 Layer *newLayer = createLayer(*types.begin()); |
242 // | 260 setModel(newLayer, newModel); |
243 // Once we do clone models here, of course, we'll have to avoid | 261 |
244 // leaking them too. | 262 //!!! We need to clone the model when adding the layer, so that it |
245 // | 263 //can be edited without affecting other layers that are based on |
246 // We want the user to be able to add a model to a second layer | 264 //the same model. Unfortunately we can't just clone it now, |
247 // _while it's still being calculated in the first_ and have it | 265 //because it probably hasn't been completed yet -- the transform |
248 // work quickly. That means we need to put the same physical | 266 //runs in the background. Maybe the transform has to handle |
249 // model pointer in both layers, so they can't actually be cloned. | 267 //cloning and cacheing models itself. |
268 // | |
269 // Once we do clone models here, of course, we'll have to avoid | |
270 // leaking them too. | |
271 // | |
272 // We want the user to be able to add a model to a second layer | |
273 // _while it's still being calculated in the first_ and have it | |
274 // work quickly. That means we need to put the same physical | |
275 // model pointer in both layers, so they can't actually be cloned. | |
250 | 276 |
251 if (newLayer) { | 277 if (newLayer) { |
252 newLayer->setObjectName(getUniqueLayerName | 278 newLayer->setObjectName(getUniqueLayerName |
253 (TransformFactory::getInstance()-> | 279 (TransformFactory::getInstance()-> |
254 getTransformFriendlyName | 280 getTransformFriendlyName |
255 (transform.getIdentifier()))); | 281 (transforms[i].getIdentifier()))); |
256 } | 282 } |
257 | 283 |
258 emit layerAdded(newLayer); | 284 emit layerAdded(newLayer); |
259 return newLayer; | 285 layers.push_back(newLayer); |
286 } | |
287 | |
288 return layers; | |
260 } | 289 } |
261 | 290 |
262 void | 291 void |
263 Document::setMainModel(WaveFileModel *model) | 292 Document::setMainModel(WaveFileModel *model) |
264 { | 293 { |
501 Model * | 530 Model * |
502 Document::addDerivedModel(const Transform &transform, | 531 Document::addDerivedModel(const Transform &transform, |
503 const ModelTransformer::Input &input, | 532 const ModelTransformer::Input &input, |
504 QString &message) | 533 QString &message) |
505 { | 534 { |
506 Model *model = 0; | |
507 | |
508 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { | 535 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { |
509 if (i->second.transform == transform && | 536 if (i->second.transform == transform && |
510 i->second.source == input.getModel() && | 537 i->second.source == input.getModel() && |
511 i->second.channel == input.getChannel()) { | 538 i->second.channel == input.getChannel()) { |
512 return i->first; | 539 std::cerr << "derived model taken from map " << std::endl; |
513 } | 540 return i->first; |
514 } | 541 } |
515 | 542 } |
516 model = ModelTransformerFactory::getInstance()->transform | 543 |
517 (transform, input, message); | 544 Transforms tt; |
518 | 545 tt.push_back(transform); |
519 // The transform we actually used was presumably identical to the | 546 vector<Model *> mm = addDerivedModels(tt, input, message); |
520 // one asked for, except that the version of the plugin may | 547 if (mm.empty()) return 0; |
521 // differ. It's possible that the returned message contains a | 548 else return mm[0]; |
522 // warning about this; that doesn't concern us here, but we do | 549 } |
523 // need to ensure that the transform we remember is correct for | 550 |
524 // what was actually applied, with the current plugin version. | 551 vector<Model *> |
525 | 552 Document::addDerivedModels(const Transforms &transforms, |
526 Transform applied = transform; | 553 const ModelTransformer::Input &input, |
527 applied.setPluginVersion | 554 QString &message) |
528 (TransformFactory::getInstance()-> | 555 { |
529 getDefaultTransformFor(transform.getIdentifier(), | 556 vector<Model *> mm = |
530 lrintf(transform.getSampleRate())) | 557 ModelTransformerFactory::getInstance()->transformMultiple |
531 .getPluginVersion()); | 558 (transforms, input, message); |
532 | 559 |
533 if (!model) { | 560 for (int j = 0; j < (int)mm.size(); ++j) { |
534 cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.getIdentifier() << endl; | 561 |
535 } else { | 562 Model *model = mm[j]; |
536 addDerivedModel(applied, input, model); | 563 |
537 } | 564 // The transform we actually used was presumably identical to |
538 | 565 // the one asked for, except that the version of the plugin |
539 return model; | 566 // may differ. It's possible that the returned message |
567 // contains a warning about this; that doesn't concern us | |
568 // here, but we do need to ensure that the transform we | |
569 // remember is correct for what was actually applied, with the | |
570 // current plugin version. | |
571 | |
572 Transform applied = transforms[j]; | |
573 applied.setPluginVersion | |
574 (TransformFactory::getInstance()-> | |
575 getDefaultTransformFor(applied.getIdentifier(), | |
576 lrintf(applied.getSampleRate())) | |
577 .getPluginVersion()); | |
578 | |
579 if (!model) { | |
580 cerr << "WARNING: Document::addDerivedModel: no output model for transform " << applied.getIdentifier() << endl; | |
581 } else { | |
582 addDerivedModel(applied, input, model); | |
583 } | |
584 } | |
585 | |
586 return mm; | |
540 } | 587 } |
541 | 588 |
542 void | 589 void |
543 Document::releaseModel(Model *model) // Will _not_ release main model! | 590 Document::releaseModel(Model *model) // Will _not_ release main model! |
544 { | 591 { |
688 PlayParameterRepository::getInstance()->copyParameters | 735 PlayParameterRepository::getInstance()->copyParameters |
689 (previousModel, model); | 736 (previousModel, model); |
690 } | 737 } |
691 | 738 |
692 LayerFactory::getInstance()->setModel(layer, model); | 739 LayerFactory::getInstance()->setModel(layer, model); |
740 // std::cerr << "layer type: " << LayerFactory::getInstance()->getLayerTypeName(LayerFactory::getInstance()->getLayerType(layer)) << std::endl; | |
693 | 741 |
694 if (previousModel) { | 742 if (previousModel) { |
695 releaseModel(previousModel); | 743 releaseModel(previousModel); |
696 } | 744 } |
697 } | 745 } |