Merge branch 'master' into windows
[ardour.git] / libs / ardour / ladspa_plugin.cc
index b30626927615f46fb74e5f236d46683916480ab7..8b089929b50c53ff021e59f64ea6b90de332d8d2 100644 (file)
 
 */
 
+#ifdef WAF_BUILD
+#include "libardour-config.h"
+#endif
+
 #include <inttypes.h>
 
 #include <vector>
 #include <cstdlib>
 #include <cstdio> // so libraptor doesn't complain
 #include <cmath>
+#ifndef COMPILER_MSVC
 #include <dirent.h>
+#endif
 #include <sys/stat.h>
 #include <cerrno>
 
+#ifdef HAVE_LRDF
 #include <lrdf.h>
+#endif
 
 #include "pbd/compose.h"
 #include "pbd/error.h"
 #include "pbd/xml++.h"
-
-#include "midi++/manager.h"
+#include "pbd/stacktrace.h"
 
 #include "ardour/session.h"
 #include "ardour/ladspa_plugin.h"
@@ -120,7 +127,9 @@ LadspaPlugin::init (string module_path, uint32_t index, framecnt_t rate)
        port_cnt = parameter_count();
 
        _control_data = new LADSPA_Data[port_cnt];
+       memset (_control_data, 0, sizeof (LADSPA_Data) * port_cnt);
        _shadow_data = new LADSPA_Data[port_cnt];
+       memset (_shadow_data, 0, sizeof (LADSPA_Data) * port_cnt);
 
        for (i = 0; i < port_cnt; ++i) {
                if (LADSPA_IS_PORT_CONTROL(port_descriptor (i))) {
@@ -366,6 +375,7 @@ LadspaPlugin::set_state (const XMLNode& node, int version)
                return set_state_2X (node, version);
        }
 
+#ifndef NO_PLUGIN_STATE
        XMLNodeList nodes;
        XMLProperty *prop;
        XMLNodeConstIterator iter;
@@ -373,6 +383,7 @@ LadspaPlugin::set_state (const XMLNode& node, int version)
        const char *port;
        const char *data;
        uint32_t port_id;
+#endif
        LocaleGuard lg (X_("POSIX"));
 
        if (node.name() != state_node_name()) {
@@ -380,6 +391,8 @@ LadspaPlugin::set_state (const XMLNode& node, int version)
                return -1;
        }
 
+#ifndef NO_PLUGIN_STATE
+
        nodes = node.children ("Port");
 
        for (iter = nodes.begin(); iter != nodes.end(); ++iter) {
@@ -402,6 +415,7 @@ LadspaPlugin::set_state (const XMLNode& node, int version)
                sscanf (port, "%" PRIu32, &port_id);
                set_parameter (port_id, atof(data));
        }
+#endif
 
        latency_compute_run ();
 
@@ -411,6 +425,7 @@ LadspaPlugin::set_state (const XMLNode& node, int version)
 int
 LadspaPlugin::set_state_2X (const XMLNode& node, int /* version */)
 {
+#ifndef NO_PLUGIN_STATE
        XMLNodeList nodes;
        XMLProperty *prop;
        XMLNodeConstIterator iter;
@@ -418,6 +433,7 @@ LadspaPlugin::set_state_2X (const XMLNode& node, int /* version */)
        const char *port;
        const char *data;
        uint32_t port_id;
+#endif
        LocaleGuard lg (X_("POSIX"));
 
        if (node.name() != state_node_name()) {
@@ -425,6 +441,7 @@ LadspaPlugin::set_state_2X (const XMLNode& node, int /* version */)
                return -1;
        }
 
+#ifndef NO_PLUGIN_STATE
        nodes = node.children ("port");
 
        for(iter = nodes.begin(); iter != nodes.end(); ++iter){
@@ -449,6 +466,7 @@ LadspaPlugin::set_state_2X (const XMLNode& node, int /* version */)
        }
 
        latency_compute_run ();
+#endif
 
        return 0;
 }
@@ -558,7 +576,7 @@ LadspaPlugin::connect_and_run (BufferSet& bufs,
        cycles_t then = get_cycles ();
 
        BufferSet& silent_bufs  = _session.get_silent_buffers(ChanCount(DataType::AUDIO, 1));
-       BufferSet& scratch_bufs = _session.get_silent_buffers(ChanCount(DataType::AUDIO, 1));
+       BufferSet& scratch_bufs = _session.get_scratch_buffers(ChanCount(DataType::AUDIO, 1));
 
        uint32_t audio_in_index  = 0;
        uint32_t audio_out_index = 0;
@@ -625,10 +643,11 @@ LadspaPlugin::print_parameter (uint32_t param, char *buf, uint32_t len) const
 boost::shared_ptr<Plugin::ScalePoints>
 LadspaPlugin::get_scale_points(uint32_t port_index) const
 {
+       boost::shared_ptr<Plugin::ScalePoints> ret;
+#ifdef HAVE_LRDF
        const uint32_t id     = atol(unique_id().c_str());
        lrdf_defaults* points = lrdf_get_scale_values(id, port_index);
 
-       boost::shared_ptr<Plugin::ScalePoints> ret;
        if (!points) {
                return ret;
        }
@@ -641,6 +660,7 @@ LadspaPlugin::get_scale_points(uint32_t port_index) const
        }
 
        lrdf_free_setting_values(points);
+#endif
        return ret;
 }
 
@@ -725,6 +745,7 @@ LadspaPluginInfo::LadspaPluginInfo()
 void
 LadspaPlugin::find_presets ()
 {
+#ifdef HAVE_LRDF
        uint32_t id;
        std::string unique (unique_id());
 
@@ -745,12 +766,14 @@ LadspaPlugin::find_presets ()
                }
                lrdf_free_uris(set_uris);
        }
