comparison plugin/LADSPAPluginInstance.cpp @ 1057:5c5d4863b428 tonioni

Merge from cxx11 branch
author Chris Cannam
date Mon, 23 Mar 2015 11:26:28 +0000
parents a1cd5abcb38b
children 48e9f538e6e9
comparison
equal deleted inserted replaced
1056:c4898e57eea5 1057:5c5d4863b428
35 35
36 LADSPAPluginInstance::LADSPAPluginInstance(RealTimePluginFactory *factory, 36 LADSPAPluginInstance::LADSPAPluginInstance(RealTimePluginFactory *factory,
37 int clientId, 37 int clientId,
38 QString identifier, 38 QString identifier,
39 int position, 39 int position,
40 unsigned long sampleRate, 40 sv_samplerate_t sampleRate,
41 size_t blockSize, 41 int blockSize,
42 int idealChannelCount, 42 int idealChannelCount,
43 const LADSPA_Descriptor* descriptor) : 43 const LADSPA_Descriptor* descriptor) :
44 RealTimePluginInstance(factory, identifier), 44 RealTimePluginInstance(factory, identifier),
45 m_client(clientId), 45 m_client(clientId),
46 m_position(position), 46 m_position(position),
154 lrdf_get_scale_values(m_descriptor->UniqueID, pn); 154 lrdf_get_scale_values(m_descriptor->UniqueID, pn);
155 155
156 if (defaults) { 156 if (defaults) {
157 if (defaults->count > 0) { 157 if (defaults->count > 0) {
158 std::map<int, std::string> values; 158 std::map<int, std::string> values;
159 size_t v = 0; 159 int v = 0;
160 for (size_t i = 0; i < defaults->count; ++i) { 160 for (size_t i = 0; i < defaults->count; ++i) {
161 v = size_t(lrintf(fabsf(defaults->items[i].value))); 161 v = int(lrintf(fabsf(defaults->items[i].value)));
162 values[v] = defaults->items[i].label; 162 values[v] = defaults->items[i].label;
163 } 163 }
164 for (size_t i = 0; i <= v; ++i) { 164 for (int i = 0; i <= v; ++i) {
165 pd.valueNames.push_back(values[i]); 165 pd.valueNames.push_back(values[i]);
166 } 166 }
167 haveLabels = true; 167 haveLabels = true;
168 } 168 }
169 lrdf_free_setting_values(defaults); 169 lrdf_free_setting_values(defaults);
225 << m_descriptor->PortCount << " ports" << endl; 225 << m_descriptor->PortCount << " ports" << endl;
226 #endif 226 #endif
227 227
228 // Discover ports numbers and identities 228 // Discover ports numbers and identities
229 // 229 //
230 for (unsigned long i = 0; i < m_descriptor->PortCount; ++i) { 230 for (int i = 0; i < (int)m_descriptor->PortCount; ++i) {
231 231
232 if (LADSPA_IS_PORT_AUDIO(m_descriptor->PortDescriptors[i])) { 232 if (LADSPA_IS_PORT_AUDIO(m_descriptor->PortDescriptors[i])) {
233 233
234 if (LADSPA_IS_PORT_INPUT(m_descriptor->PortDescriptors[i])) { 234 if (LADSPA_IS_PORT_INPUT(m_descriptor->PortDescriptors[i])) {
235 #ifdef DEBUG_LADSPA 235 #ifdef DEBUG_LADSPA
287 m_instanceCount = idealChannelCount; 287 m_instanceCount = idealChannelCount;
288 } 288 }
289 } 289 }
290 } 290 }
291 291
292 size_t 292 sv_frame_t
293 LADSPAPluginInstance::getLatency() 293 LADSPAPluginInstance::getLatency()
294 { 294 {
295 if (m_latencyPort) { 295 if (m_latencyPort) {
296 if (!m_run) { 296 if (!m_run) {
297 for (size_t i = 0; i < getAudioInputCount(); ++i) { 297 for (int i = 0; i < getAudioInputCount(); ++i) {
298 for (size_t j = 0; j < m_blockSize; ++j) { 298 for (int j = 0; j < m_blockSize; ++j) {
299 m_inputBuffers[i][j] = 0.f; 299 m_inputBuffers[i][j] = 0.f;
300 } 300 }
301 } 301 }
302 run(Vamp::RealTime::zeroTime); 302 run(Vamp::RealTime::zeroTime);
303 } 303 }
304 if (*m_latencyPort > 0) return (size_t)*m_latencyPort; 304 if (*m_latencyPort > 0) return (sv_frame_t)*m_latencyPort;
305 } 305 }
306 return 0; 306 return 0;
307 } 307 }
308 308
309 void 309 void
314 activate(); 314 activate();
315 } 315 }
316 } 316 }
317 317
318 void 318 void
319 LADSPAPluginInstance::setIdealChannelCount(size_t channels) 319 LADSPAPluginInstance::setIdealChannelCount(int channels)
320 { 320 {
321 if (m_audioPortsIn.size() != 1 || channels == m_instanceCount) { 321 if (m_audioPortsIn.size() != 1 || channels == m_instanceCount) {
322 silence(); 322 silence();
323 return; 323 return;
324 } 324 }
376 m_audioPortsOut.clear(); 376 m_audioPortsOut.clear();
377 } 377 }
378 378
379 379
380 void 380 void
381 LADSPAPluginInstance::instantiate(unsigned long sampleRate) 381 LADSPAPluginInstance::instantiate(sv_samplerate_t sampleRate)
382 { 382 {
383 if (!m_descriptor) return; 383 if (!m_descriptor) return;
384 384
385 #ifdef DEBUG_LADSPA 385 #ifdef DEBUG_LADSPA
386 cout << "LADSPAPluginInstance::instantiate - plugin unique id = " 386 cout << "LADSPAPluginInstance::instantiate - plugin unique id = "
392 << ":" << m_descriptor->Label 392 << ":" << m_descriptor->Label
393 << " has no instantiate method!" << endl; 393 << " has no instantiate method!" << endl;
394 return; 394 return;
395 } 395 }
396 396
397 for (size_t i = 0; i < m_instanceCount; ++i) { 397 unsigned long pluginRate = (unsigned long)(sampleRate);
398 if (sampleRate != sv_samplerate_t(pluginRate)) {
399 cerr << "LADSPAPluginInstance: WARNING: Non-integer sample rate "
400 << sampleRate << " presented, rounding to " << pluginRate
401 << endl;
402 }
403
404 for (int i = 0; i < m_instanceCount; ++i) {
398 m_instanceHandles.push_back 405 m_instanceHandles.push_back
399 (m_descriptor->instantiate(m_descriptor, sampleRate)); 406 (m_descriptor->instantiate(m_descriptor, pluginRate));
400 } 407 }
401 } 408 }
402 409
403 void 410 void
404 LADSPAPluginInstance::activate() 411 LADSPAPluginInstance::activate()
462 m_controlPortsOut[i].second); 469 m_controlPortsOut[i].second);
463 } 470 }
464 } 471 }
465 } 472 }
466 473
467 unsigned int 474 int
468 LADSPAPluginInstance::getParameterCount() const 475 LADSPAPluginInstance::getParameterCount() const
469 { 476 {
470 return m_controlPortsIn.size(); 477 return (int)m_controlPortsIn.size();
471 } 478 }
472 479
473 void 480 void
474 LADSPAPluginInstance::setParameterValue(unsigned int parameter, float value) 481 LADSPAPluginInstance::setParameterValue(int parameter, float value)
475 { 482 {
476 if (parameter >= m_controlPortsIn.size()) return; 483 if (!in_range_for(m_controlPortsIn, parameter)) return;
477 484
478 unsigned int portNumber = m_controlPortsIn[parameter].first; 485 unsigned int portNumber = m_controlPortsIn[parameter].first;
479 486
480 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); 487 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
481 if (f) { 488 if (f) {
489 496
490 (*m_controlPortsIn[parameter].second) = value; 497 (*m_controlPortsIn[parameter].second) = value;
491 } 498 }
492 499
493 float 500 float
494 LADSPAPluginInstance::getControlOutputValue(size_t output) const 501 LADSPAPluginInstance::getControlOutputValue(int output) const
495 { 502 {
496 if (output > m_controlPortsOut.size()) return 0.0; 503 if (!in_range_for(m_controlPortsOut, output)) return 0.0;
497 return (*m_controlPortsOut[output].second); 504 return (*m_controlPortsOut[output].second);
498 } 505 }
499 506
500 float 507 float
501 LADSPAPluginInstance::getParameterValue(unsigned int parameter) const 508 LADSPAPluginInstance::getParameterValue(int parameter) const
502 { 509 {
503 if (parameter >= m_controlPortsIn.size()) return 0.0; 510 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
504 return (*m_controlPortsIn[parameter].second); 511 return (*m_controlPortsIn[parameter].second);
505 } 512 }
506 513
507 float 514 float
508 LADSPAPluginInstance::getParameterDefault(unsigned int parameter) const 515 LADSPAPluginInstance::getParameterDefault(int parameter) const
509 { 516 {
510 if (parameter >= m_controlPortsIn.size()) return 0.0; 517 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
511 518
512 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); 519 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
513 if (f) { 520 if (f) {
514 return f->getPortDefault(m_descriptor, m_controlPortsIn[parameter].first); 521 return f->getPortDefault(m_descriptor, m_controlPortsIn[parameter].first);
515 } else { 522 } else {
516 return 0.0f; 523 return 0.0f;
517 } 524 }
518 } 525 }
519 526
520 int 527 int
521 LADSPAPluginInstance::getParameterDisplayHint(unsigned int parameter) const 528 LADSPAPluginInstance::getParameterDisplayHint(int parameter) const
522 { 529 {
523 if (parameter >= m_controlPortsIn.size()) return 0.0; 530 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
524 531
525 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); 532 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
526 if (f) { 533 if (f) {
527 return f->getPortDisplayHint(m_descriptor, m_controlPortsIn[parameter].first); 534 return f->getPortDisplayHint(m_descriptor, m_controlPortsIn[parameter].first);
528 } else { 535 } else {
529 return PortHint::NoHint; 536 return PortHint::NoHint;
530 } 537 }
531 } 538 }
532 539
533 void 540 void
534 LADSPAPluginInstance::run(const Vamp::RealTime &, size_t count) 541 LADSPAPluginInstance::run(const RealTime &, int count)
535 { 542 {
536 if (!m_descriptor || !m_descriptor->run) return; 543 if (!m_descriptor || !m_descriptor->run) return;
537 544
538 if (count == 0) count = m_blockSize; 545 if (count == 0) count = m_blockSize;
539 546