comparison framework/Document.cpp @ 295:14b1768e5406 tonioni

Merge from default branch
author Chris Cannam
date Tue, 26 Nov 2013 14:39:57 +0000
parents 94bf7d7f2d6f 933b5aed341a
children 19282182e60d
comparison
equal deleted inserted replaced
292:bc78f88a66f5 295:14b1768e5406
59 //!!! Document should really own the command history. atm we 59 //!!! Document should really own the command history. atm we
60 //still refer to it in various places that don't have access to 60 //still refer to it in various places that don't have access to
61 //the document, be nice to fix that 61 //the document, be nice to fix that
62 62
63 #ifdef DEBUG_DOCUMENT 63 #ifdef DEBUG_DOCUMENT
64 std::cerr << "\n\nDocument::~Document: about to clear command history" << std::endl; 64 cerr << "\n\nDocument::~Document: about to clear command history" << endl;
65 #endif 65 #endif
66 CommandHistory::getInstance()->clear(); 66 CommandHistory::getInstance()->clear();
67 67
68 #ifdef DEBUG_DOCUMENT 68 #ifdef DEBUG_DOCUMENT
69 SVDEBUG << "Document::~Document: about to delete layers" << endl; 69 SVDEBUG << "Document::~Document: about to delete layers" << endl;
140 { 140 {
141 LayerFactory::LayerTypeSet types = 141 LayerFactory::LayerTypeSet types =
142 LayerFactory::getInstance()->getValidLayerTypes(model); 142 LayerFactory::getInstance()->getValidLayerTypes(model);
143 143
144 if (types.empty()) { 144 if (types.empty()) {
145 std::cerr << "WARNING: Document::importLayer: no valid display layer for model" << std::endl; 145 cerr << "WARNING: Document::importLayer: no valid display layer for model" << endl;
146 return 0; 146 return 0;
147 } 147 }
148 148
149 //!!! for now, just use the first suitable layer type 149 //!!! for now, just use the first suitable layer type
150 LayerFactory::LayerType type = *types.begin(); 150 LayerFactory::LayerType type = *types.begin();
220 220
221 LayerFactory::LayerTypeSet types = 221 LayerFactory::LayerTypeSet types =
222 LayerFactory::getInstance()->getValidLayerTypes(newModel); 222 LayerFactory::getInstance()->getValidLayerTypes(newModel);
223 223
224 if (types.empty()) { 224 if (types.empty()) {
225 std::cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << std::endl; 225 cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << endl;
226 newModel->aboutToDelete(); 226 newModel->aboutToDelete();
227 emit modelAboutToBeDeleted(newModel); 227 emit modelAboutToBeDeleted(newModel);
228 m_models.erase(newModel); 228 m_models.erase(newModel);
229 delete newModel; 229 delete newModel;
230 return 0; 230 return 0;
343 // model, or delete the layer for each layer that is currently 343 // model, or delete the layer for each layer that is currently
344 // using one of these. Carry out this replacement before we 344 // using one of these. Carry out this replacement before we
345 // delete any of the models. 345 // delete any of the models.
346 346
347 #ifdef DEBUG_DOCUMENT 347 #ifdef DEBUG_DOCUMENT
348 std::cerr << "Document::setMainModel: Have " 348 cerr << "Document::setMainModel: Have "
349 << m_layers.size() << " layers" << std::endl; 349 << m_layers.size() << " layers" << endl;
350 std::cerr << "Models now: "; 350 cerr << "Models now: ";
351 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { 351 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) {
352 std::cerr << i->first << " "; 352 cerr << i->first << " ";
353 } 353 }
354 std::cerr << std::endl; 354 cerr << endl;
355 std::cerr << "Old main model: " << oldMainModel << std::endl; 355 cerr << "Old main model: " << oldMainModel << endl;
356 #endif 356 #endif
357 357
358 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 358 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
359 359
360 Layer *layer = *i; 360 Layer *layer = *i;
361 Model *model = layer->getModel(); 361 Model *model = layer->getModel();
362 362
363 #ifdef DEBUG_DOCUMENT 363 #ifdef DEBUG_DOCUMENT
364 std::cerr << "Document::setMainModel: inspecting model " 364 cerr << "Document::setMainModel: inspecting model "
365 << (model ? model->objectName(): "(null)") << " in layer " 365 << (model ? model->objectName(): "(null)") << " in layer "
366 << layer->objectName() << std::endl; 366 << layer->objectName() << endl;
367 #endif 367 #endif
368 368
369 if (model == oldMainModel) { 369 if (model == oldMainModel) {
370 #ifdef DEBUG_DOCUMENT 370 #ifdef DEBUG_DOCUMENT
371 std::cerr << "... it uses the old main model, replacing" << std::endl; 371 cerr << "... it uses the old main model, replacing" << endl;
372 #endif 372 #endif
373 LayerFactory::getInstance()->setModel(layer, m_mainModel); 373 LayerFactory::getInstance()->setModel(layer, m_mainModel);
374 continue; 374 continue;
375 } 375 }
376 376
377 if (!model) { 377 if (!model) {
378 std::cerr << "WARNING: Document::setMainModel: Null model in layer " 378 cerr << "WARNING: Document::setMainModel: Null model in layer "
379 << layer << std::endl; 379 << layer << endl;
380 // get rid of this hideous degenerate 380 // get rid of this hideous degenerate
381 obsoleteLayers.push_back(layer); 381 obsoleteLayers.push_back(layer);
382 continue; 382 continue;
383 } 383 }
384 384
385 if (m_models.find(model) == m_models.end()) { 385 if (m_models.find(model) == m_models.end()) {
386 std::cerr << "WARNING: Document::setMainModel: Unknown model " 386 cerr << "WARNING: Document::setMainModel: Unknown model "
387 << model << " in layer " << layer << std::endl; 387 << model << " in layer " << layer << endl;
388 // and this one 388 // and this one
389 obsoleteLayers.push_back(layer); 389 obsoleteLayers.push_back(layer);
390 continue; 390 continue;
391 } 391 }
392 392
393 if (m_models[model].source && 393 if (m_models[model].source &&
394 (m_models[model].source == oldMainModel)) { 394 (m_models[model].source == oldMainModel)) {
395 395
396 #ifdef DEBUG_DOCUMENT 396 #ifdef DEBUG_DOCUMENT
397 std::cerr << "... it uses a model derived from the old main model, regenerating" << std::endl; 397 cerr << "... it uses a model derived from the old main model, regenerating" << endl;
398 #endif 398 #endif
399 399
400 // This model was derived from the previous main 400 // This model was derived from the previous main
401 // model: regenerate it. 401 // model: regenerate it.
402 402
412 ModelTransformer::Input 412 ModelTransformer::Input
413 (m_mainModel, m_models[model].channel), 413 (m_mainModel, m_models[model].channel),
414 message); 414 message);
415 415
416 if (!replacementModel) { 416 if (!replacementModel) {
417 std::cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \"" 417 cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \""
418 << transformId << "\"" << " in layer " << layer << std::endl; 418 << transformId << "\"" << " in layer " << layer << endl;
419 if (failedTransformers.find(transformId) 419 if (failedTransformers.find(transformId)
420 == failedTransformers.end()) { 420 == failedTransformers.end()) {
421 emit modelRegenerationFailed(layer->objectName(), 421 emit modelRegenerationFailed(layer->objectName(),
422 transformId, 422 transformId,
423 message); 423 message);
429 emit modelRegenerationWarning(layer->objectName(), 429 emit modelRegenerationWarning(layer->objectName(),
430 transformId, 430 transformId,
431 message); 431 message);
432 } 432 }
433 #ifdef DEBUG_DOCUMENT 433 #ifdef DEBUG_DOCUMENT
434 std::cerr << "Replacing model " << model << " (type " 434 cerr << "Replacing model " << model << " (type "
435 << typeid(*model).name() << ") with model " 435 << typeid(*model).name() << ") with model "
436 << replacementModel << " (type " 436 << replacementModel << " (type "
437 << typeid(*replacementModel).name() << ") in layer " 437 << typeid(*replacementModel).name() << ") in layer "
438 << layer << " (name " << layer->objectName() << ")" 438 << layer << " (name " << layer->objectName() << ")"
439 << std::endl; 439 << endl;
440 #endif 440 #endif
441 RangeSummarisableTimeValueModel *rm = 441 RangeSummarisableTimeValueModel *rm =
442 dynamic_cast<RangeSummarisableTimeValueModel *>(replacementModel); 442 dynamic_cast<RangeSummarisableTimeValueModel *>(replacementModel);
443 #ifdef DEBUG_DOCUMENT 443 #ifdef DEBUG_DOCUMENT
444 if (rm) { 444 if (rm) {
445 std::cerr << "new model has " << rm->getChannelCount() << " channels " << std::endl; 445 cerr << "new model has " << rm->getChannelCount() << " channels " << endl;
446 } else { 446 } else {
447 std::cerr << "new model " << replacementModel << " is not a RangeSummarisableTimeValueModel!" << std::endl; 447 cerr << "new model " << replacementModel << " is not a RangeSummarisableTimeValueModel!" << endl;
448 } 448 }
449 #endif 449 #endif
450 setModel(layer, replacementModel); 450 setModel(layer, replacementModel);
451 } 451 }
452 } 452 }
494 Document::addDerivedModel(const Transform &transform, 494 Document::addDerivedModel(const Transform &transform,
495 const ModelTransformer::Input &input, 495 const ModelTransformer::Input &input,
496 Model *outputModelToAdd) 496 Model *outputModelToAdd)
497 { 497 {
498 if (m_models.find(outputModelToAdd) != m_models.end()) { 498 if (m_models.find(outputModelToAdd) != m_models.end()) {
499 std::cerr << "WARNING: Document::addDerivedModel: Model already added" 499 cerr << "WARNING: Document::addDerivedModel: Model already added"
500 << std::endl; 500 << endl;
501 return; 501 return;
502 } 502 }
503 503
504 #ifdef DEBUG_DOCUMENT 504 #ifdef DEBUG_DOCUMENT
505 if (input.getModel()) { 505 if (input.getModel()) {
506 std::cerr << "Document::addDerivedModel: source is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << std::endl; 506 cerr << "Document::addDerivedModel: source is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << endl;
507 } else { 507 } else {
508 std::cerr << "Document::addDerivedModel: source is " << input.getModel() << std::endl; 508 cerr << "Document::addDerivedModel: source is " << input.getModel() << endl;
509 } 509 }
510 #endif 510 #endif
511 511
512 ModelRecord rec; 512 ModelRecord rec;
513 rec.source = input.getModel(); 513 rec.source = input.getModel();
519 519
520 m_models[outputModelToAdd] = rec; 520 m_models[outputModelToAdd] = rec;
521 521
522 #ifdef DEBUG_DOCUMENT 522 #ifdef DEBUG_DOCUMENT
523 SVDEBUG << "Document::addDerivedModel: Added model " << outputModelToAdd << endl; 523 SVDEBUG << "Document::addDerivedModel: Added model " << outputModelToAdd << endl;
524 std::cerr << "Models now: "; 524 cerr << "Models now: ";
525 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { 525 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) {
526 std::cerr << i->first << " "; 526 cerr << i->first << " ";
527 } 527 }
528 std::cerr << std::endl; 528 cerr << endl;
529 #endif 529 #endif
530 530
531 emit modelAdded(outputModelToAdd); 531 emit modelAdded(outputModelToAdd);
532 } 532 }
533 533
534 534
535 void 535 void
536 Document::addImportedModel(Model *model) 536 Document::addImportedModel(Model *model)
537 { 537 {
538 if (m_models.find(model) != m_models.end()) { 538 if (m_models.find(model) != m_models.end()) {
539 std::cerr << "WARNING: Document::addImportedModel: Model already added" 539 cerr << "WARNING: Document::addImportedModel: Model already added"
540 << std::endl; 540 << endl;
541 return; 541 return;
542 } 542 }
543 543
544 ModelRecord rec; 544 ModelRecord rec;
545 rec.source = 0; 545 rec.source = 0;
547 547
548 m_models[model] = rec; 548 m_models[model] = rec;
549 549
550 #ifdef DEBUG_DOCUMENT 550 #ifdef DEBUG_DOCUMENT
551 SVDEBUG << "Document::addImportedModel: Added model " << model << endl; 551 SVDEBUG << "Document::addImportedModel: Added model " << model << endl;
552 std::cerr << "Models now: "; 552 cerr << "Models now: ";
553 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { 553 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) {
554 std::cerr << i->first << " "; 554 cerr << i->first << " ";
555 } 555 }
556 std::cerr << std::endl; 556 cerr << endl;
557 #endif 557 #endif
558 558
559 if (m_autoAlignment) alignModel(model); 559 if (m_autoAlignment) alignModel(model);
560 560
561 emit modelAdded(model); 561 emit modelAdded(model);
597 getDefaultTransformFor(transform.getIdentifier(), 597 getDefaultTransformFor(transform.getIdentifier(),
598 lrintf(transform.getSampleRate())) 598 lrintf(transform.getSampleRate()))
599 .getPluginVersion()); 599 .getPluginVersion());
600 600
601 if (!model) { 601 if (!model) {
602 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.getIdentifier() << std::endl; 602 cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.getIdentifier() << endl;
603 } else { 603 } else {
604 addDerivedModel(applied, input, model); 604 addDerivedModel(applied, input, model);
605 } 605 }
606 // std::cerr << "derived model name: " << model->getTypeName() << std::endl; 606 // std::cerr << "derived model name: " << model->getTypeName() << std::endl;
607 607
622 bool toDelete = false; 622 bool toDelete = false;
623 623
624 if (m_models.find(model) != m_models.end()) { 624 if (m_models.find(model) != m_models.end()) {
625 625
626 if (m_models[model].refcount == 0) { 626 if (m_models[model].refcount == 0) {
627 std::cerr << "WARNING: Document::releaseModel: model " << model 627 cerr << "WARNING: Document::releaseModel: model " << model
628 << " reference count is zero already!" << std::endl; 628 << " reference count is zero already!" << endl;
629 } else { 629 } else {
630 if (--m_models[model].refcount == 0) { 630 if (--m_models[model].refcount == 0) {
631 toDelete = true; 631 toDelete = true;
632 } 632 }
633 } 633 }
634 } else { 634 } else {
635 std::cerr << "WARNING: Document::releaseModel: Unfound model " 635 cerr << "WARNING: Document::releaseModel: Unfound model "
636 << model << std::endl; 636 << model << endl;
637 toDelete = true; 637 toDelete = true;
638 } 638 }
639 639
640 if (toDelete) { 640 if (toDelete) {
641 641
659 emit modelAboutToBeDeleted(model); 659 emit modelAboutToBeDeleted(model);
660 m_models.erase(model); 660 m_models.erase(model);
661 661
662 #ifdef DEBUG_DOCUMENT 662 #ifdef DEBUG_DOCUMENT
663 SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; 663 SVDEBUG << "Document::releaseModel: Deleted model " << model << endl;
664 std::cerr << "Models now: "; 664 cerr << "Models now: ";
665 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { 665 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) {
666 std::cerr << i->first << " "; 666 cerr << i->first << " ";
667 } 667 }
668 std::cerr << std::endl; 668 cerr << endl;
669 #endif 669 #endif
670 670
671 delete model; 671 delete model;
672 } 672 }
673 } 673 }
676 Document::deleteLayer(Layer *layer, bool force) 676 Document::deleteLayer(Layer *layer, bool force)
677 { 677 {
678 if (m_layerViewMap.find(layer) != m_layerViewMap.end() && 678 if (m_layerViewMap.find(layer) != m_layerViewMap.end() &&
679 m_layerViewMap[layer].size() > 0) { 679 m_layerViewMap[layer].size() > 0) {
680 680
681 std::cerr << "WARNING: Document::deleteLayer: Layer " 681 cerr << "WARNING: Document::deleteLayer: Layer "
682 << layer << " [" << layer->objectName() << "]" 682 << layer << " [" << layer->objectName() << "]"
683 << " is still used in " << m_layerViewMap[layer].size() 683 << " is still used in " << m_layerViewMap[layer].size()
684 << " views!" << std::endl; 684 << " views!" << endl;
685 685
686 if (force) { 686 if (force) {
687 687
688 #ifdef DEBUG_DOCUMENT 688 #ifdef DEBUG_DOCUMENT
689 std::cerr << "(force flag set -- deleting from all views)" << std::endl; 689 cerr << "(force flag set -- deleting from all views)" << endl;
690 #endif 690 #endif
691 691
692 for (std::set<View *>::iterator j = m_layerViewMap[layer].begin(); 692 for (std::set<View *>::iterator j = m_layerViewMap[layer].begin();
693 j != m_layerViewMap[layer].end(); ++j) { 693 j != m_layerViewMap[layer].end(); ++j) {
694 // don't use removeLayerFromView, as it issues a command 694 // don't use removeLayerFromView, as it issues a command
728 Document::setModel(Layer *layer, Model *model) 728 Document::setModel(Layer *layer, Model *model)
729 { 729 {
730 if (model && 730 if (model &&
731 model != m_mainModel && 731 model != m_mainModel &&
732 m_models.find(model) == m_models.end()) { 732 m_models.find(model) == m_models.end()) {
733 std::cerr << "ERROR: Document::setModel: Layer " << layer 733 cerr << "ERROR: Document::setModel: Layer " << layer
734 << " (\"" << layer->objectName().toStdString() 734 << " (\"" << layer->objectName()
735 << "\") wants to use unregistered model " << model 735 << "\") wants to use unregistered model " << model
736 << ": register the layer's model before setting it!" 736 << ": register the layer's model before setting it!"
737 << std::endl; 737 << endl;
738 return; 738 return;
739 } 739 }
740 740
741 Model *previousModel = layer->getModel(); 741 Model *previousModel = layer->getModel();
742 742
783 << "normally you want to set the model first" << endl; 783 << "normally you want to set the model first" << endl;
784 #endif 784 #endif
785 } else { 785 } else {
786 if (model != m_mainModel && 786 if (model != m_mainModel &&
787 m_models.find(model) == m_models.end()) { 787 m_models.find(model) == m_models.end()) {
788 std::cerr << "ERROR: Document::addLayerToView: Layer " << layer 788 cerr << "ERROR: Document::addLayerToView: Layer " << layer
789 << " has unregistered model " << model 789 << " has unregistered model " << model
790 << " -- register the layer's model before adding the layer!" << std::endl; 790 << " -- register the layer's model before adding the layer!" << endl;
791 return; 791 return;
792 } 792 }
793 } 793 }
794 794
795 CommandHistory::getInstance()->addCommand 795 CommandHistory::getInstance()->addCommand
809 bool firstView = (m_layerViewMap.find(layer) == m_layerViewMap.end() || 809 bool firstView = (m_layerViewMap.find(layer) == m_layerViewMap.end() ||
810 m_layerViewMap[layer].empty()); 810 m_layerViewMap[layer].empty());
811 811
812 if (m_layerViewMap[layer].find(view) != 812 if (m_layerViewMap[layer].find(view) !=
813 m_layerViewMap[layer].end()) { 813 m_layerViewMap[layer].end()) {
814 std::cerr << "WARNING: Document::addToLayerViewMap:" 814 cerr << "WARNING: Document::addToLayerViewMap:"
815 << " Layer " << layer << " -> view " << view << " already in" 815 << " Layer " << layer << " -> view " << view << " already in"
816 << " layer view map -- internal inconsistency" << std::endl; 816 << " layer view map -- internal inconsistency" << endl;
817 } 817 }
818 818
819 m_layerViewMap[layer].insert(view); 819 m_layerViewMap[layer].insert(view);
820 820
821 if (firstView) emit layerInAView(layer, true); 821 if (firstView) emit layerInAView(layer, true);
824 void 824 void
825 Document::removeFromLayerViewMap(Layer *layer, View *view) 825 Document::removeFromLayerViewMap(Layer *layer, View *view)
826 { 826 {
827 if (m_layerViewMap[layer].find(view) == 827 if (m_layerViewMap[layer].find(view) ==
828 m_layerViewMap[layer].end()) { 828 m_layerViewMap[layer].end()) {
829 std::cerr << "WARNING: Document::removeFromLayerViewMap:" 829 cerr << "WARNING: Document::removeFromLayerViewMap:"
830 << " Layer " << layer << " -> view " << view << " not in" 830 << " Layer " << layer << " -> view " << view << " not in"
831 << " layer view map -- internal inconsistency" << std::endl; 831 << " layer view map -- internal inconsistency" << endl;
832 } 832 }
833 833
834 m_layerViewMap[layer].erase(view); 834 m_layerViewMap[layer].erase(view);
835 835
836 if (m_layerViewMap[layer].empty()) { 836 if (m_layerViewMap[layer].empty()) {
991 991
992 SparseTimeValueModel *path = dynamic_cast<SparseTimeValueModel *> 992 SparseTimeValueModel *path = dynamic_cast<SparseTimeValueModel *>
993 (transformOutput); 993 (transformOutput);
994 994
995 if (!path) { 995 if (!path) {
996 std::cerr << "Document::alignModel: ERROR: Failed to create alignment path (no MATCH plugin?)" << std::endl; 996 cerr << "Document::alignModel: ERROR: Failed to create alignment path (no MATCH plugin?)" << endl;
997 emit alignmentFailed(id, message); 997 emit alignmentFailed(id, message);
998 delete transformOutput; 998 delete transformOutput;
999 delete aggregateModel; 999 delete aggregateModel;
1000 return; 1000 return;
1001 } 1001 }