+#endif
 }
 
 
 bool
 LadspaPlugin::load_preset (PresetRecord r)
 {
+#ifdef HAVE_LRDF
        lrdf_defaults* defs = lrdf_get_setting_values (r.uri.c_str());
 
        if (defs) {
@@ -763,6 +786,7 @@ LadspaPlugin::load_preset (PresetRecord r)
        }
 
        Plugin::load_preset (r);
+#endif
        return true;
 }
 
@@ -770,6 +794,7 @@ LadspaPlugin::load_preset (PresetRecord r)
 static void
 lrdf_remove_preset (const char* /*source*/, const char *setting_uri)
 {
+#ifdef HAVE_LRDF
        lrdf_statement p;
        lrdf_statement *q;
        lrdf_statement *i;
@@ -803,11 +828,13 @@ lrdf_remove_preset (const char* /*source*/, const char *setting_uri)
        p.predicate = NULL;
        p.object = NULL;
        lrdf_remove_matches (&p);
+#endif
 }
 
 void
 LadspaPlugin::do_remove_preset (string name)
 {
+#ifdef HAVE_LRDF
        string const envvar = preset_envvar ();
        if (envvar.empty()) {
                warning << _("Could not locate HOME.  Preset not removed.") << endmsg;
@@ -823,6 +850,7 @@ LadspaPlugin::do_remove_preset (string name)
        lrdf_remove_preset (source.c_str(), p->uri.c_str ());
 
        write_preset_file (envvar);
+#endif
 }
 
 string
@@ -845,6 +873,7 @@ LadspaPlugin::preset_source (string envvar) const
 bool
 LadspaPlugin::write_preset_file (string envvar)
 {
+#ifdef HAVE_LRDF
        string path = string_compose("%1/.ladspa", envvar);
        if (g_mkdir_with_parents (path.c_str(), 0775)) {
                warning << string_compose(_("Could not create %1.  Preset not saved. (%2)"), path, strerror(errno)) << endmsg;
@@ -865,11 +894,15 @@ LadspaPlugin::write_preset_file (string envvar)
        }
 
        return true;
+#else
+       return false;
+#endif
 }
 
 string
 LadspaPlugin::do_save_preset (string name)
 {
+#ifdef HAVE_LRDF
        /* make a vector of pids that are input parameters */
        vector<int> input_parameter_pids;
        for (uint32_t i = 0; i < parameter_count(); ++i) {
@@ -888,8 +921,8 @@ LadspaPlugin::do_save_preset (string name)
 
        lrdf_defaults defaults;
        defaults.count = input_parameter_pids.size ();
-       lrdf_portvalue portvalues[input_parameter_pids.size()];
-       defaults.items = portvalues;
+       std::vector<lrdf_portvalue> portvalues(input_parameter_pids.size());
+       defaults.items = &portvalues[0];
 
        for (vector<int>::size_type i = 0; i < input_parameter_pids.size(); ++i) {
                portvalues[i].pid = input_parameter_pids[i];
@@ -913,6 +946,9 @@ LadspaPlugin::do_save_preset (string name)
        }
 
        return uri;
+#else
+       return string();
+#endif
 }
 
 LADSPA_PortDescriptor