Fix a problem where VST automation data wasn't getting written (if the adjustments...
[ardour.git] / libs / ardour / vst_plugin.cc
index 52e139db84fab0bcc7ab722006271cac9b4e2931..08db7dec5e56fa18d533a366a13dd6f9377e51bf 100644 (file)
 */
 
 #include <glib.h>
-#include <glib/gstdio.h>
+#include "pbd/gstdio_compat.h"
 
 #include <glibmm/fileutils.h>
 #include <glibmm/miscutils.h>
 
 #include "pbd/floating.h"
 #include "pbd/locale_guard.h"
-#include "pbd/pathscanner.h"
 
 #include "ardour/vst_plugin.h"
 #include "ardour/vestige/aeffectx.h"
@@ -118,6 +117,12 @@ VSTPlugin::set_parameter (uint32_t which, float newval)
        }
 }
 
+void
+VSTPlugin::set_parameter_automated (uint32_t which, float newval)
+{
+       Plugin::set_parameter_automated (which, newval);
+}
+
 uint32_t
 VSTPlugin::nth_parameter (uint32_t n, bool& ok) const
 {
@@ -159,7 +164,7 @@ VSTPlugin::set_chunk (gchar const * data, bool single)
 void
 VSTPlugin::add_state (XMLNode* root) const
 {
-       LocaleGuard lg (X_("POSIX"));
+       LocaleGuard lg (X_("C"));
 
        if (_plugin->flags & 32 /* effFlagsProgramsChunks */) {
 
@@ -196,7 +201,7 @@ VSTPlugin::add_state (XMLNode* root) const
 int
 VSTPlugin::set_state (const XMLNode& node, int version)
 {
-       LocaleGuard lg (X_("POSIX"));
+       LocaleGuard lg (X_("C"));
        int ret = -1;
 
        if (node.name() != state_node_name()) {
@@ -250,6 +255,7 @@ VSTPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
 {
        VstParameterProperties prop;
 
+       memset (&prop, 0, sizeof (VstParameterProperties));
        desc.min_unbound = false;
        desc.max_unbound = false;
        prop.flags = 0;
@@ -257,6 +263,7 @@ VSTPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
        if (_plugin->dispatcher (_plugin, effGetParameterProperties, which, 0, &prop, 0)) {
 
                /* i have yet to find or hear of a VST plugin that uses this */
+               /* RG: faust2vsti does use this :) */
 
                if (prop.flags & kVstParameterUsesIntegerMinMax) {
                        desc.lower = prop.minInteger;
@@ -287,6 +294,10 @@ VSTPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
                        desc.largestep = desc.step * 10.0f;
                }
 
+               if (strlen(prop.label) == 0) {
+                       _plugin->dispatcher (_plugin, effGetParamName, which, 0, prop.label, 0);
+               }
+
                desc.toggled = prop.flags & kVstParameterIsSwitch;
                desc.logarithmic = false;
                desc.sr_dependent = false;
@@ -544,7 +555,7 @@ VSTPlugin::connect_and_run (BufferSet& bufs,
        */
 
        float** ins = (float**)alloca(_plugin->numInputs*sizeof(float*));
-       float** outs = (float**)alloca(_plugin->numInputs*sizeof(float*));
+       float** outs = (float**)alloca(_plugin->numOutputs*sizeof(float*));
 
        int32_t i;
 
@@ -560,12 +571,7 @@ VSTPlugin::connect_and_run (BufferSet& bufs,
 
        uint32_t out_index = 0;
        for (i = 0; i < (int32_t) _plugin->numOutputs; ++i) {
-               uint32_t  index;
-               bool      valid = false;
-               index = out_map.get(DataType::AUDIO, out_index++, &valid);
-               outs[i] = (valid)
-                                       ? bufs.get_audio(index).data(offset)
-                                       : scratch_bufs.get_audio(0).data(offset);
+               outs[i] = scratch_bufs.get_audio(i).data(offset);
        }
 
        if (bufs.count().n_midi() > 0) {
@@ -592,6 +598,16 @@ VSTPlugin::connect_and_run (BufferSet& bufs,
        _plugin->processReplacing (_plugin, &ins[0], &outs[0], nframes);
        _midi_out_buf = 0;
 
+       out_index = 0;
+       for (i = 0; i < (int32_t) _plugin->numOutputs; ++i) {
+               uint32_t  index;
+               bool      valid = false;
+               index = out_map.get(DataType::AUDIO, out_index++, &valid);
+               if (!valid) {
+                       continue;
+               }
+               copy_vector (bufs.get_audio(index).data(offset), outs[i], nframes);
+       }
        return 0;
 }
 
@@ -609,6 +625,9 @@ VSTPlugin::unique_id () const
 const char *
 VSTPlugin::name () const
 {
+       if (!_info->name.empty ()) {
+               return _info->name.c_str();
+       }
        return _handle->name;
 }