changeset 1335:bc44b520405f zoom

Factor out paintChannelScaleGuides
author Chris Cannam
date Fri, 21 Sep 2018 14:46:53 +0100
parents 0e4551fd7f14
children 43296804c473
files layer/WaveformLayer.cpp layer/WaveformLayer.h
diffstat 2 files changed, 67 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- 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
 {
--- 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<RangeSummarisableTimeValueModel::RangeBlock> &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;