Conditionally remove possibly unused functions.
[ardour.git] / libs / ardour / ladspa_plugin.cc
index 6ee810f6b1bd4ef176e388d6101fbb2ba991fc37..db28d6d199b074b04cc9228864164f39fc0b0da4 100644 (file)
@@ -29,7 +29,9 @@
 #include <cstdlib>
 #include <cstdio> // so libraptor doesn't complain
 #include <cmath>
+#ifndef COMPILER_MSVC
 #include <dirent.h>
+#endif
 #include <sys/stat.h>
 #include <cerrno>
 
@@ -40,8 +42,7 @@
 #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"
@@ -126,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))) {
@@ -142,7 +145,7 @@ LadspaPlugin::init (string module_path, uint32_t index, framecnt_t rate)
                                continue;
                        }
 
-                       _shadow_data[i] = default_value (i);
+                       _shadow_data[i] = _default_value (i);
                }
        }
 
@@ -170,7 +173,7 @@ LadspaPlugin::unique_id() const
 }
 
 float
-LadspaPlugin::default_value (uint32_t port)
+LadspaPlugin::_default_value (uint32_t port) const
 {
        const LADSPA_PortRangeHint *prh = port_range_hints();
        float ret = 0.0f;
@@ -372,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;
@@ -379,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()) {
@@ -386,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) {
@@ -408,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 ();
 
@@ -417,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;
@@ -424,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()) {
@@ -431,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){
@@ -455,6 +466,7 @@ LadspaPlugin::set_state_2X (const XMLNode& node, int /* version */)
        }
 
        latency_compute_run ();
+#endif
 
        return 0;
 }
@@ -492,15 +504,14 @@ LadspaPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& des
                desc.upper = 4; /* completely arbitrary */
        }
 
-       if (LADSPA_IS_HINT_INTEGER (prh.HintDescriptor)) {
-               desc.step = 1.0;
-               desc.smallstep = 0.1;
-               desc.largestep = 10.0;
+       if (LADSPA_IS_HINT_HAS_DEFAULT (prh.HintDescriptor)) {
+               desc.normal = _default_value(which);
        } else {
-               float delta = desc.upper - desc.lower;
-               desc.step = delta / 1000.0f;
-               desc.smallstep = delta / 10000.0f;
-               desc.largestep = delta/10.0f;
+               /* if there is no explicit hint for the default
+                * value, use lower bound. This is not great but
+                * better than just assuming '0' which may be out-of range.
+                */
+               desc.normal = desc.lower;
        }
 
        desc.toggled = LADSPA_IS_HINT_TOGGLED (prh.HintDescriptor);
@@ -510,6 +521,9 @@ LadspaPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& des
 
        desc.label = port_names()[which];
 
+       desc.scale_points = get_scale_points(which);
+       desc.update_steps();
+
        return 0;
 }
 
@@ -564,7 +578,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;
@@ -628,10 +642,10 @@ LadspaPlugin::print_parameter (uint32_t param, char *buf, uint32_t len) const
        }
 }
 
-boost::shared_ptr<Plugin::ScalePoints>
+boost::shared_ptr<ScalePoints>
 LadspaPlugin::get_scale_points(uint32_t port_index) const
 {
-       boost::shared_ptr<Plugin::ScalePoints> ret;
+       boost::shared_ptr<ScalePoints> ret;
 #ifdef HAVE_LRDF
        const uint32_t id     = atol(unique_id().c_str());
        lrdf_defaults* points = lrdf_get_scale_values(id, port_index);
@@ -640,7 +654,7 @@ LadspaPlugin::get_scale_points(uint32_t port_index) const
                return ret;
        }
 
-       ret = boost::shared_ptr<Plugin::ScalePoints>(new ScalePoints());
+       ret = boost::shared_ptr<ScalePoints>(new ScalePoints());
 
        for (uint32_t i = 0; i < points->count; ++i) {
                ret->insert(make_pair(points->items[i].label,
@@ -778,11 +792,11 @@ LadspaPlugin::load_preset (PresetRecord r)
        return true;
 }
 
+#ifdef HAVE_LRDF
 /* XXX: should be in liblrdf */
 static void
 lrdf_remove_preset (const char* /*source*/, const char *setting_uri)
 {
-#ifdef HAVE_LRDF
        lrdf_statement p;
        lrdf_statement *q;
        lrdf_statement *i;
@@ -816,8 +830,8 @@ lrdf_remove_preset (const char* /*source*/, const char *setting_uri)
        p.predicate = NULL;
        p.object = NULL;
        lrdf_remove_matches (&p);
-#endif
 }
+#endif
 
 void
 LadspaPlugin::do_remove_preset (string name)
@@ -909,8 +923,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];