Mercurial > hg > svgui
comparison view/Pane.cpp @ 1475:84c4ddb38415 by-id
Further layer updates
author | Chris Cannam |
---|---|
date | Tue, 02 Jul 2019 15:29:17 +0100 |
parents | de41a11cabc2 |
children | e540aa5d89cd |
comparison
equal
deleted
inserted
replaced
1474:36ad3cdabf55 | 1475:84c4ddb38415 |
---|---|
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 const Model *waveformModel = nullptr; // just for reporting purposes | 370 std::shared_ptr<const Model> waveformModel; // just for reporting purposes |
371 const Model *workModel = nullptr; | 371 std::shared_ptr<const Model> workModel; |
372 | 372 |
373 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { | 373 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { |
374 --vi; | 374 --vi; |
375 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { | 375 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { |
376 haveSomeTimeXAxis = true; | 376 haveSomeTimeXAxis = true; |
377 } | 377 } |
378 if (dynamic_cast<WaveformLayer *>(*vi)) { | 378 auto model = ModelById::get((*vi)->getModel()); |
379 waveformModel = (*vi)->getModel(); | 379 |
380 workModel = waveformModel; | 380 if (model) { |
381 } else { | 381 if (dynamic_cast<WaveformLayer *>(*vi)) { |
382 Model *m = (*vi)->getModel(); | 382 waveformModel = model; |
383 if (dynamic_cast<WaveFileModel *>(m)) { | 383 workModel = waveformModel; |
384 workModel = m; | 384 } else { |
385 } else if (m && dynamic_cast<WaveFileModel *>(m->getSourceModel())) { | 385 if (std::dynamic_pointer_cast<WaveFileModel>(model)) { |
386 workModel = m->getSourceModel(); | 386 workModel = model; |
387 } else if (auto wm = ModelById::getAs<WaveFileModel> | |
388 (model->getSourceModel())) { | |
389 workModel = wm; | |
390 } | |
387 } | 391 } |
388 } | 392 } |
389 | 393 |
390 if (waveformModel && workModel && haveSomeTimeXAxis) break; | 394 if (waveformModel && workModel && haveSomeTimeXAxis) break; |
391 } | 395 } |
392 | 396 |
393 // Block off left and right extents so we can see where the main model ends | 397 // Block off left and right extents so we can see where the main model ends |
394 | 398 |
395 if (workModel && hasTopLayerTimeXAxis()) { | 399 if (workModel && hasTopLayerTimeXAxis()) { |
396 drawModelTimeExtents(r, paint, workModel); | 400 drawModelTimeExtents(r, paint, *workModel); |
397 } | 401 } |
398 | 402 |
399 // Crosshairs for mouse movement in measure mode | 403 // Crosshairs for mouse movement in measure mode |
400 | 404 |
401 if (m_manager && | 405 if (m_manager && |
446 | 450 |
447 if (waveformModel && | 451 if (waveformModel && |
448 sampleRate && | 452 sampleRate && |
449 m_manager && | 453 m_manager && |
450 m_manager->shouldShowDuration()) { | 454 m_manager->shouldShowDuration()) { |
451 drawDurationAndRate(r, waveformModel, sampleRate, paint); | 455 drawDurationAndRate(r, *waveformModel, sampleRate, paint); |
452 } | 456 } |
453 | 457 |
454 bool haveWorkTitle = false; | 458 bool haveWorkTitle = false; |
455 | 459 |
456 if (workModel && | 460 if (workModel && |
457 m_manager && | 461 m_manager && |
458 m_manager->shouldShowWorkTitle()) { | 462 m_manager->shouldShowWorkTitle()) { |
459 drawWorkTitle(r, paint, workModel); | 463 drawWorkTitle(r, paint, *workModel); |
460 haveWorkTitle = true; | 464 haveWorkTitle = true; |
461 } | 465 } |
462 | 466 |
463 if (workModel && | 467 if (workModel && |
464 m_manager && | 468 m_manager && |
465 m_manager->getAlignMode()) { | 469 m_manager->getAlignMode()) { |
466 drawAlignmentStatus(r, paint, workModel, haveWorkTitle); | 470 drawAlignmentStatus(r, paint, *workModel, haveWorkTitle); |
467 } | 471 } |
468 | 472 |
469 if (m_manager && | 473 if (m_manager && |
470 m_manager->shouldShowLayerNames()) { | 474 m_manager->shouldShowLayerNames()) { |
471 drawLayerNames(r, paint); | 475 drawLayerNames(r, paint); |
630 | 634 |
631 if (desc != "") { | 635 if (desc != "") { |
632 | 636 |
633 paint.save(); | 637 paint.save(); |
634 | 638 |
639 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested | |
640 // replacement (horizontalAdvance) was only added in Qt 5.11 | |
641 // which is too new for us | |
642 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
643 | |
635 int tabStop = | 644 int tabStop = |
636 paint.fontMetrics().width(tr("Some lengthy prefix:")); | 645 paint.fontMetrics().width(tr("Some lengthy prefix:")); |
637 | 646 |
638 QRect boundingRect = | 647 QRect boundingRect = |
639 paint.fontMetrics().boundingRect | 648 paint.fontMetrics().boundingRect |
748 PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); | 757 PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); |
749 } | 758 } |
750 } | 759 } |
751 | 760 |
752 void | 761 void |
753 Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model *model) | 762 Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model &model) |
754 { | 763 { |
755 paint.save(); | 764 paint.save(); |
756 | 765 |
757 QBrush brush; | 766 QBrush brush; |
758 | 767 |
762 } else { | 771 } else { |
763 brush = QBrush(QColor("#aa101010")); | 772 brush = QBrush(QColor("#aa101010")); |
764 paint.setPen(Qt::white); | 773 paint.setPen(Qt::white); |
765 } | 774 } |
766 | 775 |
767 sv_frame_t f0 = model->getStartFrame(); | 776 sv_frame_t f0 = model.getStartFrame(); |
768 | 777 |
769 if (f0 > getStartFrame() && f0 < getEndFrame()) { | 778 if (f0 > getStartFrame() && f0 < getEndFrame()) { |
770 int x0 = getXForFrame(f0); | 779 int x0 = getXForFrame(f0); |
771 if (x0 > r.x()) { | 780 if (x0 > r.x()) { |
772 paint.fillRect(0, 0, x0, height(), brush); | 781 paint.fillRect(0, 0, x0, height(), brush); |
773 paint.drawLine(x0, 0, x0, height()); | 782 paint.drawLine(x0, 0, x0, height()); |
774 } | 783 } |
775 } | 784 } |
776 | 785 |
777 sv_frame_t f1 = model->getEndFrame(); | 786 sv_frame_t f1 = model.getEndFrame(); |
778 | 787 |
779 if (f1 > getStartFrame() && f1 < getEndFrame()) { | 788 if (f1 > getStartFrame() && f1 < getEndFrame()) { |
780 int x1 = getXForFrame(f1); | 789 int x1 = getXForFrame(f1); |
781 if (x1 < r.x() + r.width()) { | 790 if (x1 < r.x() + r.width()) { |
782 paint.fillRect(x1, 0, width() - x1, height(), brush); | 791 paint.fillRect(x1, 0, width() - x1, height(), brush); |
786 | 795 |
787 paint.restore(); | 796 paint.restore(); |
788 } | 797 } |
789 | 798 |
790 void | 799 void |
791 Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model, | 800 Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model &model, |
792 bool down) | 801 bool down) |
793 { | 802 { |
794 const Model *reference = model->getAlignmentReference(); | 803 ModelId reference = model.getAlignmentReference(); |
795 /* | 804 /* |
796 if (!reference) { | 805 if (!reference) { |
797 cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl; | 806 cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl; |
798 } else if (reference == model) { | 807 } else if (reference == model.getId()) { |
799 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl; | 808 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl; |
800 } else { | 809 } else { |
801 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl; | 810 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl; |
802 } | 811 } |
803 */ | 812 */ |
804 QString text; | 813 QString text; |
805 int completion = 100; | 814 int completion = 100; |
806 | 815 |
807 if (reference == model) { | 816 if (reference == model.getId()) { |
808 text = tr("Reference"); | 817 text = tr("Reference"); |
809 } else if (!reference) { | 818 } else if (reference.isNone()) { |
810 text = tr("Unaligned"); | 819 text = tr("Unaligned"); |
811 } else { | 820 } else { |
812 completion = model->getAlignmentCompletion(); | 821 completion = model.getAlignmentCompletion(); |
813 if (completion == 0) { | 822 if (completion == 0) { |
814 text = tr("Unaligned"); | 823 text = tr("Unaligned"); |
815 } else if (completion < 100) { | 824 } else if (completion < 100) { |
816 text = tr("Aligning: %1%").arg(completion); | 825 text = tr("Aligning: %1%").arg(completion); |
817 } else { | 826 } else { |
846 View::modelAlignmentCompletionChanged(); | 855 View::modelAlignmentCompletionChanged(); |
847 update(QRect(0, 0, 300, 100)); | 856 update(QRect(0, 0, 300, 100)); |
848 } | 857 } |
849 | 858 |
850 void | 859 void |
851 Pane::drawWorkTitle(QRect r, QPainter &paint, const Model *model) | 860 Pane::drawWorkTitle(QRect r, QPainter &paint, const Model &model) |
852 { | 861 { |
853 QString title = model->getTitle(); | 862 QString title = model.getTitle(); |
854 QString maker = model->getMaker(); | 863 QString maker = model.getMaker(); |
855 //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl; | 864 //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl; |
856 if (title == "") return; | 865 if (title == "") return; |
857 | 866 |
858 QString text = title; | 867 QString text = title; |
859 if (maker != "") { | 868 if (maker != "") { |
1023 } | 1032 } |
1024 paint.restore(); | 1033 paint.restore(); |
1025 } | 1034 } |
1026 | 1035 |
1027 void | 1036 void |
1028 Pane::drawDurationAndRate(QRect r, const Model *waveformModel, | 1037 Pane::drawDurationAndRate(QRect r, const Model &waveformModel, |
1029 sv_samplerate_t sampleRate, QPainter &paint) | 1038 sv_samplerate_t sampleRate, QPainter &paint) |
1030 { | 1039 { |
1031 int fontHeight = paint.fontMetrics().height(); | 1040 int fontHeight = paint.fontMetrics().height(); |
1032 int fontAscent = paint.fontMetrics().ascent(); | 1041 int fontAscent = paint.fontMetrics().ascent(); |
1033 | 1042 |
1034 if (r.y() + r.height() < height() - fontHeight - 6) return; | 1043 if (r.y() + r.height() < height() - fontHeight - 6) return; |
1035 | 1044 |
1036 sv_samplerate_t modelRate = waveformModel->getSampleRate(); | 1045 sv_samplerate_t modelRate = waveformModel.getSampleRate(); |
1037 sv_samplerate_t nativeRate = waveformModel->getNativeRate(); | 1046 sv_samplerate_t nativeRate = waveformModel.getNativeRate(); |
1038 sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate(); | 1047 sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate(); |
1039 | 1048 |
1040 QString srNote = ""; | 1049 QString srNote = ""; |
1041 | 1050 |
1042 // Show (R) for waveform models that have been resampled during | 1051 // Show (R) for waveform models that have been resampled during |
1051 srNote = " " + tr("(R)"); | 1060 srNote = " " + tr("(R)"); |
1052 } | 1061 } |
1053 } | 1062 } |
1054 | 1063 |
1055 QString desc = tr("%1 / %2Hz%3") | 1064 QString desc = tr("%1 / %2Hz%3") |
1056 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(), | 1065 .arg(RealTime::frame2RealTime(waveformModel.getEndFrame(), |
1057 sampleRate) | 1066 sampleRate) |
1058 .toText(false).c_str()) | 1067 .toText(false).c_str()) |
1059 .arg(nativeRate) | 1068 .arg(nativeRate) |
1060 .arg(srNote); | 1069 .arg(srNote); |
1061 | 1070 |