diff 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
line wrap: on
line diff
--- a/framework/TransformUserConfigurator.cpp	Thu Mar 19 16:14:02 2020 +0000
+++ b/framework/TransformUserConfigurator.cpp	Fri Mar 20 16:31:58 2020 +0000
@@ -40,15 +40,20 @@
 
 bool
 TransformUserConfigurator::getChannelRange(TransformId identifier,
-                                           Vamp::PluginBase *plugin,
+                                           std::shared_ptr<Vamp::PluginBase> plugin,
                                            int &minChannels, int &maxChannels)
 {
     if (plugin && plugin->getType() == "Feature Extraction Plugin") {
-        Vamp::Plugin *vp = static_cast<Vamp::Plugin *>(plugin);
-        SVDEBUG << "TransformUserConfigurator::getChannelRange: is a Vamp plugin" << endl;
-        minChannels = int(vp->getMinChannelCount());
-        maxChannels = int(vp->getMaxChannelCount());
-        return true;
+        auto vp = std::dynamic_pointer_cast<Vamp::Plugin>(plugin);
+        if (vp) {
+            SVDEBUG << "TransformUserConfigurator::getChannelRange: is a Vamp plugin" << endl;
+            minChannels = int(vp->getMinChannelCount());
+            maxChannels = int(vp->getMaxChannelCount());
+            return true;
+        } else {
+            SVCERR << "TransformUserConfigurator::getChannelRange: inconsistent plugin identity!" << endl;
+            return false;
+        }
     } else {
         SVDEBUG << "TransformUserConfigurator::getChannelRange: is not a Vamp plugin" << endl;
         return TransformFactory::getInstance()->
@@ -59,7 +64,7 @@
 bool
 TransformUserConfigurator::configure(ModelTransformer::Input &input,
                                      Transform &transform,
-                                     Vamp::PluginBase *plugin,
+                                     std::shared_ptr<Vamp::PluginBase> plugin,
                                      ModelId &inputModel,
                                      AudioPlaySource *source,
                                      sv_frame_t startFrame,
@@ -85,40 +90,35 @@
     if (RealTimePluginFactory::instanceFor(id)) {
 
         RealTimePluginFactory *factory = RealTimePluginFactory::instanceFor(id);
-        const RealTimePluginDescriptor *desc = factory->getPluginDescriptor(id);
+        RealTimePluginDescriptor desc = factory->getPluginDescriptor(id);
 
-        if (desc->audioInputPortCount > 0 && 
-            desc->audioOutputPortCount > 0 &&
-            !desc->isSynth) {
+        if (desc.audioInputPortCount > 0 && 
+            desc.audioOutputPortCount > 0 &&
+            !desc.isSynth) {
             effect = true;
         }
 
-        if (desc->audioInputPortCount == 0) {
+        if (desc.audioInputPortCount == 0) {
             generator = true;
         }
 
         if (output != "A") {
             int outputNo = output.toInt();
-            if (outputNo >= 0 && outputNo < int(desc->controlOutputPortCount)) {
-                outputLabel = desc->controlOutputPortNames[outputNo].c_str();
+            if (outputNo >= 0 && outputNo < int(desc.controlOutputPortCount)) {
+                outputLabel = desc.controlOutputPortNames[outputNo].c_str();
             }
         }
 
-        RealTimePluginInstance *rtp =
-            static_cast<RealTimePluginInstance *>(plugin);
-
-        if (effect && source) {
+        auto auditionable = std::dynamic_pointer_cast<Auditionable>(plugin);
+        
+        if (effect && source && auditionable) {
             SVDEBUG << "Setting auditioning effect" << endl;
-            //!!! This requires a shared_ptr, but we don't manage our
-            //!!! plugin using shared_ptrs yet. Do this as a stopgap.
-            std::shared_ptr<Auditionable> auditionable
-                (std::make_shared<bool>(true), rtp);
             source->setAuditioningEffect(auditionable);
         }
 
     } else {
 
-        Vamp::Plugin *vp = static_cast<Vamp::Plugin *>(plugin);
+        auto vp = std::dynamic_pointer_cast<Vamp::Plugin>(plugin);
 
         frequency = (vp->getInputDomain() == Vamp::Plugin::FrequencyDomain);