Mercurial > hg > svgui
changeset 985:8053c0dfa919 simple-fft-model
Fill extent is not relevant in simple-fft-model code, as it's always the full extent
author | Chris Cannam |
---|---|
date | Wed, 01 Jul 2015 11:32:18 +0100 |
parents | b8187c83b93a |
children | aef8f6fff278 |
files | layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h |
diffstat | 2 files changed, 40 insertions(+), 137 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Fri Jun 12 14:51:46 2015 +0100 +++ b/layer/SpectrogramLayer.cpp Wed Jul 01 11:32:18 2015 +0100 @@ -48,7 +48,7 @@ #include <alloca.h> #endif -//#define DEBUG_SPECTROGRAM_REPAINT 1 +#define DEBUG_SPECTROGRAM_REPAINT 1 using std::vector; @@ -80,8 +80,6 @@ m_synchronous(false), m_haveDetailedScale(false), m_lastPaintBlockWidth(0), - m_updateTimer(0), - m_candidateFillStartFrame(0), m_exiting(false), m_sliceableModel(0) { @@ -120,9 +118,6 @@ SpectrogramLayer::~SpectrogramLayer() { - delete m_updateTimer; - m_updateTimer = 0; - invalidateFFTModels(); } @@ -581,7 +576,7 @@ const View *v = i->first; #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::invalidateImageCaches(" + cerr << "SpectrogramLayer::invalidateImageCaches(" << startFrame << ", " << endFrame << "): view range is " << v->getStartFrame() << ", " << v->getEndFrame() << endl; @@ -601,7 +596,7 @@ } int x = v->getXForFrame(startFrame); #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "clipping from 0 to " << x-1 << endl; + cerr << "clipping from 0 to " << x-1 << endl; #endif if (x > 1) { i->second.validArea &= @@ -618,7 +613,7 @@ } int x = v->getXForFrame(endFrame); #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "clipping from " << x+1 << " to " << v->width() + cerr << "clipping from " << x+1 << " to " << v->width() << endl; #endif if (x < v->width()) { @@ -996,7 +991,7 @@ if (dormant) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::setLayerDormant(" << dormant << ")" + cerr << "SpectrogramLayer::setLayerDormant(" << dormant << ")" << endl; #endif @@ -1011,12 +1006,12 @@ if (m_fftModels.find(v) != m_fftModels.end()) { - if (m_sliceableModel == m_fftModels[v].first) { + if (m_sliceableModel == m_fftModels[v]) { bool replaced = false; for (ViewFFTMap::iterator i = m_fftModels.begin(); i != m_fftModels.end(); ++i) { - if (i->second.first != m_sliceableModel) { - emit sliceableModelReplaced(m_sliceableModel, i->second.first); + if (i->second != m_sliceableModel) { + emit sliceableModelReplaced(m_sliceableModel, i->second); replaced = true; break; } @@ -1024,7 +1019,7 @@ if (!replaced) emit sliceableModelReplaced(m_sliceableModel, 0); } - delete m_fftModels[v].first; + delete m_fftModels[v]; m_fftModels.erase(v); delete m_peakCaches[v]; @@ -1041,7 +1036,7 @@ SpectrogramLayer::cacheInvalid() { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::cacheInvalid()" << endl; + cerr << "SpectrogramLayer::cacheInvalid()" << endl; #endif invalidateImageCaches(); @@ -1052,81 +1047,13 @@ SpectrogramLayer::cacheInvalid(sv_frame_t from, sv_frame_t to) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; + cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; #endif invalidateImageCaches(from, to); invalidateMagnitudes(); } -void -SpectrogramLayer::fillTimerTimedOut() -{ - if (!m_model) return; - - bool allDone = true; - -#ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: have " << m_fftModels.size() << " FFT models associated with views" << endl; -#endif - - for (ViewFFTMap::iterator i = m_fftModels.begin(); - i != m_fftModels.end(); ++i) { - - const FFTModel *model = i->second.first; - sv_frame_t lastFill = i->second.second; - - if (model) { - - sv_frame_t fill = model->getFillExtent(); - -#ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl; -#endif - - if (fill >= lastFill) { - if (fill >= m_model->getEndFrame() && lastFill > 0) { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "complete!" << endl; -#endif - invalidateImageCaches(); - i->second.second = -1; - emit modelChanged(); - - } else if (fill > lastFill) { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "SpectrogramLayer: emitting modelChanged(" - << lastFill << "," << fill << ")" << endl; -#endif - invalidateImageCaches(lastFill, fill); - i->second.second = fill; - emit modelChangedWithin(lastFill, fill); - } - } else { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "SpectrogramLayer: going backwards, emitting modelChanged(" - << m_model->getStartFrame() << "," << m_model->getEndFrame() << ")" << endl; -#endif - invalidateImageCaches(); - i->second.second = fill; - emit modelChangedWithin(m_model->getStartFrame(), m_model->getEndFrame()); - } - - if (i->second.second >= 0) { - allDone = false; - } - } - } - - if (allDone) { -#ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << "SpectrogramLayer: all complete!" << endl; -#endif - delete m_updateTimer; - m_updateTimer = 0; - } -} - bool SpectrogramLayer::hasLightBackground() const { @@ -1600,25 +1527,25 @@ int fftSize = getFFTSize(v); if (m_fftModels.find(v) != m_fftModels.end()) { - if (m_fftModels[v].first == 0) { + if (m_fftModels[v] == 0) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; + cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; #endif return 0; } - if (m_fftModels[v].first->getHeight() != fftSize / 2 + 1) { + if (m_fftModels[v]->getHeight() != fftSize / 2 + 1) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[v].first->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl; + cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[v]->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl; #endif - delete m_fftModels[v].first; + delete m_fftModels[v]; m_fftModels.erase(v); delete m_peakCaches[v]; m_peakCaches.erase(v); } else { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[v].first->getHeight() << endl; + cerr << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[v]->getHeight() << endl; #endif - return m_fftModels[v].first; + return m_fftModels[v]; } } @@ -1637,7 +1564,7 @@ tr("Failed to create the FFT model for this spectrogram.\n" "There may be insufficient memory or disc space to continue.")); delete model; - m_fftModels[v] = FFTFillPair(0, 0); + m_fftModels[v] = 0; return 0; } @@ -1649,16 +1576,10 @@ m_sliceableModel = model; } - m_fftModels[v] = FFTFillPair(model, 0); - - delete m_updateTimer; - m_updateTimer = new QTimer((SpectrogramLayer *)this); - connect(m_updateTimer, SIGNAL(timeout()), - this, SLOT(fillTimerTimedOut())); - m_updateTimer->start(200); + m_fftModels[v] = model; } - return m_fftModels[v].first; + return m_fftModels[v]; } Dense3DModelPeakCache * @@ -1677,7 +1598,7 @@ { if (m_sliceableModel) return m_sliceableModel; if (m_fftModels.empty()) return 0; - m_sliceableModel = m_fftModels.begin()->second.first; + m_sliceableModel = m_fftModels.begin()->second; return m_sliceableModel; } @@ -1686,7 +1607,7 @@ { for (ViewFFTMap::iterator i = m_fftModels.begin(); i != m_fftModels.end(); ++i) { - delete i->second.first; + delete i->second; } for (PeakCacheMap::iterator i = m_peakCaches.begin(); i != m_peakCaches.end(); ++i) { @@ -1745,7 +1666,7 @@ } #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::updateViewMagnitudes returning from cols " + cerr << "SpectrogramLayer::updateViewMagnitudes returning from cols " << s0 << " -> " << s1 << " inclusive" << endl; #endif @@ -1770,14 +1691,12 @@ Profiler profiler("SpectrogramLayer::paint", false); #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", m_updateTimer " << m_updateTimer << endl; + cerr << "SpectrogramLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << endl; cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl; #endif sv_frame_t startFrame = v->getStartFrame(); - if (startFrame < 0) m_candidateFillStartFrame = 0; - else m_candidateFillStartFrame = startFrame; if (!m_model || !m_model->isOK() || !m_model->isReady()) { return; @@ -1805,16 +1724,11 @@ ImageCache &cache = m_imageCaches[v]; #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::paint(): image cache valid area " << cache. + cerr << "SpectrogramLayer::paint(): image cache valid area " << cache. validArea.x() << ", " << cache.validArea.y() << ", " << cache.validArea.width() << "x" << cache.validArea.height() << endl; #endif -#ifdef DEBUG_SPECTROGRAM_REPAINT - bool stillCacheing = (m_updateTimer != 0); - SVDEBUG << "SpectrogramLayer::paint(): Still cacheing = " << stillCacheing << endl; -#endif - int zoomLevel = v->getZoomLevel(); int x0 = 0; @@ -2169,10 +2083,6 @@ SVDEBUG << "*** NOTE: w == 0" << endl; } -#ifdef DEBUG_SPECTROGRAM_REPAINT - int pixels = 0; -#endif - Profiler outerprof("SpectrogramLayer::paint: all cols"); // The draw buffer contains a fragment at either our pixel @@ -2323,7 +2233,7 @@ if (recreateWholeImageCache) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "Recreating image cache: width = " << v->width() + cerr << "Recreating image cache: width = " << v->width() << ", height = " << h << endl; #endif cache.image = QImage(v->width(), h, QImage::Format_ARGB32_Premultiplied); @@ -2331,7 +2241,7 @@ if (w > 0) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "Painting " << w << "x" << h + cerr << "Painting " << w << "x" << h << " from draw buffer at " << 0 << "," << 0 << " to " << w << "x" << h << " on cache at " << x0 << "," << 0 << endl; @@ -2343,7 +2253,7 @@ int scaledLeft = v->getXForFrame(leftBoundaryFrame); int scaledRight = v->getXForFrame(rightBoundaryFrame); #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "Rescaling image from " << bufwid + cerr << "Rescaling image from " << bufwid << "x" << h << " to " << scaledRight-scaledLeft << "x" << h << endl; #endif @@ -2358,7 +2268,7 @@ int scaledLeftCrop = v->getXForFrame(leftCropFrame); int scaledRightCrop = v->getXForFrame(rightCropFrame); #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to " + cerr << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to " << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl; #endif cachePainter.drawImage @@ -2379,7 +2289,7 @@ QRect pr = rect & cache.validArea; #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "Painting " << pr.width() << "x" << pr.height() + cerr << "Painting " << pr.width() << "x" << pr.height() << " from cache at " << pr.x() << "," << pr.y() << " to window" << endl; #endif @@ -2399,7 +2309,7 @@ if (cache.validArea.x() > 0) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::paint() updating left (0, " + cerr << "SpectrogramLayer::paint() updating left (0, " << cache.validArea.x() << ")" << endl; #endif v->update(0, 0, cache.validArea.x(), h); @@ -2408,7 +2318,7 @@ if (cache.validArea.x() + cache.validArea.width() < cache.image.width()) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::paint() updating right (" + cerr << "SpectrogramLayer::paint() updating right (" << cache.validArea.x() + cache.validArea.width() << ", " << cache.image.width() - (cache.validArea.x() + @@ -2432,7 +2342,7 @@ illuminateLocalFeatures(v, paint); #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::paint() returning" << endl; + cerr << "SpectrogramLayer::paint() returning" << endl; #endif if (!m_synchronous) { @@ -2670,7 +2580,7 @@ if (sx != psx) { if (fft) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "Retrieving column " << sx << " from fft directly" << endl; + cerr << "Retrieving column " << sx << " from fft directly" << endl; #endif if (m_colourScale == PhaseColourScale) { fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1); @@ -2689,7 +2599,7 @@ } } else { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "Retrieving column " << sx << " from peaks cache" << endl; + cerr << "Retrieving column " << sx << " from peaks cache" << endl; #endif c = sourceModel->getColumn(sx); if (m_normalizeColumns || m_normalizeHybrid) { @@ -2871,12 +2781,11 @@ int SpectrogramLayer::getCompletion(View *v) const { - if (m_updateTimer == 0) return 100; if (m_fftModels.find(v) == m_fftModels.end()) return 100; - int completion = m_fftModels[v].first->getCompletion(); + int completion = m_fftModels[v]->getCompletion(); #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl; + cerr << "SpectrogramLayer::getCompletion: completion = " << completion << endl; #endif return completion; } @@ -2885,7 +2794,7 @@ SpectrogramLayer::getError(View *v) const { if (m_fftModels.find(v) == m_fftModels.end()) return ""; - return m_fftModels[v].first->getError(); + return m_fftModels[v]->getError(); } bool
--- a/layer/SpectrogramLayer.h Fri Jun 12 14:51:46 2015 +0100 +++ b/layer/SpectrogramLayer.h Wed Jul 01 11:32:18 2015 +0100 @@ -247,8 +247,6 @@ void preferenceChanged(PropertyContainer::PropertyName name); - void fillTimerTimedOut(); - protected: const DenseTimeValueModel *m_model; // I do not own this @@ -326,9 +324,6 @@ */ mutable QImage m_drawBuffer; - mutable QTimer *m_updateTimer; - - mutable sv_frame_t m_candidateFillStartFrame; bool m_exiting; void initialisePalette(); @@ -373,8 +368,7 @@ Dense3DModelPeakCache *getPeakCache(const View *v) const; void invalidateFFTModels(); - typedef std::pair<FFTModel *, sv_frame_t> FFTFillPair; // model, last fill - typedef std::map<const View *, FFTFillPair> ViewFFTMap; + typedef std::map<const View *, FFTModel *> ViewFFTMap; typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap; mutable ViewFFTMap m_fftModels; mutable PeakCacheMap m_peakCaches;