changeset 137:10a82b2bbb8b

* experiment with finer zoom level changes when using h thumbwheel
author Chris Cannam
date Tue, 22 Aug 2006 14:18:28 +0000
parents a859b87162ca
children 0f1ac9562c76
files layer/Layer.h layer/SpectrogramLayer.cpp view/Pane.cpp view/View.cpp
diffstat 4 files changed, 107 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Layer.h	Mon Aug 21 16:26:35 2006 +0000
+++ b/layer/Layer.h	Tue Aug 22 14:18:28 2006 +0000
@@ -55,7 +55,23 @@
 	return const_cast<Model *>(const_cast<const Layer *>(this)->getModel());
     }
 
+    /**
+     * Return a zoom constraint object defining the supported zoom
+     * levels for this layer.  If this returns zero, the layer will
+     * support any integer zoom level.
+     */
     virtual const ZoomConstraint *getZoomConstraint() const { return 0; }
+
+    /**
+     * Return true if this layer can handle zoom levels other than
+     * those supported by its zoom constraint (presumably less
+     * efficiently or accurately than the officially supported zoom
+     * levels).  If true, the layer will unenthusistically accept any
+     * integer zoom level from 1 to the maximum returned by its zoom
+     * constraint.
+     */
+    virtual bool supportsOtherZoomLevels() const { return true; }
+
     virtual void paint(View *, QPainter &, QRect) const = 0;   
 
     enum VerticalPosition {
--- a/layer/SpectrogramLayer.cpp	Mon Aug 21 16:26:35 2006 +0000
+++ b/layer/SpectrogramLayer.cpp	Tue Aug 22 14:18:28 2006 +0000
@@ -1979,6 +1979,10 @@
 
     fft->suspendWrites();
 
+#ifdef DEBUG_SPECTROGRAM_REPAINT
+    std::cerr << (float(v->getFrameForX(1) - v->getFrameForX(0)) / increment) << " bins per pixel" << std::endl;
+#endif
+
     for (int x = 0; x < w; ++x) {
 
 	for (int y = 0; y < h; ++y) {
@@ -2112,6 +2116,8 @@
         std::cerr << "Overall mag unchanged at [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << std::endl;
     }
 
+    Profiler profiler2("SpectrogramLayer::paint: draw image", true);
+
     paint.drawImage(x0, y0, m_drawBuffer, 0, 0, w, h);
 
     if (recreateWholePixmapCache) {
--- a/view/Pane.cpp	Mon Aug 21 16:26:35 2006 +0000
+++ b/view/Pane.cpp	Tue Aug 22 14:18:28 2006 +0000
@@ -110,13 +110,44 @@
     int current = 0;
     int level = 1;
 
-    while (true) {
-        if (getZoomLevel() == level) current = count;
-        int newLevel = getZoomConstraintBlockSize(level + 1,
-                                                  ZoomConstraint::RoundUp);
-        if (newLevel == level) break;
-        level = newLevel;
-        if (++count == 50) break;
+    //!!! pull out into function (presumably in View)
+    bool haveConstraint = false;
+    for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
+         ++i) {
+        if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
+            haveConstraint = true;
+            break;
+        }
+    }
+
+    if (haveConstraint) {
+        while (true) {
+            if (getZoomLevel() == level) current = count;
+            int newLevel = getZoomConstraintBlockSize(level + 1,
+                                                      ZoomConstraint::RoundUp);
+            if (newLevel == level) break;
+            level = newLevel;
+            if (++count == 50) break;
+        }
+    } else {
+        // if we have no particular constraints, we can really spread out
+        while (true) {
+            if (getZoomLevel() >= level) current = count;
+            int step = level / 10;
+            int pwr = 0;
+            while (step > 0) {
+                ++pwr;
+                step /= 2;
+            }
+            step = 1;
+            while (pwr > 0) {
+                step *= 2;
+                --pwr;
+            }
+            std::cerr << level << std::endl;
+            level += step;
+            if (++count == 100 || level > 262144) break;
+        }
     }
 
 //    std::cerr << "Have " << count << " zoom levels" << std::endl;
@@ -1175,18 +1206,52 @@
 void
 Pane::horizontalThumbwheelMoved(int value)
 {
+    //!!! dupe with updateHeadsUpDisplay
+
     int count = 0;
     int level = 1;
-    while (true) {
-        if (m_hthumb->getMaximumValue() - value == count) break;
-        int newLevel = getZoomConstraintBlockSize(level + 1,
-                                                  ZoomConstraint::RoundUp);
-        if (newLevel == level) break;
-        level = newLevel;
-        ++count;
+
+
+    //!!! pull out into function (presumably in View)
+    bool haveConstraint = false;
+    for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
+         ++i) {
+        if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
+            haveConstraint = true;
+            break;
+        }
     }
 
-//    std::cerr << "new level is " << level << std::endl;
+    if (haveConstraint) {
+        while (true) {
+            if (m_hthumb->getMaximumValue() - value == count) break;
+            int newLevel = getZoomConstraintBlockSize(level + 1,
+                                                      ZoomConstraint::RoundUp);
+            if (newLevel == level) break;
+            level = newLevel;
+            if (++count == 50) break;
+        }
+    } else {
+        while (true) {
+            if (m_hthumb->getMaximumValue() - value == count) break;
+            int step = level / 10;
+            int pwr = 0;
+            while (step > 0) {
+                ++pwr;
+                step /= 2;
+            }
+            step = 1;
+            while (pwr > 0) {
+                step *= 2;
+                --pwr;
+            }
+//            std::cerr << level << std::endl;
+            level += step;
+            if (++count == 100 || level > 262144) break;
+        }
+    }
+        
+    std::cerr << "new level is " << level << std::endl;
     setZoomLevel(level);
 }    
 
--- a/view/View.cpp	Mon Aug 21 16:26:35 2006 +0000
+++ b/view/View.cpp	Tue Aug 22 14:18:28 2006 +0000
@@ -1114,8 +1114,13 @@
     }
 
     // ensure our constraints are met
+
+/*!!! Should we do this only if we have layers that can't support other
+  zoom levels?
+
     m_zoomLevel = getZoomConstraintBlockSize(m_zoomLevel,
 					     ZoomConstraint::RoundUp);
+*/
 
     QPainter paint;
     bool repaintCache = false;