# HG changeset patch # User Chris Cannam # Date 1435324411 -3600 # Node ID 98827470ada2609207b65027dda747869076524b # Parent 64c2b3a4435a691a0c3a800b4c1f2a6dc4e02988# Parent 1986c9b0d9c3355324cef2b67917d64d660ea949 Merge from branch normalize_hybrid_option diff -r 64c2b3a4435a -r 98827470ada2 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Fri Jun 26 14:10:40 2015 +0100 +++ b/layer/SpectrogramLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -73,9 +73,7 @@ m_colourMap(0), m_frequencyScale(LinearFrequencyScale), m_binDisplay(AllBins), - m_normalizeColumns(false), - m_normalizeVisibleArea(false), - m_normalizeHybrid(false), + m_normalization(NoNormalization), m_lastEmittedZoomStep(-1), m_synchronous(false), m_haveDetailedScale(false), @@ -107,7 +105,7 @@ setFrequencyScale(LogFrequencyScale); setColourScale(LinearColourScale); setBinDisplay(PeakFrequencies); - setNormalizeColumns(true); + setNormalization(NormalizeColumns); } Preferences *prefs = Preferences::getInstance(); @@ -155,8 +153,7 @@ list.push_back("Colour Scale"); list.push_back("Window Size"); list.push_back("Window Increment"); - list.push_back("Normalize Columns"); - list.push_back("Normalize Visible Area"); + list.push_back("Normalization"); list.push_back("Bin Display"); list.push_back("Threshold"); list.push_back("Gain"); @@ -175,8 +172,7 @@ if (name == "Colour Scale") return tr("Colour Scale"); if (name == "Window Size") return tr("Window Size"); if (name == "Window Increment") return tr("Window Overlap"); - if (name == "Normalize Columns") return tr("Normalize Columns"); - if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); + if (name == "Normalization") return tr("Normalization"); if (name == "Bin Display") return tr("Bin Display"); if (name == "Threshold") return tr("Threshold"); if (name == "Gain") return tr("Gain"); @@ -189,10 +185,8 @@ } QString -SpectrogramLayer::getPropertyIconName(const PropertyName &name) const +SpectrogramLayer::getPropertyIconName(const PropertyName &) const { - if (name == "Normalize Columns") return "normalise-columns"; - if (name == "Normalize Visible Area") return "normalise"; return ""; } @@ -201,8 +195,6 @@ { if (name == "Gain") return RangeProperty; if (name == "Colour Rotation") return RangeProperty; - if (name == "Normalize Columns") return ToggleProperty; - if (name == "Normalize Visible Area") return ToggleProperty; if (name == "Threshold") return RangeProperty; if (name == "Zero Padding") return ToggleProperty; return ValueProperty; @@ -219,8 +211,7 @@ if (name == "Colour" || name == "Threshold" || name == "Colour Rotation") return tr("Colour"); - if (name == "Normalize Columns" || - name == "Normalize Visible Area" || + if (name == "Normalization" || name == "Gain" || name == "Colour Scale") return tr("Scale"); return QString(); @@ -365,15 +356,12 @@ *deflt = int(AllBins); val = (int)m_binDisplay; - } else if (name == "Normalize Columns") { + } else if (name == "Normalization") { - *deflt = 0; - val = (m_normalizeColumns ? 1 : 0); - - } else if (name == "Normalize Visible Area") { - - *deflt = 0; - val = (m_normalizeVisibleArea ? 1 : 0); + *min = 0; + *max = 3; + *deflt = int(NoNormalization); + val = (int)m_normalization; } else { val = Layer::getPropertyRangeAndValue(name, min, max, deflt); @@ -399,6 +387,9 @@ case 4: return tr("Phase"); } } + if (name == "Normalization") { + return ""; // icon only + } if (name == "Window Size") { return QString("%1").arg(32 << value); } @@ -465,6 +456,22 @@ return tr(""); } +QString +SpectrogramLayer::getPropertyValueIconName(const PropertyName &name, + int value) const +{ + if (name == "Normalization") { + switch(value) { + default: + case 0: return "normalise-none"; + case 1: return "normalise-columns"; + case 2: return "normalise"; + case 3: return "normalise-hybrid"; + } + } + return ""; +} + RangeMapper * SpectrogramLayer::getNewPropertyRangeMapper(const PropertyName &name) const { @@ -555,10 +562,14 @@ case 1: setBinDisplay(PeakBins); break; case 2: setBinDisplay(PeakFrequencies); break; } - } else if (name == "Normalize Columns") { - setNormalizeColumns(value ? true : false); - } else if (name == "Normalize Visible Area") { - setNormalizeVisibleArea(value ? true : false); + } else if (name == "Normalization") { + switch (value) { + default: + case 0: setNormalization(NoNormalization); break; + case 1: setNormalization(NormalizeColumns); break; + case 2: setNormalization(NormalizeVisibleArea); break; + case 3: setNormalization(NormalizeHybrid); break; + } } } @@ -934,60 +945,21 @@ } void -SpectrogramLayer::setNormalizeColumns(bool n) +SpectrogramLayer::setNormalization(Normalization n) { - if (m_normalizeColumns == n) return; + if (m_normalization == n) return; invalidateImageCaches(); invalidateMagnitudes(); - m_normalizeColumns = n; + m_normalization = n; emit layerParametersChanged(); } -bool -SpectrogramLayer::getNormalizeColumns() const +SpectrogramLayer::Normalization +SpectrogramLayer::getNormalization() const { - return m_normalizeColumns; -} - -void -SpectrogramLayer::setNormalizeHybrid(bool n) -{ - if (m_normalizeHybrid == n) return; - - invalidateImageCaches(); - invalidateMagnitudes(); - m_normalizeHybrid = n; - - emit layerParametersChanged(); -} - -bool -SpectrogramLayer::getNormalizeHybrid() const -{ - return m_normalizeHybrid; -} - -void -SpectrogramLayer::setNormalizeVisibleArea(bool n) -{ - SVDEBUG << "SpectrogramLayer::setNormalizeVisibleArea(" << n - << ") (from " << m_normalizeVisibleArea << ")" << endl; - - if (m_normalizeVisibleArea == n) return; - - invalidateImageCaches(); - invalidateMagnitudes(); - m_normalizeVisibleArea = n; - - emit layerParametersChanged(); -} - -bool -SpectrogramLayer::getNormalizeVisibleArea() const -{ - return m_normalizeVisibleArea; + return m_normalization; } void @@ -1190,10 +1162,10 @@ double min = 0.0; double max = 1.0; - if (m_normalizeVisibleArea) { + if (m_normalization == NormalizeVisibleArea) { min = m_viewMags[v].getMin(); max = m_viewMags[v].getMax(); - } else if (!m_normalizeColumns) { + } else if (m_normalization != NormalizeColumns) { if (m_colourScale == LinearColourScale //|| // m_colourScale == MeterColourScale) { ) { @@ -1968,7 +1940,7 @@ #ifdef DEBUG_SPECTROGRAM_REPAINT cerr << "SpectrogramLayer: magnitude range changed to [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << endl; #endif - if (m_normalizeVisibleArea) { + if (m_normalization == NormalizeVisibleArea) { cache.validArea = QRect(); recreateWholeImageCache = true; } @@ -2403,7 +2375,7 @@ if (!m_synchronous) { - if (!m_normalizeVisibleArea || !overallMagChanged) { + if ((m_normalization != NormalizeVisibleArea) || !overallMagChanged) { if (cache.validArea.x() > 0) { #ifdef DEBUG_SPECTROGRAM_REPAINT @@ -2515,9 +2487,9 @@ minbin, maxbin - 1); if (m_colourScale == PhaseColourScale) { fft->getPhasesAt(sx, values, minbin, maxbin - minbin + 1); - } else if (m_normalizeColumns) { + } else if (m_normalization == NormalizeColumns) { fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); - } else if (m_normalizeHybrid) { + } else if (m_normalization == NormalizeHybrid) { fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); double max = fft->getMaximumMagnitudeAt(sx); if (max > 0.f) { @@ -2543,7 +2515,7 @@ double value = values[bin - minbin]; if (m_colourScale != PhaseColourScale) { - if (!m_normalizeColumns && !m_normalizeHybrid) { + if (m_normalization != NormalizeColumns) { value /= (m_fftSize/2.0); } mag.sample(float(value)); @@ -2682,15 +2654,15 @@ #endif if (m_colourScale == PhaseColourScale) { fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1); - } else if (m_normalizeColumns) { + } else if (m_normalization == NormalizeColumns) { fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); - } else if (m_normalizeHybrid) { + } else if (m_normalization == NormalizeHybrid) { fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); double max = fft->getMaximumMagnitudeAt(sx); + float scale = log10(max + 1.f); + cout << "sx = " << sx << ", max = " << max << ", log10(max) = " << log10(max) << ", scale = " << scale << endl; for (int i = minbin; i <= maxbin; ++i) { - if (max > 0.0) { - autoarray[i - minbin] = float(autoarray[i - minbin] * log10(max)); - } + autoarray[i - minbin] *= scale; } } else { fft->getMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); @@ -2700,7 +2672,8 @@ SVDEBUG << "Retrieving column " << sx << " from peaks cache" << endl; #endif c = sourceModel->getColumn(sx); - if (m_normalizeColumns || m_normalizeHybrid) { + if (m_normalization == NormalizeColumns || + m_normalization == NormalizeHybrid) { for (int y = 0; y < h; ++y) { if (c[y] > columnMax) columnMax = c[y]; } @@ -2743,7 +2716,8 @@ value = prop * v0 + (1.0 - prop) * v1; if (m_colourScale != PhaseColourScale) { - if (!m_normalizeColumns) { + if (m_normalization != NormalizeColumns && + m_normalization != NormalizeHybrid) { value /= (m_fftSize/2.0); } mag.sample(float(value)); @@ -2768,7 +2742,8 @@ } if (m_colourScale != PhaseColourScale) { - if (!m_normalizeColumns) { + if (m_normalization != NormalizeColumns && + m_normalization != NormalizeHybrid) { value /= (m_fftSize/2.0); } mag.sample(float(value)); @@ -2802,11 +2777,12 @@ double peak = peaks[y]; if (m_colourScale != PhaseColourScale && - (m_normalizeColumns || m_normalizeHybrid) && + (m_normalization == NormalizeColumns || + m_normalization == NormalizeHybrid) && columnMax > 0.f) { peak /= columnMax; - if (m_normalizeHybrid) { - peak *= log10(columnMax); + if (m_normalization == NormalizeHybrid) { + peak *= log10(columnMax + 1.f); } } @@ -3663,9 +3639,9 @@ s += QString("normalizeColumns=\"%1\" " "normalizeVisibleArea=\"%2\" " "normalizeHybrid=\"%3\" ") - .arg(m_normalizeColumns ? "true" : "false") - .arg(m_normalizeVisibleArea ? "true" : "false") - .arg(m_normalizeHybrid ? "true" : "false"); + .arg(m_normalization == NormalizeColumns ? "true" : "false") + .arg(m_normalization == NormalizeVisibleArea ? "true" : "false") + .arg(m_normalization == NormalizeHybrid ? "true" : "false"); Layer::toXml(stream, indent, extraAttributes + " " + s); } @@ -3733,14 +3709,20 @@ bool normalizeColumns = (attributes.value("normalizeColumns").trimmed() == "true"); - setNormalizeColumns(normalizeColumns); + if (normalizeColumns) { + setNormalization(NormalizeColumns); + } bool normalizeVisibleArea = (attributes.value("normalizeVisibleArea").trimmed() == "true"); - setNormalizeVisibleArea(normalizeVisibleArea); + if (normalizeVisibleArea) { + setNormalization(NormalizeVisibleArea); + } bool normalizeHybrid = (attributes.value("normalizeHybrid").trimmed() == "true"); - setNormalizeHybrid(normalizeHybrid); + if (normalizeHybrid) { + setNormalization(NormalizeHybrid); + } } diff -r 64c2b3a4435a -r 98827470ada2 layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Fri Jun 26 14:10:40 2015 +0100 +++ b/layer/SpectrogramLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -88,6 +88,8 @@ int *min, int *max, int *deflt) const; virtual QString getPropertyValueLabel(const PropertyName &, int value) const; + virtual QString getPropertyValueIconName(const PropertyName &, + int value) const; virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const; virtual void setProperty(const PropertyName &, int value); @@ -170,27 +172,24 @@ */ void setBinDisplay(BinDisplay); BinDisplay getBinDisplay() const; - - /** - * Normalize each column to its maximum value, independent of its - * neighbours. - */ - void setNormalizeColumns(bool n); - bool getNormalizeColumns() const; + + enum Normalization { + NoNormalization, + NormalizeColumns, + NormalizeVisibleArea, + NormalizeHybrid + }; /** - * Normalize each value against the maximum in the visible region. + * Specify the normalization mode for bin values. */ - void setNormalizeVisibleArea(bool n); - bool getNormalizeVisibleArea() const; + void setNormalization(Normalization); + Normalization getNormalization() const; /** - * Normalize each column to its maximum value, and then scale by - * the log of the (absolute) maximum value. + * Specify the colour map. See ColourMapper for the colour map + * values. */ - void setNormalizeHybrid(bool n); - bool getNormalizeHybrid() const; - void setColourMap(int map); int getColourMap() const; @@ -272,9 +271,7 @@ QColor m_crosshairColour; FrequencyScale m_frequencyScale; BinDisplay m_binDisplay; - bool m_normalizeColumns; - bool m_normalizeVisibleArea; - bool m_normalizeHybrid; + Normalization m_normalization; int m_lastEmittedZoomStep; bool m_synchronous; diff -r 64c2b3a4435a -r 98827470ada2 widgets/PropertyBox.cpp --- a/widgets/PropertyBox.cpp Fri Jun 26 14:10:40 2015 +0100 +++ b/widgets/PropertyBox.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -443,7 +443,16 @@ if (type == PropertyContainer::ValueProperty) { for (int i = min; i <= max; ++i) { - cb->addItem(m_container->getPropertyValueLabel(name, i)); + + QString label = m_container->getPropertyValueLabel(name, i); + QString iname = m_container->getPropertyValueIconName(name, i); + + if (iname != "") { + QIcon icon(IconLoader().load(iname)); + cb->addItem(icon, label); + } else { + cb->addItem(label); + } } } else if (type == PropertyContainer::UnitsProperty) {