comparison framework/Document.cpp @ 54:a798f5e6fc5e

* Further naming change: Transformer -> ModelTransformer. The Transform class now describes a thing that can be done, and the ModelTransformer does it to a Model.
author Chris Cannam
date Wed, 07 Nov 2007 12:59:01 +0000
parents de2b3c6479c8
children eb596ef12041
comparison
equal deleted inserted replaced
53:de2b3c6479c8 54:a798f5e6fc5e
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/TransformerFactory.h" 28 #include "plugin/transform/TransformFactory.h"
29 #include "plugin/transform/ModelTransformerFactory.h"
29 #include <QApplication> 30 #include <QApplication>
30 #include <QTextStream> 31 #include <QTextStream>
31 #include <iostream> 32 #include <iostream>
32 33
33 // For alignment: 34 // For alignment:
40 Document::Document() : 41 Document::Document() :
41 m_mainModel(0), 42 m_mainModel(0),
42 m_autoAlignment(false) 43 m_autoAlignment(false)
43 { 44 {
44 connect(this, SIGNAL(modelAboutToBeDeleted(Model *)), 45 connect(this, SIGNAL(modelAboutToBeDeleted(Model *)),
45 TransformerFactory::getInstance(), 46 ModelTransformerFactory::getInstance(),
46 SLOT(modelAboutToBeDeleted(Model *))); 47 SLOT(modelAboutToBeDeleted(Model *)));
47 } 48 }
48 49
49 Document::~Document() 50 Document::~Document()
50 { 51 {
172 return newLayer; 173 return newLayer;
173 } 174 }
174 175
175 Layer * 176 Layer *
176 Document::createDerivedLayer(LayerFactory::LayerType type, 177 Document::createDerivedLayer(LayerFactory::LayerType type,
177 TransformerId transform) 178 TransformId transform)
178 { 179 {
179 Layer *newLayer = createLayer(type); 180 Layer *newLayer = createLayer(type);
180 if (!newLayer) return 0; 181 if (!newLayer) return 0;
181 182
182 newLayer->setObjectName(getUniqueLayerName 183 newLayer->setObjectName(getUniqueLayerName
183 (TransformerFactory::getInstance()-> 184 (TransformFactory::getInstance()->
184 getTransformerFriendlyName(transform))); 185 getTransformFriendlyName(transform)));
185 186
186 return newLayer; 187 return newLayer;
187 } 188 }
188 189
189 Layer * 190 Layer *
190 Document::createDerivedLayer(TransformerId transform, 191 Document::createDerivedLayer(TransformId transform,
191 Model *inputModel, 192 Model *inputModel,
192 const PluginTransformer::ExecutionContext &context, 193 const PluginTransformer::ExecutionContext &context,
193 QString configurationXml) 194 QString configurationXml)
194 { 195 {
195 Model *newModel = addDerivedModel(transform, inputModel, 196 Model *newModel = addDerivedModel(transform, inputModel,
229 // work quickly. That means we need to put the same physical 230 // work quickly. That means we need to put the same physical
230 // model pointer in both layers, so they can't actually be cloned. 231 // model pointer in both layers, so they can't actually be cloned.
231 232
232 if (newLayer) { 233 if (newLayer) {
233 newLayer->setObjectName(getUniqueLayerName 234 newLayer->setObjectName(getUniqueLayerName
234 (TransformerFactory::getInstance()-> 235 (TransformFactory::getInstance()->
235 getTransformerFriendlyName(transform))); 236 getTransformFriendlyName(transform)));
236 } 237 }
237 238
238 emit layerAdded(newLayer); 239 emit layerAdded(newLayer);
239 return newLayer; 240 return newLayer;
240 } 241 }
287 // std::cerr << "... it uses a model derived from the old main model, regenerating" << std::endl; 288 // std::cerr << "... it uses a model derived from the old main model, regenerating" << std::endl;
288 289
289 // This model was derived from the previous main 290 // This model was derived from the previous main
290 // model: regenerate it. 291 // model: regenerate it.
291 292
292 TransformerId transform = m_models[model].transform; 293 TransformId transform = m_models[model].transform;
293 PluginTransformer::ExecutionContext context = m_models[model].context; 294 PluginTransformer::ExecutionContext context = m_models[model].context;
294 295
295 Model *replacementModel = 296 Model *replacementModel =
296 addDerivedModel(transform, 297 addDerivedModel(transform,
297 m_mainModel, 298 m_mainModel,
341 // we already emitted modelAboutToBeDeleted for this 342 // we already emitted modelAboutToBeDeleted for this
342 delete oldMainModel; 343 delete oldMainModel;
343 } 344 }
344 345
345 void 346 void
346 Document::addDerivedModel(TransformerId transform, 347 Document::addDerivedModel(TransformId transform,
347 Model *inputModel, 348 Model *inputModel,
348 const PluginTransformer::ExecutionContext &context, 349 const PluginTransformer::ExecutionContext &context,
349 Model *outputModelToAdd, 350 Model *outputModelToAdd,
350 QString configurationXml) 351 QString configurationXml)
351 { 352 {
392 393
393 emit modelAdded(model); 394 emit modelAdded(model);
394 } 395 }
395 396
396 Model * 397 Model *
397 Document::addDerivedModel(TransformerId transform, 398 Document::addDerivedModel(TransformId transform,
398 Model *inputModel, 399 Model *inputModel,
399 const PluginTransformer::ExecutionContext &context, 400 const PluginTransformer::ExecutionContext &context,
400 QString configurationXml) 401 QString configurationXml)
401 { 402 {
402 Model *model = 0; 403 Model *model = 0;
408 i->second.configurationXml == configurationXml) { 409 i->second.configurationXml == configurationXml) {
409 return i->first; 410 return i->first;
410 } 411 }
411 } 412 }
412 413
413 model = TransformerFactory::getInstance()->transform 414 model = ModelTransformerFactory::getInstance()->transform
414 (transform, inputModel, context, configurationXml); 415 (transform, inputModel, context, configurationXml);
415 416
416 if (!model) { 417 if (!model) {
417 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.toStdString() << std::endl; 418 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.toStdString() << std::endl;
418 } else { 419 } else {
685 } 686 }
686 687
687 bool 688 bool
688 Document::canAlign() 689 Document::canAlign()
689 { 690 {
690 TransformerId id = "vamp:match-vamp-plugin:match:path"; 691 TransformId id = "vamp:match-vamp-plugin:match:path";
691 TransformerFactory *factory = TransformerFactory::getInstance(); 692 TransformFactory *factory = TransformFactory::getInstance();
692 return factory->haveTransformer(id); 693 return factory->haveTransform(id);
693 } 694 }
694 695
695 void 696 void
696 Document::alignModel(Model *model) 697 Document::alignModel(Model *model)
697 { 698 {
730 components.push_back(AggregateWaveModel::ModelChannelSpec 731 components.push_back(AggregateWaveModel::ModelChannelSpec
731 (rm, -1)); 732 (rm, -1));
732 733
733 Model *aggregate = new AggregateWaveModel(components); 734 Model *aggregate = new AggregateWaveModel(components);
734 735
735 TransformerId id = "vamp:match-vamp-plugin:match:path"; 736 TransformId id = "vamp:match-vamp-plugin:match:path";
736 737
737 TransformerFactory *factory = TransformerFactory::getInstance(); 738 ModelTransformerFactory *factory = ModelTransformerFactory::getInstance();
738 739
739 Model *transformOutput = factory->transform 740 Model *transformOutput = factory->transform
740 (id, aggregate, 741 (id, aggregate,
741 factory->getDefaultContextForTransformer(id, aggregate), 742 factory->getDefaultContextForTransformer(id, aggregate),
742 "<plugin param-serialise=\"1\"/>"); 743 "<plugin param-serialise=\"1\"/>");