comparison document/Document.cpp @ 55:ca1e3f5657d5

* Simplify maker names in plugin menu * Make sure derived models have a name (based on the transform) * Don't start deriving a model from a derived model until the derived model is ready * Tidy up completion management in writable wave file model * Make writable models save/reload correctly from session file (i.e. regenerating from the original transform) * Same for dense 3d models -- don't save the data, just the transform details * Add a comment describing the SV file format
author Chris Cannam
date Fri, 13 Oct 2006 12:51:05 +0000
parents ec77936c268e
children cf27fc7feb7a
comparison
equal deleted inserted replaced
54:ec77936c268e 55:ca1e3f5657d5
14 */ 14 */
15 15
16 #include "Document.h" 16 #include "Document.h"
17 17
18 #include "data/model/WaveFileModel.h" 18 #include "data/model/WaveFileModel.h"
19 #include "data/model/WritableWaveFileModel.h"
20 #include "data/model/DenseThreeDimensionalModel.h"
19 #include "layer/Layer.h" 21 #include "layer/Layer.h"
20 #include "base/CommandHistory.h" 22 #include "base/CommandHistory.h"
21 #include "base/Command.h" 23 #include "base/Command.h"
22 #include "view/View.h" 24 #include "view/View.h"
23 #include "base/PlayParameterRepository.h" 25 #include "base/PlayParameterRepository.h"
162 Document::createDerivedLayer(TransformName transform, 164 Document::createDerivedLayer(TransformName transform,
163 Model *inputModel, 165 Model *inputModel,
164 const PluginTransform::ExecutionContext &context, 166 const PluginTransform::ExecutionContext &context,
165 QString configurationXml) 167 QString configurationXml)
166 { 168 {
167 Model *newModel = createModelForTransform(transform, inputModel, 169 Model *newModel = addDerivedModel(transform, inputModel,
168 context, configurationXml); 170 context, configurationXml);
169 if (!newModel) { 171 if (!newModel) {
170 // error already printed to stderr by createModelForTransform 172 // error already printed to stderr by addDerivedModel
171 emit modelGenerationFailed(transform); 173 emit modelGenerationFailed(transform);
172 return 0; 174 return 0;
173 } 175 }
174 176
175 LayerFactory::LayerTypeSet types = 177 LayerFactory::LayerTypeSet types =
260 262
261 TransformName transform = m_models[model].transform; 263 TransformName transform = m_models[model].transform;
262 PluginTransform::ExecutionContext context = m_models[model].context; 264 PluginTransform::ExecutionContext context = m_models[model].context;
263 265
264 Model *replacementModel = 266 Model *replacementModel =
265 createModelForTransform(transform, 267 addDerivedModel(transform,
266 m_mainModel, 268 m_mainModel,
267 context, 269 context,
268 m_models[model].configurationXml); 270 m_models[model].configurationXml);
269 271
270 if (!replacementModel) { 272 if (!replacementModel) {
271 std::cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \"" 273 std::cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \""
272 << transform.toStdString() << "\"" << " in layer " << layer << std::endl; 274 << transform.toStdString() << "\"" << " in layer " << layer << std::endl;
273 if (failedTransforms.find(transform) == failedTransforms.end()) { 275 if (failedTransforms.find(transform) == failedTransforms.end()) {
351 353
352 emit modelAdded(model); 354 emit modelAdded(model);
353 } 355 }
354 356
355 Model * 357 Model *
356 Document::createModelForTransform(TransformName transform, 358 Document::addDerivedModel(TransformName transform,
357 Model *inputModel, 359 Model *inputModel,
358 const PluginTransform::ExecutionContext &context, 360 const PluginTransform::ExecutionContext &context,
359 QString configurationXml) 361 QString configurationXml)
360 { 362 {
361 Model *model = 0; 363 Model *model = 0;
362 364
363 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { 365 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) {
364 if (i->second.transform == transform && 366 if (i->second.transform == transform &&
371 373
372 model = TransformFactory::getInstance()->transform 374 model = TransformFactory::getInstance()->transform
373 (transform, inputModel, context, configurationXml); 375 (transform, inputModel, context, configurationXml);
374 376
375 if (!model) { 377 if (!model) {
376 std::cerr << "WARNING: Document::createModelForTransform: no output model for transform " << transform.toStdString() << std::endl; 378 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.toStdString() << std::endl;
377 } else { 379 } else {
378 addDerivedModel(transform, inputModel, context, model, configurationXml); 380 addDerivedModel(transform, inputModel, context, model, configurationXml);
379 } 381 }
380 382
381 return model; 383 return model;
492 } 494 }
493 495
494 Model *previousModel = layer->getModel(); 496 Model *previousModel = layer->getModel();
495 497
496 if (previousModel == model) { 498 if (previousModel == model) {
497 std::cerr << "WARNING: Document::setModel: Layer is already set to this model" << std::endl; 499 std::cerr << "WARNING: Document::setModel: Layer " << layer << " (\""
500 << layer->objectName().toStdString()
501 << "\") is already set to model "
502 << model << " (\""
503 << (model ? model->objectName().toStdString() : "(null)")
504 << "\")" << std::endl;
498 return; 505 return;
499 } 506 }
500 507
501 if (model && model != m_mainModel) { 508 if (model && model != m_mainModel) {
502 m_models[model].refcount ++; 509 m_models[model].refcount ++;
518 void 525 void
519 Document::addLayerToView(View *view, Layer *layer) 526 Document::addLayerToView(View *view, Layer *layer)
520 { 527 {
521 Model *model = layer->getModel(); 528 Model *model = layer->getModel();
522 if (!model) { 529 if (!model) {
523 std::cerr << "Document::addLayerToView: Layer with no model being added to view: normally you want to set the model first" << std::endl; 530 std::cerr << "Document::addLayerToView: Layer (\""
531 << layer->objectName().toStdString()
532 << "\") with no model being added to view: "
533 << "normally you want to set the model first" << std::endl;
524 } else { 534 } else {
525 if (model != m_mainModel && 535 if (model != m_mainModel &&
526 m_models.find(model) == m_models.end()) { 536 m_models.find(model) == m_models.end()) {
527 std::cerr << "ERROR: Document::addLayerToView: Layer " << layer 537 std::cerr << "ERROR: Document::addLayerToView: Layer " << layer
528 << " has unregistered model " << model 538 << " has unregistered model " << model
712 } 722 }
713 723
714 for (ModelMap::const_iterator i = m_models.begin(); 724 for (ModelMap::const_iterator i = m_models.begin();
715 i != m_models.end(); ++i) { 725 i != m_models.end(); ++i) {
716 726
717 i->first->toXml(out, indent + " "); 727 const Model *model = i->first;
718
719 const ModelRecord &rec = i->second; 728 const ModelRecord &rec = i->second;
720 729
721 if (rec.source && rec.transform != "") { 730 // We need an intelligent way to determine which models need
731 // to be streamed (i.e. have been edited, or are small) and
732 // which should not be (i.e. remain as generated by a
733 // transform, and are large).
734 //
735 // At the moment we can get away with deciding not to stream
736 // dense 3d models or writable wave file models, provided they
737 // were generated from a transform, because at the moment there
738 // is no way to edit those model types so it should be safe to
739 // regenerate them. That won't always work in future though.
740 // It would be particularly nice to be able to ask the user,
741 // as well as making an intelligent guess.
742
743 bool writeModel = true;
744 bool haveDerivation = false;
745
746 if (rec.source && rec.transform != "") {
747 haveDerivation = true;
748 }
749
750 if (haveDerivation) {
751 if (dynamic_cast<const WritableWaveFileModel *>(model)) {
752 writeModel = false;
753 } else if (dynamic_cast<const DenseThreeDimensionalModel *>(model)) {
754 writeModel = false;
755 }
756 }
757
758 if (writeModel) {
759 i->first->toXml(out, indent + " ");
760 }
761
762 if (haveDerivation) {
722 763
723 //!!! stream the rest of the execution context in both directions (i.e. not just channel) 764 //!!! stream the rest of the execution context in both directions (i.e. not just channel)
724 765
725 out << indent; 766 out << indent;
726 out << QString(" <derivation source=\"%1\" model=\"%2\" channel=\"%3\" domain=\"%4\" stepSize=\"%5\" blockSize=\"%6\" windowType=\"%7\" transform=\"%8\"") 767 out << QString(" <derivation source=\"%1\" model=\"%2\" channel=\"%3\" domain=\"%4\" stepSize=\"%5\" blockSize=\"%6\" windowType=\"%7\" transform=\"%8\"")