summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lilv/lilv.h11
-rw-r--r--src/lilv_internal.h1
-rw-r--r--src/plugin.c28
-rw-r--r--src/world.c1
-rw-r--r--test/lilv_test.c11
5 files changed, 43 insertions, 9 deletions
diff --git a/lilv/lilv.h b/lilv/lilv.h
index f41a4a9..fb9a7d9 100644
--- a/lilv/lilv.h
+++ b/lilv/lilv.h
@@ -899,15 +899,14 @@ lilv_plugin_get_port_by_symbol(const LilvPlugin* plugin,
const LilvNode* symbol);
/**
- Get a port on @c plugin by an lv2:PortProperty.
- This function only makes sense for port properties which apply to a single
- port per plugin (like lv2:reportsLatency). Otherwise, the matching port
- with the lowest index will be returned.
+ Get a port on @c plugin by the lv2:relation it represents.
+ If the plugin has multiple ports with the same relation (which it should
+ not), the one with the lowest index will be returned.
*/
LILV_API
LilvPort*
-lilv_plugin_get_port_by_property(const LilvPlugin* plugin,
- const LilvNode* port_property);
+lilv_plugin_get_port_by_relation(const LilvPlugin* plugin,
+ const LilvNode* relation);
/**
Get the full name of the plugin's author.
diff --git a/src/lilv_internal.h b/src/lilv_internal.h
index 18aaed5..a6d53f7 100644
--- a/src/lilv_internal.h
+++ b/src/lilv_internal.h
@@ -150,6 +150,7 @@ struct LilvWorldImpl {
SordNode* lv2_Plugin;
SordNode* lv2_port;
SordNode* lv2_portProperty;
+ SordNode* lv2_relation;
SordNode* lv2_reportsLatency;
SordNode* lv2_requiredFeature;
SordNode* lv2_Specification;
diff --git a/src/plugin.c b/src/plugin.c
index c6d36a7..df113a0 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -585,8 +585,7 @@ lilv_plugin_has_latency(const LilvPlugin* p)
return ret;
}
-LILV_API
-LilvPort*
+static LilvPort*
lilv_plugin_get_port_by_property(const LilvPlugin* plugin,
const LilvNode* port_property)
{
@@ -611,6 +610,31 @@ lilv_plugin_get_port_by_property(const LilvPlugin* plugin,
}
LILV_API
+LilvPort*
+lilv_plugin_get_port_by_relation(const LilvPlugin* plugin,
+ const LilvNode* relation)
+{
+ 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_relation,
+ relation->val.uri_val);
+
+ const bool found = !lilv_matches_end(iter);
+ lilv_match_end(iter);
+
+ if (found) {
+ return port;
+ }
+ }
+
+ return NULL;
+}
+
+LILV_API
uint32_t
lilv_plugin_get_latency_port_index(const LilvPlugin* p)
{
diff --git a/src/world.c b/src/world.c
index 28a58c5..198a02a 100644
--- a/src/world.c
+++ b/src/world.c
@@ -62,6 +62,7 @@ lilv_world_new(void)
world->uris.lv2_Plugin = NEW_URI(LILV_NS_LV2 "Plugin");
world->uris.lv2_port = NEW_URI(LILV_NS_LV2 "port");
world->uris.lv2_portProperty = NEW_URI(LILV_NS_LV2 "portProperty");
+ world->uris.lv2_relation = NEW_URI(LILV_NS_LV2 "relation");
world->uris.lv2_reportsLatency = NEW_URI(LILV_NS_LV2 "reportsLatency");
world->uris.lv2_requiredFeature = NEW_URI(LILV_NS_LV2 "requiredFeature");
world->uris.lv2_Specification = NEW_URI(LILV_NS_LV2 "Specification");
diff --git a/test/lilv_test.c b/test/lilv_test.c
index b20b9df..b73d9e6 100644
--- a/test/lilv_test.c
+++ b/test/lilv_test.c
@@ -544,7 +544,8 @@ test_plugin(void)
"] , [ "
" a lv2:ControlPort ; a lv2:OutputPort ; "
" lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; "
- " lv2:portProperty lv2:reportsLatency "
+ " lv2:portProperty lv2:reportsLatency ; "
+ " lv2:relation lv2:latency "
"] . \n"
":thing doap:name \"Something else\" .\n"))
return 0;
@@ -612,6 +613,14 @@ test_plugin(void)
TEST_ASSERT(lilv_plugin_has_latency(plug));
TEST_ASSERT(lilv_plugin_get_latency_port_index(plug) == 2);
+ LilvNode* lv2_latency = lilv_new_uri(world,
+ "http://lv2plug.in/ns/lv2core#latency");
+ LilvPort* latency_port = lilv_plugin_get_port_by_relation(
+ plug, lv2_latency);
+
+ TEST_ASSERT(latency_port);
+ TEST_ASSERT(lilv_port_get_index(plug, latency_port) == 2);
+
LilvNode* rt_feature = lilv_new_uri(world,
"http://lv2plug.in/ns/lv2core#hardRTCapable");
LilvNode* event_feature = lilv_new_uri(world,