changeset 754:efbb6b8f943b tony_integration

Merge from branch tonioni
author Chris Cannam
date Mon, 31 Mar 2014 13:00:42 +0100
parents b6dc57688c72 (diff) 394caa98d21a (current diff)
children 2cd6d2d17437
files
diffstat 3 files changed, 68 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Mon Mar 31 10:20:21 2014 +0100
+++ b/layer/Colour3DPlotLayer.cpp	Mon Mar 31 13:00:42 2014 +0100
@@ -579,6 +579,13 @@
     return true;
 }
 
+bool
+Colour3DPlotLayer::getYScaleValue(const View *v, int y,
+                                  float &value, QString &unit) const
+{
+    return false;//!!!
+}
+
 int
 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const
 {
@@ -952,6 +959,7 @@
     size_t cacheHeight = m_model->getHeight();
 
     if (m_cache && (m_cache->height() != int(cacheHeight))) {
+        // height has changed: delete everything rather than resizing
         delete m_cache;
         delete m_peaksCache;
         m_cache = 0;
@@ -959,6 +967,7 @@
     } 
 
     if (m_cache && (m_cache->width() != int(cacheWidth))) {
+        // width has changed and we have an existing cache: resize it
         QImage *newCache =
             new QImage(m_cache->copy(0, 0, cacheWidth, cacheHeight));
         delete m_cache;
@@ -966,7 +975,7 @@
         if (m_peaksCache) {
             QImage *newPeaksCache =
                 new QImage(m_peaksCache->copy
-                           (0, 0, cacheWidth / m_peakResolution, cacheHeight));
+                           (0, 0, cacheWidth / m_peakResolution + 1, cacheHeight));
             delete m_peaksCache;
             m_peaksCache = newPeaksCache;
         }
@@ -991,6 +1000,9 @@
         m_cacheValidEnd = 0;
     }
 
+//    cerr << "cache size = " << m_cache->width() << "x" << m_cache->height()
+//         << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl;
+
     if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) {
 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
         cerr << "Cache is valid in this region already" << endl;
@@ -1117,6 +1129,12 @@
 	
         values = getColumn(c);
 
+        if (c >= m_cache->width()) {
+            cerr << "ERROR: column " << c << " >= cache width "
+                 << m_cache->width() << endl;
+            continue;
+        }
+
         for (size_t y = 0; y < cacheHeight; ++y) {
 
             float value = min;
@@ -1145,7 +1163,11 @@
             if (m_invertVertical) {
                 m_cache->setPixel(c, cacheHeight - y - 1, pixel);
             } else {
-                m_cache->setPixel(c, y, pixel);
+                if (y >= m_cache->height()) {
+                    cerr << "ERROR: row " << y << " >= cache height " << m_cache->height() << endl;
+                } else {
+                    m_cache->setPixel(c, y, pixel);
+                }
             }
         }
 
@@ -1153,11 +1175,23 @@
             size_t notch = (c % m_peakResolution);
             if (notch == m_peakResolution-1 || c == fillEnd) {
                 size_t pc = c / m_peakResolution;
+                if (pc >= m_peaksCache->width()) {
+                    cerr << "ERROR: peak column " << pc
+                         << " (from col " << c << ") >= peaks cache width "
+                         << m_peaksCache->width() << endl;
+                    continue;
+                }
                 for (size_t y = 0; y < cacheHeight; ++y) {
                     if (m_invertVertical) {
                         m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]);
                     } else {
-                        m_peaksCache->setPixel(pc, y, peaks[y]);
+                        if (y >= m_peaksCache->height()) {
+                            cerr << "ERROR: row " << y
+                                 << " >= peaks cache height "
+                                 << m_peaksCache->height() << endl;
+                        } else {
+                            m_peaksCache->setPixel(pc, y, peaks[y]);
+                        }
                     }
                 }
                 for (int y = 0; y < cacheHeight; ++y) {
--- a/layer/Colour3DPlotLayer.h	Mon Mar 31 10:20:21 2014 +0100
+++ b/layer/Colour3DPlotLayer.h	Mon Mar 31 13:00:42 2014 +0100
@@ -151,6 +151,9 @@
     virtual bool getDisplayExtents(float &min, float &max) const;
     virtual bool setDisplayExtents(float min, float max);
 
+    virtual bool getYScaleValue(const View *, int /* y */,
+                                float &/* value */, QString &/* unit */) const;
+
     virtual int getVerticalZoomSteps(int &defaultStep) const;
     virtual int getCurrentVerticalZoomStep() const;
     virtual void setVerticalZoomStep(int);
@@ -188,17 +191,32 @@
     bool        m_smooth;
     size_t      m_peakResolution;
 
+    // Minimum and maximum bin numbers visible within the view. We
+    // always snap to whole bins at view edges.
     int         m_miny;
     int         m_maxy;
+
+    /**
+     * Return the y coordinate at which the given bin "starts"
+     * (i.e. at the bottom of the bin, if the given bin is an integer
+     * and the vertical scale is the usual way up). Bin number may be
+     * fractional, to obtain a position part-way through a bin.
+     */
+    float getYForBin(View *, float bin) const;
+
+    /**
+     * Return the bin number, possibly fractional, at the given y
+     * coordinate. Note that the whole numbers occur at the positions
+     * at which the bins "start" (i.e. the bottom of the visible bin,
+     * if the vertical scale is the usual way up).
+     */
+    float getBinForY(View *, float y) const;
     
     DenseThreeDimensionalModel::Column getColumn(size_t col) const;
 
     int getColourScaleWidth(QPainter &) const;
     void fillCache(size_t firstBin, size_t lastBin) const;
     void paintDense(View *v, QPainter &paint, QRect rect) const;
-
-    float getYForBin(View *, float bin) const;
-    float getBinForY(View *, float y) const;
 };
 
 #endif
--- a/layer/SpectrogramLayer.cpp	Mon Mar 31 10:20:21 2014 +0100
+++ b/layer/SpectrogramLayer.cpp	Mon Mar 31 13:00:42 2014 +0100
@@ -3459,6 +3459,11 @@
 
         return n;
     }
+    
+    virtual int getPositionForValueUnclamped(float value) const {
+        // We don't really support this
+        return getPositionForValue(value);
+    }
 
     virtual float getValueForPosition(int position) const {
 
@@ -3478,6 +3483,11 @@
         return dist;
     }
     
+    virtual float getValueForPositionUnclamped(int position) const {
+        // We don't really support this
+        return getValueForPosition(position);
+    }
+
     virtual QString getUnit() const { return "Hz"; }
 
 protected: