changeset 1131:ee98d587cd1a spectrogram-minor-refactor

Sensible vertical scale and hybrid normalisation range in colour 3d plot
author Chris Cannam
date Tue, 02 Aug 2016 09:58:41 +0100
parents dc4b8fd3fcb7
children 745a868f0abf
files layer/Colour3DPlotLayer.cpp layer/Colour3DPlotRenderer.cpp layer/SpectrogramLayer.cpp
diffstat 3 files changed, 25 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Tue Aug 02 09:20:16 2016 +0100
+++ b/layer/Colour3DPlotLayer.cpp	Tue Aug 02 09:58:41 2016 +0100
@@ -866,48 +866,18 @@
     int ch = h - 20;
     if (ch > 20) {
 
-        double min = m_model->getMinimumLevel();
-        double max = m_model->getMaximumLevel();
+        double min = m_viewMags[v->getId()].getMin();
+        double max = m_viewMags[v->getId()].getMax();
 
-        double mmin = min;
-        double mmax = max;
+        if (max <= min) max = min + 0.1;
 
-        if (m_colourScale == ColourScaleType::Log) {
-            LogRange::mapRange(mmin, mmax);
-        } else if (m_colourScale == ColourScaleType::PlusMinusOne) {
-            mmin = -1.f;
-            mmax = 1.f;
-        } else if (m_colourScale == ColourScaleType::Absolute) {
-            if (mmin < 0) {
-                if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin);
-                else mmax = fabs(mmax);
-                mmin = 0;
-            } else {
-                mmin = fabs(mmin);
-                mmax = fabs(mmax);
-            }
-        }
-    
-        if (max == min) max = min + 1.f;
-        if (mmax == mmin) mmax = mmin + 1.f;
-    
         paint.setPen(v->getForeground());
         paint.drawRect(4, 10, cw - 8, ch+1);
 
         for (int y = 0; y < ch; ++y) {
             double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min;
-            if (m_colourScale == ColourScaleType::Log) {
-                value = LogRange::map(value);
-            }
-            int pixel = int(((value - mmin) * 256) / (mmax - mmin));
-            if (pixel >= 0 && pixel < 256) {
-//!!! replace this
-                // QRgb c = m_cache->color(pixel);
-                // paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c)));
-                paint.drawLine(5, 11 + y, cw - 5, 11 + y);
-            } else {
-                cerr << "WARNING: Colour3DPlotLayer::paintVerticalScale: value " << value << ", mmin " << mmin << ", mmax " << mmax << " leads to invalid pixel " << pixel << endl;
-            }
+            paint.setPen(getRenderer(v)->getColour(value));
+            paint.drawLine(5, 11 + y, cw - 5, 11 + y);
         }
 
         QString minstr = QString("%1").arg(min);
@@ -1065,6 +1035,18 @@
         cparams.scale = m_colourScale;
         cparams.gain = m_gain;
 
+        if (m_normalization == ColumnNormalization::None) {
+            cparams.minValue = m_model->getMinimumLevel();
+            cparams.maxValue = m_model->getMaximumLevel();
+        } else if (m_normalization == ColumnNormalization::Hybrid) {
+            cparams.minValue = 0;
+            cparams.maxValue = log10(m_model->getMaximumLevel() + 1.0);
+        }
+
+        if (cparams.maxValue <= cparams.minValue) {
+            cparams.maxValue = cparams.minValue + 0.1;
+        }
+        
         Colour3DPlotRenderer::Parameters params;
         params.colourScale = ColourScale(cparams);
         params.normalization = m_normalization;
--- a/layer/Colour3DPlotRenderer.cpp	Tue Aug 02 09:20:16 2016 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Tue Aug 02 09:58:41 2016 +0100
@@ -30,7 +30,7 @@
 
 #include <vector>
 
-#define DEBUG_COLOUR_PLOT_REPAINT 1
+//#define DEBUG_COLOUR_PLOT_REPAINT 1
 
 using namespace std;
 
@@ -360,12 +360,12 @@
                               fullColumn.data() + maxbin + 1);
 
             column = ColumnOp::applyGain(column, m_params.scaleFactor);
-            
-            magRange.sample(column);
 
 //                if (m_colourScale != ColourScaleType::Phase) {
             preparedColumn = ColumnOp::normalize(column, m_params.normalization);
 //                }
+            
+            magRange.sample(preparedColumn);
 
             if (m_params.binDisplay == BinDisplay::PeakBins) {
                 preparedColumn = ColumnOp::peakPick(preparedColumn);
@@ -788,12 +788,12 @@
 
                 column = ColumnOp::applyGain(column, m_params.scaleFactor);
 
-                magRange.sample(column);
-
 //                if (m_colourScale != ColourScaleType::Phase) {
                     column = ColumnOp::normalize(column, m_params.normalization);
 //                }
 
+                magRange.sample(column);
+
                 if (m_params.binDisplay == BinDisplay::PeakBins) {
                     column = ColumnOp::peakPick(column);
                 }
@@ -932,14 +932,14 @@
                                   fullColumn.data() + maxbin + 1);
 
                 column = ColumnOp::applyGain(column, m_params.scaleFactor);
-
-                magRange.sample(column);
                 
 //!!!                if (m_colourScale != ColourScaleType::Phase) {
                 preparedColumn = ColumnOp::normalize
                     (column, m_params.normalization);
 //!!!                }
 
+                magRange.sample(preparedColumn);
+
                 psx = sx;
             }
 
--- a/layer/SpectrogramLayer.cpp	Tue Aug 02 09:20:16 2016 +0100
+++ b/layer/SpectrogramLayer.cpp	Tue Aug 02 09:58:41 2016 +0100
@@ -2061,7 +2061,7 @@
         double max = m_viewMags[v->getId()].getMax();
 
         if (min < m_threshold) min = m_threshold;
-        if (max < min) max = min;
+        if (max <= min) max = min + 0.1;
         
         double dBmin = AudioLevel::multiplier_to_dB(min);
         double dBmax = AudioLevel::multiplier_to_dB(max);