# HG changeset patch # User Chris Cannam # Date 1537537613 -3600 # Node ID bc44b520405f86336f6bc41f7a4e88ac17f2ccad # Parent 0e4551fd7f1407890d0bf17a9628a7ed9a74bb08 Factor out paintChannelScaleGuides diff -r 0e4551fd7f14 -r bc44b520405f layer/WaveformLayer.cpp --- a/layer/WaveformLayer.cpp Fri Sep 21 14:33:43 2018 +0100 +++ b/layer/WaveformLayer.cpp Fri Sep 21 14:46:53 2018 +0100 @@ -698,58 +698,10 @@ my = m + (((ch - minChannel) * h) / channels); } - - paint->setPen(greys[1]); paint->drawLine(x0, my, x1, my); - int n = 10; - int py = -1; - - if (v->hasLightBackground() && - v->getViewManager() && - v->getViewManager()->shouldShowScaleGuides()) { - - paint->setPen(QColor(240, 240, 240)); - - for (int i = 1; i < n; ++i) { - - double val = 0.0, nval = 0.0; - - switch (m_scale) { - - case LinearScale: - val = (i * gain) / n; - if (i > 0) nval = -val; - break; - - case MeterScale: - val = AudioLevel::dB_to_multiplier(meterdbs[i]) * gain; - break; - - case dBScale: - val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10) * gain; - break; - } - - if (val < -1.0 || val > 1.0) continue; - - int y = getYForValue(v, val, ch); - - if (py >= 0 && abs(y - py) < 10) continue; - else py = y; - - int ny = y; - if (nval != 0.0) { - ny = getYForValue(v, nval, ch); - } - - paint->drawLine(x0, y, x1, y); - if (ny != y) { - paint->drawLine(x0, ny, x1, ny); - } - } - } + paintChannelScaleGuides(v, paint, rect, ch); int rangeix = ch - minChannel; @@ -982,6 +934,69 @@ } } +void +WaveformLayer::paintChannelScaleGuides(LayerGeometryProvider *v, + QPainter *paint, + QRect rect, + int ch) const +{ + int x0 = rect.left(); + int y0 = rect.top(); + + int x1 = rect.right(); + int y1 = rect.bottom(); + + int n = 10; + int py = -1; + + double gain = m_effectiveGains[ch]; + + if (v->hasLightBackground() && + v->getViewManager() && + v->getViewManager()->shouldShowScaleGuides()) { + + paint->setPen(QColor(240, 240, 240)); + + for (int i = 1; i < n; ++i) { + + double val = 0.0, nval = 0.0; + + switch (m_scale) { + + case LinearScale: + val = (i * gain) / n; + if (i > 0) nval = -val; + break; + + case MeterScale: + val = AudioLevel::dB_to_multiplier(meterdbs[i]) * gain; + break; + + case dBScale: + val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10) * gain; + break; + } + + if (val < -1.0 || val > 1.0) continue; + + int y = getYForValue(v, val, ch); + + if (py >= 0 && abs(y - py) < 10) continue; + else py = y; + + int ny = y; + if (nval != 0.0) { + ny = getYForValue(v, nval, ch); + } + + paint->drawLine(x0, y, x1, y); + if (ny != y) { + paint->drawLine(x0, ny, x1, ny); + } + } + } +} + QString WaveformLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { diff -r 0e4551fd7f14 -r bc44b520405f layer/WaveformLayer.h --- a/layer/WaveformLayer.h Fri Sep 21 14:33:43 2018 +0100 +++ b/layer/WaveformLayer.h Fri Sep 21 14:46:53 2018 +0100 @@ -218,6 +218,9 @@ const std::vector &ranges, int blockSize, sv_frame_t frame0, sv_frame_t frame1) const; + + void paintChannelScaleGuides(LayerGeometryProvider *, QPainter *paint, + QRect rect, int channel) const; int getYForValue(const LayerGeometryProvider *v, double value, int channel) const;