Add dialog to allow removal of plugin presets. Should fix #2662.
[ardour.git] / libs / ardour / ladspa_plugin.cc
index 70a8390de1a4126a3f2c5df5cdabb925baadb6bb..00454cea5ed76b1e60a8e14f6dae2890e45b6c1e 100644 (file)
@@ -17,7 +17,6 @@
 
 */
 
-#define __STDC_FORMAT_MACROS 1
 #include <inttypes.h>
 
 #include <vector>
@@ -54,7 +53,7 @@ using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
-LadspaPlugin::LadspaPlugin (void *mod, AudioEngine& e, Session& session, uint32_t index, nframes_t rate)
+LadspaPlugin::LadspaPlugin (void *mod, AudioEngine& e, Session& session, uint32_t index, framecnt_t rate)
        : Plugin (e, session)
 {
        init (mod, index, rate);
@@ -72,7 +71,7 @@ LadspaPlugin::LadspaPlugin (const LadspaPlugin &other)
 }
 
 void
-LadspaPlugin::init (void *mod, uint32_t index, nframes_t rate)
+LadspaPlugin::init (void *mod, uint32_t index, framecnt_t rate)
 {
        LADSPA_Descriptor_Function dfunc;
        uint32_t i, port_cnt;
@@ -144,8 +143,6 @@ LadspaPlugin::~LadspaPlugin ()
        deactivate ();
        cleanup ();
 
-       GoingAway (); /* EMIT SIGNAL */
-
        /* XXX who should close a plugin? */
 
         // dlclose (module);
@@ -180,8 +177,6 @@ LadspaPlugin::default_value (uint32_t port)
                        sr_scaling = true;
                }
 
-               /* FIXME: add support for logarithmic defaults */
-
                else if (LADSPA_IS_HINT_DEFAULT_LOW(prh[port].HintDescriptor)) {
                        if (LADSPA_IS_HINT_LOGARITHMIC(prh[port].HintDescriptor)) {
                                ret = exp(log(prh[port].LowerBound) * 0.75f + log(prh[port].UpperBound) * 0.25f);
@@ -377,9 +372,19 @@ LadspaPlugin::save_preset (string name)
        return Plugin::save_preset (name, "ladspa");
 }
 
+void
+LadspaPlugin::remove_preset (string name)
+{
+       return Plugin::remove_preset (name, "ladspa");
+}
+
 int
-LadspaPlugin::set_state(const XMLNode& node)
+LadspaPlugin::set_state (const XMLNode& node, int version)
 {
+       if (version < 3000) {
+               return set_state_2X (node, version);
+       }
+       
        XMLNodeList nodes;
        XMLProperty *prop;
        XMLNodeConstIterator iter;
@@ -422,6 +427,51 @@ LadspaPlugin::set_state(const XMLNode& node)
        return 0;
 }
 
+int
+LadspaPlugin::set_state_2X (const XMLNode& node, int /* version */)
+{
+       XMLNodeList nodes;
+       XMLProperty *prop;
+       XMLNodeConstIterator iter;
+       XMLNode *child;
+       const char *port;
+       const char *data;
+       uint32_t port_id;
+       LocaleGuard lg (X_("POSIX"));
+
+       if (node.name() != state_node_name()) {
+               error << _("Bad node sent to LadspaPlugin::set_state") << endmsg;
+               return -1;
+       }
+
+       nodes = node.children ("port");
+
+       for(iter = nodes.begin(); iter != nodes.end(); ++iter){
+
+               child = *iter;
+
+               if ((prop = child->property("number")) != 0) {
+                       port = prop->value().c_str();
+               } else {
+                       warning << _("LADSPA: no ladspa port number") << endmsg;
+                       continue;
+               }
+               if ((prop = child->property("value")) != 0) {
+                       data = prop->value().c_str();
+               } else {
+                       warning << _("LADSPA: no ladspa port data") << endmsg;
+                       continue;
+               }
+
+               sscanf (port, "%" PRIu32, &port_id);
+               set_parameter (port_id, atof(data));
+       }
+
+       latency_compute_run ();
+
+       return 0;
+}
+
 int
 LadspaPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc) const
 {
@@ -486,7 +536,7 @@ LadspaPlugin::describe_parameter (Evoral::Parameter which)
        }
 }
 
-ARDOUR::nframes_t
+ARDOUR::framecnt_t
 LadspaPlugin::signal_latency () const
 {
        if (_user_latency) {
@@ -494,7 +544,7 @@ LadspaPlugin::signal_latency () const
        }
 
        if (_latency_control_port) {
-               return (nframes_t) floor (*_latency_control_port);
+               return (framecnt_t) floor (*_latency_control_port);
        } else {
                return 0;
        }
@@ -519,7 +569,7 @@ LadspaPlugin::automatable () const
 int
 LadspaPlugin::connect_and_run (BufferSet& bufs,
                ChanMapping in_map, ChanMapping out_map,
-               nframes_t nframes, nframes_t offset)
+               pframes_t nframes, framecnt_t offset)
 {
        cycles_t now;
        cycles_t then = get_cycles ();
@@ -582,13 +632,16 @@ LadspaPlugin::print_parameter (uint32_t param, char *buf, uint32_t len) const
 }
 
 void
-LadspaPlugin::run_in_place (nframes_t nframes)
+LadspaPlugin::run_in_place (pframes_t nframes)
 {
        for (uint32_t i = 0; i < parameter_count(); ++i) {
                if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) && LADSPA_IS_PORT_CONTROL(port_descriptor (i))) {
                        _control_data[i] = _shadow_data[i];
                }
        }
+
+       assert (_was_activated);
+       
        _descriptor->run (_handle, nframes);
 }
 
@@ -608,7 +661,7 @@ LadspaPlugin::latency_compute_run ()
        uint32_t port_index = 0;
        uint32_t in_index = 0;
        uint32_t out_index = 0;
-       const nframes_t bufsize = 1024;
+       const framecnt_t bufsize = 1024;
        LADSPA_Data buffer[bufsize];
 
        memset(buffer,0,sizeof(LADSPA_Data)*bufsize);
@@ -646,6 +699,7 @@ LadspaPluginInfo::load (Session& session)
                if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
                        error << string_compose(_("LADSPA: cannot load module from \"%1\""), path) << endmsg;
                        error << dlerror() << endmsg;
+                        return PluginPtr ((Plugin*) 0);
                } else {
                        plugin.reset (new LadspaPlugin (module, session.engine(), session, index, session.frame_rate()));
                }
@@ -658,3 +712,8 @@ LadspaPluginInfo::load (Session& session)
                return PluginPtr ((Plugin*) 0);
        }
 }
+
+LadspaPluginInfo::LadspaPluginInfo()
+{
+       type = ARDOUR::LADSPA;
+}