Yamaha-PSR-S900.midnam: correct organ flutes, duplicate settings generated from fault...
[ardour.git] / libs / ardour / vst_plugin.cc
index 2d1a24ae93d420bb050b2d91cd3ed2d329b48964..3885bc2a1cab8fd2c42bf302495bab952d202e90 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"
@@ -92,10 +100,22 @@ 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);
-       Plugin::set_parameter (which, val);
+       float oldval = get_parameter (which);
+
+       if (PBD::floateq (oldval, newval, 1)) {
+               return;
+       }
+
+       _plugin->setParameter (_plugin, which, newval);
+       
+       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);
+       }
 }
 
 uint32_t
@@ -234,8 +254,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) {
@@ -271,7 +289,6 @@ VSTPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
                desc.logarithmic = false;
                desc.sr_dependent = false;
                desc.label = prop.label;
-#endif
 
        } else {
 
@@ -439,11 +456,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;
 }
 
@@ -457,11 +473,10 @@ 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 
@@ -601,7 +616,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];
@@ -631,7 +646,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));
                }
        }
@@ -646,21 +661,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;