Mercurial > hg > svgui
changeset 1022:2bd5eb6a6c6b colourschemes
Tidy a bit
author | Chris Cannam |
---|---|
date | Fri, 22 Jan 2016 17:08:02 +0000 |
parents | 33d7e1a6747b |
children | 74755fa6ea9e |
files | layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h |
diffstat | 2 files changed, 33 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Fri Jan 22 15:17:25 2016 +0000 +++ b/layer/SpectrogramLayer.cpp Fri Jan 22 17:08:02 2016 +0000 @@ -49,7 +49,7 @@ #include <alloca.h> #endif -//#define DEBUG_SPECTROGRAM_REPAINT 1 +#define DEBUG_SPECTROGRAM_REPAINT 1 using std::vector; @@ -1358,8 +1358,6 @@ for (int s = s0i; s <= s1i; ++s) { - if (!fft->isColumnAvailable(s)) continue; - double binfreq = (double(sr) * q) / m_windowSize; if (q == q0i) freqMin = binfreq; if (q == q1i) freqMax = binfreq; @@ -1433,8 +1431,6 @@ for (int s = s0i; s <= s1i; ++s) { if (s >= 0 && q >= 0 && s < cw && q < ch) { - if (!fft->isColumnAvailable(s)) continue; - double value; value = fft->getPhaseAt(s, q); @@ -1705,13 +1701,6 @@ const_cast<SpectrogramLayer *>(this)->Layer::setLayerDormant(v, false); int fftSize = getFFTSize(v); -/* - FFTModel *fft = getFFTModel(v); - if (!fft) { - cerr << "ERROR: SpectrogramLayer::paint(): No FFT model, returning" << endl; - return; - } -*/ const View *view = v->getView(); @@ -1732,11 +1721,16 @@ x0 = rect.left(); x1 = rect.right() + 1; -/* - double xPixelRatio = double(fft->getResolution()) / double(zoomLevel); - cerr << "xPixelRatio = " << xPixelRatio << endl; - if (xPixelRatio < 1.f) xPixelRatio = 1.f; -*/ + + if (updateViewMagnitudes(v)) { +#ifdef DEBUG_SPECTROGRAM_REPAINT + cerr << "SpectrogramLayer: magnitude range changed to [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << endl; +#endif + if (m_normalization == NormalizeVisibleArea) { + cache.validArea = QRect(); + } + } + if (cache.validArea.width() > 0) { int cw = cache.image.width(); @@ -1746,25 +1740,30 @@ cw == v->getPaintWidth() && ch == v->getPaintHeight()) { + // cache size and zoom level exactly match the view + if (v->getXForFrame(cache.startFrame) == v->getXForFrame(startFrame) && cache.validArea.x() <= x0 && cache.validArea.x() + cache.validArea.width() >= x1) { - + + // and cache begins at the right frame, so use it whole + #ifdef DEBUG_SPECTROGRAM_REPAINT cerr << "SpectrogramLayer: image cache good" << endl; #endif paint.drawImage(rect, cache.image, rect); - //!!! -// paint.drawImage(v->rect(), cache.image, -// QRect(QPoint(0, 0), cache.image.size())); illuminateLocalFeatures(v, paint); return; } else { + // cache doesn't begin at the right frame or doesn't + // contain the complete view, but might be scrollable + // or partially usable + #ifdef DEBUG_SPECTROGRAM_REPAINT cerr << "SpectrogramLayer: image cache partially OK" << endl; #endif @@ -1781,6 +1780,8 @@ if (dx != 0 && dx > -cw && dx < cw) { + + // cache is scrollable, scroll it int dxp = dx; if (dxp < 0) dxp = -dxp; @@ -1794,6 +1795,8 @@ } } + // and calculate its new valid area + int px = cache.validArea.x(); int pw = cache.validArea.width(); @@ -1826,14 +1829,11 @@ << " " << pw << "x" << cache.validArea.height() << endl; #endif -/* - paint.drawImage(rect & cache.validArea, - cache.image, - rect & cache.validArea); -*/ + } else if (dx != 0) { - // we scrolled too far to be of use + // we've moved too far from the cached area for it + // to be of use #ifdef DEBUG_SPECTROGRAM_REPAINT cerr << "dx == " << dx << ": scrolled too far for cache to be useful" << endl; @@ -1860,24 +1860,9 @@ } #endif cache.validArea = QRect(); -// recreateWholeImageCache = true; } } - if (updateViewMagnitudes(v)) { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "SpectrogramLayer: magnitude range changed to [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << endl; -#endif - if (m_normalization == NormalizeVisibleArea) { - cache.validArea = QRect(); - recreateWholeImageCache = true; - } - } else { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "No change in magnitude range [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << endl; -#endif - } - if (recreateWholeImageCache) { x0 = 0; x1 = v->getPaintWidth(); @@ -2346,7 +2331,7 @@ } } -bool +void SpectrogramLayer::paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h, @@ -2368,7 +2353,7 @@ if (maxbin < 0) maxbin = minbin+1; FFTModel *fft = getFFTModel(v); - if (!fft) return false; + if (!fft) return; FFTModel::PeakSet peakfreqs; @@ -2395,15 +2380,6 @@ if (sx < 0 || sx >= int(fft->getWidth())) continue; - if (!m_synchronous) { - if (!fft->isColumnAvailable(sx)) { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "Met unavailable column at col " << sx << endl; -#endif - return false; - } - } - MagnitudeRange mag; if (sx != psx) { @@ -2470,11 +2446,9 @@ } } } - - return true; } -bool +void SpectrogramLayer::paintDrawBuffer(LayerGeometryProvider *v, int w, int h, @@ -2510,7 +2484,7 @@ sourceModel = fft = getFFTModel(v); } - if (!sourceModel) return false; + if (!sourceModel) return; bool interpolate = false; Preferences::SpectrogramSmoothing smoothing = @@ -2560,15 +2534,6 @@ if (sx < 0 || sx >= int(sourceModel->getWidth())) continue; - if (!m_synchronous) { - if (!sourceModel->isColumnAvailable(sx)) { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "Met unavailable column at col " << sx << endl; -#endif - return false; - } - } - MagnitudeRange mag; if (sx != psx) { @@ -2715,8 +2680,6 @@ m_drawBuffer.setPixel(x, h-y-1, peakpix); } } - - return true; } void
--- a/layer/SpectrogramLayer.h Fri Jan 22 15:17:25 2016 +0000 +++ b/layer/SpectrogramLayer.h Fri Jan 22 17:08:02 2016 +0000 @@ -418,13 +418,13 @@ mutable std::vector<MagnitudeRange> m_columnMags; void invalidateMagnitudes(); bool updateViewMagnitudes(LayerGeometryProvider *v) const; - bool paintDrawBuffer(LayerGeometryProvider *v, int w, int h, + void paintDrawBuffer(LayerGeometryProvider *v, int w, int h, const std::vector<int> &binforx, const std::vector<double> &binfory, bool usePeaksCache, MagnitudeRange &overallMag, bool &overallMagChanged) const; - bool paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h, + void paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h, const std::vector<int> &binforx, int minbin, int maxbin,