changeset 1044:4e5c1c326794 3.0-integration

Make ViewProxy objects share the ids of their Views; fixes incorrect colour scale drawing
author Chris Cannam
date Tue, 09 Feb 2016 10:59:36 +0000
parents fccee028a522
children f535f6e5dbb0 40480e4bab6a
files layer/SpectrogramLayer.cpp view/LayerGeometryProvider.h view/View.cpp view/View.h view/ViewProxy.h
diffstat 5 files changed, 49 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Thu Feb 04 11:18:08 2016 +0000
+++ b/layer/SpectrogramLayer.cpp	Tue Feb 09 10:59:36 2016 +0000
@@ -48,7 +48,7 @@
 #include <alloca.h>
 #endif
 
-//#define DEBUG_SPECTROGRAM_REPAINT 1
+#define DEBUG_SPECTROGRAM_REPAINT 1
 
 using namespace std;
 
@@ -582,6 +582,9 @@
 void
 SpectrogramLayer::invalidateImageCaches()
 {
+#ifdef DEBUG_SPECTROGRAM
+    cerr << "SpectrogramLayer::invalidateImageCaches called" << endl;
+#endif
     for (ViewImageCache::iterator i = m_imageCaches.begin();
          i != m_imageCaches.end(); ++i) {
         i->second.invalidate();
@@ -1535,6 +1538,9 @@
 void
 SpectrogramLayer::invalidateFFTModels()
 {
+#ifdef DEBUG_SPECTROGRAM
+    cerr << "SpectrogramLayer::invalidateFFTModels called" << endl;
+#endif
     for (ViewFFTMap::iterator i = m_fftModels.begin();
          i != m_fftModels.end(); ++i) {
         delete i->second;
@@ -1557,6 +1563,9 @@
 void
 SpectrogramLayer::invalidateMagnitudes()
 {
+#ifdef DEBUG_SPECTROGRAM
+    cerr << "SpectrogramLayer::invalidateMagnitudes called" << endl;
+#endif
     m_viewMags.clear();
     for (vector<MagnitudeRange>::iterator i = m_columnMags.begin();
          i != m_columnMags.end(); ++i) {
@@ -1597,7 +1606,9 @@
 
 #ifdef DEBUG_SPECTROGRAM_REPAINT
     cerr << "SpectrogramLayer::updateViewMagnitudes returning from cols "
-              << s0 << " -> " << s1 << " inclusive" << endl;
+         << s0 << " -> " << s1 << " inclusive" << endl;
+    cerr << "SpectrogramLayer::updateViewMagnitudes: for view id " << v->getId()
+         << ": min is " << mag.getMin() << ", max is " << mag.getMax() << endl;
 #endif
 
     if (!mag.isSet()) return false;
@@ -3123,6 +3134,12 @@
         double dBmin = AudioLevel::multiplier_to_dB(min);
         double dBmax = AudioLevel::multiplier_to_dB(max);
 
+#ifdef DEBUG_SPECTROGRAM_REPAINT
+        cerr << "paintVerticalScale: for view id " << v->getId()
+             << ": min = " << min << ", max = " << max
+             << ", dBmin = " << dBmin << ", dBmax = " << dBmax << endl;
+#endif
+        
         if (dBmax < -60.f) dBmax = -60.f;
         else top = QString("%1").arg(lrint(dBmax));
 
--- a/view/LayerGeometryProvider.h	Thu Feb 04 11:18:08 2016 +0000
+++ b/view/LayerGeometryProvider.h	Tue Feb 09 10:59:36 2016 +0000
@@ -27,20 +27,32 @@
 
 class LayerGeometryProvider
 {
-public:
-    LayerGeometryProvider() {
+protected:
+    static int getNextId() {
         static QMutex idMutex;
         static int nextId = 1;
+        static int maxId = INT_MAX;
         QMutexLocker locker(&idMutex);
-        m_id = nextId;
-        nextId++;
-    }
+        int id = nextId;
+        if (nextId == maxId) {
+            // we don't expect this to happen in the lifetime of a
+            // process, but it would be undefined behaviour if it did
+            // since we're using a signed int, so we should really
+            // guard for it...
+            nextId = 1;
+        } else {
+            nextId++;
+        }
+        return id;
+    }            
+    
+public:
+    LayerGeometryProvider() { }
     
     /**
-     * Retrieve the id of this object. Each LayerGeometryProvider has
-     * a separate id.
+     * Retrieve the id of this object.
      */
-    int getId() const { return m_id; }
+    virtual int getId() const = 0;
 
     /**
      * Retrieve the first visible sample frame on the widget.
@@ -157,9 +169,6 @@
     
     virtual View *getView() = 0;
     virtual const View *getView() const = 0;
-
-private:
-    int m_id;
 };
 
 #endif
--- a/view/View.cpp	Thu Feb 04 11:18:08 2016 +0000
+++ b/view/View.cpp	Tue Feb 09 10:59:36 2016 +0000
@@ -51,6 +51,7 @@
 
 View::View(QWidget *w, bool showProgress) :
     QFrame(w),
+    m_id(getNextId()),
     m_centreFrame(0),
     m_zoomLevel(1024),
     m_followPan(true),
--- a/view/View.h	Thu Feb 04 11:18:08 2016 +0000
+++ b/view/View.h	Tue Feb 09 10:59:36 2016 +0000
@@ -62,6 +62,12 @@
      * be managed elsewhere (e.g. by the Document).
      */
     virtual ~View();
+
+    /**
+     * Retrieve the id of this object. Views have their own unique
+     * ids, but ViewProxy objects share the id of their View.
+     */
+    int getId() const { return m_id; }
     
     /**
      * Retrieve the first visible sample frame on the widget.
--- a/view/ViewProxy.h	Thu Feb 04 11:18:08 2016 +0000
+++ b/view/ViewProxy.h	Tue Feb 09 10:59:36 2016 +0000
@@ -23,6 +23,9 @@
     ViewProxy(View *view, int scaleFactor) :
 	m_view(view), m_scaleFactor(scaleFactor) { }
 
+    virtual int getId() const {
+        return m_view->getId();
+    }
     virtual sv_frame_t getStartFrame() const {
 	return m_view->getStartFrame();
     }