Replaced stuff that wasnt supposed to be commited
[ardour.git] / libs / ardour / ladspa_plugin.cc
index 11001655d2974efa014c1d5f5ec3377665397872..c96e14e30a3071cdb50d56dcce5cee62741c22fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000-2002 Paul Davis 
+    Copyright (C) 2000-2006 Paul Davis 
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -51,7 +51,7 @@ using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
-LadspaPlugin::LadspaPlugin (void *mod, AudioEngine& e, Session& session, uint32_t index, jack_nframes_t rate)
+LadspaPlugin::LadspaPlugin (void *mod, AudioEngine& e, Session& session, uint32_t index, nframes_t rate)
        : Plugin (e, session)
 {
        init (mod, index, rate);
@@ -69,7 +69,7 @@ LadspaPlugin::LadspaPlugin (const LadspaPlugin &other)
 }
 
 void
-LadspaPlugin::init (void *mod, uint32_t index, jack_nframes_t rate)
+LadspaPlugin::init (void *mod, uint32_t index, nframes_t rate)
 {
        LADSPA_Descriptor_Function dfunc;
        uint32_t i, port_cnt;
@@ -133,20 +133,9 @@ LadspaPlugin::init (void *mod, uint32_t index, jack_nframes_t rate)
                }
        }
 
-       Plugin::setup_midi_controls ();
+       Plugin::setup_controls ();
 
        latency_compute_run ();
-
-       MIDI::Controllable *mcontrol;
-
-       for (uint32_t i = 0; i < parameter_count(); ++i) {
-               if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) &&
-                   LADSPA_IS_PORT_CONTROL(port_descriptor (i))) {
-                       if ((mcontrol = get_nth_midi_control (i)) != 0) {
-                               mcontrol->midi_rebind (_session.midi_port(), 0);
-                       }
-               }
-       }
 }
 
 LadspaPlugin::~LadspaPlugin ()
@@ -154,7 +143,7 @@ LadspaPlugin::~LadspaPlugin ()
        deactivate ();
        cleanup ();
 
-       GoingAway (this); /* EMIT SIGNAL */
+       GoingAway (); /* EMIT SIGNAL */
        
        /* XXX who should close a plugin? */
 
@@ -169,33 +158,6 @@ LadspaPlugin::~LadspaPlugin ()
        }
 }
 
-void
-LadspaPlugin::store_state (PluginState& state)
-{
-       state.parameters.clear ();
-       
-       for (uint32_t i = 0; i < parameter_count(); ++i){
-
-               if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) && 
-                   LADSPA_IS_PORT_CONTROL(port_descriptor (i))){
-                       pair<uint32_t,float> datum;
-
-                       datum.first = i;
-                       datum.second = shadow_data[i];
-
-                       state.parameters.insert (datum);
-               }
-       }
-}
-
-void
-LadspaPlugin::restore_state (PluginState& state)
-{
-       for (map<uint32_t,float>::iterator i = state.parameters.begin(); i != state.parameters.end(); ++i) {
-               set_parameter (i->first, i->second);
-       }
-}
-
 float
 LadspaPlugin::default_value (uint32_t port)
 {
@@ -318,17 +280,14 @@ LadspaPlugin::set_parameter (uint32_t which, float val)
                shadow_data[which] = (LADSPA_Data) val;
                ParameterChanged (which, val); /* EMIT SIGNAL */
 
-               if (session().get_midi_feedback()) {
-
-                       if (which < parameter_count() && midi_controls[which]) {
-                               midi_controls[which]->send_feedback (val);
-                       }
+               if (which < parameter_count() && controls[which]) {
+                       controls[which]->Changed ();
                }
-
+               
        } else {
                warning << string_compose (_("illegal parameter number used with plugin \"%1\". This may"
-                                     "indicate a change in the plugin design, and presets may be"
-                                     "invalid"), name())
+                                            "indicate a change in the plugin design, and presets may be"
+                                            "invalid"), name())
                        << endmsg;
        }
 }
@@ -380,28 +339,6 @@ LadspaPlugin::get_state()
                        snprintf(buf, sizeof(buf), "%+f", shadow_data[i]);
                        child->add_property("value", string(buf));
                        root->add_child_nocopy (*child);
-
-                       MIDI::Controllable *pcontrol = get_nth_midi_control (i);
-                       
-                       if (pcontrol) {
-
-                               MIDI::eventType ev;
-                               MIDI::byte      additional;
-                               MIDI::channel_t chn;
-                               XMLNode*        midi_node;
-
-                               if (pcontrol->get_control_info (chn, ev, additional)) {
-
-                                       midi_node = child->add_child ("midi-control");
-               
-                                       snprintf (buf, sizeof(buf), "0x%x", ev);
-                                       midi_node->add_property ("event", buf);
-                                       snprintf (buf, sizeof(buf), "%d", chn);
-                                       midi_node->add_property ("channel", buf);
-                                       snprintf (buf, sizeof(buf), "0x%x", additional);
-                                       midi_node->add_property ("additional", buf);
-                               }
-                       }
                }
        }
 
