Mercurial > hg > svapp
comparison framework/Document.cpp @ 293:068235cf5bf7
Drop std:: from cout, cerr, endl -- pull these in through Debug.h
author | Chris Cannam |
---|---|
date | Tue, 26 Nov 2013 14:12:50 +0000 |
parents | ecbf3b75c562 |
children | 933b5aed341a |
comparison
equal
deleted
inserted
replaced
291:3fc0df289533 | 293:068235cf5bf7 |
---|---|
56 //!!! Document should really own the command history. atm we | 56 //!!! Document should really own the command history. atm we |
57 //still refer to it in various places that don't have access to | 57 //still refer to it in various places that don't have access to |
58 //the document, be nice to fix that | 58 //the document, be nice to fix that |
59 | 59 |
60 #ifdef DEBUG_DOCUMENT | 60 #ifdef DEBUG_DOCUMENT |
61 std::cerr << "\n\nDocument::~Document: about to clear command history" << std::endl; | 61 cerr << "\n\nDocument::~Document: about to clear command history" << endl; |
62 #endif | 62 #endif |
63 CommandHistory::getInstance()->clear(); | 63 CommandHistory::getInstance()->clear(); |
64 | 64 |
65 #ifdef DEBUG_DOCUMENT | 65 #ifdef DEBUG_DOCUMENT |
66 SVDEBUG << "Document::~Document: about to delete layers" << endl; | 66 SVDEBUG << "Document::~Document: about to delete layers" << endl; |
137 { | 137 { |
138 LayerFactory::LayerTypeSet types = | 138 LayerFactory::LayerTypeSet types = |
139 LayerFactory::getInstance()->getValidLayerTypes(model); | 139 LayerFactory::getInstance()->getValidLayerTypes(model); |
140 | 140 |
141 if (types.empty()) { | 141 if (types.empty()) { |
142 std::cerr << "WARNING: Document::importLayer: no valid display layer for model" << std::endl; | 142 cerr << "WARNING: Document::importLayer: no valid display layer for model" << endl; |
143 return 0; | 143 return 0; |
144 } | 144 } |
145 | 145 |
146 //!!! for now, just use the first suitable layer type | 146 //!!! for now, just use the first suitable layer type |
147 LayerFactory::LayerType type = *types.begin(); | 147 LayerFactory::LayerType type = *types.begin(); |
218 | 218 |
219 LayerFactory::LayerTypeSet types = | 219 LayerFactory::LayerTypeSet types = |
220 LayerFactory::getInstance()->getValidLayerTypes(newModel); | 220 LayerFactory::getInstance()->getValidLayerTypes(newModel); |
221 | 221 |
222 if (types.empty()) { | 222 if (types.empty()) { |
223 std::cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << std::endl; | 223 cerr << "WARNING: Document::createLayerForTransformer: no valid display layer for output of transform " << transform.getIdentifier() << endl; |
224 newModel->aboutToDelete(); | 224 newModel->aboutToDelete(); |
225 emit modelAboutToBeDeleted(newModel); | 225 emit modelAboutToBeDeleted(newModel); |
226 m_models.erase(newModel); | 226 m_models.erase(newModel); |
227 delete newModel; | 227 delete newModel; |
228 return 0; | 228 return 0; |
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 cerr << "Document::setMainModel: Have " |
286 << m_layers.size() << " layers" << std::endl; | 286 << m_layers.size() << " layers" << endl; |
287 std::cerr << "Models now: "; | 287 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 cerr << i->first << " "; |
290 } | 290 } |
291 std::cerr << std::endl; | 291 cerr << endl; |
292 std::cerr << "Old main model: " << oldMainModel << std::endl; | 292 cerr << "Old main model: " << oldMainModel << endl; |
293 #endif | 293 #endif |
294 | 294 |
295 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { | 295 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { |
296 | 296 |
297 Layer *layer = *i; | 297 Layer *layer = *i; |
298 Model *model = layer->getModel(); | 298 Model *model = layer->getModel(); |
299 | 299 |
300 #ifdef DEBUG_DOCUMENT | 300 #ifdef DEBUG_DOCUMENT |
301 std::cerr << "Document::setMainModel: inspecting model " | 301 cerr << "Document::setMainModel: inspecting model " |
302 << (model ? model->objectName(): "(null)") << " in layer " | 302 << (model ? model->objectName(): "(null)") << " in layer " |
303 << layer->objectName() << std::endl; | 303 << layer->objectName() << endl; |
304 #endif | 304 #endif |
305 | 305 |
306 if (model == oldMainModel) { | 306 if (model == oldMainModel) { |
307 #ifdef DEBUG_DOCUMENT | 307 #ifdef DEBUG_DOCUMENT |
308 std::cerr << "... it uses the old main model, replacing" << std::endl; | 308 cerr << "... it uses the old main model, replacing" << endl; |
309 #endif | 309 #endif |
310 LayerFactory::getInstance()->setModel(layer, m_mainModel); | 310 LayerFactory::getInstance()->setModel(layer, m_mainModel); |
311 continue; | 311 continue; |
312 } | 312 } |
313 | 313 |
314 if (!model) { | 314 if (!model) { |
315 std::cerr << "WARNING: Document::setMainModel: Null model in layer " | 315 cerr << "WARNING: Document::setMainModel: Null model in layer " |
316 << layer << std::endl; | 316 << layer << endl; |
317 // get rid of this hideous degenerate | 317 // get rid of this hideous degenerate |
318 obsoleteLayers.push_back(layer); | 318 obsoleteLayers.push_back(layer); |
319 continue; | 319 continue; |
320 } | 320 } |
321 | 321 |
322 if (m_models.find(model) == m_models.end()) { | 322 if (m_models.find(model) == m_models.end()) { |
323 std::cerr << "WARNING: Document::setMainModel: Unknown model " | 323 cerr << "WARNING: Document::setMainModel: Unknown model " |
324 << model << " in layer " << layer << std::endl; | 324 << model << " in layer " << layer << endl; |
325 // and this one | 325 // and this one |
326 obsoleteLayers.push_back(layer); | 326 obsoleteLayers.push_back(layer); |
327 continue; | 327 continue; |
328 } | 328 } |
329 | 329 |
330 if (m_models[model].source && | 330 if (m_models[model].source && |
331 (m_models[model].source == oldMainModel)) { | 331 (m_models[model].source == oldMainModel)) { |
332 | 332 |
333 #ifdef DEBUG_DOCUMENT | 333 #ifdef DEBUG_DOCUMENT |
334 std::cerr << "... it uses a model derived from the old main model, regenerating" << std::endl; | 334 cerr << "... it uses a model derived from the old main model, regenerating" << endl; |
335 #endif | 335 #endif |
336 | 336 |
337 // This model was derived from the previous main | 337 // This model was derived from the previous main |
338 // model: regenerate it. | 338 // model: regenerate it. |
339 | 339 |
349 ModelTransformer::Input | 349 ModelTransformer::Input |
350 (m_mainModel, m_models[model].channel), | 350 (m_mainModel, m_models[model].channel), |
351 message); | 351 message); |
352 | 352 |
353 if (!replacementModel) { | 353 if (!replacementModel) { |
354 std::cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \"" | 354 cerr << "WARNING: Document::setMainModel: Failed to regenerate model for transform \"" |
355 << transformId << "\"" << " in layer " << layer << std::endl; | 355 << transformId << "\"" << " in layer " << layer << endl; |
356 if (failedTransformers.find(transformId) | 356 if (failedTransformers.find(transformId) |
357 == failedTransformers.end()) { | 357 == failedTransformers.end()) { |
358 emit modelRegenerationFailed(layer->objectName(), | 358 emit modelRegenerationFailed(layer->objectName(), |
359 transformId, | 359 transformId, |
360 message); | 360 message); |
366 emit modelRegenerationWarning(layer->objectName(), | 366 emit modelRegenerationWarning(layer->objectName(), |
367 transformId, | 367 transformId, |
368 message); | 368 message); |
369 } | 369 } |
370 #ifdef DEBUG_DOCUMENT | 370 #ifdef DEBUG_DOCUMENT |
371 std::cerr << "Replacing model " << model << " (type " | 371 cerr << "Replacing model " << model << " (type " |
372 << typeid(*model).name() << ") with model " | 372 << typeid(*model).name() << ") with model " |
373 << replacementModel << " (type " | 373 << replacementModel << " (type " |
374 << typeid(*replacementModel).name() << ") in layer " | 374 << typeid(*replacementModel).name() << ") in layer " |
375 << layer << " (name " << layer->objectName() << ")" | 375 << layer << " (name " << layer->objectName() << ")" |
376 << std::endl; | 376 << endl; |
377 #endif | 377 #endif |
378 RangeSummarisableTimeValueModel *rm = | 378 RangeSummarisableTimeValueModel *rm = |
379 dynamic_cast<RangeSummarisableTimeValueModel *>(replacementModel); | 379 dynamic_cast<RangeSummarisableTimeValueModel *>(replacementModel); |
380 #ifdef DEBUG_DOCUMENT | 380 #ifdef DEBUG_DOCUMENT |
381 if (rm) { | 381 if (rm) { |
382 std::cerr << "new model has " << rm->getChannelCount() << " channels " << std::endl; | 382 cerr << "new model has " << rm->getChannelCount() << " channels " << endl; |
383 } else { | 383 } else { |
384 std::cerr << "new model " << replacementModel << " is not a RangeSummarisableTimeValueModel!" << std::endl; | 384 cerr << "new model " << replacementModel << " is not a RangeSummarisableTimeValueModel!" << endl; |
385 } | 385 } |
386 #endif | 386 #endif |
387 setModel(layer, replacementModel); | 387 setModel(layer, replacementModel); |
388 } | 388 } |
389 } | 389 } |
431 Document::addDerivedModel(const Transform &transform, | 431 Document::addDerivedModel(const Transform &transform, |
432 const ModelTransformer::Input &input, | 432 const ModelTransformer::Input &input, |
433 Model *outputModelToAdd) | 433 Model *outputModelToAdd) |
434 { | 434 { |
435 if (m_models.find(outputModelToAdd) != m_models.end()) { | 435 if (m_models.find(outputModelToAdd) != m_models.end()) { |
436 std::cerr << "WARNING: Document::addDerivedModel: Model already added" | 436 cerr << "WARNING: Document::addDerivedModel: Model already added" |
437 << std::endl; | 437 << endl; |
438 return; | 438 return; |
439 } | 439 } |
440 | 440 |
441 #ifdef DEBUG_DOCUMENT | 441 #ifdef DEBUG_DOCUMENT |
442 if (input.getModel()) { | 442 if (input.getModel()) { |
443 std::cerr << "Document::addDerivedModel: source is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << std::endl; | 443 cerr << "Document::addDerivedModel: source is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << endl; |
444 } else { | 444 } else { |
445 std::cerr << "Document::addDerivedModel: source is " << input.getModel() << std::endl; | 445 cerr << "Document::addDerivedModel: source is " << input.getModel() << endl; |
446 } | 446 } |
447 #endif | 447 #endif |
448 | 448 |
449 ModelRecord rec; | 449 ModelRecord rec; |
450 rec.source = input.getModel(); | 450 rec.source = input.getModel(); |
456 | 456 |
457 m_models[outputModelToAdd] = rec; | 457 m_models[outputModelToAdd] = rec; |
458 | 458 |
459 #ifdef DEBUG_DOCUMENT | 459 #ifdef DEBUG_DOCUMENT |
460 SVDEBUG << "Document::addDerivedModel: Added model " << outputModelToAdd << endl; | 460 SVDEBUG << "Document::addDerivedModel: Added model " << outputModelToAdd << endl; |
461 std::cerr << "Models now: "; | 461 cerr << "Models now: "; |
462 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { | 462 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { |
463 std::cerr << i->first << " "; | 463 cerr << i->first << " "; |
464 } | 464 } |
465 std::cerr << std::endl; | 465 cerr << endl; |
466 #endif | 466 #endif |
467 | 467 |
468 emit modelAdded(outputModelToAdd); | 468 emit modelAdded(outputModelToAdd); |
469 } | 469 } |
470 | 470 |
471 | 471 |
472 void | 472 void |
473 Document::addImportedModel(Model *model) | 473 Document::addImportedModel(Model *model) |
474 { | 474 { |
475 if (m_models.find(model) != m_models.end()) { | 475 if (m_models.find(model) != m_models.end()) { |
476 std::cerr << "WARNING: Document::addImportedModel: Model already added" | 476 cerr << "WARNING: Document::addImportedModel: Model already added" |
477 << std::endl; | 477 << endl; |
478 return; | 478 return; |
479 } | 479 } |
480 | 480 |
481 ModelRecord rec; | 481 ModelRecord rec; |
482 rec.source = 0; | 482 rec.source = 0; |
484 | 484 |
485 m_models[model] = rec; | 485 m_models[model] = rec; |
486 | 486 |
487 #ifdef DEBUG_DOCUMENT | 487 #ifdef DEBUG_DOCUMENT |
488 SVDEBUG << "Document::addImportedModel: Added model " << model << endl; | 488 SVDEBUG << "Document::addImportedModel: Added model " << model << endl; |
489 std::cerr << "Models now: "; | 489 cerr << "Models now: "; |
490 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { | 490 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { |
491 std::cerr << i->first << " "; | 491 cerr << i->first << " "; |
492 } | 492 } |
493 std::cerr << std::endl; | 493 cerr << endl; |
494 #endif | 494 #endif |
495 | 495 |
496 if (m_autoAlignment) alignModel(model); | 496 if (m_autoAlignment) alignModel(model); |
497 | 497 |
498 emit modelAdded(model); | 498 emit modelAdded(model); |
529 getDefaultTransformFor(transform.getIdentifier(), | 529 getDefaultTransformFor(transform.getIdentifier(), |
530 lrintf(transform.getSampleRate())) | 530 lrintf(transform.getSampleRate())) |
531 .getPluginVersion()); | 531 .getPluginVersion()); |
532 | 532 |
533 if (!model) { | 533 if (!model) { |
534 std::cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.getIdentifier() << std::endl; | 534 cerr << "WARNING: Document::addDerivedModel: no output model for transform " << transform.getIdentifier() << endl; |
535 } else { | 535 } else { |
536 addDerivedModel(applied, input, model); | 536 addDerivedModel(applied, input, model); |
537 } | 537 } |
538 | 538 |
539 return model; | 539 return model; |
553 bool toDelete = false; | 553 bool toDelete = false; |
554 | 554 |
555 if (m_models.find(model) != m_models.end()) { | 555 if (m_models.find(model) != m_models.end()) { |
556 | 556 |
557 if (m_models[model].refcount == 0) { | 557 if (m_models[model].refcount == 0) { |
558 std::cerr << "WARNING: Document::releaseModel: model " << model | 558 cerr << "WARNING: Document::releaseModel: model " << model |
559 << " reference count is zero already!" << std::endl; | 559 << " reference count is zero already!" << endl; |
560 } else { | 560 } else { |
561 if (--m_models[model].refcount == 0) { | 561 if (--m_models[model].refcount == 0) { |
562 toDelete = true; | 562 toDelete = true; |
563 } | 563 } |
564 } | 564 } |
565 } else { | 565 } else { |
566 std::cerr << "WARNING: Document::releaseModel: Unfound model " | 566 cerr << "WARNING: Document::releaseModel: Unfound model " |
567 << model << std::endl; | 567 << model << endl; |
568 toDelete = true; | 568 toDelete = true; |
569 } | 569 } |
570 | 570 |
571 if (toDelete) { | 571 if (toDelete) { |
572 | 572 |
590 emit modelAboutToBeDeleted(model); | 590 emit modelAboutToBeDeleted(model); |
591 m_models.erase(model); | 591 m_models.erase(model); |
592 | 592 |
593 #ifdef DEBUG_DOCUMENT | 593 #ifdef DEBUG_DOCUMENT |
594 SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; | 594 SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; |
595 std::cerr << "Models now: "; | 595 cerr << "Models now: "; |
596 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { | 596 for (ModelMap::const_iterator i = m_models.begin(); i != m_models.end(); ++i) { |
597 std::cerr << i->first << " "; | 597 cerr << i->first << " "; |
598 } | 598 } |
599 std::cerr << std::endl; | 599 cerr << endl; |
600 #endif | 600 #endif |
601 | 601 |
602 delete model; | 602 delete model; |
603 } | 603 } |
604 } | 604 } |
607 Document::deleteLayer(Layer *layer, bool force) | 607 Document::deleteLayer(Layer *layer, bool force) |
608 { | 608 { |
609 if (m_layerViewMap.find(layer) != m_layerViewMap.end() && | 609 if (m_layerViewMap.find(layer) != m_layerViewMap.end() && |
610 m_layerViewMap[layer].size() > 0) { | 610 m_layerViewMap[layer].size() > 0) { |
611 | 611 |
612 std::cerr << "WARNING: Document::deleteLayer: Layer " | 612 cerr << "WARNING: Document::deleteLayer: Layer " |
613 << layer << " [" << layer->objectName() << "]" | 613 << layer << " [" << layer->objectName() << "]" |
614 << " is still used in " << m_layerViewMap[layer].size() | 614 << " is still used in " << m_layerViewMap[layer].size() |
615 << " views!" << std::endl; | 615 << " views!" << endl; |
616 | 616 |
617 if (force) { | 617 if (force) { |
618 | 618 |
619 #ifdef DEBUG_DOCUMENT | 619 #ifdef DEBUG_DOCUMENT |
620 std::cerr << "(force flag set -- deleting from all views)" << std::endl; | 620 cerr << "(force flag set -- deleting from all views)" << endl; |
621 #endif | 621 #endif |
622 | 622 |
623 for (std::set<View *>::iterator j = m_layerViewMap[layer].begin(); | 623 for (std::set<View *>::iterator j = m_layerViewMap[layer].begin(); |
624 j != m_layerViewMap[layer].end(); ++j) { | 624 j != m_layerViewMap[layer].end(); ++j) { |
625 // don't use removeLayerFromView, as it issues a command | 625 // don't use removeLayerFromView, as it issues a command |
659 Document::setModel(Layer *layer, Model *model) | 659 Document::setModel(Layer *layer, Model *model) |
660 { | 660 { |
661 if (model && | 661 if (model && |
662 model != m_mainModel && | 662 model != m_mainModel && |
663 m_models.find(model) == m_models.end()) { | 663 m_models.find(model) == m_models.end()) { |
664 std::cerr << "ERROR: Document::setModel: Layer " << layer | 664 cerr << "ERROR: Document::setModel: Layer " << layer |
665 << " (\"" << layer->objectName().toStdString() | 665 << " (\"" << layer->objectName().toStdString() |
666 << "\") wants to use unregistered model " << model | 666 << "\") wants to use unregistered model " << model |
667 << ": register the layer's model before setting it!" | 667 << ": register the layer's model before setting it!" |
668 << std::endl; | 668 << endl; |
669 return; | 669 return; |
670 } | 670 } |
671 | 671 |
672 Model *previousModel = layer->getModel(); | 672 Model *previousModel = layer->getModel(); |
673 | 673 |
713 << "normally you want to set the model first" << endl; | 713 << "normally you want to set the model first" << endl; |
714 #endif | 714 #endif |
715 } else { | 715 } else { |
716 if (model != m_mainModel && | 716 if (model != m_mainModel && |
717 m_models.find(model) == m_models.end()) { | 717 m_models.find(model) == m_models.end()) { |
718 std::cerr << "ERROR: Document::addLayerToView: Layer " << layer | 718 cerr << "ERROR: Document::addLayerToView: Layer " << layer |
719 << " has unregistered model " << model | 719 << " has unregistered model " << model |
720 << " -- register the layer's model before adding the layer!" << std::endl; | 720 << " -- register the layer's model before adding the layer!" << endl; |
721 return; | 721 return; |
722 } | 722 } |
723 } | 723 } |
724 | 724 |
725 CommandHistory::getInstance()->addCommand | 725 CommandHistory::getInstance()->addCommand |
739 bool firstView = (m_layerViewMap.find(layer) == m_layerViewMap.end() || | 739 bool firstView = (m_layerViewMap.find(layer) == m_layerViewMap.end() || |
740 m_layerViewMap[layer].empty()); | 740 m_layerViewMap[layer].empty()); |
741 | 741 |
742 if (m_layerViewMap[layer].find(view) != | 742 if (m_layerViewMap[layer].find(view) != |
743 m_layerViewMap[layer].end()) { | 743 m_layerViewMap[layer].end()) { |
744 std::cerr << "WARNING: Document::addToLayerViewMap:" | 744 cerr << "WARNING: Document::addToLayerViewMap:" |
745 << " Layer " << layer << " -> view " << view << " already in" | 745 << " Layer " << layer << " -> view " << view << " already in" |
746 << " layer view map -- internal inconsistency" << std::endl; | 746 << " layer view map -- internal inconsistency" << endl; |
747 } | 747 } |
748 | 748 |
749 m_layerViewMap[layer].insert(view); | 749 m_layerViewMap[layer].insert(view); |
750 | 750 |
751 if (firstView) emit layerInAView(layer, true); | 751 if (firstView) emit layerInAView(layer, true); |
754 void | 754 void |
755 Document::removeFromLayerViewMap(Layer *layer, View *view) | 755 Document::removeFromLayerViewMap(Layer *layer, View *view) |
756 { | 756 { |
757 if (m_layerViewMap[layer].find(view) == | 757 if (m_layerViewMap[layer].find(view) == |
758 m_layerViewMap[layer].end()) { | 758 m_layerViewMap[layer].end()) { |
759 std::cerr << "WARNING: Document::removeFromLayerViewMap:" | 759 cerr << "WARNING: Document::removeFromLayerViewMap:" |
760 << " Layer " << layer << " -> view " << view << " not in" | 760 << " Layer " << layer << " -> view " << view << " not in" |
761 << " layer view map -- internal inconsistency" << std::endl; | 761 << " layer view map -- internal inconsistency" << endl; |
762 } | 762 } |
763 | 763 |
764 m_layerViewMap[layer].erase(view); | 764 m_layerViewMap[layer].erase(view); |
765 | 765 |
766 if (m_layerViewMap[layer].empty()) { | 766 if (m_layerViewMap[layer].empty()) { |
921 | 921 |
922 SparseTimeValueModel *path = dynamic_cast<SparseTimeValueModel *> | 922 SparseTimeValueModel *path = dynamic_cast<SparseTimeValueModel *> |
923 (transformOutput); | 923 (transformOutput); |
924 | 924 |
925 if (!path) { | 925 if (!path) { |
926 std::cerr << "Document::alignModel: ERROR: Failed to create alignment path (no MATCH plugin?)" << std::endl; | 926 cerr << "Document::alignModel: ERROR: Failed to create alignment path (no MATCH plugin?)" << endl; |
927 emit alignmentFailed(id, message); | 927 emit alignmentFailed(id, message); |
928 delete transformOutput; | 928 delete transformOutput; |
929 delete aggregateModel; | 929 delete aggregateModel; |
930 return; | 930 return; |
931 } | 931 } |