From 72e3c06d3a6b2558e5e156f917e1c28441819417 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 26 Feb 2012 22:20:40 +0000 Subject: Add lilv_plugin_get_port_by_property() and lilv_port_get_index() as an improved generic alternative to lilv_plugin_get_latency_port_index(). git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@4001 a436a847-0d15-0410-975c-d299462d15a1 --- src/plugin.c | 53 +++++++++++++++++++++++++++-------------------------- src/port.c | 8 ++++++++ 2 files changed, 35 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/plugin.c b/src/plugin.c index dfeff76..c6d36a7 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -586,38 +586,39 @@ lilv_plugin_has_latency(const LilvPlugin* p) } LILV_API -uint32_t -lilv_plugin_get_latency_port_index(const LilvPlugin* p) +LilvPort* +lilv_plugin_get_port_by_property(const LilvPlugin* plugin, + const LilvNode* port_property) { - lilv_plugin_load_if_necessary(p); - SordIter* ports = lilv_world_query_internal( - p->world, - p->plugin_uri->val.uri_val, - p->world->uris.lv2_port, - NULL); + lilv_plugin_load_ports_if_necessary(plugin); + for (uint32_t i = 0; i < plugin->num_ports; ++i) { + LilvPort* port = plugin->ports[i]; + SordIter* iter = lilv_world_query_internal( + plugin->world, + port->node, + plugin->world->uris.lv2_portProperty, + port_property->val.uri_val); - uint32_t ret = 0; - FOREACH_MATCH(ports) { - const SordNode* port = lilv_match_object(ports); - SordIter* reports_latency = lilv_world_query_internal( - p->world, - port, - p->world->uris.lv2_portProperty, - p->world->uris.lv2_reportsLatency); - if (!lilv_matches_end(reports_latency)) { - LilvNode* index = lilv_plugin_get_unique( - p, port, p->world->uris.lv2_index); + const bool found = !lilv_matches_end(iter); + lilv_match_end(iter); - ret = lilv_node_as_int(index); - lilv_node_free(index); - lilv_match_end(reports_latency); - break; + if (found) { + return port; } - lilv_match_end(reports_latency); } - lilv_match_end(ports); - return ret; // FIXME: error handling + return NULL; +} + +LILV_API +uint32_t +lilv_plugin_get_latency_port_index(const LilvPlugin* p) +{ + LilvNode* property = lilv_node_new_from_node( + p->world, p->world->uris.lv2_reportsLatency); + LilvPort* latency_port = lilv_plugin_get_port_by_property(p, property); + lilv_node_free(property); + return latency_port ? latency_port->index : UINT32_MAX; } LILV_API diff --git a/src/port.c b/src/port.c index f008020..f2f8fd6 100644 --- a/src/port.c +++ b/src/port.c @@ -130,6 +130,14 @@ lilv_port_get_value(const LilvPlugin* p, lilv_node_as_node(predicate)); } +LILV_API +uint32_t +lilv_port_get_index(const LilvPlugin* p, + const LilvPort* port) +{ + return port->index; +} + LILV_API const LilvNode* lilv_port_get_symbol(const LilvPlugin* p, -- cgit v1.2.1