changeset 214:8520b7918104

* Fix overzealous cacheing in waveform layer that was leading to inaccurate positioning of view rects & playback pointer on overview widget sometimes
author Chris Cannam
date Thu, 01 Mar 2007 17:12:50 +0000
parents df791d8c8f58
children d2334a77db73
files layer/WaveformLayer.cpp view/Overview.cpp
diffstat 2 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/layer/WaveformLayer.cpp	Thu Mar 01 15:35:27 2007 +0000
+++ b/layer/WaveformLayer.cpp	Thu Mar 01 17:12:50 2007 +0000
@@ -466,20 +466,30 @@
 
     if (m_aggressive) {
 
+#ifdef DEBUG_WAVEFORM_PAINT
+        std::cerr << "WaveformLayer::paint: aggressive is true" << std::endl;
+#endif
+
 	if (m_cacheValid && (zoomLevel != m_cacheZoomLevel)) {
 	    m_cacheValid = false;
 	}
 
+	if (!m_cache || m_cache->width() != w || m_cache->height() != h) {
+#ifdef DEBUG_WAVEFORM_PAINT
+            if (m_cache) {
+                std::cerr << "WaveformLayer::paint: cache size " << m_cache->width() << "x" << m_cache->height() << " differs from view size " << w << "x" << h << ": regenerating aggressive cache" << std::endl;
+            }
+#endif
+	    delete m_cache;
+	    m_cache = new QPixmap(w, h);
+            m_cacheValid = false;
+	}
+
 	if (m_cacheValid) {
 	    viewPainter.drawPixmap(rect, *m_cache, rect);
 	    return;
 	}
 
-	if (!m_cache || m_cache->width() != w || m_cache->height() != h) {
-	    delete m_cache;
-	    m_cache = new QPixmap(w, h);
-	}
-
 	paint = new QPainter(m_cache);
 
 	paint->setPen(Qt::NoPen);
--- a/view/Overview.cpp	Thu Mar 01 15:35:27 2007 +0000
+++ b/view/Overview.cpp	Thu Mar 01 17:12:50 2007 +0000
@@ -101,6 +101,8 @@
 {
     // Recalculate zoom in case the size of the widget has changed.
 
+//    std::cerr << "Overview::paintEvent: width is " << width() << ", centre frame " << m_centreFrame << std::endl;
+
     size_t startFrame = getModelsStartFrame();
     size_t frameCount = getModelsEndFrame() - getModelsStartFrame();
     int zoomLevel = frameCount / width();
@@ -116,7 +118,10 @@
 	centreFrame = (startFrame + getModelsEndFrame())/2;
     }
     if (centreFrame != m_centreFrame) {
+//        std::cerr << "Overview::paintEvent: Centre frame changed from "
+//                  << m_centreFrame << " to " << centreFrame << " and thus start frame from " << getStartFrame();
 	m_centreFrame = centreFrame;
+//        std::cerr << " to " << getStartFrame() << std::endl;
 	emit centreFrameChanged(m_centreFrame, false, PlaybackIgnore);
     }