Mercurial > hg > svapp
comparison framework/TransformUserConfigurator.cpp @ 740:846970dbef17 audio-source-refactor
Use shared_ptr for plugin instances throughout
| author | Chris Cannam | 
|---|---|
| date | Fri, 20 Mar 2020 16:31:58 +0000 | 
| parents | ddfac001b543 | 
| children | bac019c94e38 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 739:ddfac001b543 | 740:846970dbef17 | 
|---|---|
| 38 parentWidget = w; | 38 parentWidget = w; | 
| 39 } | 39 } | 
| 40 | 40 | 
| 41 bool | 41 bool | 
| 42 TransformUserConfigurator::getChannelRange(TransformId identifier, | 42 TransformUserConfigurator::getChannelRange(TransformId identifier, | 
| 43 Vamp::PluginBase *plugin, | 43 std::shared_ptr<Vamp::PluginBase> plugin, | 
| 44 int &minChannels, int &maxChannels) | 44 int &minChannels, int &maxChannels) | 
| 45 { | 45 { | 
| 46 if (plugin && plugin->getType() == "Feature Extraction Plugin") { | 46 if (plugin && plugin->getType() == "Feature Extraction Plugin") { | 
| 47 Vamp::Plugin *vp = static_cast<Vamp::Plugin *>(plugin); | 47 auto vp = std::dynamic_pointer_cast<Vamp::Plugin>(plugin); | 
| 48 SVDEBUG << "TransformUserConfigurator::getChannelRange: is a Vamp plugin" << endl; | 48 if (vp) { | 
| 49 minChannels = int(vp->getMinChannelCount()); | 49 SVDEBUG << "TransformUserConfigurator::getChannelRange: is a Vamp plugin" << endl; | 
| 50 maxChannels = int(vp->getMaxChannelCount()); | 50 minChannels = int(vp->getMinChannelCount()); | 
| 51 return true; | 51 maxChannels = int(vp->getMaxChannelCount()); | 
| 52 return true; | |
| 53 } else { | |
| 54 SVCERR << "TransformUserConfigurator::getChannelRange: inconsistent plugin identity!" << endl; | |
| 55 return false; | |
| 56 } | |
| 52 } else { | 57 } else { | 
| 53 SVDEBUG << "TransformUserConfigurator::getChannelRange: is not a Vamp plugin" << endl; | 58 SVDEBUG << "TransformUserConfigurator::getChannelRange: is not a Vamp plugin" << endl; | 
| 54 return TransformFactory::getInstance()-> | 59 return TransformFactory::getInstance()-> | 
| 55 getTransformChannelRange(identifier, minChannels, maxChannels); | 60 getTransformChannelRange(identifier, minChannels, maxChannels); | 
| 56 } | 61 } | 
| 57 } | 62 } | 
| 58 | 63 | 
| 59 bool | 64 bool | 
| 60 TransformUserConfigurator::configure(ModelTransformer::Input &input, | 65 TransformUserConfigurator::configure(ModelTransformer::Input &input, | 
| 61 Transform &transform, | 66 Transform &transform, | 
| 62 Vamp::PluginBase *plugin, | 67 std::shared_ptr<Vamp::PluginBase> plugin, | 
| 63 ModelId &inputModel, | 68 ModelId &inputModel, | 
| 64 AudioPlaySource *source, | 69 AudioPlaySource *source, | 
| 65 sv_frame_t startFrame, | 70 sv_frame_t startFrame, | 
| 66 sv_frame_t duration, | 71 sv_frame_t duration, | 
| 67 const QMap<QString, ModelId> &modelMap, | 72 const QMap<QString, ModelId> &modelMap, | 
| 83 SVDEBUG << "TransformUserConfigurator::configure: identifier " << id << endl; | 88 SVDEBUG << "TransformUserConfigurator::configure: identifier " << id << endl; | 
| 84 | 89 | 
| 85 if (RealTimePluginFactory::instanceFor(id)) { | 90 if (RealTimePluginFactory::instanceFor(id)) { | 
| 86 | 91 | 
| 87 RealTimePluginFactory *factory = RealTimePluginFactory::instanceFor(id); | 92 RealTimePluginFactory *factory = RealTimePluginFactory::instanceFor(id); | 
| 88 const RealTimePluginDescriptor *desc = factory->getPluginDescriptor(id); | 93 RealTimePluginDescriptor desc = factory->getPluginDescriptor(id); | 
| 89 | 94 | 
| 90 if (desc->audioInputPortCount > 0 && | 95 if (desc.audioInputPortCount > 0 && | 
| 91 desc->audioOutputPortCount > 0 && | 96 desc.audioOutputPortCount > 0 && | 
| 92 !desc->isSynth) { | 97 !desc.isSynth) { | 
| 93 effect = true; | 98 effect = true; | 
| 94 } | 99 } | 
| 95 | 100 | 
| 96 if (desc->audioInputPortCount == 0) { | 101 if (desc.audioInputPortCount == 0) { | 
| 97 generator = true; | 102 generator = true; | 
| 98 } | 103 } | 
| 99 | 104 | 
| 100 if (output != "A") { | 105 if (output != "A") { | 
| 101 int outputNo = output.toInt(); | 106 int outputNo = output.toInt(); | 
| 102 if (outputNo >= 0 && outputNo < int(desc->controlOutputPortCount)) { | 107 if (outputNo >= 0 && outputNo < int(desc.controlOutputPortCount)) { | 
| 103 outputLabel = desc->controlOutputPortNames[outputNo].c_str(); | 108 outputLabel = desc.controlOutputPortNames[outputNo].c_str(); | 
| 104 } | 109 } | 
| 105 } | 110 } | 
| 106 | 111 | 
| 107 RealTimePluginInstance *rtp = | 112 auto auditionable = std::dynamic_pointer_cast<Auditionable>(plugin); | 
| 108 static_cast<RealTimePluginInstance *>(plugin); | 113 | 
| 109 | 114 if (effect && source && auditionable) { | 
| 110 if (effect && source) { | |
| 111 SVDEBUG << "Setting auditioning effect" << endl; | 115 SVDEBUG << "Setting auditioning effect" << endl; | 
| 112 //!!! This requires a shared_ptr, but we don't manage our | |
| 113 //!!! plugin using shared_ptrs yet. Do this as a stopgap. | |
| 114 std::shared_ptr<Auditionable> auditionable | |
| 115 (std::make_shared<bool>(true), rtp); | |
| 116 source->setAuditioningEffect(auditionable); | 116 source->setAuditioningEffect(auditionable); | 
| 117 } | 117 } | 
| 118 | 118 | 
| 119 } else { | 119 } else { | 
| 120 | 120 | 
| 121 Vamp::Plugin *vp = static_cast<Vamp::Plugin *>(plugin); | 121 auto vp = std::dynamic_pointer_cast<Vamp::Plugin>(plugin); | 
| 122 | 122 | 
| 123 frequency = (vp->getInputDomain() == Vamp::Plugin::FrequencyDomain); | 123 frequency = (vp->getInputDomain() == Vamp::Plugin::FrequencyDomain); | 
| 124 | 124 | 
| 125 std::vector<Vamp::Plugin::OutputDescriptor> od = | 125 std::vector<Vamp::Plugin::OutputDescriptor> od = | 
| 126 vp->getOutputDescriptors(); | 126 vp->getOutputDescriptors(); | 
