Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 121:7363cacf7de0
* start work on prefs dialog
* some work on highlighting local points in spectrogram
author | Chris Cannam |
---|---|
date | Thu, 20 Jul 2006 16:51:20 +0000 |
parents | 8dfa20f1c70a |
children | 71992cee2ece |
comparison
equal
deleted
inserted
replaced
120:8dfa20f1c70a | 121:7363cacf7de0 |
---|---|
1337 int sr = m_model->getSampleRate(); | 1337 int sr = m_model->getSampleRate(); |
1338 | 1338 |
1339 //!!! wrong for smoothing -- wrong fft size for fft adapter | 1339 //!!! wrong for smoothing -- wrong fft size for fft adapter |
1340 | 1340 |
1341 for (int q = q0i; q <= q1i; ++q) { | 1341 for (int q = q0i; q <= q1i; ++q) { |
1342 int binfreq = (sr * q) / m_fftSize; | 1342 if (q == q0i) freqMin = (sr * q) / m_fftSize; |
1343 if (q == q0i) freqMin = binfreq; | 1343 if (q == q1i) freqMax = (sr * (q+1)) / m_fftSize; |
1344 if (q == q1i) freqMax = binfreq; | |
1345 } | 1344 } |
1346 return true; | 1345 return true; |
1347 } | 1346 } |
1348 | 1347 |
1349 bool | 1348 bool |
1542 (new FFTFuzzyAdapter(m_model, | 1541 (new FFTFuzzyAdapter(m_model, |
1543 m_channel, | 1542 m_channel, |
1544 m_windowType, | 1543 m_windowType, |
1545 m_windowSize, | 1544 m_windowSize, |
1546 getWindowIncrement(), | 1545 getWindowIncrement(), |
1547 getFFTSize(v), | 1546 fftSize, |
1548 true, | 1547 true, |
1549 m_candidateFillStartFrame), | 1548 m_candidateFillStartFrame), |
1550 0); | 1549 0); |
1551 | 1550 |
1552 delete m_updateTimer; | 1551 delete m_updateTimer; |
1695 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1694 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1696 std::cerr << "SpectrogramLayer: pixmap cache good" << std::endl; | 1695 std::cerr << "SpectrogramLayer: pixmap cache good" << std::endl; |
1697 #endif | 1696 #endif |
1698 | 1697 |
1699 paint.drawPixmap(rect, cache.pixmap, rect); | 1698 paint.drawPixmap(rect, cache.pixmap, rect); |
1699 illuminateLocalFeatures(v, paint); | |
1700 return; | 1700 return; |
1701 | 1701 |
1702 } else { | 1702 } else { |
1703 | 1703 |
1704 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1704 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1881 float minFreq = (float(minbin) * sr) / fftSize; | 1881 float minFreq = (float(minbin) * sr) / fftSize; |
1882 float maxFreq = (float(bins) * sr) / fftSize; | 1882 float maxFreq = (float(bins) * sr) / fftSize; |
1883 | 1883 |
1884 float ymag[h]; | 1884 float ymag[h]; |
1885 float ydiv[h]; | 1885 float ydiv[h]; |
1886 float yval[bins + 1]; | 1886 float yval[bins + 1]; //!!! cache this |
1887 | 1887 |
1888 size_t increment = getWindowIncrement(); | 1888 size_t increment = getWindowIncrement(); |
1889 | 1889 |
1890 bool logarithmic = (m_frequencyScale == LogFrequencyScale); | 1890 bool logarithmic = (m_frequencyScale == LogFrequencyScale); |
1891 | 1891 |
2069 // overallMagChanged | 2069 // overallMagChanged |
2070 cache.validArea = QRect(); | 2070 cache.validArea = QRect(); |
2071 v->update(); | 2071 v->update(); |
2072 } | 2072 } |
2073 | 2073 |
2074 QPoint localPos; | 2074 illuminateLocalFeatures(v, paint); |
2075 | |
2076 if (v->shouldIlluminateLocalFeatures(this, localPos)) { | |
2077 | |
2078 std::cerr << "SpectrogramLayer: shouldIlluminateLocalFeatures(" | |
2079 << localPos.x() << "," << localPos.y() << ")" << std::endl; | |
2080 | |
2081 float s0, s1; | |
2082 float q0, q1; | |
2083 | |
2084 if (getXBinRange(v, localPos.x(), s0, s1) && | |
2085 getYBinRange(v, localPos.y(), q0, q1)) { | |
2086 | |
2087 int s0i = int(s0 + 0.001); | |
2088 int s1i = int(s1); | |
2089 | |
2090 int q0i = int(q0 + 0.001); | |
2091 int q1i = int(q1); | |
2092 | |
2093 int x0 = v->getXForFrame(s0i * getWindowIncrement()); | |
2094 int x1 = v->getXForFrame(s1i * getWindowIncrement() + 1); | |
2095 int y1 = yval[q0i]; | |
2096 int y0 = yval[q1i + 1]; | |
2097 | |
2098 std::cerr << "SpectrogramLayer::paint: illuminate " | |
2099 << x0 << "," << y1 << " -> " << x1 << "," << y0 << std::endl; | |
2100 | |
2101 paint.setPen(Qt::white); | |
2102 paint.drawRect(x0, y1, x1 - x0 + 1, y0 - y1 + 1); | |
2103 } | |
2104 } | |
2105 | 2075 |
2106 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2076 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2107 std::cerr << "SpectrogramLayer::paint() returning" << std::endl; | 2077 std::cerr << "SpectrogramLayer::paint() returning" << std::endl; |
2108 #endif | 2078 #endif |
2079 } | |
2080 | |
2081 void | |
2082 SpectrogramLayer::illuminateLocalFeatures(View *v, QPainter &paint) const | |
2083 { | |
2084 QPoint localPos; | |
2085 if (!v->shouldIlluminateLocalFeatures(this, localPos) || !m_model) { | |
2086 return; | |
2087 } | |
2088 | |
2089 std::cerr << "SpectrogramLayer: illuminateLocalFeatures(" | |
2090 << localPos.x() << "," << localPos.y() << ")" << std::endl; | |
2091 | |
2092 float s0, s1; | |
2093 float f0, f1; | |
2094 | |
2095 if (getXBinRange(v, localPos.x(), s0, s1) && | |
2096 getYBinSourceRange(v, localPos.y(), f0, f1)) { | |
2097 | |
2098 int s0i = int(s0 + 0.001); | |
2099 int s1i = int(s1); | |
2100 | |
2101 int x0 = v->getXForFrame(s0i * getWindowIncrement()); | |
2102 int x1 = v->getXForFrame((s1i + 1) * getWindowIncrement()); | |
2103 | |
2104 int y1 = getYForFrequency(v, f1); | |
2105 int y0 = getYForFrequency(v, f0); | |
2106 | |
2107 std::cerr << "SpectrogramLayer: illuminate " | |
2108 << x0 << "," << y1 << " -> " << x1 << "," << y0 << std::endl; | |
2109 | |
2110 paint.setPen(Qt::white); | |
2111 paint.drawRect(x0, y1, x1 - x0 + 1, y0 - y1 + 1); | |
2112 } | |
2109 } | 2113 } |
2110 | 2114 |
2111 float | 2115 float |
2112 SpectrogramLayer::getYForFrequency(View *v, float frequency) const | 2116 SpectrogramLayer::getYForFrequency(View *v, float frequency) const |
2113 { | 2117 { |