changeset 1555:745be36202aa spectrogram-export

Provide export model
author Chris Cannam
date Tue, 07 Jan 2020 11:18:43 +0000
parents a0b2f3b4dd2f
children ac8da42674ff
files layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h
diffstat 2 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 <QPainter>
 #include <QImage>
@@ -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<Colour3DPlotExporter>(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<Colour3DPlotExporter>(exporterId)) {
+            exporter->discardSources();
+        }
+        ModelById::release(exporterId);
+    }
+    m_exporters.clear();
+    
     m_fftModel = {};
     m_peakCache = {};
     m_wholeCache = {};
--- 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<ModelId> m_exporters; // used and waiting to be released
     void checkCacheSpace(int *suggestedPeakDivisor,
                          bool *createWholeCache) const;
     void recreateFFTModel();