comparison view/Pane.cpp @ 1481:e540aa5d89cd by-id

Update for removal of (public) getId from Model
author Chris Cannam
date Fri, 05 Jul 2019 15:34:50 +0100
parents 84c4ddb38415
children c83504eb2649
comparison
equal deleted inserted replaced
1480:232262e38051 1481:e540aa5d89cd
365 // Locate some relevant layers and models 365 // Locate some relevant layers and models
366 366
367 Layer *topLayer = getTopLayer(); 367 Layer *topLayer = getTopLayer();
368 bool haveSomeTimeXAxis = false; 368 bool haveSomeTimeXAxis = false;
369 369
370 std::shared_ptr<const Model> waveformModel; // just for reporting purposes 370 ModelId waveformModelId; // just for reporting purposes
371 std::shared_ptr<const Model> workModel; 371 ModelId workModelId;
372 372
373 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { 373 for (LayerList::iterator vi = m_layerStack.end();
374 vi != m_layerStack.begin(); ) {
375
374 --vi; 376 --vi;
377
375 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { 378 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) {
376 haveSomeTimeXAxis = true; 379 haveSomeTimeXAxis = true;
377 } 380 }
378 auto model = ModelById::get((*vi)->getModel()); 381
379 382 ModelId modelId = (*vi)->getModel();
380 if (model) { 383 if (!modelId.isNone()) {
381 if (dynamic_cast<WaveformLayer *>(*vi)) { 384 if (dynamic_cast<WaveformLayer *>(*vi)) {
382 waveformModel = model; 385 waveformModelId = modelId;
383 workModel = waveformModel; 386 workModelId = modelId;
384 } else { 387 } else {
385 if (std::dynamic_pointer_cast<WaveFileModel>(model)) { 388 if (ModelById::isa<WaveFileModel>(modelId)) {
386 workModel = model; 389 workModelId = modelId;
387 } else if (auto wm = ModelById::getAs<WaveFileModel> 390 } else {
388 (model->getSourceModel())) { 391 auto model = ModelById::get(modelId);
389 workModel = wm; 392 if (model) {
393 ModelId sourceId = model->getSourceModel();
394 if (ModelById::isa<WaveFileModel>(sourceId)) {
395 workModelId = sourceId;
396 }
397 }
390 } 398 }
391 } 399 }
392 } 400 }
393 401
394 if (waveformModel && workModel && haveSomeTimeXAxis) break; 402 if (!waveformModelId.isNone() &&
403 !workModelId.isNone() &&
404 haveSomeTimeXAxis) {
405 break;
406 }
395 } 407 }
396 408
397 // Block off left and right extents so we can see where the main model ends 409 // Block off left and right extents so we can see where the main model ends
398 410
399 if (workModel && hasTopLayerTimeXAxis()) { 411 if (!workModelId.isNone() && hasTopLayerTimeXAxis()) {
400 drawModelTimeExtents(r, paint, *workModel); 412 drawModelTimeExtents(r, paint, workModelId);
401 } 413 }
402 414
403 // Crosshairs for mouse movement in measure mode 415 // Crosshairs for mouse movement in measure mode
404 416
405 if (m_manager && 417 if (m_manager &&
446 drawCentreLine(sampleRate, paint, !haveSomeTimeXAxis); 458 drawCentreLine(sampleRate, paint, !haveSomeTimeXAxis);
447 } 459 }
448 460
449 paint.setPen(QColor(50, 50, 50)); 461 paint.setPen(QColor(50, 50, 50));
450 462
451 if (waveformModel && 463 if (!waveformModelId.isNone() &&
452 sampleRate && 464 sampleRate &&
453 m_manager && 465 m_manager &&
454 m_manager->shouldShowDuration()) { 466 m_manager->shouldShowDuration()) {
455 drawDurationAndRate(r, *waveformModel, sampleRate, paint); 467 drawDurationAndRate(r, waveformModelId, sampleRate, paint);
456 } 468 }
457 469
458 bool haveWorkTitle = false; 470 bool haveWorkTitle = false;
459 471
460 if (workModel && 472 if (!workModelId.isNone() &&
461 m_manager && 473 m_manager &&
462 m_manager->shouldShowWorkTitle()) { 474 m_manager->shouldShowWorkTitle()) {
463 drawWorkTitle(r, paint, *workModel); 475 drawWorkTitle(r, paint, workModelId);
464 haveWorkTitle = true; 476 haveWorkTitle = true;
465 } 477 }
466 478
467 if (workModel && 479 if (!workModelId.isNone() &&
468 m_manager && 480 m_manager &&
469 m_manager->getAlignMode()) { 481 m_manager->getAlignMode()) {
470 drawAlignmentStatus(r, paint, *workModel, haveWorkTitle); 482 drawAlignmentStatus(r, paint, workModelId, haveWorkTitle);
471 } 483 }
472 484
473 if (m_manager && 485 if (m_manager &&
474 m_manager->shouldShowLayerNames()) { 486 m_manager->shouldShowLayerNames()) {
475 drawLayerNames(r, paint); 487 drawLayerNames(r, paint);
757 PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); 769 PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText);
758 } 770 }
759 } 771 }
760 772
761 void 773 void
762 Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model &model) 774 Pane::drawModelTimeExtents(QRect r, QPainter &paint, ModelId modelId)
763 { 775 {
776 auto model = ModelById::get(modelId);
777 if (!model) return;
778
764 paint.save(); 779 paint.save();
765 780
766 QBrush brush; 781 QBrush brush;
767 782
768 if (hasLightBackground()) { 783 if (hasLightBackground()) {
771 } else { 786 } else {
772 brush = QBrush(QColor("#aa101010")); 787 brush = QBrush(QColor("#aa101010"));
773 paint.setPen(Qt::white); 788 paint.setPen(Qt::white);
774 } 789 }
775 790
776 sv_frame_t f0 = model.getStartFrame(); 791 sv_frame_t f0 = model->getStartFrame();
777 792
778 if (f0 > getStartFrame() && f0 < getEndFrame()) { 793 if (f0 > getStartFrame() && f0 < getEndFrame()) {
779 int x0 = getXForFrame(f0); 794 int x0 = getXForFrame(f0);
780 if (x0 > r.x()) { 795 if (x0 > r.x()) {
781 paint.fillRect(0, 0, x0, height(), brush); 796 paint.fillRect(0, 0, x0, height(), brush);
782 paint.drawLine(x0, 0, x0, height()); 797 paint.drawLine(x0, 0, x0, height());
783 } 798 }
784 } 799 }
785 800
786 sv_frame_t f1 = model.getEndFrame(); 801 sv_frame_t f1 = model->getEndFrame();
787 802
788 if (f1 > getStartFrame() && f1 < getEndFrame()) { 803 if (f1 > getStartFrame() && f1 < getEndFrame()) {
789 int x1 = getXForFrame(f1); 804 int x1 = getXForFrame(f1);
790 if (x1 < r.x() + r.width()) { 805 if (x1 < r.x() + r.width()) {
791 paint.fillRect(x1, 0, width() - x1, height(), brush); 806 paint.fillRect(x1, 0, width() - x1, height(), brush);
795 810
796 paint.restore(); 811 paint.restore();
797 } 812 }
798 813
799 void 814 void
800 Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model &model, 815 Pane::drawAlignmentStatus(QRect r, QPainter &paint, ModelId modelId,
801 bool down) 816 bool down)
802 { 817 {
803 ModelId reference = model.getAlignmentReference(); 818 auto model = ModelById::get(modelId);
819 if (!model) return;
820
821 ModelId reference = model->getAlignmentReference();
804 /* 822 /*
805 if (!reference) { 823 if (!reference) {
806 cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl; 824 cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl;
807 } else if (reference == model.getId()) { 825 } else if (reference == model->getId()) {
808 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl; 826 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl;
809 } else { 827 } else {
810 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl; 828 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl;
811 } 829 }
812 */ 830 */
813 QString text; 831 QString text;
814 int completion = 100; 832 int completion = 100;
815 833
816 if (reference == model.getId()) { 834 if (reference == modelId) {
817 text = tr("Reference"); 835 text = tr("Reference");
818 } else if (reference.isNone()) { 836 } else if (reference.isNone()) {
819 text = tr("Unaligned"); 837 text = tr("Unaligned");
820 } else { 838 } else {
821 completion = model.getAlignmentCompletion(); 839 completion = model->getAlignmentCompletion();
822 if (completion == 0) { 840 if (completion == 0) {
823 text = tr("Unaligned"); 841 text = tr("Unaligned");
824 } else if (completion < 100) { 842 } else if (completion < 100) {
825 text = tr("Aligning: %1%").arg(completion); 843 text = tr("Aligning: %1%").arg(completion);
826 } else { 844 } else {
848 866
849 paint.restore(); 867 paint.restore();
850 } 868 }
851 869
852 void 870 void
853 Pane::modelAlignmentCompletionChanged() 871 Pane::modelAlignmentCompletionChanged(ModelId modelId)
854 { 872 {
855 View::modelAlignmentCompletionChanged(); 873 View::modelAlignmentCompletionChanged(modelId);
856 update(QRect(0, 0, 300, 100)); 874 update(QRect(0, 0, 300, 100));
857 } 875 }
858 876
859 void 877 void
860 Pane::drawWorkTitle(QRect r, QPainter &paint, const Model &model) 878 Pane::drawWorkTitle(QRect r, QPainter &paint, ModelId modelId)
861 { 879 {
862 QString title = model.getTitle(); 880 auto model = ModelById::get(modelId);
863 QString maker = model.getMaker(); 881 if (!model) return;
882
883 QString title = model->getTitle();
884 QString maker = model->getMaker();
864 //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl; 885 //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl;
865 if (title == "") return; 886 if (title == "") return;
866 887
867 QString text = title; 888 QString text = title;
868 if (maker != "") { 889 if (maker != "") {
1032 } 1053 }
1033 paint.restore(); 1054 paint.restore();
1034 } 1055 }
1035 1056
1036 void 1057 void
1037 Pane::drawDurationAndRate(QRect r, const Model &waveformModel, 1058 Pane::drawDurationAndRate(QRect r, ModelId waveformModelId,
1038 sv_samplerate_t sampleRate, QPainter &paint) 1059 sv_samplerate_t sampleRate, QPainter &paint)
1039 { 1060 {
1061 auto waveformModel = ModelById::get(waveformModelId);
1062 if (!waveformModel) return;
1063
1040 int fontHeight = paint.fontMetrics().height(); 1064 int fontHeight = paint.fontMetrics().height();
1041 int fontAscent = paint.fontMetrics().ascent(); 1065 int fontAscent = paint.fontMetrics().ascent();
1042 1066
1043 if (r.y() + r.height() < height() - fontHeight - 6) return; 1067 if (r.y() + r.height() < height() - fontHeight - 6) return;
1044 1068
1045 sv_samplerate_t modelRate = waveformModel.getSampleRate(); 1069 sv_samplerate_t modelRate = waveformModel->getSampleRate();
1046 sv_samplerate_t nativeRate = waveformModel.getNativeRate(); 1070 sv_samplerate_t nativeRate = waveformModel->getNativeRate();
1047 sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate(); 1071 sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate();
1048 1072
1049 QString srNote = ""; 1073 QString srNote = "";
1050 1074
1051 // Show (R) for waveform models that have been resampled during 1075 // Show (R) for waveform models that have been resampled during
1060 srNote = " " + tr("(R)"); 1084 srNote = " " + tr("(R)");
1061 } 1085 }
1062 } 1086 }
1063 1087
1064 QString desc = tr("%1 / %2Hz%3") 1088 QString desc = tr("%1 / %2Hz%3")
1065 .arg(RealTime::frame2RealTime(waveformModel.getEndFrame(), 1089 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
1066 sampleRate) 1090 sampleRate)
1067 .toText(false).c_str()) 1091 .toText(false).c_str())
1068 .arg(nativeRate) 1092 .arg(nativeRate)
1069 .arg(srNote); 1093 .arg(srNote);
1070 1094