changeset 1103:d84a0033b305 spectrogram-minor-refactor

Turn BinDisplay and BinScale into enum classes
author Chris Cannam
date Thu, 14 Jul 2016 15:13:37 +0100
parents 36a981a0fa31
children 46cc4644206d
files layer/Colour3DPlotLayer.cpp layer/Colour3DPlotLayer.h layer/Colour3DPlotRenderer.cpp layer/Colour3DPlotRenderer.h layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h
diffstat 6 files changed, 78 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Wed Jul 13 13:44:11 2016 +0100
+++ b/layer/Colour3DPlotLayer.cpp	Thu Jul 14 15:13:37 2016 +0100
@@ -56,7 +56,7 @@
     m_colourScaleSet(false),
     m_colourMap(0),
     m_gain(1.0),
-    m_binScale(Colour3DPlotRenderer::LinearBinScale),
+    m_binScale(BinScale::Linear),
     m_normalization(ColumnOp::NoNormalization),
     m_invertVertical(false),
     m_opaque(false),
@@ -321,7 +321,7 @@
 
 	*min = 0;
 	*max = 1;
-        *deflt = int(Colour3DPlotRenderer::LinearBinScale);
+        *deflt = int(BinScale::Linear);
 	val = (int)m_binScale;
 
     } else if (name == "Opaque") {
@@ -420,8 +420,8 @@
     } else if (name == "Bin Scale") {
 	switch (value) {
 	default:
-	case 0: setBinScale(Colour3DPlotRenderer::LinearBinScale); break;
-	case 1: setBinScale(Colour3DPlotRenderer::LogBinScale); break;
+	case 0: setBinScale(BinScale::Linear); break;
+	case 1: setBinScale(BinScale::Log); break;
 	}
     } else if (name == "Normalization") {
         switch (value) {
@@ -469,7 +469,7 @@
 }
 
 void
-Colour3DPlotLayer::setBinScale(Colour3DPlotRenderer::BinScale binScale)
+Colour3DPlotLayer::setBinScale(BinScale binScale)
 {
     if (m_binScale == binScale) return;
     m_binScale = binScale;
@@ -477,7 +477,7 @@
     emit layerParametersChanged();
 }
 
-Colour3DPlotRenderer::BinScale
+BinScale
 Colour3DPlotLayer::getBinScale() const
 {
     return m_binScale;
@@ -690,7 +690,7 @@
     double mn = 0, mx = m_model->getHeight();
     getDisplayExtents(mn, mx);
     double h = v->getPaintHeight();
-    if (m_binScale == Colour3DPlotRenderer::LinearBinScale) {
+    if (m_binScale == BinScale::Linear) {
         y = h - (((bin - mn) * h) / (mx - mn));
     } else {
         double logmin = mn + 1, logmax = mx + 1;
@@ -708,7 +708,7 @@
     double mn = 0, mx = m_model->getHeight();
     getDisplayExtents(mn, mx);
     double h = v->getPaintHeight();
-    if (m_binScale == Colour3DPlotRenderer::LinearBinScale) {
+    if (m_binScale == BinScale::Linear) {
         bin = mn + ((h - y) * (mx - mn)) / h;
     } else {
         double logmin = mn + 1, logmax = mx + 1;
@@ -1851,7 +1851,7 @@
         .arg(m_invertVertical ? "true" : "false")
         .arg(m_opaque ? "true" : "false")
         .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ")
-             .arg((int)m_binScale)
+             .arg(int(m_binScale))
              .arg(m_smooth ? "true" : "false")
              .arg(m_gain));
     
@@ -1889,7 +1889,7 @@
     int colourMap = attributes.value("colourScheme").toInt(&ok);
     if (ok) setColourMap(colourMap);
 
-    Colour3DPlotRenderer::BinScale binScale = (Colour3DPlotRenderer::BinScale)
+    BinScale binScale = (BinScale)
 	attributes.value("binScale").toInt(&ok);
     if (ok) setBinScale(binScale);
 
--- a/layer/Colour3DPlotLayer.h	Wed Jul 13 13:44:11 2016 +0100
+++ b/layer/Colour3DPlotLayer.h	Thu Jul 14 15:13:37 2016 +0100
@@ -106,8 +106,8 @@
     /**
      * Specify the scale for the y axis.
      */
-    void setBinScale(Colour3DPlotRenderer::BinScale);
-    Colour3DPlotRenderer::BinScale getBinScale() const;
+    void setBinScale(BinScale);
+    BinScale getBinScale() const;
 
     /**
      * Specify the normalization mode for bin values.
@@ -161,7 +161,7 @@
     bool        m_colourScaleSet;
     int         m_colourMap;
     float       m_gain;
-    Colour3DPlotRenderer::BinScale m_binScale;
+    BinScale m_binScale;
     ColumnOp::Normalization m_normalization;
     bool        m_invertVertical;
     bool        m_opaque;
--- a/layer/Colour3DPlotRenderer.cpp	Wed Jul 13 13:44:11 2016 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Thu Jul 14 15:13:37 2016 +0100
@@ -175,7 +175,7 @@
     // well as horizontal. That's why this function didn't take any
     // y/height parameters.
 
-    if (bufferIsBinResolution && (m_params.binDisplay != PeakFrequencies)) {
+    if (bufferIsBinResolution && (m_params.binDisplay != BinDisplay::PeakFrequencies)) {
         renderToCacheBinResolution(v, x0, x1 - x0);
     } else {
         renderToCachePixelResolution(v, x0, x1 - x0, rightToLeft, timeConstrained);
@@ -281,7 +281,7 @@
 
     int attainedWidth;
 
-    if (m_params.binDisplay == PeakFrequencies) {
+    if (m_params.binDisplay == BinDisplay::PeakFrequencies) {
         attainedWidth = renderDrawBufferPeakFrequencies(v,
                                                         repaintWidth,
                                                         h,
@@ -547,7 +547,7 @@
                     column = ColumnOp::normalize(column, m_params.normalization);
 //                }
 
-                if (m_params.binDisplay == PeakBins) {
+                if (m_params.binDisplay == BinDisplay::PeakBins) {
                     column = ColumnOp::peakPick(column);
                 }
 
@@ -636,7 +636,7 @@
     double minFreq = (double(minbin) * fft->getSampleRate()) / fft->getFFTSize();
     double maxFreq = (double(maxbin) * fft->getSampleRate()) / fft->getFFTSize();
 
-    bool logarithmic = (m_params.binScale == LogBinScale);
+    bool logarithmic = (m_params.binScale == BinScale::Log);
     
     for (int x = start; x != finish; x += step) {
         
--- a/layer/Colour3DPlotRenderer.h	Wed Jul 13 13:44:11 2016 +0100
+++ b/layer/Colour3DPlotRenderer.h	Thu Jul 14 15:13:37 2016 +0100
@@ -32,20 +32,20 @@
 class Dense3DModelPeakCache;
 class FFTModel;
 
+enum class BinDisplay {
+    AllBins,
+    PeakBins,
+    PeakFrequencies
+};
+
+enum class BinScale {
+    Linear,
+    Log
+};
+
 class Colour3DPlotRenderer
 {
 public:
-    enum BinDisplay {
-	AllBins,
-	PeakBins,
-	PeakFrequencies
-    };
-
-    enum BinScale {
-	LinearBinScale,
-	LogBinScale
-    };
-
     struct Sources {
         Sources() : verticalBinLayer(0), source(0), peaks(0), fft(0) { }
         
@@ -60,8 +60,8 @@
 	Parameters() :
 	    colourScale(ColourScale::Parameters()),
 	    normalization(ColumnOp::NoNormalization),
-	    binDisplay(AllBins),
-            binScale(LinearBinScale),
+	    binDisplay(BinDisplay::AllBins),
+            binScale(BinScale::Linear),
 	    alwaysOpaque(false),
             interpolate(false), //!!! separate out x-interpolate and y-interpolate? the spectrogram actually does (or used to)
             invertVertical(false) { }
--- a/layer/SpectrogramLayer.cpp	Wed Jul 13 13:44:11 2016 +0100
+++ b/layer/SpectrogramLayer.cpp	Thu Jul 14 15:13:37 2016 +0100
@@ -74,8 +74,8 @@
     m_initialMaxFrequency(8000),
     m_colourScale(ColourScale::LogColourScale),
     m_colourMap(0),
-    m_binScale(Colour3DPlotRenderer::LinearBinScale),
-    m_binDisplay(Colour3DPlotRenderer::AllBins),
+    m_binScale(BinScale::Linear),
+    m_binDisplay(BinDisplay::AllBins),
     m_normalization(ColumnOp::NoNormalization),
     m_lastEmittedZoomStep(-1),
     m_synchronous(false),
@@ -99,7 +99,7 @@
         setMinFrequency(40);
 	setColourScale(ColourScale::LinearColourScale);
         setColourMap(ColourMapper::Sunset);
-        setBinScale(Colour3DPlotRenderer::LogBinScale);
+        setBinScale(BinScale::Log);
         colourConfigName = "spectrogram-melodic-colour";
         colourConfigDefault = int(ColourMapper::Sunset);
 //        setGain(20);
@@ -109,9 +109,9 @@
         m_initialMaxFrequency = 2000;
 	setMaxFrequency(2000);
 	setMinFrequency(40);
-	setBinScale(Colour3DPlotRenderer::LogBinScale);
+	setBinScale(BinScale::Log);
 	setColourScale(ColourScale::LinearColourScale);
-	setBinDisplay(Colour3DPlotRenderer::PeakFrequencies);
+	setBinDisplay(BinDisplay::PeakFrequencies);
         setNormalization(ColumnOp::NormalizeColumns);
         colourConfigName = "spectrogram-melodic-colour";
         colourConfigDefault = int(ColourMapper::Sunset);
@@ -347,14 +347,14 @@
 
 	*min = 0;
 	*max = 1;
-        *deflt = int(Colour3DPlotRenderer::LinearBinScale);
+        *deflt = int(BinScale::Linear);
 	val = (int)m_binScale;
 
     } else if (name == "Bin Display") {
 
 	*min = 0;
 	*max = 2;
-        *deflt = int(Colour3DPlotRenderer::AllBins);
+        *deflt = int(BinDisplay::AllBins);
 	val = (int)m_binDisplay;
 
     } else if (name == "Normalization") {
@@ -547,15 +547,15 @@
     } else if (name == "Frequency Scale") {
 	switch (value) {
 	default:
-	case 0: setBinScale(Colour3DPlotRenderer::LinearBinScale); break;
-	case 1: setBinScale(Colour3DPlotRenderer::LogBinScale); break;
+	case 0: setBinScale(BinScale::Linear); break;
+	case 1: setBinScale(BinScale::Log); break;
 	}
     } else if (name == "Bin Display") {
 	switch (value) {
 	default:
-	case 0: setBinDisplay(Colour3DPlotRenderer::AllBins); break;
-	case 1: setBinDisplay(Colour3DPlotRenderer::PeakBins); break;
-	case 2: setBinDisplay(Colour3DPlotRenderer::PeakFrequencies); break;
+	case 0: setBinDisplay(BinDisplay::AllBins); break;
+	case 1: setBinDisplay(BinDisplay::PeakBins); break;
+	case 2: setBinDisplay(BinDisplay::PeakFrequencies); break;
 	}
     } else if (name == "Normalization") {
         switch (value) {
@@ -633,7 +633,7 @@
 int
 SpectrogramLayer::getFFTOversampling() const
 {
-    if (m_binDisplay != Colour3DPlotRenderer::AllBins) {
+    if (m_binDisplay != BinDisplay::AllBins) {
         return 1;
     }
 
@@ -852,7 +852,7 @@
 }
 
 void
-SpectrogramLayer::setBinScale(Colour3DPlotRenderer::BinScale binScale)
+SpectrogramLayer::setBinScale(BinScale binScale)
 {
     if (m_binScale == binScale) return;
 
@@ -862,14 +862,14 @@
     emit layerParametersChanged();
 }
 
-Colour3DPlotRenderer::BinScale
+BinScale
 SpectrogramLayer::getBinScale() const
 {
     return m_binScale;
 }
 
 void
-SpectrogramLayer::setBinDisplay(Colour3DPlotRenderer::BinDisplay binDisplay)
+SpectrogramLayer::setBinDisplay(BinDisplay binDisplay)
 {
     if (m_binDisplay == binDisplay) return;
 
@@ -879,7 +879,7 @@
     emit layerParametersChanged();
 }
 
-Colour3DPlotRenderer::BinDisplay
+BinDisplay
 SpectrogramLayer::getBinDisplay() const
 {
     return m_binDisplay;
@@ -1152,7 +1152,7 @@
     double minf = getEffectiveMinFrequency();
     double maxf = getEffectiveMaxFrequency();
 
-    bool logarithmic = (m_binScale == Colour3DPlotRenderer::LogBinScale);
+    bool logarithmic = (m_binScale == BinScale::Log);
 
     q0 = v->getFrequencyForY(y, minf, maxf, logarithmic);
     q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic);
@@ -1184,7 +1184,7 @@
     double minf = getEffectiveMinFrequency();
     double maxf = getEffectiveMaxFrequency();
 
-    bool logarithmic = (m_binScale == Colour3DPlotRenderer::LogBinScale);
+    bool logarithmic = (m_binScale == BinScale::Log);
 
     double q = v->getFrequencyForY(y, minf, maxf, logarithmic);
 
@@ -1286,8 +1286,8 @@
 
     bool haveAdj = false;
 
-    bool peaksOnly = (m_binDisplay == Colour3DPlotRenderer::PeakBins ||
-		      m_binDisplay == Colour3DPlotRenderer::PeakFrequencies);
+    bool peaksOnly = (m_binDisplay == BinDisplay::PeakBins ||
+		      m_binDisplay == BinDisplay::PeakFrequencies);
 
     for (int q = q0i; q <= q1i; ++q) {
 
@@ -1820,7 +1820,7 @@
 
     int increment = getWindowIncrement();
     
-    bool logarithmic = (m_binScale == Colour3DPlotRenderer::LogBinScale);
+    bool logarithmic = (m_binScale == BinScale::Log);
 
     MagnitudeRange overallMag = m_viewMags[v->getId()];
     bool overallMagChanged = false;
@@ -1943,14 +1943,14 @@
 
         // neither limitation applies, so use a short soft limit
 
-        if (m_binDisplay == Colour3DPlotRenderer::PeakFrequencies) {
+        if (m_binDisplay == BinDisplay::PeakFrequencies) {
             softTimeLimit = 0.15;
         } else {
             softTimeLimit = 0.1;
         }
     }
 
-    if (m_binDisplay != Colour3DPlotRenderer::PeakFrequencies) {
+    if (m_binDisplay != BinDisplay::PeakFrequencies) {
 
         for (int y = 0; y < h; ++y) {
             double q0 = 0, q1 = 0;
@@ -2407,7 +2407,7 @@
     DenseThreeDimensionalModel *sourceModel = 0;
     
 #ifdef DEBUG_SPECTROGRAM_REPAINT
-    cerr << "SpectrogramLayer::paintDrawBuffer: Note: bin display = " << m_binDisplay << ", w = " << w << ", binforx[" << w-1 << "] = " << binforx[w-1] << ", binforx[0] = " << binforx[0] << endl;
+    cerr << "SpectrogramLayer::paintDrawBuffer: Note: bin display = " << int(m_binDisplay) << ", w = " << w << ", binforx[" << w-1 << "] = " << binforx[w-1] << ", binforx[0] = " << binforx[0] << endl;
 #endif
 
     int divisor = 1;
@@ -2427,8 +2427,8 @@
         Preferences::getInstance()->getSpectrogramSmoothing();
     if (smoothing == Preferences::SpectrogramInterpolated ||
         smoothing == Preferences::SpectrogramZeroPaddedAndInterpolated) {
-        if (m_binDisplay != Colour3DPlotRenderer::PeakBins &&
-            m_binDisplay != Colour3DPlotRenderer::PeakFrequencies) {
+        if (m_binDisplay != BinDisplay::PeakBins &&
+            m_binDisplay != BinDisplay::PeakFrequencies) {
             interpolate = true;
         }
     }
@@ -2517,7 +2517,7 @@
                     column = ColumnOp::normalize(column, m_normalization);
                 }
 
-                if (m_binDisplay == Colour3DPlotRenderer::PeakBins) {
+                if (m_binDisplay == BinDisplay::PeakBins) {
                     column = ColumnOp::peakPick(column);
                 }
 
@@ -2626,7 +2626,7 @@
     return v->getYForFrequency(frequency,
 			       getEffectiveMinFrequency(),
 			       getEffectiveMaxFrequency(),
-			       m_binScale == Colour3DPlotRenderer::LogBinScale);
+			       m_binScale == BinScale::Log);
 }
 
 double
@@ -2635,7 +2635,7 @@
     return v->getFrequencyForY(y,
 			       getEffectiveMinFrequency(),
 			       getEffectiveMaxFrequency(),
-			       m_binScale == Colour3DPlotRenderer::LogBinScale);
+			       m_binScale == BinScale::Log);
 }
 
 int
@@ -2666,7 +2666,7 @@
     min = double(sr) / getFFTSize();
     max = double(sr) / 2;
     
-    logarithmic = (m_binScale == Colour3DPlotRenderer::LogBinScale);
+    logarithmic = (m_binScale == BinScale::Log);
     unit = "Hz";
     return true;
 }
@@ -2909,7 +2909,7 @@
 
     QString adjFreqText = "", adjPitchText = "";
 
-    if (m_binDisplay == Colour3DPlotRenderer::PeakFrequencies) {
+    if (m_binDisplay == BinDisplay::PeakFrequencies) {
 
 	if (!getAdjustedYBinSourceRange(v, x, y, freqMin, freqMax,
 					adjFreqMin, adjFreqMax)) {
@@ -3021,7 +3021,7 @@
     int fw = paint.fontMetrics().width(tr("43Hz"));
     if (tw < fw) tw = fw;
 
-    int tickw = (m_binScale == Colour3DPlotRenderer::LogBinScale ? 10 : 4);
+    int tickw = (m_binScale == BinScale::Log ? 10 : 4);
     
     return cw + tickw + tw + 13;
 }
@@ -3039,8 +3039,8 @@
 
     int h = rect.height(), w = rect.width();
 
-    int tickw = (m_binScale == Colour3DPlotRenderer::LogBinScale ? 10 : 4);
-    int pkw = (m_binScale == Colour3DPlotRenderer::LogBinScale ? 10 : 0);
+    int tickw = (m_binScale == BinScale::Log ? 10 : 4);
+    int pkw = (m_binScale == BinScale::Log ? 10 : 0);
 
     int bins = getFFTSize() / 2;
     sv_samplerate_t sr = m_model->getSampleRate();
@@ -3164,7 +3164,7 @@
 	int freq = int((sr * bin) / getFFTSize());
 
 	if (py >= 0 && (vy - py) < textHeight - 1) {
-	    if (m_binScale == Colour3DPlotRenderer::LinearBinScale) {
+	    if (m_binScale == BinScale::Linear) {
 		paint.drawLine(w - tickw, h - vy, w, h - vy);
 	    }
 	    continue;
@@ -3182,7 +3182,7 @@
 	py = vy;
     }
 
-    if (m_binScale == Colour3DPlotRenderer::LogBinScale) {
+    if (m_binScale == BinScale::Log) {
 
         // piano keyboard
 
@@ -3304,7 +3304,7 @@
 
     double newmin, newmax;
 
-    if (m_binScale == Colour3DPlotRenderer::LogBinScale) {
+    if (m_binScale == BinScale::Log) {
 
         // need to pick newmin and newmax such that
         //
@@ -3446,8 +3446,8 @@
 	.arg(convertOutColourScale(m_colourScale))
 	.arg(m_colourMap)
 	.arg(m_colourRotation)
-	.arg(m_binScale)
-	.arg(m_binDisplay);
+	.arg(int(m_binScale))
+	.arg(int(m_binDisplay));
 
     // New-style normalization attributes, allowing for more types of
     // normalization in future: write out the column normalization
@@ -3528,11 +3528,11 @@
     int colourRotation = attributes.value("colourRotation").toInt(&ok);
     if (ok) setColourRotation(colourRotation);
 
-    Colour3DPlotRenderer::BinScale binScale = (Colour3DPlotRenderer::BinScale)
+    BinScale binScale = (BinScale)
 	attributes.value("frequencyScale").toInt(&ok);
     if (ok) setBinScale(binScale);
 
-    Colour3DPlotRenderer::BinDisplay binDisplay = (Colour3DPlotRenderer::BinDisplay)
+    BinDisplay binDisplay = (BinDisplay)
 	attributes.value("binDisplay").toInt(&ok);
     if (ok) setBinDisplay(binDisplay);
 
--- a/layer/SpectrogramLayer.h	Wed Jul 13 13:44:11 2016 +0100
+++ b/layer/SpectrogramLayer.h	Thu Jul 14 15:13:37 2016 +0100
@@ -149,14 +149,14 @@
     /**
      * Specify the scale for the y axis.
      */
-    void setBinScale(Colour3DPlotRenderer::BinScale);
-    Colour3DPlotRenderer::BinScale getBinScale() const;
+    void setBinScale(BinScale);
+    BinScale getBinScale() const;
 
     /**
      * Specify the processing of frequency bins for the y axis.
      */
-    void setBinDisplay(Colour3DPlotRenderer::BinDisplay);
-    Colour3DPlotRenderer::BinDisplay getBinDisplay() const;
+    void setBinDisplay(BinDisplay);
+    BinDisplay getBinDisplay() const;
 
     /**
      * Specify the normalization mode for bin values.
@@ -247,8 +247,8 @@
     ColourScale::Scale  m_colourScale;
     int                 m_colourMap;
     QColor              m_crosshairColour;
-    Colour3DPlotRenderer::BinScale m_binScale;
-    Colour3DPlotRenderer::BinDisplay m_binDisplay;
+    BinScale m_binScale;
+    BinDisplay m_binDisplay;
     ColumnOp::Normalization m_normalization;
     int                 m_lastEmittedZoomStep;
     bool                m_synchronous;