changeset 1089:c8683d94442a spectrogram-minor-refactor

Start to introduce renderer objects
author Chris Cannam
date Tue, 05 Jul 2016 12:20:56 +0100
parents c520f90bbf2e
children c8c747783110
files layer/Colour3DPlotRenderer.h layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h
diffstat 3 files changed, 63 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotRenderer.h	Tue Jul 05 08:58:28 2016 +0100
+++ b/layer/Colour3DPlotRenderer.h	Tue Jul 05 12:20:56 2016 +0100
@@ -51,11 +51,11 @@
                     source(0), peaks(0), fft(0) { }
         
         // These must all outlive this class
-        LayerGeometryProvider *geometryProvider; // always
-        VerticalBinLayer *verticalBinLayer;      // always
-	DenseThreeDimensionalModel *source;      // always
-	Dense3DModelPeakCache *peaks;	         // optionally
-	FFTModel *fft;			         // optionally
+        LayerGeometryProvider *geometryProvider;   // always
+        const VerticalBinLayer *verticalBinLayer;  // always
+	DenseThreeDimensionalModel *source;        // always
+	Dense3DModelPeakCache *peaks;	           // optionally
+	FFTModel *fft;			           // optionally
     };        
 
     struct Parameters {
--- a/layer/SpectrogramLayer.cpp	Tue Jul 05 08:58:28 2016 +0100
+++ b/layer/SpectrogramLayer.cpp	Tue Jul 05 12:20:56 2016 +0100
@@ -31,6 +31,7 @@
 #include "ImageRegionFinder.h"
 #include "PianoScale.h"
 #include "PaintAssistant.h"
+#include "Colour3DPlotRenderer.h"
 
 #include <QPainter>
 #include <QImage>
@@ -574,6 +575,13 @@
          i != m_imageCaches.end(); ++i) {
         i->second.invalidate();
     }
+
+    //!!!
+    for (ViewRendererMap::iterator i = m_renderers.begin();
+         i != m_renderers.end(); ++i) {
+        delete i->second;
+    }
+    m_renderers.clear();
 }
 
 void
@@ -1523,6 +1531,43 @@
 }
 
 void
+SpectrogramLayer::paintAlternative(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
+{
+    Colour3DPlotRenderer *renderer = getRenderer(v);
+
+    
+}
+
+Colour3DPlotRenderer *
+SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const
+{
+    if (m_renderers.find(v->getId()) == m_renderers.end()) {
+
+        Colour3DPlotRenderer::Sources sources;
+        sources.geometryProvider = v;
+        sources.verticalBinLayer = this;
+        sources.source = m_fftModel;
+        sources.peaks = m_peakCache;
+        sources.fft = m_fftModel;
+
+        ::ColourScale::Parameters cparams;
+        //!!! todo 
+        
+        Colour3DPlotRenderer::Parameters params;
+        params.colourScale = ::ColourScale(cparams);
+        params.normalization = m_normalization;
+        //!!! map properly:
+        params.binDisplay = (Colour3DPlotRenderer::BinDisplay)(int)m_binDisplay;
+        params.binScale = (Colour3DPlotRenderer::BinScale)(int)m_frequencyScale;
+        //!!! and the rest
+
+        m_renderers[v->getId()] = new Colour3DPlotRenderer(sources, params);
+    }
+
+    return m_renderers[v->getId()];
+}
+
+void
 SpectrogramLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
 {
     Profiler profiler("SpectrogramLayer::paint", false);
@@ -1543,6 +1588,11 @@
 	SVDEBUG << "SpectrogramLayer::paint(): Layer is dormant, making it undormant again" << endl;
     }
 
+//    paintAlternative(v, paint, rect);
+//    return;
+
+    //!!!
+    
     // Need to do this even if !isLayerDormant, as that could mean v
     // is not in the dormancy map at all -- we need it to be present
     // and accountable for when determining whether we need the cache
--- a/layer/SpectrogramLayer.h	Tue Jul 05 08:58:28 2016 +0100
+++ b/layer/SpectrogramLayer.h	Tue Jul 05 12:20:56 2016 +0100
@@ -41,7 +41,7 @@
 class QTimer;
 class FFTModel;
 class Dense3DModelPeakCache;
-
+class Colour3DPlotRenderer;
 
 /**
  * SpectrogramLayer represents waveform data (obtained from a
@@ -340,7 +340,7 @@
     int getFFTOversampling() const;
     int getFFTSize() const; // m_windowSize * getFFTOversampling()
 
-    mutable FFTModel *m_fftModel; //!!! should not be mutable, see getFFTModel()
+    mutable FFTModel *m_fftModel; //!!! should not be mutable, see getFFTModel()?
     mutable Dense3DModelPeakCache *m_peakCache;
     const int m_peakCacheDivisor;
 
@@ -349,10 +349,16 @@
     mutable std::vector<MagnitudeRange> m_columnMags;
     void invalidateMagnitudes();
     bool updateViewMagnitudes(LayerGeometryProvider *v) const;
+
+    typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
+    mutable ViewRendererMap m_renderers;
+    Colour3DPlotRenderer *getRenderer(LayerGeometryProvider *) const;
     
     FFTModel *getFFTModel() const;
     Dense3DModelPeakCache *getPeakCache() const;
     void invalidateFFTModel();
+
+    void paintAlternative(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
     
     int paintDrawBuffer(LayerGeometryProvider *v, int w, int h,
                         const std::vector<int> &binforx,