Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 197:6b023411087b
* Work on harmonising colour and scale ranges between types of layer
* Add normalize options to colour 3d plot layer
author | Chris Cannam |
---|---|
date | Thu, 01 Feb 2007 14:31:28 +0000 |
parents | 22c99c8aa1e0 |
children | 45e995ed84d9 |
comparison
equal
deleted
inserted
replaced
196:22c99c8aa1e0 | 197:6b023411087b |
---|---|
52 m_colourRotation(0), | 52 m_colourRotation(0), |
53 m_minFrequency(10), | 53 m_minFrequency(10), |
54 m_maxFrequency(8000), | 54 m_maxFrequency(8000), |
55 m_initialMaxFrequency(8000), | 55 m_initialMaxFrequency(8000), |
56 m_colourScale(dBColourScale), | 56 m_colourScale(dBColourScale), |
57 m_colourScheme(0), | 57 m_colourMap(0), |
58 m_frequencyScale(LinearFrequencyScale), | 58 m_frequencyScale(LinearFrequencyScale), |
59 m_binDisplay(AllBins), | 59 m_binDisplay(AllBins), |
60 m_normalizeColumns(false), | 60 m_normalizeColumns(false), |
61 m_normalizeVisibleArea(false), | 61 m_normalizeVisibleArea(false), |
62 m_lastEmittedZoomStep(-1), | 62 m_lastEmittedZoomStep(-1), |
88 Preferences *prefs = Preferences::getInstance(); | 88 Preferences *prefs = Preferences::getInstance(); |
89 connect(prefs, SIGNAL(propertyChanged(PropertyContainer::PropertyName)), | 89 connect(prefs, SIGNAL(propertyChanged(PropertyContainer::PropertyName)), |
90 this, SLOT(preferenceChanged(PropertyContainer::PropertyName))); | 90 this, SLOT(preferenceChanged(PropertyContainer::PropertyName))); |
91 setWindowType(prefs->getWindowType()); | 91 setWindowType(prefs->getWindowType()); |
92 | 92 |
93 setColourmap(); | 93 initialisePalette(); |
94 } | 94 } |
95 | 95 |
96 SpectrogramLayer::~SpectrogramLayer() | 96 SpectrogramLayer::~SpectrogramLayer() |
97 { | 97 { |
98 delete m_updateTimer; | 98 delete m_updateTimer; |
187 name == "Frequency Scale") return tr("Bins"); | 187 name == "Frequency Scale") return tr("Bins"); |
188 if (name == "Window Size" || | 188 if (name == "Window Size" || |
189 name == "Window Increment" || | 189 name == "Window Increment" || |
190 name == "Zero Padding") return tr("Window"); | 190 name == "Zero Padding") return tr("Window"); |
191 if (name == "Colour" || | 191 if (name == "Colour" || |
192 // name == "Gain" || | |
193 name == "Threshold" || | 192 name == "Threshold" || |
194 name == "Colour Rotation") return tr("Colour"); | 193 name == "Colour Rotation") return tr("Colour"); |
195 if (name == "Normalize Columns" || | 194 if (name == "Normalize Columns" || |
196 name == "Normalize Visible Area" || | 195 name == "Normalize Visible Area" || |
197 // name == "Bin Display" || | |
198 name == "Gain" || | 196 name == "Gain" || |
199 name == "Colour Scale") return tr("Scale"); | 197 name == "Colour Scale") return tr("Scale"); |
200 // if (name == "Max Frequency" || | |
201 // name == "Min Frequency" || | |
202 // name == "Frequency Scale" || | |
203 // name == "Frequency Adjustment") return tr("Range"); | |
204 return QString(); | 198 return QString(); |
205 } | 199 } |
206 | 200 |
207 int | 201 int |
208 SpectrogramLayer::getPropertyRangeAndValue(const PropertyName &name, | 202 SpectrogramLayer::getPropertyRangeAndValue(const PropertyName &name, |
249 } else if (name == "Colour") { | 243 } else if (name == "Colour") { |
250 | 244 |
251 *min = 0; | 245 *min = 0; |
252 *max = ColourMapper::getColourMapCount() - 1; | 246 *max = ColourMapper::getColourMapCount() - 1; |
253 | 247 |
254 deft = m_colourScheme; | 248 deft = m_colourMap; |
255 | 249 |
256 } else if (name == "Window Size") { | 250 } else if (name == "Window Size") { |
257 | 251 |
258 *min = 0; | 252 *min = 0; |
259 *max = 10; | 253 *max = 10; |
443 if (value == -50) setThreshold(0.0); | 437 if (value == -50) setThreshold(0.0); |
444 else setThreshold(AudioLevel::dB_to_multiplier(value)); | 438 else setThreshold(AudioLevel::dB_to_multiplier(value)); |
445 } else if (name == "Colour Rotation") { | 439 } else if (name == "Colour Rotation") { |
446 setColourRotation(value); | 440 setColourRotation(value); |
447 } else if (name == "Colour") { | 441 } else if (name == "Colour") { |
448 setColourScheme(value); | 442 setColourMap(value); |
449 } else if (name == "Window Size") { | 443 } else if (name == "Window Size") { |
450 setWindowSize(32 << value); | 444 setWindowSize(32 << value); |
451 } else if (name == "Window Increment") { | 445 } else if (name == "Window Increment") { |
452 setWindowHopLevel(value); | 446 setWindowHopLevel(value); |
453 } else if (name == "Zero Padding") { | 447 } else if (name == "Zero Padding") { |
753 if (r < 0) r = 0; | 747 if (r < 0) r = 0; |
754 if (r > 256) r = 256; | 748 if (r > 256) r = 256; |
755 int distance = r - m_colourRotation; | 749 int distance = r - m_colourRotation; |
756 | 750 |
757 if (distance != 0) { | 751 if (distance != 0) { |
758 rotateColourmap(-distance); | 752 rotatePalette(-distance); |
759 m_colourRotation = r; | 753 m_colourRotation = r; |
760 } | 754 } |
761 | 755 |
762 emit layerParametersChanged(); | 756 emit layerParametersChanged(); |
763 } | 757 } |
779 { | 773 { |
780 return m_colourScale; | 774 return m_colourScale; |
781 } | 775 } |
782 | 776 |
783 void | 777 void |
784 SpectrogramLayer::setColourScheme(int scheme) | 778 SpectrogramLayer::setColourMap(int map) |
785 { | 779 { |
786 if (m_colourScheme == scheme) return; | 780 if (m_colourMap == map) return; |
787 | 781 |
788 invalidatePixmapCaches(); | 782 invalidatePixmapCaches(); |
789 | 783 |
790 m_colourScheme = scheme; | 784 m_colourMap = map; |
791 setColourmap(); | 785 initialisePalette(); |
792 | 786 |
793 emit layerParametersChanged(); | 787 emit layerParametersChanged(); |
794 } | 788 } |
795 | 789 |
796 int | 790 int |
797 SpectrogramLayer::getColourScheme() const | 791 SpectrogramLayer::getColourMap() const |
798 { | 792 { |
799 return m_colourScheme; | 793 return m_colourMap; |
800 } | 794 } |
801 | 795 |
802 void | 796 void |
803 SpectrogramLayer::setFrequencyScale(FrequencyScale frequencyScale) | 797 SpectrogramLayer::setFrequencyScale(FrequencyScale frequencyScale) |
804 { | 798 { |
990 m_updateTimer = 0; | 984 m_updateTimer = 0; |
991 } | 985 } |
992 } | 986 } |
993 | 987 |
994 void | 988 void |
995 SpectrogramLayer::setColourmap() | 989 SpectrogramLayer::initialisePalette() |
996 { | 990 { |
997 int formerRotation = m_colourRotation; | 991 int formerRotation = m_colourRotation; |
998 | 992 |
999 if (m_colourScheme == (int)ColourMapper::BlackOnWhite) { | 993 if (m_colourMap == (int)ColourMapper::BlackOnWhite) { |
1000 m_colourMap.setColour(NO_VALUE, Qt::white); | 994 m_palette.setColour(NO_VALUE, Qt::white); |
1001 } else { | 995 } else { |
1002 m_colourMap.setColour(NO_VALUE, Qt::black); | 996 m_palette.setColour(NO_VALUE, Qt::black); |
1003 } | 997 } |
1004 | 998 |
1005 ColourMapper mapper(m_colourScheme, 1.f, 256.f); | 999 ColourMapper mapper(m_colourMap, 1.f, 255.f); |
1006 | 1000 |
1007 for (int pixel = 1; pixel < 256; ++pixel) { | 1001 for (int pixel = 1; pixel < 256; ++pixel) { |
1008 | 1002 m_palette.setColour(pixel, mapper.map(pixel)); |
1009 m_colourMap.setColour(pixel, mapper.map(pixel)); | |
1010 } | 1003 } |
1011 | 1004 |
1012 m_crosshairColour = mapper.getContrastingColour(); | 1005 m_crosshairColour = mapper.getContrastingColour(); |
1013 | 1006 |
1014 m_colourRotation = 0; | 1007 m_colourRotation = 0; |
1015 rotateColourmap(m_colourRotation - formerRotation); | 1008 rotatePalette(m_colourRotation - formerRotation); |
1016 m_colourRotation = formerRotation; | 1009 m_colourRotation = formerRotation; |
1017 } | 1010 } |
1018 | 1011 |
1019 void | 1012 void |
1020 SpectrogramLayer::rotateColourmap(int distance) | 1013 SpectrogramLayer::rotatePalette(int distance) |
1021 { | 1014 { |
1022 QColor newPixels[256]; | 1015 QColor newPixels[256]; |
1023 | 1016 |
1024 newPixels[NO_VALUE] = m_colourMap.getColour(NO_VALUE); | 1017 newPixels[NO_VALUE] = m_palette.getColour(NO_VALUE); |
1025 | 1018 |
1026 for (int pixel = 1; pixel < 256; ++pixel) { | 1019 for (int pixel = 1; pixel < 256; ++pixel) { |
1027 int target = pixel + distance; | 1020 int target = pixel + distance; |
1028 while (target < 1) target += 255; | 1021 while (target < 1) target += 255; |
1029 while (target > 255) target -= 255; | 1022 while (target > 255) target -= 255; |
1030 newPixels[target] = m_colourMap.getColour(pixel); | 1023 newPixels[target] = m_palette.getColour(pixel); |
1031 } | 1024 } |
1032 | 1025 |
1033 for (int pixel = 0; pixel < 256; ++pixel) { | 1026 for (int pixel = 0; pixel < 256; ++pixel) { |
1034 m_colourMap.setColour(pixel, newPixels[pixel]); | 1027 m_palette.setColour(pixel, newPixels[pixel]); |
1035 } | 1028 } |
1036 } | 1029 } |
1037 | 1030 |
1038 float | 1031 float |
1039 SpectrogramLayer::calculateFrequency(size_t bin, | 1032 SpectrogramLayer::calculateFrequency(size_t bin, |
1664 } | 1657 } |
1665 | 1658 |
1666 void | 1659 void |
1667 SpectrogramLayer::paint(View *v, QPainter &paint, QRect rect) const | 1660 SpectrogramLayer::paint(View *v, QPainter &paint, QRect rect) const |
1668 { | 1661 { |
1669 if (m_colourScheme == (int)ColourMapper::BlackOnWhite) { | 1662 if (m_colourMap == (int)ColourMapper::BlackOnWhite) { |
1670 v->setLightBackground(true); | 1663 v->setLightBackground(true); |
1671 } else { | 1664 } else { |
1672 v->setLightBackground(false); | 1665 v->setLightBackground(false); |
1673 } | 1666 } |
1674 | 1667 |
1928 | 1921 |
1929 if (m_drawBuffer.width() < w || m_drawBuffer.height() < h) { | 1922 if (m_drawBuffer.width() < w || m_drawBuffer.height() < h) { |
1930 m_drawBuffer = QImage(w, h, QImage::Format_RGB32); | 1923 m_drawBuffer = QImage(w, h, QImage::Format_RGB32); |
1931 } | 1924 } |
1932 | 1925 |
1933 m_drawBuffer.fill(m_colourMap.getColour(0).rgb()); | 1926 m_drawBuffer.fill(m_palette.getColour(0).rgb()); |
1934 | 1927 |
1935 int sr = m_model->getSampleRate(); | 1928 int sr = m_model->getSampleRate(); |
1936 | 1929 |
1937 // Set minFreq and maxFreq to the frequency extents of the possibly | 1930 // Set minFreq and maxFreq to the frequency extents of the possibly |
1938 // zero-padded visible bin range, and displayMinFreq and displayMaxFreq | 1931 // zero-padded visible bin range, and displayMinFreq and displayMaxFreq |
2106 | 2099 |
2107 float avg = ymag[y] / ydiv[y]; | 2100 float avg = ymag[y] / ydiv[y]; |
2108 pixel = getDisplayValue(v, avg); | 2101 pixel = getDisplayValue(v, avg); |
2109 | 2102 |
2110 assert(x <= m_drawBuffer.width()); | 2103 assert(x <= m_drawBuffer.width()); |
2111 QColor c = m_colourMap.getColour(pixel); | 2104 QColor c = m_palette.getColour(pixel); |
2112 m_drawBuffer.setPixel(x, y, | 2105 m_drawBuffer.setPixel(x, y, |
2113 qRgb(c.red(), c.green(), c.blue())); | 2106 qRgb(c.red(), c.green(), c.blue())); |
2114 } | 2107 } |
2115 } | 2108 } |
2116 } | 2109 } |
2657 int colour = getDisplayValue(v, value * m_gain); | 2650 int colour = getDisplayValue(v, value * m_gain); |
2658 */ | 2651 */ |
2659 /* | 2652 /* |
2660 int colour = (i * 255) / ch + 1; | 2653 int colour = (i * 255) / ch + 1; |
2661 */ | 2654 */ |
2662 paint.setPen(m_colourMap.getColour(colour)); | 2655 paint.setPen(m_palette.getColour(colour)); |
2663 | 2656 |
2664 int y = textHeight * topLines + 4 + ch - i; | 2657 int y = textHeight * topLines + 4 + ch - i; |
2665 | 2658 |
2666 paint.drawLine(5 + cw - cbw, y, cw + 2, y); | 2659 paint.drawLine(5 + cw - cbw, y, cw + 2, y); |
2667 | 2660 |
2937 "normalizeColumns=\"%8\" " | 2930 "normalizeColumns=\"%8\" " |
2938 "normalizeVisibleArea=\"%9\"") | 2931 "normalizeVisibleArea=\"%9\"") |
2939 .arg(m_minFrequency) | 2932 .arg(m_minFrequency) |
2940 .arg(m_maxFrequency) | 2933 .arg(m_maxFrequency) |
2941 .arg(m_colourScale) | 2934 .arg(m_colourScale) |
2942 .arg(m_colourScheme) | 2935 .arg(m_colourMap) |
2943 .arg(m_colourRotation) | 2936 .arg(m_colourRotation) |
2944 .arg(m_frequencyScale) | 2937 .arg(m_frequencyScale) |
2945 .arg(m_binDisplay) | 2938 .arg(m_binDisplay) |
2946 .arg(m_normalizeColumns ? "true" : "false") | 2939 .arg(m_normalizeColumns ? "true" : "false") |
2947 .arg(m_normalizeVisibleArea ? "true" : "false"); | 2940 .arg(m_normalizeVisibleArea ? "true" : "false"); |
2994 | 2987 |
2995 ColourScale colourScale = (ColourScale) | 2988 ColourScale colourScale = (ColourScale) |
2996 attributes.value("colourScale").toInt(&ok); | 2989 attributes.value("colourScale").toInt(&ok); |
2997 if (ok) setColourScale(colourScale); | 2990 if (ok) setColourScale(colourScale); |
2998 | 2991 |
2999 int colourScheme = attributes.value("colourScheme").toInt(&ok); | 2992 int colourMap = attributes.value("colourScheme").toInt(&ok); |
3000 if (ok) setColourScheme(colourScheme); | 2993 if (ok) setColourMap(colourMap); |
3001 | 2994 |
3002 int colourRotation = attributes.value("colourRotation").toInt(&ok); | 2995 int colourRotation = attributes.value("colourRotation").toInt(&ok); |
3003 if (ok) setColourRotation(colourRotation); | 2996 if (ok) setColourRotation(colourRotation); |
3004 | 2997 |
3005 FrequencyScale frequencyScale = (FrequencyScale) | 2998 FrequencyScale frequencyScale = (FrequencyScale) |