changeset 1082:5b4fe7bb9430 spectrogram-minor-refactor

VerticalBinLayer for vertical mapping abstraction. Not totally sure about this
author Chris Cannam
date Fri, 01 Jul 2016 09:55:48 +0100
parents cbc7c8675706
children 7122aae95a88
files layer/Colour3DPlotLayer.h layer/Colour3DPlotRenderer.cpp layer/Colour3DPlotRenderer.h layer/LayerGeometryProvider.h layer/VerticalBinLayer.h
diffstat 5 files changed, 67 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.h	Thu Jun 30 18:21:11 2016 +0100
+++ b/layer/Colour3DPlotLayer.h	Fri Jul 01 09:55:48 2016 +0100
@@ -17,6 +17,7 @@
 #define COLOUR_3D_PLOT_LAYER_H
 
 #include "SliceableLayer.h"
+#include "VerticalBinLayer.h"
 
 #include "data/model/DenseThreeDimensionalModel.h"
 
@@ -34,7 +35,8 @@
  * implementation that derived the spectrogram itself from a
  * DenseTimeValueModel instead of using a three-dimensional model.
  */
-class Colour3DPlotLayer : public SliceableLayer
+class Colour3DPlotLayer : public SliceableLayer,
+                          public VerticalBinLayer
 {
     Q_OBJECT
 
--- a/layer/Colour3DPlotRenderer.cpp	Thu Jun 30 18:21:11 2016 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Fri Jul 01 09:55:48 2016 +0100
@@ -21,6 +21,7 @@
 #include "data/model/FFTModel.h"
 
 #include "LayerGeometryProvider.h"
+#include "VerticalBinLayer.h"
 
 #include <vector>
 
@@ -266,16 +267,13 @@
             }
         }
     }
-    /*!!!
+
     for (int y = 0; y < h; ++y) {
-        double q0 = 0, q1 = 0;
-        if (!getSmoothedYBinRange(v, h-y-1, q0, q1)) {
-            binfory[y] = -1;
-        } else {
-            binfory[y] = q0;
-        }
+        binfory[y] =
+            m_sources.verticalBinLayer->getBinForY(m_sources.geometryProvider, y);
     }
 
+    /*
     int attainedWidth = renderDrawBuffer(v,
                                          repaintWidth,
                                          h,
--- a/layer/Colour3DPlotRenderer.h	Thu Jun 30 18:21:11 2016 +0100
+++ b/layer/Colour3DPlotRenderer.h	Fri Jul 01 09:55:48 2016 +0100
@@ -27,6 +27,7 @@
 #include <QImage>
 
 class LayerGeometryProvider;
+class VerticalBinLayer;
 class DenseThreeDimensionalModel;
 class Dense3DModelPeakCache;
 class FFTModel;
@@ -46,10 +47,12 @@
     };
 
     struct Sources {
-        Sources() : geometryProvider(0), source(0), peaks(0), fft(0) { }
+        Sources() : geometryProvider(0), verticalBinLayer(0),
+                    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
--- a/layer/LayerGeometryProvider.h	Thu Jun 30 18:21:11 2016 +0100
+++ b/layer/LayerGeometryProvider.h	Fri Jul 01 09:55:48 2016 +0100
@@ -120,7 +120,7 @@
      * Not thread-safe in logarithmic mode.  Call only from GUI thread.
      */
     virtual double getFrequencyForY(int y, double minFreq, double maxFreq,
-			   bool logarithmic) const = 0;
+                                    bool logarithmic) const = 0;
 
     virtual int getTextLabelHeight(const Layer *layer, QPainter &) const = 0;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/layer/VerticalBinLayer.h	Fri Jul 01 09:55:48 2016 +0100
@@ -0,0 +1,54 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006-2016 Chris Cannam and QMUL.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef VERTICAL_BIN_LAYER_H
+#define VERTICAL_BIN_LAYER_H
+
+/**
+ * Interface for layers in which the Y axis corresponds to bin number
+ * rather than scale value. Colour3DPlotLayer is the obvious example.
+ */
+class VerticalBinLayer
+{
+public:
+    /**
+     * 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.
+     */
+    virtual double getYForBin(LayerGeometryProvider *, double bin) const = 0;
+
+    /**
+     * As getYForBin, but rounding to integer values.
+     */
+    virtual int getIYForBin(LayerGeometryProvider *, int bin) const = 0;
+    
+    /**
+     * 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).
+     */
+    virtual double getBinForY(LayerGeometryProvider *, double y) const = 0;
+
+    /**
+     * As getBinForY, but rounding to integer values.
+     */
+    virtual int getIBinForY(LayerGeometryProvider *, int y) const = 0;
+};
+
+#endif
+