From 8509d8ff5c1cbcc45785fc296f22ccc8afcd7b70 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 16 Jan 2011 21:02:57 +0200 Subject: [PATCH] Use port symbols when restoring lv2 plugin state. Bug #3717 Backport from 3.0 branch. The fix itself was commited as part of r5055. r5055 needs _port_indices member of the class. _port_indices was introduced in r4547. (cherry picked from commit fc258ef102fa101697814478c83a3a2e83ba614a) Conflicts: libs/ardour/ardour/lv2_plugin.h libs/ardour/lv2_plugin.cc This cherry-pick updates the patch to recent upstream version, from slv2 to lilv. --- libs/ardour/ardour/lv2_plugin.h | 1 + libs/ardour/lv2_plugin.cc | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libs/ardour/ardour/lv2_plugin.h b/libs/ardour/ardour/lv2_plugin.h index 595dcc1a8a..65a8d76b9e 100644 --- a/libs/ardour/ardour/lv2_plugin.h +++ b/libs/ardour/ardour/lv2_plugin.h @@ -141,6 +141,7 @@ class LV2Plugin : public ARDOUR::Plugin float* _latency_control_port; ///< Special output set by plugin bool _was_activated; vector _port_is_input; + map _port_indices; typedef struct { const void* (*extension_data)(const char* uri); } LV2_DataAccess; LV2_DataAccess _data_access_extension_data; diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 6d21091c05..05f17c7d04 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -171,8 +171,10 @@ LV2Plugin::init (LV2World& world, LilvPlugin* plugin, nframes_t rate) designated_input (LILV_NS_LV2 "freeWheeling", params, (void**)&_freewheel_control_port); for (uint32_t i = 0; i < num_ports; ++i) { + const LilvPort* port = lilv_plugin_get_port_by_index(plugin, i); + const LilvNode* sym = lilv_port_get_symbol(_plugin, port); + _port_indices.insert(std::make_pair(lilv_node_as_string(sym), i)); if (parameter_is_control(i)) { - const LilvPort* port = lilv_plugin_get_port_by_index(plugin, i); LilvNode* def; lilv_port_get_range(plugin, port, &def, NULL, NULL); _defaults[i] = def ? lilv_node_as_float(def) : 0.0f; @@ -392,8 +394,8 @@ LV2Plugin::set_state(const XMLNode& node) XMLProperty *prop; XMLNodeConstIterator iter; XMLNode *child; - const char *port; - const char *data; + const char *sym; + const char *value; uint32_t port_id; LocaleGuard lg (X_("POSIX")); @@ -408,22 +410,29 @@ LV2Plugin::set_state(const XMLNode& node) child = *iter; - if ((prop = child->property("number")) != 0) { - port = prop->value().c_str(); + if ((prop = child->property("symbol")) != 0) { + sym = prop->value().c_str(); } else { - warning << _("LV2: no lv2 port number") << endmsg; + warning << _("LV2: port has no symbol, ignored") << endmsg; + continue; + } + + map::iterator i = _port_indices.find(sym); + if (i != _port_indices.end()) { + port_id = i->second; + } else { + warning << _("LV2: port has unknown index, ignored") << endmsg; continue; } if ((prop = child->property("value")) != 0) { - data = prop->value().c_str(); + value = prop->value().c_str(); } else { - warning << _("LV2: no lv2 port data") << endmsg; + warning << _("LV2: port has no value, ignored") << endmsg; continue; } - sscanf (port, "%" PRIu32, &port_id); - set_parameter (port_id, atof(data)); + set_parameter (port_id, atof(value)); } latency_compute_run ();