Add control-focus notifications from bindable widgets.
[ardour.git] / libs / ardour / ladspa_plugin.cc
index ac9c227fba3d7aec3fd79142116e920daf761f3e..3100b0891ffac69e225ceb1cbcf5326e5bed9e4d 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "pbd/compose.h"
 #include "pbd/error.h"
+#include "pbd/locale_guard.h"
 #include "pbd/xml++.h"
 #include "pbd/stacktrace.h"
 
@@ -51,7 +52,7 @@
 
 #include "pbd/stl_delete.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 #include <locale.h>
 
 using namespace std;
@@ -347,8 +348,6 @@ void
 LadspaPlugin::add_state (XMLNode* root) const
 {
        XMLNode *child;
-       char buf[32];
-       LocaleGuard lg ();
 
        for (uint32_t i = 0; i < parameter_count(); ++i){
 
@@ -356,10 +355,8 @@ LadspaPlugin::add_state (XMLNode* root) const
                    LADSPA_IS_PORT_CONTROL(port_descriptor (i))){
 
                        child = new XMLNode("Port");
-                       snprintf(buf, sizeof(buf), "%u", i);
-                       child->add_property("number", string(buf));
-                       snprintf(buf, sizeof(buf), "%+f", _shadow_data[i]);
-                       child->add_property("value", string(buf));
+                       child->set_property("number", i);
+                       child->set_property("value", _shadow_data[i]);
                        root->add_child_nocopy (*child);
                }
        }
@@ -374,14 +371,9 @@ LadspaPlugin::set_state (const XMLNode& node, int version)
 
 #ifndef NO_PLUGIN_STATE
        XMLNodeList nodes;
-       XMLProperty const * prop;
        XMLNodeConstIterator iter;
        XMLNode *child;
-       const char *port;
-       const char *data;
-       uint32_t port_id;
 #endif
-       LocaleGuard lg ();
 
        if (node.name() != state_node_name()) {
                error << _("Bad node sent to LadspaPlugin::set_state") << endmsg;
@@ -396,21 +388,20 @@ LadspaPlugin::set_state (const XMLNode& node, int version)
 
                child = *iter;
 
-               if ((prop = child->property("number")) != 0) {
-                       port = prop->value().c_str();
-               } else {
+               uint32_t port_id;
+               float value;
+
+               if (!child->get_property ("number", port_id)) {
                        warning << _("LADSPA: no ladspa port number") << endmsg;
                        continue;
                }
-               if ((prop = child->property("value")) != 0) {
-                       data = prop->value().c_str();
-               } else {
+
+               if (!child->get_property ("value", value)) {
                        warning << _("LADSPA: no ladspa port data") << endmsg;
                        continue;
                }
 
-               sscanf (port, "%" PRIu32, &port_id);
-               set_parameter (port_id, atof(data));
+               set_parameter (port_id, value);
        }
 #endif
 
@@ -431,7 +422,7 @@ LadspaPlugin::set_state_2X (const XMLNode& node, int /* version */)
        const char *data;
        uint32_t port_id;
 #endif
-       LocaleGuard lg ();
+       LocaleGuard lg;
 
        if (node.name() != state_node_name()) {
                error << _("Bad node sent to LadspaPlugin::set_state") << endmsg;
@@ -477,28 +468,28 @@ LadspaPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& des
 
 
        if (LADSPA_IS_HINT_BOUNDED_BELOW(prh.HintDescriptor)) {
-               desc.min_unbound = false;
                if (LADSPA_IS_HINT_SAMPLE_RATE(prh.HintDescriptor)) {
                        desc.lower = prh.LowerBound * _session.frame_rate();
                } else {
                        desc.lower = prh.LowerBound;
                }
        } else {
-               desc.min_unbound = true;
                desc.lower = 0;
        }
 
 
        if (LADSPA_IS_HINT_BOUNDED_ABOVE(prh.HintDescriptor)) {
-               desc.max_unbound = false;
                if (LADSPA_IS_HINT_SAMPLE_RATE(prh.HintDescriptor)) {
                        desc.upper = prh.UpperBound * _session.frame_rate();
                } else {
                        desc.upper = prh.UpperBound;
                }
        } else {
-               desc.max_unbound = true;
-               desc.upper = 4; /* completely arbitrary */
+               if (LADSPA_IS_HINT_TOGGLED (prh.HintDescriptor)) {
+                       desc.upper = 1;
+               } else {
+                       desc.upper = 4; /* completely arbitrary */
+               }
        }
 
        if (LADSPA_IS_HINT_HAS_DEFAULT (prh.HintDescriptor)) {
@@ -566,10 +557,11 @@ LadspaPlugin::automatable () const
 
 int
 LadspaPlugin::connect_and_run (BufferSet& bufs,
+               framepos_t start, framepos_t end, double speed,
                ChanMapping in_map, ChanMapping out_map,
                pframes_t nframes, framecnt_t offset)
 {
-       Plugin::connect_and_run (bufs, in_map, out_map, nframes, offset);
+       Plugin::connect_and_run (bufs, start, end, speed, in_map, out_map, nframes, offset);
 
        cycles_t now;
        cycles_t then = get_cycles ();
@@ -802,6 +794,7 @@ LadspaPlugin::load_preset (PresetRecord r)
                for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) {
                        if (parameter_is_input (defs->items[i].pid)) {
                                set_parameter(defs->items[i].pid, defs->items[i].value);
+                               PresetPortSetValue (defs->items[i].pid, defs->items[i].value); /* EMIT SIGNAL */
                        }
                }
                lrdf_free_setting_values(defs);