summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slv2/slv2.h282
-rw-r--r--slv2/slv2mm.hpp1
-rw-r--r--src/collections.c170
-rw-r--r--src/plugin.c27
-rw-r--r--src/plugins.c74
-rw-r--r--src/pluginui.c2
-rw-r--r--src/pluginuiinstance.c2
-rw-r--r--src/port.c12
-rw-r--r--src/slv2_internal.h9
-rw-r--r--src/world.c23
-rw-r--r--test/slv2_test.c101
-rw-r--r--utils/lv2_inspect.c78
-rw-r--r--utils/lv2_jack_host.c1
-rw-r--r--utils/lv2_list.c7
-rw-r--r--wscript1
15 files changed, 413 insertions, 377 deletions
diff --git a/slv2/slv2.h b/slv2/slv2.h
index 61af2e4..c4c2420 100644
--- a/slv2/slv2.h
+++ b/slv2/slv2.h
@@ -54,11 +54,7 @@
#endif
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
- #ifdef SLV2_INTERNAL
- #define SLV2_DEPRECATED
- #else
- #define SLV2_DEPRECATED __attribute__((__deprecated__))
- #endif
+ #define SLV2_DEPRECATED __attribute__((__deprecated__))
#else
#define SLV2_DEPRECATED
#endif
@@ -86,9 +82,9 @@ typedef struct _SLV2World* SLV2World; /**< SLV2 World. */
typedef void* SLV2PluginClasses; /**< set<PluginClass>. */
typedef void* SLV2Plugins; /**< set<Plugin>. */
-typedef void* SLV2ScalePoints; /**< array<ScalePoint>. */
+typedef void* SLV2ScalePoints; /**< set<ScalePoint>. */
typedef void* SLV2UIs; /**< set<UI>. */
-typedef void* SLV2Values; /**< array<Value>. */
+typedef void* SLV2Values; /**< set<Value>. */
/**
@defgroup slv2 SLV2
@@ -314,71 +310,211 @@ slv2_value_as_bool(SLV2Value value);
@{
*/
-#define SLV2_COLLECTION(CollType, ElemType, prefix) \
-\
+/* Iter */
+
+typedef void* SLV2Iter;
+
+SLV2_API
+SLV2Iter
+slv2_iter_next(SLV2Iter i);
+
+SLV2_API
+bool
+slv2_iter_end(SLV2Iter i);
+
+/* Collection */
+
+typedef void* SLV2Collection;
+
/**
Free @a collection.
-*/ \
-SLV2_API \
-void \
-prefix ## _free(CollType collection); \
-\
-\
+*/
+SLV2_API
+void
+slv2_collection_free(SLV2Collection collection);
+
/**
Get the number of elements in @a collection.
-*/ \
-SLV2_API \
-unsigned \
-prefix ## _size(CollType collection); \
-\
-\
+*/
+SLV2_API
+unsigned
+slv2_collection_size(SLV2Collection collection);
+
/**
Get an element from @a collection by index.
- @a index has no significance other than as an index into this collection.
+
+ @a index has no significance other than as an index into @a collection.
+
Any @a index not less than the size of the collection will return NULL,
so all elements in a collection can be enumerated by repeated calls
to this function starting with @a index = 0.
+
+ Note this function is a search, and not constant time.
+ This function is deprecated, use iterators instead.
+
@return NULL if @a index is out of range.
-*/ \
-SLV2_API \
-ElemType \
-prefix ## _get_at(CollType collection, \
- unsigned index);
+*/
+SLV2_API
+void*
+slv2_collection_get_at(SLV2Collection collection,
+ unsigned index);
-SLV2_COLLECTION(SLV2PluginClasses, SLV2PluginClass, slv2_plugin_classes)
-SLV2_COLLECTION(SLV2ScalePoints, SLV2ScalePoint, slv2_scale_points)
-SLV2_COLLECTION(SLV2UIs, SLV2UI, slv2_uis)
-SLV2_COLLECTION(SLV2Values, SLV2Value, slv2_values)
+SLV2_API
+SLV2Iter
+slv2_collection_begin(SLV2Plugins plugins);
-/**
- Free a plugin collection.
- Freeing a plugin collection does not destroy the plugins it contains
- (plugins are owned by the world). @a plugins is invalid after this call.
-*/
SLV2_API
-void
-slv2_plugins_free(SLV2World world,
- SLV2Plugins plugins);
+void*
+slv2_collection_get(SLV2Collection collection,
+ SLV2Iter i);
+
+#define SLV2_FOREACH(iter, collection) \
+ for (SLV2Iter (iter) = slv2_collection_begin(collection); \
+ !slv2_iter_end(i); \
+ i = slv2_iter_next(i))
+
+/* SLV2PluginClasses */
+
+static inline void
+slv2_plugin_classes_free(SLV2PluginClasses collection) {
+ slv2_collection_free(collection);
+}
+
+static inline unsigned
+slv2_plugin_classes_size(SLV2PluginClasses collection) {
+ return slv2_collection_size(collection);
+}
+
+static inline SLV2PluginClass
+slv2_plugin_classes_get(SLV2PluginClasses collection, SLV2Iter i) {
+ return (SLV2PluginClass)slv2_collection_get(collection, i);
+}
+
+SLV2_DEPRECATED
+static inline SLV2PluginClass
+slv2_plugin_classes_get_at(SLV2PluginClasses collection, unsigned index) {
+ return (SLV2PluginClass)slv2_collection_get_at(collection, index);
+}
+
+/* SLV2ScalePoints */
-/**
- Get the number of plugins in the collection.
-*/
SLV2_API
-unsigned
-slv2_plugins_size(SLV2Plugins plugins);
+SLV2ScalePoints
+slv2_scale_points_new(void);
+
+static inline void
+slv2_scale_points_free(SLV2ScalePoints collection) {
+ slv2_collection_free(collection);
+}
+
+static inline unsigned
+slv2_scale_points_size(SLV2ScalePoints collection) {
+ return slv2_collection_size(collection);
+}
+
+static inline SLV2Iter
+slv2_scale_points_begin(SLV2ScalePoints collection) {
+ return slv2_collection_begin(collection);
+}
+
+static inline SLV2ScalePoint
+slv2_scale_points_get(SLV2ScalePoints collection, SLV2Iter i) {
+ return (SLV2ScalePoint)slv2_collection_get(collection, i);
+}
+
+SLV2_DEPRECATED
+static inline SLV2ScalePoint
+slv2_scale_points_get_at(SLV2ScalePoints collection, unsigned index) {
+ return (SLV2ScalePoint)slv2_collection_get_at(collection, index);
+}
+
+/* UIs */
+
+static inline void
+slv2_uis_free(SLV2UIs collection) {
+ slv2_collection_free(collection);
+}
+
+static inline unsigned
+slv2_uis_size(SLV2UIs collection) {
+ return slv2_collection_size(collection);
+}
+
+static inline SLV2Iter
+slv2_uis_begin(SLV2UIs collection) {
+ return slv2_collection_begin(collection);
+}
+
+static inline SLV2UI
+slv2_uis_get(SLV2UIs collection, SLV2Iter i) {
+ return (SLV2UI)slv2_collection_get(collection, i);
+}
+
+SLV2_DEPRECATED
+static inline SLV2UI
+slv2_uis_get_at(SLV2UIs collection, unsigned index) {
+ return (SLV2UI)slv2_collection_get_at(collection, index);
+}
+
+/* Values */
-/**
- Get a plugin from @a plugins by index.
- @a index has no significance other than as an index into this plugins.
- Any @a index not less than slv2_plugins_get_length(plugins) will return NULL,
- so all plugins in a plugins can be enumerated by repeated calls
- to this function starting with @a index = 0.
- @return NULL if @a index out of range.
-*/
SLV2_API
-SLV2Plugin
-slv2_plugins_get_at(SLV2Plugins plugins,
- unsigned index);
+SLV2ScalePoints
+slv2_values_new(void);
+
+static inline void
+slv2_values_free(SLV2Values collection) {
+ slv2_collection_free(collection);
+}
+
+static inline unsigned
+slv2_values_size(SLV2Values collection) {
+ return slv2_collection_size(collection);
+}
+
+static inline SLV2Iter
+slv2_values_begin(SLV2Values collection) {
+ return slv2_collection_begin(collection);
+}
+
+static inline SLV2Value
+slv2_values_get(SLV2Values collection, SLV2Iter i) {
+ return (SLV2Value)slv2_collection_get(collection, i);
+}
+
+static inline SLV2Value
+slv2_values_get_first(SLV2Values collection) {
+ return (SLV2Value)slv2_collection_get(collection, slv2_collection_begin(collection));
+}
+
+SLV2_DEPRECATED
+static inline SLV2Value
+slv2_values_get_at(SLV2Values collection, unsigned index) {
+ return (SLV2Value)slv2_collection_get_at(collection, index);
+}
+
+/* Plugins */
+
+static inline unsigned
+slv2_plugins_size(SLV2Plugins collection) {
+ return slv2_collection_size(collection);
+}
+
+static inline SLV2Iter
+slv2_plugins_begin(SLV2Plugins collection) {
+ return slv2_collection_begin(collection);
+}
+
+static inline SLV2Plugin
+slv2_plugins_get(SLV2Plugins collection, SLV2Iter i) {
+ return (SLV2Plugin)slv2_collection_get(collection, i);
+}
+
+SLV2_DEPRECATED
+static inline SLV2Plugin
+slv2_plugins_get_at(SLV2Plugins collection, unsigned index) {
+ return (SLV2Plugin)slv2_collection_get_at(collection, index);
+}
/**
Get a plugin from @a plugins by URI.
@@ -403,20 +539,6 @@ slv2_plugin_classes_get_by_uri(SLV2PluginClasses classes,
SLV2Value uri);
/**
- Allocate a new, empty SLV2ScalePoints.
-*/
-SLV2_API
-SLV2ScalePoints
-slv2_scale_points_new(void);
-
-/**
- Allocate a new, empty SLV2Values.
-*/
-SLV2_API
-SLV2Values
-slv2_values_new(void);
-
-/**
Return whether @a values contains @a value.
*/
SLV2_API
@@ -523,27 +645,13 @@ slv2_world_get_plugin_classes(SLV2World world);
loaded into memory until a call to an slv2_plugin_* function results in
a query (at which time the data is cached with the SLV2Plugin so future
queries are very fast).
-
- Returned list must be freed by user with slv2_plugins_free. The contained
- plugins are owned by @a world and must not be freed by caller.
-*/
-SLV2_API
-SLV2Plugins
-slv2_world_get_all_plugins(SLV2World world);
-/**
- Return a list of found plugins filtered by a user-defined filter function.
- All plugins currently found in @a world that return true when passed to
- @a include (a pointer to a function which takes an SLV2Plugin and returns
- a bool) will be in the returned list.
-
- Returned list must be freed by user with slv2_plugins_free. The contained
- plugins are owned by @a world and must not be freed by caller.
+ The returned list and the plugins it contains are owned by @a world
+ and must not be freed by caller.
*/
SLV2_API
SLV2Plugins
-slv2_world_get_plugins_by_filter(SLV2World world,
- bool (*include)(SLV2Plugin));
+slv2_world_get_all_plugins(SLV2World world);
/**
Return the plugin with the given @a uri, or NULL if not found.
@@ -1329,7 +1437,6 @@ typedef uint32_t (*SLV2PortUnsubscribeFunction)(LV2UI_Controller controller,
/**
Create a new UI host descriptor.
- @param controller Opaque host pointer passed to each function.
@param write_function Function to send a value to a plugin port.
@param port_index_function Function to get the index for a port by symbol.
@param port_subscribe_function Function to subscribe to port updates.
@@ -1362,6 +1469,7 @@ slv2_ui_host_free(SLV2UIHost ui_host);
@param ui The plugin UI to instantiate.
@param widget_type_uri The type of the desired widget.
@param ui_host UI host descriptor (callbacks).
+ @param controller Opaque host pointer passed to each function.
@param features NULL-terminated array of features the host supports.
NULL may be passed if the host supports no additional features.
diff --git a/slv2/slv2mm.hpp b/slv2/slv2mm.hpp
index 7d203b6..402a7a1 100644
--- a/slv2/slv2mm.hpp
+++ b/slv2/slv2mm.hpp
@@ -155,7 +155,6 @@ struct World {
SLV2_WRAP0(SLV2PluginClasses, world, get_plugin_classes);
SLV2_WRAP0(Plugins, world, get_all_plugins);
//SLV2_WRAP1(Plugin, world, get_plugin_by_uri_string, const char*, uri);
- // TODO: get_plugins_by_filter (takes a function parameter)
SLV2World me;
};
diff --git a/src/collections.c b/src/collections.c
index 43c8af7..ee84f68 100644
--- a/src/collections.c
+++ b/src/collections.c
@@ -27,54 +27,85 @@
#include "slv2_internal.h"
-/* SEQUENCE */
-
-#define SLV2_SEQUENCE_IMPL(CollType, ElemType, prefix, free_func) \
-\
-CollType \
-prefix ## _new() \
-{ \
- return g_sequence_new((GDestroyNotify)free_func); \
-} \
-\
-SLV2_API \
-void \
-prefix ## _free(CollType coll) \
-{ \
- if (coll) \
- g_sequence_free((GSequence*)coll); \
-} \
-\
-SLV2_API \
-unsigned \
-prefix ## _size(CollType coll) \
-{ \
- return (coll ? g_sequence_get_length((GSequence*)coll) : 0); \
-} \
-\
-SLV2_API \
-ElemType \
-prefix ## _get_at(CollType coll, unsigned index) \
-{ \
- if (!coll || index >= prefix ## _size(coll)) { \
- return NULL; \
- } else { \
- GSequenceIter* i = g_sequence_get_iter_at_pos((GSequence*)coll, (int)index); \
- return (ElemType)g_sequence_get(i); \
- } \
-}
-
-SLV2_SEQUENCE_IMPL(SLV2ScalePoints, SLV2ScalePoint,
- slv2_scale_points, &slv2_scale_point_free)
-
-SLV2_SEQUENCE_IMPL(SLV2Values, SLV2Value,
- slv2_values, &slv2_value_free)
-
-SLV2_SEQUENCE_IMPL(SLV2PluginClasses, SLV2PluginClass,
- slv2_plugin_classes, &slv2_plugin_class_free)
-
-SLV2_SEQUENCE_IMPL(SLV2UIs, SLV2UI,
- slv2_uis, &slv2_ui_free)
+/* Generic collection functions */
+
+static inline SLV2Collection
+slv2_collection_new(GDestroyNotify destructor)
+{
+ return g_sequence_new(destructor);
+}
+
+SLV2_API
+void
+slv2_collection_free(SLV2Collection coll)
+{
+ if (coll)
+ g_sequence_free((GSequence*)coll);
+}
+
+SLV2_API
+unsigned
+slv2_collection_size(SLV2Collection coll)
+{
+ return (coll ? g_sequence_get_length((GSequence*)coll) : 0);
+}
+
+SLV2_API
+void*
+slv2_collection_get_at(SLV2Collection coll, unsigned index)
+{
+ if (!coll || index >= slv2_collection_size(coll)) {
+ return NULL;
+ } else {
+ GSequenceIter* i = g_sequence_get_iter_at_pos((GSequence*)coll, (int)index);
+ return g_sequence_get(i);
+ }
+}
+
+SLV2_API
+SLV2Iter
+slv2_collection_begin(SLV2Collection collection)
+{
+ return collection ? g_sequence_get_begin_iter(collection) : NULL;
+}
+
+SLV2_API
+void*
+slv2_collection_get(SLV2Collection collection,
+ SLV2Iter i)
+{
+ return g_sequence_get((GSequenceIter*)i);
+}
+
+/* Constructors */
+
+SLV2_API
+SLV2ScalePoints
+slv2_scale_points_new(void)
+{
+ return slv2_collection_new((GDestroyNotify)slv2_scale_point_free);
+}
+
+SLV2_API
+SLV2Values
+slv2_values_new(void)
+{
+ return slv2_collection_new((GDestroyNotify)slv2_value_free);
+}
+
+SLV2UIs
+slv2_uis_new(void)
+{
+ return slv2_collection_new((GDestroyNotify)slv2_ui_free);
+}
+
+SLV2PluginClasses
+slv2_plugin_classes_new(void)
+{
+ return slv2_collection_new((GDestroyNotify)slv2_plugin_class_free);
+}
+
+/* URI based accessors (for collections of things with URIs) */
SLV2_API
SLV2PluginClass
@@ -90,17 +121,54 @@ slv2_uis_get_by_uri(SLV2UIs coll, SLV2Value uri)
return (SLV2UIs)slv2_sequence_get_by_uri(coll, uri);
}
+/* Plugins */
-/* VALUES */
+SLV2Plugins
+slv2_plugins_new()
+{
+ return g_sequence_new(NULL);
+}
+
+void
+slv2_plugins_free(SLV2World world, SLV2Plugins list)
+{
+ if (list && list != world->plugins)
+ g_sequence_free(list);
+}
+
+SLV2_API
+SLV2Plugin
+slv2_plugins_get_by_uri(SLV2Plugins list, SLV2Value uri)
+{
+ return (SLV2Plugin)slv2_sequence_get_by_uri(list, uri);
+}
+
+
+/* Values */
SLV2_API
bool
slv2_values_contains(SLV2Values list, SLV2Value value)
{
- for (unsigned i = 0; i < slv2_values_size(list); ++i)
- if (slv2_value_equals(slv2_values_get_at(list, i), value))
+ SLV2_FOREACH(i, list)
+ if (slv2_value_equals(slv2_values_get(list, i), value))
return true;
return false;
}
+/* Iterator */
+
+SLV2_API
+SLV2Iter
+slv2_iter_next(SLV2Iter i)
+{
+ return g_sequence_iter_next((GSequenceIter*)i);
+}
+
+SLV2_API
+bool
+slv2_iter_end(SLV2Iter i)
+{
+ return !i || g_sequence_iter_is_end((GSequenceIter*)i);
+}
diff --git a/src/plugin.c b/src/plugin.c
index 4159cdf..e86b16a 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -131,7 +131,7 @@ slv2_plugin_get_unique(SLV2Plugin p, SLV2Node subject, SLV2Node predicate)
sord_node_get_string(predicate));
return NULL;
}
- SLV2Value ret = slv2_value_duplicate(slv2_values_get_at(values, 0));
+ SLV2Value ret = slv2_value_duplicate(slv2_values_get_first(values));
slv2_values_free(values);
return ret;
}
@@ -143,7 +143,7 @@ slv2_plugin_get_one(SLV2Plugin p, SLV2Node subject, SLV2Node predicate)
if (!values) {
return NULL;
}
- SLV2Value ret = slv2_value_duplicate(slv2_values_get_at(values, 0));
+ SLV2Value ret = slv2_value_duplicate(slv2_values_get_first(values));
slv2_values_free(values);
return ret;
}
@@ -152,8 +152,8 @@ static void
slv2_plugin_load(SLV2Plugin p)
{
// Parse all the plugin's data files into RDF model
- for (unsigned i = 0; i < slv2_values_size(p->data_uris); ++i) {
- SLV2Value data_uri_val = slv2_values_get_at(p->data_uris, i);
+ SLV2_FOREACH(i, p->data_uris) {
+ SLV2Value data_uri_val = slv2_values_get(p->data_uris, i);
sord_read_file(p->world->model,
sord_node_get_string(data_uri_val->val.uri_val),
p->bundle_uri->val.uri_val,
@@ -434,7 +434,7 @@ slv2_plugin_get_name(SLV2Plugin plugin)
SLV2Value ret = NULL;
if (results) {
- SLV2Value val = slv2_values_get_at(results, 0);
+ SLV2Value val = slv2_values_get_first(results);
if (slv2_value_is_string(val))
ret = slv2_value_duplicate(val);
slv2_values_free(results);
@@ -653,17 +653,16 @@ SLV2_API
SLV2Values
slv2_plugin_get_supported_features(SLV2Plugin p)
{
- SLV2Values optional = slv2_plugin_get_optional_features(p);
- SLV2Values required = slv2_plugin_get_required_features(p);
- SLV2Values result = slv2_values_new();
- unsigned n_optional = slv2_values_size(optional);
- unsigned n_required = slv2_values_size(required);
- for (unsigned i = 0 ; i < n_optional; ++i)
+ SLV2Values optional = slv2_plugin_get_optional_features(p);
+ SLV2Values required = slv2_plugin_get_required_features(p);
+ SLV2Values result = slv2_values_new();
+
+ SLV2_FOREACH(i, optional)
slv2_array_append(
- result, slv2_value_duplicate(slv2_values_get_at(optional, i)));
- for (unsigned i = 0 ; i < n_required; ++i)
+ result, slv2_value_duplicate(slv2_values_get(optional, i)));
+ SLV2_FOREACH(i, required)
slv2_array_append(
- result, slv2_value_duplicate(slv2_values_get_at(required, i)));
+ result, slv2_value_duplicate(slv2_values_get(required, i)));
slv2_values_free(optional);
slv2_values_free(required);
diff --git a/src/plugins.c b/src/plugins.c
deleted file mode 100644
index 0e62419..0000000
--- a/src/plugins.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- Copyright 2007-2011 David Robillard <http://drobilla.net>
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#define _XOPEN_SOURCE 500
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "slv2_internal.h"
-
-SLV2Plugins
-slv2_plugins_new()
-{
- return g_sequence_new(NULL);
-}
-
-SLV2_API
-void
-slv2_plugins_free(SLV2World world, SLV2Plugins list)
-{
- if (list && list != world->plugins)
- g_sequence_free(list);
-}
-
-SLV2_API
-unsigned
-slv2_plugins_size(SLV2Plugins list)
-{
- return (list ? g_sequence_get_length((GSequence*)list) : 0); \
-}
-
-SLV2_API
-SLV2Plugin
-slv2_plugins_get_by_uri(SLV2Plugins list, SLV2Value uri)
-{
- return (SLV2Plugin)slv2_sequence_get_by_uri(list, uri);
-}
-
-SLV2_API
-SLV2Plugin
-slv2_plugins_get_at(SLV2Plugins list, unsigned index)
-{
- if (!list || index >= slv2_plugins_size(list)) {
- return NULL;
- } else {
- GSequenceIter* i = g_sequence_get_iter_at_pos((GSequence*)list, (int)index);
- return (SLV2Plugin)g_sequence_get(i);
- }
-}
-
diff --git a/src/pluginui.c b/src/pluginui.c
index e857e60..4d61690 100644
--- a/src/pluginui.c
+++ b/src/pluginui.c
@@ -97,7 +97,7 @@ slv2_ui_supported(SLV2UI ui,
#ifdef HAVE_SUIL
return suil_ui_type_supported(
slv2_value_as_uri(widget_type_uri),
- slv2_value_as_uri(slv2_values_get_at(ui->classes, 0)));
+ slv2_value_as_uri(slv2_values_get_first(ui->classes)));
#else
return false;
#endif
diff --git a/src/pluginuiinstance.c b/src/pluginuiinstance.c
index 2c7b60f..189ae6e 100644
--- a/src/pluginuiinstance.c
+++ b/src/pluginuiinstance.c
@@ -94,7 +94,7 @@ slv2_ui_instance_new(SLV2Plugin plugin,
return NULL;
}
- SLV2Value ui_type = slv2_values_get_at(ui->classes, 0);
+ SLV2Value ui_type = slv2_values_get_first(ui->classes);
if (!widget_type_uri) {
widget_type_uri = ui_type;
}
diff --git a/src/port.c b/src/port.c
index cb96bf9..6ae6a08 100644
--- a/src/port.c
+++ b/src/port.c
@@ -57,8 +57,8 @@ slv2_port_is_a(SLV2Plugin plugin,
SLV2Port port,
SLV2Value port_class)
{
- for (unsigned i = 0; i < slv2_values_size(port->classes); ++i)
- if (slv2_value_equals(slv2_values_get_at(port->classes, i), port_class))
+ SLV2_FOREACH(i, port->classes)
+ if (slv2_value_equals(slv2_values_get(port->classes, i), port_class))
return true;
return false;
@@ -209,7 +209,7 @@ slv2_port_get_name(SLV2Plugin p,
SLV2Value ret = NULL;
if (results) {
- SLV2Value val = slv2_values_get_at(results, 0);
+ SLV2Value val = slv2_values_get_first(results);
if (slv2_value_is_string(val))
ret = slv2_value_duplicate(val);
slv2_values_free(results);
@@ -242,7 +242,7 @@ slv2_port_get_range(SLV2Plugin p,
SLV2Values defaults = slv2_port_get_value_by_node(
p, port, p->world->lv2_default_node);
*def = defaults
- ? slv2_value_duplicate(slv2_values_get_at(defaults, 0))
+ ? slv2_value_duplicate(slv2_values_get_first(defaults))
: NULL;
slv2_values_free(defaults);
}
@@ -250,7 +250,7 @@ slv2_port_get_range(SLV2Plugin p,
SLV2Values minimums = slv2_port_get_value_by_node(
p, port, p->world->lv2_minimum_node);
*min = minimums
- ? slv2_value_duplicate(slv2_values_get_at(minimums, 0))
+ ? slv2_value_duplicate(slv2_values_get_first(minimums))
: NULL;
slv2_values_free(minimums);
}
@@ -258,7 +258,7 @@ slv2_port_get_range(SLV2Plugin p,
SLV2Values maximums = slv2_port_get_value_by_node(
p, port, p->world->lv2_maximum_node);
*max = maximums
- ? slv2_value_duplicate(slv2_values_get_at(maximums, 0))
+ ? slv2_value_duplicate(slv2_values_get_first(maximums))
: NULL;
slv2_values_free(maximums);
}
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index a3b4f1e..880f3c5 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -143,6 +143,15 @@ slv2_plugin_get_unique(SLV2Plugin p,
SLV2Plugins
slv2_plugins_new();
+/**
+ Free a plugin collection.
+ Freeing a plugin collection does not destroy the plugins it contains
+ (plugins are owned by the world). @a plugins is invalid after this call.
+*/
+void
+slv2_plugins_free(SLV2World world,
+ SLV2Plugins plugins);
+
/* ********* Instance ********* */
diff --git a/src/world.c b/src/world.c
index 3749f1f..97539c0 100644
--- a/src/world.c
+++ b/src/world.c
@@ -154,13 +154,8 @@ slv2_world_free(SLV2World world)
slv2_value_free(world->doap_name_val);
slv2_value_free(world->lv2_name_val);
-#define SLV2_FOREACH(iter, seq) \
- for (GSequenceIter* (iter) = g_sequence_get_begin_iter(seq); \
- (iter) != g_sequence_get_end_iter(seq); \
- (iter) = g_sequence_iter_next(iter))
-
SLV2_FOREACH(i, world->plugins) {
- SLV2Plugin p = g_sequence_get(i);
+ SLV2Plugin p = slv2_plugins_get(world->plugins, i);
slv2_plugin_free(p);
}
g_sequence_free(world->plugins);
@@ -692,22 +687,6 @@ slv2_world_get_all_plugins(SLV2World world)
}
SLV2_API
-SLV2Plugins
-slv2_world_get_plugins_by_filter(SLV2World world, bool (*include)(SLV2Plugin))
-{
- SLV2Plugins result = slv2_plugins_new();
-
- const unsigned n = slv2_plugins_size(world->plugins);
- for (unsigned i = 0; i < n; ++i) {
- SLV2Plugin p = slv2_plugins_get_at(world->plugins, i);
- if (include(p))
- slv2_sequence_insert(result, p);
- }
-
- return result;
-}
-
-SLV2_API
SLV2Plugin
slv2_world_get_plugin_by_uri_string(SLV2World world,
const char* uri)
diff --git a/test/slv2_test.c b/test/slv2_test.c
index e5c3aea..5635076 100644
--- a/test/slv2_test.c
+++ b/test/slv2_test.c
@@ -324,30 +324,6 @@ test_values()
static int discovery_plugin_found = 0;
-static bool
-discovery_plugin_filter_all(SLV2Plugin plugin)
-{
- return true;
-}
-
-static bool
-discovery_plugin_filter_none(SLV2Plugin plugin)
-{
- return false;
-}
-
-static bool
-discovery_plugin_filter_ours(SLV2Plugin plugin)
-{
- return slv2_value_equals(slv2_plugin_get_uri(plugin), plugin_uri_value);
-}
-
-static bool
-discovery_plugin_filter_fake(SLV2Plugin plugin)
-{
- return slv2_value_equals(slv2_plugin_get_uri(plugin), plugin2_uri_value);
-}
-
static void
discovery_verify_plugin(SLV2Plugin plugin)
{
@@ -370,8 +346,6 @@ discovery_verify_plugin(SLV2Plugin plugin)
int
test_discovery()
{
- SLV2Plugins plugins = NULL;
-
if (!start_bundle(MANIFEST_PREFIXES
":plug a lv2:Plugin ; lv2:binary <foo.so> ; rdfs:seeAlso <plugin.ttl> .\n",
BUNDLE_PREFIXES
@@ -384,64 +358,26 @@ test_discovery()
init_uris();
- /* lookup 1: all plugins (get_all_plugins)
- * lookup 2: all plugins (get_plugins_by_filter, always true)
- * lookup 3: no plugins (get_plugins_by_filter, always false)
- * lookup 4: only example plugin (get_plugins_by_filter)
- * lookup 5: no plugins (get_plugins_by_filter, non-existing plugin)
- */
- for (int lookup = 1; lookup <= 5; lookup++) {
- //printf("Lookup variant %d\n", lookup);
- int expect_found = 0;
- switch (lookup) {
- case 1:
- plugins = slv2_world_get_all_plugins(world);
- TEST_ASSERT(slv2_plugins_size(plugins) > 0);
- expect_found = 1;
- break;
- case 2:
- plugins = slv2_world_get_plugins_by_filter(world,
- discovery_plugin_filter_all);
- TEST_ASSERT(slv2_plugins_size(plugins) > 0);
- expect_found = 1;
- break;
- case 3:
- plugins = slv2_world_get_plugins_by_filter(world,
- discovery_plugin_filter_none);
- TEST_ASSERT(slv2_plugins_size(plugins) == 0);
- break;
- case 4:
- plugins = slv2_world_get_plugins_by_filter(world,
- discovery_plugin_filter_ours);
- TEST_ASSERT(slv2_plugins_size(plugins) == 1);
- expect_found = 1;
- break;
- case 5:
- plugins = slv2_world_get_plugins_by_filter(world,
- discovery_plugin_filter_fake);
- TEST_ASSERT(slv2_plugins_size(plugins) == 0);
- break;
- }
-
- SLV2Plugin explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value);
- TEST_ASSERT((explug != NULL) == expect_found);
- SLV2Plugin explug2 = slv2_plugins_get_by_uri(plugins, plugin2_uri_value);
- TEST_ASSERT(explug2 == NULL);
+ SLV2Plugins plugins = slv2_world_get_all_plugins(world);
+ TEST_ASSERT(slv2_plugins_size(plugins) > 0);
- if (explug && expect_found) {
- SLV2Value name = slv2_plugin_get_name(explug);
- TEST_ASSERT(!strcmp(slv2_value_as_string(name), "Test plugin"));
- slv2_value_free(name);
- }
+ SLV2Plugin explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value);
+ TEST_ASSERT(explug != NULL);
+ SLV2Plugin explug2 = slv2_plugins_get_by_uri(plugins, plugin2_uri_value);
+ TEST_ASSERT(explug2 == NULL);
+
+ if (explug) {
+ SLV2Value name = slv2_plugin_get_name(explug);
+ TEST_ASSERT(!strcmp(slv2_value_as_string(name), "Test plugin"));
+ slv2_value_free(name);
+ }
- discovery_plugin_found = 0;
- for (size_t i = 0; i < slv2_plugins_size(plugins); i++)
- discovery_verify_plugin(slv2_plugins_get_at(plugins, i));
+ discovery_plugin_found = 0;
+ for (size_t i = 0; i < slv2_plugins_size(plugins); i++)
+ discovery_verify_plugin(slv2_plugins_get_at(plugins, i));
- TEST_ASSERT(discovery_plugin_found == expect_found);
- slv2_plugins_free(world, plugins);
- plugins = NULL;
- }
+ TEST_ASSERT(discovery_plugin_found);
+ plugins = NULL;
TEST_ASSERT(slv2_plugins_get_at(plugins, (unsigned)INT_MAX + 1) == NULL);
@@ -471,7 +407,6 @@ test_verify()
SLV2Plugin explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value);
TEST_ASSERT(explug);
TEST_ASSERT(slv2_plugin_verify(explug));
- slv2_plugins_free(world, plugins);
cleanup_uris();
return 1;
}
@@ -492,7 +427,6 @@ test_no_verify()
SLV2Plugin explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value);
TEST_ASSERT(explug);
TEST_ASSERT(!slv2_plugin_verify(explug));
- slv2_plugins_free(world, plugins);
cleanup_uris();
return 1;
}
@@ -906,7 +840,6 @@ test_port()
slv2_value_free(control_class);
slv2_value_free(audio_class);
slv2_value_free(in_class);
- slv2_plugins_free(world, plugins);
cleanup_uris();
return 1;
}
diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c
index 7477fe8..a3245a3 100644
--- a/utils/lv2_inspect.c
+++ b/utils/lv2_inspect.c
@@ -60,13 +60,17 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
return;
}
- SLV2Values classes = slv2_port_get_classes(p, port);
+ bool first = true;
+ SLV2Values classes = slv2_port_get_classes(p, port);
printf("\t\tType: ");
- for (unsigned i = 0; i < slv2_values_size(classes); ++i) {
- printf("%s", slv2_value_as_uri(slv2_values_get_at(classes, i)));
- if (i != slv2_values_size(classes) - 1)
+ SLV2_FOREACH(i, classes) {
+ SLV2Value value = slv2_values_get(classes, i);
+ if (!first) {
printf("\n\t\t ");
+ }
+ printf("%s", slv2_value_as_uri(value));
+ first = false;
}
if (slv2_port_is_a(p, port, event_class)) {
@@ -74,8 +78,9 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
"lv2ev:supportsEvent");
if (slv2_values_size(supported) > 0) {
printf("\n\t\tSupported events:\n");
- for (unsigned i = 0; i < slv2_values_size(supported); ++i) {
- printf("\t\t\t%s\n", slv2_value_as_uri(slv2_values_get_at(supported, i)));
+ SLV2_FOREACH(i, supported) {
+ SLV2Value value = slv2_values_get(supported, i);
+ printf("\t\t\t%s\n", slv2_value_as_uri(value));
}
}
slv2_values_free(supported);
@@ -84,8 +89,8 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
SLV2ScalePoints points = slv2_port_get_scale_points(p, port);
if (points)
printf("\n\t\tScale Points:\n");
- for (unsigned i = 0; i < slv2_scale_points_size(points); ++i) {
- SLV2ScalePoint p = slv2_scale_points_get_at(points, i);
+ SLV2_FOREACH(i, points) {
+ SLV2ScalePoint p = slv2_scale_points_get(points, i);
printf("\t\t\t%s = \"%s\"\n",
slv2_value_as_string(slv2_scale_point_get_value(p)),
slv2_value_as_string(slv2_scale_point_get_label(p)));
@@ -101,12 +106,16 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
SLV2Values groups = slv2_port_get_value(p, port, in_group_pred);
if (slv2_values_size(groups) > 0)
- printf("\t\tGroup: %s\n", slv2_value_as_string(slv2_values_get_at(groups, 0)));
+ printf("\t\tGroup: %s\n",
+ slv2_value_as_string(
+ slv2_values_get(groups, slv2_values_begin(groups))));
slv2_values_free(groups);
SLV2Values roles = slv2_port_get_value(p, port, role_pred);
if (slv2_values_size(roles) > 0)
- printf("\t\tRole: %s\n", slv2_value_as_string(slv2_values_get_at(roles, 0)));
+ printf("\t\tRole: %s\n",
+ slv2_value_as_string(
+ slv2_values_get(roles, slv2_values_begin(roles))));
slv2_values_free(roles);
if (slv2_port_is_a(p, port, control_class)) {
@@ -121,11 +130,13 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
SLV2Values properties = slv2_port_get_properties(p, port);
if (slv2_values_size(properties) > 0)
printf("\t\tProperties: ");
- for (unsigned i = 0; i < slv2_values_size(properties); ++i) {
- if (i > 0) {
+ first = true;
+ SLV2_FOREACH(i, properties) {
+ if (!first) {
printf("\t\t ");
}
- printf("%s\n", slv2_value_as_uri(slv2_values_get_at(properties, i)));
+ printf("%s\n", slv2_value_as_uri(slv2_values_get(properties, i)));
+ first = false;
}
if (slv2_values_size(properties) > 0)
printf("\n");
@@ -187,34 +198,36 @@ print_plugin(SLV2Plugin p)
SLV2UIs uis = slv2_plugin_get_uis(p);
if (slv2_values_size(uis) > 0) {
printf("\tUI: ");
- for (unsigned i = 0; i < slv2_uis_size(uis); ++i) {
- SLV2UI ui = slv2_uis_get_at(uis, i);
+ SLV2_FOREACH(i, uis) {
+ SLV2UI ui = slv2_uis_get(uis, i);
printf("%s\n", slv2_value_as_uri(slv2_ui_get_uri(ui)));
const char* binary = slv2_value_as_uri(slv2_ui_get_binary_uri(ui));
SLV2Values types = slv2_ui_get_classes(ui);
- for (unsigned i = 0; i < slv2_values_size(types); ++i) {
+ SLV2_FOREACH(i, types) {
printf("\t Class: %s\n",
- slv2_value_as_uri(slv2_values_get_at(types, i)));
+ slv2_value_as_uri(slv2_values_get(types, i)));
}
if (binary)
printf("\t Binary: %s\n", binary);
printf("\t Bundle: %s\n",
- slv2_value_as_uri(slv2_ui_get_bundle_uri(ui)));
+ slv2_value_as_uri(slv2_ui_get_bundle_uri(ui)));
}
}
slv2_uis_free(uis);
printf("\tData URIs: ");
SLV2Values data_uris = slv2_plugin_get_data_uris(p);
- for (unsigned i = 0; i < slv2_values_size(data_uris); ++i) {
- if (i > 0) {
+ bool first = true;
+ SLV2_FOREACH(i, data_uris) {
+ if (!first) {
printf("\n\t ");
}
- printf("%s", slv2_value_as_uri(slv2_values_get_at(data_uris, i)));
+ printf("%s", slv2_value_as_uri(slv2_values_get(data_uris, i)));
+ first = false;
}
printf("\n");
@@ -223,11 +236,13 @@ print_plugin(SLV2Plugin p)
SLV2Values features = slv2_plugin_get_required_features(p);
if (features)
printf("\tRequired Features: ");
- for (unsigned i = 0; i < slv2_values_size(features); ++i) {
- if (i > 0) {
+ first = true;
+ SLV2_FOREACH(i, data_uris) {
+ if (!first) {
printf("\n\t ");
}
- printf("%s", slv2_value_as_uri(slv2_values_get_at(features, i)));
+ printf("%s", slv2_value_as_uri(slv2_values_get(features, i)));
+ first = false;
}
if (features)
printf("\n");
@@ -238,11 +253,13 @@ print_plugin(SLV2Plugin p)
features = slv2_plugin_get_optional_features(p);
if (features)
printf("\tOptional Features: ");
- for (unsigned i = 0; i < slv2_values_size(features); ++i) {
- if (i > 0) {
+ first = true;
+ SLV2_FOREACH(i, features) {
+ if (!first) {
printf("\n\t ");
}
- printf("%s", slv2_value_as_uri(slv2_values_get_at(features, i)));
+ printf("%s", slv2_value_as_uri(slv2_values_get(features, i)));
+ first = false;
}
if (features)
printf("\n");
@@ -253,11 +270,11 @@ print_plugin(SLV2Plugin p)
SLV2Values presets = slv2_plugin_get_value(p, preset_pred);
if (presets)
printf("\tPresets: \n");
- for (unsigned i = 0; i < slv2_values_size(presets); ++i) {
+ SLV2_FOREACH(i, presets) {
SLV2Values titles = slv2_plugin_get_value_for_subject(
- p, slv2_values_get_at(presets, i), title_pred);
+ p, slv2_values_get(presets, i), title_pred);
if (titles) {
- SLV2Value title = slv2_values_get_at(titles, 0);
+ SLV2Value title = slv2_values_get(titles, slv2_values_begin(titles));
printf("\t %s\n", slv2_value_as_string(title));
}
}
@@ -349,7 +366,6 @@ main(int argc, char** argv)
ret = (p != NULL ? 0 : -1);
slv2_value_free(uri);
- slv2_plugins_free(world, plugins);
done:
slv2_value_free(title_pred);
diff --git a/utils/lv2_jack_host.c b/utils/lv2_jack_host.c
index 65ecc56..9e34f88 100644
--- a/utils/lv2_jack_host.c
+++ b/utils/lv2_jack_host.c
@@ -452,7 +452,6 @@ main(int argc, char** argv)
slv2_value_free(host.event_class);
slv2_value_free(host.midi_class);
slv2_value_free(host.optional);
- slv2_plugins_free(world, plugins);
slv2_world_free(world);
#ifdef SLV2_JACK_SESSION
diff --git a/utils/lv2_list.c b/utils/lv2_list.c
index a6ba803..c589cb0 100644
--- a/utils/lv2_list.c
+++ b/utils/lv2_list.c
@@ -34,8 +34,10 @@
void
list_plugins(SLV2Plugins list, bool show_names)
{
- for (unsigned i=0; i < slv2_plugins_size(list); ++i) {
- SLV2Plugin p = slv2_plugins_get_at(list, i);
+ for (SLV2Iter i = slv2_plugins_begin(list);
+ !slv2_iter_end(i);
+ i = slv2_iter_next(i)) {
+ SLV2Plugin p = slv2_plugins_get(list, i);
if (show_names) {
SLV2Value n = slv2_plugin_get_name(p);
printf("%s\n", slv2_value_as_string(n));
@@ -96,7 +98,6 @@ main(int argc, char** argv)
list_plugins(plugins, show_names);
- slv2_plugins_free(world, plugins);
slv2_world_free(world);
return 0;
diff --git a/wscript b/wscript
index 927c5d2..8109b1c 100644
--- a/wscript
+++ b/wscript
@@ -182,7 +182,6 @@ def build(bld):
src/plugin.c
src/pluginclass.c
src/plugininstance.c
- src/plugins.c
src/pluginui.c
src/pluginuiinstance.c
src/port.c