add display name to processors (so that it can differ from the "real name"); pay...
[ardour.git] / libs / ardour / ladspa_plugin.cc
index 29f2d16767909392d1b02a75423dbd31ab8158ea..852587896ea6c6d71604cdd6cc320f847177fbd3 100644 (file)
 
 #include <lrdf.h>
 
-#include <pbd/compose.h>
-#include <pbd/error.h>
-#include <pbd/xml++.h>
+#include "pbd/compose.h"
+#include "pbd/error.h"
+#include "pbd/xml++.h"
 
-#include <midi++/manager.h>
+#include "midi++/manager.h"
 
-#include <ardour/ardour.h>
-#include <ardour/session.h>
-#include <ardour/audioengine.h>
-#include <ardour/ladspa_plugin.h>
-#include <ardour/buffer_set.h>
+#include "ardour/ardour.h"
+#include "ardour/session.h"
+#include "ardour/audioengine.h"
+#include "ardour/ladspa_plugin.h"
+#include "ardour/buffer_set.h"
+#include "ardour/audio_buffer.h"
 
-#include <pbd/stl_delete.h>
+#include "pbd/stl_delete.h"
 
 #include "i18n.h"
 #include <locale.h>
@@ -149,13 +150,8 @@ LadspaPlugin::~LadspaPlugin ()
 
         // dlclose (module);
 
-       if (_control_data) {
-               delete [] _control_data;
-       }
-
-       if (_shadow_data) {
-               delete [] _shadow_data;
-       }
+       delete [] _control_data;
+       delete [] _shadow_data;
 }
 
 string
@@ -297,7 +293,7 @@ LadspaPlugin::set_parameter (uint32_t which, float val)
        if (which < _descriptor->PortCount) {
                _shadow_data[which] = (LADSPA_Data) val;
 #if 0
-               ParameterChanged (Parameter(PluginAutomation, which), val); /* EMIT SIGNAL */
+               ParameterChanged (Parameter(PluginAutomation, 0, which), val); /* EMIT SIGNAL */
 
                if (which < parameter_count() && controls[which]) {
                        controls[which]->Changed ();
@@ -353,7 +349,7 @@ LadspaPlugin::get_state()
                if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) && 
                    LADSPA_IS_PORT_CONTROL(port_descriptor (i))){
 
-                       child = new XMLNode("port");
+                       child = new XMLNode("Port");
                        snprintf(buf, sizeof(buf), "%u", i);
                        child->add_property("number", string(buf));
                        snprintf(buf, sizeof(buf), "%+f", _shadow_data[i]);
@@ -388,7 +384,7 @@ LadspaPlugin::set_state(const XMLNode& node)
                return -1;
        }
 
-       nodes = node.children ("port");
+       nodes = node.children ("Port");
 
        for(iter = nodes.begin(); iter != nodes.end(); ++iter){
 
@@ -471,7 +467,7 @@ LadspaPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& des
 }
 
 string
-LadspaPlugin::describe_parameter (Parameter which)
+LadspaPlugin::describe_parameter (Evoral::Parameter which)
 {
        if (which.type() == PluginAutomation && which.id() < parameter_count()) {
                return port_names()[which.id()];
@@ -494,16 +490,16 @@ LadspaPlugin::signal_latency () const
        }
 }
 
-set<Parameter>
+set<Evoral::Parameter>
 LadspaPlugin::automatable () const
 {
-       set<Parameter> ret;
+       set<Evoral::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(), Parameter(PluginAutomation, i));
+                       ret.insert (ret.end(), Evoral::Parameter(PluginAutomation, 0, i));
                }
        }
 
@@ -511,34 +507,25 @@ LadspaPlugin::automatable () const
 }
 
 int
-LadspaPlugin::connect_and_run (BufferSet& bufs, uint32_t& in_index, uint32_t& out_index, nframes_t nframes, nframes_t offset)
+LadspaPlugin::connect_and_run (BufferSet& bufs,
+               ChanMapping in_map, ChanMapping out_map,
+               nframes_t nframes, nframes_t offset)
 {
-       uint32_t port_index = 0;
-       cycles_t then, now;
-
-       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))) {
-                               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))) {
-                               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++;
+       cycles_t now;
+       cycles_t then = get_cycles ();
+
+       uint32_t audio_in_index  = 0;
+       uint32_t audio_out_index = 0;
+       for (uint32_t port_index = 0; port_index < parameter_count(); ++port_index) {
+               if (LADSPA_IS_PORT_AUDIO(port_descriptor(port_index))) {
+                       if (LADSPA_IS_PORT_INPUT(port_descriptor(port_index))) {
+                               const uint32_t buf_index = in_map.get(DataType::AUDIO, audio_in_index++);
+                               connect_port(port_index, bufs.get_audio(buf_index).data(offset));
+                       } else if (LADSPA_IS_PORT_OUTPUT(port_descriptor(port_index))) {
+                               const uint32_t buf_index = out_map.get(DataType::AUDIO, audio_out_index++);
+                               connect_port(port_index, bufs.get_audio(buf_index).data(offset));
                        }
                }
-               port_index++;
        }
        
        run_in_place (nframes);