diff options
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | lilv/lilv.h | 14 | ||||
-rw-r--r-- | lilv/lilvmm.hpp | 13 | ||||
-rw-r--r-- | src/plugin.c | 58 | ||||
-rw-r--r-- | wscript | 2 |
5 files changed, 66 insertions, 25 deletions
@@ -1,8 +1,10 @@ -lilv (0.14.5) unstable; +lilv (0.15.0) unstable; * Support atom:supports in lilv_port_supports_event(). + * Add va_list variant of lilv_plugin_get_num_ports_of_class(). * Correctly depend on serd at build time (fix compilation in odd cases) * Disable timestamps in HTML documentation for reproducible build + * lilvmm.hpp: Support varargs for Plugin::get_num_ports_of_class() -- David Robillard <d@drobilla.net> Thu, 22 Nov 2012 21:47:57 -0500 diff --git a/lilv/lilv.h b/lilv/lilv.h index 30bb3f5..5ef5e59 100644 --- a/lilv/lilv.h +++ b/lilv/lilv.h @@ -21,6 +21,7 @@ #ifndef LILV_LILV_H #define LILV_LILV_H +#include <stdarg.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> @@ -858,6 +859,19 @@ uint32_t lilv_plugin_get_num_ports_of_class(const LilvPlugin* p, const LilvNode* class_1, ...); +#ifndef SWIG +/** + Variant of lilv_plugin_get_num_ports_of_class() that takes a va_list. + + This function calls va_arg() on @p args but does not call va_end(). +*/ +LILV_API +uint32_t +lilv_plugin_get_num_ports_of_class_va(const LilvPlugin* p, + const LilvNode* class_1, + va_list args); +#endif + /** Return whether or not the plugin introduces (and reports) latency. The index of the latency port can be found with lilv_plugin_get_latency_port diff --git a/lilv/lilvmm.hpp b/lilv/lilvmm.hpp index 67fbbc4..2ce29f8 100644 --- a/lilv/lilvmm.hpp +++ b/lilv/lilvmm.hpp @@ -206,10 +206,15 @@ struct Plugin { me, min_values, max_values, def_values); } - inline unsigned get_num_ports_of_class(LilvNode* class_1, - LilvNode* class_2) { - // TODO: varargs - return lilv_plugin_get_num_ports_of_class(me, class_1, class_2, NULL); + inline unsigned get_num_ports_of_class(LilvNode* class_1, ...) { + va_list args; + va_start(args, class_1); + + const uint32_t count = lilv_plugin_get_num_ports_of_class_va( + me, class_1, args); + + va_end(args); + return count; } const LilvPlugin* me; diff --git a/src/plugin.c b/src/plugin.c index 4decba7..9912112 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -528,37 +528,57 @@ lilv_plugin_get_port_ranges_float(const LilvPlugin* p, LILV_API uint32_t -lilv_plugin_get_num_ports_of_class(const LilvPlugin* p, - const LilvNode* class_1, ...) +lilv_plugin_get_num_ports_of_class_va(const LilvPlugin* p, + const LilvNode* class_1, + va_list args) { lilv_plugin_load_ports_if_necessary(p); - uint32_t ret = 0; - va_list args; + uint32_t count = 0; + // Build array of classes from args so we can walk it several times + size_t n_classes = 0; + const LilvNode** classes = NULL; + for (LilvNode* class_i = NULL; (class_i = va_arg(args, LilvNode*)); ) { + classes = (const LilvNode**)realloc( + classes, ++n_classes * sizeof(LilvNode*)); + classes[n_classes - 1] = class_i; + } + + // Check each port against every type for (unsigned i = 0; i < p->num_ports; ++i) { LilvPort* port = p->ports[i]; - if (!port || !lilv_port_is_a(p, port, class_1)) - continue; - - va_start(args, class_1); + if (port && lilv_port_is_a(p, port, class_1)) { + bool matches = true; + for (size_t j = 0; j < n_classes; ++j) { + if (!lilv_port_is_a(p, port, classes[j])) { + matches = false; + break; + } + } - bool matches = true; - for (LilvNode* class_i = NULL; (class_i = va_arg(args, LilvNode*)); ) { - if (!lilv_port_is_a(p, port, class_i)) { - va_end(args); - matches = false; - break; + if (matches) { + ++count; } } + } - if (matches) - ++ret; + free(classes); + return count; +} - va_end(args); - } +LILV_API +uint32_t +lilv_plugin_get_num_ports_of_class(const LilvPlugin* p, + const LilvNode* class_1, ...) +{ + va_list args; + va_start(args, class_1); - return ret; + uint32_t count = lilv_plugin_get_num_ports_of_class_va(p, class_1, args); + + va_end(args); + return count; } LILV_API @@ -9,7 +9,7 @@ import waflib.extras.autowaf as autowaf # major increment <=> incompatible changes # minor increment <=> compatible changes (additions) # micro increment <=> no interface changes -LILV_VERSION = '0.14.5' +LILV_VERSION = '0.15.0' LILV_MAJOR_VERSION = '0' # Mandatory waf variables |