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