Mercurial > hg > svgui
diff layer/SpectrogramLayer.cpp @ 1566:1f80a514ce29
Merge from branch spectrogram-export
author | Chris Cannam |
---|---|
date | Fri, 10 Jan 2020 14:54:27 +0000 |
parents | 3b45788b7804 |
children |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Fri Nov 22 14:12:50 2019 +0000 +++ b/layer/SpectrogramLayer.cpp Fri Jan 10 14:54:27 2020 +0000 @@ -34,6 +34,7 @@ #include "PianoScale.h" #include "PaintAssistant.h" #include "Colour3DPlotRenderer.h" +#include "Colour3DPlotExporter.h" #include <QPainter> #include <QImage> @@ -142,6 +143,40 @@ recreateFFTModel(); } +ModelId +SpectrogramLayer::getExportModel(LayerGeometryProvider *v) const +{ + // Creating Colour3DPlotExporters is cheap, so we create one on + // every call - calls probably being infrequent - to avoid having + // to worry about view lifecycles. We can't delete them on the + // same call of course as we need to return a valid id, so we push + // them onto a list that then gets cleared (with calls to + // Colour3DPlotExporter::discardSources() and + // ModelById::release()) in deleteDerivedModels(). + + Colour3DPlotExporter::Sources sources; + sources.verticalBinLayer = this; + sources.fft = m_fftModel; + sources.source = sources.fft; + sources.provider = v; + + Colour3DPlotExporter::Parameters params; + params.binDisplay = m_binDisplay; + params.scaleFactor = 1.0; + if (m_colourScale != ColourScaleType::Phase && + m_normalization != ColumnNormalization::Hybrid) { + params.scaleFactor *= 2.f / float(getWindowSize()); + } + params.threshold = m_threshold; // matching ColourScale in getRenderer + params.gain = m_gain; // matching ColourScale in getRenderer + params.normalization = m_normalization; + + ModelId exporter = ModelById::add + (std::make_shared<Colour3DPlotExporter>(sources, params)); + m_exporters.push_back(exporter); + return exporter; +} + void SpectrogramLayer::deleteDerivedModels() { @@ -149,6 +184,15 @@ ModelById::release(m_peakCache); ModelById::release(m_wholeCache); + for (auto exporterId: m_exporters) { + if (auto exporter = + ModelById::getAs<Colour3DPlotExporter>(exporterId)) { + exporter->discardSources(); + } + ModelById::release(exporterId); + } + m_exporters.clear(); + m_fftModel = {}; m_peakCache = {}; m_wholeCache = {};