changeset 1120:65cdaf8d6b50 spectrogram-minor-refactor

Toward updating mag cache
author Chris Cannam
date Wed, 20 Jul 2016 13:40:23 +0100
parents be5b91ec81a0
children d930ff725f64
files layer/Colour3DPlotRenderer.cpp layer/ScrollableMagRangeCache.cpp layer/ScrollableMagRangeCache.h
diffstat 3 files changed, 61 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotRenderer.cpp	Wed Jul 20 08:42:04 2016 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Wed Jul 20 13:40:23 2016 +0100
@@ -30,7 +30,7 @@
 
 #include <vector>
 
-//#define DEBUG_SPECTROGRAM_REPAINT 1
+#define DEBUG_SPECTROGRAM_REPAINT 1 //!!! name
 
 using namespace std;
 
@@ -76,25 +76,37 @@
         // fiddly for partial paints otherwise.
         timeConstrained = false;
     }
-    
-    if (renderType == DirectTranslucent) {
-        renderDirectTranslucent(v, paint, rect);
-        return { rect, {} }; //!!! this return arg is not very useful
-    }
 
-    sv_frame_t startFrame = v->getStartFrame();
-    
     int x0 = v->getXForViewX(rect.x());
     int x1 = v->getXForViewX(rect.x() + rect.width());
     if (x0 < 0) x0 = 0;
     if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth();
 
+    sv_frame_t startFrame = v->getStartFrame();
+    
     m_cache.resize(v->getPaintSize());
     m_cache.setZoomLevel(v->getZoomLevel());
 
     m_magCache.resize(v->getPaintSize().width());
     m_magCache.setZoomLevel(v->getZoomLevel());
     
+    if (renderType == DirectTranslucent) {
+        renderDirectTranslucent(v, paint, rect);
+        //!!! mag range!
+
+        //!!! a dev debug check
+        if (!m_magCache.areColumnsSet(x0, x1 - x0)) {
+            cerr << "Columns (" << x0 << " -> " << x1-x0
+                 << ") not set in mag cache" << endl;
+            throw std::logic_error("Columns not set in mag cache");
+        }
+
+        //!!! this is wrong
+        MagnitudeRange range = m_magCache.getRange(x0, x1-x0);
+
+        return { rect, range }; //!!! this return arg is not very useful
+    }
+    
     cerr << "cache start " << m_cache.getStartFrame()
          << " valid left " << m_cache.getValidLeft()
          << " valid right " << m_cache.getValidRight()
@@ -216,8 +228,17 @@
         //!!! then fix
         throw std::logic_error("internal error: failed to render entire requested rect even when not time-constrained");
     }
+
+    //!!! a dev debug check
+    if (!m_magCache.areColumnsSet(x0, x1 - x0)) {
+        cerr << "Columns (" << x0 << " -> " << x1-x0
+             << ") not set in mag cache" << endl;
+        throw std::logic_error("Columns not set in mag cache");
+    }
     
-    return { pr, {} };
+    MagnitudeRange range = m_magCache.getRange(x0, x1-x0);
+    
+    return { pr, range };
 
     //!!! todo: timing/incomplete paint
 
@@ -719,6 +740,10 @@
         // source column index
         
         ++columnCount;
+
+#ifdef DEBUG_SPECTROGRAM_REPAINT
+        cerr << "x = " << x << endl;
+#endif
         
         if (binforx[x] < 0) continue;
 
@@ -761,6 +786,13 @@
 //                    column = ColumnOp::fftScale(column, m_fftSize);
 //                }
 
+                MagnitudeRange r;
+                r.sample(column);
+                int magColIndex = sx - int(m_magCache.getStartFrame() /
+                                           sourceModel->getResolution());
+                cerr << "magColIndex = " << magColIndex << endl;
+                m_magCache.sampleColumn(magColIndex, r);
+                
 //!!! extents                recordColumnExtents(column,
 //                                    sx,
 //                                    overallMag,
--- a/layer/ScrollableMagRangeCache.cpp	Wed Jul 20 08:42:04 2016 +0100
+++ b/layer/ScrollableMagRangeCache.cpp	Wed Jul 20 13:40:23 2016 +0100
@@ -78,6 +78,19 @@
 }
 
 void
+ScrollableMagRangeCache::sampleColumn(int column, const MagnitudeRange &r)
+{
+    if (!in_range_for(m_ranges, column)) {
+	cerr << "ERROR: ScrollableMagRangeCache::sampleColumn: column " << column
+	     << " is out of range for cache of width " << m_ranges.size()
+	     << " (with start frame " << m_startFrame << ")" << endl;
+	throw logic_error("column out of range");
+    } else {
+	m_ranges[column].sample(r);
+    }
+}
+
+void
 ScrollableMagRangeCache::sampleColumn(const LayerGeometryProvider *v,
 				      sv_frame_t frame,
 				      const MagnitudeRange &r)
@@ -88,7 +101,9 @@
     if (!in_range_for(m_ranges, x)) {
 	cerr << "WARNING: ScrollableMagRangeCache::sampleColumn: column " << x
 	     << " arising from frame " << frame << " is out of range for cache "
-	     << "of width " << m_ranges.size() << endl;
+	     << "of width " << m_ranges.size()
+	     << " (with start frame " << m_startFrame << ")" << endl;
+	throw logic_error("column out of range");
     } else {
 	sampleColumn(x, r);
     }
--- a/layer/ScrollableMagRangeCache.h	Wed Jul 20 08:42:04 2016 +0100
+++ b/layer/ScrollableMagRangeCache.h	Wed Jul 20 13:40:23 2016 +0100
@@ -130,11 +130,11 @@
     void scrollTo(const LayerGeometryProvider *v, sv_frame_t newStartFrame);
     
     /**
-     * Update a column in the cache, by column number.
+     * Update a column in the cache, by column index. (Column zero is
+     * the first column in the cache, it has nothing to do with any
+     * underlying model that the cache may be used with.)
      */
-    void sampleColumn(int column, const MagnitudeRange &r) {
-	m_ranges[column].sample(r);
-    }
+    void sampleColumn(int column, const MagnitudeRange &r);
     
     /**
      * Update a column in the cache, by frame.