Mercurial > hg > svgui
comparison layer/SpectrumLayer.cpp @ 284:1284955856ab
* threshold, show-peaks properties in spectrum
author | Chris Cannam |
---|---|
date | Fri, 06 Jul 2007 15:17:35 +0000 |
parents | 4edaff85875d |
children | 9dd432665059 |
comparison
equal
deleted
inserted
replaced
283:86a112b5b319 | 284:1284955856ab |
---|---|
30 m_channel(-1), | 30 m_channel(-1), |
31 m_channelSet(false), | 31 m_channelSet(false), |
32 m_windowSize(1024), | 32 m_windowSize(1024), |
33 m_windowType(HanningWindow), | 33 m_windowType(HanningWindow), |
34 m_windowHopLevel(2), | 34 m_windowHopLevel(2), |
35 m_showPeaks(false), | |
35 m_newFFTNeeded(true) | 36 m_newFFTNeeded(true) |
36 { | 37 { |
37 Preferences *prefs = Preferences::getInstance(); | 38 Preferences *prefs = Preferences::getInstance(); |
38 connect(prefs, SIGNAL(propertyChanged(PropertyContainer::PropertyName)), | 39 connect(prefs, SIGNAL(propertyChanged(PropertyContainer::PropertyName)), |
39 this, SLOT(preferenceChanged(PropertyContainer::PropertyName))); | 40 this, SLOT(preferenceChanged(PropertyContainer::PropertyName))); |
106 return; | 107 return; |
107 } | 108 } |
108 | 109 |
109 m_channel = channel; | 110 m_channel = channel; |
110 | 111 |
111 //!!! if (!fft) setupFFT(); | |
112 | |
113 emit layerParametersChanged(); | 112 emit layerParametersChanged(); |
114 } | 113 } |
115 | 114 |
116 Layer::PropertyList | 115 Layer::PropertyList |
117 SpectrumLayer::getProperties() const | 116 SpectrumLayer::getProperties() const |
118 { | 117 { |
119 PropertyList list = SliceLayer::getProperties(); | 118 PropertyList list = SliceLayer::getProperties(); |
120 list.push_back("Window Size"); | 119 list.push_back("Window Size"); |
121 list.push_back("Window Increment"); | 120 list.push_back("Window Increment"); |
121 list.push_back("Show Peak Frequencies"); | |
122 return list; | 122 return list; |
123 } | 123 } |
124 | 124 |
125 QString | 125 QString |
126 SpectrumLayer::getPropertyLabel(const PropertyName &name) const | 126 SpectrumLayer::getPropertyLabel(const PropertyName &name) const |
127 { | 127 { |
128 if (name == "Window Size") return tr("Window Size"); | 128 if (name == "Window Size") return tr("Window Size"); |
129 if (name == "Window Increment") return tr("Window Overlap"); | 129 if (name == "Window Increment") return tr("Window Overlap"); |
130 if (name == "Show Peak Frequencies") return tr("Show Peak Frequencies"); | |
130 return SliceLayer::getPropertyLabel(name); | 131 return SliceLayer::getPropertyLabel(name); |
131 } | 132 } |
132 | 133 |
133 Layer::PropertyType | 134 Layer::PropertyType |
134 SpectrumLayer::getPropertyType(const PropertyName &name) const | 135 SpectrumLayer::getPropertyType(const PropertyName &name) const |
135 { | 136 { |
136 if (name == "Window Size") return ValueProperty; | 137 if (name == "Window Size") return ValueProperty; |
137 if (name == "Window Increment") return ValueProperty; | 138 if (name == "Window Increment") return ValueProperty; |
139 if (name == "Show Peak Frequencies") return ToggleProperty; | |
138 return SliceLayer::getPropertyType(name); | 140 return SliceLayer::getPropertyType(name); |
139 } | 141 } |
140 | 142 |
141 QString | 143 QString |
142 SpectrumLayer::getPropertyGroupName(const PropertyName &name) const | 144 SpectrumLayer::getPropertyGroupName(const PropertyName &name) const |
143 { | 145 { |
144 if (name == "Window Size" || | 146 if (name == "Window Size" || |
145 name == "Window Increment") return tr("Window"); | 147 name == "Window Increment") return tr("Window"); |
148 if (name == "Show Peak Frequencies") return tr("Plot Type"); | |
146 return SliceLayer::getPropertyGroupName(name); | 149 return SliceLayer::getPropertyGroupName(name); |
147 } | 150 } |
148 | 151 |
149 int | 152 int |
150 SpectrumLayer::getPropertyRangeAndValue(const PropertyName &name, | 153 SpectrumLayer::getPropertyRangeAndValue(const PropertyName &name, |
173 *max = 5; | 176 *max = 5; |
174 *deflt = 2; | 177 *deflt = 2; |
175 | 178 |
176 val = m_windowHopLevel; | 179 val = m_windowHopLevel; |
177 | 180 |
181 } else if (name == "Show Peak Frequencies") { | |
182 | |
183 return m_showPeaks ? 1 : 0; | |
184 | |
178 } else { | 185 } else { |
179 | 186 |
180 val = SliceLayer::getPropertyRangeAndValue(name, min, max, deflt); | 187 val = SliceLayer::getPropertyRangeAndValue(name, min, max, deflt); |
181 } | 188 } |
182 | 189 |
215 { | 222 { |
216 if (name == "Window Size") { | 223 if (name == "Window Size") { |
217 setWindowSize(32 << value); | 224 setWindowSize(32 << value); |
218 } else if (name == "Window Increment") { | 225 } else if (name == "Window Increment") { |
219 setWindowHopLevel(value); | 226 setWindowHopLevel(value); |
227 } else if (name == "Show Peak Frequencies") { | |
228 setShowPeaks(value ? true : false); | |
220 } else { | 229 } else { |
221 SliceLayer::setProperty(name, value); | 230 SliceLayer::setProperty(name, value); |
222 } | 231 } |
223 } | 232 } |
224 | 233 |
225 void | 234 void |
226 SpectrumLayer::setWindowSize(size_t ws) | 235 SpectrumLayer::setWindowSize(size_t ws) |
227 { | 236 { |
228 if (m_windowSize == ws) return; | 237 if (m_windowSize == ws) return; |
229 m_windowSize = ws; | 238 m_windowSize = ws; |
230 //!!! setupFFT(); | |
231 m_newFFTNeeded = true; | 239 m_newFFTNeeded = true; |
232 emit layerParametersChanged(); | 240 emit layerParametersChanged(); |
233 } | 241 } |
234 | 242 |
235 void | 243 void |
236 SpectrumLayer::setWindowHopLevel(size_t v) | 244 SpectrumLayer::setWindowHopLevel(size_t v) |
237 { | 245 { |
238 if (m_windowHopLevel == v) return; | 246 if (m_windowHopLevel == v) return; |
239 m_windowHopLevel = v; | 247 m_windowHopLevel = v; |
240 //!!! setupFFT(); | |
241 m_newFFTNeeded = true; | 248 m_newFFTNeeded = true; |
242 emit layerParametersChanged(); | 249 emit layerParametersChanged(); |
243 } | 250 } |
244 | 251 |
245 void | 252 void |
246 SpectrumLayer::setWindowType(WindowType w) | 253 SpectrumLayer::setWindowType(WindowType w) |
247 { | 254 { |
248 if (m_windowType == w) return; | 255 if (m_windowType == w) return; |
249 m_windowType = w; | 256 m_windowType = w; |
250 //!!! setupFFT(); | |
251 m_newFFTNeeded = true; | 257 m_newFFTNeeded = true; |
258 emit layerParametersChanged(); | |
259 } | |
260 | |
261 void | |
262 SpectrumLayer::setShowPeaks(bool show) | |
263 { | |
264 if (m_showPeaks == show) return; | |
265 m_showPeaks = show; | |
252 emit layerParametersChanged(); | 266 emit layerParametersChanged(); |
253 } | 267 } |
254 | 268 |
255 void | 269 void |
256 SpectrumLayer::preferenceChanged(PropertyContainer::PropertyName name) | 270 SpectrumLayer::preferenceChanged(PropertyContainer::PropertyName name) |
363 { | 377 { |
364 value = getValueForY(y, v); | 378 value = getValueForY(y, v); |
365 | 379 |
366 if (m_energyScale == dBScale || m_energyScale == MeterScale) { | 380 if (m_energyScale == dBScale || m_energyScale == MeterScale) { |
367 | 381 |
368 float thresh = -80.f; | |
369 | |
370 if (value > 0.f) { | 382 if (value > 0.f) { |
371 value = 10.f * log10f(value); | 383 value = 10.f * log10f(value); |
372 if (value < thresh) value = thresh; | 384 if (value < m_threshold) value = m_threshold; |
373 } else value = thresh; | 385 } else value = m_threshold; |
374 | 386 |
375 unit = "dBV"; | 387 unit = "dBV"; |
376 | 388 |
377 } else { | 389 } else { |
378 unit = "V"; | 390 unit = "V"; |
474 pitchLabel, | 486 pitchLabel, |
475 View::OutlinedText); | 487 View::OutlinedText); |
476 } | 488 } |
477 | 489 |
478 float value = getValueForY(cursorPos.y(), v); | 490 float value = getValueForY(cursorPos.y(), v); |
479 float thresh = -80.f; | 491 float thresh = m_threshold; |
480 float db = thresh; | 492 float db = thresh; |
481 if (value > 0.f) db = 10.f * log10f(value); | 493 if (value > 0.f) db = 10.f * log10f(value); |
482 if (db < thresh) db = thresh; | 494 if (db < thresh) db = thresh; |
483 | 495 |
484 v->drawVisibleText(paint, | 496 v->drawVisibleText(paint, |
632 int w = v->width() - xorigin - 1; | 644 int w = v->width() - xorigin - 1; |
633 | 645 |
634 int pkh = 0; | 646 int pkh = 0; |
635 if (m_binScale == LogBins) pkh = 10; | 647 if (m_binScale == LogBins) pkh = 10; |
636 | 648 |
637 if (fft) { | 649 if (fft && m_showPeaks) { |
638 | 650 |
639 // draw peak lines | 651 // draw peak lines |
640 //!!! should be optional | |
641 | 652 |
642 size_t col = v->getCentreFrame() / fft->getResolution(); | 653 size_t col = v->getCentreFrame() / fft->getResolution(); |
643 | 654 |
644 paint.save(); | 655 paint.save(); |
645 paint.setRenderHint(QPainter::Antialiasing, false); | 656 paint.setRenderHint(QPainter::Antialiasing, false); |
736 | 747 |
737 int n = (i % 12); | 748 int n = (i % 12); |
738 | 749 |
739 if (n == 1) { | 750 if (n == 1) { |
740 // C# -- fill the C from here | 751 // C# -- fill the C from here |
752 QColor col = Qt::gray; | |
753 if (i == 61) { // filling middle C | |
754 col = Qt::blue; | |
755 col = col.light(150); | |
756 } | |
741 if (x - ppx > 2) { | 757 if (x - ppx > 2) { |
742 paint.fillRect((px + ppx) / 2 + 1, | 758 paint.fillRect((px + ppx) / 2 + 1, |
743 h - pkh, | 759 h - pkh, |
744 x - (px + ppx) / 2 - 1, | 760 x - (px + ppx) / 2 - 1, |
745 pkh, | 761 pkh, |
746 Qt::gray); | 762 col); |
747 } | 763 } |
748 } | 764 } |
749 | 765 |
750 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { | 766 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { |
751 // black notes | 767 // black notes |