comparison layer/SpectrogramLayer.cpp @ 682:1a0dfcbffaf1

Drop std:: from cout, cerr, endl -- pull these in through Debug.h
author Chris Cannam
date Tue, 26 Nov 2013 14:06:40 +0000
parents d632a1e87018
children 8072264dc61f
comparison
equal deleted inserted replaced
681:eaf4446a1bef 682:1a0dfcbffaf1
38 #include <QMouseEvent> 38 #include <QMouseEvent>
39 #include <QTextStream> 39 #include <QTextStream>
40 40
41 #include <iostream> 41 #include <iostream>
42 42
43 using std::cerr; 43
44 using std::endl; 44
45 #include <cassert> 45 #include <cassert>
46 #include <cmath> 46 #include <cmath>
47 47
48 #ifndef __GNUC__ 48 #ifndef __GNUC__
49 #include <alloca.h> 49 #include <alloca.h>
125 } 125 }
126 126
127 void 127 void
128 SpectrogramLayer::setModel(const DenseTimeValueModel *model) 128 SpectrogramLayer::setModel(const DenseTimeValueModel *model)
129 { 129 {
130 // std::cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << std::endl; 130 // cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << endl;
131 131
132 if (model == m_model) return; 132 if (model == m_model) return;
133 133
134 m_model = model; 134 m_model = model;
135 invalidateFFTModels(); 135 invalidateFFTModels();
582 SVDEBUG << "SpectrogramLayer::invalidateImageCaches(" 582 SVDEBUG << "SpectrogramLayer::invalidateImageCaches("
583 << startFrame << ", " << endFrame << "): view range is " 583 << startFrame << ", " << endFrame << "): view range is "
584 << v->getStartFrame() << ", " << v->getEndFrame() 584 << v->getStartFrame() << ", " << v->getEndFrame()
585 << endl; 585 << endl;
586 586
587 std::cerr << "Valid area was: " << i->second.validArea.x() << ", " 587 cerr << "Valid area was: " << i->second.validArea.x() << ", "
588 << i->second.validArea.y() << " " 588 << i->second.validArea.y() << " "
589 << i->second.validArea.width() << "x" 589 << i->second.validArea.width() << "x"
590 << i->second.validArea.height() << std::endl; 590 << i->second.validArea.height() << endl;
591 #endif 591 #endif
592 592
593 if (long(startFrame) > v->getStartFrame()) { 593 if (long(startFrame) > v->getStartFrame()) {
594 if (startFrame >= v->getEndFrame()) { 594 if (startFrame >= v->getEndFrame()) {
595 #ifdef DEBUG_SPECTROGRAM_REPAINT 595 #ifdef DEBUG_SPECTROGRAM_REPAINT
596 std::cerr << "Modified start frame is off right of view" << std::endl; 596 cerr << "Modified start frame is off right of view" << endl;
597 #endif 597 #endif
598 return; 598 return;
599 } 599 }
600 int x = v->getXForFrame(startFrame); 600 int x = v->getXForFrame(startFrame);
601 #ifdef DEBUG_SPECTROGRAM_REPAINT 601 #ifdef DEBUG_SPECTROGRAM_REPAINT
608 i->second.validArea = QRect(); 608 i->second.validArea = QRect();
609 } 609 }
610 } else { 610 } else {
611 if (long(endFrame) < v->getStartFrame()) { 611 if (long(endFrame) < v->getStartFrame()) {
612 #ifdef DEBUG_SPECTROGRAM_REPAINT 612 #ifdef DEBUG_SPECTROGRAM_REPAINT
613 std::cerr << "Modified end frame is off left of view" << std::endl; 613 cerr << "Modified end frame is off left of view" << endl;
614 #endif 614 #endif
615 return; 615 return;
616 } 616 }
617 int x = v->getXForFrame(endFrame); 617 int x = v->getXForFrame(endFrame);
618 #ifdef DEBUG_SPECTROGRAM_REPAINT 618 #ifdef DEBUG_SPECTROGRAM_REPAINT
626 i->second.validArea = QRect(); 626 i->second.validArea = QRect();
627 } 627 }
628 } 628 }
629 629
630 #ifdef DEBUG_SPECTROGRAM_REPAINT 630 #ifdef DEBUG_SPECTROGRAM_REPAINT
631 std::cerr << "Valid area is now: " << i->second.validArea.x() << ", " 631 cerr << "Valid area is now: " << i->second.validArea.x() << ", "
632 << i->second.validArea.y() << " " 632 << i->second.validArea.y() << " "
633 << i->second.validArea.width() << "x" 633 << i->second.validArea.width() << "x"
634 << i->second.validArea.height() << std::endl; 634 << i->second.validArea.height() << endl;
635 #endif 635 #endif
636 } 636 }
637 } 637 }
638 638
639 void 639 void
1065 #endif 1065 #endif
1066 1066
1067 if (fill >= lastFill) { 1067 if (fill >= lastFill) {
1068 if (fill >= m_model->getEndFrame() && lastFill > 0) { 1068 if (fill >= m_model->getEndFrame() && lastFill > 0) {
1069 #ifdef DEBUG_SPECTROGRAM_REPAINT 1069 #ifdef DEBUG_SPECTROGRAM_REPAINT
1070 std::cerr << "complete!" << std::endl; 1070 cerr << "complete!" << endl;
1071 #endif 1071 #endif
1072 invalidateImageCaches(); 1072 invalidateImageCaches();
1073 i->second.second = -1; 1073 i->second.second = -1;
1074 emit modelChanged(); 1074 emit modelChanged();
1075 1075
1076 } else if (fill > lastFill) { 1076 } else if (fill > lastFill) {
1077 #ifdef DEBUG_SPECTROGRAM_REPAINT 1077 #ifdef DEBUG_SPECTROGRAM_REPAINT
1078 std::cerr << "SpectrogramLayer: emitting modelChanged(" 1078 cerr << "SpectrogramLayer: emitting modelChanged("
1079 << lastFill << "," << fill << ")" << std::endl; 1079 << lastFill << "," << fill << ")" << endl;
1080 #endif 1080 #endif
1081 invalidateImageCaches(lastFill, fill); 1081 invalidateImageCaches(lastFill, fill);
1082 i->second.second = fill; 1082 i->second.second = fill;
1083 emit modelChanged(lastFill, fill); 1083 emit modelChanged(lastFill, fill);
1084 } 1084 }
1085 } else { 1085 } else {
1086 #ifdef DEBUG_SPECTROGRAM_REPAINT 1086 #ifdef DEBUG_SPECTROGRAM_REPAINT
1087 std::cerr << "SpectrogramLayer: going backwards, emitting modelChanged(" 1087 cerr << "SpectrogramLayer: going backwards, emitting modelChanged("
1088 << m_model->getStartFrame() << "," << m_model->getEndFrame() << ")" << std::endl; 1088 << m_model->getStartFrame() << "," << m_model->getEndFrame() << ")" << endl;
1089 #endif 1089 #endif
1090 invalidateImageCaches(); 1090 invalidateImageCaches();
1091 i->second.second = fill; 1091 i->second.second = fill;
1092 emit modelChanged(m_model->getStartFrame(), m_model->getEndFrame()); 1092 emit modelChanged(m_model->getStartFrame(), m_model->getEndFrame());
1093 } 1093 }
1098 } 1098 }
1099 } 1099 }
1100 1100
1101 if (allDone) { 1101 if (allDone) {
1102 #ifdef DEBUG_SPECTROGRAM_REPAINT 1102 #ifdef DEBUG_SPECTROGRAM_REPAINT
1103 std::cerr << "SpectrogramLayer: all complete!" << std::endl; 1103 cerr << "SpectrogramLayer: all complete!" << endl;
1104 #endif 1104 #endif
1105 delete m_updateTimer; 1105 delete m_updateTimer;
1106 m_updateTimer = 0; 1106 m_updateTimer = 0;
1107 } 1107 }
1108 } 1108 }
1672 return 0; 1672 return 0;
1673 } 1673 }
1674 1674
1675 if (!m_sliceableModel) { 1675 if (!m_sliceableModel) {
1676 #ifdef DEBUG_SPECTROGRAM 1676 #ifdef DEBUG_SPECTROGRAM
1677 std::cerr << "SpectrogramLayer: emitting sliceableModelReplaced(0, " << model << ")" << std::endl; 1677 cerr << "SpectrogramLayer: emitting sliceableModelReplaced(0, " << model << ")" << endl;
1678 #endif 1678 #endif
1679 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, model); 1679 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, model);
1680 m_sliceableModel = model; 1680 m_sliceableModel = model;
1681 } 1681 }
1682 1682
1728 1728
1729 m_fftModels.clear(); 1729 m_fftModels.clear();
1730 m_peakCaches.clear(); 1730 m_peakCaches.clear();
1731 1731
1732 if (m_sliceableModel) { 1732 if (m_sliceableModel) {
1733 std::cerr << "SpectrogramLayer: emitting sliceableModelReplaced(" << m_sliceableModel << ", 0)" << std::endl; 1733 cerr << "SpectrogramLayer: emitting sliceableModelReplaced(" << m_sliceableModel << ", 0)" << endl;
1734 emit sliceableModelReplaced(m_sliceableModel, 0); 1734 emit sliceableModelReplaced(m_sliceableModel, 0);
1735 m_sliceableModel = 0; 1735 m_sliceableModel = 0;
1736 } 1736 }
1737 } 1737 }
1738 1738
1803 Profiler profiler("SpectrogramLayer::paint", false); 1803 Profiler profiler("SpectrogramLayer::paint", false);
1804 1804
1805 #ifdef DEBUG_SPECTROGRAM_REPAINT 1805 #ifdef DEBUG_SPECTROGRAM_REPAINT
1806 SVDEBUG << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", m_updateTimer " << m_updateTimer << endl; 1806 SVDEBUG << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", m_updateTimer " << m_updateTimer << endl;
1807 1807
1808 std::cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << std::endl; 1808 cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl;
1809 #endif 1809 #endif
1810 1810
1811 long startFrame = v->getStartFrame(); 1811 long startFrame = v->getStartFrame();
1812 if (startFrame < 0) m_candidateFillStartFrame = 0; 1812 if (startFrame < 0) m_candidateFillStartFrame = 0;
1813 else m_candidateFillStartFrame = startFrame; 1813 else m_candidateFillStartFrame = startFrame;
1829 1829
1830 size_t fftSize = getFFTSize(v); 1830 size_t fftSize = getFFTSize(v);
1831 /* 1831 /*
1832 FFTModel *fft = getFFTModel(v); 1832 FFTModel *fft = getFFTModel(v);
1833 if (!fft) { 1833 if (!fft) {
1834 std::cerr << "ERROR: SpectrogramLayer::paint(): No FFT model, returning" << std::endl; 1834 cerr << "ERROR: SpectrogramLayer::paint(): No FFT model, returning" << endl;
1835 return; 1835 return;
1836 } 1836 }
1837 */ 1837 */
1838 ImageCache &cache = m_imageCaches[v]; 1838 ImageCache &cache = m_imageCaches[v];
1839 1839
1857 1857
1858 x0 = rect.left(); 1858 x0 = rect.left();
1859 x1 = rect.right() + 1; 1859 x1 = rect.right() + 1;
1860 /* 1860 /*
1861 float xPixelRatio = float(fft->getResolution()) / float(zoomLevel); 1861 float xPixelRatio = float(fft->getResolution()) / float(zoomLevel);
1862 std::cerr << "xPixelRatio = " << xPixelRatio << std::endl; 1862 cerr << "xPixelRatio = " << xPixelRatio << endl;
1863 if (xPixelRatio < 1.f) xPixelRatio = 1.f; 1863 if (xPixelRatio < 1.f) xPixelRatio = 1.f;
1864 */ 1864 */
1865 if (cache.validArea.width() > 0) { 1865 if (cache.validArea.width() > 0) {
1866 1866
1867 int cw = cache.image.width(); 1867 int cw = cache.image.width();
1875 v->getXForFrame(startFrame) && 1875 v->getXForFrame(startFrame) &&
1876 cache.validArea.x() <= x0 && 1876 cache.validArea.x() <= x0 &&
1877 cache.validArea.x() + cache.validArea.width() >= x1) { 1877 cache.validArea.x() + cache.validArea.width() >= x1) {
1878 1878
1879 #ifdef DEBUG_SPECTROGRAM_REPAINT 1879 #ifdef DEBUG_SPECTROGRAM_REPAINT
1880 std::cerr << "SpectrogramLayer: image cache good" << std::endl; 1880 cerr << "SpectrogramLayer: image cache good" << endl;
1881 #endif 1881 #endif
1882 1882
1883 paint.drawImage(rect, cache.image, rect); 1883 paint.drawImage(rect, cache.image, rect);
1884 //!!! 1884 //!!!
1885 // paint.drawImage(v->rect(), cache.image, 1885 // paint.drawImage(v->rect(), cache.image,
1889 return; 1889 return;
1890 1890
1891 } else { 1891 } else {
1892 1892
1893 #ifdef DEBUG_SPECTROGRAM_REPAINT 1893 #ifdef DEBUG_SPECTROGRAM_REPAINT
1894 std::cerr << "SpectrogramLayer: image cache partially OK" << std::endl; 1894 cerr << "SpectrogramLayer: image cache partially OK" << endl;
1895 #endif 1895 #endif
1896 1896
1897 recreateWholeImageCache = false; 1897 recreateWholeImageCache = false;
1898 1898
1899 int dx = v->getXForFrame(cache.startFrame) - 1899 int dx = v->getXForFrame(cache.startFrame) -
1900 v->getXForFrame(startFrame); 1900 v->getXForFrame(startFrame);
1901 1901
1902 #ifdef DEBUG_SPECTROGRAM_REPAINT 1902 #ifdef DEBUG_SPECTROGRAM_REPAINT
1903 std::cerr << "SpectrogramLayer: dx = " << dx << " (image cache " << cw << "x" << ch << ")" << std::endl; 1903 cerr << "SpectrogramLayer: dx = " << dx << " (image cache " << cw << "x" << ch << ")" << endl;
1904 #endif 1904 #endif
1905 1905
1906 if (dx != 0 && 1906 if (dx != 0 &&
1907 dx > -cw && 1907 dx > -cw &&
1908 dx < cw) { 1908 dx < cw) {
1944 cache.validArea = 1944 cache.validArea =
1945 QRect(px, cache.validArea.y(), 1945 QRect(px, cache.validArea.y(),
1946 pw, cache.validArea.height()); 1946 pw, cache.validArea.height());
1947 1947
1948 #ifdef DEBUG_SPECTROGRAM_REPAINT 1948 #ifdef DEBUG_SPECTROGRAM_REPAINT
1949 std::cerr << "valid area now " 1949 cerr << "valid area now "
1950 << px << "," << cache.validArea.y() 1950 << px << "," << cache.validArea.y()
1951 << " " << pw << "x" << cache.validArea.height() 1951 << " " << pw << "x" << cache.validArea.height()
1952 << std::endl; 1952 << endl;
1953 #endif 1953 #endif
1954 /* 1954 /*
1955 paint.drawImage(rect & cache.validArea, 1955 paint.drawImage(rect & cache.validArea,
1956 cache.image, 1956 cache.image,
1957 rect & cache.validArea); 1957 rect & cache.validArea);
1959 } else if (dx != 0) { 1959 } else if (dx != 0) {
1960 1960
1961 // we scrolled too far to be of use 1961 // we scrolled too far to be of use
1962 1962
1963 #ifdef DEBUG_SPECTROGRAM_REPAINT 1963 #ifdef DEBUG_SPECTROGRAM_REPAINT
1964 std::cerr << "dx == " << dx << ": scrolled too far for cache to be useful" << std::endl; 1964 cerr << "dx == " << dx << ": scrolled too far for cache to be useful" << endl;
1965 #endif 1965 #endif
1966 1966
1967 cache.validArea = QRect(); 1967 cache.validArea = QRect();
1968 recreateWholeImageCache = true; 1968 recreateWholeImageCache = true;
1969 } 1969 }
1970 } 1970 }
1971 } else { 1971 } else {
1972 #ifdef DEBUG_SPECTROGRAM_REPAINT 1972 #ifdef DEBUG_SPECTROGRAM_REPAINT
1973 std::cerr << "SpectrogramLayer: image cache useless" << std::endl; 1973 cerr << "SpectrogramLayer: image cache useless" << endl;
1974 if (int(cache.zoomLevel) != zoomLevel) { 1974 if (int(cache.zoomLevel) != zoomLevel) {
1975 std::cerr << "(cache zoomLevel " << cache.zoomLevel 1975 cerr << "(cache zoomLevel " << cache.zoomLevel
1976 << " != " << zoomLevel << ")" << std::endl; 1976 << " != " << zoomLevel << ")" << endl;
1977 } 1977 }
1978 if (cw != v->width()) { 1978 if (cw != v->width()) {
1979 std::cerr << "(cache width " << cw 1979 cerr << "(cache width " << cw
1980 << " != " << v->width(); 1980 << " != " << v->width();
1981 } 1981 }
1982 if (ch != v->height()) { 1982 if (ch != v->height()) {
1983 std::cerr << "(cache height " << ch 1983 cerr << "(cache height " << ch
1984 << " != " << v->height(); 1984 << " != " << v->height();
1985 } 1985 }
1986 #endif 1986 #endif
1987 cache.validArea = QRect(); 1987 cache.validArea = QRect();
1988 // recreateWholeImageCache = true; 1988 // recreateWholeImageCache = true;
1989 } 1989 }
1990 } 1990 }
1991 1991
1992 if (updateViewMagnitudes(v)) { 1992 if (updateViewMagnitudes(v)) {
1993 #ifdef DEBUG_SPECTROGRAM_REPAINT 1993 #ifdef DEBUG_SPECTROGRAM_REPAINT
1994 std::cerr << "SpectrogramLayer: magnitude range changed to [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << std::endl; 1994 cerr << "SpectrogramLayer: magnitude range changed to [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << endl;
1995 #endif 1995 #endif
1996 if (m_normalizeVisibleArea) { 1996 if (m_normalizeVisibleArea) {
1997 cache.validArea = QRect(); 1997 cache.validArea = QRect();
1998 recreateWholeImageCache = true; 1998 recreateWholeImageCache = true;
1999 } 1999 }
2000 } else { 2000 } else {
2001 #ifdef DEBUG_SPECTROGRAM_REPAINT 2001 #ifdef DEBUG_SPECTROGRAM_REPAINT
2002 std::cerr << "No change in magnitude range [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << std::endl; 2002 cerr << "No change in magnitude range [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << endl;
2003 #endif 2003 #endif
2004 } 2004 }
2005 2005
2006 if (recreateWholeImageCache) { 2006 if (recreateWholeImageCache) {
2007 x0 = 0; 2007 x0 = 0;
2038 2038
2039 if (paintBlockWidth < 20) paintBlockWidth = 20; 2039 if (paintBlockWidth < 20) paintBlockWidth = 20;
2040 } 2040 }
2041 2041
2042 #ifdef DEBUG_SPECTROGRAM_REPAINT 2042 #ifdef DEBUG_SPECTROGRAM_REPAINT
2043 std::cerr << "[" << this << "]: last paint width: " << m_lastPaintBlockWidth << ", last paint time: " << m_lastPaintTime << ", new paint width: " << paintBlockWidth << std::endl; 2043 cerr << "[" << this << "]: last paint width: " << m_lastPaintBlockWidth << ", last paint time: " << m_lastPaintTime << ", new paint width: " << paintBlockWidth << endl;
2044 #endif 2044 #endif
2045 2045
2046 // We always paint the full height when refreshing the cache. 2046 // We always paint the full height when refreshing the cache.
2047 // Smaller heights can be used when painting direct from cache 2047 // Smaller heights can be used when painting direct from cache
2048 // (further up in this function), but we want to ensure the cache 2048 // (further up in this function), but we want to ensure the cache
2063 int vx0 = 0, vx1 = 0; 2063 int vx0 = 0, vx1 = 0;
2064 vx0 = cache.validArea.x(); 2064 vx0 = cache.validArea.x();
2065 vx1 = cache.validArea.x() + cache.validArea.width(); 2065 vx1 = cache.validArea.x() + cache.validArea.width();
2066 2066
2067 #ifdef DEBUG_SPECTROGRAM_REPAINT 2067 #ifdef DEBUG_SPECTROGRAM_REPAINT
2068 std::cerr << "x0 " << x0 << ", x1 " << x1 << ", vx0 " << vx0 << ", vx1 " << vx1 << ", paintBlockWidth " << paintBlockWidth << std::endl; 2068 cerr << "x0 " << x0 << ", x1 " << x1 << ", vx0 " << vx0 << ", vx1 " << vx1 << ", paintBlockWidth " << paintBlockWidth << endl;
2069 #endif 2069 #endif
2070 if (x0 < vx0) { 2070 if (x0 < vx0) {
2071 if (x0 + paintBlockWidth < vx0) { 2071 if (x0 + paintBlockWidth < vx0) {
2072 x0 = vx0 - paintBlockWidth; 2072 x0 = vx0 - paintBlockWidth;
2073 } 2073 }
2094 std::max(vx1 - std::min(vx0, x0), 2094 std::max(vx1 - std::min(vx0, x0),
2095 x1 - std::min(vx0, x0)), 2095 x1 - std::min(vx0, x0)),
2096 cache.validArea.height()); 2096 cache.validArea.height());
2097 2097
2098 #ifdef DEBUG_SPECTROGRAM_REPAINT 2098 #ifdef DEBUG_SPECTROGRAM_REPAINT
2099 std::cerr << "Valid area becomes " << cache.validArea.x() 2099 cerr << "Valid area becomes " << cache.validArea.x()
2100 << ", " << cache.validArea.y() << ", " 2100 << ", " << cache.validArea.y() << ", "
2101 << cache.validArea.width() << "x" 2101 << cache.validArea.width() << "x"
2102 << cache.validArea.height() << std::endl; 2102 << cache.validArea.height() << endl;
2103 #endif 2103 #endif
2104 2104
2105 } else { 2105 } else {
2106 if (x1 > x0 + paintBlockWidth) { 2106 if (x1 > x0 + paintBlockWidth) {
2107 int sfx = x1; 2107 int sfx = x1;
2114 x0 = mid - paintBlockWidth/2; 2114 x0 = mid - paintBlockWidth/2;
2115 x1 = x0 + paintBlockWidth; 2115 x1 = x0 + paintBlockWidth;
2116 } 2116 }
2117 } 2117 }
2118 #ifdef DEBUG_SPECTROGRAM_REPAINT 2118 #ifdef DEBUG_SPECTROGRAM_REPAINT
2119 std::cerr << "Valid area becomes " << x0 << ", 0, " << (x1-x0) 2119 cerr << "Valid area becomes " << x0 << ", 0, " << (x1-x0)
2120 << "x" << h << std::endl; 2120 << "x" << h << endl;
2121 #endif 2121 #endif
2122 cache.validArea = QRect(x0, 0, x1 - x0, h); 2122 cache.validArea = QRect(x0, 0, x1 - x0, h);
2123 } 2123 }
2124 2124
2125 /* 2125 /*
2129 } 2129 }
2130 */ 2130 */
2131 int w = x1 - x0; 2131 int w = x1 - x0;
2132 2132
2133 #ifdef DEBUG_SPECTROGRAM_REPAINT 2133 #ifdef DEBUG_SPECTROGRAM_REPAINT
2134 std::cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << std::endl; 2134 cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << endl;
2135 #endif 2135 #endif
2136 2136
2137 int sr = m_model->getSampleRate(); 2137 int sr = m_model->getSampleRate();
2138 2138
2139 // Set minFreq and maxFreq to the frequency extents of the possibly 2139 // Set minFreq and maxFreq to the frequency extents of the possibly
2154 } 2154 }
2155 2155
2156 size_t minbin = 1; 2156 size_t minbin = 1;
2157 if (m_minFrequency > 0) { 2157 if (m_minFrequency > 0) {
2158 minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.001); 2158 minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.001);
2159 // std::cerr << "m_minFrequency = " << m_minFrequency << " -> minbin = " << minbin << std::endl; 2159 // cerr << "m_minFrequency = " << m_minFrequency << " -> minbin = " << minbin << endl;
2160 if (minbin < 1) minbin = 1; 2160 if (minbin < 1) minbin = 1;
2161 if (minbin >= maxbin) minbin = maxbin - 1; 2161 if (minbin >= maxbin) minbin = maxbin - 1;
2162 } 2162 }
2163 2163
2164 int zpl = getZeroPadLevel(v) + 1; 2164 int zpl = getZeroPadLevel(v) + 1;
2174 if (fftSize != m_fftSize) { 2174 if (fftSize != m_fftSize) {
2175 displayMinFreq = getEffectiveMinFrequency(); 2175 displayMinFreq = getEffectiveMinFrequency();
2176 displayMaxFreq = getEffectiveMaxFrequency(); 2176 displayMaxFreq = getEffectiveMaxFrequency();
2177 } 2177 }
2178 2178
2179 // std::cerr << "(giving actual minFreq " << minFreq << " and display minFreq " << displayMinFreq << ")" << std::endl; 2179 // cerr << "(giving actual minFreq " << minFreq << " and display minFreq " << displayMinFreq << ")" << endl;
2180 2180
2181 int increment = getWindowIncrement(); 2181 int increment = getWindowIncrement();
2182 2182
2183 bool logarithmic = (m_frequencyScale == LogFrequencyScale); 2183 bool logarithmic = (m_frequencyScale == LogFrequencyScale);
2184 /* 2184 /*
2195 bool overallMagChanged = false; 2195 bool overallMagChanged = false;
2196 2196
2197 bool fftSuspended = false; 2197 bool fftSuspended = false;
2198 2198
2199 #ifdef DEBUG_SPECTROGRAM_REPAINT 2199 #ifdef DEBUG_SPECTROGRAM_REPAINT
2200 std::cerr << ((float(v->getFrameForX(1) - v->getFrameForX(0))) / increment) << " bin(s) per pixel" << std::endl; 2200 cerr << ((float(v->getFrameForX(1) - v->getFrameForX(0))) / increment) << " bin(s) per pixel" << endl;
2201 #endif 2201 #endif
2202 2202
2203 bool runOutOfData = false; 2203 bool runOutOfData = false;
2204 2204
2205 if (w == 0) { 2205 if (w == 0) {
2335 xPixelRatio, 2335 xPixelRatio,
2336 h, yforbin); 2336 h, yforbin);
2337 2337
2338 if (runOutOfData) { 2338 if (runOutOfData) {
2339 #ifdef DEBUG_SPECTROGRAM_REPAINT 2339 #ifdef DEBUG_SPECTROGRAM_REPAINT
2340 std::cerr << "Run out of data -- dropping out of loop" << std::endl; 2340 cerr << "Run out of data -- dropping out of loop" << endl;
2341 #endif 2341 #endif
2342 break; 2342 break;
2343 } 2343 }
2344 } 2344 }
2345 */ 2345 */
2346 #ifdef DEBUG_SPECTROGRAM_REPAINT 2346 #ifdef DEBUG_SPECTROGRAM_REPAINT
2347 // std::cerr << pixels << " pixels drawn" << std::endl; 2347 // cerr << pixels << " pixels drawn" << endl;
2348 #endif 2348 #endif
2349 2349
2350 if (overallMagChanged) { 2350 if (overallMagChanged) {
2351 m_viewMags[v] = overallMag; 2351 m_viewMags[v] = overallMag;
2352 #ifdef DEBUG_SPECTROGRAM_REPAINT 2352 #ifdef DEBUG_SPECTROGRAM_REPAINT
2353 std::cerr << "Overall mag is now [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "] - will be updating" << std::endl; 2353 cerr << "Overall mag is now [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "] - will be updating" << endl;
2354 #endif 2354 #endif
2355 } else { 2355 } else {
2356 #ifdef DEBUG_SPECTROGRAM_REPAINT 2356 #ifdef DEBUG_SPECTROGRAM_REPAINT
2357 std::cerr << "Overall mag unchanged at [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << std::endl; 2357 cerr << "Overall mag unchanged at [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << endl;
2358 #endif 2358 #endif
2359 } 2359 }
2360 2360
2361 outerprof.end(); 2361 outerprof.end();
2362 2362
2462 cache.validArea.width()), 2462 cache.validArea.width()),
2463 h); 2463 h);
2464 } 2464 }
2465 } else { 2465 } else {
2466 // overallMagChanged 2466 // overallMagChanged
2467 std::cerr << "\noverallMagChanged - updating all\n" << std::endl; 2467 cerr << "\noverallMagChanged - updating all\n" << endl;
2468 cache.validArea = QRect(); 2468 cache.validArea = QRect();
2469 v->update(); 2469 v->update();
2470 } 2470 }
2471 } 2471 }
2472 2472
2538 if (sx < 0 || sx >= int(fft->getWidth())) continue; 2538 if (sx < 0 || sx >= int(fft->getWidth())) continue;
2539 2539
2540 if (!m_synchronous) { 2540 if (!m_synchronous) {
2541 if (!fft->isColumnAvailable(sx)) { 2541 if (!fft->isColumnAvailable(sx)) {
2542 #ifdef DEBUG_SPECTROGRAM_REPAINT 2542 #ifdef DEBUG_SPECTROGRAM_REPAINT
2543 std::cerr << "Met unavailable column at col " << sx << std::endl; 2543 cerr << "Met unavailable column at col " << sx << endl;
2544 #endif 2544 #endif
2545 return false; 2545 return false;
2546 } 2546 }
2547 } 2547 }
2548 2548
2590 } 2590 }
2591 2591
2592 if (mag.isSet()) { 2592 if (mag.isSet()) {
2593 if (sx >= int(m_columnMags.size())) { 2593 if (sx >= int(m_columnMags.size())) {
2594 #ifdef DEBUG_SPECTROGRAM 2594 #ifdef DEBUG_SPECTROGRAM
2595 std::cerr << "INTERNAL ERROR: " << sx << " >= " 2595 cerr << "INTERNAL ERROR: " << sx << " >= "
2596 << m_columnMags.size() 2596 << m_columnMags.size()
2597 << " at SpectrogramLayer.cpp::paintDrawBuffer" 2597 << " at SpectrogramLayer.cpp::paintDrawBuffer"
2598 << std::endl; 2598 << endl;
2599 #endif 2599 #endif
2600 } else { 2600 } else {
2601 m_columnMags[sx].sample(mag); 2601 m_columnMags[sx].sample(mag);
2602 if (overallMag.sample(mag)) overallMagChanged = true; 2602 if (overallMag.sample(mag)) overallMagChanged = true;
2603 } 2603 }
2687 for (int y = 0; y < h; ++y) peaks[y] = 0.f; 2687 for (int y = 0; y < h; ++y) peaks[y] = 0.f;
2688 2688
2689 for (int sx = sx0; sx < sx1; ++sx) { 2689 for (int sx = sx0; sx < sx1; ++sx) {
2690 2690
2691 #ifdef DEBUG_SPECTROGRAM_REPAINT 2691 #ifdef DEBUG_SPECTROGRAM_REPAINT
2692 // std::cerr << "sx = " << sx << std::endl; 2692 // cerr << "sx = " << sx << endl;
2693 #endif 2693 #endif
2694 2694
2695 if (sx < 0 || sx >= int(sourceModel->getWidth())) continue; 2695 if (sx < 0 || sx >= int(sourceModel->getWidth())) continue;
2696 2696
2697 if (!m_synchronous) { 2697 if (!m_synchronous) {
2698 if (!sourceModel->isColumnAvailable(sx)) { 2698 if (!sourceModel->isColumnAvailable(sx)) {
2699 #ifdef DEBUG_SPECTROGRAM_REPAINT 2699 #ifdef DEBUG_SPECTROGRAM_REPAINT
2700 std::cerr << "Met unavailable column at col " << sx << std::endl; 2700 cerr << "Met unavailable column at col " << sx << endl;
2701 #endif 2701 #endif
2702 return false; 2702 return false;
2703 } 2703 }
2704 } 2704 }
2705 2705
2803 } 2803 }
2804 2804
2805 if (mag.isSet()) { 2805 if (mag.isSet()) {
2806 if (sx >= int(m_columnMags.size())) { 2806 if (sx >= int(m_columnMags.size())) {
2807 #ifdef DEBUG_SPECTROGRAM 2807 #ifdef DEBUG_SPECTROGRAM
2808 std::cerr << "INTERNAL ERROR: " << sx << " >= " 2808 cerr << "INTERNAL ERROR: " << sx << " >= "
2809 << m_columnMags.size() 2809 << m_columnMags.size()
2810 << " at SpectrogramLayer.cpp::paintDrawBuffer" 2810 << " at SpectrogramLayer.cpp::paintDrawBuffer"
2811 << std::endl; 2811 << endl;
2812 #endif 2812 #endif
2813 } else { 2813 } else {
2814 m_columnMags[sx].sample(mag); 2814 m_columnMags[sx].sample(mag);
2815 if (overallMag.sample(mag)) overallMagChanged = true; 2815 if (overallMag.sample(mag)) overallMagChanged = true;
2816 } 2816 }
2844 QPoint localPos; 2844 QPoint localPos;
2845 if (!v->shouldIlluminateLocalFeatures(this, localPos) || !m_model) { 2845 if (!v->shouldIlluminateLocalFeatures(this, localPos) || !m_model) {
2846 return; 2846 return;
2847 } 2847 }
2848 2848
2849 // std::cerr << "SpectrogramLayer: illuminateLocalFeatures(" 2849 // cerr << "SpectrogramLayer: illuminateLocalFeatures("
2850 // << localPos.x() << "," << localPos.y() << ")" << std::endl; 2850 // << localPos.x() << "," << localPos.y() << ")" << endl;
2851 2851
2852 float s0, s1; 2852 float s0, s1;
2853 float f0, f1; 2853 float f0, f1;
2854 2854
2855 if (getXBinRange(v, localPos.x(), s0, s1) && 2855 if (getXBinRange(v, localPos.x(), s0, s1) &&
2862 int x1 = v->getXForFrame((s1i + 1) * getWindowIncrement()); 2862 int x1 = v->getXForFrame((s1i + 1) * getWindowIncrement());
2863 2863
2864 int y1 = int(getYForFrequency(v, f1)); 2864 int y1 = int(getYForFrequency(v, f1));
2865 int y0 = int(getYForFrequency(v, f0)); 2865 int y0 = int(getYForFrequency(v, f0));
2866 2866
2867 // std::cerr << "SpectrogramLayer: illuminate " 2867 // cerr << "SpectrogramLayer: illuminate "
2868 // << x0 << "," << y1 << " -> " << x1 << "," << y0 << std::endl; 2868 // << x0 << "," << y1 << " -> " << x1 << "," << y0 << endl;
2869 2869
2870 paint.setPen(v->getForeground()); 2870 paint.setPen(v->getForeground());
2871 2871
2872 //!!! should we be using paintCrosshairs for this? 2872 //!!! should we be using paintCrosshairs for this?
2873 2873
3004 void 3004 void
3005 SpectrogramLayer::measureDoubleClick(View *v, QMouseEvent *e) 3005 SpectrogramLayer::measureDoubleClick(View *v, QMouseEvent *e)
3006 { 3006 {
3007 ImageCache &cache = m_imageCaches[v]; 3007 ImageCache &cache = m_imageCaches[v];
3008 3008
3009 std::cerr << "cache width: " << cache.image.width() << ", height: " 3009 cerr << "cache width: " << cache.image.width() << ", height: "
3010 << cache.image.height() << std::endl; 3010 << cache.image.height() << endl;
3011 3011
3012 QImage image = cache.image; 3012 QImage image = cache.image;
3013 3013
3014 ImageRegionFinder finder; 3014 ImageRegionFinder finder;
3015 QRect rect = finder.findRegionExtents(&image, e->pos()); 3015 QRect rect = finder.findRegionExtents(&image, e->pos());
3582 if (!m_model) return; 3582 if (!m_model) return;
3583 3583
3584 float dmin = m_minFrequency, dmax = m_maxFrequency; 3584 float dmin = m_minFrequency, dmax = m_maxFrequency;
3585 // getDisplayExtents(dmin, dmax); 3585 // getDisplayExtents(dmin, dmax);
3586 3586
3587 // std::cerr << "current range " << dmin << " -> " << dmax << ", range " << dmax-dmin << ", mid " << (dmax + dmin)/2 << std::endl; 3587 // cerr << "current range " << dmin << " -> " << dmax << ", range " << dmax-dmin << ", mid " << (dmax + dmin)/2 << endl;
3588 3588
3589 int sr = m_model->getSampleRate(); 3589 int sr = m_model->getSampleRate();
3590 SpectrogramRangeMapper mapper(sr, m_fftSize); 3590 SpectrogramRangeMapper mapper(sr, m_fftSize);
3591 float newdist = mapper.getValueForPosition(step); 3591 float newdist = mapper.getValueForPosition(step);
3592 3592
3616 // so newmax = (newdist + sqrtf(newdist^2 + 4dmin.dmax)) / 2 3616 // so newmax = (newdist + sqrtf(newdist^2 + 4dmin.dmax)) / 2
3617 3617
3618 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2; 3618 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2;
3619 newmin = newmax - newdist; 3619 newmin = newmax - newdist;
3620 3620
3621 // std::cerr << "newmin = " << newmin << ", newmax = " << newmax << std::endl; 3621 // cerr << "newmin = " << newmin << ", newmax = " << newmax << endl;
3622 3622
3623 } else { 3623 } else {
3624 float dmid = (dmax + dmin) / 2; 3624 float dmid = (dmax + dmin) / 2;
3625 newmin = dmid - newdist / 2; 3625 newmin = dmid - newdist / 2;
3626 newmax = dmid + newdist / 2; 3626 newmax = dmid + newdist / 2;