Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 248:28c8e8e3c537
* Fix many compile warnings, remove some debug output
author | Chris Cannam |
---|---|
date | Mon, 30 Apr 2007 13:36:23 +0000 |
parents | b4809e942e7d |
children | 3fe622570b35 |
comparison
equal
deleted
inserted
replaced
247:0e9f59f991aa | 248:28c8e8e3c537 |
---|---|
730 void | 730 void |
731 SpectrogramLayer::setMinFrequency(size_t mf) | 731 SpectrogramLayer::setMinFrequency(size_t mf) |
732 { | 732 { |
733 if (m_minFrequency == mf) return; | 733 if (m_minFrequency == mf) return; |
734 | 734 |
735 std::cerr << "SpectrogramLayer::setMinFrequency: " << mf << std::endl; | 735 // std::cerr << "SpectrogramLayer::setMinFrequency: " << mf << std::endl; |
736 | 736 |
737 invalidatePixmapCaches(); | 737 invalidatePixmapCaches(); |
738 invalidateMagnitudes(); | 738 invalidateMagnitudes(); |
739 | 739 |
740 m_minFrequency = mf; | 740 m_minFrequency = mf; |
751 void | 751 void |
752 SpectrogramLayer::setMaxFrequency(size_t mf) | 752 SpectrogramLayer::setMaxFrequency(size_t mf) |
753 { | 753 { |
754 if (m_maxFrequency == mf) return; | 754 if (m_maxFrequency == mf) return; |
755 | 755 |
756 std::cerr << "SpectrogramLayer::setMaxFrequency: " << mf << std::endl; | 756 // std::cerr << "SpectrogramLayer::setMaxFrequency: " << mf << std::endl; |
757 | 757 |
758 invalidatePixmapCaches(); | 758 invalidatePixmapCaches(); |
759 invalidateMagnitudes(); | 759 invalidateMagnitudes(); |
760 | 760 |
761 m_maxFrequency = mf; | 761 m_maxFrequency = mf; |
958 #endif | 958 #endif |
959 | 959 |
960 for (ViewFFTMap::iterator i = m_fftModels.begin(); | 960 for (ViewFFTMap::iterator i = m_fftModels.begin(); |
961 i != m_fftModels.end(); ++i) { | 961 i != m_fftModels.end(); ++i) { |
962 | 962 |
963 const View *v = i->first; | |
964 const FFTModel *model = i->second.first; | 963 const FFTModel *model = i->second.first; |
965 size_t lastFill = i->second.second; | 964 size_t lastFill = i->second.second; |
966 | 965 |
967 if (model) { | 966 if (model) { |
968 | 967 |
1592 m_fftModels[v] = FFTFillPair(0, 0); | 1591 m_fftModels[v] = FFTFillPair(0, 0); |
1593 return 0; | 1592 return 0; |
1594 } | 1593 } |
1595 | 1594 |
1596 if (!m_sliceableModel) { | 1595 if (!m_sliceableModel) { |
1596 #ifdef DEBUG_SPECTROGRAM | |
1597 std::cerr << "SpectrogramLayer: emitting sliceableModelReplaced(0, " << model << ")" << std::endl; | 1597 std::cerr << "SpectrogramLayer: emitting sliceableModelReplaced(0, " << model << ")" << std::endl; |
1598 #endif | |
1598 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, model); | 1599 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, model); |
1599 m_sliceableModel = model; | 1600 m_sliceableModel = model; |
1600 } | 1601 } |
1601 | 1602 |
1602 m_fftModels[v] = FFTFillPair(model, 0); | 1603 m_fftModels[v] = FFTFillPair(model, 0); |
1668 int s0 = int(std::min(s00, s10) + 0.0001); | 1669 int s0 = int(std::min(s00, s10) + 0.0001); |
1669 int s1 = int(std::max(s01, s11) + 0.0001); | 1670 int s1 = int(std::max(s01, s11) + 0.0001); |
1670 | 1671 |
1671 // std::cerr << "SpectrogramLayer::updateViewMagnitudes: x0 = " << x0 << ", x1 = " << x1 << ", s00 = " << s00 << ", s11 = " << s11 << " s0 = " << s0 << ", s1 = " << s1 << std::endl; | 1672 // std::cerr << "SpectrogramLayer::updateViewMagnitudes: x0 = " << x0 << ", x1 = " << x1 << ", s00 = " << s00 << ", s11 = " << s11 << " s0 = " << s0 << ", s1 = " << s1 << std::endl; |
1672 | 1673 |
1673 if (m_columnMags.size() <= s1) { | 1674 if (int(m_columnMags.size()) <= s1) { |
1674 m_columnMags.resize(s1 + 1); | 1675 m_columnMags.resize(s1 + 1); |
1675 } | 1676 } |
1676 | 1677 |
1677 for (int s = s0; s <= s1; ++s) { | 1678 for (int s = s0; s <= s1; ++s) { |
1678 if (m_columnMags[s].isSet()) { | 1679 if (m_columnMags[s].isSet()) { |
1731 | 1732 |
1732 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1733 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1733 std::cerr << "SpectrogramLayer::paint(): pixmap cache valid area " << cache.validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << std::endl; | 1734 std::cerr << "SpectrogramLayer::paint(): pixmap cache valid area " << cache.validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << std::endl; |
1734 #endif | 1735 #endif |
1735 | 1736 |
1737 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
1736 bool stillCacheing = (m_updateTimer != 0); | 1738 bool stillCacheing = (m_updateTimer != 0); |
1737 | |
1738 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
1739 std::cerr << "SpectrogramLayer::paint(): Still cacheing = " << stillCacheing << std::endl; | 1739 std::cerr << "SpectrogramLayer::paint(): Still cacheing = " << stillCacheing << std::endl; |
1740 #endif | 1740 #endif |
1741 | 1741 |
1742 int zoomLevel = v->getZoomLevel(); | 1742 int zoomLevel = v->getZoomLevel(); |
1743 | 1743 |
2065 } | 2065 } |
2066 | 2066 |
2067 int s0i = int(s0 + 0.001); | 2067 int s0i = int(s0 + 0.001); |
2068 int s1i = int(s1); | 2068 int s1i = int(s1); |
2069 | 2069 |
2070 if (s1i >= fft->getWidth()) { | 2070 if (s1i >= int(fft->getWidth())) { |
2071 if (s0i >= fft->getWidth()) { | 2071 if (s0i >= int(fft->getWidth())) { |
2072 continue; | 2072 continue; |
2073 } else { | 2073 } else { |
2074 s1i = s0i; | 2074 s1i = s0i; |
2075 } | 2075 } |
2076 } | 2076 } |
2206 } | 2206 } |
2207 } | 2207 } |
2208 | 2208 |
2209 if (mag.isSet()) { | 2209 if (mag.isSet()) { |
2210 | 2210 |
2211 if (s >= m_columnMags.size()) { | 2211 if (s >= int(m_columnMags.size())) { |
2212 std::cerr << "INTERNAL ERROR: " << s << " >= " | 2212 std::cerr << "INTERNAL ERROR: " << s << " >= " |
2213 << m_columnMags.size() << " at SpectrogramLayer.cpp:2087" << std::endl; | 2213 << m_columnMags.size() << " at SpectrogramLayer.cpp:2087" << std::endl; |
2214 } | 2214 } |
2215 | 2215 |
2216 m_columnMags[s].sample(mag); | 2216 m_columnMags[s].sample(mag); |
2346 int s1i = int(s1); | 2346 int s1i = int(s1); |
2347 | 2347 |
2348 int x0 = v->getXForFrame(s0i * getWindowIncrement()); | 2348 int x0 = v->getXForFrame(s0i * getWindowIncrement()); |
2349 int x1 = v->getXForFrame((s1i + 1) * getWindowIncrement()); | 2349 int x1 = v->getXForFrame((s1i + 1) * getWindowIncrement()); |
2350 | 2350 |
2351 int y1 = getYForFrequency(v, f1); | 2351 int y1 = int(getYForFrequency(v, f1)); |
2352 int y0 = getYForFrequency(v, f0); | 2352 int y0 = int(getYForFrequency(v, f0)); |
2353 | 2353 |
2354 // std::cerr << "SpectrogramLayer: illuminate " | 2354 // std::cerr << "SpectrogramLayer: illuminate " |
2355 // << x0 << "," << y1 << " -> " << x1 << "," << y0 << std::endl; | 2355 // << x0 << "," << y1 << " -> " << x1 << "," << y0 << std::endl; |
2356 | 2356 |
2357 paint.setPen(Qt::white); | 2357 paint.setPen(Qt::white); |
2411 bool | 2411 bool |
2412 SpectrogramLayer::getDisplayExtents(float &min, float &max) const | 2412 SpectrogramLayer::getDisplayExtents(float &min, float &max) const |
2413 { | 2413 { |
2414 min = getEffectiveMinFrequency(); | 2414 min = getEffectiveMinFrequency(); |
2415 max = getEffectiveMaxFrequency(); | 2415 max = getEffectiveMaxFrequency(); |
2416 std::cerr << "SpectrogramLayer::getDisplayExtents: " << min << "->" << max << std::endl; | 2416 // std::cerr << "SpectrogramLayer::getDisplayExtents: " << min << "->" << max << std::endl; |
2417 return true; | 2417 return true; |
2418 } | 2418 } |
2419 | 2419 |
2420 bool | 2420 bool |
2421 SpectrogramLayer::setDisplayExtents(float min, float max) | 2421 SpectrogramLayer::setDisplayExtents(float min, float max) |
2448 | 2448 |
2449 return true; | 2449 return true; |
2450 } | 2450 } |
2451 | 2451 |
2452 bool | 2452 bool |
2453 SpectrogramLayer::snapToFeatureFrame(View *v, int &frame, | 2453 SpectrogramLayer::snapToFeatureFrame(View *, int &frame, |
2454 size_t &resolution, | 2454 size_t &resolution, |
2455 SnapType snap) const | 2455 SnapType snap) const |
2456 { | 2456 { |
2457 resolution = getWindowIncrement(); | 2457 resolution = getWindowIncrement(); |
2458 int left = (frame / resolution) * resolution; | 2458 int left = (frame / resolution) * resolution; |
2470 | 2470 |
2471 return true; | 2471 return true; |
2472 } | 2472 } |
2473 | 2473 |
2474 bool | 2474 bool |
2475 SpectrogramLayer::getCrosshairExtents(View *v, QPainter &paint, | 2475 SpectrogramLayer::getCrosshairExtents(View *v, QPainter &, |
2476 QPoint cursorPos, | 2476 QPoint cursorPos, |
2477 std::vector<QRect> &extents) const | 2477 std::vector<QRect> &extents) const |
2478 { | 2478 { |
2479 QRect vertical(cursorPos.x() - 12, 0, 12, v->height()); | 2479 QRect vertical(cursorPos.x() - 12, 0, 12, v->height()); |
2480 extents.push_back(vertical); | 2480 extents.push_back(vertical); |
2513 len = 10; | 2513 len = 10; |
2514 } | 2514 } |
2515 } | 2515 } |
2516 | 2516 |
2517 paint.drawLine(cursorPos.x() - len, | 2517 paint.drawLine(cursorPos.x() - len, |
2518 hy, | 2518 int(hy), |
2519 cursorPos.x(), | 2519 cursorPos.x(), |
2520 hy); | 2520 int(hy)); |
2521 | 2521 |
2522 ++harmonic; | 2522 ++harmonic; |
2523 } | 2523 } |
2524 | 2524 |
2525 paint.restore(); | 2525 paint.restore(); |
2646 | 2646 |
2647 return cw; | 2647 return cw; |
2648 } | 2648 } |
2649 | 2649 |
2650 int | 2650 int |
2651 SpectrogramLayer::getVerticalScaleWidth(View *v, QPainter &paint) const | 2651 SpectrogramLayer::getVerticalScaleWidth(View *, QPainter &paint) const |
2652 { | 2652 { |
2653 if (!m_model || !m_model->isOK()) return 0; | 2653 if (!m_model || !m_model->isOK()) return 0; |
2654 | 2654 |
2655 int cw = getColourScaleWidth(paint); | 2655 int cw = getColourScaleWidth(paint); |
2656 | 2656 |
2817 | 2817 |
2818 if (m_frequencyScale == LogFrequencyScale) { | 2818 if (m_frequencyScale == LogFrequencyScale) { |
2819 | 2819 |
2820 paint.drawLine(w - pkw - 1, 0, w - pkw - 1, h); | 2820 paint.drawLine(w - pkw - 1, 0, w - pkw - 1, h); |
2821 | 2821 |
2822 int sr = m_model->getSampleRate(); | |
2823 float minf = getEffectiveMinFrequency(); | 2822 float minf = getEffectiveMinFrequency(); |
2824 float maxf = getEffectiveMaxFrequency(); | 2823 float maxf = getEffectiveMaxFrequency(); |
2825 | 2824 |
2826 int py = h, ppy = h; | 2825 int py = h, ppy = h; |
2827 paint.setBrush(paint.pen().color()); | 2826 paint.setBrush(paint.pen().color()); |
2871 } | 2870 } |
2872 | 2871 |
2873 class SpectrogramRangeMapper : public RangeMapper | 2872 class SpectrogramRangeMapper : public RangeMapper |
2874 { | 2873 { |
2875 public: | 2874 public: |
2876 SpectrogramRangeMapper(int sr, int fftsize) : | 2875 SpectrogramRangeMapper(int sr, int /* fftsize */) : |
2877 m_dist(float(sr) / 2), | 2876 m_dist(float(sr) / 2), |
2878 m_s2(sqrtf(sqrtf(2))) { } | 2877 m_s2(sqrtf(sqrtf(2))) { } |
2879 ~SpectrogramRangeMapper() { } | 2878 ~SpectrogramRangeMapper() { } |
2880 | 2879 |
2881 virtual int getPositionForValue(float value) const { | 2880 virtual int getPositionForValue(float value) const { |
2882 | 2881 |
2883 float dist = m_dist; | 2882 float dist = m_dist; |
2884 | 2883 |
2885 int n = 0; | 2884 int n = 0; |
2886 int discard = 0; | |
2887 | 2885 |
2888 while (dist > (value + 0.00001) && dist > 0.1f) { | 2886 while (dist > (value + 0.00001) && dist > 0.1f) { |
2889 dist /= m_s2; | 2887 dist /= m_s2; |
2890 ++n; | 2888 ++n; |
2891 } | 2889 } |
2931 int maxStep = mapper.getPositionForValue(0); | 2929 int maxStep = mapper.getPositionForValue(0); |
2932 int minStep = mapper.getPositionForValue(float(sr) / 2); | 2930 int minStep = mapper.getPositionForValue(float(sr) / 2); |
2933 | 2931 |
2934 defaultStep = mapper.getPositionForValue(m_initialMaxFrequency) - minStep; | 2932 defaultStep = mapper.getPositionForValue(m_initialMaxFrequency) - minStep; |
2935 | 2933 |
2936 std::cerr << "SpectrogramLayer::getVerticalZoomSteps: " << maxStep - minStep << " (" << maxStep <<"-" << minStep << "), default is " << defaultStep << " (from initial max freq " << m_initialMaxFrequency << ")" << std::endl; | 2934 // std::cerr << "SpectrogramLayer::getVerticalZoomSteps: " << maxStep - minStep << " (" << maxStep <<"-" << minStep << "), default is " << defaultStep << " (from initial max freq " << m_initialMaxFrequency << ")" << std::endl; |
2937 | 2935 |
2938 return maxStep - minStep; | 2936 return maxStep - minStep; |
2939 } | 2937 } |
2940 | 2938 |
2941 int | 2939 int |
2946 float dmin, dmax; | 2944 float dmin, dmax; |
2947 getDisplayExtents(dmin, dmax); | 2945 getDisplayExtents(dmin, dmax); |
2948 | 2946 |
2949 SpectrogramRangeMapper mapper(m_model->getSampleRate(), m_fftSize); | 2947 SpectrogramRangeMapper mapper(m_model->getSampleRate(), m_fftSize); |
2950 int n = mapper.getPositionForValue(dmax - dmin); | 2948 int n = mapper.getPositionForValue(dmax - dmin); |
2951 std::cerr << "SpectrogramLayer::getCurrentVerticalZoomStep: " << n << std::endl; | 2949 // std::cerr << "SpectrogramLayer::getCurrentVerticalZoomStep: " << n << std::endl; |
2952 return n; | 2950 return n; |
2953 } | 2951 } |
2954 | 2952 |
2955 void | 2953 void |
2956 SpectrogramLayer::setVerticalZoomStep(int step) | 2954 SpectrogramLayer::setVerticalZoomStep(int step) |
2980 } | 2978 } |
2981 if (newmax > mmax) { | 2979 if (newmax > mmax) { |
2982 newmax = mmax; | 2980 newmax = mmax; |
2983 } | 2981 } |
2984 | 2982 |
2985 std::cerr << "SpectrogramLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << ddist << ")" << std::endl; | 2983 // std::cerr << "SpectrogramLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << ddist << ")" << std::endl; |
2986 | 2984 |
2987 setMinFrequency(int(newmin)); | 2985 setMinFrequency(int(newmin)); |
2988 setMaxFrequency(int(newmax)); | 2986 setMaxFrequency(int(newmax)); |
2989 } | 2987 } |
2990 | 2988 |