Mercurial > hg > svapp
comparison framework/Document.cpp @ 595:b23bebfdfaba
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | cce97b00663a |
children | 021d42e6c8cb |
comparison
equal
deleted
inserted
replaced
594:72b4870f0e6b | 595:b23bebfdfaba |
---|---|
80 | 80 |
81 #ifdef DEBUG_DOCUMENT | 81 #ifdef DEBUG_DOCUMENT |
82 SVDEBUG << "Document::~Document: about to delete layers" << endl; | 82 SVDEBUG << "Document::~Document: about to delete layers" << endl; |
83 #endif | 83 #endif |
84 while (!m_layers.empty()) { | 84 while (!m_layers.empty()) { |
85 deleteLayer(*m_layers.begin(), true); | 85 deleteLayer(*m_layers.begin(), true); |
86 } | 86 } |
87 | 87 |
88 if (!m_models.empty()) { | 88 if (!m_models.empty()) { |
89 SVDEBUG << "Document::~Document: WARNING: " | 89 SVDEBUG << "Document::~Document: WARNING: " |
90 << m_models.size() << " model(s) still remain -- " | 90 << m_models.size() << " model(s) still remain -- " |
91 << "should have been garbage collected when deleting layers" | 91 << "should have been garbage collected when deleting layers" |
92 << endl; | 92 << endl; |
93 while (!m_models.empty()) { | 93 while (!m_models.empty()) { |
94 Model *model = m_models.begin()->first; | 94 Model *model = m_models.begin()->first; |
95 if (model == m_mainModel) { | 95 if (model == m_mainModel) { |
96 // just in case! | 96 // just in case! |
97 SVDEBUG << "Document::~Document: WARNING: Main model is also" | 97 SVDEBUG << "Document::~Document: WARNING: Main model is also" |
98 << " in models list!" << endl; | 98 << " in models list!" << endl; |
99 } else if (model) { | 99 } else if (model) { |
100 model->aboutToDelete(); | 100 model->aboutToDelete(); |
101 emit modelAboutToBeDeleted(model); | 101 emit modelAboutToBeDeleted(model); |
102 delete model; | 102 delete model; |
103 } | 103 } |
104 m_models.erase(m_models.begin()); | 104 m_models.erase(m_models.begin()); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 #ifdef DEBUG_DOCUMENT | 108 #ifdef DEBUG_DOCUMENT |
109 SVDEBUG << "Document::~Document: About to get rid of main model" | 109 SVDEBUG << "Document::~Document: About to get rid of main model" |
110 << endl; | 110 << endl; |
111 #endif | 111 #endif |
112 if (m_mainModel) { | 112 if (m_mainModel) { |
113 m_mainModel->aboutToDelete(); | 113 m_mainModel->aboutToDelete(); |
114 emit modelAboutToBeDeleted(m_mainModel); | 114 emit modelAboutToBeDeleted(m_mainModel); |
115 } | 115 } |
149 | 149 |
150 Layer * | 150 Layer * |
151 Document::createImportedLayer(Model *model) | 151 Document::createImportedLayer(Model *model) |
152 { | 152 { |
153 LayerFactory::LayerTypeSet types = | 153 LayerFactory::LayerTypeSet types = |
154 LayerFactory::getInstance()->getValidLayerTypes(model); | 154 LayerFactory::getInstance()->getValidLayerTypes(model); |
155 | 155 |
156 if (types.empty()) { | 156 if (types.empty()) { |
157 cerr << "WARNING: Document::importLayer: no valid display layer for model" << endl; | 157 cerr << "WARNING: Document::importLayer: no valid display layer for model" << endl; |
158 return 0; | 158 return 0; |
159 } | 159 } |
160 | 160 |
161 //!!! for now, just use the first suitable layer type | 161 //!!! for now, just use the first suitable layer type |
162 LayerFactory::LayerType type = *types.begin(); | 162 LayerFactory::LayerType type = *types.begin(); |
163 | 163 |
187 Document::createEmptyLayer(LayerFactory::LayerType type) | 187 Document::createEmptyLayer(LayerFactory::LayerType type) |
188 { | 188 { |
189 if (!m_mainModel) return 0; | 189 if (!m_mainModel) return 0; |
190 | 190 |
191 Model *newModel = | 191 Model *newModel = |
192 LayerFactory::getInstance()->createEmptyModel(type, m_mainModel); | 192 LayerFactory::getInstance()->createEmptyModel(type, m_mainModel); |
193 if (!newModel) return 0; | 193 if (!newModel) return 0; |
194 | 194 |
195 Layer *newLayer = createLayer(type); | 195 Layer *newLayer = createLayer(type); |
196 if (!newLayer) { | 196 if (!newLayer) { |
197 delete newModel; | 197 delete newModel; |
198 return 0; | 198 return 0; |
199 } | 199 } |
200 | 200 |
201 addImportedModel(newModel); | 201 addImportedModel(newModel); |
202 setModel(newLayer, newModel); | 202 setModel(newLayer, newModel); |
203 | 203 |
204 return newLayer; | 204 return newLayer; |
205 } | 205 } |
206 | 206 |
207 Layer * | 207 Layer * |
208 Document::createDerivedLayer(LayerFactory::LayerType type, | 208 Document::createDerivedLayer(LayerFactory::LayerType type, |
209 TransformId transform) | 209 TransformId transform) |
210 { | 210 { |
211 Layer *newLayer = createLayer(type); | 211 Layer *newLayer = createLayer(type); |
212 if (!newLayer) return 0; | 212 if (!newLayer) return 0; |
213 | 213 |
214 newLayer->setObjectName(getUniqueLayerName | 214 newLayer->setObjectName(getUniqueLayerName |
442 cerr << "Old main model: " << oldMainModel << endl; | 442 cerr << "Old main model: " << oldMainModel << endl; |
443 #endif | 443 #endif |
444 | 444 |
445 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { | 445 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { |
446 | 446 |
447 Layer *layer = *i; | 447 Layer *layer = *i; |
448 Model *model = layer->getModel(); | 448 Model *model = layer->getModel(); |
449 | 449 |
450 #ifdef DEBUG_DOCUMENT | 450 #ifdef DEBUG_DOCUMENT |
451 cerr << "Document::setMainModel: inspecting model " | 451 cerr << "Document::setMainModel: inspecting model " |
452 << (model ? model->objectName(): "(null)") << " in layer " | 452 << (model ? model->objectName(): "(null)") << " in layer " |
453 << layer->objectName() << endl; | 453 << layer->objectName() << endl; |
454 #endif | 454 #endif |
455 | 455 |
456 if (model == oldMainModel) { | 456 if (model == oldMainModel) { |
457 #ifdef DEBUG_DOCUMENT | 457 #ifdef DEBUG_DOCUMENT |
458 cerr << "... it uses the old main model, replacing" << endl; | 458 cerr << "... it uses the old main model, replacing" << endl; |
459 #endif | 459 #endif |
460 LayerFactory::getInstance()->setModel(layer, m_mainModel); | 460 LayerFactory::getInstance()->setModel(layer, m_mainModel); |
461 continue; | 461 continue; |
462 } | 462 } |
463 | 463 |
464 if (!model) { | 464 if (!model) { |
465 cerr << "WARNING: Document::setMainModel: Null model in layer " | 465 cerr << "WARNING: Document::setMainModel: Null model in layer " |
466 << layer << endl; | 466 << layer << endl; |
467 // get rid of this hideous degenerate | 467 // get rid of this hideous degenerate |
468 obsoleteLayers.push_back(layer); | 468 obsoleteLayers.push_back(layer); |
469 continue; | 469 continue; |
470 } | 470 } |
471 | 471 |
472 if (m_models.find(model) == m_models.end()) { | 472 if (m_models.find(model) == m_models.end()) { |
473 cerr << "WARNING: Document::setMainModel: Unknown model " | 473 cerr << "WARNING: Document::setMainModel: Unknown model " |
474 << model << " in layer " << layer << endl; | 474 << model << " in layer " << layer << endl; |
475 // and this one | 475 // and this one |
476 obsoleteLayers.push_back(layer); | 476 obsoleteLayers.push_back(layer); |
477 continue; | 477 continue; |
478 } | 478 } |
479 | 479 |
480 if (m_models[model].source && | 480 if (m_models[model].source && |
481 (m_models[model].source == oldMainModel)) { | 481 (m_models[model].source == oldMainModel)) { |
482 | 482 |
483 #ifdef DEBUG_DOCUMENT | 483 #ifdef DEBUG_DOCUMENT |
484 cerr << "... it uses a model derived from the old main model, regenerating" << endl; | 484 cerr << "... it uses a model derived from the old main model, regenerating" << endl; |
485 #endif | 485 #endif |
486 | 486 |
487 // This model was derived from the previous main | 487 // This model was derived from the previous main |
488 // model: regenerate it. | 488 // model: regenerate it. |
489 | 489 |
490 const Transform &transform = m_models[model].transform; | 490 const Transform &transform = m_models[model].transform; |
491 QString transformId = transform.getIdentifier(); | 491 QString transformId = transform.getIdentifier(); |
492 | 492 |
493 //!!! We have a problem here if the number of channels in | 493 //!!! We have a problem here if the number of channels in |
494 //the main model has changed. | 494 //the main model has changed. |
495 | 495 |
496 QString message; | 496 QString message; |
497 Model *replacementModel = | 497 Model *replacementModel = |
498 addDerivedModel(transform, | 498 addDerivedModel(transform, |
499 ModelTransformer::Input | 499 ModelTransformer::Input |
500 (m_mainModel, m_models[model].channel), | 500 (m_mainModel, m_models[model].channel), |
501 message); | 501 message); |
502 | 502 |
503 if (!replacementModel) { | 503 if (!replacementModel) { |
504 cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \"" | 504 cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \"" |
505 << transformId << "\"" << " in layer " << layer << endl; | 505 << transformId << "\"" << " in layer " << layer << endl; |
506 if (failedTransformers.find(transformId) | 506 if (failedTransformers.find(transformId) |
507 == failedTransformers.end()) { | 507 == failedTransformers.end()) { |
508 emit modelRegenerationFailed(layer->objectName(), | 508 emit modelRegenerationFailed(layer->objectName(), |
509 transformId, | 509 transformId, |
510 message); | 510 message); |
511 failedTransformers.insert(transformId); | 511 failedTransformers.insert(transformId); |
512 } | 512 } |
513 obsoleteLayers.push_back(layer); | 513 obsoleteLayers.push_back(layer); |
514 } else { | 514 } else { |
515 if (message != "") { | 515 if (message != "") { |
516 emit modelRegenerationWarning(layer->objectName(), | 516 emit modelRegenerationWarning(layer->objectName(), |
517 transformId, | 517 transformId, |
518 message); | 518 message); |
519 } | 519 } |
531 cerr << "new model has " << rm->getChannelCount() << " channels " << endl; | 531 cerr << "new model has " << rm->getChannelCount() << " channels " << endl; |
532 } else { | 532 } else { |
533 cerr << "new model " << replacementModel << " is not a RangeSummarisableTimeValueModel!" << endl; | 533 cerr << "new model " << replacementModel << " is not a RangeSummarisableTimeValueModel!" << endl; |
534 } | 534 } |
535 #endif | 535 #endif |
536 setModel(layer, replacementModel); | 536 setModel(layer, replacementModel); |
537 } | 537 } |
538 } | 538 } |
539 } | 539 } |
540 | 540 |
541 for (size_t k = 0; k < obsoleteLayers.size(); ++k) { | 541 for (size_t k = 0; k < obsoleteLayers.size(); ++k) { |
542 deleteLayer(obsoleteLayers[k], true); | 542 deleteLayer(obsoleteLayers[k], true); |
543 } | 543 } |
544 | 544 |
545 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { | 545 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { |
546 if (i->second.additional) { | 546 if (i->second.additional) { |
547 Model *m = i->first; | 547 Model *m = i->first; |
590 Document::addAlreadyDerivedModel(const Transform &transform, | 590 Document::addAlreadyDerivedModel(const Transform &transform, |
591 const ModelTransformer::Input &input, | 591 const ModelTransformer::Input &input, |
592 Model *outputModelToAdd) | 592 Model *outputModelToAdd) |
593 { | 593 { |
594 if (m_models.find(outputModelToAdd) != m_models.end()) { | 594 if (m_models.find(outputModelToAdd) != m_models.end()) { |
595 cerr << "WARNING: Document::addAlreadyDerivedModel: Model already added" | 595 cerr << "WARNING: Document::addAlreadyDerivedModel: Model already added" |
596 << endl; | 596 << endl; |
597 return; | 597 return; |
598 } | 598 } |
599 | 599 |
600 #ifdef DEBUG_DOCUMENT | 600 #ifdef DEBUG_DOCUMENT |
601 if (input.getModel()) { | 601 if (input.getModel()) { |
602 cerr << "Document::addAlreadyDerivedModel: source is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << endl; | 602 cerr << "Document::addAlreadyDerivedModel: source is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << endl; |
631 | 631 |
632 void | 632 void |
633 Document::addImportedModel(Model *model) | 633 Document::addImportedModel(Model *model) |
634 { | 634 { |
635 if (m_models.find(model) != m_models.end()) { | 635 if (m_models.find(model) != m_models.end()) { |
636 cerr << "WARNING: Document::addImportedModel: Model already added" | 636 cerr << "WARNING: Document::addImportedModel: Model already added" |
637 << endl; | 637 << endl; |
638 return; | 638 return; |
639 } | 639 } |
640 | 640 |
641 ModelRecord rec; | 641 ModelRecord rec; |
642 rec.source = 0; | 642 rec.source = 0; |
643 rec.channel = 0; | 643 rec.channel = 0; |
667 | 667 |
668 void | 668 void |
669 Document::addAdditionalModel(Model *model) | 669 Document::addAdditionalModel(Model *model) |
670 { | 670 { |
671 if (m_models.find(model) != m_models.end()) { | 671 if (m_models.find(model) != m_models.end()) { |
672 cerr << "WARNING: Document::addAdditionalModel: Model already added" | 672 cerr << "WARNING: Document::addAdditionalModel: Model already added" |
673 << endl; | 673 << endl; |
674 return; | 674 return; |
675 } | 675 } |
676 | 676 |
677 ModelRecord rec; | 677 ModelRecord rec; |
678 rec.source = 0; | 678 rec.source = 0; |
679 rec.channel = 0; | 679 rec.channel = 0; |
773 cerr << "WARNING: Document::addDerivedModel: no output model for transform " << applied.getIdentifier() << endl; | 773 cerr << "WARNING: Document::addDerivedModel: no output model for transform " << applied.getIdentifier() << endl; |
774 } else { | 774 } else { |
775 addAlreadyDerivedModel(applied, input, model); | 775 addAlreadyDerivedModel(applied, input, model); |
776 } | 776 } |
777 } | 777 } |
778 | 778 |
779 return mm; | 779 return mm; |
780 } | 780 } |
781 | 781 |
782 void | 782 void |
783 Document::releaseModel(Model *model) // Will _not_ release main model! | 783 Document::releaseModel(Model *model) // Will _not_ release main model! |
784 { | 784 { |
785 if (model == 0) { | 785 if (model == 0) { |
786 return; | 786 return; |
787 } | 787 } |
788 | 788 |
789 if (model == m_mainModel) { | 789 if (model == m_mainModel) { |
790 return; | 790 return; |
791 } | 791 } |
792 | 792 |
793 bool toDelete = false; | 793 bool toDelete = false; |
794 | 794 |
795 if (m_models.find(model) != m_models.end()) { | 795 if (m_models.find(model) != m_models.end()) { |
796 if (m_models[model].refcount == 0) { | 796 if (m_models[model].refcount == 0) { |
797 SVCERR << "WARNING: Document::releaseModel: model " << model | 797 SVCERR << "WARNING: Document::releaseModel: model " << model |
798 << " reference count is zero already!" << endl; | 798 << " reference count is zero already!" << endl; |
799 } else { | 799 } else { |
800 if (--m_models[model].refcount == 0) { | 800 if (--m_models[model].refcount == 0) { |
801 toDelete = true; | 801 toDelete = true; |
802 } | 802 } |
803 } | 803 } |
804 } else if (m_aggregateModels.find(model) != m_aggregateModels.end()) { | 804 } else if (m_aggregateModels.find(model) != m_aggregateModels.end()) { |
805 SVDEBUG << "Document::releaseModel: is an aggregate model" << endl; | 805 SVDEBUG << "Document::releaseModel: is an aggregate model" << endl; |
806 toDelete = true; | 806 toDelete = true; |
807 } else { | 807 } else { |
808 SVCERR << "WARNING: Document::releaseModel: Unfound model " | 808 SVCERR << "WARNING: Document::releaseModel: Unfound model " |
809 << model << endl; | 809 << model << endl; |
810 toDelete = true; | 810 toDelete = true; |
811 } | 811 } |
812 | 812 |
813 if (toDelete) { | 813 if (toDelete) { |
814 | 814 |
815 int sourceCount = 0; | 815 int sourceCount = 0; |
816 | 816 |
817 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { | 817 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { |
818 if (i->second.source == model) { | 818 if (i->second.source == model) { |
819 ++sourceCount; | 819 ++sourceCount; |
820 i->second.source = 0; | 820 i->second.source = 0; |
821 } | 821 } |
822 } | 822 } |
823 | 823 |
824 if (sourceCount > 0) { | 824 if (sourceCount > 0) { |
825 SVDEBUG << "Document::releaseModel: Deleting model " | 825 SVDEBUG << "Document::releaseModel: Deleting model " |
826 << model << " even though it is source for " | 826 << model << " even though it is source for " |
827 << sourceCount << " other derived model(s) -- resetting " | 827 << sourceCount << " other derived model(s) -- resetting " |
828 << "their source fields appropriately" << endl; | 828 << "their source fields appropriately" << endl; |
829 } | 829 } |
830 | 830 |
831 model->aboutToDelete(); | 831 model->aboutToDelete(); |
832 emit modelAboutToBeDeleted(model); | 832 emit modelAboutToBeDeleted(model); |
833 m_models.erase(model); | 833 m_models.erase(model); |
834 | 834 |
835 #ifdef DEBUG_DOCUMENT | 835 #ifdef DEBUG_DOCUMENT |
836 SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; | 836 SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; |
837 cerr << "Models now: "; | 837 cerr << "Models now: "; |
838 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { | 838 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { |
839 cerr << i->first << " "; | 839 cerr << i->first << " "; |
840 } | 840 } |
841 cerr << endl; | 841 cerr << endl; |
842 #endif | 842 #endif |
843 | 843 |
844 delete model; | 844 delete model; |
845 } | 845 } |
846 } | 846 } |
847 | 847 |
848 void | 848 void |
849 Document::deleteLayer(Layer *layer, bool force) | 849 Document::deleteLayer(Layer *layer, bool force) |
850 { | 850 { |
851 if (m_layerViewMap.find(layer) != m_layerViewMap.end() && | 851 if (m_layerViewMap.find(layer) != m_layerViewMap.end() && |
852 m_layerViewMap[layer].size() > 0) { | 852 m_layerViewMap[layer].size() > 0) { |
853 | 853 |
854 cerr << "WARNING: Document::deleteLayer: Layer " | 854 cerr << "WARNING: Document::deleteLayer: Layer " |
855 << layer << " [" << layer->objectName() << "]" | 855 << layer << " [" << layer->objectName() << "]" |
856 << " is still used in " << m_layerViewMap[layer].size() | 856 << " is still used in " << m_layerViewMap[layer].size() |
857 << " views!" << endl; | 857 << " views!" << endl; |
858 | 858 |
859 if (force) { | 859 if (force) { |
860 | 860 |
861 #ifdef DEBUG_DOCUMENT | 861 #ifdef DEBUG_DOCUMENT |
862 cerr << "(force flag set -- deleting from all views)" << endl; | 862 cerr << "(force flag set -- deleting from all views)" << endl; |
863 #endif | 863 #endif |
864 | 864 |
865 for (std::set<View *>::iterator j = m_layerViewMap[layer].begin(); | 865 for (std::set<View *>::iterator j = m_layerViewMap[layer].begin(); |
866 j != m_layerViewMap[layer].end(); ++j) { | 866 j != m_layerViewMap[layer].end(); ++j) { |
867 // don't use removeLayerFromView, as it issues a command | 867 // don't use removeLayerFromView, as it issues a command |
868 layer->setLayerDormant(*j, true); | 868 layer->setLayerDormant(*j, true); |
869 (*j)->removeLayer(layer); | 869 (*j)->removeLayer(layer); |
870 } | 870 } |
871 | 871 |
872 m_layerViewMap.erase(layer); | 872 m_layerViewMap.erase(layer); |
873 | 873 |
874 } else { | 874 } else { |
875 return; | 875 return; |
876 } | 876 } |
877 } | 877 } |
878 | 878 |
879 if (m_layers.find(layer) == m_layers.end()) { | 879 if (m_layers.find(layer) == m_layers.end()) { |
880 SVDEBUG << "Document::deleteLayer: Layer " | 880 SVDEBUG << "Document::deleteLayer: Layer " |
881 << layer << " (" << typeid(layer).name() << | 881 << layer << " (" << typeid(layer).name() << |
882 ") does not exist, or has already been deleted " | 882 ") does not exist, or has already been deleted " |
883 << "(this may not be as serious as it sounds)" << endl; | 883 << "(this may not be as serious as it sounds)" << endl; |
884 return; | 884 return; |
885 } | 885 } |
886 | 886 |
887 m_layers.erase(layer); | 887 m_layers.erase(layer); |
888 | 888 |
889 #ifdef DEBUG_DOCUMENT | 889 #ifdef DEBUG_DOCUMENT |
899 | 899 |
900 void | 900 void |
901 Document::setModel(Layer *layer, Model *model) | 901 Document::setModel(Layer *layer, Model *model) |
902 { | 902 { |
903 if (model && | 903 if (model && |
904 model != m_mainModel && | 904 model != m_mainModel && |
905 m_models.find(model) == m_models.end()) { | 905 m_models.find(model) == m_models.end()) { |
906 cerr << "ERROR: Document::setModel: Layer " << layer | 906 cerr << "ERROR: Document::setModel: Layer " << layer |
907 << " (\"" << layer->objectName() | 907 << " (\"" << layer->objectName() |
908 << "\") wants to use unregistered model " << model | 908 << "\") wants to use unregistered model " << model |
909 << ": register the layer's model before setting it!" | 909 << ": register the layer's model before setting it!" |
910 << endl; | 910 << endl; |
911 return; | 911 return; |
912 } | 912 } |
913 | 913 |
914 Model *previousModel = layer->getModel(); | 914 Model *previousModel = layer->getModel(); |
915 | 915 |
916 if (previousModel == model) { | 916 if (previousModel == model) { |
921 << "\")" << endl; | 921 << "\")" << endl; |
922 return; | 922 return; |
923 } | 923 } |
924 | 924 |
925 if (model && model != m_mainModel) { | 925 if (model && model != m_mainModel) { |
926 m_models[model].refcount ++; | 926 m_models[model].refcount ++; |
927 } | 927 } |
928 | 928 |
929 if (model && previousModel) { | 929 if (model && previousModel) { |
930 PlayParameterRepository::getInstance()->copyParameters | 930 PlayParameterRepository::getInstance()->copyParameters |
931 (previousModel, model); | 931 (previousModel, model); |
932 } | 932 } |
933 | 933 |
934 LayerFactory::getInstance()->setModel(layer, model); | 934 LayerFactory::getInstance()->setModel(layer, model); |
935 // std::cerr << "layer type: " << LayerFactory::getInstance()->getLayerTypeName(LayerFactory::getInstance()->getLayerType(layer)) << std::endl; | 935 // std::cerr << "layer type: " << LayerFactory::getInstance()->getLayerTypeName(LayerFactory::getInstance()->getLayerType(layer)) << std::endl; |
936 | 936 |
937 if (previousModel) { | 937 if (previousModel) { |
938 releaseModel(previousModel); | 938 releaseModel(previousModel); |
939 } | 939 } |
940 } | 940 } |
949 Document::addLayerToView(View *view, Layer *layer) | 949 Document::addLayerToView(View *view, Layer *layer) |
950 { | 950 { |
951 Model *model = layer->getModel(); | 951 Model *model = layer->getModel(); |
952 if (!model) { | 952 if (!model) { |
953 #ifdef DEBUG_DOCUMENT | 953 #ifdef DEBUG_DOCUMENT |
954 SVDEBUG << "Document::addLayerToView: Layer (\"" | 954 SVDEBUG << "Document::addLayerToView: Layer (\"" |
955 << layer->objectName() << "\") with no model being added to view: " | 955 << layer->objectName() << "\") with no model being added to view: " |
956 << "normally you want to set the model first" << endl; | 956 << "normally you want to set the model first" << endl; |
957 #endif | 957 #endif |
958 } else { | 958 } else { |
959 if (model != m_mainModel && | 959 if (model != m_mainModel && |
960 m_models.find(model) == m_models.end()) { | 960 m_models.find(model) == m_models.end()) { |
961 cerr << "ERROR: Document::addLayerToView: Layer " << layer | 961 cerr << "ERROR: Document::addLayerToView: Layer " << layer |
962 << " has unregistered model " << model | 962 << " has unregistered model " << model |
963 << " -- register the layer's model before adding the layer!" << endl; | 963 << " -- register the layer's model before adding the layer!" << endl; |
964 return; | 964 return; |
965 } | 965 } |
966 } | 966 } |
967 | 967 |
968 CommandHistory::getInstance()->addCommand | 968 CommandHistory::getInstance()->addCommand |
969 (new Document::AddLayerCommand(this, view, layer)); | 969 (new Document::AddLayerCommand(this, view, layer)); |
970 } | 970 } |
971 | 971 |
972 void | 972 void |
973 Document::removeLayerFromView(View *view, Layer *layer) | 973 Document::removeLayerFromView(View *view, Layer *layer) |
974 { | 974 { |
975 CommandHistory::getInstance()->addCommand | 975 CommandHistory::getInstance()->addCommand |
976 (new Document::RemoveLayerCommand(this, view, layer)); | 976 (new Document::RemoveLayerCommand(this, view, layer)); |
977 } | 977 } |
978 | 978 |
979 void | 979 void |
980 Document::addToLayerViewMap(Layer *layer, View *view) | 980 Document::addToLayerViewMap(Layer *layer, View *view) |
981 { | 981 { |
982 bool firstView = (m_layerViewMap.find(layer) == m_layerViewMap.end() || | 982 bool firstView = (m_layerViewMap.find(layer) == m_layerViewMap.end() || |
983 m_layerViewMap[layer].empty()); | 983 m_layerViewMap[layer].empty()); |
984 | 984 |
985 if (m_layerViewMap[layer].find(view) != | 985 if (m_layerViewMap[layer].find(view) != |
986 m_layerViewMap[layer].end()) { | 986 m_layerViewMap[layer].end()) { |
987 cerr << "WARNING: Document::addToLayerViewMap:" | 987 cerr << "WARNING: Document::addToLayerViewMap:" |
988 << " Layer " << layer << " -> view " << view << " already in" | 988 << " Layer " << layer << " -> view " << view << " already in" |
989 << " layer view map -- internal inconsistency" << endl; | 989 << " layer view map -- internal inconsistency" << endl; |
990 } | 990 } |
991 | 991 |
992 m_layerViewMap[layer].insert(view); | 992 m_layerViewMap[layer].insert(view); |
993 | 993 |
994 if (firstView) emit layerInAView(layer, true); | 994 if (firstView) emit layerInAView(layer, true); |
996 | 996 |
997 void | 997 void |
998 Document::removeFromLayerViewMap(Layer *layer, View *view) | 998 Document::removeFromLayerViewMap(Layer *layer, View *view) |
999 { | 999 { |
1000 if (m_layerViewMap[layer].find(view) == | 1000 if (m_layerViewMap[layer].find(view) == |
1001 m_layerViewMap[layer].end()) { | 1001 m_layerViewMap[layer].end()) { |
1002 cerr << "WARNING: Document::removeFromLayerViewMap:" | 1002 cerr << "WARNING: Document::removeFromLayerViewMap:" |
1003 << " Layer " << layer << " -> view " << view << " not in" | 1003 << " Layer " << layer << " -> view " << view << " not in" |
1004 << " layer view map -- internal inconsistency" << endl; | 1004 << " layer view map -- internal inconsistency" << endl; |
1005 } | 1005 } |
1006 | 1006 |
1007 m_layerViewMap[layer].erase(view); | 1007 m_layerViewMap[layer].erase(view); |
1008 | 1008 |
1009 if (m_layerViewMap[layer].empty()) { | 1009 if (m_layerViewMap[layer].empty()) { |
1118 } | 1118 } |
1119 alignModel(m_mainModel); | 1119 alignModel(m_mainModel); |
1120 } | 1120 } |
1121 | 1121 |
1122 Document::AddLayerCommand::AddLayerCommand(Document *d, | 1122 Document::AddLayerCommand::AddLayerCommand(Document *d, |
1123 View *view, | 1123 View *view, |
1124 Layer *layer) : | 1124 Layer *layer) : |
1125 m_d(d), | 1125 m_d(d), |
1126 m_view(view), | 1126 m_view(view), |
1127 m_layer(layer), | 1127 m_layer(layer), |
1128 m_name(qApp->translate("AddLayerCommand", "Add %1 Layer").arg(layer->objectName())), | 1128 m_name(qApp->translate("AddLayerCommand", "Add %1 Layer").arg(layer->objectName())), |
1129 m_added(false) | 1129 m_added(false) |
1134 { | 1134 { |
1135 #ifdef DEBUG_DOCUMENT | 1135 #ifdef DEBUG_DOCUMENT |
1136 SVDEBUG << "Document::AddLayerCommand::~AddLayerCommand" << endl; | 1136 SVDEBUG << "Document::AddLayerCommand::~AddLayerCommand" << endl; |
1137 #endif | 1137 #endif |
1138 if (!m_added) { | 1138 if (!m_added) { |
1139 m_d->deleteLayer(m_layer); | 1139 m_d->deleteLayer(m_layer); |
1140 } | 1140 } |
1141 } | 1141 } |
1142 | 1142 |
1143 QString | 1143 QString |
1144 Document::AddLayerCommand::getName() const | 1144 Document::AddLayerCommand::getName() const |
1152 | 1152 |
1153 void | 1153 void |
1154 Document::AddLayerCommand::execute() | 1154 Document::AddLayerCommand::execute() |
1155 { | 1155 { |
1156 for (int i = 0; i < m_view->getLayerCount(); ++i) { | 1156 for (int i = 0; i < m_view->getLayerCount(); ++i) { |
1157 if (m_view->getLayer(i) == m_layer) { | 1157 if (m_view->getLayer(i) == m_layer) { |
1158 // already there | 1158 // already there |
1159 m_layer->setLayerDormant(m_view, false); | 1159 m_layer->setLayerDormant(m_view, false); |
1160 m_added = true; | 1160 m_added = true; |
1161 return; | 1161 return; |
1162 } | 1162 } |
1163 } | 1163 } |
1164 | 1164 |
1165 m_view->addLayer(m_layer); | 1165 m_view->addLayer(m_layer); |
1166 m_layer->setLayerDormant(m_view, false); | 1166 m_layer->setLayerDormant(m_view, false); |
1167 | 1167 |
1178 m_d->removeFromLayerViewMap(m_layer, m_view); | 1178 m_d->removeFromLayerViewMap(m_layer, m_view); |
1179 m_added = false; | 1179 m_added = false; |
1180 } | 1180 } |
1181 | 1181 |
1182 Document::RemoveLayerCommand::RemoveLayerCommand(Document *d, | 1182 Document::RemoveLayerCommand::RemoveLayerCommand(Document *d, |
1183 View *view, | 1183 View *view, |
1184 Layer *layer) : | 1184 Layer *layer) : |
1185 m_d(d), | 1185 m_d(d), |
1186 m_view(view), | 1186 m_view(view), |
1187 m_layer(layer), | 1187 m_layer(layer), |
1188 m_wasDormant(layer->isLayerDormant(view)), | 1188 m_wasDormant(layer->isLayerDormant(view)), |
1189 m_name(qApp->translate("RemoveLayerCommand", "Delete %1 Layer").arg(layer->objectName())), | 1189 m_name(qApp->translate("RemoveLayerCommand", "Delete %1 Layer").arg(layer->objectName())), |
1195 { | 1195 { |
1196 #ifdef DEBUG_DOCUMENT | 1196 #ifdef DEBUG_DOCUMENT |
1197 SVDEBUG << "Document::RemoveLayerCommand::~RemoveLayerCommand" << endl; | 1197 SVDEBUG << "Document::RemoveLayerCommand::~RemoveLayerCommand" << endl; |
1198 #endif | 1198 #endif |
1199 if (!m_added) { | 1199 if (!m_added) { |
1200 m_d->deleteLayer(m_layer); | 1200 m_d->deleteLayer(m_layer); |
1201 } | 1201 } |
1202 } | 1202 } |
1203 | 1203 |
1204 QString | 1204 QString |
1205 Document::RemoveLayerCommand::getName() const | 1205 Document::RemoveLayerCommand::getName() const |
1214 void | 1214 void |
1215 Document::RemoveLayerCommand::execute() | 1215 Document::RemoveLayerCommand::execute() |
1216 { | 1216 { |
1217 bool have = false; | 1217 bool have = false; |
1218 for (int i = 0; i < m_view->getLayerCount(); ++i) { | 1218 for (int i = 0; i < m_view->getLayerCount(); ++i) { |
1219 if (m_view->getLayer(i) == m_layer) { | 1219 if (m_view->getLayer(i) == m_layer) { |
1220 have = true; | 1220 have = true; |
1221 break; | 1221 break; |
1222 } | 1222 } |
1223 } | 1223 } |
1224 | 1224 |
1225 if (!have) { // not there! | 1225 if (!have) { // not there! |
1226 m_layer->setLayerDormant(m_view, true); | 1226 m_layer->setLayerDormant(m_view, true); |
1227 m_added = false; | 1227 m_added = false; |
1228 return; | 1228 return; |
1229 } | 1229 } |
1230 | 1230 |
1231 m_view->removeLayer(m_layer); | 1231 m_view->removeLayer(m_layer); |
1232 m_layer->setLayerDormant(m_view, true); | 1232 m_layer->setLayerDormant(m_view, true); |
1233 | 1233 |
1323 } | 1323 } |
1324 | 1324 |
1325 std::set<Model *> written; | 1325 std::set<Model *> written; |
1326 | 1326 |
1327 for (ModelMap::const_iterator i = m_models.begin(); | 1327 for (ModelMap::const_iterator i = m_models.begin(); |
1328 i != m_models.end(); ++i) { | 1328 i != m_models.end(); ++i) { |
1329 | 1329 |
1330 Model *model = i->first; | 1330 Model *model = i->first; |
1331 const ModelRecord &rec = i->second; | 1331 const ModelRecord &rec = i->second; |
1332 | 1332 |
1333 if (used.find(model) == used.end()) continue; | 1333 if (used.find(model) == used.end()) continue; |
1334 | 1334 |
1335 // We need an intelligent way to determine which models need | 1335 // We need an intelligent way to determine which models need |
1336 // to be streamed (i.e. have been edited, or are small) and | 1336 // to be streamed (i.e. have been edited, or are small) and |
1363 if (writeModel) { | 1363 if (writeModel) { |
1364 model->toXml(out, indent + " "); | 1364 model->toXml(out, indent + " "); |
1365 written.insert(model); | 1365 written.insert(model); |
1366 } | 1366 } |
1367 | 1367 |
1368 if (haveDerivation) { | 1368 if (haveDerivation) { |
1369 writeBackwardCompatibleDerivation(out, indent + " ", | 1369 writeBackwardCompatibleDerivation(out, indent + " ", |
1370 model, rec); | 1370 model, rec); |
1371 } | 1371 } |
1372 | 1372 |
1373 //!!! We should probably own the PlayParameterRepository | 1373 //!!! We should probably own the PlayParameterRepository |
1374 PlayParameters *playParameters = | 1374 PlayParameters *playParameters = |
1375 PlayParameterRepository::getInstance()->getPlayParameters(model); | 1375 PlayParameterRepository::getInstance()->getPlayParameters(model); |
1376 if (playParameters) { | 1376 if (playParameters) { |
1388 // and aligned models, and then streams its path model. Note that | 1388 // and aligned models, and then streams its path model. Note that |
1389 // this will only work when the alignment is complete, so we | 1389 // this will only work when the alignment is complete, so we |
1390 // should probably wait for it if it isn't already by this point. | 1390 // should probably wait for it if it isn't already by this point. |
1391 | 1391 |
1392 for (std::set<Model *>::const_iterator i = written.begin(); | 1392 for (std::set<Model *>::const_iterator i = written.begin(); |
1393 i != written.end(); ++i) { | 1393 i != written.end(); ++i) { |
1394 | 1394 |
1395 const Model *model = *i; | 1395 const Model *model = *i; |
1396 const AlignmentModel *alignment = model->getAlignment(); | 1396 const AlignmentModel *alignment = model->getAlignment(); |
1397 if (!alignment) continue; | 1397 if (!alignment) continue; |
1398 | 1398 |
1399 alignment->toXml(out, indent + " "); | 1399 alignment->toXml(out, indent + " "); |
1400 } | 1400 } |
1401 | 1401 |
1402 for (LayerSet::const_iterator i = m_layers.begin(); | 1402 for (LayerSet::const_iterator i = m_layers.begin(); |
1403 i != m_layers.end(); ++i) { | 1403 i != m_layers.end(); ++i) { |
1404 | 1404 |
1405 (*i)->toXml(out, indent + " "); | 1405 (*i)->toXml(out, indent + " "); |
1406 } | 1406 } |
1407 | 1407 |
1408 out << indent + "</data>\n"; | 1408 out << indent + "</data>\n"; |
1409 } | 1409 } |
1410 | 1410 |
1469 .arg(RealTime::realTime2Frame(transform.getStartTime(), | 1469 .arg(RealTime::realTime2Frame(transform.getStartTime(), |
1470 targetModel->getSampleRate())) | 1470 targetModel->getSampleRate())) |
1471 .arg(RealTime::realTime2Frame(transform.getDuration(), | 1471 .arg(RealTime::realTime2Frame(transform.getDuration(), |
1472 targetModel->getSampleRate())); | 1472 targetModel->getSampleRate())); |
1473 } | 1473 } |
1474 | 1474 |
1475 out << indent; | 1475 out << indent; |
1476 out << QString("<derivation type=\"transform\" source=\"%1\" " | 1476 out << QString("<derivation type=\"transform\" source=\"%1\" " |
1477 "model=\"%2\" channel=\"%3\" domain=\"%4\" " | 1477 "model=\"%2\" channel=\"%3\" domain=\"%4\" " |
1478 "stepSize=\"%5\" blockSize=\"%6\" %7windowType=\"%8\" " | 1478 "stepSize=\"%5\" blockSize=\"%6\" %7windowType=\"%8\" " |
1479 "transform=\"%9\">\n") | 1479 "transform=\"%9\">\n") |