vestige-based VST support, back-ported from 2.0-ongoing
[ardour.git] / libs / ardour / vst_plugin.cc
index 5d7a303fc626ff78e6167c9e91d7be0ec65cb5c2..cd2531d52296882feeb3abb9aa7e6794298ca8da 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <algorithm>
 #include <vector>
 #include <string>
-#include <ctype.h>
+#include <cctype>
 
 #include <cstdlib>
 #include <cstdio> // so libraptor doesn't complain
 #include <cmath>
 #include <dirent.h>
-#include <string.h> // for memmove
+#include <cstring> // for memmove
 #include <sys/stat.h>
 #include <cerrno>
 
+#include <glibmm/ustring.h>
+#include <glibmm/miscutils.h>
+
 #include <lrdf.h>
 #include <fst.h>
 
-#include <pbd/compose.h>
-#include <pbd/error.h>
-#include <pbd/pathscanner.h>
-#include <pbd/xml++.h>
+#include "pbd/compose.h"
+#include "pbd/error.h"
+#include "pbd/pathscanner.h"
+#include "pbd/xml++.h"
 
 #include <vst/aeffectx.h>
 
-#include <ardour/ardour.h>
-#include <ardour/session.h>
-#include <ardour/audioengine.h>
-#include <ardour/vst_plugin.h>
+#include "ardour/session.h"
+#include "ardour/audioengine.h"
+#include "ardour/filesystem_paths.h"
+#include "ardour/vst_plugin.h"
+#include "ardour/buffer_set.h"
 
-#include <pbd/stl_delete.h>
+#include "pbd/stl_delete.h"
 
 #include "i18n.h"
 #include <locale.h>
@@ -120,7 +123,7 @@ void
 VSTPlugin::set_parameter (uint32_t which, float val)
 {
        _plugin->setParameter (_plugin, which, val);
-       ParameterChanged (which, val); /* EMIT SIGNAL */
+       //ParameterChanged (which, val); /* EMIT SIGNAL */
 }
 
 float
@@ -142,25 +145,27 @@ VSTPlugin::get_state()
 {
        XMLNode *root = new XMLNode (state_node_name());
        LocaleGuard lg (X_("POSIX"));
-       
-       if (_plugin->flags & effFlagsProgramChunks) {
+
+       if (_plugin->flags & 32 /* effFlagsProgramsChunks */) {
 
                /* fetch the current chunk */
                
                void* data;
                long  data_size;
                
-               if ((data_size = _plugin->dispatcher (_plugin, effGetChunk, 0, 0, &data, false)) == 0) {
+               if ((data_size = _plugin->dispatcher (_plugin, 23 /* effGetChunk */, 0, 0, &data, false)) == 0) {
                        return *root;
                }
 
                /* save it to a file */
 
-               string path;
+               Glib::ustring path = Glib::build_filename (get_user_ardour_path (), "vst");
                struct stat sbuf;
 
-               path = getenv ("HOME");
-               path += "/.ardour/vst";
+               sys::path user_vst_directory(user_config_directory());
+       
+               user_vst_directory /= "vst";
+               path = user_vst_directory.to_string();
 
                if (stat (path.c_str(), &sbuf)) {
                        if (errno == ENOENT) {
@@ -173,9 +178,8 @@ VSTPlugin::get_state()
 
                        } else {
 
-                               error << string_compose (_("cannot check VST chunk directory: %1"),
-                                                 strerror (errno))
-                                     << endmsg;
+                               warning << string_compose (_("cannot check VST chunk directory: %1"), strerror (errno))
+                                       << endmsg;
                                return *root;
                        }
 
@@ -185,7 +189,7 @@ VSTPlugin::get_state()
                        return *root;
                }
                
-               path += "something";
+               path = Glib::build_filename (path, "something");
                
                /* store information */
 
@@ -258,6 +262,8 @@ VSTPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
 
        if (_plugin->dispatcher (_plugin, effGetParameterProperties, which, 0, &prop, 0)) {
 
+#ifdef VESTIGE_COMPLETE
+
                /* i have yet to find or hear of a VST plugin that uses this */
 
                if (prop.flags & kVstParameterUsesIntegerMinMax) {
@@ -293,6 +299,7 @@ VSTPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
                desc.logarithmic = false;
                desc.sr_dependent = false;
                desc.label = prop.label;
+#endif
 
        } else {
 
@@ -321,7 +328,7 @@ VSTPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
 bool
 VSTPlugin::load_preset (string name)
 {
-       if (_plugin->flags & effFlagsProgramChunks) {
+       if (_plugin->flags & 32 /* effFlagsProgramsChunks */) {
                error << _("no support for presets using chunks at this time")
                      << endmsg;
                return false;
@@ -332,7 +339,7 @@ VSTPlugin::load_preset (string name)
 bool
 VSTPlugin::save_preset (string name)
 {
-       if (_plugin->flags & effFlagsProgramChunks) {
+       if (_plugin->flags & 32 /* effFlagsProgramsChunks */) {
                error << _("no support for presets using chunks at this time")
                      << endmsg;
                return false;
@@ -349,9 +356,17 @@ VSTPlugin::describe_parameter (uint32_t param)
 }
 
 nframes_t
-VSTPlugin::latency () const
+VSTPlugin::signal_latency () const
 {
-       return _plugin->initialDelay;
+       if (_user_latency) {
+               return _user_latency;
+       }
+
+#ifdef VESTIGE_HEADER
+        return *((nframes_t *) (((char *) &_plugin->flags) + 12)); /* initialDelay */
+#else
+       return _plugin->initial_delay;
+#endif
 }
 
 set<uint32_t>
@@ -367,19 +382,21 @@ VSTPlugin::automatable () const
 }
 
 int
-VSTPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in_index, int32_t& out_index, nframes_t nframes, nframes_t offset)
+VSTPlugin::connect_and_run (BufferSet& bufs, uint32_t& in_index, uint32_t& out_index, nframes_t nframes, nframes_t offset)
 {
        float *ins[_plugin->numInputs];
        float *outs[_plugin->numOutputs];
        int32_t i;
 
+       const uint32_t nbufs = bufs.count().n_audio();
+
        for (i = 0; i < (int32_t) _plugin->numInputs; ++i) {
-               ins[i] = bufs[min((uint32_t) in_index,maxbuf - 1)] + offset;
+               ins[i] = bufs.get_audio(min((uint32_t) in_index, nbufs - 1)).data() + offset;
                in_index++;
        }
 
        for (i = 0; i < (int32_t) _plugin->numOutputs; ++i) {
-               outs[i] = bufs[min((uint32_t) out_index,maxbuf - 1)] + offset;
+               outs[i] = bufs.get_audio(min((uint32_t) out_index, nbufs - 1)).data() + offset;
 
                /* unbelievably, several VST plugins still rely on Cubase
                   behaviour and do not silence the buffer in processReplacing 
@@ -410,10 +427,17 @@ VSTPlugin::activate ()
        _plugin->dispatcher (_plugin, effMainsChanged, 0, 1, NULL, 0.0f);
 }
 
-uint32_t 
+string
 VSTPlugin::unique_id() const
 {
-       return _plugin->uniqueID;
+       char buf[32];
+
+#ifdef VESTIGE_HEADER
+       snprintf (buf, sizeof (buf), "%d", *((int32_t*) &_plugin->unused_id));
+#else
+       snprintf (buf, sizeof (buf), "%d", _plugin->uniqueID);
+#endif
+       return string (buf);
 }