comparison framework/Document.cpp @ 53:de2b3c6479c8

* Introduce new Transform class which contains data necessary to describe the context for a plugin -- the plugin's name and output, the step/block size etc (formerly spread across ExecutionContext and TransformFactory). Other code hasn't been updated to use this yet. * Rename existing Transform stuff to Transformers (because they run Transforms) I'm still not 100% sure about this change, don't rely on it.
author Chris Cannam
date Mon, 05 Nov 2007 15:31:06 +0000
parents 43ad8d909e28
children a798f5e6fc5e
comparison
equal deleted inserted replaced
52:43ad8d909e28 53:de2b3c6479c8
23 #include "base/CommandHistory.h" 23 #include "base/CommandHistory.h"
24 #include "base/Command.h" 24 #include "base/Command.h"
25 #include "view/View.h" 25 #include "view/View.h"
26 #include "base/PlayParameterRepository.h" 26 #include "base/PlayParameterRepository.h"
27 #include "base/PlayParameters.h" 27 #include "base/PlayParameters.h"
28 #include "plugin/transform/TransformFactory.h" 28 #include "plugin/transform/TransformerFactory.h"
29 #include <QApplication> 29 #include <QApplication>
30 #include <QTextStream> 30 #include <QTextStream>
31 #include <iostream> 31 #include <iostream>
32 32
33 // For alignment: 33 // For alignment:
40 Document::Document() : 40 Document::Document() :
41 m_mainModel(0), 41 m_mainModel(0),
42 m_autoAlignment(false) 42 m_autoAlignment(false)
43 { 43 {
44 connect(this, SIGNAL(modelAboutToBeDeleted(Model *)), 44 connect(this, SIGNAL(modelAboutToBeDeleted(Model *)),
45 TransformFactory::getInstance(), 45 TransformerFactory::getInstance(),
46 SLOT(modelAboutToBeDeleted(Model *))); 46 SLOT(modelAboutToBeDeleted(Model *)));
47 } 47 }
48 48
49 Document::~Document() 49 Document::~Document()
50 { 50 {
172 return newLayer; 172 return newLayer;
173 } 173 }
174 174
175 Layer * 175 Layer *
176 Document::createDerivedLayer(LayerFactory::LayerType type, 176 Document::createDerivedLayer(LayerFactory::LayerType type,
177 TransformId transform) 177 TransformerId transform)
178 { 178 {
179 Layer *newLayer = createLayer(type); 179 Layer *newLayer = createLayer(type);
180 if (!newLayer) return 0; 180 if (!newLayer) return 0;
181 181
182 newLayer->setObjectName(getUniqueLayerName 182 newLayer->setObjectName(getUniqueLayerName
183 (TransformFactory::getInstance()-> 183 (TransformerFactory::getInstance()->
184 getTransformFriendlyName(transform))); 184 getTransformerFriendlyName(transform)));
185 185
186 return newLayer; 186 return newLayer;
187 } 187 }
188 188
189 Layer * 189 Layer *
190 Document::createDerivedLayer(TransformId transform, 190 Document::createDerivedLayer(TransformerId transform,
191 Model *inputModel, 191 Model *inputModel,
192 const PluginTransform::ExecutionContext &context, 192 const PluginTransformer::ExecutionContext &context,
193 QString configurationXml) 193 QString configurationXml)
194 { 194 {
195 Model *newModel = addDerivedModel(transform, inputModel, 195 Model *newModel = addDerivedModel(transform, inputModel,
196 context, configurationXml); 196 context, configurationXml);
197 if (!newModel) { 197 if (!newModel) {
202 202
203 LayerFactory::LayerTypeSet types = 203 LayerFactory::LayerTypeSet types =
204 LayerFactory::getInstance()->getValidLayerTypes(newModel); 204 LayerFactory::getInstance()->getValidLayerTypes(newModel);
205 205
206 if (types.empty()) { 206 if (types.empty()) {
207 std::cerr << "WARNING: Document::createLayerForTransform: no valid display layer for output of transform " << transform.toStdString() << std::endl; 207 std::cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.toStdString() << std::endl;
208 delete newModel; 208 delete newModel;
209 return 0; 209 return 0;
210 } 210 }
211 211
212 //!!! for now, just use the first suitable layer type 212 //!!! for now, just use the first suitable layer type
229 // work quickly. That means we need to put the same physical 229 // work quickly. That means we need to put the same physical
230 // model pointer in both layers, so they can't actually be cloned. 230 // model pointer in both layers, so they can't actually be cloned.
231 231
232 if (newLayer) { 232 if (newLayer) {
233 newLayer->setObjectName(getUniqueLayerName 233 newLayer->setObjectName(getUniqueLayerName
234 (TransformFactory::getInstance()-> 234 (TransformerFactory::getInstance()->
235 getTransformFriendlyName(transform))); 235 getTransformerFriendlyName(transform)));
236 } 236 }
237 237
238 emit layerAdded(newLayer); 238 emit layerAdded(newLayer);
239 return newLayer; 239 return newLayer;
240 } 240 }
246 m_mainModel = model; 246 m_mainModel = model;
247 247
248 emit modelAdded(m_mainModel); 248 emit modelAdded(m_mainModel);
249 249
250 std::vector<Layer *> obsoleteLayers; 250 std::vector<Layer *> obsoleteLayers;
251 std::set<QString> failedTransforms; 251 std::set<QString> failedTransformers;
252 252
253 // We need to ensure that no layer is left using oldMainModel or 253 // We need to ensure that no layer is left using oldMainModel or
254 // any of the old derived models as its model. Either replace the 254 // any of the old derived models as its model. Either replace the
255 // model, or delete the layer for each layer that is currently 255 // model, or delete the layer for each layer that is currently
256 // using one of these. Carry out this replacement before we 256 // using one of these. Carry out this replacement before we
287 // std::cerr << "... it uses a model derived from the old main model, regenerating" << std::endl; 287 // std::cerr << "... it uses a model derived from the old main model, regenerating" << std::endl;
288 288
289 // This model was derived from the previous main 289 // This model was derived from the previous main
290 // model: regenerate it. 290 // model: regenerate it.
291 291
292 TransformId transform = m_models[model].transform; 292 TransformerId transform = m_models[model].transform;
293 PluginTransform::ExecutionContext context = m_models[model].context; 293 PluginTransformer::ExecutionContext context = m_models[model].context;
294 294
295 Model *replacementModel = 295 Model *replacementModel =
296 addDerivedModel(transform, 296 addDerivedModel(transform,
297 m_mainModel, 297 m_mainModel,
298 context, 298 context,
299 m_models[model].configurationXml); 299 m_models[model].configurationXml);
300 300
301 if (!replacementModel) { 301 if (!replacementModel) {
302 std::cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \"" 302 std::cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \""
303 << transform.toStdString() << "\"" << " in layer " << layer << std::endl; 303 << transform.toStdString() << "\"" << " in layer " << layer << std::endl;
304 if (failedTransforms.find(transform) == failedTransforms.end()) { 304 if (failedTransformers.find(transform) == failedTransformers.end()) {
305 emit modelRegenerationFailed(layer->objectName(), 305 emit modelRegenerationFailed(layer->objectName(),
306 transform); 306 transform);
307 failedTransforms.insert(transform); 307 failedTransformers.insert(transform);
308 } 308 }
309 obsoleteLayers.push_back(layer); 309 obsoleteLayers.push_back(layer);
310 } else { 310 } else {
311 std::cerr << "Replacing model " << model << " (type " 311 std::cerr << "Replacing model " << model << " (type "
312 << typeid(*model).name() << ") with model " 312 << typeid(*model).name() << ") with model "
341 // we already emitted modelAboutToBeDeleted for this 341 // we already emitted modelAboutToBeDeleted for this
342 delete oldMainModel; 342 delete oldMainModel;
343 } 343 }
344 344
345 void 345 void
346 Document::addDerivedModel(TransformId transform, 346 Document::addDerivedModel(TransformerId transform,
347 Model *inputModel, 347 Model *inputModel,
348 const PluginTransform::ExecutionContext &context, 348 const PluginTransformer::ExecutionContext &context,
349 Model *outputModelToAdd, 349 Model *outputModelToAdd,
350 QString configurationXml) 350 QString configurationXml)
351 { 351 {
352 if (m_models.find(outputModelToAdd) != m_models.end()) { 352 if (m_models.find(outputModelToAdd) != m_models.end()) {
353 std::cerr << "WARNING: Document::addDerivedModel: Model already added" 353 std::cerr << "WARNING: Document::addDerivedModel: Model already added"
392 392
393 emit modelAdded(model); 393 emit modelAdded(model);
394 } 394 }
395 395
396 Model * 396 Model *
397 Document::addDerivedModel(TransformId transform, 397 Document::addDerivedModel(TransformerId transform,
398 Model *inputModel, 398 Model *inputModel,
399 const PluginTransform::ExecutionContext &context, 399 const PluginTransformer::ExecutionContext &context,
400 QString configurationXml) 400 QString configurationXml)
401 { 401 {
402 Model *model = 0; 402 Model *model = 0;
403 403
404 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { 404 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) {
408 i->second.configurationXml == configurationXml) { 408 i->second.configurationXml == configurationXml) {
409 return i->first; 409 return i->first;
410 } 410 }
411 } 411 }
412 412
413 model = TransformFactory::getInstance()->transform 413 model = TransformerFactory::getInstance()->transform
414 (transform, inputModel, context, configurationXml); 414 (transform, inputModel, context, configurationXml);
415 415
416 if (!model) { 416 if (!model) {
417 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.toStdString() << std::endl; 417 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.toStdString() << std::endl;
418 } else { 418 } else {
658 if (!duplicate) return adjusted; 658 if (!duplicate) return adjusted;
659 } 659 }
660 } 660 }
661 661
662 std::vector<Model *> 662 std::vector<Model *>
663 Document::getTransformInputModels() 663 Document::getTransformerInputModels()
664 { 664 {
665 std::vector<Model *> models; 665 std::vector<Model *> models;
666 666
667 if (!m_mainModel) return models; 667 if (!m_mainModel) return models;
668 668
685 } 685 }
686 686
687 bool 687 bool
688 Document::canAlign() 688 Document::canAlign()
689 { 689 {
690 TransformId id = "vamp:match-vamp-plugin:match:path"; 690 TransformerId id = "vamp:match-vamp-plugin:match:path";
691 TransformFactory *factory = TransformFactory::getInstance(); 691 TransformerFactory *factory = TransformerFactory::getInstance();
692 return factory->haveTransform(id); 692 return factory->haveTransformer(id);
693 } 693 }
694 694
695 void 695 void
696 Document::alignModel(Model *model) 696 Document::alignModel(Model *model)
697 { 697 {
708 // 1. an AggregateWaveModel to provide the mixdowns of the main 708 // 1. an AggregateWaveModel to provide the mixdowns of the main
709 // model and the new model in its two channels, as input to the 709 // model and the new model in its two channels, as input to the
710 // MATCH plugin 710 // MATCH plugin
711 711
712 // 2. a SparseTimeValueModel, which is the model automatically 712 // 2. a SparseTimeValueModel, which is the model automatically
713 // created by FeatureExtractionPluginTransform when running the 713 // created by FeatureExtractionPluginTransformer when running the
714 // MATCH plugin (thus containing the alignment path) 714 // MATCH plugin (thus containing the alignment path)
715 715
716 // 3. an AlignmentModel, which stores the path model and carries 716 // 3. an AlignmentModel, which stores the path model and carries
717 // out alignment lookups on it. 717 // out alignment lookups on it.
718 718
730 components.push_back(AggregateWaveModel::ModelChannelSpec 730 components.push_back(AggregateWaveModel::ModelChannelSpec
731 (rm, -1)); 731 (rm, -1));
732 732
733 Model *aggregate = new AggregateWaveModel(components); 733 Model *aggregate = new AggregateWaveModel(components);
734 734
735 TransformId id = "vamp:match-vamp-plugin:match:path"; 735 TransformerId id = "vamp:match-vamp-plugin:match:path";
736 736
737 TransformFactory *factory = TransformFactory::getInstance(); 737 TransformerFactory *factory = TransformerFactory::getInstance();
738 738
739 Model *transformOutput = factory->transform 739 Model *transformOutput = factory->transform
740 (id, aggregate, 740 (id, aggregate,
741 factory->getDefaultContextForTransform(id, aggregate), 741 factory->getDefaultContextForTransformer(id, aggregate),
742 "<plugin param-serialise=\"1\"/>"); 742 "<plugin param-serialise=\"1\"/>");
743 743
744 SparseTimeValueModel *path = dynamic_cast<SparseTimeValueModel *> 744 SparseTimeValueModel *path = dynamic_cast<SparseTimeValueModel *>
745 (transformOutput); 745 (transformOutput);
746 746