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