comparison src/vamp-sdk/PluginAdapter.cpp @ 268:6579e441f2fe

* Ensure that output descriptors are re-queried after a call to initialise, setParameter or selectProgram (following "What can depend on a parameter?" section of programmers guide)
author cannam
date Tue, 25 Nov 2008 13:16:07 +0000
parents 7b90fe049d04
children 9abf7455a1a3
comparison
equal deleted inserted replaced
267:93c81a6c917a 268:6579e441f2fe
96 96
97 static VampFeatureList *vampGetRemainingFeatures(VampPluginHandle handle); 97 static VampFeatureList *vampGetRemainingFeatures(VampPluginHandle handle);
98 98
99 static void vampReleaseFeatureSet(VampFeatureList *fs); 99 static void vampReleaseFeatureSet(VampFeatureList *fs);
100 100
101 void checkOutputMap(Plugin *plugin);
102 void markOutputsChanged(Plugin *plugin);
103
101 void cleanup(Plugin *plugin); 104 void cleanup(Plugin *plugin);
102 void checkOutputMap(Plugin *plugin);
103 unsigned int getOutputCount(Plugin *plugin); 105 unsigned int getOutputCount(Plugin *plugin);
104 VampOutputDescriptor *getOutputDescriptor(Plugin *plugin, 106 VampOutputDescriptor *getOutputDescriptor(Plugin *plugin,
105 unsigned int i); 107 unsigned int i);
106 VampFeatureList *process(Plugin *plugin, 108 VampFeatureList *process(Plugin *plugin,
107 const float *const *inputBuffers, 109 const float *const *inputBuffers,
323 return i->second; 325 return i->second;
324 } 326 }
325 327
326 VampPluginHandle 328 VampPluginHandle
327 PluginAdapterBase::Impl::vampInstantiate(const VampPluginDescriptor *desc, 329 PluginAdapterBase::Impl::vampInstantiate(const VampPluginDescriptor *desc,
328 float inputSampleRate) 330 float inputSampleRate)
329 { 331 {
330 #ifdef DEBUG_PLUGIN_ADAPTER 332 #ifdef DEBUG_PLUGIN_ADAPTER
331 std::cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << ")" << std::endl; 333 std::cerr << "PluginAdapterBase::Impl::vampInstantiate(" << desc << ")" << std::endl;
332 #endif 334 #endif
333 335
370 adapter->cleanup(((Plugin *)handle)); 372 adapter->cleanup(((Plugin *)handle));
371 } 373 }
372 374
373 int 375 int
374 PluginAdapterBase::Impl::vampInitialise(VampPluginHandle handle, 376 PluginAdapterBase::Impl::vampInitialise(VampPluginHandle handle,
375 unsigned int channels, 377 unsigned int channels,
376 unsigned int stepSize, 378 unsigned int stepSize,
377 unsigned int blockSize) 379 unsigned int blockSize)
378 { 380 {
379 #ifdef DEBUG_PLUGIN_ADAPTER 381 #ifdef DEBUG_PLUGIN_ADAPTER
380 std::cerr << "PluginAdapterBase::Impl::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << std::endl; 382 std::cerr << "PluginAdapterBase::Impl::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << std::endl;
381 #endif 383 #endif
382 384
383 bool result = ((Plugin *)handle)->initialise 385 Impl *adapter = lookupAdapter(handle);
384 (channels, stepSize, blockSize); 386 if (!adapter) return 0;
387 bool result = ((Plugin *)handle)->initialise(channels, stepSize, blockSize);
388 adapter->markOutputsChanged((Plugin *)handle);
385 return result ? 1 : 0; 389 return result ? 1 : 0;
386 } 390 }
387 391
388 void 392 void
389 PluginAdapterBase::Impl::vampReset(VampPluginHandle handle) 393 PluginAdapterBase::Impl::vampReset(VampPluginHandle handle)
419 423
420 Impl *adapter = lookupAdapter(handle); 424 Impl *adapter = lookupAdapter(handle);
421 if (!adapter) return; 425 if (!adapter) return;
422 Plugin::ParameterList &list = adapter->m_parameters; 426 Plugin::ParameterList &list = adapter->m_parameters;
423 ((Plugin *)handle)->setParameter(list[param].identifier, value); 427 ((Plugin *)handle)->setParameter(list[param].identifier, value);
428 adapter->markOutputsChanged((Plugin *)handle);
424 } 429 }
425 430
426 unsigned int 431 unsigned int
427 PluginAdapterBase::Impl::vampGetCurrentProgram(VampPluginHandle handle) 432 PluginAdapterBase::Impl::vampGetCurrentProgram(VampPluginHandle handle)
428 { 433 {
440 return 0; 445 return 0;
441 } 446 }
442 447
443 void 448 void
444 PluginAdapterBase::Impl::vampSelectProgram(VampPluginHandle handle, 449 PluginAdapterBase::Impl::vampSelectProgram(VampPluginHandle handle,
445 unsigned int program) 450 unsigned int program)
446 { 451 {
447 #ifdef DEBUG_PLUGIN_ADAPTER 452 #ifdef DEBUG_PLUGIN_ADAPTER
448 std::cerr << "PluginAdapterBase::Impl::vampSelectProgram(" << handle << ", " << program << ")" << std::endl; 453 std::cerr << "PluginAdapterBase::Impl::vampSelectProgram(" << handle << ", " << program << ")" << std::endl;
449 #endif 454 #endif
450 455
451 Impl *adapter = lookupAdapter(handle); 456 Impl *adapter = lookupAdapter(handle);
452 if (!adapter) return; 457 if (!adapter) return;
458
453 Plugin::ProgramList &list = adapter->m_programs; 459 Plugin::ProgramList &list = adapter->m_programs;
454 ((Plugin *)handle)->selectProgram(list[program]); 460 ((Plugin *)handle)->selectProgram(list[program]);
461
462 adapter->markOutputsChanged((Plugin *)handle);
455 } 463 }
456 464
457 unsigned int 465 unsigned int
458 PluginAdapterBase::Impl::vampGetPreferredStepSize(VampPluginHandle handle) 466 PluginAdapterBase::Impl::vampGetPreferredStepSize(VampPluginHandle handle)
459 { 467 {
509 return adapter->getOutputCount((Plugin *)handle); 517 return adapter->getOutputCount((Plugin *)handle);
510 } 518 }
511 519
512 VampOutputDescriptor * 520 VampOutputDescriptor *
513 PluginAdapterBase::Impl::vampGetOutputDescriptor(VampPluginHandle handle, 521 PluginAdapterBase::Impl::vampGetOutputDescriptor(VampPluginHandle handle,
514 unsigned int i) 522 unsigned int i)
515 { 523 {
516 #ifdef DEBUG_PLUGIN_ADAPTER 524 #ifdef DEBUG_PLUGIN_ADAPTER
517 std::cerr << "PluginAdapterBase::Impl::vampGetOutputDescriptor(" << handle << ", " << i << ")" << std::endl; 525 std::cerr << "PluginAdapterBase::Impl::vampGetOutputDescriptor(" << handle << ", " << i << ")" << std::endl;
518 #endif 526 #endif
519 527
557 std::cerr << "PluginAdapterBase::Impl::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << std::endl; 565 std::cerr << "PluginAdapterBase::Impl::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << std::endl;
558 #endif 566 #endif
559 567
560 Impl *adapter = lookupAdapter(handle); 568 Impl *adapter = lookupAdapter(handle);
561 if (!adapter) return 0; 569 if (!adapter) return 0;
562 return adapter->process((Plugin *)handle, 570 return adapter->process((Plugin *)handle, inputBuffers, sec, nsec);
563 inputBuffers, sec, nsec);
564 } 571 }
565 572
566 VampFeatureList * 573 VampFeatureList *
567 PluginAdapterBase::Impl::vampGetRemainingFeatures(VampPluginHandle handle) 574 PluginAdapterBase::Impl::vampGetRemainingFeatures(VampPluginHandle handle)
568 { 575 {
626 } 633 }
627 634
628 void 635 void
629 PluginAdapterBase::Impl::checkOutputMap(Plugin *plugin) 636 PluginAdapterBase::Impl::checkOutputMap(Plugin *plugin)
630 { 637 {
631 if (m_pluginOutputs.find(plugin) == m_pluginOutputs.end() || 638 OutputMap::iterator i = m_pluginOutputs.find(plugin);
632 !m_pluginOutputs[plugin]) { 639
640 if (i == m_pluginOutputs.end() || !i->second) {
641
633 m_pluginOutputs[plugin] = new Plugin::OutputList 642 m_pluginOutputs[plugin] = new Plugin::OutputList
634 (plugin->getOutputDescriptors()); 643 (plugin->getOutputDescriptors());
644
635 // std::cerr << "PluginAdapterBase::Impl::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << std::endl; 645 // std::cerr << "PluginAdapterBase::Impl::checkOutputMap: Have " << m_pluginOutputs[plugin]->size() << " outputs for plugin " << plugin->getIdentifier() << std::endl;
646 }
647 }
648
649 void
650 PluginAdapterBase::Impl::markOutputsChanged(Plugin *plugin)
651 {
652 OutputMap::iterator i = m_pluginOutputs.find(plugin);
653
654 // std::cerr << "PluginAdapterBase::Impl::markOutputsChanged" << std::endl;
655
656 if (i != m_pluginOutputs.end()) {
657
658 Plugin::OutputList *list = i->second;
659 m_pluginOutputs.erase(i);
660 delete list;
636 } 661 }
637 } 662 }
638 663
639 unsigned int 664 unsigned int
640 PluginAdapterBase::Impl::getOutputCount(Plugin *plugin) 665 PluginAdapterBase::Impl::getOutputCount(Plugin *plugin)
641 { 666 {
642 checkOutputMap(plugin); 667 checkOutputMap(plugin);
668
643 return m_pluginOutputs[plugin]->size(); 669 return m_pluginOutputs[plugin]->size();
644 } 670 }
645 671
646 VampOutputDescriptor * 672 VampOutputDescriptor *
647 PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin, 673 PluginAdapterBase::Impl::getOutputDescriptor(Plugin *plugin,
648 unsigned int i) 674 unsigned int i)
649 { 675 {
650 checkOutputMap(plugin); 676 checkOutputMap(plugin);
677
651 Plugin::OutputDescriptor &od = 678 Plugin::OutputDescriptor &od =
652 (*m_pluginOutputs[plugin])[i]; 679 (*m_pluginOutputs[plugin])[i];
653 680
654 VampOutputDescriptor *desc = (VampOutputDescriptor *) 681 VampOutputDescriptor *desc = (VampOutputDescriptor *)
655 malloc(sizeof(VampOutputDescriptor)); 682 malloc(sizeof(VampOutputDescriptor));