comparison framework/Document.cpp @ 86:dd74c5332b49

* More work on aligning copy/paste between layers. It's a surprisingly complicated business.
author Chris Cannam
date Wed, 06 Feb 2008 12:49:49 +0000
parents c60bf8995166
children db267a315058
comparison
equal deleted inserted replaced
85:40d0c964ad24 86:dd74c5332b49
368 for (size_t k = 0; k < obsoleteLayers.size(); ++k) { 368 for (size_t k = 0; k < obsoleteLayers.size(); ++k) {
369 deleteLayer(obsoleteLayers[k], true); 369 deleteLayer(obsoleteLayers[k], true);
370 } 370 }
371 371
372 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { 372 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) {
373 if (oldMainModel && 373
374 (i->first->getAlignmentReference() == oldMainModel)) { 374 if (m_autoAlignment) {
375
376 alignModel(i->first);
377
378 } else if (oldMainModel &&
379 (i->first->getAlignmentReference() == oldMainModel)) {
380
375 alignModel(i->first); 381 alignModel(i->first);
376 } 382 }
377 } 383 }
378 384
379 if (oldMainModel) { 385 if (oldMainModel) {
380 oldMainModel->aboutToDelete(); 386 oldMainModel->aboutToDelete();
381 emit modelAboutToBeDeleted(oldMainModel); 387 emit modelAboutToBeDeleted(oldMainModel);
388 }
389
390 if (m_autoAlignment) {
391 alignModel(m_mainModel);
382 } 392 }
383 393
384 emit mainModelChanged(m_mainModel); 394 emit mainModelChanged(m_mainModel);
385 395
386 delete oldMainModel; 396 delete oldMainModel;
758 } 768 }
759 769
760 void 770 void
761 Document::alignModel(Model *model) 771 Document::alignModel(Model *model)
762 { 772 {
763 if (!m_mainModel || model == m_mainModel) return; 773 if (!m_mainModel) return;
764 774
765 RangeSummarisableTimeValueModel *rm = 775 RangeSummarisableTimeValueModel *rm =
766 dynamic_cast<RangeSummarisableTimeValueModel *>(model); 776 dynamic_cast<RangeSummarisableTimeValueModel *>(model);
767 if (!rm) return; 777 if (!rm) return;
768 778
769 if (rm->getAlignmentReference() == m_mainModel) return; 779 if (rm->getAlignmentReference() == m_mainModel) {
780 std::cerr << "Document::alignModel: model " << rm << " is already aligned to main model " << m_mainModel << std::endl;
781 return;
782 }
770 783
784 if (model == m_mainModel) {
785 // The reference has an empty alignment to itself. This makes
786 // it possible to distinguish between the reference and any
787 // unaligned model just by looking at the model itself,
788 // without also knowing what the main model is
789 std::cerr << "Document::alignModel(" << model << "): is main model, setting appropriately" << std::endl;
790 rm->setAlignment(new AlignmentModel(model, model, 0, 0));
791 return;
792 }
793
771 // This involves creating three new models: 794 // This involves creating three new models:
772 795
773 // 1. an AggregateWaveModel to provide the mixdowns of the main 796 // 1. an AggregateWaveModel to provide the mixdowns of the main
774 // model and the new model in its two channels, as input to the 797 // model and the new model in its two channels, as input to the
775 // MATCH plugin 798 // MATCH plugin
843 Document::alignModels() 866 Document::alignModels()
844 { 867 {
845 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { 868 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) {
846 alignModel(i->first); 869 alignModel(i->first);
847 } 870 }
871 alignModel(m_mainModel);
848 } 872 }
849 873
850 Document::AddLayerCommand::AddLayerCommand(Document *d, 874 Document::AddLayerCommand::AddLayerCommand(Document *d,
851 View *view, 875 View *view,
852 Layer *layer) : 876 Layer *layer) :