comparison framework/Document.cpp @ 229:8c13e8219903 debug-output

Convert many cerrs to DEBUGs
author Chris Cannam
date Mon, 16 May 2011 17:19:40 +0100
parents 67cea66bd588
children 8aace2d9f1c2
comparison
equal deleted inserted replaced
228:67cea66bd588 229:8c13e8219903
61 std::cerr << "\n\nDocument::~Document: about to clear command history" << std::endl; 61 std::cerr << "\n\nDocument::~Document: about to clear command history" << std::endl;
62 #endif 62 #endif
63 CommandHistory::getInstance()->clear(); 63 CommandHistory::getInstance()->clear();
64 64
65 #ifdef DEBUG_DOCUMENT 65 #ifdef DEBUG_DOCUMENT
66 std::cerr << "Document::~Document: about to delete layers" << std::endl; 66 DEBUG << "Document::~Document: about to delete layers" << endl;
67 #endif 67 #endif
68 while (!m_layers.empty()) { 68 while (!m_layers.empty()) {
69 deleteLayer(*m_layers.begin(), true); 69 deleteLayer(*m_layers.begin(), true);
70 } 70 }
71 71
72 if (!m_models.empty()) { 72 if (!m_models.empty()) {
73 std::cerr << "Document::~Document: WARNING: " 73 DEBUG << "Document::~Document: WARNING: "
74 << m_models.size() << " model(s) still remain -- " 74 << m_models.size() << " model(s) still remain -- "
75 << "should have been garbage collected when deleting layers" 75 << "should have been garbage collected when deleting layers"
76 << std::endl; 76 << endl;
77 while (!m_models.empty()) { 77 while (!m_models.empty()) {
78 Model *model = m_models.begin()->first; 78 Model *model = m_models.begin()->first;
79 if (model == m_mainModel) { 79 if (model == m_mainModel) {
80 // just in case! 80 // just in case!
81 std::cerr << "Document::~Document: WARNING: Main model is also" 81 DEBUG << "Document::~Document: WARNING: Main model is also"
82 << " in models list!" << std::endl; 82 << " in models list!" << endl;
83 } else if (model) { 83 } else if (model) {
84 model->aboutToDelete(); 84 model->aboutToDelete();
85 emit modelAboutToBeDeleted(model); 85 emit modelAboutToBeDeleted(model);
86 delete model; 86 delete model;
87 } 87 }
88 m_models.erase(m_models.begin()); 88 m_models.erase(m_models.begin());
89 } 89 }
90 } 90 }
91 91
92 #ifdef DEBUG_DOCUMENT 92 #ifdef DEBUG_DOCUMENT
93 std::cerr << "Document::~Document: About to get rid of main model" 93 DEBUG << "Document::~Document: About to get rid of main model"
94 << std::endl; 94 << endl;
95 #endif 95 #endif
96 if (m_mainModel) { 96 if (m_mainModel) {
97 m_mainModel->aboutToDelete(); 97 m_mainModel->aboutToDelete();
98 emit modelAboutToBeDeleted(m_mainModel); 98 emit modelAboutToBeDeleted(m_mainModel);
99 } 99 }
112 newLayer->setObjectName(getUniqueLayerName(newLayer->objectName())); 112 newLayer->setObjectName(getUniqueLayerName(newLayer->objectName()));
113 113
114 m_layers.insert(newLayer); 114 m_layers.insert(newLayer);
115 115
116 #ifdef DEBUG_DOCUMENT 116 #ifdef DEBUG_DOCUMENT
117 std::cerr << "Document::createLayer: Added layer of type " << type 117 DEBUG << "Document::createLayer: Added layer of type " << type
118 << ", now have " << m_layers.size() << " layers" << std::endl; 118 << ", now have " << m_layers.size() << " layers" << endl;
119 #endif 119 #endif
120 120
121 emit layerAdded(newLayer); 121 emit layerAdded(newLayer);
122 122
123 return newLayer; 123 return newLayer;
158 setChannel(newLayer, -1); 158 setChannel(newLayer, -1);
159 159
160 m_layers.insert(newLayer); 160 m_layers.insert(newLayer);
161 161
162 #ifdef DEBUG_DOCUMENT 162 #ifdef DEBUG_DOCUMENT
163 std::cerr << "Document::createImportedLayer: Added layer of type " << type 163 DEBUG << "Document::createImportedLayer: Added layer of type " << type
164 << ", now have " << m_layers.size() << " layers" << std::endl; 164 << ", now have " << m_layers.size() << " layers" << endl;
165 #endif 165 #endif
166 166
167 emit layerAdded(newLayer); 167 emit layerAdded(newLayer);
168 return newLayer; 168 return newLayer;
169 } 169 }
280 // model, or delete the layer for each layer that is currently 280 // model, or delete the layer for each layer that is currently
281 // using one of these. Carry out this replacement before we 281 // using one of these. Carry out this replacement before we
282 // delete any of the models. 282 // delete any of the models.
283 283
284 #ifdef DEBUG_DOCUMENT 284 #ifdef DEBUG_DOCUMENT
285 std::cerr << "Document::setMainModel: Have " 285 DEBUG << "Document::setMainModel: Have "
286 << m_layers.size() << " layers" << std::endl; 286 << m_layers.size() << " layers" << endl;
287 std::cerr << "Models now: "; 287 std::cerr << "Models now: ";
288 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { 288 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) {
289 std::cerr << i->first << " "; 289 std::cerr << i->first << " ";
290 } 290 }
291 std::cerr << std::endl; 291 std::cerr << std::endl;
295 295
296 Layer *layer = *i; 296 Layer *layer = *i;
297 Model *model = layer->getModel(); 297 Model *model = layer->getModel();
298 298
299 #ifdef DEBUG_DOCUMENT 299 #ifdef DEBUG_DOCUMENT
300 std::cerr << "Document::setMainModel: inspecting model " 300 DEBUG << "Document::setMainModel: inspecting model "
301 << (model ? model->objectName().toStdString() : "(null)") << " in layer " 301 << (model ? model->objectName(): "(null)") << " in layer "
302 << layer->objectName() << std::endl; 302 << layer->objectName() << endl;
303 #endif 303 #endif
304 304
305 if (model == oldMainModel) { 305 if (model == oldMainModel) {
306 #ifdef DEBUG_DOCUMENT 306 #ifdef DEBUG_DOCUMENT
307 std::cerr << "... it uses the old main model, replacing" << std::endl; 307 std::cerr << "... it uses the old main model, replacing" << std::endl;
365 emit modelRegenerationWarning(layer->objectName(), 365 emit modelRegenerationWarning(layer->objectName(),
366 transformId, 366 transformId,
367 message); 367 message);
368 } 368 }
369 #ifdef DEBUG_DOCUMENT 369 #ifdef DEBUG_DOCUMENT
370 std::cerr << "Replacing model " << model << " (type " 370 DEBUG << "Replacing model " << model << " (type "
371 << typeid(*model).name() << ") with model " 371 << typeid(*model).name() << ") with model "
372 << replacementModel << " (type " 372 << replacementModel << " (type "
373 << typeid(*replacementModel).name() << ") in layer " 373 << typeid(*replacementModel).name() << ") in layer "
374 << layer << " (name " << layer->objectName() << ")" 374 << layer << " (name " << layer->objectName() << ")"
375 << std::endl; 375 << endl;
376 #endif 376 #endif
377 RangeSummarisableTimeValueModel *rm = 377 RangeSummarisableTimeValueModel *rm =
378 dynamic_cast<RangeSummarisableTimeValueModel *>(replacementModel); 378 dynamic_cast<RangeSummarisableTimeValueModel *>(replacementModel);
379 #ifdef DEBUG_DOCUMENT 379 #ifdef DEBUG_DOCUMENT
380 if (rm) { 380 if (rm) {
395 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) { 395 for (ModelMap::iterator i = m_models.begin(); i != m_models.end(); ++i) {
396 396
397 Model *m = i->first; 397 Model *m = i->first;
398 398
399 #ifdef DEBUG_DOCUMENT 399 #ifdef DEBUG_DOCUMENT
400 std::cerr << "considering alignment for model " << m << " (name \"" 400 DEBUG << "considering alignment for model " << m << " (name \""
401 << m->objectName() << "\")" << std::endl; 401 << m->objectName() << "\")" << endl;
402 #endif 402 #endif
403 403
404 if (m_autoAlignment) { 404 if (m_autoAlignment) {
405 405
406 alignModel(m); 406 alignModel(m);
436 << std::endl; 436 << std::endl;
437 return; 437 return;
438 } 438 }
439 439
440 #ifdef DEBUG_DOCUMENT 440 #ifdef DEBUG_DOCUMENT
441 std::cerr << "Document::addDerivedModel: source is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << std::endl; 441 DEBUG << "Document::addDerivedModel: source is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << endl;
442 #endif 442 #endif
443 443
444 ModelRecord rec; 444 ModelRecord rec;
445 rec.source = input.getModel(); 445 rec.source = input.getModel();
446 rec.channel = input.getChannel(); 446 rec.channel = input.getChannel();
450 outputModelToAdd->setSourceModel(input.getModel()); 450 outputModelToAdd->setSourceModel(input.getModel());
451 451
452 m_models[outputModelToAdd] = rec; 452 m_models[outputModelToAdd] = rec;
453 453
454 #ifdef DEBUG_DOCUMENT 454 #ifdef DEBUG_DOCUMENT
455 std::cerr << "Document::addDerivedModel: Added model " << outputModelToAdd << std::endl; 455 DEBUG << "Document::addDerivedModel: Added model " << outputModelToAdd << endl;
456 std::cerr << "Models now: "; 456 std::cerr << "Models now: ";
457 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { 457 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) {
458 std::cerr << i->first << " "; 458 std::cerr << i->first << " ";
459 } 459 }
460 std::cerr << std::endl; 460 std::cerr << std::endl;
478 rec.refcount = 0; 478 rec.refcount = 0;
479 479
480 m_models[model] = rec; 480 m_models[model] = rec;
481 481
482 #ifdef DEBUG_DOCUMENT 482 #ifdef DEBUG_DOCUMENT
483 std::cerr << "Document::addImportedModel: Added model " << model << std::endl; 483 DEBUG << "Document::addImportedModel: Added model " << model << endl;
484 std::cerr << "Models now: "; 484 std::cerr << "Models now: ";
485 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { 485 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) {
486 std::cerr << i->first << " "; 486 std::cerr << i->first << " ";
487 } 487 }
488 std::cerr << std::endl; 488 std::cerr << std::endl;
573 i->second.source = 0; 573 i->second.source = 0;
574 } 574 }
575 } 575 }
576 576
577 if (sourceCount > 0) { 577 if (sourceCount > 0) {
578 std::cerr << "Document::releaseModel: Deleting model " 578 DEBUG << "Document::releaseModel: Deleting model "
579 << model << " even though it is source for " 579 << model << " even though it is source for "
580 << sourceCount << " other derived model(s) -- resetting " 580 << sourceCount << " other derived model(s) -- resetting "
581 << "their source fields appropriately" << std::endl; 581 << "their source fields appropriately" << endl;
582 } 582 }
583 583
584 model->aboutToDelete(); 584 model->aboutToDelete();
585 emit modelAboutToBeDeleted(model); 585 emit modelAboutToBeDeleted(model);
586 m_models.erase(model); 586 m_models.erase(model);
587 587
588 #ifdef DEBUG_DOCUMENT 588 #ifdef DEBUG_DOCUMENT
589 std::cerr << "Document::releaseModel: Deleted model " << model << std::endl; 589 DEBUG << "Document::releaseModel: Deleted model " << model << endl;
590 std::cerr << "Models now: "; 590 std::cerr << "Models now: ";
591 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { 591 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) {
592 std::cerr << i->first << " "; 592 std::cerr << i->first << " ";
593 } 593 }
594 std::cerr << std::endl; 594 std::cerr << std::endl;
628 return; 628 return;
629 } 629 }
630 } 630 }
631 631
632 if (m_layers.find(layer) == m_layers.end()) { 632 if (m_layers.find(layer) == m_layers.end()) {
633 std::cerr << "Document::deleteLayer: Layer " 633 DEBUG << "Document::deleteLayer: Layer "
634 << layer << " (" << typeid(layer).name() << 634 << layer << " (" << typeid(layer).name() <<
635 ") does not exist, or has already been deleted " 635 ") does not exist, or has already been deleted "
636 << "(this may not be as serious as it sounds)" << std::endl; 636 << "(this may not be as serious as it sounds)" << endl;
637 return; 637 return;
638 } 638 }
639 639
640 m_layers.erase(layer); 640 m_layers.erase(layer);
641 641
642 #ifdef DEBUG_DOCUMENT 642 #ifdef DEBUG_DOCUMENT
643 std::cerr << "Document::deleteLayer: Removing, now have " 643 DEBUG << "Document::deleteLayer: Removing, now have "
644 << m_layers.size() << " layers" << std::endl; 644 << m_layers.size() << " layers" << endl;
645 #endif 645 #endif
646 646
647 releaseModel(layer->getModel()); 647 releaseModel(layer->getModel());
648 emit layerRemoved(layer); 648 emit layerRemoved(layer);
649 emit layerAboutToBeDeleted(layer); 649 emit layerAboutToBeDeleted(layer);
665 } 665 }
666 666
667 Model *previousModel = layer->getModel(); 667 Model *previousModel = layer->getModel();
668 668
669 if (previousModel == model) { 669 if (previousModel == model) {
670 std::cerr << "NOTE: Document::setModel: Layer " << layer << " (\"" 670 DEBUG << "NOTE: Document::setModel: Layer " << layer << " (\""
671 << layer->objectName().toStdString() 671 << layer->objectName() << "\") is already set to model "
672 << "\") is already set to model "
673 << model << " (\"" 672 << model << " (\""
674 << (model ? model->objectName().toStdString() : "(null)") 673 << (model ? model->objectName(): "(null)")
675 << "\")" << std::endl; 674 << "\")" << endl;
676 return; 675 return;
677 } 676 }
678 677
679 if (model && model != m_mainModel) { 678 if (model && model != m_mainModel) {
680 m_models[model].refcount ++; 679 m_models[model].refcount ++;
702 Document::addLayerToView(View *view, Layer *layer) 701 Document::addLayerToView(View *view, Layer *layer)
703 { 702 {
704 Model *model = layer->getModel(); 703 Model *model = layer->getModel();
705 if (!model) { 704 if (!model) {
706 #ifdef DEBUG_DOCUMENT 705 #ifdef DEBUG_DOCUMENT
707 std::cerr << "Document::addLayerToView: Layer (\"" 706 DEBUG << "Document::addLayerToView: Layer (\""
708 << layer->objectName().toStdString() 707 << layer->objectName() << "\") with no model being added to view: "
709 << "\") with no model being added to view: " 708 << "normally you want to set the model first" << endl;
710 << "normally you want to set the model first" << std::endl;
711 #endif 709 #endif
712 } else { 710 } else {
713 if (model != m_mainModel && 711 if (model != m_mainModel &&
714 m_models.find(model) == m_models.end()) { 712 m_models.find(model) == m_models.end()) {
715 std::cerr << "ERROR: Document::addLayerToView: Layer " << layer 713 std::cerr << "ERROR: Document::addLayerToView: Layer " << layer
848 RangeSummarisableTimeValueModel *rm = 846 RangeSummarisableTimeValueModel *rm =
849 dynamic_cast<RangeSummarisableTimeValueModel *>(model); 847 dynamic_cast<RangeSummarisableTimeValueModel *>(model);
850 if (!rm) return; 848 if (!rm) return;
851 849
852 if (rm->getAlignmentReference() == m_mainModel) { 850 if (rm->getAlignmentReference() == m_mainModel) {
853 std::cerr << "Document::alignModel: model " << rm << " is already aligned to main model " << m_mainModel << std::endl; 851 DEBUG << "Document::alignModel: model " << rm << " is already aligned to main model " << m_mainModel << endl;
854 return; 852 return;
855 } 853 }
856 854
857 if (model == m_mainModel) { 855 if (model == m_mainModel) {
858 // The reference has an empty alignment to itself. This makes 856 // The reference has an empty alignment to itself. This makes
859 // it possible to distinguish between the reference and any 857 // it possible to distinguish between the reference and any
860 // unaligned model just by looking at the model itself, 858 // unaligned model just by looking at the model itself,
861 // without also knowing what the main model is 859 // without also knowing what the main model is
862 std::cerr << "Document::alignModel(" << model << "): is main model, setting appropriately" << std::endl; 860 DEBUG << "Document::alignModel(" << model << "): is main model, setting appropriately" << endl;
863 rm->setAlignment(new AlignmentModel(model, model, 0, 0)); 861 rm->setAlignment(new AlignmentModel(model, model, 0, 0));
864 return; 862 return;
865 } 863 }
866 864
867 // This involves creating three new models: 865 // This involves creating three new models:
902 (id, aggregateModel->getSampleRate()); 900 (id, aggregateModel->getSampleRate());
903 901
904 transform.setStepSize(transform.getBlockSize()/2); 902 transform.setStepSize(transform.getBlockSize()/2);
905 transform.setParameter("serialise", 1); 903 transform.setParameter("serialise", 1);
906 904
907 std::cerr << "Document::alignModel: Alignment transform step size " << transform.getStepSize() << ", block size " << transform.getBlockSize() << std::endl; 905 DEBUG << "Document::alignModel: Alignment transform step size " << transform.getStepSize() << ", block size " << transform.getBlockSize() << endl;
908 906
909 ModelTransformerFactory *mtf = ModelTransformerFactory::getInstance(); 907 ModelTransformerFactory *mtf = ModelTransformerFactory::getInstance();
910 908
911 QString message; 909 QString message;
912 Model *transformOutput = mtf->transform(transform, aggregate, message); 910 Model *transformOutput = mtf->transform(transform, aggregate, message);
956 } 954 }
957 955
958 Document::AddLayerCommand::~AddLayerCommand() 956 Document::AddLayerCommand::~AddLayerCommand()
959 { 957 {
960 #ifdef DEBUG_DOCUMENT 958 #ifdef DEBUG_DOCUMENT
961 std::cerr << "Document::AddLayerCommand::~AddLayerCommand" << std::endl; 959 DEBUG << "Document::AddLayerCommand::~AddLayerCommand" << endl;
962 #endif 960 #endif
963 if (!m_added) { 961 if (!m_added) {
964 m_d->deleteLayer(m_layer); 962 m_d->deleteLayer(m_layer);
965 } 963 }
966 } 964 }
967 965
968 QString 966 QString
969 Document::AddLayerCommand::getName() const 967 Document::AddLayerCommand::getName() const
970 { 968 {
971 #ifdef DEBUG_DOCUMENT 969 #ifdef DEBUG_DOCUMENT
972 std::cerr << "Document::AddLayerCommand::getName(): Name is " 970 DEBUG << "Document::AddLayerCommand::getName(): Name is "
973 << m_name << std::endl; 971 << m_name << endl;
974 #endif 972 #endif
975 return m_name; 973 return m_name;
976 } 974 }
977 975
978 void 976 void
1016 } 1014 }
1017 1015
1018 Document::RemoveLayerCommand::~RemoveLayerCommand() 1016 Document::RemoveLayerCommand::~RemoveLayerCommand()
1019 { 1017 {
1020 #ifdef DEBUG_DOCUMENT 1018 #ifdef DEBUG_DOCUMENT
1021 std::cerr << "Document::RemoveLayerCommand::~RemoveLayerCommand" << std::endl; 1019 DEBUG << "Document::RemoveLayerCommand::~RemoveLayerCommand" << endl;
1022 #endif 1020 #endif
1023 if (!m_added) { 1021 if (!m_added) {
1024 m_d->deleteLayer(m_layer); 1022 m_d->deleteLayer(m_layer);
1025 } 1023 }
1026 } 1024 }
1027 1025
1028 QString 1026 QString
1029 Document::RemoveLayerCommand::getName() const 1027 Document::RemoveLayerCommand::getName() const
1030 { 1028 {
1031 #ifdef DEBUG_DOCUMENT 1029 #ifdef DEBUG_DOCUMENT
1032 std::cerr << "Document::RemoveLayerCommand::getName(): Name is " 1030 DEBUG << "Document::RemoveLayerCommand::getName(): Name is "
1033 << m_name << std::endl; 1031 << m_name << endl;
1034 #endif 1032 #endif
1035 return m_name; 1033 return m_name;
1036 } 1034 }
1037 1035
1038 void 1036 void