diff transform/TransformFactory.cpp @ 41:fbd7a497fd89

* Audition effects plugins during playback
author Chris Cannam
date Wed, 04 Oct 2006 11:01:39 +0000
parents 06787742542a
children c0ae41c72421
line wrap: on
line diff
--- a/transform/TransformFactory.cpp	Tue Oct 03 15:01:50 2006 +0000
+++ b/transform/TransformFactory.cpp	Wed Oct 04 11:01:39 2006 +0000
@@ -28,6 +28,8 @@
 
 #include "vamp-sdk/PluginHostAdapter.h"
 
+#include "sv/audioio/AudioCallbackPlaySource.h" //!!! shouldn't include here
+
 #include <iostream>
 #include <set>
 
@@ -443,7 +445,8 @@
 TransformFactory::getConfigurationForTransform(TransformName name,
                                                Model *inputModel,
                                                PluginTransform::ExecutionContext &context,
-                                               QString &configurationXml)
+                                               QString &configurationXml,
+                                               AudioCallbackPlaySource *source)
 {
     QString id = name.section(':', 0, 2);
     QString output = name.section(':', 3);
@@ -456,6 +459,7 @@
     Vamp::PluginBase *plugin = 0;
 
     bool frequency = false;
+    bool effect = false;
 
     if (FeatureExtractionPluginFactory::instanceFor(id)) {
 
@@ -469,8 +473,32 @@
 
     } else if (RealTimePluginFactory::instanceFor(id)) {
 
-        plugin = RealTimePluginFactory::instanceFor(id)->instantiatePlugin
-            (id, 0, 0, inputModel->getSampleRate(), 1024, 1);
+        RealTimePluginFactory *factory = RealTimePluginFactory::instanceFor(id);
+        const RealTimePluginDescriptor *desc = factory->getPluginDescriptor(id);
+
+        if (desc->audioInputPortCount > 0 && 
+            desc->audioOutputPortCount > 0 &&
+            !desc->isSynth) {
+            effect = true;
+        }
+
+        size_t sampleRate = inputModel->getSampleRate();
+        size_t blockSize = 1024;
+        size_t channels = 1;
+        if (effect && source) {
+            sampleRate = source->getTargetSampleRate();
+            blockSize = source->getTargetBlockSize();
+            channels = source->getTargetChannelCount();
+        }
+
+        RealTimePluginInstance *rtp = factory->instantiatePlugin
+            (id, 0, 0, sampleRate, blockSize, channels);
+
+        plugin = rtp;
+
+        if (effect && source && rtp) {
+            source->setAuditioningPlugin(rtp);
+        }
     }
 
     if (plugin) {
@@ -516,7 +544,12 @@
         context.makeConsistentWithPlugin(plugin);
 
         delete dialog;
-        delete plugin;
+
+        if (effect && source) {
+            source->setAuditioningPlugin(0); // will delete our plugin
+        } else {
+            delete plugin;
+        }
     }
 
     if (ok) m_lastConfigurations[name] = configurationXml;