Start of AudioUnit work. COREAUDIO=y is a little destable for now.
[ardour.git] / libs / ardour / ladspa_plugin.cc
index ef136a78078ce8b7b8292632b616d6de713ca1d8..fa19a682e77fcd279a5c064db0225691bf0efd5c 100644 (file)
@@ -49,6 +49,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)
        : Plugin (e, session)
@@ -132,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 ()
@@ -317,17 +307,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;
        }
 }
@@ -379,28 +366,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);
-                               }
-                       }
                }
        }
 
@@ -426,7 +391,7 @@ LadspaPlugin::set_state(const XMLNode& node)
        LocaleGuard lg (X_("POSIX"));
 
        if (node.name() != state_node_name()) {
-               error << _("Bad node send to LadspaPlugin::set_state") << endmsg;
+               error << _("Bad node sent to LadspaPlugin::set_state") << endmsg;
                return -1;
        }
 
@@ -451,52 +416,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 ();
@@ -609,16 +528,16 @@ LadspaPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t nbufs, int32_t& i
        while (port_index < parameter_count()) {
                if (LADSPA_IS_PORT_AUDIO (port_descriptor(port_index))) {
                        if (LADSPA_IS_PORT_INPUT (port_descriptor(port_index))) {
-                               connect_port (port_index, bufs[min((uint32_t) in_index,nbufs)]);
+                               connect_port (port_index, bufs[min((uint32_t) in_index,nbufs - 1)] + offset);
                                //cerr << this << ' ' << name() << " @ " << offset << " inport " << in_index << " = buf " 
-                               //<< min((uint32_t)in_index,nbufs) << " = " << &bufs[min((uint32_t)in_index,nbufs)][offset] << endl;
+                               //     << min((uint32_t)in_index,nbufs) << " = " << &bufs[min((uint32_t)in_index,nbufs)][offset] << endl;
                                in_index++;
 
 
                        } else if (LADSPA_IS_PORT_OUTPUT (port_descriptor (port_index))) {
-                               connect_port (port_index, bufs[min((uint32_t) out_index,nbufs)]);
-                               //cerr << this << ' ' << name() << " @ " << offset << " outport " << out_index << " = buf " 
-                               //<< min((uint32_t)out_index,nbufs) << " = " << &bufs[min((uint32_t)out_index,nbufs)][offset] << endl;
+                               connect_port (port_index, bufs[min((uint32_t) out_index,nbufs - 1)] + offset);
+                               // cerr << this << ' ' << name() << " @ " << offset << " outport " << out_index << " = buf " 
+                               //     << min((uint32_t)out_index,nbufs) << " = " << &bufs[min((uint32_t)out_index,nbufs)][offset] << endl;
                                out_index++;
                        }
                }