use K-20 meter as default master bus
[ardour.git] / libs / ardour / vst_plugin.cc
index ae5e4897f8642eb4aa48d63039f9b747daf95ccd..b80a594495d8c936125d3fff58853aeb1f77a35c 100644 (file)
 
 */
 
+#include <glib.h>
+#include <glib/gstdio.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"
 #include "ardour/session.h"
@@ -56,10 +64,6 @@ VSTPlugin::set_plugin (AEffect* e)
 
        _plugin->dispatcher (_plugin, effSetSampleRate, 0, 0, NULL, (float) _session.frame_rate());
        _plugin->dispatcher (_plugin, effSetBlockSize, 0, _session.get_block_size(), NULL, 0.0f);
-
-       /* set program to zero */
-
-       _plugin->dispatcher (_plugin, effSetProgram, 0, 0, NULL, 0.0f);
 }
 
 void
@@ -96,17 +100,21 @@ VSTPlugin::get_parameter (uint32_t which) const
 }
 
 void 
-VSTPlugin::set_parameter (uint32_t which, float val)
+VSTPlugin::set_parameter (uint32_t which, float newval)
 {
-       _plugin->setParameter (_plugin, which, val);
+       float oldval = get_parameter (which);
+
+       if (PBD::floateq (oldval, newval, 1)) {
+               return;
+       }
+
+       _plugin->setParameter (_plugin, which, newval);
        
-       if (_state->want_program == -1 && _state->want_chunk == 0) {
-               /* Heinous hack: Plugin::set_parameter below updates the `modified' status of the
-                  current preset, but if _state->want_program is not -1 then there is a preset
-                  setup pending or in progress, which we don't want any `modified' updates
-                  to happen for.  So we only do this if _state->want_program is -1.
-               */
-               Plugin::set_parameter (which, val);
+       float curval = get_parameter (which);
+
+       if (!PBD::floateq (curval, oldval, 1)) {
+               /* value has changed, follow rest of the notification path */
+               Plugin::set_parameter (which, newval);
        }
 }
 
@@ -153,12 +161,6 @@ VSTPlugin::add_state (XMLNode* root) const
 {
        LocaleGuard lg (X_("POSIX"));
 
-       if (_state->current_program != -1) {
-               char buf[32];
-               snprintf (buf, sizeof (buf), "%d", _state->current_program);
-               root->add_property ("current-program", buf);
-       }
-
        if (_plugin->flags & 32 /* effFlagsProgramsChunks */) {
 
                gchar* data = get_chunk (false);
@@ -195,20 +197,15 @@ int
 VSTPlugin::set_state (const XMLNode& node, int version)
 {
        LocaleGuard lg (X_("POSIX"));
+       int ret = -1;
 
        if (node.name() != state_node_name()) {
                error << _("Bad node sent to VSTPlugin::set_state") << endmsg;
                return 0;
        }
 
-       const XMLProperty* prop;
-
-       if ((prop = node.property ("current-program")) != 0) {
-               _state->want_program = atoi (prop->value().c_str());
-       }
-
+#ifndef NO_PLUGIN_STATE
        XMLNode* child;
-       int ret = -1;
 
        if ((child = find_named_node (node, X_("chunk"))) != 0) {
 
@@ -238,13 +235,10 @@ VSTPlugin::set_state (const XMLNode& node, int version)
                        _plugin->setParameter (_plugin, param, val);
                }
 
-               /* program number is not knowable */
-
-               _state->current_program = -1;
-
                ret = 0;
 
        }
+#endif
 
        Plugin::set_state (node, version);
        return ret;
@@ -262,8 +256,6 @@ 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) {
@@ -299,17 +291,17 @@ VSTPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
                desc.logarithmic = false;
                desc.sr_dependent = false;
                desc.label = prop.label;
-#endif
 
        } else {
 
                /* old style */
 
                char label[64];
-               label[0] = '\0';
+               /* some VST plugins expect this buffer to be zero-filled */
+               memset (label, sizeof (label), 0);
 
                _plugin->dispatcher (_plugin, effGetParamName, which, 0, label, 0);
-
+               
                desc.label = label;
                desc.integer_step = false;
                desc.lower = 0.0f;
@@ -409,8 +401,8 @@ VSTPlugin::load_user_preset (PresetRecord r)
 
                        return false;
 
-               }
-               else {
+               } else {
+                       
                        for (XMLNodeList::const_iterator j = (*i)->children().begin(); j != (*i)->children().end(); ++j) {
                                if ((*j)->name() == X_("Parameter")) {
                                                XMLProperty* index = (*j)->property (X_("index"));
@@ -449,8 +441,7 @@ VSTPlugin::do_save_preset (string name)
                p->add_content (string (data));
                g_free (data);
 
-       }
-       else {
+       } else {
 
                p = new XMLNode (X_("Preset"));
                p->add_property (X_("uri"), uri);
@@ -468,11 +459,10 @@ VSTPlugin::do_save_preset (string name)
 
        t->root()->add_child_nocopy (*p);
 
-       sys::path f = ARDOUR::user_config_directory ();
-       f /= "presets";
-       f /= presets_file ();
+       std::string f = Glib::build_filename (ARDOUR::user_config_directory (), "presets");
+       f = Glib::build_filename (f, presets_file ());
 
-       t->write (f.to_string ());
+       t->write (f);
        return uri;
 }
 
@@ -486,18 +476,26 @@ VSTPlugin::do_remove_preset (string name)
 
        t->root()->remove_nodes_and_delete (X_("label"), name);
 
-       sys::path f = ARDOUR::user_config_directory ();
-       f /= "presets";
-       f /= presets_file ();
+       std::string f = Glib::build_filename (ARDOUR::user_config_directory (), "presets");
+       f = Glib::build_filename (f, presets_file ());
 
-       t->write (f.to_string ());
+       t->write (f);
 }
 
 string 
 VSTPlugin::describe_parameter (Evoral::Parameter param)
 {
-       char name[64] = "Unkown";
+       char name[64];
+       memset (name, sizeof (name), 0);
+
+       /* some VST plugins expect this buffer to be zero-filled */
+
        _plugin->dispatcher (_plugin, effGetParamName, param.id(), 0, name, 0);
+
+       if (name[0] == '\0') {
+               strcpy (name, _("Unknown"));
+       }
+
        return name;
 }
 
@@ -630,7 +628,7 @@ VSTPlugin::find_presets ()
 
        int const vst_version = _plugin->dispatcher (_plugin, effGetVstVersion, 0, 0, NULL, 0);
        for (int i = 0; i < _plugin->numPrograms; ++i) {
-               PresetRecord r (string_compose (X_("VST:%1:%2"), unique_id (), i), "", false);
+               PresetRecord r (string_compose (X_("VST:%1:%2"), unique_id (), i), "", -1, false);
 
                if (vst_version >= 2) {
                        char buf[256];
@@ -660,7 +658,7 @@ VSTPlugin::find_presets ()
                        assert (uri);
                        assert (label);
 
-                       PresetRecord r (uri->value(), label->value(), true);
+                       PresetRecord r (uri->value(), label->value(), -1, true);
                        _presets.insert (make_pair (r.uri, r));
                }
        }
@@ -675,21 +673,22 @@ VSTPlugin::presets_tree () const
 {
        XMLTree* t = new XMLTree;
 
-       sys::path p = ARDOUR::user_config_directory ();
-       p /= "presets";
+       std::string p = Glib::build_filename (ARDOUR::user_config_directory (), "presets");
 
-       if (!is_directory (p)) {
-               create_directory (p);
+       if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {
+               if (g_mkdir_with_parents (p.c_str(), 0755) != 0) {
+                       error << _("Unable to make VST presets directory") << endmsg;
+               };
        }
 
-       p /= presets_file ();
+       p = Glib::build_filename (p, presets_file ());
 
-       if (!exists (p)) {
+       if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) {
                t->set_root (new XMLNode (X_("VSTPresets")));
                return t;
        }
 
-       t->set_filename (p.to_string ());
+       t->set_filename (p);
        if (!t->read ()) {
                delete t;
                return 0;