Mercurial > hg > svgui
changeset 1117:64709d4d09ef spectrogram-minor-refactor
Fix translucent mode for spectrogram
author | Chris Cannam |
---|---|
date | Tue, 19 Jul 2016 17:28:03 +0100 |
parents | e7a07cd63d21 |
children | 175d4e15884d |
files | layer/Colour3DPlotRenderer.cpp layer/SpectrogramLayer.cpp |
diffstat | 2 files changed, 38 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Colour3DPlotRenderer.cpp Tue Jul 19 15:08:22 2016 +0100 +++ b/layer/Colour3DPlotRenderer.cpp Tue Jul 19 17:28:03 2016 +0100 @@ -16,6 +16,8 @@ #include "Colour3DPlotRenderer.h" #include "RenderTimer.h" +#include "base/Profiler.h" + #include "data/model/DenseThreeDimensionalModel.h" #include "data/model/Dense3DModelPeakCache.h" #include "data/model/FFTModel.h" @@ -247,8 +249,8 @@ // consider translucent option -- only if not smoothing & not // explicitly requested opaque & sufficiently zoomed-in - if (model->getHeight() < v->getPaintHeight() && - relativeBinResolution >= 2 * zoomLevel) { + if (model->getHeight() * 3 < v->getPaintHeight() && + relativeBinResolution >= 3 * zoomLevel) { return DirectTranslucent; } } @@ -265,6 +267,8 @@ QPainter &paint, QRect rect) { + Profiler profiler("Colour3DPlotRenderer::renderDirectTranslucent"); + QPoint illuminatePos; bool illuminate = v->shouldIlluminateLocalFeatures (m_sources.verticalBinLayer, illuminatePos); @@ -430,6 +434,7 @@ bool rightToLeft, bool timeConstrained) { + Profiler profiler("Colour3DPlotRenderer::renderToCachePixelResolution"); cerr << "renderToCachePixelResolution" << endl; // Draw to the draw buffer, and then copy from there. The draw @@ -520,6 +525,7 @@ Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v, int x0, int repaintWidth) { + Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution"); cerr << "renderToCacheBinResolution" << endl; // Draw to the draw buffer, and then scale-copy from there. Draw
--- a/layer/SpectrogramLayer.cpp Tue Jul 19 15:08:22 2016 +0100 +++ b/layer/SpectrogramLayer.cpp Tue Jul 19 17:28:03 2016 +0100 @@ -1017,6 +1017,7 @@ cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; #endif + //!!! now in common with Colour3DPlotLayer: // We used to call invalidateMagnitudes(from, to) to invalidate // only those caches whose views contained some of the (from, to) // range. That's the right thing to do; it has been lost in @@ -1067,60 +1068,43 @@ SpectrogramLayer::getYBinRange(LayerGeometryProvider *v, int y, double &q0, double &q1) const { Profiler profiler("SpectrogramLayer::getYBinRange"); - int h = v->getPaintHeight(); if (y < 0 || y >= h) return false; - + q0 = getBinForY(v, y); + q1 = getBinForY(v, y-1); + return true; +} + +double +SpectrogramLayer::getYForBin(const LayerGeometryProvider *v, double bin) const +{ + double minf = getEffectiveMinFrequency(); + double maxf = getEffectiveMaxFrequency(); + bool logarithmic = (m_binScale == BinScale::Log); + sv_samplerate_t sr = m_model->getSampleRate(); + + double freq = (bin * sr) / getFFTSize(); + + double y = v->getYForFrequency(freq, minf, maxf, logarithmic); + + return y; +} + +double +SpectrogramLayer::getBinForY(const LayerGeometryProvider *v, double y) const +{ sv_samplerate_t sr = m_model->getSampleRate(); double minf = getEffectiveMinFrequency(); double maxf = getEffectiveMaxFrequency(); bool logarithmic = (m_binScale == BinScale::Log); - q0 = v->getFrequencyForY(y, minf, maxf, logarithmic); - q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic); - - // Now map these on to ("proportions of") actual bins - - q0 = (q0 * getFFTSize()) / sr; - q1 = (q1 * getFFTSize()) / sr; - - return true; -} - -double -SpectrogramLayer::getYForBin(const LayerGeometryProvider *, double) const { - //!!! not implemented -- needed for non-opaque render - - //!!! this will crash, as it stands, when a spectrogram without - //!!! smoothing is zoomed in - - //!!! overlap with range methods - throw std::logic_error("not implemented"); -} - -double -SpectrogramLayer::getBinForY(const LayerGeometryProvider *v, double y) const -{ - //!!! overlap with range methods above (but using double arg) - //!!! tidy this - - int h = v->getPaintHeight(); - if (y < 0 || y >= h) return false; - - sv_samplerate_t sr = m_model->getSampleRate(); - double minf = getEffectiveMinFrequency(); - double maxf = getEffectiveMaxFrequency(); - - bool logarithmic = (m_binScale == BinScale::Log); - - double q = v->getFrequencyForY(y, minf, maxf, logarithmic); - - // Now map on to ("proportions of") actual bins - - q = (q * getFFTSize()) / sr; - - return q; + double freq = v->getFrequencyForY(y, minf, maxf, logarithmic); + + // Now map on to ("proportion of") actual bins + double bin = (freq * getFFTSize()) / sr; + + return bin; } bool