# HG changeset patch # User Chris Cannam # Date 1453486361 0 # Node ID 74755fa6ea9e12df2161de1aa7e5c51eee3022ba # Parent 2bd5eb6a6c6b874c48e02b71d674b87768d4653a Avoid reusing a large paint width if the zoom level has changed (in case it has changed dramatically, as for example when the user hits the F key). Also some tidying and adjustment to timing stuff diff -r 2bd5eb6a6c6b -r 74755fa6ea9e layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Fri Jan 22 17:08:02 2016 +0000 +++ b/layer/SpectrogramLayer.cpp Fri Jan 22 18:12:41 2016 +0000 @@ -49,7 +49,7 @@ #include #endif -#define DEBUG_SPECTROGRAM_REPAINT 1 +//#define DEBUG_SPECTROGRAM_REPAINT 1 using std::vector; @@ -1731,6 +1731,13 @@ } } + if (cache.zoomLevel != zoomLevel) { + // no matter what we do with the cache, we'll need to + // recalculate our paint width again because each block will + // take a different time to render from previously + m_lastPaintBlockWidth = 0; + } + if (cache.validArea.width() > 0) { int cw = cache.image.width(); @@ -1868,9 +1875,7 @@ x1 = v->getPaintWidth(); } - struct timeval tv; - (void)gettimeofday(&tv, 0); - RealTime mainPaintStart = RealTime::fromTimeval(tv); + auto mainPaintStart = std::chrono::steady_clock::now(); int paintBlockWidth = m_lastPaintBlockWidth; @@ -1883,13 +1888,14 @@ if (paintBlockWidth == 0) { paintBlockWidth = (300000 / zoomLevel); } else { - RealTime lastTime = m_lastPaintTime; - while (lastTime > RealTime::fromMilliseconds(200) && - paintBlockWidth > 50) { + double lastTime = m_lastPaintTime; + while (lastTime > 0.2 && + paintBlockWidth > 30) { paintBlockWidth /= 2; lastTime = lastTime / 2; } - while (lastTime < RealTime::fromMilliseconds(90) && + while (lastTime < 0.09 && + paintBlockWidth < std::max(50, 1200000 / zoomLevel) && paintBlockWidth < 1500) { paintBlockWidth *= 2; lastTime = lastTime * 2; @@ -1899,9 +1905,9 @@ if (paintBlockWidth < 20) paintBlockWidth = 20; } -#ifdef DEBUG_SPECTROGRAM_REPAINT +//#ifdef DEBUG_SPECTROGRAM_REPAINT cerr << "[" << this << "]: last paint width: " << m_lastPaintBlockWidth << ", last paint time: " << m_lastPaintTime << ", new paint width: " << paintBlockWidth << endl; -#endif +//#endif // We always paint the full height when refreshing the cache. // Smaller heights can be used when painting direct from cache @@ -2156,7 +2162,6 @@ binfory[y] = -1; } else { binfory[y] = q0; -// cerr << "binfory[" << y << "] = " << binfory[y] << endl; } } @@ -2172,38 +2177,11 @@ overallMag, overallMagChanged); } -/* - for (int x = 0; x < w / xPixelRatio; ++x) { - - Profiler innerprof("SpectrogramLayer::paint: 1 pixel column"); - - runOutOfData = !paintColumnValues(v, fft, x0, x, - minbin, maxbin, - displayMinFreq, displayMaxFreq, - xPixelRatio, - h, yforbin); - - if (runOutOfData) { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "Run out of data -- dropping out of loop" << endl; -#endif - break; - } - } -*/ -#ifdef DEBUG_SPECTROGRAM_REPAINT -// cerr << pixels << " pixels drawn" << endl; -#endif - if (overallMagChanged) { m_viewMags[v] = overallMag; #ifdef DEBUG_SPECTROGRAM_REPAINT cerr << "Overall mag is now [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "] - will be updating" << endl; #endif - } else { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "Overall mag unchanged at [" << m_viewMags[v].getMin() << "->" << m_viewMags[v].getMax() << "]" << endl; -#endif } outerprof.end(); @@ -2275,9 +2253,6 @@ paint.drawImage(pr.x(), pr.y(), cache.image, pr.x(), pr.y(), pr.width(), pr.height()); - //!!! -// paint.drawImage(v->rect(), cache.image, -// QRect(QPoint(0, 0), cache.image.size())); cache.startFrame = startFrame; cache.zoomLevel = zoomLevel; @@ -2325,9 +2300,10 @@ #endif if (!m_synchronous) { + auto mainPaintEnd = std::chrono::steady_clock::now(); + auto diff = mainPaintEnd - mainPaintStart; + m_lastPaintTime = std::chrono::duration(diff).count(); m_lastPaintBlockWidth = paintBlockWidth; - (void)gettimeofday(&tv, 0); - m_lastPaintTime = RealTime::fromTimeval(tv) - mainPaintStart; } } @@ -2464,7 +2440,7 @@ int maxbin = int(binfory[h-1]); #ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "minbin " << minbin << ", maxbin " << maxbin << "; w " << w << ", h " << h << endl; + cerr << "paintDrawBuffer: minbin " << minbin << ", maxbin " << maxbin << "; w " << w << ", h " << h << endl; #endif if (minbin < 0) minbin = 0; if (maxbin < 0) maxbin = minbin+1; diff -r 2bd5eb6a6c6b -r 74755fa6ea9e layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Fri Jan 22 17:08:02 2016 +0000 +++ b/layer/SpectrogramLayer.h Fri Jan 22 18:12:41 2016 +0000 @@ -250,20 +250,20 @@ const DenseTimeValueModel *m_model; // I do not own this int m_channel; - int m_windowSize; + int m_windowSize; WindowType m_windowType; - int m_windowHopLevel; - int m_zeroPadLevel; - int m_fftSize; + int m_windowHopLevel; + int m_zeroPadLevel; + int m_fftSize; float m_gain; float m_initialGain; float m_threshold; float m_initialThreshold; int m_colourRotation; int m_initialRotation; - int m_minFrequency; - int m_maxFrequency; - int m_initialMaxFrequency; + int m_minFrequency; + int m_maxFrequency; + int m_initialMaxFrequency; ColourScale m_colourScale; int m_colourMap; QColor m_crosshairColour; @@ -275,7 +275,7 @@ mutable bool m_haveDetailedScale; mutable int m_lastPaintBlockWidth; - mutable RealTime m_lastPaintTime; + mutable double m_lastPaintTime; // seconds enum { NO_VALUE = 0 }; // colour index for unused pixels