Mercurial > hg > vamp-test-plugin
comparison VampTestPlugin.cpp @ 5:d83566810b96
Add notes-or-regions output
author | Chris Cannam |
---|---|
date | Tue, 26 Mar 2013 17:08:39 +0000 |
parents | 6ece30ceb931 |
children | 9b4ce965db35 |
comparison
equal
deleted
inserted
replaced
4:6ece30ceb931 | 5:d83566810b96 |
---|---|
212 d.sampleType = OutputDescriptor::FixedSampleRate; | 212 d.sampleType = OutputDescriptor::FixedSampleRate; |
213 d.sampleRate = 2; | 213 d.sampleRate = 2; |
214 d.hasDuration = false; | 214 d.hasDuration = false; |
215 list.push_back(d); | 215 list.push_back(d); |
216 | 216 |
217 // 6 -> notes | |
218 d.identifier = "notes-regions"; | |
219 d.name = "Notes or Regions"; | |
220 d.description = "Variably-spaced features with one value and duration"; | |
221 d.unit = ""; | |
222 d.hasFixedBinCount = true; | |
223 d.binCount = 1; | |
224 d.hasKnownExtents = false; | |
225 d.isQuantized = false; | |
226 d.sampleType = OutputDescriptor::VariableSampleRate; | |
227 d.sampleRate = 0; | |
228 d.hasDuration = true; | |
229 list.push_back(d); | |
217 | 230 |
218 return list; | 231 return list; |
219 } | 232 } |
220 | 233 |
221 bool | 234 bool |
292 s << i+1 << " of " << n << " at " << r.toText(); | 305 s << i+1 << " of " << n << " at " << r.toText(); |
293 f.label = s.str(); | 306 f.label = s.str(); |
294 return f; | 307 return f; |
295 } | 308 } |
296 | 309 |
297 VampTestPlugin::FeatureSet | 310 static Vamp::Plugin::Feature |
298 VampTestPlugin::process(const float *const *inputBuffers, RealTime timestamp) | 311 noteOrRegion(RealTime r, RealTime d, int i, int n) |
312 { | |
313 std::stringstream s; | |
314 Vamp::Plugin::Feature f; | |
315 f.hasTimestamp = true; | |
316 f.timestamp = r; | |
317 f.hasDuration = true; | |
318 f.duration = d; | |
319 float v = float(i) / float(n); | |
320 f.values.push_back(v); | |
321 s << i+1 << " of " << n << ": " << v << " at " << r.toText() << " dur. " << d.toText(); | |
322 f.label = s.str(); | |
323 return f; | |
324 } | |
325 | |
326 Vamp::Plugin::FeatureSet | |
327 VampTestPlugin::featuresFrom(RealTime timestamp, bool final) | |
299 { | 328 { |
300 FeatureSet fs; | 329 FeatureSet fs; |
301 | 330 |
302 RealTime endTime = timestamp + RealTime::frame2RealTime | 331 RealTime endTime = timestamp + RealTime::frame2RealTime |
303 (m_stepSize, m_inputSampleRate); | 332 (m_stepSize, m_inputSampleRate); |
304 | 333 |
305 for (int i = 0; i < (int)m_instants.size(); ++i) { | 334 for (int i = 0; i < (int)m_instants.size(); ++i) { |
306 if (m_instants[i] >= timestamp && m_instants[i] < endTime) { | 335 |
336 if (m_instants[i] >= timestamp && (final || m_instants[i] < endTime)) { | |
307 // instants output | 337 // instants output |
308 fs[0].push_back(instant(m_instants[i], i, m_instants.size())); | 338 fs[0].push_back(instant(m_instants[i], i, m_instants.size())); |
309 } | 339 } |
310 | 340 |
311 RealTime variCurveTime = m_instants[i] / 2; | 341 RealTime variCurveTime = m_instants[i] / 2; |
312 if (variCurveTime >= timestamp && variCurveTime < endTime) { | 342 if (variCurveTime >= timestamp && (final || variCurveTime < endTime)) { |
313 // curve-vsr output | 343 // curve-vsr output |
314 fs[3].push_back(timedCurveValue(variCurveTime, i, m_instants.size())); | 344 fs[3].push_back(timedCurveValue(variCurveTime, i, m_instants.size())); |
315 } | 345 } |
346 | |
347 RealTime noteTime = (m_instants[i] + m_instants[i]) / 3; | |
348 RealTime noteDuration = RealTime::fromSeconds((i % 2 == 0) ? 1.75 : 0.5); | |
349 | |
350 if (noteTime >= timestamp && (final || noteTime < endTime)) { | |
351 // notes-regions output | |
352 fs[6].push_back(noteOrRegion(noteTime, noteDuration, i, m_instants.size())); | |
353 } | |
316 } | 354 } |
317 | 355 |
318 if (m_n < 20) { | 356 if (!final) { |
319 // curve-oss output | 357 |
320 fs[1].push_back(untimedCurveValue(timestamp, m_n, 20)); | 358 if (m_n < 20) { |
321 } | 359 // curve-oss output |
322 | 360 fs[1].push_back(untimedCurveValue(timestamp, m_n, 20)); |
323 if (m_n < 5) { | 361 } |
324 // curve-fsr output | 362 |
325 fs[2].push_back(untimedCurveValue(RealTime::fromSeconds(m_n / 2.0), m_n, 10)); | 363 if (m_n < 5) { |
326 } | 364 // curve-fsr output |
327 | 365 fs[2].push_back(untimedCurveValue(RealTime::fromSeconds(m_n / 2.0), m_n, 10)); |
328 if (m_n < 20) { | 366 } |
329 // grid-oss output | 367 |
330 fs[4].push_back(gridColumn(timestamp, m_n, 20)); | 368 if (m_n < 20) { |
369 // grid-oss output | |
370 fs[4].push_back(gridColumn(timestamp, m_n, 20)); | |
371 } | |
372 | |
373 } else { | |
374 | |
375 for (int i = (m_n > 5 ? 5 : m_n); i < 10; ++i) { | |
376 // curve-fsr output | |
377 fs[2].push_back(untimedCurveValue(RealTime::fromSeconds(i / 2.0), i, 10)); | |
378 } | |
379 | |
380 for (int i = (m_n > 5 ? 5 : m_n); i < 10; ++i) { | |
381 // grid-fsr output | |
382 fs[5].push_back(gridColumn(RealTime::fromSeconds(i / 2.0), i, 10)); | |
383 } | |
331 } | 384 } |
332 | 385 |
333 m_lastTime = endTime; | 386 m_lastTime = endTime; |
334 m_n = m_n + 1; | 387 m_n = m_n + 1; |
335 return fs; | 388 return fs; |
389 } | |
390 | |
391 VampTestPlugin::FeatureSet | |
392 VampTestPlugin::process(const float *const *inputBuffers, RealTime timestamp) | |
393 { | |
394 FeatureSet fs = featuresFrom(timestamp, false); | |
395 return fs; | |
336 } | 396 } |
337 | 397 |
338 VampTestPlugin::FeatureSet | 398 VampTestPlugin::FeatureSet |
339 VampTestPlugin::getRemainingFeatures() | 399 VampTestPlugin::getRemainingFeatures() |
340 { | 400 { |
341 FeatureSet fs; | 401 FeatureSet fs = featuresFrom(m_lastTime, true); |
342 | |
343 for (int i = 0; i < (int)m_instants.size(); ++i) { | |
344 if (m_instants[i] >= m_lastTime) { | |
345 // instants output | |
346 fs[0].push_back(instant(m_instants[i], i, m_instants.size())); | |
347 } | |
348 | |
349 RealTime variCurveTime = m_instants[i] / 2; | |
350 if (variCurveTime >= m_lastTime) { | |
351 // curve-vsr output | |
352 fs[3].push_back(timedCurveValue(m_instants[i], i, m_instants.size())); | |
353 } | |
354 } | |
355 | |
356 for (int i = (m_n > 5 ? 5 : m_n); i < 10; ++i) { | |
357 // curve-fsr output | |
358 fs[2].push_back(untimedCurveValue(RealTime::fromSeconds(i / 2.0), i, 10)); | |
359 } | |
360 | |
361 for (int i = (m_n > 5 ? 5 : m_n); i < 10; ++i) { | |
362 // grid-fsr output | |
363 fs[5].push_back(gridColumn(RealTime::fromSeconds(i / 2.0), i, 10)); | |
364 } | |
365 | |
366 return fs; | 402 return fs; |
367 } | 403 } |
368 | 404 |