Remove unused header include from ardour/ladspa_plugin.cc
[ardour.git] / libs / ardour / ladspa_plugin.cc
index 6d55423e372463a1485c7a2838ce20b819b2aa25..0614e3334d1d171a5aa6ce7d07841d36a0b78337 100644 (file)
@@ -17,6 +17,9 @@
 
 */
 
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
 #include <vector>
 #include <string>
 
@@ -31,7 +34,6 @@
 
 #include <pbd/compose.h>
 #include <pbd/error.h>
-#include <pbd/pathscanner.h>
 #include <pbd/xml++.h>
 
 #include <midi++/manager.h>
@@ -40,6 +42,7 @@
 #include <ardour/session.h>
 #include <ardour/audioengine.h>
 #include <ardour/ladspa_plugin.h>
+#include <ardour/buffer_set.h>
 
 #include <pbd/stl_delete.h>
 
@@ -132,8 +135,6 @@ LadspaPlugin::init (void *mod, uint32_t index, nframes_t rate)
                }
        }
 
-       Plugin::setup_controls ();
-
        latency_compute_run ();
 }
 
@@ -157,6 +158,33 @@ 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)
 {
@@ -287,11 +315,13 @@ LadspaPlugin::set_parameter (uint32_t which, float val)
 {
        if (which < descriptor->PortCount) {
                shadow_data[which] = (LADSPA_Data) val;
-               ParameterChanged (which, val); /* EMIT SIGNAL */
+#if 0
+               ParameterChanged (Parameter(PluginAutomation, which), val); /* EMIT SIGNAL */
 
                if (which < parameter_count() && controls[which]) {
                        controls[which]->Changed ();
                }
+#endif
                
        } else {
                warning << string_compose (_("illegal parameter number used with plugin \"%1\". This may"
@@ -460,20 +490,23 @@ LadspaPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& des
        return 0;
 }
 
-
 string
-LadspaPlugin::describe_parameter (uint32_t which)
+LadspaPlugin::describe_parameter (Parameter which)
 {
-       if (which < parameter_count()) {
-               return port_names()[which];
+       if (which.type() == PluginAutomation && which.id() < parameter_count()) {
+               return port_names()[which.id()];
        } else {
                return "??";
        }
 }
 
-nframes_t
-LadspaPlugin::latency () const
+ARDOUR::nframes_t
+LadspaPlugin::signal_latency () const
 {
+       if (_user_latency) {
+               return _user_latency;
+       }
+
        if (latency_control_port) {
                return (nframes_t) floor (*latency_control_port);
        } else {
@@ -481,16 +514,16 @@ LadspaPlugin::latency () const
        }
 }
 
-set<uint32_t>
+set<Parameter>
 LadspaPlugin::automatable () const
 {
-       set<uint32_t> ret;
+       set<Parameter> ret;
 
        for (uint32_t i = 0; i < parameter_count(); ++i){
                if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) && 
                    LADSPA_IS_PORT_CONTROL(port_descriptor (i))){
                        
-                       ret.insert (ret.end(), i);
+                       ret.insert (ret.end(), Parameter(PluginAutomation, i));
                }
        }
 
@@ -498,26 +531,28 @@ LadspaPlugin::automatable () const
 }
 
 int
-LadspaPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t nbufs, int32_t& in_index, int32_t& out_index, nframes_t nframes, nframes_t offset)
+LadspaPlugin::connect_and_run (BufferSet& bufs, uint32_t& in_index, uint32_t& out_index, nframes_t nframes, nframes_t offset)
 {
-       uint32_t port_index;
+       uint32_t port_index = 0;
        cycles_t then, now;
 
-       port_index = 0;
-
        then = get_cycles ();
 
+       const uint32_t nbufs = bufs.count().n_audio();
+
        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 - 1)] + offset);
+                               const size_t index = min(in_index, nbufs - 1);
+                               connect_port (port_index, bufs.get_audio(index).data(nframes, offset));
                                //cerr << this << ' ' << name() << " @ " << offset << " inport " << in_index << " = buf " 
                                //     << 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 - 1)] + offset);
+                               const size_t index = min(out_index,nbufs - 1);
+                               connect_port (port_index, bufs.get_audio(index).data(nframes, 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++;
@@ -526,7 +561,7 @@ LadspaPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t nbufs, int32_t& i
                port_index++;
        }
        
-       run (nframes);
+       run_in_place (nframes);
        now = get_cycles ();
        set_cycles ((uint32_t) (now - then));
 
@@ -570,7 +605,7 @@ LadspaPlugin::print_parameter (uint32_t param, char *buf, uint32_t len) const
 }
 
 void
-LadspaPlugin::run (nframes_t nframes)
+LadspaPlugin::run_in_place (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))) {
@@ -620,7 +655,7 @@ LadspaPlugin::latency_compute_run ()
                port_index++;
        }
        
-       run (bufsize);
+       run_in_place (bufsize);
        deactivate ();
 }