summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--lilv/lilv.h21
-rw-r--r--src/plugin.c53
-rw-r--r--src/port.c8
-rw-r--r--wscript2
5 files changed, 59 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index f1d1ff0..2d4291c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,8 @@ lilv (UNRELEASED) unstable; urgency=low
* Update old references to lv2_list (now lv2ls)
* Support compilation as C++ under MSVC++.
* Remove use of wordexp.
+ * Add lilv_plugin_get_port_by_property() and lilv_port_get_index() as an
+ improved generic alternative to lilv_plugin_get_latency_port_index().
-- David Robillard <d@drobilla.net> (UNRELEASED)
diff --git a/lilv/lilv.h b/lilv/lilv.h
index f392b6f..f41a4a9 100644
--- a/lilv/lilv.h
+++ b/lilv/lilv.h
@@ -899,6 +899,17 @@ 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.
+*/
+LILV_API
+LilvPort*
+lilv_plugin_get_port_by_property(const LilvPlugin* plugin,
+ const LilvNode* port_property);
+
+/**
Get the full name of the plugin's author.
Returns NULL if author name is not present.
Returned value must be freed by caller.
@@ -1021,6 +1032,16 @@ lilv_port_supports_event(const LilvPlugin* p,
const LilvNode* event_uri);
/**
+ Get the index of a port.
+ The index is only valid for the life of the plugin and may change between
+ versions. For a stable identifier, use the symbol.
+*/
+LILV_API
+uint32_t
+lilv_port_get_index(const LilvPlugin* plugin,
+ const LilvPort* port);
+
+/**
Get the symbol of a port.
The 'symbol' is a short string, a valid C identifier.
Returned value is owned by @a port and must not be freed.
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
@@ -131,6 +131,14 @@ lilv_port_get_value(const LilvPlugin* p,
}
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,
const LilvPort* port)
diff --git a/wscript b/wscript
index b469ff3..1fdefef 100644
--- a/wscript
+++ b/wscript
@@ -8,7 +8,7 @@ import waflib.Options as Options
import waflib.Logs as Logs
# Version of this package (even if built as a child)
-LILV_VERSION = '0.9.0'
+LILV_VERSION = '0.10.0'
LILV_MAJOR_VERSION = '0'
# Library version (UNIX style major, minor, micro)