diff layer/WaveformLayer.cpp @ 1372:2c01be836570

Short-circuit drawing a little bit for contiguous ranges
author Chris Cannam
date Fri, 02 Nov 2018 15:23:53 +0000
parents ca9a36a5ab76
children cca66ce390e0
line wrap: on
line diff
--- a/layer/WaveformLayer.cpp	Fri Nov 02 15:23:42 2018 +0000
+++ b/layer/WaveformLayer.cpp	Fri Nov 02 15:23:53 2018 +0000
@@ -801,6 +801,7 @@
     vector<QPointF> individualSamplePoints;
 
     bool firstPoint = true;
+    double prevRangeBottom = 0, prevRangeTop = 0;
     
     for (int x = x0; x <= x1; ++x) {
 
@@ -986,20 +987,30 @@
                 individualSamplePoints.push_back(QPointF(px, rangeBottom));
             }
         }
+
+        bool contiguous = true;
+        if (rangeTop > prevRangeBottom + 0.5 ||
+            rangeBottom < prevRangeTop - 0.5) {
+            contiguous = false;
+        }
         
-        if (firstPoint) {
-            waveformPath = QPainterPath(QPointF(px, rangeMiddle));
-            firstPoint = false;
+        if (firstPoint || (contiguous && !trivialRange)) {
+            waveformPath.moveTo(QPointF(px, rangeTop));
+            waveformPath.lineTo(QPointF(px, rangeBottom));
+            waveformPath.moveTo(QPointF(px, rangeMiddle));
         } else {
             waveformPath.lineTo(QPointF(px, rangeMiddle));
+            if (!trivialRange) {
+                waveformPath.lineTo(QPointF(px, rangeTop));
+                waveformPath.lineTo(QPointF(px, rangeBottom));
+                waveformPath.lineTo(QPointF(px, rangeMiddle));
+            }
         }
 
-        if (!trivialRange) {
-            waveformPath.lineTo(QPointF(px, rangeTop));
-            waveformPath.lineTo(QPointF(px, rangeBottom));
-            waveformPath.lineTo(QPointF(px, rangeMiddle));
-        }
-
+        firstPoint = false;
+        prevRangeTop = rangeTop;
+        prevRangeBottom = rangeBottom;
+        
         if (drawMean) {
             meanPath.moveTo(QPointF(px, meanBottom));
             meanPath.lineTo(QPointF(px, meanTop));