comparison layer/WaveformLayer.cpp @ 1335:bc44b520405f zoom

Factor out paintChannelScaleGuides
author Chris Cannam
date Fri, 21 Sep 2018 14:46:53 +0100
parents 0e4551fd7f14
children 43296804c473
comparison
equal deleted inserted replaced
1334:0e4551fd7f14 1335:bc44b520405f
696 m_channelMode != MergeChannels) { 696 m_channelMode != MergeChannels) {
697 m = (h / channels); 697 m = (h / channels);
698 my = m + (((ch - minChannel) * h) / channels); 698 my = m + (((ch - minChannel) * h) / channels);
699 } 699 }
700 700
701
702
703 paint->setPen(greys[1]); 701 paint->setPen(greys[1]);
704 paint->drawLine(x0, my, x1, my); 702 paint->drawLine(x0, my, x1, my);
705 703
706 int n = 10; 704 paintChannelScaleGuides(v, paint, rect, ch);
707 int py = -1;
708
709 if (v->hasLightBackground() &&
710 v->getViewManager() &&
711 v->getViewManager()->shouldShowScaleGuides()) {
712
713 paint->setPen(QColor(240, 240, 240));
714
715 for (int i = 1; i < n; ++i) {
716
717 double val = 0.0, nval = 0.0;
718
719 switch (m_scale) {
720
721 case LinearScale:
722 val = (i * gain) / n;
723 if (i > 0) nval = -val;
724 break;
725
726 case MeterScale:
727 val = AudioLevel::dB_to_multiplier(meterdbs[i]) * gain;
728 break;
729
730 case dBScale:
731 val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10) * gain;
732 break;
733 }
734
735 if (val < -1.0 || val > 1.0) continue;
736
737 int y = getYForValue(v, val, ch);
738
739 if (py >= 0 && abs(y - py) < 10) continue;
740 else py = y;
741
742 int ny = y;
743 if (nval != 0.0) {
744 ny = getYForValue(v, nval, ch);
745 }
746
747 paint->drawLine(x0, y, x1, y);
748 if (ny != y) {
749 paint->drawLine(x0, ny, x1, ny);
750 }
751 }
752 }
753 705
754 int rangeix = ch - minChannel; 706 int rangeix = ch - minChannel;
755 707
756 for (int x = x0; x <= x1; ++x) { 708 for (int x = x0; x <= x1; ++x) {
757 709
977 paint->drawLine(x, meanBottom, x, meanTop); 929 paint->drawLine(x, meanBottom, x, meanTop);
978 } 930 }
979 931
980 prevRangeBottom = rangeBottom; 932 prevRangeBottom = rangeBottom;
981 prevRangeTop = rangeTop; 933 prevRangeTop = rangeTop;
934 }
935 }
936
937 void
938 WaveformLayer::paintChannelScaleGuides(LayerGeometryProvider *v,
939 QPainter *paint,
940 QRect rect,
941 int ch) const
942 {
943 int x0 = rect.left();
944 int y0 = rect.top();
945
946 int x1 = rect.right();
947 int y1 = rect.bottom();
948
949 int n = 10;
950 int py = -1;
951
952 double gain = m_effectiveGains[ch];
953
954 if (v->hasLightBackground() &&
955 v->getViewManager() &&
956 v->getViewManager()->shouldShowScaleGuides()) {
957
958 paint->setPen(QColor(240, 240, 240));
959
960 for (int i = 1; i < n; ++i) {
961
962 double val = 0.0, nval = 0.0;
963
964 switch (m_scale) {
965
966 case LinearScale:
967 val = (i * gain) / n;
968 if (i > 0) nval = -val;
969 break;
970
971 case MeterScale:
972 val = AudioLevel::dB_to_multiplier(meterdbs[i]) * gain;
973 break;
974
975 case dBScale:
976 val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10) * gain;
977 break;
978 }
979
980 if (val < -1.0 || val > 1.0) continue;
981
982 int y = getYForValue(v, val, ch);
983
984 if (py >= 0 && abs(y - py) < 10) continue;
985 else py = y;
986
987 int ny = y;
988 if (nval != 0.0) {
989 ny = getYForValue(v, nval, ch);
990 }
991
992 paint->drawLine(x0, y, x1, y);
993 if (ny != y) {
994 paint->drawLine(x0, ny, x1, ny);
995 }
996 }
982 } 997 }
983 } 998 }
984 999
985 QString 1000 QString
986 WaveformLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const 1001 WaveformLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const