Chris@320
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@320
|
2
|
Chris@320
|
3 /*
|
Chris@320
|
4 Sonic Visualiser
|
Chris@320
|
5 An audio file viewer and annotation editor.
|
Chris@320
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@320
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@320
|
8
|
Chris@320
|
9 This program is free software; you can redistribute it and/or
|
Chris@320
|
10 modify it under the terms of the GNU General Public License as
|
Chris@320
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@320
|
12 License, or (at your option) any later version. See the file
|
Chris@320
|
13 COPYING included with this distribution for more information.
|
Chris@320
|
14 */
|
Chris@320
|
15
|
Chris@331
|
16 #include "FeatureExtractionModelTransformer.h"
|
Chris@320
|
17
|
Chris@320
|
18 #include "plugin/FeatureExtractionPluginFactory.h"
|
Chris@320
|
19 #include "plugin/PluginXml.h"
|
Chris@475
|
20 #include <vamp-hostsdk/Plugin.h>
|
Chris@320
|
21
|
Chris@320
|
22 #include "data/model/Model.h"
|
Chris@320
|
23 #include "base/Window.h"
|
Chris@387
|
24 #include "base/Exceptions.h"
|
Chris@320
|
25 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@320
|
26 #include "data/model/SparseTimeValueModel.h"
|
Chris@320
|
27 #include "data/model/EditableDenseThreeDimensionalModel.h"
|
Chris@320
|
28 #include "data/model/DenseTimeValueModel.h"
|
Chris@320
|
29 #include "data/model/NoteModel.h"
|
gyorgyf@786
|
30 #include "data/model/FlexiNoteModel.h"
|
Chris@441
|
31 #include "data/model/RegionModel.h"
|
Chris@320
|
32 #include "data/model/FFTModel.h"
|
Chris@320
|
33 #include "data/model/WaveFileModel.h"
|
Chris@558
|
34 #include "rdf/PluginRDFDescription.h"
|
Chris@320
|
35
|
Chris@350
|
36 #include "TransformFactory.h"
|
Chris@350
|
37
|
Chris@320
|
38 #include <iostream>
|
Chris@320
|
39
|
Chris@350
|
40 FeatureExtractionModelTransformer::FeatureExtractionModelTransformer(Input in,
|
gyorgyf@786
|
41 const Transform &transform,
|
gyorgyf@786
|
42 const PreferredOutputModel outputmodel) :
|
Chris@350
|
43 ModelTransformer(in, transform),
|
Chris@320
|
44 m_plugin(0),
|
Chris@320
|
45 m_descriptor(0),
|
Chris@779
|
46 m_outputNo(0),
|
Chris@822
|
47 m_fixedRateFeatureNo(-1), // we increment before use
|
Chris@822
|
48 m_preferredOutputModel(outputmodel)
|
Chris@320
|
49 {
|
Chris@690
|
50 // SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << pluginId << ", outputName " << m_transform.getOutput() << endl;
|
Chris@350
|
51
|
Chris@350
|
52 QString pluginId = transform.getPluginIdentifier();
|
Chris@320
|
53
|
Chris@320
|
54 FeatureExtractionPluginFactory *factory =
|
Chris@320
|
55 FeatureExtractionPluginFactory::instanceFor(pluginId);
|
Chris@320
|
56
|
Chris@320
|
57 if (!factory) {
|
Chris@361
|
58 m_message = tr("No factory available for feature extraction plugin id \"%1\" (unknown plugin type, or internal error?)").arg(pluginId);
|
Chris@320
|
59 return;
|
Chris@320
|
60 }
|
Chris@320
|
61
|
Chris@350
|
62 DenseTimeValueModel *input = getConformingInput();
|
Chris@350
|
63 if (!input) {
|
Chris@361
|
64 m_message = tr("Input model for feature extraction plugin \"%1\" is of wrong type (internal error?)").arg(pluginId);
|
Chris@350
|
65 return;
|
Chris@350
|
66 }
|
Chris@320
|
67
|
Chris@350
|
68 m_plugin = factory->instantiatePlugin(pluginId, input->getSampleRate());
|
Chris@320
|
69 if (!m_plugin) {
|
Chris@361
|
70 m_message = tr("Failed to instantiate plugin \"%1\"").arg(pluginId);
|
Chris@320
|
71 return;
|
Chris@320
|
72 }
|
Chris@320
|
73
|
Chris@350
|
74 TransformFactory::getInstance()->makeContextConsistentWithPlugin
|
Chris@350
|
75 (m_transform, m_plugin);
|
Chris@343
|
76
|
Chris@350
|
77 TransformFactory::getInstance()->setPluginParameters
|
Chris@350
|
78 (m_transform, m_plugin);
|
Chris@320
|
79
|
Chris@320
|
80 size_t channelCount = input->getChannelCount();
|
Chris@320
|
81 if (m_plugin->getMaxChannelCount() < channelCount) {
|
Chris@320
|
82 channelCount = 1;
|
Chris@320
|
83 }
|
Chris@320
|
84 if (m_plugin->getMinChannelCount() > channelCount) {
|
Chris@361
|
85 m_message = tr("Cannot provide enough channels to feature extraction plugin \"%1\" (plugin min is %2, max %3; input model has %4)")
|
Chris@361
|
86 .arg(pluginId)
|
Chris@361
|
87 .arg(m_plugin->getMinChannelCount())
|
Chris@361
|
88 .arg(m_plugin->getMaxChannelCount())
|
Chris@361
|
89 .arg(input->getChannelCount());
|
Chris@320
|
90 return;
|
Chris@320
|
91 }
|
Chris@320
|
92
|
Chris@690
|
93 SVDEBUG << "Initialising feature extraction plugin with channels = "
|
Chris@350
|
94 << channelCount << ", step = " << m_transform.getStepSize()
|
Chris@687
|
95 << ", block = " << m_transform.getBlockSize() << endl;
|
Chris@320
|
96
|
Chris@320
|
97 if (!m_plugin->initialise(channelCount,
|
Chris@350
|
98 m_transform.getStepSize(),
|
Chris@350
|
99 m_transform.getBlockSize())) {
|
Chris@361
|
100
|
Chris@361
|
101 size_t pstep = m_transform.getStepSize();
|
Chris@361
|
102 size_t pblock = m_transform.getBlockSize();
|
Chris@361
|
103
|
Chris@361
|
104 m_transform.setStepSize(0);
|
Chris@361
|
105 m_transform.setBlockSize(0);
|
Chris@361
|
106 TransformFactory::getInstance()->makeContextConsistentWithPlugin
|
Chris@361
|
107 (m_transform, m_plugin);
|
Chris@361
|
108
|
Chris@361
|
109 if (m_transform.getStepSize() != pstep ||
|
Chris@361
|
110 m_transform.getBlockSize() != pblock) {
|
Chris@361
|
111
|
Chris@361
|
112 if (!m_plugin->initialise(channelCount,
|
Chris@361
|
113 m_transform.getStepSize(),
|
Chris@361
|
114 m_transform.getBlockSize())) {
|
Chris@361
|
115
|
Chris@361
|
116 m_message = tr("Failed to initialise feature extraction plugin \"%1\"").arg(pluginId);
|
Chris@361
|
117 return;
|
Chris@361
|
118
|
Chris@361
|
119 } else {
|
Chris@361
|
120
|
Chris@361
|
121 m_message = tr("Feature extraction plugin \"%1\" rejected the given step and block sizes (%2 and %3); using plugin defaults (%4 and %5) instead")
|
Chris@361
|
122 .arg(pluginId)
|
Chris@361
|
123 .arg(pstep)
|
Chris@361
|
124 .arg(pblock)
|
Chris@361
|
125 .arg(m_transform.getStepSize())
|
Chris@361
|
126 .arg(m_transform.getBlockSize());
|
Chris@361
|
127 }
|
Chris@361
|
128
|
Chris@361
|
129 } else {
|
Chris@361
|
130
|
Chris@361
|
131 m_message = tr("Failed to initialise feature extraction plugin \"%1\"").arg(pluginId);
|
Chris@361
|
132 return;
|
Chris@361
|
133 }
|
Chris@320
|
134 }
|
Chris@320
|
135
|
Chris@366
|
136 if (m_transform.getPluginVersion() != "") {
|
Chris@366
|
137 QString pv = QString("%1").arg(m_plugin->getPluginVersion());
|
Chris@366
|
138 if (pv != m_transform.getPluginVersion()) {
|
Chris@366
|
139 QString vm = tr("Transform was configured for version %1 of plugin \"%2\", but the plugin being used is version %3")
|
Chris@366
|
140 .arg(m_transform.getPluginVersion())
|
Chris@366
|
141 .arg(pluginId)
|
Chris@366
|
142 .arg(pv);
|
Chris@366
|
143 if (m_message != "") {
|
Chris@366
|
144 m_message = QString("%1; %2").arg(vm).arg(m_message);
|
Chris@366
|
145 } else {
|
Chris@366
|
146 m_message = vm;
|
Chris@366
|
147 }
|
Chris@366
|
148 }
|
Chris@366
|
149 }
|
Chris@366
|
150
|
Chris@320
|
151 Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors();
|
Chris@320
|
152
|
Chris@320
|
153 if (outputs.empty()) {
|
Chris@361
|
154 m_message = tr("Plugin \"%1\" has no outputs").arg(pluginId);
|
Chris@320
|
155 return;
|
Chris@320
|
156 }
|
Chris@320
|
157
|
Chris@320
|
158 for (size_t i = 0; i < outputs.size(); ++i) {
|
Chris@690
|
159 // SVDEBUG << "comparing output " << i << " name \"" << outputs[i].identifier << "\" with expected \"" << m_transform.getOutput() << "\"" << endl;
|
Chris@350
|
160 if (m_transform.getOutput() == "" ||
|
Chris@350
|
161 outputs[i].identifier == m_transform.getOutput().toStdString()) {
|
Chris@778
|
162 m_outputNo = i;
|
Chris@441
|
163 m_descriptor = new Vamp::Plugin::OutputDescriptor(outputs[i]);
|
Chris@320
|
164 break;
|
Chris@320
|
165 }
|
Chris@320
|
166 }
|
Chris@320
|
167
|
Chris@320
|
168 if (!m_descriptor) {
|
Chris@361
|
169 m_message = tr("Plugin \"%1\" has no output named \"%2\"")
|
Chris@361
|
170 .arg(pluginId)
|
Chris@361
|
171 .arg(m_transform.getOutput());
|
Chris@320
|
172 return;
|
Chris@320
|
173 }
|
Chris@320
|
174
|
Chris@558
|
175 createOutputModel();
|
Chris@558
|
176 }
|
Chris@558
|
177
|
Chris@558
|
178 void
|
Chris@558
|
179 FeatureExtractionModelTransformer::createOutputModel()
|
Chris@558
|
180 {
|
Chris@558
|
181 DenseTimeValueModel *input = getConformingInput();
|
Chris@558
|
182
|
Chris@712
|
183 // std::cerr << "FeatureExtractionModelTransformer::createOutputModel: sample type " << m_descriptor->sampleType << ", rate " << m_descriptor->sampleRate << std::endl;
|
Chris@712
|
184
|
Chris@558
|
185 PluginRDFDescription description(m_transform.getPluginIdentifier());
|
Chris@558
|
186 QString outputId = m_transform.getOutput();
|
Chris@558
|
187
|
Chris@320
|
188 int binCount = 1;
|
Chris@320
|
189 float minValue = 0.0, maxValue = 0.0;
|
Chris@320
|
190 bool haveExtents = false;
|
Chris@320
|
191
|
Chris@320
|
192 if (m_descriptor->hasFixedBinCount) {
|
Chris@320
|
193 binCount = m_descriptor->binCount;
|
Chris@320
|
194 }
|
Chris@320
|
195
|
Chris@331
|
196 // std::cerr << "FeatureExtractionModelTransformer: output bin count "
|
Chris@320
|
197 // << binCount << std::endl;
|
Chris@320
|
198
|
Chris@320
|
199 if (binCount > 0 && m_descriptor->hasKnownExtents) {
|
Chris@320
|
200 minValue = m_descriptor->minValue;
|
Chris@320
|
201 maxValue = m_descriptor->maxValue;
|
Chris@320
|
202 haveExtents = true;
|
Chris@320
|
203 }
|
Chris@320
|
204
|
Chris@350
|
205 size_t modelRate = input->getSampleRate();
|
Chris@320
|
206 size_t modelResolution = 1;
|
Chris@712
|
207
|
Chris@785
|
208 if (m_descriptor->sampleType !=
|
Chris@785
|
209 Vamp::Plugin::OutputDescriptor::OneSamplePerStep) {
|
Chris@785
|
210 if (m_descriptor->sampleRate > input->getSampleRate()) {
|
Chris@785
|
211 std::cerr << "WARNING: plugin reports output sample rate as "
|
Chris@785
|
212 << m_descriptor->sampleRate << " (can't display features with finer resolution than the input rate of " << input->getSampleRate() << ")" << std::endl;
|
Chris@785
|
213 }
|
Chris@785
|
214 }
|
Chris@785
|
215
|
Chris@320
|
216 switch (m_descriptor->sampleType) {
|
Chris@320
|
217
|
Chris@320
|
218 case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
|
Chris@320
|
219 if (m_descriptor->sampleRate != 0.0) {
|
Chris@320
|
220 modelResolution = size_t(modelRate / m_descriptor->sampleRate + 0.001);
|
Chris@320
|
221 }
|
Chris@320
|
222 break;
|
Chris@320
|
223
|
Chris@320
|
224 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep:
|
Chris@350
|
225 modelResolution = m_transform.getStepSize();
|
Chris@320
|
226 break;
|
Chris@320
|
227
|
Chris@320
|
228 case Vamp::Plugin::OutputDescriptor::FixedSampleRate:
|
Chris@451
|
229 //!!! SV doesn't actually support display of models that have
|
Chris@451
|
230 //!!! different underlying rates together -- so we always set
|
Chris@451
|
231 //!!! the model rate to be the input model's rate, and adjust
|
Chris@451
|
232 //!!! the resolution appropriately. We can't properly display
|
Chris@451
|
233 //!!! data with a higher resolution than the base model at all
|
Chris@451
|
234 // modelRate = size_t(m_descriptor->sampleRate + 0.001);
|
Chris@451
|
235 if (m_descriptor->sampleRate > input->getSampleRate()) {
|
Chris@451
|
236 modelResolution = 1;
|
Chris@451
|
237 } else {
|
Chris@451
|
238 modelResolution = size_t(input->getSampleRate() /
|
Chris@451
|
239 m_descriptor->sampleRate);
|
Chris@451
|
240 }
|
Chris@320
|
241 break;
|
Chris@320
|
242 }
|
Chris@320
|
243
|
Chris@441
|
244 bool preDurationPlugin = (m_plugin->getVampApiVersion() < 2);
|
Chris@441
|
245
|
Chris@441
|
246 if (binCount == 0 &&
|
Chris@441
|
247 (preDurationPlugin || !m_descriptor->hasDuration)) {
|
Chris@320
|
248
|
Chris@445
|
249 // Anything with no value and no duration is an instant
|
Chris@445
|
250
|
Chris@320
|
251 m_output = new SparseOneDimensionalModel(modelRate, modelResolution,
|
Chris@320
|
252 false);
|
Chris@320
|
253
|
Chris@558
|
254 QString outputEventTypeURI = description.getOutputEventTypeURI(outputId);
|
Chris@558
|
255 m_output->setRDFTypeURI(outputEventTypeURI);
|
Chris@558
|
256
|
Chris@441
|
257 } else if ((preDurationPlugin && binCount > 1 &&
|
Chris@441
|
258 (m_descriptor->sampleType ==
|
Chris@441
|
259 Vamp::Plugin::OutputDescriptor::VariableSampleRate)) ||
|
Chris@441
|
260 (!preDurationPlugin && m_descriptor->hasDuration)) {
|
Chris@441
|
261
|
Chris@441
|
262 // For plugins using the old v1 API without explicit duration,
|
Chris@441
|
263 // we treat anything that has multiple bins (i.e. that has the
|
Chris@441
|
264 // potential to have value and duration) and a variable sample
|
Chris@441
|
265 // rate as a note model, taking its values as pitch, duration
|
Chris@441
|
266 // and velocity (if present) respectively. This is the same
|
Chris@441
|
267 // behaviour as always applied by SV to these plugins in the
|
Chris@441
|
268 // past.
|
Chris@441
|
269
|
Chris@441
|
270 // For plugins with the newer API, we treat anything with
|
Chris@441
|
271 // duration as either a note model with pitch and velocity, or
|
Chris@441
|
272 // a region model.
|
Chris@441
|
273
|
Chris@441
|
274 // How do we know whether it's an interval or note model?
|
Chris@441
|
275 // What's the essential difference? Is a note model any
|
Chris@441
|
276 // interval model using a Hz or "MIDI pitch" scale? There
|
Chris@441
|
277 // isn't really a reliable test for "MIDI pitch"... Does a
|
Chris@441
|
278 // note model always have velocity? This is a good question
|
Chris@441
|
279 // to be addressed by accompanying RDF, but for the moment we
|
Chris@441
|
280 // will do the following...
|
Chris@441
|
281
|
Chris@441
|
282 bool isNoteModel = false;
|
Chris@441
|
283
|
Chris@441
|
284 // Regions have only value (and duration -- we can't extract a
|
Chris@441
|
285 // region model from an old-style plugin that doesn't support
|
Chris@441
|
286 // duration)
|
Chris@441
|
287 if (binCount > 1) isNoteModel = true;
|
Chris@441
|
288
|
Chris@595
|
289 // Regions do not have units of Hz or MIDI things (a sweeping
|
Chris@595
|
290 // assumption!)
|
Chris@595
|
291 if (m_descriptor->unit == "Hz" ||
|
Chris@595
|
292 m_descriptor->unit.find("MIDI") != std::string::npos ||
|
Chris@595
|
293 m_descriptor->unit.find("midi") != std::string::npos) {
|
Chris@595
|
294 isNoteModel = true;
|
Chris@595
|
295 }
|
Chris@441
|
296
|
Chris@441
|
297 // If we had a "sparse 3D model", we would have the additional
|
Chris@441
|
298 // problem of determining whether to use that here (if bin
|
Chris@441
|
299 // count > 1). But we don't.
|
Chris@441
|
300
|
gyorgyf@786
|
301 if (isNoteModel && m_preferredOutputModel == NoteOutputModel) {
|
Chris@441
|
302
|
Chris@441
|
303 NoteModel *model;
|
Chris@441
|
304 if (haveExtents) {
|
gyorgyf@786
|
305 model = new NoteModel (modelRate, modelResolution, minValue, maxValue, false);
|
Chris@441
|
306 } else {
|
gyorgyf@786
|
307 model = new NoteModel (modelRate, modelResolution, false);
|
gyorgyf@786
|
308 }
|
gyorgyf@786
|
309 model->setScaleUnits(m_descriptor->unit.c_str());
|
gyorgyf@786
|
310 m_output = model;
|
gyorgyf@786
|
311
|
gyorgyf@787
|
312 // GF: FlexiNoteModel is selected if the m_preferredOutputModel is set
|
gyorgyf@786
|
313 } else if (isNoteModel && m_preferredOutputModel == FlexiNoteOutputModel) {
|
gyorgyf@786
|
314
|
gyorgyf@786
|
315 FlexiNoteModel *model;
|
gyorgyf@786
|
316 if (haveExtents) {
|
gyorgyf@786
|
317 model = new FlexiNoteModel (modelRate, modelResolution, minValue, maxValue, false);
|
gyorgyf@786
|
318 } else {
|
gyorgyf@786
|
319 model = new FlexiNoteModel (modelRate, modelResolution, false);
|
Chris@441
|
320 }
|
Chris@441
|
321 model->setScaleUnits(m_descriptor->unit.c_str());
|
Chris@441
|
322 m_output = model;
|
Chris@441
|
323
|
Chris@441
|
324 } else {
|
Chris@441
|
325
|
Chris@441
|
326 RegionModel *model;
|
Chris@441
|
327 if (haveExtents) {
|
Chris@441
|
328 model = new RegionModel
|
Chris@441
|
329 (modelRate, modelResolution, minValue, maxValue, false);
|
Chris@441
|
330 } else {
|
Chris@441
|
331 model = new RegionModel
|
Chris@441
|
332 (modelRate, modelResolution, false);
|
Chris@441
|
333 }
|
Chris@441
|
334 model->setScaleUnits(m_descriptor->unit.c_str());
|
Chris@441
|
335 m_output = model;
|
Chris@441
|
336 }
|
Chris@441
|
337
|
Chris@558
|
338 QString outputEventTypeURI = description.getOutputEventTypeURI(outputId);
|
Chris@558
|
339 m_output->setRDFTypeURI(outputEventTypeURI);
|
Chris@558
|
340
|
Chris@441
|
341 } else if (binCount == 1 ||
|
Chris@441
|
342 (m_descriptor->sampleType ==
|
Chris@441
|
343 Vamp::Plugin::OutputDescriptor::VariableSampleRate)) {
|
Chris@441
|
344
|
Chris@441
|
345 // Anything that is not a 1D, note, or interval model and that
|
Chris@441
|
346 // has only one value per result must be a sparse time value
|
Chris@441
|
347 // model.
|
Chris@441
|
348
|
Chris@441
|
349 // Anything that is not a 1D, note, or interval model and that
|
Chris@441
|
350 // has a variable sample rate is also treated as a sparse time
|
Chris@441
|
351 // value model regardless of its bin count, because we lack a
|
Chris@441
|
352 // sparse 3D model.
|
Chris@320
|
353
|
Chris@320
|
354 SparseTimeValueModel *model;
|
Chris@320
|
355 if (haveExtents) {
|
Chris@320
|
356 model = new SparseTimeValueModel
|
Chris@320
|
357 (modelRate, modelResolution, minValue, maxValue, false);
|
Chris@320
|
358 } else {
|
Chris@320
|
359 model = new SparseTimeValueModel
|
Chris@320
|
360 (modelRate, modelResolution, false);
|
Chris@320
|
361 }
|
Chris@558
|
362
|
Chris@558
|
363 Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors();
|
Chris@778
|
364 model->setScaleUnits(outputs[m_outputNo].unit.c_str());
|
Chris@320
|
365
|
Chris@320
|
366 m_output = model;
|
Chris@320
|
367
|
Chris@558
|
368 QString outputEventTypeURI = description.getOutputEventTypeURI(outputId);
|
Chris@558
|
369 m_output->setRDFTypeURI(outputEventTypeURI);
|
Chris@558
|
370
|
Chris@441
|
371 } else {
|
Chris@320
|
372
|
Chris@441
|
373 // Anything that is not a 1D, note, or interval model and that
|
Chris@441
|
374 // has a fixed sample rate and more than one value per result
|
Chris@441
|
375 // must be a dense 3D model.
|
Chris@320
|
376
|
Chris@320
|
377 EditableDenseThreeDimensionalModel *model =
|
Chris@320
|
378 new EditableDenseThreeDimensionalModel
|
Chris@535
|
379 (modelRate, modelResolution, binCount,
|
Chris@535
|
380 EditableDenseThreeDimensionalModel::BasicMultirateCompression,
|
Chris@535
|
381 false);
|
Chris@320
|
382
|
Chris@320
|
383 if (!m_descriptor->binNames.empty()) {
|
Chris@320
|
384 std::vector<QString> names;
|
Chris@320
|
385 for (size_t i = 0; i < m_descriptor->binNames.size(); ++i) {
|
Chris@320
|
386 names.push_back(m_descriptor->binNames[i].c_str());
|
Chris@320
|
387 }
|
Chris@320
|
388 model->setBinNames(names);
|
Chris@320
|
389 }
|
Chris@320
|
390
|
Chris@320
|
391 m_output = model;
|
Chris@558
|
392
|
Chris@558
|
393 QString outputSignalTypeURI = description.getOutputSignalTypeURI(outputId);
|
Chris@558
|
394 m_output->setRDFTypeURI(outputSignalTypeURI);
|
Chris@320
|
395 }
|
Chris@333
|
396
|
Chris@350
|
397 if (m_output) m_output->setSourceModel(input);
|
Chris@320
|
398 }
|
Chris@320
|
399
|
Chris@331
|
400 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()
|
Chris@320
|
401 {
|
Chris@690
|
402 // SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl;
|
Chris@320
|
403 delete m_plugin;
|
Chris@320
|
404 delete m_descriptor;
|
Chris@320
|
405 }
|
Chris@320
|
406
|
Chris@320
|
407 DenseTimeValueModel *
|
Chris@350
|
408 FeatureExtractionModelTransformer::getConformingInput()
|
Chris@320
|
409 {
|
Chris@690
|
410 // SVDEBUG << "FeatureExtractionModelTransformer::getConformingInput: input model is " << getInputModel() << endl;
|
Chris@408
|
411
|
Chris@320
|
412 DenseTimeValueModel *dtvm =
|
Chris@320
|
413 dynamic_cast<DenseTimeValueModel *>(getInputModel());
|
Chris@320
|
414 if (!dtvm) {
|
Chris@690
|
415 SVDEBUG << "FeatureExtractionModelTransformer::getConformingInput: WARNING: Input model is not conformable to DenseTimeValueModel" << endl;
|
Chris@320
|
416 }
|
Chris@320
|
417 return dtvm;
|
Chris@320
|
418 }
|
Chris@320
|
419
|
Chris@320
|
420 void
|
Chris@331
|
421 FeatureExtractionModelTransformer::run()
|
Chris@320
|
422 {
|
Chris@350
|
423 DenseTimeValueModel *input = getConformingInput();
|
Chris@320
|
424 if (!input) return;
|
Chris@320
|
425
|
Chris@320
|
426 if (!m_output) return;
|
Chris@320
|
427
|
Chris@497
|
428 while (!input->isReady() && !m_abandoned) {
|
Chris@690
|
429 SVDEBUG << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl;
|
Chris@497
|
430 usleep(500000);
|
Chris@320
|
431 }
|
Chris@497
|
432 if (m_abandoned) return;
|
Chris@320
|
433
|
Chris@350
|
434 size_t sampleRate = input->getSampleRate();
|
Chris@320
|
435
|
Chris@320
|
436 size_t channelCount = input->getChannelCount();
|
Chris@320
|
437 if (m_plugin->getMaxChannelCount() < channelCount) {
|
Chris@320
|
438 channelCount = 1;
|
Chris@320
|
439 }
|
Chris@320
|
440
|
Chris@320
|
441 float **buffers = new float*[channelCount];
|
Chris@320
|
442 for (size_t ch = 0; ch < channelCount; ++ch) {
|
Chris@350
|
443 buffers[ch] = new float[m_transform.getBlockSize() + 2];
|
Chris@320
|
444 }
|
Chris@320
|
445
|
Chris@350
|
446 size_t stepSize = m_transform.getStepSize();
|
Chris@350
|
447 size_t blockSize = m_transform.getBlockSize();
|
Chris@350
|
448
|
Chris@320
|
449 bool frequencyDomain = (m_plugin->getInputDomain() ==
|
Chris@320
|
450 Vamp::Plugin::FrequencyDomain);
|
Chris@320
|
451 std::vector<FFTModel *> fftModels;
|
Chris@320
|
452
|
Chris@320
|
453 if (frequencyDomain) {
|
Chris@320
|
454 for (size_t ch = 0; ch < channelCount; ++ch) {
|
Chris@320
|
455 FFTModel *model = new FFTModel
|
Chris@350
|
456 (getConformingInput(),
|
Chris@350
|
457 channelCount == 1 ? m_input.getChannel() : ch,
|
Chris@350
|
458 m_transform.getWindowType(),
|
Chris@350
|
459 blockSize,
|
Chris@350
|
460 stepSize,
|
Chris@350
|
461 blockSize,
|
Chris@334
|
462 false,
|
Chris@334
|
463 StorageAdviser::PrecisionCritical);
|
Chris@320
|
464 if (!model->isOK()) {
|
Chris@320
|
465 delete model;
|
Chris@320
|
466 setCompletion(100);
|
Chris@387
|
467 //!!! need a better way to handle this -- previously we were using a QMessageBox but that isn't an appropriate thing to do here either
|
Chris@387
|
468 throw AllocationFailed("Failed to create the FFT model for this feature extraction model transformer");
|
Chris@320
|
469 }
|
Chris@320
|
470 model->resume();
|
Chris@320
|
471 fftModels.push_back(model);
|
Chris@320
|
472 }
|
Chris@320
|
473 }
|
Chris@320
|
474
|
Chris@350
|
475 long startFrame = m_input.getModel()->getStartFrame();
|
Chris@350
|
476 long endFrame = m_input.getModel()->getEndFrame();
|
Chris@320
|
477
|
Chris@350
|
478 RealTime contextStartRT = m_transform.getStartTime();
|
Chris@350
|
479 RealTime contextDurationRT = m_transform.getDuration();
|
Chris@350
|
480
|
Chris@350
|
481 long contextStart =
|
Chris@350
|
482 RealTime::realTime2Frame(contextStartRT, sampleRate);
|
Chris@350
|
483
|
Chris@350
|
484 long contextDuration =
|
Chris@350
|
485 RealTime::realTime2Frame(contextDurationRT, sampleRate);
|
Chris@320
|
486
|
Chris@320
|
487 if (contextStart == 0 || contextStart < startFrame) {
|
Chris@320
|
488 contextStart = startFrame;
|
Chris@320
|
489 }
|
Chris@320
|
490
|
Chris@320
|
491 if (contextDuration == 0) {
|
Chris@320
|
492 contextDuration = endFrame - contextStart;
|
Chris@320
|
493 }
|
Chris@320
|
494 if (contextStart + contextDuration > endFrame) {
|
Chris@320
|
495 contextDuration = endFrame - contextStart;
|
Chris@320
|
496 }
|
Chris@320
|
497
|
Chris@320
|
498 long blockFrame = contextStart;
|
Chris@320
|
499
|
Chris@320
|
500 long prevCompletion = 0;
|
Chris@320
|
501
|
Chris@320
|
502 setCompletion(0);
|
Chris@320
|
503
|
Chris@556
|
504 float *reals = 0;
|
Chris@556
|
505 float *imaginaries = 0;
|
Chris@556
|
506 if (frequencyDomain) {
|
Chris@556
|
507 reals = new float[blockSize/2 + 1];
|
Chris@556
|
508 imaginaries = new float[blockSize/2 + 1];
|
Chris@556
|
509 }
|
Chris@556
|
510
|
Chris@678
|
511 QString error = "";
|
Chris@678
|
512
|
Chris@320
|
513 while (!m_abandoned) {
|
Chris@320
|
514
|
Chris@320
|
515 if (frequencyDomain) {
|
Chris@350
|
516 if (blockFrame - int(blockSize)/2 >
|
Chris@320
|
517 contextStart + contextDuration) break;
|
Chris@320
|
518 } else {
|
Chris@320
|
519 if (blockFrame >=
|
Chris@320
|
520 contextStart + contextDuration) break;
|
Chris@320
|
521 }
|
Chris@320
|
522
|
Chris@690
|
523 // SVDEBUG << "FeatureExtractionModelTransformer::run: blockFrame "
|
Chris@320
|
524 // << blockFrame << ", endFrame " << endFrame << ", blockSize "
|
Chris@687
|
525 // << blockSize << endl;
|
Chris@320
|
526
|
Chris@320
|
527 long completion =
|
Chris@350
|
528 (((blockFrame - contextStart) / stepSize) * 99) /
|
Chris@557
|
529 (contextDuration / stepSize + 1);
|
Chris@320
|
530
|
Chris@350
|
531 // channelCount is either m_input.getModel()->channelCount or 1
|
Chris@320
|
532
|
Chris@363
|
533 if (frequencyDomain) {
|
Chris@363
|
534 for (size_t ch = 0; ch < channelCount; ++ch) {
|
Chris@350
|
535 int column = (blockFrame - startFrame) / stepSize;
|
Chris@556
|
536 fftModels[ch]->getValuesAt(column, reals, imaginaries);
|
Chris@350
|
537 for (size_t i = 0; i <= blockSize/2; ++i) {
|
Chris@556
|
538 buffers[ch][i*2] = reals[i];
|
Chris@556
|
539 buffers[ch][i*2+1] = imaginaries[i];
|
Chris@320
|
540 }
|
Chris@678
|
541 error = fftModels[ch]->getError();
|
Chris@678
|
542 if (error != "") {
|
Chris@686
|
543 std::cerr << "FeatureExtractionModelTransformer::run: Abandoning, error is " << error << std::endl;
|
Chris@678
|
544 m_abandoned = true;
|
Chris@678
|
545 m_message = error;
|
Chris@678
|
546 }
|
Chris@363
|
547 }
|
Chris@363
|
548 } else {
|
Chris@363
|
549 getFrames(channelCount, blockFrame, blockSize, buffers);
|
Chris@320
|
550 }
|
Chris@320
|
551
|
Chris@497
|
552 if (m_abandoned) break;
|
Chris@497
|
553
|
Chris@320
|
554 Vamp::Plugin::FeatureSet features = m_plugin->process
|
Chris@320
|
555 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate));
|
Chris@320
|
556
|
Chris@497
|
557 if (m_abandoned) break;
|
Chris@497
|
558
|
Chris@778
|
559 for (size_t fi = 0; fi < features[m_outputNo].size(); ++fi) {
|
Chris@778
|
560 Vamp::Plugin::Feature feature = features[m_outputNo][fi];
|
Chris@320
|
561 addFeature(blockFrame, feature);
|
Chris@320
|
562 }
|
Chris@320
|
563
|
Chris@320
|
564 if (blockFrame == contextStart || completion > prevCompletion) {
|
Chris@320
|
565 setCompletion(completion);
|
Chris@320
|
566 prevCompletion = completion;
|
Chris@320
|
567 }
|
Chris@320
|
568
|
Chris@350
|
569 blockFrame += stepSize;
|
Chris@320
|
570 }
|
Chris@320
|
571
|
Chris@497
|
572 if (!m_abandoned) {
|
Chris@497
|
573 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures();
|
Chris@320
|
574
|
Chris@778
|
575 for (size_t fi = 0; fi < features[m_outputNo].size(); ++fi) {
|
Chris@778
|
576 Vamp::Plugin::Feature feature = features[m_outputNo][fi];
|
Chris@497
|
577 addFeature(blockFrame, feature);
|
Chris@497
|
578 }
|
Chris@497
|
579 }
|
Chris@320
|
580
|
Chris@497
|
581 setCompletion(100);
|
Chris@320
|
582
|
Chris@320
|
583 if (frequencyDomain) {
|
Chris@320
|
584 for (size_t ch = 0; ch < channelCount; ++ch) {
|
Chris@320
|
585 delete fftModels[ch];
|
Chris@320
|
586 }
|
Chris@556
|
587 delete[] reals;
|
Chris@556
|
588 delete[] imaginaries;
|
Chris@320
|
589 }
|
Chris@320
|
590 }
|
Chris@320
|
591
|
Chris@320
|
592 void
|
Chris@363
|
593 FeatureExtractionModelTransformer::getFrames(int channelCount,
|
Chris@363
|
594 long startFrame, long size,
|
Chris@363
|
595 float **buffers)
|
Chris@320
|
596 {
|
Chris@320
|
597 long offset = 0;
|
Chris@320
|
598
|
Chris@320
|
599 if (startFrame < 0) {
|
Chris@363
|
600 for (int c = 0; c < channelCount; ++c) {
|
Chris@363
|
601 for (int i = 0; i < size && startFrame + i < 0; ++i) {
|
Chris@363
|
602 buffers[c][i] = 0.0f;
|
Chris@363
|
603 }
|
Chris@320
|
604 }
|
Chris@320
|
605 offset = -startFrame;
|
Chris@320
|
606 size -= offset;
|
Chris@320
|
607 if (size <= 0) return;
|
Chris@320
|
608 startFrame = 0;
|
Chris@320
|
609 }
|
Chris@320
|
610
|
Chris@350
|
611 DenseTimeValueModel *input = getConformingInput();
|
Chris@350
|
612 if (!input) return;
|
Chris@363
|
613
|
Chris@363
|
614 long got = 0;
|
Chris@350
|
615
|
Chris@363
|
616 if (channelCount == 1) {
|
Chris@363
|
617
|
Chris@363
|
618 got = input->getData(m_input.getChannel(), startFrame, size,
|
Chris@363
|
619 buffers[0] + offset);
|
Chris@363
|
620
|
Chris@363
|
621 if (m_input.getChannel() == -1 && input->getChannelCount() > 1) {
|
Chris@363
|
622 // use mean instead of sum, as plugin input
|
Chris@363
|
623 float cc = float(input->getChannelCount());
|
Chris@363
|
624 for (long i = 0; i < size; ++i) {
|
Chris@363
|
625 buffers[0][i + offset] /= cc;
|
Chris@363
|
626 }
|
Chris@363
|
627 }
|
Chris@363
|
628
|
Chris@363
|
629 } else {
|
Chris@363
|
630
|
Chris@363
|
631 float **writebuf = buffers;
|
Chris@363
|
632 if (offset > 0) {
|
Chris@363
|
633 writebuf = new float *[channelCount];
|
Chris@363
|
634 for (int i = 0; i < channelCount; ++i) {
|
Chris@363
|
635 writebuf[i] = buffers[i] + offset;
|
Chris@363
|
636 }
|
Chris@363
|
637 }
|
Chris@363
|
638
|
Chris@363
|
639 got = input->getData(0, channelCount-1, startFrame, size, writebuf);
|
Chris@363
|
640
|
Chris@363
|
641 if (writebuf != buffers) delete[] writebuf;
|
Chris@363
|
642 }
|
Chris@320
|
643
|
Chris@320
|
644 while (got < size) {
|
Chris@363
|
645 for (int c = 0; c < channelCount; ++c) {
|
Chris@363
|
646 buffers[c][got + offset] = 0.0;
|
Chris@363
|
647 }
|
Chris@320
|
648 ++got;
|
Chris@320
|
649 }
|
Chris@320
|
650 }
|
Chris@320
|
651
|
Chris@320
|
652 void
|
Chris@331
|
653 FeatureExtractionModelTransformer::addFeature(size_t blockFrame,
|
Chris@320
|
654 const Vamp::Plugin::Feature &feature)
|
Chris@320
|
655 {
|
Chris@350
|
656 size_t inputRate = m_input.getModel()->getSampleRate();
|
Chris@320
|
657
|
Chris@712
|
658 // std::cerr << "FeatureExtractionModelTransformer::addFeature: blockFrame = "
|
Chris@712
|
659 // << blockFrame << ", hasTimestamp = " << feature.hasTimestamp
|
Chris@712
|
660 // << ", timestamp = " << feature.timestamp << ", hasDuration = "
|
Chris@712
|
661 // << feature.hasDuration << ", duration = " << feature.duration
|
Chris@712
|
662 // << std::endl;
|
Chris@320
|
663
|
Chris@320
|
664 int binCount = 1;
|
Chris@320
|
665 if (m_descriptor->hasFixedBinCount) {
|
Chris@320
|
666 binCount = m_descriptor->binCount;
|
Chris@320
|
667 }
|
Chris@320
|
668
|
Chris@320
|
669 size_t frame = blockFrame;
|
Chris@320
|
670
|
Chris@320
|
671 if (m_descriptor->sampleType ==
|
Chris@320
|
672 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
|
Chris@320
|
673
|
Chris@320
|
674 if (!feature.hasTimestamp) {
|
Chris@320
|
675 std::cerr
|
Chris@331
|
676 << "WARNING: FeatureExtractionModelTransformer::addFeature: "
|
Chris@320
|
677 << "Feature has variable sample rate but no timestamp!"
|
Chris@320
|
678 << std::endl;
|
Chris@320
|
679 return;
|
Chris@320
|
680 } else {
|
Chris@320
|
681 frame = Vamp::RealTime::realTime2Frame(feature.timestamp, inputRate);
|
Chris@320
|
682 }
|
Chris@320
|
683
|
Chris@320
|
684 } else if (m_descriptor->sampleType ==
|
Chris@320
|
685 Vamp::Plugin::OutputDescriptor::FixedSampleRate) {
|
Chris@320
|
686
|
Chris@779
|
687 if (!feature.hasTimestamp) {
|
Chris@779
|
688 ++m_fixedRateFeatureNo;
|
Chris@779
|
689 } else {
|
Chris@779
|
690 RealTime ts(feature.timestamp.sec, feature.timestamp.nsec);
|
Chris@779
|
691 m_fixedRateFeatureNo =
|
Chris@779
|
692 lrint(ts.toDouble() * m_descriptor->sampleRate);
|
Chris@779
|
693 }
|
Chris@779
|
694
|
Chris@779
|
695 frame = lrintf((m_fixedRateFeatureNo / m_descriptor->sampleRate)
|
Chris@779
|
696 * inputRate);
|
Chris@320
|
697 }
|
Chris@320
|
698
|
Chris@441
|
699 // Rather than repeat the complicated tests from the constructor
|
Chris@441
|
700 // to determine what sort of model we must be adding the features
|
Chris@441
|
701 // to, we instead test what sort of model the constructor decided
|
Chris@441
|
702 // to create.
|
Chris@320
|
703
|
Chris@441
|
704 if (isOutput<SparseOneDimensionalModel>()) {
|
Chris@441
|
705
|
Chris@441
|
706 SparseOneDimensionalModel *model =
|
Chris@350
|
707 getConformingOutput<SparseOneDimensionalModel>();
|
Chris@320
|
708 if (!model) return;
|
Chris@350
|
709
|
Chris@441
|
710 model->addPoint(SparseOneDimensionalModel::Point
|
Chris@441
|
711 (frame, feature.label.c_str()));
|
Chris@320
|
712
|
Chris@441
|
713 } else if (isOutput<SparseTimeValueModel>()) {
|
Chris@320
|
714
|
Chris@350
|
715 SparseTimeValueModel *model =
|
Chris@350
|
716 getConformingOutput<SparseTimeValueModel>();
|
Chris@320
|
717 if (!model) return;
|
Chris@350
|
718
|
Chris@454
|
719 for (int i = 0; i < feature.values.size(); ++i) {
|
Chris@454
|
720
|
Chris@454
|
721 float value = feature.values[i];
|
Chris@454
|
722
|
Chris@454
|
723 QString label = feature.label.c_str();
|
Chris@454
|
724 if (feature.values.size() > 1) {
|
Chris@454
|
725 label = QString("[%1] %2").arg(i+1).arg(label);
|
Chris@454
|
726 }
|
Chris@454
|
727
|
Chris@454
|
728 model->addPoint(SparseTimeValueModel::Point(frame, value, label));
|
Chris@454
|
729 }
|
Chris@320
|
730
|
gyorgyf@786
|
731 } else if (isOutput<FlexiNoteModel>() || isOutput<NoteModel>() || isOutput<RegionModel>()) { //GF: Added Note Model
|
Chris@320
|
732
|
Chris@441
|
733 int index = 0;
|
Chris@441
|
734
|
Chris@441
|
735 float value = 0.0;
|
Chris@441
|
736 if (feature.values.size() > index) {
|
Chris@441
|
737 value = feature.values[index++];
|
Chris@441
|
738 }
|
Chris@320
|
739
|
Chris@320
|
740 float duration = 1;
|
Chris@441
|
741 if (feature.hasDuration) {
|
Chris@441
|
742 duration = Vamp::RealTime::realTime2Frame(feature.duration, inputRate);
|
Chris@441
|
743 } else {
|
Chris@441
|
744 if (feature.values.size() > index) {
|
Chris@441
|
745 duration = feature.values[index++];
|
Chris@441
|
746 }
|
Chris@441
|
747 }
|
gyorgyf@786
|
748
|
gyorgyf@786
|
749 if (isOutput<FlexiNoteModel>()) { // GF: added for flexi note model
|
gyorgyf@786
|
750
|
gyorgyf@786
|
751 float velocity = 100;
|
gyorgyf@786
|
752 if (feature.values.size() > index) {
|
gyorgyf@786
|
753 velocity = feature.values[index++];
|
gyorgyf@786
|
754 }
|
gyorgyf@786
|
755 if (velocity < 0) velocity = 127;
|
gyorgyf@786
|
756 if (velocity > 127) velocity = 127;
|
gyorgyf@786
|
757
|
gyorgyf@786
|
758 FlexiNoteModel *model = getConformingOutput<FlexiNoteModel>();
|
gyorgyf@786
|
759 if (!model) return;
|
gyorgyf@786
|
760 model->addPoint(FlexiNoteModel::Point(frame, value, // value is pitch
|
gyorgyf@786
|
761 lrintf(duration),
|
gyorgyf@786
|
762 velocity / 127.f,
|
gyorgyf@786
|
763 feature.label.c_str()));
|
gyorgyf@786
|
764 // GF: end -- added for flexi note model
|
gyorgyf@786
|
765 } else if (isOutput<NoteModel>()) {
|
Chris@320
|
766
|
Chris@441
|
767 float velocity = 100;
|
Chris@441
|
768 if (feature.values.size() > index) {
|
Chris@441
|
769 velocity = feature.values[index++];
|
Chris@441
|
770 }
|
Chris@441
|
771 if (velocity < 0) velocity = 127;
|
Chris@441
|
772 if (velocity > 127) velocity = 127;
|
Chris@320
|
773
|
Chris@441
|
774 NoteModel *model = getConformingOutput<NoteModel>();
|
Chris@441
|
775 if (!model) return;
|
Chris@441
|
776 model->addPoint(NoteModel::Point(frame, value, // value is pitch
|
Chris@441
|
777 lrintf(duration),
|
Chris@441
|
778 velocity / 127.f,
|
Chris@441
|
779 feature.label.c_str()));
|
Chris@441
|
780 } else {
|
gyorgyf@786
|
781
|
Chris@441
|
782 RegionModel *model = getConformingOutput<RegionModel>();
|
Chris@454
|
783 if (!model) return;
|
Chris@454
|
784
|
Chris@474
|
785 if (feature.hasDuration && !feature.values.empty()) {
|
Chris@454
|
786
|
Chris@454
|
787 for (int i = 0; i < feature.values.size(); ++i) {
|
Chris@454
|
788
|
Chris@454
|
789 float value = feature.values[i];
|
Chris@454
|
790
|
Chris@454
|
791 QString label = feature.label.c_str();
|
Chris@454
|
792 if (feature.values.size() > 1) {
|
Chris@454
|
793 label = QString("[%1] %2").arg(i+1).arg(label);
|
Chris@454
|
794 }
|
Chris@454
|
795
|
Chris@454
|
796 model->addPoint(RegionModel::Point(frame, value,
|
Chris@454
|
797 lrintf(duration),
|
Chris@454
|
798 label));
|
Chris@454
|
799 }
|
Chris@454
|
800 } else {
|
Chris@454
|
801
|
Chris@441
|
802 model->addPoint(RegionModel::Point(frame, value,
|
Chris@441
|
803 lrintf(duration),
|
Chris@441
|
804 feature.label.c_str()));
|
Chris@454
|
805 }
|
Chris@441
|
806 }
|
Chris@320
|
807
|
Chris@441
|
808 } else if (isOutput<EditableDenseThreeDimensionalModel>()) {
|
Chris@320
|
809
|
Chris@533
|
810 DenseThreeDimensionalModel::Column values =
|
Chris@533
|
811 DenseThreeDimensionalModel::Column::fromStdVector(feature.values);
|
Chris@320
|
812
|
Chris@320
|
813 EditableDenseThreeDimensionalModel *model =
|
Chris@350
|
814 getConformingOutput<EditableDenseThreeDimensionalModel>();
|
Chris@320
|
815 if (!model) return;
|
Chris@320
|
816
|
Chris@320
|
817 model->setColumn(frame / model->getResolution(), values);
|
Chris@441
|
818
|
Chris@441
|
819 } else {
|
Chris@690
|
820 SVDEBUG << "FeatureExtractionModelTransformer::addFeature: Unknown output model type!" << endl;
|
Chris@320
|
821 }
|
Chris@320
|
822 }
|
Chris@320
|
823
|
Chris@320
|
824 void
|
Chris@331
|
825 FeatureExtractionModelTransformer::setCompletion(int completion)
|
Chris@320
|
826 {
|
Chris@320
|
827 int binCount = 1;
|
Chris@320
|
828 if (m_descriptor->hasFixedBinCount) {
|
Chris@320
|
829 binCount = m_descriptor->binCount;
|
Chris@320
|
830 }
|
Chris@320
|
831
|
Chris@690
|
832 // SVDEBUG << "FeatureExtractionModelTransformer::setCompletion("
|
Chris@687
|
833 // << completion << ")" << endl;
|
Chris@320
|
834
|
Chris@441
|
835 if (isOutput<SparseOneDimensionalModel>()) {
|
Chris@320
|
836
|
Chris@350
|
837 SparseOneDimensionalModel *model =
|
Chris@350
|
838 getConformingOutput<SparseOneDimensionalModel>();
|
Chris@320
|
839 if (!model) return;
|
Chris@441
|
840 model->setCompletion(completion, true);
|
Chris@320
|
841
|
Chris@441
|
842 } else if (isOutput<SparseTimeValueModel>()) {
|
Chris@320
|
843
|
Chris@350
|
844 SparseTimeValueModel *model =
|
Chris@350
|
845 getConformingOutput<SparseTimeValueModel>();
|
Chris@320
|
846 if (!model) return;
|
Chris@441
|
847 model->setCompletion(completion, true);
|
Chris@320
|
848
|
Chris@441
|
849 } else if (isOutput<NoteModel>()) {
|
Chris@320
|
850
|
Chris@441
|
851 NoteModel *model = getConformingOutput<NoteModel>();
|
Chris@320
|
852 if (!model) return;
|
Chris@441
|
853 model->setCompletion(completion, true);
|
gyorgyf@786
|
854
|
gyorgyf@786
|
855 } else if (isOutput<FlexiNoteModel>()) {
|
gyorgyf@786
|
856
|
gyorgyf@786
|
857 FlexiNoteModel *model = getConformingOutput<FlexiNoteModel>();
|
gyorgyf@786
|
858 if (!model) return;
|
gyorgyf@786
|
859 model->setCompletion(completion, true);
|
Chris@320
|
860
|
Chris@441
|
861 } else if (isOutput<RegionModel>()) {
|
Chris@441
|
862
|
Chris@441
|
863 RegionModel *model = getConformingOutput<RegionModel>();
|
Chris@441
|
864 if (!model) return;
|
Chris@441
|
865 model->setCompletion(completion, true);
|
Chris@441
|
866
|
Chris@441
|
867 } else if (isOutput<EditableDenseThreeDimensionalModel>()) {
|
Chris@320
|
868
|
Chris@320
|
869 EditableDenseThreeDimensionalModel *model =
|
Chris@350
|
870 getConformingOutput<EditableDenseThreeDimensionalModel>();
|
Chris@320
|
871 if (!model) return;
|
Chris@350
|
872 model->setCompletion(completion, true); //!!!m_context.updates);
|
Chris@320
|
873 }
|
Chris@320
|
874 }
|
Chris@320
|
875
|