# HG changeset patch # User Chris Cannam # Date 1578395923 0 # Node ID 745be36202aa6d0d1f5904d138c0a3ab7f3623bb # Parent a0b2f3b4dd2f6d07a4ce8b0ea3a89fc8e98d85a5 Provide export model diff -r a0b2f3b4dd2f -r 745be36202aa layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Mon Jan 06 14:46:25 2020 +0000 +++ b/layer/SpectrogramLayer.cpp Tue Jan 07 11:18:43 2020 +0000 @@ -34,6 +34,7 @@ #include "PianoScale.h" #include "PaintAssistant.h" #include "Colour3DPlotRenderer.h" +#include "Colour3DPlotExporter.h" #include #include @@ -142,6 +143,33 @@ recreateFFTModel(); } +ModelId +SpectrogramLayer::getExportModel(LayerGeometryProvider *v) const +{ + //!!! Creating Colour3DPlotExporters is cheap, so perhaps we + // should 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 could 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; + + ModelId exporter = ModelById::add + (std::make_shared(sources, params)); + m_exporters.push_back(exporter); + return exporter; +} + void SpectrogramLayer::deleteDerivedModels() { @@ -149,6 +177,15 @@ ModelById::release(m_peakCache); ModelById::release(m_wholeCache); + for (auto exporterId: m_exporters) { + if (auto exporter = + ModelById::getAs(exporterId)) { + exporter->discardSources(); + } + ModelById::release(exporterId); + } + m_exporters.clear(); + m_fftModel = {}; m_peakCache = {}; m_wholeCache = {}; diff -r a0b2f3b4dd2f -r 745be36202aa layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Mon Jan 06 14:46:25 2020 +0000 +++ b/layer/SpectrogramLayer.h Tue Jan 07 11:18:43 2020 +0000 @@ -334,6 +334,7 @@ ModelId m_wholeCache; // a Dense3DModelPeakCache ModelId m_peakCache; // a Dense3DModelPeakCache int m_peakCacheDivisor; + mutable std::vector m_exporters; // used and waiting to be released void checkCacheSpace(int *suggestedPeakDivisor, bool *createWholeCache) const; void recreateFFTModel();