summaryrefslogtreecommitdiffstats
path: root/src/plugin.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-02-26 22:20:40 +0000
committerDavid Robillard <d@drobilla.net>2012-02-26 22:20:40 +0000
commit72e3c06d3a6b2558e5e156f917e1c28441819417 (patch)
tree2a82d6701e1a2e75fd1d3d38eb11fbc7fc8b5fce /src/plugin.c
parente1624b6435b3392ed03b8b5d4751cfeb53eb1f61 (diff)
downloadlilv-72e3c06d3a6b2558e5e156f917e1c28441819417.tar.gz
lilv-72e3c06d3a6b2558e5e156f917e1c28441819417.tar.bz2
lilv-72e3c06d3a6b2558e5e156f917e1c28441819417.zip
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
Diffstat (limited to 'src/plugin.c')
-rw-r--r--src/plugin.c53
1 files changed, 27 insertions, 26 deletions
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