comparison 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
comparison
equal deleted inserted replaced
1553:76e4302a3fc2 1566:1f80a514ce29
32 32
33 #include "ColourMapper.h" 33 #include "ColourMapper.h"
34 #include "PianoScale.h" 34 #include "PianoScale.h"
35 #include "PaintAssistant.h" 35 #include "PaintAssistant.h"
36 #include "Colour3DPlotRenderer.h" 36 #include "Colour3DPlotRenderer.h"
37 #include "Colour3DPlotExporter.h"
37 38
38 #include <QPainter> 39 #include <QPainter>
39 #include <QImage> 40 #include <QImage>
40 #include <QPixmap> 41 #include <QPixmap>
41 #include <QRect> 42 #include <QRect>
140 if (m_verticallyFixed) return; 141 if (m_verticallyFixed) return;
141 m_verticallyFixed = true; 142 m_verticallyFixed = true;
142 recreateFFTModel(); 143 recreateFFTModel();
143 } 144 }
144 145
146 ModelId
147 SpectrogramLayer::getExportModel(LayerGeometryProvider *v) const
148 {
149 // Creating Colour3DPlotExporters is cheap, so we create one on
150 // every call - calls probably being infrequent - to avoid having
151 // to worry about view lifecycles. We can't delete them on the
152 // same call of course as we need to return a valid id, so we push
153 // them onto a list that then gets cleared (with calls to
154 // Colour3DPlotExporter::discardSources() and
155 // ModelById::release()) in deleteDerivedModels().
156
157 Colour3DPlotExporter::Sources sources;
158 sources.verticalBinLayer = this;
159 sources.fft = m_fftModel;
160 sources.source = sources.fft;
161 sources.provider = v;
162
163 Colour3DPlotExporter::Parameters params;
164 params.binDisplay = m_binDisplay;
165 params.scaleFactor = 1.0;
166 if (m_colourScale != ColourScaleType::Phase &&
167 m_normalization != ColumnNormalization::Hybrid) {
168 params.scaleFactor *= 2.f / float(getWindowSize());
169 }
170 params.threshold = m_threshold; // matching ColourScale in getRenderer
171 params.gain = m_gain; // matching ColourScale in getRenderer
172 params.normalization = m_normalization;
173
174 ModelId exporter = ModelById::add
175 (std::make_shared<Colour3DPlotExporter>(sources, params));
176 m_exporters.push_back(exporter);
177 return exporter;
178 }
179
145 void 180 void
146 SpectrogramLayer::deleteDerivedModels() 181 SpectrogramLayer::deleteDerivedModels()
147 { 182 {
148 ModelById::release(m_fftModel); 183 ModelById::release(m_fftModel);
149 ModelById::release(m_peakCache); 184 ModelById::release(m_peakCache);
150 ModelById::release(m_wholeCache); 185 ModelById::release(m_wholeCache);
151 186
187 for (auto exporterId: m_exporters) {
188 if (auto exporter =
189 ModelById::getAs<Colour3DPlotExporter>(exporterId)) {
190 exporter->discardSources();
191 }
192 ModelById::release(exporterId);
193 }
194 m_exporters.clear();
195
152 m_fftModel = {}; 196 m_fftModel = {};
153 m_peakCache = {}; 197 m_peakCache = {};
154 m_wholeCache = {}; 198 m_wholeCache = {};
155 } 199 }
156 200