@@ -452,52 +389,6 @@ LadspaPlugin::set_state(const XMLNode& node)
 
                sscanf (port, "%" PRIu32, &port_id);
                set_parameter (port_id, atof(data));
-
-               XMLNodeList midi_kids;
-               XMLNodeConstIterator iter;
-               
-               midi_kids = child->children ("midi-control");
-               
-               for (iter = midi_kids.begin(); iter != midi_kids.end(); ++iter) {
-                       
-                       child = *iter;
-
-                       MIDI::eventType ev = MIDI::on; /* initialize to keep gcc happy */
-                       MIDI::byte additional = 0; /* initialize to keep gcc happy */
-                       MIDI::channel_t chn = 0; /* initialize to keep gcc happy */
-                       bool ok = true;
-                       int xx;
-                       
-                       if ((prop = child->property ("event")) != 0) {
-                               sscanf (prop->value().c_str(), "0x%x", &xx);
-                               ev = (MIDI::eventType) xx;
-                       } else {
-                               ok = false;
-                       }
-                       
-                       if (ok && ((prop = child->property ("channel")) != 0)) {
-                               sscanf (prop->value().c_str(), "%d", &xx);
-                               chn = (MIDI::channel_t) xx;
-                       } else {
-                               ok = false;
-                       }
-                       
-                       if (ok && ((prop = child->property ("additional")) != 0)) {
-                               sscanf (prop->value().c_str(), "0x%x", &xx);
-                               additional = (MIDI::byte) xx;
-                       }
-                       
-                       if (ok) {
-                               MIDI::Controllable* pcontrol = get_nth_midi_control (port_id);
-
-                               if (pcontrol) {
-                                       pcontrol->set_control_type (chn, ev, additional);
-                               }
-
-                       } else {
-                               error << string_compose(_("LADSPA LadspaPlugin MIDI control specification for port %1 is incomplete, so it has been ignored"), port) << endl;
-                       }
-               }
        }
 
        latency_compute_run ();
@@ -571,11 +462,11 @@ LadspaPlugin::describe_parameter (uint32_t which)
        }
 }
 
-jack_nframes_t
+nframes_t
 LadspaPlugin::latency () const
 {
        if (latency_control_port) {
-               return (jack_nframes_t) floor (*latency_control_port);
+               return (nframes_t) floor (*latency_control_port);
        } else {
                return 0;
        }
@@ -598,7 +489,7 @@ LadspaPlugin::automatable () const
 }
 
 int
-LadspaPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t nbufs, int32_t& in_index, int32_t& out_index, jack_nframes_t nframes, jack_nframes_t offset)
+LadspaPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t nbufs, int32_t& in_index, int32_t& out_index, nframes_t nframes, nframes_t offset)
 {
        uint32_t port_index;
        cycles_t then, now;
@@ -670,7 +561,7 @@ LadspaPlugin::print_parameter (uint32_t param, char *buf, uint32_t len) const
 }
 
 void
-LadspaPlugin::run (jack_nframes_t nframes)
+LadspaPlugin::run (nframes_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))) {
@@ -696,7 +587,7 @@ LadspaPlugin::latency_compute_run ()
        uint32_t port_index = 0;
        uint32_t in_index = 0;
        uint32_t out_index = 0;
-       const jack_nframes_t bufsize = 1024;
+       const nframes_t bufsize = 1024;
        LADSPA_Data buffer[bufsize];
 
        memset(buffer,0,sizeof(LADSPA_Data)*bufsize);
@@ -723,3 +614,26 @@ LadspaPlugin::latency_compute_run ()
        run (bufsize);
        deactivate ();
 }
+
+PluginPtr
+LadspaPluginInfo::load (Session& session)
+{
+       try {
+               PluginPtr plugin;
+               void *module;
+
+               if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
+                       error << string_compose(_("LADSPA: cannot load module from \"%1\""), path) << endmsg;
+                       error << dlerror() << endmsg;
+               } else {
+                       plugin.reset (new LadspaPlugin (module, session.engine(), session, index, session.frame_rate()));
+               }
+
+               plugin->set_info(PluginInfoPtr(new LadspaPluginInfo(*this)));
+               return plugin;
+       }
+
+       catch (failed_constructor &err) {
+               return PluginPtr ((Plugin*) 0);
+       }       
+}