diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/collections.c | 182 | ||||
-rw-r--r-- | src/lilv_internal.h | 407 | ||||
-rw-r--r-- | src/plugin.c | 576 | ||||
-rw-r--r-- | src/pluginclass.c | 62 | ||||
-rw-r--r-- | src/plugininstance.c | 46 | ||||
-rw-r--r-- | src/pluginui.c | 88 | ||||
-rw-r--r-- | src/port.c | 252 | ||||
-rw-r--r-- | src/query.c | 100 | ||||
-rw-r--r-- | src/scalepoint.c | 26 | ||||
-rw-r--r-- | src/slv2_internal.h | 428 | ||||
-rw-r--r-- | src/util.c | 16 | ||||
-rw-r--r-- | src/value.c | 280 | ||||
-rw-r--r-- | src/world.c | 504 |
13 files changed, 1460 insertions, 1507 deletions
diff --git a/src/collections.c b/src/collections.c index d8f5e1b..9111835 100644 --- a/src/collections.c +++ b/src/collections.c @@ -16,118 +16,107 @@ #include <glib.h> -#include "slv2_internal.h" +#include "lilv_internal.h" /* Generic collection functions */ -static inline SLV2Collection -slv2_collection_new(GDestroyNotify destructor) +static inline LilvCollection +lilv_collection_new(GDestroyNotify destructor) { return g_sequence_new(destructor); } void -slv2_collection_free(SLV2Collection coll) +lilv_collection_free(LilvCollection coll) { if (coll) g_sequence_free((GSequence*)coll); } unsigned -slv2_collection_size(SLV2Collection coll) +lilv_collection_size(LilvCollection coll) { return (coll ? g_sequence_get_length((GSequence*)coll) : 0); } -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); - } -} - -SLV2Iter -slv2_collection_begin(SLV2Collection collection) +LilvIter +lilv_collection_begin(LilvCollection collection) { return collection ? g_sequence_get_begin_iter(collection) : NULL; } void* -slv2_collection_get(SLV2Collection collection, - SLV2Iter i) +lilv_collection_get(LilvCollection collection, + LilvIter i) { return g_sequence_get((GSequenceIter*)i); } /* Constructors */ -SLV2ScalePoints -slv2_scale_points_new(void) +LilvScalePoints +lilv_scale_points_new(void) { - return slv2_collection_new((GDestroyNotify)slv2_scale_point_free); + return lilv_collection_new((GDestroyNotify)lilv_scale_point_free); } -SLV2Values -slv2_values_new(void) +LilvValues +lilv_values_new(void) { - return slv2_collection_new((GDestroyNotify)slv2_value_free); + return lilv_collection_new((GDestroyNotify)lilv_value_free); } -SLV2UIs -slv2_uis_new(void) +LilvUIs +lilv_uis_new(void) { - return slv2_collection_new((GDestroyNotify)slv2_ui_free); + return lilv_collection_new((GDestroyNotify)lilv_ui_free); } -SLV2PluginClasses -slv2_plugin_classes_new(void) +LilvPluginClasses +lilv_plugin_classes_new(void) { - return slv2_collection_new((GDestroyNotify)slv2_plugin_class_free); + return lilv_collection_new((GDestroyNotify)lilv_plugin_class_free); } /* URI based accessors (for collections of things with URIs) */ -SLV2_API -SLV2PluginClass -slv2_plugin_classes_get_by_uri(SLV2PluginClasses coll, SLV2Value uri) +LILV_API +LilvPluginClass +lilv_plugin_classes_get_by_uri(LilvPluginClasses coll, LilvValue uri) { - return (SLV2PluginClass)slv2_sequence_get_by_uri(coll, uri); + return (LilvPluginClass)lilv_sequence_get_by_uri(coll, uri); } -SLV2_API -SLV2UI -slv2_uis_get_by_uri(SLV2UIs coll, SLV2Value uri) +LILV_API +LilvUI +lilv_uis_get_by_uri(LilvUIs coll, LilvValue uri) { - return (SLV2UIs)slv2_sequence_get_by_uri(coll, uri); + return (LilvUIs)lilv_sequence_get_by_uri(coll, uri); } /* Plugins */ -SLV2Plugins -slv2_plugins_new() +LilvPlugins +lilv_plugins_new() { return g_sequence_new(NULL); } -SLV2_API -SLV2Plugin -slv2_plugins_get_by_uri(SLV2Plugins list, SLV2Value uri) +LILV_API +LilvPlugin +lilv_plugins_get_by_uri(LilvPlugins list, LilvValue uri) { - return (SLV2Plugin)slv2_sequence_get_by_uri(list, uri); + return (LilvPlugin)lilv_sequence_get_by_uri(list, uri); } /* Values */ -SLV2_API +LILV_API bool -slv2_values_contains(SLV2Values list, SLV2Value value) +lilv_values_contains(LilvValues list, LilvValue value) { - SLV2_FOREACH(values, i, list) - if (slv2_value_equals(slv2_values_get(list, i), value)) + LILV_FOREACH(values, i, list) + if (lilv_value_equals(lilv_values_get(list, i), value)) return true; return false; @@ -135,94 +124,87 @@ slv2_values_contains(SLV2Values list, SLV2Value value) /* Iterator */ -SLV2Iter -slv2_iter_next(SLV2Iter i) +LilvIter +lilv_iter_next(LilvIter i) { return g_sequence_iter_next((GSequenceIter*)i); } bool -slv2_iter_end(SLV2Iter i) +lilv_iter_end(LilvIter i) { return !i || g_sequence_iter_is_end((GSequenceIter*)i); } -#define SLV2_COLLECTION_IMPL(prefix, CT, ET) \ -SLV2_API \ +#define LILV_COLLECTION_IMPL(prefix, CT, ET) \ +LILV_API \ unsigned \ prefix##_size(CT collection) { \ - return slv2_collection_size(collection); \ + return lilv_collection_size(collection); \ } \ \ -SLV2_API \ -SLV2Iter \ +LILV_API \ +LilvIter \ prefix##_begin(CT collection) { \ - return slv2_collection_begin(collection); \ + return lilv_collection_begin(collection); \ } \ \ -SLV2_API \ +LILV_API \ ET \ -prefix##_get(CT collection, SLV2Iter i) { \ - return (ET)slv2_collection_get(collection, i); \ +prefix##_get(CT collection, LilvIter i) { \ + return (ET)lilv_collection_get(collection, i); \ } \ \ -SLV2_API \ -SLV2Iter \ -prefix##_next(CT collection, SLV2Iter i) { \ - return slv2_iter_next(i); \ +LILV_API \ +LilvIter \ +prefix##_next(CT collection, LilvIter i) { \ + return lilv_iter_next(i); \ } \ \ -SLV2_API \ +LILV_API \ bool \ -prefix##_is_end(CT collection, SLV2Iter i) { \ - return slv2_iter_end(i); \ -} \ -\ -SLV2_DEPRECATED \ -SLV2_API \ -ET \ -prefix##_get_at(CT collection, unsigned index) { \ - return (ET)slv2_collection_get_at(collection, index); \ +prefix##_is_end(CT collection, LilvIter i) { \ + return lilv_iter_end(i); \ } -SLV2_COLLECTION_IMPL(slv2_plugin_classes, SLV2PluginClasses, SLV2PluginClass) -SLV2_COLLECTION_IMPL(slv2_scale_points, SLV2ScalePoints, SLV2ScalePoint) -SLV2_COLLECTION_IMPL(slv2_uis, SLV2UIs, SLV2UI) -SLV2_COLLECTION_IMPL(slv2_values, SLV2Values, SLV2Value) -SLV2_COLLECTION_IMPL(slv2_plugins, SLV2Plugins, SLV2Plugin) +LILV_COLLECTION_IMPL(lilv_plugin_classes, LilvPluginClasses, LilvPluginClass) +LILV_COLLECTION_IMPL(lilv_scale_points, LilvScalePoints, LilvScalePoint) +LILV_COLLECTION_IMPL(lilv_uis, LilvUIs, LilvUI) +LILV_COLLECTION_IMPL(lilv_values, LilvValues, LilvValue) +LILV_COLLECTION_IMPL(lilv_plugins, LilvPlugins, LilvPlugin) -SLV2_API +LILV_API void -slv2_plugin_classes_free(SLV2PluginClasses collection) { - slv2_collection_free(collection); +lilv_plugin_classes_free(LilvPluginClasses collection) { + lilv_collection_free(collection); } -SLV2_API +LILV_API void -slv2_scale_points_free(SLV2ScalePoints collection) { - slv2_collection_free(collection); +lilv_scale_points_free(LilvScalePoints collection) { + lilv_collection_free(collection); } -SLV2_API +LILV_API void -slv2_uis_free(SLV2UIs collection) { - slv2_collection_free(collection); +lilv_uis_free(LilvUIs collection) { + lilv_collection_free(collection); } -SLV2_API +LILV_API void -slv2_values_free(SLV2Values collection) { - slv2_collection_free(collection); +lilv_values_free(LilvValues collection) { + lilv_collection_free(collection); } -SLV2_API +LILV_API void -slv2_plugins_free(SLV2World world, SLV2Plugins plugins){ +lilv_plugins_free(LilvWorld world, LilvPlugins plugins){ } -SLV2_API -SLV2Value -slv2_values_get_first(SLV2Values collection) { - return (SLV2Value)slv2_collection_get(collection, - slv2_collection_begin(collection)); +LILV_API +LilvValue +lilv_values_get_first(LilvValues collection) { + return (LilvValue)lilv_collection_get(collection, + lilv_collection_begin(collection)); } diff --git a/src/lilv_internal.h b/src/lilv_internal.h new file mode 100644 index 0000000..f856508 --- /dev/null +++ b/src/lilv_internal.h @@ -0,0 +1,407 @@ +/* + Copyright 2007-2011 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef LILV_INTERNAL_H +#define LILV_INTERNAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> + +#ifdef __WIN32__ +#include <windows.h> +#define dlopen(path, flags) LoadLibrary(path) +#define dlclose(lib) FreeLibrary(lib) +#define dlsym GetProcAddress +static inline char* dlerror(void) { return "Unknown error"; } +#else +#include <dlfcn.h> +#endif + +#include <glib.h> + +#include "serd/serd.h" +#include "sord/sord.h" + +#include "lilv-config.h" + +#ifdef LILV_DYN_MANIFEST +#include "lv2/lv2plug.in/ns/ext/dyn-manifest/dyn-manifest.h" +#endif + +#include "lilv/lilv.h" + +#define LILV_NS_DOAP (const uint8_t*)"http://usefulinc.com/ns/doap#" +#define LILV_NS_RDFS (const uint8_t*)"http://www.w3.org/2000/01/rdf-schema#" +#define LILV_NS_LILV (const uint8_t*)"http://drobilla.net/ns/lilv#" +#define LILV_NS_LV2 (const uint8_t*)"http://lv2plug.in/ns/lv2core#" +#define LILV_NS_XSD (const uint8_t*)"http://www.w3.org/2001/XMLSchema#" +#define LILV_NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#" + +typedef SordIter* LilvMatches; +typedef const SordNode* LilvNode; + +#define FOREACH_MATCH(iter) \ + for (; !sord_iter_end(iter); sord_iter_next(iter)) + +static inline const SordNode* +lilv_match_subject(LilvMatches iter) { + SordQuad tup; + sord_iter_get(iter, tup); + return tup[SORD_SUBJECT]; +} + +static inline const SordNode* +lilv_match_object(LilvMatches iter) { + SordQuad tup; + sord_iter_get(iter, tup); + return tup[SORD_OBJECT]; +} + +static inline void +lilv_match_end(LilvMatches iter) +{ + sord_iter_free(iter); +} + +/* ********* PORT ********* */ + +/** Reference to a port on some plugin. */ +struct _LilvPort { + uint32_t index; ///< lv2:index + LilvValue symbol; ///< lv2:symbol + LilvValues classes; ///< rdf:type +}; + +LilvPort lilv_port_new(LilvWorld world, uint32_t index, const char* symbol); +void lilv_port_free(LilvPort port); + +/* ********* Spec ********* */ + +struct _LilvSpec { + SordNode* spec; + SordNode* bundle; + LilvValues data_uris; +}; + +typedef struct _LilvSpec* LilvSpec; + +/* ********* Plugin ********* */ + +/** Header of an LilvPlugin, LilvPluginClass, or LilvUI. + * Any of these structs may be safely casted to _LilvHeader, which is used to + * implement sequences without code duplication (see lilv_sequence_get_by_uri). + */ +struct _LilvHeader { + struct _LilvWorld* world; + LilvValue uri; +}; + +/** Record of an installed/available plugin. + * + * A simple reference to a plugin somewhere on the system. This just holds + * paths of relevant files, the actual data therein isn't loaded into memory. + */ +struct _LilvPlugin { + struct _LilvWorld* world; + LilvValue plugin_uri; + LilvValue bundle_uri; ///< Bundle directory plugin was loaded from + LilvValue binary_uri; ///< lv2:binary + LilvValue dynman_uri; ///< dynamic manifest binary + LilvPluginClass plugin_class; + LilvValues data_uris; ///< rdfs::seeAlso + LilvPort* ports; + uint32_t num_ports; + bool loaded; + bool replaced; +}; + +LilvPlugin lilv_plugin_new(LilvWorld world, LilvValue uri, LilvValue bundle_uri); +void lilv_plugin_load_if_necessary(LilvPlugin p); +void lilv_plugin_free(LilvPlugin plugin); + +LilvValue +lilv_plugin_get_unique(LilvPlugin p, + LilvNode subject, + LilvNode predicate); + +/* ********* Plugins ********* */ + +typedef void* LilvCollection; + +LilvPlugins +lilv_plugins_new(); + + +/** + Increment @a i to point at the next element in the collection. +*/ +LilvIter +lilv_iter_next(LilvIter i); + +/** + Return true iff @a i is at the end of the collection. +*/ +bool +lilv_iter_end(LilvIter i); + +LilvIter +lilv_collection_begin(LilvCollection collection); + +void* +lilv_collection_get(LilvCollection collection, + LilvIter i); + +/** + Free @a collection. +*/ +void +lilv_collection_free(LilvCollection collection); + +/** + Get the number of elements in @a collection. +*/ +unsigned +lilv_collection_size(LilvCollection collection); + +LilvValues +lilv_values_new(void); + +LilvScalePoints +lilv_scale_points_new(void); + + +/* ********* Instance ********* */ + +/** Pimpl portion of LilvInstance */ +struct _LilvInstanceImpl { + void* lib_handle; +}; + +/* ********* Plugin Class ********* */ + +struct _LilvPluginClass { + struct _LilvWorld* world; + LilvValue uri; + LilvValue parent_uri; + LilvValue label; +}; + +LilvPluginClass lilv_plugin_class_new(LilvWorld world, + LilvNode parent_uri, + LilvNode uri, + const char* label); + +void lilv_plugin_class_free(LilvPluginClass plugin_class); + +/* ********* Plugin Classes ********* */ + +LilvPluginClasses lilv_plugin_classes_new(); +void lilv_plugin_classes_free(); + +/* ********* World ********* */ + +typedef struct { + bool dyn_manifest; + bool filter_language; +} LilvOptions; + +/** Model of LV2 (RDF) data loaded from bundles. + */ +struct _LilvWorld { + SordWorld* world; + SordModel* model; + SerdReader* reader; + SerdEnv* namespaces; + unsigned n_read_files; + LilvPluginClass lv2_plugin_class; + LilvPluginClasses plugin_classes; + GSList* specs; + LilvPlugins plugins; + SordNode* dc_replaces_node; + SordNode* dyn_manifest_node; + SordNode* lv2_specification_node; + SordNode* lv2_plugin_node; + SordNode* lv2_binary_node; + SordNode* lv2_default_node; + SordNode* lv2_minimum_node; + SordNode* lv2_maximum_node; + SordNode* lv2_port_node; + SordNode* lv2_portproperty_node; + SordNode* lv2_reportslatency_node; + SordNode* lv2_index_node; + SordNode* lv2_symbol_node; + SordNode* rdf_a_node; + SordNode* rdf_value_node; + SordNode* rdfs_class_node; + SordNode* rdfs_label_node; + SordNode* rdfs_seealso_node; + SordNode* rdfs_subclassof_node; + SordNode* lilv_dmanifest_node; + SordNode* xsd_boolean_node; + SordNode* xsd_decimal_node; + SordNode* xsd_double_node; + SordNode* xsd_integer_node; + LilvValue doap_name_val; + LilvValue lv2_name_val; + LilvOptions opt; +}; + +const uint8_t* +lilv_world_blank_node_prefix(LilvWorld world); +void +lilv_world_load_file(LilvWorld world, const char* file_uri); + +/* ********* Plugin UI ********* */ + +struct _LilvUI { + struct _LilvWorld* world; + LilvValue uri; + LilvValue bundle_uri; + LilvValue binary_uri; + LilvValues classes; +}; + +LilvUIs lilv_uis_new(); + +LilvUI +lilv_ui_new(LilvWorld world, + LilvValue uri, + LilvValue type_uri, + LilvValue binary_uri); + +void lilv_ui_free(LilvUI ui); + +/* ********* Value ********* */ + +typedef enum _LilvValueType { + LILV_VALUE_URI, + LILV_VALUE_QNAME_UNUSED, ///< FIXME: APIBREAK: remove + LILV_VALUE_STRING, + LILV_VALUE_INT, + LILV_VALUE_FLOAT, + LILV_VALUE_BOOL, + LILV_VALUE_BLANK +} LilvValueType; + +struct _LilvValue { + LilvWorld world; + char* str_val; ///< always present + union { + int int_val; + float float_val; + bool bool_val; + SordNode* uri_val; + } val; + LilvValueType type; +}; + +LilvValue lilv_value_new(LilvWorld world, LilvValueType type, const char* val); +LilvValue lilv_value_new_from_node(LilvWorld world, LilvNode node); +LilvNode lilv_value_as_node(LilvValue value); + +int +lilv_header_compare_by_uri(const void* a, const void* b, void* user_data); + +static inline void +lilv_sequence_insert(GSequence* seq, void* value) +{ + g_sequence_insert_sorted(seq, value, lilv_header_compare_by_uri, NULL); +} + +static inline void +lilv_array_append(GSequence* seq, void* value) { + g_sequence_append(seq, value); +} + +struct _LilvHeader* +lilv_sequence_get_by_uri(GSequence* seq, LilvValue uri); + +static inline SordNode* lilv_node_copy(LilvNode node) { + return sord_node_copy(node); +} + +static inline void lilv_node_free(LilvWorld world, SordNode* node) { + sord_node_free(world->world, node); +} + +/* ********* Scale Points ********* */ + +struct _LilvScalePoint { + LilvValue value; + LilvValue label; +}; + +LilvScalePoint lilv_scale_point_new(LilvValue value, LilvValue label); +void lilv_scale_point_free(LilvScalePoint point); + +/* ********* Query Results ********* */ + +LilvMatches lilv_plugin_find_statements(LilvPlugin plugin, + LilvNode subject, + LilvNode predicate, + LilvNode object); + +static inline bool lilv_matches_next(LilvMatches matches) { + return sord_iter_next(matches); +} + +static inline bool lilv_matches_end(LilvMatches matches) { + return sord_iter_end(matches); +} + +LilvValues lilv_values_from_stream_objects(LilvPlugin p, + LilvMatches stream); + +/* ********* Utilities ********* */ + +char* lilv_strjoin(const char* first, ...); +char* lilv_strdup(const char* str); +char* lilv_get_lang(); +uint8_t* lilv_qname_expand(LilvPlugin p, const char* qname); + +typedef void (*VoidFunc)(); + +/** dlsym wrapper to return a function pointer (without annoying warning) */ +static inline VoidFunc +lilv_dlfunc(void* handle, const char* symbol) +{ + typedef VoidFunc (*VoidFuncGetter)(void*, const char*); + VoidFuncGetter dlfunc = (VoidFuncGetter)dlsym; + return dlfunc(handle, symbol); +} + +/* ********* Dynamic Manifest ********* */ +#ifdef LILV_DYN_MANIFEST +static const LV2_Feature* const dman_features = { NULL }; +#endif + +#define LILV_ERROR(str) fprintf(stderr, "ERROR: %s: " str, __func__) +#define LILV_ERRORF(fmt, ...) fprintf(stderr, "ERROR: %s: " fmt, __func__, __VA_ARGS__) + +#define LILV_WARN(str) fprintf(stderr, "WARNING: %s: " str, __func__) +#define LILV_WARNF(fmt, ...) fprintf(stderr, "WARNING: %s: " fmt, __func__, __VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif /* LILV_INTERNAL_H */ diff --git a/src/plugin.c b/src/plugin.c index d5c9880..6ba6676 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -21,32 +21,28 @@ #include <stdlib.h> #include <string.h> -#include "slv2-config.h" -#include "slv2_internal.h" - -#ifdef HAVE_SUIL -#include "suil/suil.h" -#endif +#include "lilv-config.h" +#include "lilv_internal.h" #define NS_UI (const uint8_t*)"http://lv2plug.in/ns/extensions/ui#" #define NS_DOAP (const uint8_t*)"http://usefulinc.com/ns/doap#" #define NS_FOAF (const uint8_t*)"http://xmlns.com/foaf/0.1/" /** Ownership of @a uri is taken */ -SLV2Plugin -slv2_plugin_new(SLV2World world, SLV2Value uri, SLV2Value bundle_uri) +LilvPlugin +lilv_plugin_new(LilvWorld world, LilvValue uri, LilvValue bundle_uri) { assert(bundle_uri); - struct _SLV2Plugin* plugin = malloc(sizeof(struct _SLV2Plugin)); + struct _LilvPlugin* plugin = malloc(sizeof(struct _LilvPlugin)); plugin->world = world; plugin->plugin_uri = uri; plugin->bundle_uri = bundle_uri; plugin->binary_uri = NULL; -#ifdef SLV2_DYN_MANIFEST +#ifdef LILV_DYN_MANIFEST plugin->dynman_uri = NULL; #endif plugin->plugin_class = NULL; - plugin->data_uris = slv2_values_new(); + plugin->data_uris = lilv_values_new(); plugin->ports = NULL; plugin->num_ports = 0; plugin->loaded = false; @@ -56,112 +52,112 @@ slv2_plugin_new(SLV2World world, SLV2Value uri, SLV2Value bundle_uri) } void -slv2_plugin_free(SLV2Plugin p) +lilv_plugin_free(LilvPlugin p) { - slv2_value_free(p->plugin_uri); + lilv_value_free(p->plugin_uri); p->plugin_uri = NULL; - slv2_value_free(p->bundle_uri); + lilv_value_free(p->bundle_uri); p->bundle_uri = NULL; - slv2_value_free(p->binary_uri); + lilv_value_free(p->binary_uri); p->binary_uri = NULL; -#ifdef SLV2_DYN_MANIFEST - slv2_value_free(p->dynman_uri); +#ifdef LILV_DYN_MANIFEST + lilv_value_free(p->dynman_uri); p->dynman_uri = NULL; #endif if (p->ports) { for (uint32_t i = 0; i < p->num_ports; ++i) - slv2_port_free(p->ports[i]); + lilv_port_free(p->ports[i]); free(p->ports); p->ports = NULL; } - slv2_values_free(p->data_uris); + lilv_values_free(p->data_uris); p->data_uris = NULL; free(p); } -static SLV2Values -slv2_plugin_query_node(SLV2Plugin p, SLV2Node subject, SLV2Node predicate) +static LilvValues +lilv_plugin_query_node(LilvPlugin p, LilvNode subject, LilvNode predicate) { - slv2_plugin_load_if_necessary(p); + lilv_plugin_load_if_necessary(p); // <subject> <predicate> ?value - SLV2Matches results = slv2_plugin_find_statements( + LilvMatches results = lilv_plugin_find_statements( p, subject, predicate, NULL); - if (slv2_matches_end(results)) { - slv2_match_end(results); + if (lilv_matches_end(results)) { + lilv_match_end(results); return NULL; } - SLV2Values result = slv2_values_new(); + LilvValues result = lilv_values_new(); FOREACH_MATCH(results) { - SLV2Node node = slv2_match_object(results); - SLV2Value value = slv2_value_new_from_node(p->world, node); + LilvNode node = lilv_match_object(results); + LilvValue value = lilv_value_new_from_node(p->world, node); if (value) - slv2_array_append(result, value); + lilv_array_append(result, value); } - slv2_match_end(results); + lilv_match_end(results); return result; } -SLV2Value -slv2_plugin_get_unique(SLV2Plugin p, SLV2Node subject, SLV2Node predicate) +LilvValue +lilv_plugin_get_unique(LilvPlugin p, LilvNode subject, LilvNode predicate) { - SLV2Values values = slv2_plugin_query_node(p, subject, predicate); - if (!values || slv2_values_size(values) != 1) { - SLV2_ERRORF("Port does not have exactly one `%s' property\n", + LilvValues values = lilv_plugin_query_node(p, subject, predicate); + if (!values || lilv_values_size(values) != 1) { + LILV_ERRORF("Port does not have exactly one `%s' property\n", sord_node_get_string(predicate)); return NULL; } - SLV2Value ret = slv2_value_duplicate(slv2_values_get_first(values)); - slv2_values_free(values); + LilvValue ret = lilv_value_duplicate(lilv_values_get_first(values)); + lilv_values_free(values); return ret; } -static SLV2Value -slv2_plugin_get_one(SLV2Plugin p, SLV2Node subject, SLV2Node predicate) +static LilvValue +lilv_plugin_get_one(LilvPlugin p, LilvNode subject, LilvNode predicate) { - SLV2Values values = slv2_plugin_query_node(p, subject, predicate); + LilvValues values = lilv_plugin_query_node(p, subject, predicate); if (!values) { return NULL; } - SLV2Value ret = slv2_value_duplicate(slv2_values_get_first(values)); - slv2_values_free(values); + LilvValue ret = lilv_value_duplicate(lilv_values_get_first(values)); + lilv_values_free(values); return ret; } static void -slv2_plugin_load(SLV2Plugin p) +lilv_plugin_load(LilvPlugin p) { // Parse all the plugin's data files into RDF model - SLV2_FOREACH(values, i, p->data_uris) { - SLV2Value data_uri_val = slv2_values_get(p->data_uris, i); + LILV_FOREACH(values, i, p->data_uris) { + LilvValue data_uri_val = lilv_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, - slv2_world_blank_node_prefix(p->world)); + lilv_world_blank_node_prefix(p->world)); } -#ifdef SLV2_DYN_MANIFEST +#ifdef LILV_DYN_MANIFEST typedef void* LV2_Dyn_Manifest_Handle; // Load and parse dynamic manifest data, if this is a library if (p->dynman_uri) { - const char* lib_path = slv2_uri_to_path(slv2_value_as_string(p->dynman_uri)); + const char* lib_path = lilv_uri_to_path(lilv_value_as_string(p->dynman_uri)); void* lib = dlopen(lib_path, RTLD_LAZY); if (!lib) { - SLV2_WARNF("Unable to open dynamic manifest %s\n", - slv2_value_as_string(p->dynman_uri)); + LILV_WARNF("Unable to open dynamic manifest %s\n", + lilv_value_as_string(p->dynman_uri)); return; } typedef int (*OpenFunc)(LV2_Dyn_Manifest_Handle*, const LV2_Feature *const *); - OpenFunc open_func = (OpenFunc)slv2_dlfunc(lib, "lv2_dyn_manifest_open"); + OpenFunc open_func = (OpenFunc)lilv_dlfunc(lib, "lv2_dyn_manifest_open"); LV2_Dyn_Manifest_Handle handle = NULL; if (open_func) open_func(&handle, &dman_features); @@ -169,22 +165,22 @@ slv2_plugin_load(SLV2Plugin p) typedef int (*GetDataFunc)(LV2_Dyn_Manifest_Handle handle, FILE* fp, const char* uri); - GetDataFunc get_data_func = (GetDataFunc)slv2_dlfunc( + GetDataFunc get_data_func = (GetDataFunc)lilv_dlfunc( lib, "lv2_dyn_manifest_get_data"); if (get_data_func) { FILE* fd = tmpfile(); - get_data_func(handle, fd, slv2_value_as_string(p->plugin_uri)); + get_data_func(handle, fd, lilv_value_as_string(p->plugin_uri)); rewind(fd); sord_read_file_handle(p->world->model, fd, - (const uint8_t*)slv2_value_as_uri(p->dynman_uri), + (const uint8_t*)lilv_value_as_uri(p->dynman_uri), p->bundle_uri->val.uri_val, - slv2_world_blank_node_prefix(p->world)); + lilv_world_blank_node_prefix(p->world)); fclose(fd); } typedef int (*CloseFunc)(LV2_Dyn_Manifest_Handle); - CloseFunc close_func = (CloseFunc)slv2_dlfunc(lib, "lv2_dyn_manifest_close"); + CloseFunc close_func = (CloseFunc)lilv_dlfunc(lib, "lv2_dyn_manifest_close"); if (close_func) close_func(handle); } @@ -194,185 +190,185 @@ slv2_plugin_load(SLV2Plugin p) } static void -slv2_plugin_load_ports_if_necessary(SLV2Plugin p) +lilv_plugin_load_ports_if_necessary(LilvPlugin p) { if (!p->loaded) - slv2_plugin_load(p); + lilv_plugin_load(p); if (!p->ports) { - p->ports = malloc(sizeof(SLV2Port*)); + p->ports = malloc(sizeof(LilvPort*)); p->ports[0] = NULL; - SLV2Matches ports = slv2_plugin_find_statements( + LilvMatches ports = lilv_plugin_find_statements( p, p->plugin_uri->val.uri_val, p->world->lv2_port_node, NULL); FOREACH_MATCH(ports) { - SLV2Value index = NULL; - SLV2Node port = slv2_match_object(ports); - SLV2Value symbol = slv2_plugin_get_unique( + LilvValue index = NULL; + LilvNode port = lilv_match_object(ports); + LilvValue symbol = lilv_plugin_get_unique( p, port, p->world->lv2_symbol_node); - if (!slv2_value_is_string(symbol)) { - SLV2_ERROR("port has a non-string symbol\n"); + if (!lilv_value_is_string(symbol)) { + LILV_ERROR("port has a non-string symbol\n"); p->num_ports = 0; goto error; } - index = slv2_plugin_get_unique(p, port, p->world->lv2_index_node); + index = lilv_plugin_get_unique(p, port, p->world->lv2_index_node); - if (!slv2_value_is_int(index)) { - SLV2_ERROR("port has a non-integer index\n"); + if (!lilv_value_is_int(index)) { + LILV_ERROR("port has a non-integer index\n"); p->num_ports = 0; goto error; } - uint32_t this_index = slv2_value_as_int(index); - SLV2Port this_port = NULL; + uint32_t this_index = lilv_value_as_int(index); + LilvPort this_port = NULL; if (p->num_ports > this_index) { this_port = p->ports[this_index]; } else { - p->ports = realloc(p->ports, (this_index + 1) * sizeof(SLV2Port*)); + p->ports = realloc(p->ports, (this_index + 1) * sizeof(LilvPort*)); memset(p->ports + p->num_ports, '\0', - (this_index - p->num_ports) * sizeof(SLV2Port)); + (this_index - p->num_ports) * sizeof(LilvPort)); p->num_ports = this_index + 1; } // Havn't seen this port yet, add it to array if (!this_port) { - this_port = slv2_port_new(p->world, + this_port = lilv_port_new(p->world, this_index, - slv2_value_as_string(symbol)); + lilv_value_as_string(symbol)); p->ports[this_index] = this_port; } - SLV2Matches types = slv2_plugin_find_statements( + LilvMatches types = lilv_plugin_find_statements( p, port, p->world->rdf_a_node, NULL); FOREACH_MATCH(types) { - SLV2Node type = slv2_match_object(types); + LilvNode type = lilv_match_object(types); if (sord_node_get_type(type) == SORD_URI) { - slv2_array_append( + lilv_array_append( this_port->classes, - slv2_value_new_from_node(p->world, type)); + lilv_value_new_from_node(p->world, type)); } else { - SLV2_WARN("port has non-URI rdf:type\n"); + LILV_WARN("port has non-URI rdf:type\n"); } } - slv2_match_end(types); + lilv_match_end(types); error: - slv2_value_free(symbol); - slv2_value_free(index); + lilv_value_free(symbol); + lilv_value_free(index); if (p->num_ports == 0) { if (p->ports) { for (uint32_t i = 0; i < p->num_ports; ++i) - slv2_port_free(p->ports[i]); + lilv_port_free(p->ports[i]); free(p->ports); p->ports = NULL; } break; // Invalid plugin } } - slv2_match_end(ports); + lilv_match_end(ports); } } void -slv2_plugin_load_if_necessary(SLV2Plugin p) +lilv_plugin_load_if_necessary(LilvPlugin p) { if (!p->loaded) - slv2_plugin_load(p); + lilv_plugin_load(p); } -SLV2_API -SLV2Value -slv2_plugin_get_uri(SLV2Plugin p) +LILV_API +LilvValue +lilv_plugin_get_uri(LilvPlugin p) { assert(p); assert(p->plugin_uri); return p->plugin_uri; } -SLV2_API -SLV2Value -slv2_plugin_get_bundle_uri(SLV2Plugin p) +LILV_API +LilvValue +lilv_plugin_get_bundle_uri(LilvPlugin p) { assert(p); assert(p->bundle_uri); return p->bundle_uri; } -SLV2_API -SLV2Value -slv2_plugin_get_library_uri(SLV2Plugin p) +LILV_API +LilvValue +lilv_plugin_get_library_uri(LilvPlugin p) { - slv2_plugin_load_if_necessary(p); + lilv_plugin_load_if_necessary(p); if (!p->binary_uri) { // <plugin> lv2:binary ?binary - SLV2Matches results = slv2_plugin_find_statements( + LilvMatches results = lilv_plugin_find_statements( p, p->plugin_uri->val.uri_val, p->world->lv2_binary_node, NULL); FOREACH_MATCH(results) { - SLV2Node binary_node = slv2_match_object(results); + LilvNode binary_node = lilv_match_object(results); if (sord_node_get_type(binary_node) == SORD_URI) { - p->binary_uri = slv2_value_new_from_node(p->world, binary_node); + p->binary_uri = lilv_value_new_from_node(p->world, binary_node); break; } } - slv2_match_end(results); + lilv_match_end(results); } if (!p->binary_uri) { - SLV2_WARNF("Plugin <%s> has no lv2:binary\n", - slv2_value_as_uri(slv2_plugin_get_uri(p))); + LILV_WARNF("Plugin <%s> has no lv2:binary\n", + lilv_value_as_uri(lilv_plugin_get_uri(p))); } return p->binary_uri; } -SLV2_API -SLV2Values -slv2_plugin_get_data_uris(SLV2Plugin p) +LILV_API +LilvValues +lilv_plugin_get_data_uris(LilvPlugin p) { return p->data_uris; } -SLV2_API -SLV2PluginClass -slv2_plugin_get_class(SLV2Plugin p) +LILV_API +LilvPluginClass +lilv_plugin_get_class(LilvPlugin p) { - slv2_plugin_load_if_necessary(p); + lilv_plugin_load_if_necessary(p); if (!p->plugin_class) { // <plugin> a ?class - SLV2Matches results = slv2_plugin_find_statements( + LilvMatches results = lilv_plugin_find_statements( p, p->plugin_uri->val.uri_val, p->world->rdf_a_node, NULL); FOREACH_MATCH(results) { - SLV2Node class_node = slv2_match_object(results); + LilvNode class_node = lilv_match_object(results); if (sord_node_get_type(class_node) != SORD_URI) { continue; } - SLV2Value class = slv2_value_new_from_node(p->world, class_node); - if ( ! slv2_value_equals(class, p->world->lv2_plugin_class->uri)) { + LilvValue class = lilv_value_new_from_node(p->world, class_node); + if ( ! lilv_value_equals(class, p->world->lv2_plugin_class->uri)) { - SLV2PluginClass plugin_class = slv2_plugin_classes_get_by_uri( + LilvPluginClass plugin_class = lilv_plugin_classes_get_by_uri( p->world->plugin_classes, class); if (plugin_class) { p->plugin_class = plugin_class; - slv2_value_free(class); + lilv_value_free(class); break; } } - slv2_value_free(class); + lilv_value_free(class); } - slv2_match_end(results); + lilv_match_end(results); if (p->plugin_class == NULL) p->plugin_class = p->world->lv2_plugin_class; @@ -380,167 +376,167 @@ slv2_plugin_get_class(SLV2Plugin p) return p->plugin_class; } -SLV2_API +LILV_API bool -slv2_plugin_verify(SLV2Plugin plugin) +lilv_plugin_verify(LilvPlugin plugin) { - SLV2Values results = slv2_plugin_get_value_by_qname(plugin, "rdf:type"); + LilvValues results = lilv_plugin_get_value_by_qname(plugin, "rdf:type"); if (!results) { return false; } - slv2_values_free(results); - results = slv2_plugin_get_value(plugin, plugin->world->doap_name_val); + lilv_values_free(results); + results = lilv_plugin_get_value(plugin, plugin->world->doap_name_val); if (!results) { return false; } - slv2_values_free(results); - results = slv2_plugin_get_value_by_qname(plugin, "doap:license"); + lilv_values_free(results); + results = lilv_plugin_get_value_by_qname(plugin, "doap:license"); if (!results) { return false; } - slv2_values_free(results); - results = slv2_plugin_get_value_by_qname(plugin, "lv2:port"); + lilv_values_free(results); + results = lilv_plugin_get_value_by_qname(plugin, "lv2:port"); if (!results) { return false; } - slv2_values_free(results); + lilv_values_free(results); return true; } -SLV2_API -SLV2Value -slv2_plugin_get_name(SLV2Plugin plugin) +LILV_API +LilvValue +lilv_plugin_get_name(LilvPlugin plugin) { - SLV2Values results = slv2_plugin_get_value(plugin, + LilvValues results = lilv_plugin_get_value(plugin, plugin->world->doap_name_val); - SLV2Value ret = NULL; + LilvValue ret = NULL; if (results) { - SLV2Value val = slv2_values_get_first(results); - if (slv2_value_is_string(val)) - ret = slv2_value_duplicate(val); - slv2_values_free(results); + LilvValue val = lilv_values_get_first(results); + if (lilv_value_is_string(val)) + ret = lilv_value_duplicate(val); + lilv_values_free(results); } if (!ret) - SLV2_WARNF("<%s> has no (mandatory) doap:name\n", - slv2_value_as_string(slv2_plugin_get_uri(plugin))); + LILV_WARNF("<%s> has no (mandatory) doap:name\n", + lilv_value_as_string(lilv_plugin_get_uri(plugin))); return ret; } -SLV2_API -SLV2Values -slv2_plugin_get_value(SLV2Plugin p, - SLV2Value predicate) +LILV_API +LilvValues +lilv_plugin_get_value(LilvPlugin p, + LilvValue predicate) { - return slv2_plugin_get_value_for_subject(p, p->plugin_uri, predicate); + return lilv_plugin_get_value_for_subject(p, p->plugin_uri, predicate); } -SLV2_API -SLV2Values -slv2_plugin_get_value_by_qname(SLV2Plugin p, +LILV_API +LilvValues +lilv_plugin_get_value_by_qname(LilvPlugin p, const char* predicate) { - char* pred_uri = (char*)slv2_qname_expand(p, predicate); + char* pred_uri = (char*)lilv_qname_expand(p, predicate); if (!pred_uri) { return NULL; } - SLV2Value pred_value = slv2_value_new_uri(p->world, pred_uri); - SLV2Values ret = slv2_plugin_get_value(p, pred_value); + LilvValue pred_value = lilv_value_new_uri(p->world, pred_uri); + LilvValues ret = lilv_plugin_get_value(p, pred_value); - slv2_value_free(pred_value); + lilv_value_free(pred_value); free(pred_uri); return ret; } -SLV2_API -SLV2Values -slv2_plugin_get_value_for_subject(SLV2Plugin p, - SLV2Value subject, - SLV2Value predicate) +LILV_API +LilvValues +lilv_plugin_get_value_for_subject(LilvPlugin p, + LilvValue subject, + LilvValue predicate) { - if ( ! slv2_value_is_uri(subject) && ! slv2_value_is_blank(subject)) { - SLV2_ERROR("Subject is not a resource\n"); + if ( ! lilv_value_is_uri(subject) && ! lilv_value_is_blank(subject)) { + LILV_ERROR("Subject is not a resource\n"); return NULL; } - if ( ! slv2_value_is_uri(predicate)) { - SLV2_ERROR("Predicate is not a URI\n"); + if ( ! lilv_value_is_uri(predicate)) { + LILV_ERROR("Predicate is not a URI\n"); return NULL; } - SordNode* subject_node = (slv2_value_is_uri(subject)) - ? slv2_node_copy(subject->val.uri_val) + SordNode* subject_node = (lilv_value_is_uri(subject)) + ? lilv_node_copy(subject->val.uri_val) : sord_new_blank(p->world->world, - (const uint8_t*)slv2_value_as_blank(subject)); + (const uint8_t*)lilv_value_as_blank(subject)); - SLV2Values ret = slv2_plugin_query_node(p, + LilvValues ret = lilv_plugin_query_node(p, subject_node, predicate->val.uri_val); - slv2_node_free(p->world, subject_node); + lilv_node_free(p->world, subject_node); return ret; } -SLV2_API +LILV_API uint32_t -slv2_plugin_get_num_ports(SLV2Plugin p) +lilv_plugin_get_num_ports(LilvPlugin p) { - slv2_plugin_load_ports_if_necessary(p); + lilv_plugin_load_ports_if_necessary(p); return p->num_ports; } -SLV2_API +LILV_API void -slv2_plugin_get_port_ranges_float(SLV2Plugin p, +lilv_plugin_get_port_ranges_float(LilvPlugin p, float* min_values, float* max_values, float* def_values) { - slv2_plugin_load_ports_if_necessary(p); + lilv_plugin_load_ports_if_necessary(p); for (uint32_t i = 0; i < p->num_ports; ++i) { - SLV2Value def, min, max; - slv2_port_get_range(p, p->ports[i], &def, &min, &max); + LilvValue def, min, max; + lilv_port_get_range(p, p->ports[i], &def, &min, &max); if (min_values) - min_values[i] = min ? slv2_value_as_float(min) : NAN; + min_values[i] = min ? lilv_value_as_float(min) : NAN; if (max_values) - max_values[i] = max ? slv2_value_as_float(max) : NAN; + max_values[i] = max ? lilv_value_as_float(max) : NAN; if (def_values) - def_values[i] = def ? slv2_value_as_float(def) : NAN; + def_values[i] = def ? lilv_value_as_float(def) : NAN; - slv2_value_free(def); - slv2_value_free(min); - slv2_value_free(max); + lilv_value_free(def); + lilv_value_free(min); + lilv_value_free(max); } } -SLV2_API +LILV_API uint32_t -slv2_plugin_get_num_ports_of_class(SLV2Plugin p, - SLV2Value class_1, ...) +lilv_plugin_get_num_ports_of_class(LilvPlugin p, + LilvValue class_1, ...) { - slv2_plugin_load_ports_if_necessary(p); + lilv_plugin_load_ports_if_necessary(p); uint32_t ret = 0; va_list args; for (unsigned i = 0; i < p->num_ports; ++i) { - SLV2Port port = p->ports[i]; - if (!port || !slv2_port_is_a(p, port, class_1)) + LilvPort port = p->ports[i]; + if (!port || !lilv_port_is_a(p, port, class_1)) continue; va_start(args, class_1); bool matches = true; - for (SLV2Value class_i = NULL; (class_i = va_arg(args, SLV2Value)) != NULL ; ) { - if (!slv2_port_is_a(p, port, class_i)) { + for (LilvValue class_i = NULL; (class_i = va_arg(args, LilvValue)) != NULL ; ) { + if (!lilv_port_is_a(p, port, class_i)) { va_end(args); matches = false; break; @@ -556,11 +552,11 @@ slv2_plugin_get_num_ports_of_class(SLV2Plugin p, return ret; } -SLV2_API +LILV_API bool -slv2_plugin_has_latency(SLV2Plugin p) +lilv_plugin_has_latency(LilvPlugin p) { - SLV2Matches ports = slv2_plugin_find_statements( + LilvMatches ports = lilv_plugin_find_statements( p, p->plugin_uri->val.uri_val, p->world->lv2_port_node, @@ -568,29 +564,29 @@ slv2_plugin_has_latency(SLV2Plugin p) bool ret = false; FOREACH_MATCH(ports) { - SLV2Node port = slv2_match_object(ports); - SLV2Matches reports_latency = slv2_plugin_find_statements( + LilvNode port = lilv_match_object(ports); + LilvMatches reports_latency = lilv_plugin_find_statements( p, port, p->world->lv2_portproperty_node, p->world->lv2_reportslatency_node); - const bool end = slv2_matches_end(reports_latency); - slv2_match_end(reports_latency); + const bool end = lilv_matches_end(reports_latency); + lilv_match_end(reports_latency); if (!end) { ret = true; break; } } - slv2_match_end(ports); + lilv_match_end(ports); return ret; } -SLV2_API +LILV_API uint32_t -slv2_plugin_get_latency_port_index(SLV2Plugin p) +lilv_plugin_get_latency_port_index(LilvPlugin p) { - SLV2Matches ports = slv2_plugin_find_statements( + LilvMatches ports = lilv_plugin_find_statements( p, p->plugin_uri->val.uri_val, p->world->lv2_port_node, @@ -598,218 +594,218 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p) uint32_t ret = 0; FOREACH_MATCH(ports) { - SLV2Node port = slv2_match_object(ports); - SLV2Matches reports_latency = slv2_plugin_find_statements( + LilvNode port = lilv_match_object(ports); + LilvMatches reports_latency = lilv_plugin_find_statements( p, port, p->world->lv2_portproperty_node, p->world->lv2_reportslatency_node); - if (!slv2_matches_end(reports_latency)) { - SLV2Value index = slv2_plugin_get_unique( + if (!lilv_matches_end(reports_latency)) { + LilvValue index = lilv_plugin_get_unique( p, port, p->world->lv2_index_node); - ret = slv2_value_as_int(index); - slv2_value_free(index); - slv2_match_end(reports_latency); + ret = lilv_value_as_int(index); + lilv_value_free(index); + lilv_match_end(reports_latency); break; } - slv2_match_end(reports_latency); + lilv_match_end(reports_latency); } - slv2_match_end(ports); + lilv_match_end(ports); return ret; // FIXME: error handling } -SLV2_API +LILV_API bool -slv2_plugin_has_feature(SLV2Plugin p, - SLV2Value feature) +lilv_plugin_has_feature(LilvPlugin p, + LilvValue feature) { - SLV2Values features = slv2_plugin_get_supported_features(p); + LilvValues features = lilv_plugin_get_supported_features(p); - const bool ret = features && feature && slv2_values_contains(features, feature); + const bool ret = features && feature && lilv_values_contains(features, feature); - slv2_values_free(features); + lilv_values_free(features); return ret; } -SLV2_API -SLV2Values -slv2_plugin_get_supported_features(SLV2Plugin p) +LILV_API +LilvValues +lilv_plugin_get_supported_features(LilvPlugin p) { - SLV2Values optional = slv2_plugin_get_optional_features(p); - SLV2Values required = slv2_plugin_get_required_features(p); - SLV2Values result = slv2_values_new(); + LilvValues optional = lilv_plugin_get_optional_features(p); + LilvValues required = lilv_plugin_get_required_features(p); + LilvValues result = lilv_values_new(); - SLV2_FOREACH(values, i, optional) - slv2_array_append( - result, slv2_value_duplicate(slv2_values_get(optional, i))); - SLV2_FOREACH(values, i, required) - slv2_array_append( - result, slv2_value_duplicate(slv2_values_get(required, i))); + LILV_FOREACH(values, i, optional) + lilv_array_append( + result, lilv_value_duplicate(lilv_values_get(optional, i))); + LILV_FOREACH(values, i, required) + lilv_array_append( + result, lilv_value_duplicate(lilv_values_get(required, i))); - slv2_values_free(optional); - slv2_values_free(required); + lilv_values_free(optional); + lilv_values_free(required); return result; } -SLV2_API -SLV2Values -slv2_plugin_get_optional_features(SLV2Plugin p) +LILV_API +LilvValues +lilv_plugin_get_optional_features(LilvPlugin p) { - return slv2_plugin_get_value_by_qname(p, "lv2:optionalFeature"); + return lilv_plugin_get_value_by_qname(p, "lv2:optionalFeature"); } -SLV2_API -SLV2Values -slv2_plugin_get_required_features(SLV2Plugin p) +LILV_API +LilvValues +lilv_plugin_get_required_features(LilvPlugin p) { - return slv2_plugin_get_value_by_qname(p, "lv2:requiredFeature"); + return lilv_plugin_get_value_by_qname(p, "lv2:requiredFeature"); } -SLV2_API -SLV2Port -slv2_plugin_get_port_by_index(SLV2Plugin p, +LILV_API +LilvPort +lilv_plugin_get_port_by_index(LilvPlugin p, uint32_t index) { - slv2_plugin_load_ports_if_necessary(p); + lilv_plugin_load_ports_if_necessary(p); if (index < p->num_ports) return p->ports[index]; else return NULL; } -SLV2_API -SLV2Port -slv2_plugin_get_port_by_symbol(SLV2Plugin p, - SLV2Value symbol) +LILV_API +LilvPort +lilv_plugin_get_port_by_symbol(LilvPlugin p, + LilvValue symbol) { - slv2_plugin_load_ports_if_necessary(p); + lilv_plugin_load_ports_if_necessary(p); for (uint32_t i = 0; i < p->num_ports; ++i) { - SLV2Port port = p->ports[i]; - if (slv2_value_equals(port->symbol, symbol)) + LilvPort port = p->ports[i]; + if (lilv_value_equals(port->symbol, symbol)) return port; } return NULL; } -static SLV2Node -slv2_plugin_get_author(SLV2Plugin p) +static LilvNode +lilv_plugin_get_author(LilvPlugin p) { SordNode* doap_maintainer = sord_new_uri( p->world->world, NS_DOAP "maintainer"); - SLV2Matches maintainers = slv2_plugin_find_statements( + LilvMatches maintainers = lilv_plugin_find_statements( p, p->plugin_uri->val.uri_val, doap_maintainer, NULL); - slv2_node_free(p->world, doap_maintainer); + lilv_node_free(p->world, doap_maintainer); - if (slv2_matches_end(maintainers)) { + if (lilv_matches_end(maintainers)) { return NULL; } - SLV2Node author = slv2_match_object(maintainers); + LilvNode author = lilv_match_object(maintainers); - slv2_match_end(maintainers); + lilv_match_end(maintainers); return author; } -SLV2_API -SLV2Value -slv2_plugin_get_author_name(SLV2Plugin plugin) +LILV_API +LilvValue +lilv_plugin_get_author_name(LilvPlugin plugin) { - SLV2Node author = slv2_plugin_get_author(plugin); + LilvNode author = lilv_plugin_get_author(plugin); if (author) { - return slv2_plugin_get_one( + return lilv_plugin_get_one( plugin, author, sord_new_uri( plugin->world->world, NS_FOAF "name")); } return NULL; } -SLV2_API -SLV2Value -slv2_plugin_get_author_email(SLV2Plugin plugin) +LILV_API +LilvValue +lilv_plugin_get_author_email(LilvPlugin plugin) { - SLV2Node author = slv2_plugin_get_author(plugin); + LilvNode author = lilv_plugin_get_author(plugin); if (author) { - return slv2_plugin_get_one( + return lilv_plugin_get_one( plugin, author, sord_new_uri( plugin->world->world, NS_FOAF "mbox")); } return NULL; } -SLV2_API -SLV2Value -slv2_plugin_get_author_homepage(SLV2Plugin plugin) +LILV_API +LilvValue +lilv_plugin_get_author_homepage(LilvPlugin plugin) { - SLV2Node author = slv2_plugin_get_author(plugin); + LilvNode author = lilv_plugin_get_author(plugin); if (author) { - return slv2_plugin_get_one( + return lilv_plugin_get_one( plugin, author, sord_new_uri( plugin->world->world, NS_FOAF "homepage")); } return NULL; } -SLV2_API +LILV_API bool -slv2_plugin_is_replaced(SLV2Plugin plugin) +lilv_plugin_is_replaced(LilvPlugin plugin) { return plugin->replaced; } -SLV2_API -SLV2UIs -slv2_plugin_get_uis(SLV2Plugin p) +LILV_API +LilvUIs +lilv_plugin_get_uis(LilvPlugin p) { SordNode* ui_ui_node = sord_new_uri(p->world->world, NS_UI "ui"); SordNode* ui_binary_node = sord_new_uri(p->world->world, NS_UI "binary"); - SLV2UIs result = slv2_uis_new(); - SLV2Matches uis = slv2_plugin_find_statements( + LilvUIs result = lilv_uis_new(); + LilvMatches uis = lilv_plugin_find_statements( p, p->plugin_uri->val.uri_val, ui_ui_node, NULL); FOREACH_MATCH(uis) { - SLV2Node ui = slv2_match_object(uis); - SLV2Value type = slv2_plugin_get_unique(p, ui, p->world->rdf_a_node); - SLV2Value binary = slv2_plugin_get_unique(p, ui, ui_binary_node); + LilvNode ui = lilv_match_object(uis); + LilvValue type = lilv_plugin_get_unique(p, ui, p->world->rdf_a_node); + LilvValue binary = lilv_plugin_get_unique(p, ui, ui_binary_node); if (sord_node_get_type(ui) != SORD_URI - || !slv2_value_is_uri(type) - || !slv2_value_is_uri(binary)) { - slv2_value_free(binary); - slv2_value_free(type); - SLV2_ERROR("Corrupt UI\n"); + || !lilv_value_is_uri(type) + || !lilv_value_is_uri(binary)) { + lilv_value_free(binary); + lilv_value_free(type); + LILV_ERROR("Corrupt UI\n"); continue; } - SLV2UI slv2_ui = slv2_ui_new( + LilvUI lilv_ui = lilv_ui_new( p->world, - slv2_value_new_from_node(p->world, ui), + lilv_value_new_from_node(p->world, ui), type, binary); - slv2_sequence_insert(result, slv2_ui); + lilv_sequence_insert(result, lilv_ui); } - slv2_match_end(uis); + lilv_match_end(uis); - slv2_node_free(p->world, ui_binary_node); - slv2_node_free(p->world, ui_ui_node); + lilv_node_free(p->world, ui_binary_node); + lilv_node_free(p->world, ui_ui_node); - if (slv2_uis_size(result) > 0) { + if (lilv_uis_size(result) > 0) { return result; } else { - slv2_uis_free(result); + lilv_uis_free(result); return NULL; } } diff --git a/src/pluginclass.c b/src/pluginclass.c index fc57f8b..7144cad 100644 --- a/src/pluginclass.c +++ b/src/pluginclass.c @@ -20,40 +20,40 @@ #include <stdlib.h> #include <string.h> -#include "slv2_internal.h" +#include "lilv_internal.h" -SLV2PluginClass -slv2_plugin_class_new(SLV2World world, - SLV2Node parent_node, - SLV2Node uri, +LilvPluginClass +lilv_plugin_class_new(LilvWorld world, + LilvNode parent_node, + LilvNode uri, const char* label) { if (parent_node && sord_node_get_type(parent_node) != SORD_URI) { return NULL; // Not an LV2 plugin superclass (FIXME: discover properly) } - SLV2PluginClass pc = (SLV2PluginClass)malloc(sizeof(struct _SLV2PluginClass)); + LilvPluginClass pc = (LilvPluginClass)malloc(sizeof(struct _LilvPluginClass)); pc->world = world; - pc->uri = slv2_value_new_from_node(world, uri); - pc->label = slv2_value_new(world, SLV2_VALUE_STRING, label); + pc->uri = lilv_value_new_from_node(world, uri); + pc->label = lilv_value_new(world, LILV_VALUE_STRING, label); pc->parent_uri = (parent_node) - ? slv2_value_new_from_node(world, parent_node) + ? lilv_value_new_from_node(world, parent_node) : NULL; return pc; } void -slv2_plugin_class_free(SLV2PluginClass plugin_class) +lilv_plugin_class_free(LilvPluginClass plugin_class) { assert(plugin_class->uri); - slv2_value_free(plugin_class->uri); - slv2_value_free(plugin_class->parent_uri); - slv2_value_free(plugin_class->label); + lilv_value_free(plugin_class->uri); + lilv_value_free(plugin_class->parent_uri); + lilv_value_free(plugin_class->label); free(plugin_class); } -SLV2_API -SLV2Value -slv2_plugin_class_get_parent_uri(SLV2PluginClass plugin_class) +LILV_API +LilvValue +lilv_plugin_class_get_parent_uri(LilvPluginClass plugin_class) { if (plugin_class->parent_uri) return plugin_class->parent_uri; @@ -61,36 +61,36 @@ slv2_plugin_class_get_parent_uri(SLV2PluginClass plugin_class) return NULL; } -SLV2_API -SLV2Value -slv2_plugin_class_get_uri(SLV2PluginClass plugin_class) +LILV_API +LilvValue +lilv_plugin_class_get_uri(LilvPluginClass plugin_class) { assert(plugin_class->uri); return plugin_class->uri; } -SLV2_API -SLV2Value -slv2_plugin_class_get_label(SLV2PluginClass plugin_class) +LILV_API +LilvValue +lilv_plugin_class_get_label(LilvPluginClass plugin_class) { return plugin_class->label; } -SLV2_API -SLV2PluginClasses -slv2_plugin_class_get_children(SLV2PluginClass plugin_class) +LILV_API +LilvPluginClasses +lilv_plugin_class_get_children(LilvPluginClass plugin_class) { // Returned list doesn't own categories - SLV2PluginClasses all = plugin_class->world->plugin_classes; - SLV2PluginClasses result = g_sequence_new(NULL); + LilvPluginClasses all = plugin_class->world->plugin_classes; + LilvPluginClasses result = g_sequence_new(NULL); for (GSequenceIter* i = g_sequence_get_begin_iter(all); i != g_sequence_get_end_iter(all); i = g_sequence_iter_next(i)) { - SLV2PluginClass c = g_sequence_get(i); - SLV2Value parent = slv2_plugin_class_get_parent_uri(c); - if (parent && slv2_value_equals(slv2_plugin_class_get_uri(plugin_class), parent)) - slv2_sequence_insert(result, c); + LilvPluginClass c = g_sequence_get(i); + LilvValue parent = lilv_plugin_class_get_parent_uri(c); + if (parent && lilv_value_equals(lilv_plugin_class_get_uri(plugin_class), parent)) + lilv_sequence_insert(result, c); } return result; diff --git a/src/plugininstance.c b/src/plugininstance.c index fbbdb13..e77f7a8 100644 --- a/src/plugininstance.c +++ b/src/plugininstance.c @@ -21,11 +21,11 @@ #include <stdlib.h> #include <string.h> -#include "slv2_internal.h" +#include "lilv_internal.h" -SLV2_API -SLV2Instance -slv2_plugin_instantiate(SLV2Plugin plugin, +LILV_API +LilvInstance +lilv_plugin_instantiate(LilvPlugin plugin, double sample_rate, const LV2_Feature*const* features) { @@ -37,8 +37,8 @@ slv2_plugin_instantiate(SLV2Plugin plugin, local_features[0] = NULL; } - const char* const lib_uri = slv2_value_as_uri(slv2_plugin_get_library_uri(plugin)); - const char* const lib_path = slv2_uri_to_path(lib_uri); + const char* const lib_uri = lilv_value_as_uri(lilv_plugin_get_library_uri(plugin)); + const char* const lib_path = lilv_uri_to_path(lib_uri); if (!lib_path) return NULL; @@ -46,35 +46,35 @@ slv2_plugin_instantiate(SLV2Plugin plugin, dlerror(); void* lib = dlopen(lib_path, RTLD_NOW); if (!lib) { - SLV2_ERRORF("Unable to open library %s (%s)\n", lib_path, dlerror()); + LILV_ERRORF("Unable to open library %s (%s)\n", lib_path, dlerror()); return NULL; } LV2_Descriptor_Function df = (LV2_Descriptor_Function) - slv2_dlfunc(lib, "lv2_descriptor"); + lilv_dlfunc(lib, "lv2_descriptor"); if (!df) { - SLV2_ERRORF("Could not find symbol 'lv2_descriptor', " + LILV_ERRORF("Could not find symbol 'lv2_descriptor', " "%s is not a LV2 plugin.\n", lib_path); dlclose(lib); return NULL; } else { // Search for plugin by URI - const char* bundle_path = slv2_uri_to_path(slv2_value_as_uri( - slv2_plugin_get_bundle_uri(plugin))); + const char* bundle_path = lilv_uri_to_path(lilv_value_as_uri( + lilv_plugin_get_bundle_uri(plugin))); for (uint32_t i = 0; true; ++i) { const LV2_Descriptor* ld = df(i); if (!ld) { - SLV2_ERRORF("Did not find plugin %s in %s\n", - slv2_value_as_uri(slv2_plugin_get_uri(plugin)), lib_path); + LILV_ERRORF("Did not find plugin %s in %s\n", + lilv_value_as_uri(lilv_plugin_get_uri(plugin)), lib_path); dlclose(lib); break; // return NULL } else { // Parse bundle URI to use as base URI - const SLV2Value bundle_uri = slv2_plugin_get_bundle_uri(plugin); - const char* bundle_uri_str = slv2_value_as_uri(bundle_uri); + const LilvValue bundle_uri = lilv_plugin_get_bundle_uri(plugin); + const char* bundle_uri_str = lilv_value_as_uri(bundle_uri); SerdURI base_uri; if (!serd_uri_parse((const uint8_t*)bundle_uri_str, &base_uri)) { dlclose(lib); @@ -86,19 +86,19 @@ slv2_plugin_instantiate(SLV2Plugin plugin, SerdNode abs_uri_node = serd_node_new_uri_from_string( (const uint8_t*)ld->URI, &base_uri, &abs_uri); if (!abs_uri_node.buf) { - SLV2_ERRORF("Failed to parse library plugin URI `%s'\n", ld->URI); + LILV_ERRORF("Failed to parse library plugin URI `%s'\n", ld->URI); dlclose(lib); break; } if (!strcmp((const char*)abs_uri_node.buf, - slv2_value_as_uri(slv2_plugin_get_uri(plugin)))) { - // Create SLV2Instance to return + lilv_value_as_uri(lilv_plugin_get_uri(plugin)))) { + // Create LilvInstance to return result = malloc(sizeof(struct _Instance)); result->lv2_descriptor = ld; result->lv2_handle = ld->instantiate(ld, sample_rate, (char*)bundle_path, (features) ? features : local_features); - struct _SLV2InstanceImpl* impl = malloc(sizeof(struct _SLV2InstanceImpl)); + struct _LilvInstanceImpl* impl = malloc(sizeof(struct _LilvInstanceImpl)); impl->lib_handle = lib; result->pimpl = impl; serd_node_free(&abs_uri_node); @@ -111,7 +111,7 @@ slv2_plugin_instantiate(SLV2Plugin plugin, } if (result) { - assert(slv2_plugin_get_num_ports(plugin) > 0); + assert(lilv_plugin_get_num_ports(plugin) > 0); // Failed to instantiate if (result->lv2_handle == NULL) { @@ -120,7 +120,7 @@ slv2_plugin_instantiate(SLV2Plugin plugin, } // "Connect" all ports to NULL (catches bugs) - for (uint32_t i = 0; i < slv2_plugin_get_num_ports(plugin); ++i) + for (uint32_t i = 0; i < lilv_plugin_get_num_ports(plugin); ++i) result->lv2_descriptor->connect_port(result->lv2_handle, i, NULL); } @@ -129,9 +129,9 @@ slv2_plugin_instantiate(SLV2Plugin plugin, return result; } -SLV2_API +LILV_API void -slv2_instance_free(SLV2Instance instance) +lilv_instance_free(LilvInstance instance) { if (!instance) return; diff --git a/src/pluginui.c b/src/pluginui.c index 3cb2439..b8e9db1 100644 --- a/src/pluginui.c +++ b/src/pluginui.c @@ -20,82 +20,78 @@ #include <stdlib.h> #include <string.h> -#include "slv2_internal.h" +#include "lilv_internal.h" -#ifdef HAVE_SUIL -#include "suil/suil.h" -#endif - -SLV2UI -slv2_ui_new(SLV2World world, - SLV2Value uri, - SLV2Value type_uri, - SLV2Value binary_uri) +LilvUI +lilv_ui_new(LilvWorld world, + LilvValue uri, + LilvValue type_uri, + LilvValue binary_uri) { assert(uri); assert(type_uri); assert(binary_uri); - struct _SLV2UI* ui = malloc(sizeof(struct _SLV2UI)); + struct _LilvUI* ui = malloc(sizeof(struct _LilvUI)); ui->world = world; ui->uri = uri; ui->binary_uri = binary_uri; // FIXME: kludge - char* bundle = slv2_strdup(slv2_value_as_string(ui->binary_uri)); + char* bundle = lilv_strdup(lilv_value_as_string(ui->binary_uri)); char* last_slash = strrchr(bundle, '/') + 1; *last_slash = '\0'; - ui->bundle_uri = slv2_value_new_uri(world, bundle); + ui->bundle_uri = lilv_value_new_uri(world, bundle); free(bundle); - ui->classes = slv2_values_new(); - slv2_array_append(ui->classes, type_uri); + ui->classes = lilv_values_new(); + lilv_array_append(ui->classes, type_uri); return ui; } void -slv2_ui_free(SLV2UI ui) +lilv_ui_free(LilvUI ui) { - slv2_value_free(ui->uri); + lilv_value_free(ui->uri); ui->uri = NULL; - slv2_value_free(ui->bundle_uri); + lilv_value_free(ui->bundle_uri); ui->bundle_uri = NULL; - slv2_value_free(ui->binary_uri); + lilv_value_free(ui->binary_uri); ui->binary_uri = NULL; - slv2_values_free(ui->classes); + lilv_values_free(ui->classes); free(ui); } -SLV2_API -SLV2Value -slv2_ui_get_uri(SLV2UI ui) +LILV_API +LilvValue +lilv_ui_get_uri(LilvUI ui) { assert(ui); assert(ui->uri); return ui->uri; } -SLV2_API +LILV_API unsigned -slv2_ui_is_supported(SLV2UI ui, - SLV2UISupportedFunc supported_func, - SLV2Value container_type, - SLV2Value* ui_type) +lilv_ui_is_supported(LilvUI ui, + LilvUISupportedFunc supported_func, + LilvValue container_type, + LilvValue* ui_type) { #ifdef HAVE_SUIL - SLV2Values classes = slv2_ui_get_classes(ui); - SLV2_FOREACH(values, c, classes) { - SLV2Value type = slv2_values_get(classes, c); - const unsigned q = supported_func(slv2_value_as_uri(container_type), - slv2_value_as_uri(type)); + LilvValues classes = lilv_ui_get_classes(ui); + LILV_FOREACH(values, c, classes) { + LilvValue type = lilv_values_get(classes, c); + const unsigned q = supported_func(lilv_value_as_uri(container_type), + lilv_value_as_uri(type)); if (q) { if (ui_type) { - *ui_type = slv2_value_duplicate(type); + *ui_type = lilv_value_duplicate(type); } return q; } @@ -104,32 +100,32 @@ slv2_ui_is_supported(SLV2UI ui, return 0; } -SLV2_API -SLV2Values -slv2_ui_get_classes(SLV2UI ui) +LILV_API +LilvValues +lilv_ui_get_classes(LilvUI ui) { return ui->classes; } -SLV2_API +LILV_API bool -slv2_ui_is_a(SLV2UI ui, SLV2Value ui_class_uri) +lilv_ui_is_a(LilvUI ui, LilvValue ui_class_uri) { - return slv2_values_contains(ui->classes, ui_class_uri); + return lilv_values_contains(ui->classes, ui_class_uri); } -SLV2_API -SLV2Value -slv2_ui_get_bundle_uri(SLV2UI ui) +LILV_API +LilvValue +lilv_ui_get_bundle_uri(LilvUI ui) { assert(ui); assert(ui->bundle_uri); return ui->bundle_uri; } -SLV2_API -SLV2Value -slv2_ui_get_binary_uri(SLV2UI ui) +LILV_API +LilvValue +lilv_ui_get_binary_uri(LilvUI ui) { assert(ui); assert(ui->binary_uri); @@ -22,286 +22,286 @@ #include <stdlib.h> #include <string.h> -#include "slv2_internal.h" +#include "lilv_internal.h" -SLV2Port -slv2_port_new(SLV2World world, uint32_t index, const char* symbol) +LilvPort +lilv_port_new(LilvWorld world, uint32_t index, const char* symbol) { - struct _SLV2Port* port = malloc(sizeof(struct _SLV2Port)); + struct _LilvPort* port = malloc(sizeof(struct _LilvPort)); port->index = index; - port->symbol = slv2_value_new(world, SLV2_VALUE_STRING, symbol); - port->classes = slv2_values_new(); + port->symbol = lilv_value_new(world, LILV_VALUE_STRING, symbol); + port->classes = lilv_values_new(); return port; } void -slv2_port_free(SLV2Port port) +lilv_port_free(LilvPort port) { - slv2_values_free(port->classes); - slv2_value_free(port->symbol); + lilv_values_free(port->classes); + lilv_value_free(port->symbol); free(port); } -SLV2_API +LILV_API bool -slv2_port_is_a(SLV2Plugin plugin, - SLV2Port port, - SLV2Value port_class) +lilv_port_is_a(LilvPlugin plugin, + LilvPort port, + LilvValue port_class) { - SLV2_FOREACH(values, i, port->classes) - if (slv2_value_equals(slv2_values_get(port->classes, i), port_class)) + LILV_FOREACH(values, i, port->classes) + if (lilv_value_equals(lilv_values_get(port->classes, i), port_class)) return true; return false; } -static SLV2Node -slv2_port_get_node(SLV2Plugin p, - SLV2Port port) +static LilvNode +lilv_port_get_node(LilvPlugin p, + LilvPort port) { - SLV2Matches ports = slv2_plugin_find_statements( + LilvMatches ports = lilv_plugin_find_statements( p, p->plugin_uri->val.uri_val, p->world->lv2_port_node, NULL); - SLV2Node ret = NULL; + LilvNode ret = NULL; FOREACH_MATCH(ports) { - SLV2Node node = slv2_match_object(ports); - SLV2Value symbol = slv2_plugin_get_unique( + LilvNode node = lilv_match_object(ports); + LilvValue symbol = lilv_plugin_get_unique( p, node, p->world->lv2_symbol_node); - const bool matches = slv2_value_equals(symbol, - slv2_port_get_symbol(p, port)); + const bool matches = lilv_value_equals(symbol, + lilv_port_get_symbol(p, port)); - slv2_value_free(symbol); + lilv_value_free(symbol); if (matches) { ret = node; break; } } - slv2_match_end(ports); + lilv_match_end(ports); assert(ret); return ret; } -SLV2_API +LILV_API bool -slv2_port_has_property(SLV2Plugin p, - SLV2Port port, - SLV2Value property) +lilv_port_has_property(LilvPlugin p, + LilvPort port, + LilvValue property) { assert(property); - SLV2Node port_node = slv2_port_get_node(p, port); - SLV2Matches results = slv2_plugin_find_statements( + LilvNode port_node = lilv_port_get_node(p, port); + LilvMatches results = lilv_plugin_find_statements( p, port_node, p->world->lv2_portproperty_node, - slv2_value_as_node(property)); + lilv_value_as_node(property)); - const bool ret = !slv2_matches_end(results); - slv2_match_end(results); + const bool ret = !lilv_matches_end(results); + lilv_match_end(results); return ret; } -SLV2_API +LILV_API bool -slv2_port_supports_event(SLV2Plugin p, - SLV2Port port, - SLV2Value event) +lilv_port_supports_event(LilvPlugin p, + LilvPort port, + LilvValue event) { #define NS_EV (const uint8_t*)"http://lv2plug.in/ns/ext/event#" assert(event); - SLV2Node port_node = slv2_port_get_node(p, port); - SLV2Matches results = slv2_plugin_find_statements( + LilvNode port_node = lilv_port_get_node(p, port); + LilvMatches results = lilv_plugin_find_statements( p, port_node, sord_new_uri(p->world->world, NS_EV "supportsEvent"), - slv2_value_as_node(event)); + lilv_value_as_node(event)); - const bool ret = !slv2_matches_end(results); - slv2_match_end(results); + const bool ret = !lilv_matches_end(results); + lilv_match_end(results); return ret; } -SLV2_API -SLV2Values -slv2_port_get_value_by_qname(SLV2Plugin p, - SLV2Port port, +LILV_API +LilvValues +lilv_port_get_value_by_qname(LilvPlugin p, + LilvPort port, const char* predicate) { assert(predicate); - uint8_t* pred_uri = slv2_qname_expand(p, predicate); + uint8_t* pred_uri = lilv_qname_expand(p, predicate); if (!pred_uri) { return NULL; } - SLV2Node port_node = slv2_port_get_node(p, port); - SLV2Matches results = slv2_plugin_find_statements( + LilvNode port_node = lilv_port_get_node(p, port); + LilvMatches results = lilv_plugin_find_statements( p, port_node, sord_new_uri(p->world->world, pred_uri), NULL); free(pred_uri); - return slv2_values_from_stream_objects(p, results); + return lilv_values_from_stream_objects(p, results); } -static SLV2Values -slv2_port_get_value_by_node(SLV2Plugin p, - SLV2Port port, - SLV2Node predicate) +static LilvValues +lilv_port_get_value_by_node(LilvPlugin p, + LilvPort port, + LilvNode predicate) { assert(sord_node_get_type(predicate) == SORD_URI); - SLV2Node port_node = slv2_port_get_node(p, port); - SLV2Matches results = slv2_plugin_find_statements( + LilvNode port_node = lilv_port_get_node(p, port); + LilvMatches results = lilv_plugin_find_statements( p, port_node, predicate, NULL); - return slv2_values_from_stream_objects(p, results); + return lilv_values_from_stream_objects(p, results); } -SLV2_API -SLV2Values -slv2_port_get_value(SLV2Plugin p, - SLV2Port port, - SLV2Value predicate) +LILV_API +LilvValues +lilv_port_get_value(LilvPlugin p, + LilvPort port, + LilvValue predicate) { - if ( ! slv2_value_is_uri(predicate)) { - SLV2_ERROR("Predicate is not a URI\n"); + if ( ! lilv_value_is_uri(predicate)) { + LILV_ERROR("Predicate is not a URI\n"); return NULL; } - return slv2_port_get_value_by_node( + return lilv_port_get_value_by_node( p, port, - slv2_value_as_node(predicate)); + lilv_value_as_node(predicate)); } -SLV2_API -SLV2Value -slv2_port_get_symbol(SLV2Plugin p, - SLV2Port port) +LILV_API +LilvValue +lilv_port_get_symbol(LilvPlugin p, + LilvPort port) { return port->symbol; } -SLV2_API -SLV2Value -slv2_port_get_name(SLV2Plugin p, - SLV2Port port) +LILV_API +LilvValue +lilv_port_get_name(LilvPlugin p, + LilvPort port) { - SLV2Values results = slv2_port_get_value(p, port, + LilvValues results = lilv_port_get_value(p, port, p->world->lv2_name_val); - SLV2Value ret = NULL; + LilvValue ret = NULL; if (results) { - SLV2Value val = slv2_values_get_first(results); - if (slv2_value_is_string(val)) - ret = slv2_value_duplicate(val); - slv2_values_free(results); + LilvValue val = lilv_values_get_first(results); + if (lilv_value_is_string(val)) + ret = lilv_value_duplicate(val); + lilv_values_free(results); } if (!ret) - SLV2_WARNF("<%s> has no (mandatory) doap:name\n", - slv2_value_as_string(slv2_plugin_get_uri(p))); + LILV_WARNF("<%s> has no (mandatory) doap:name\n", + lilv_value_as_string(lilv_plugin_get_uri(p))); return ret; } -SLV2_API -SLV2Values -slv2_port_get_classes(SLV2Plugin p, - SLV2Port port) +LILV_API +LilvValues +lilv_port_get_classes(LilvPlugin p, + LilvPort port) { return port->classes; } -SLV2_API +LILV_API void -slv2_port_get_range(SLV2Plugin p, - SLV2Port port, - SLV2Value* def, - SLV2Value* min, - SLV2Value* max) +lilv_port_get_range(LilvPlugin p, + LilvPort port, + LilvValue* def, + LilvValue* min, + LilvValue* max) { if (def) { - SLV2Values defaults = slv2_port_get_value_by_node( + LilvValues defaults = lilv_port_get_value_by_node( p, port, p->world->lv2_default_node); *def = defaults - ? slv2_value_duplicate(slv2_values_get_first(defaults)) + ? lilv_value_duplicate(lilv_values_get_first(defaults)) : NULL; - slv2_values_free(defaults); + lilv_values_free(defaults); } if (min) { - SLV2Values minimums = slv2_port_get_value_by_node( + LilvValues minimums = lilv_port_get_value_by_node( p, port, p->world->lv2_minimum_node); *min = minimums - ? slv2_value_duplicate(slv2_values_get_first(minimums)) + ? lilv_value_duplicate(lilv_values_get_first(minimums)) : NULL; - slv2_values_free(minimums); + lilv_values_free(minimums); } if (max) { - SLV2Values maximums = slv2_port_get_value_by_node( + LilvValues maximums = lilv_port_get_value_by_node( p, port, p->world->lv2_maximum_node); *max = maximums - ? slv2_value_duplicate(slv2_values_get_first(maximums)) + ? lilv_value_duplicate(lilv_values_get_first(maximums)) : NULL; - slv2_values_free(maximums); + lilv_values_free(maximums); } } -SLV2_API -SLV2ScalePoints -slv2_port_get_scale_points(SLV2Plugin p, - SLV2Port port) +LILV_API +LilvScalePoints +lilv_port_get_scale_points(LilvPlugin p, + LilvPort port) { - SLV2Node port_node = slv2_port_get_node(p, port); - SLV2Matches points = slv2_plugin_find_statements( + LilvNode port_node = lilv_port_get_node(p, port); + LilvMatches points = lilv_plugin_find_statements( p, port_node, - sord_new_uri(p->world->world, SLV2_NS_LV2 "scalePoint"), + sord_new_uri(p->world->world, LILV_NS_LV2 "scalePoint"), NULL); - SLV2ScalePoints ret = NULL; - if (!slv2_matches_end(points)) - ret = slv2_scale_points_new(); + LilvScalePoints ret = NULL; + if (!lilv_matches_end(points)) + ret = lilv_scale_points_new(); FOREACH_MATCH(points) { - SLV2Node point = slv2_match_object(points); + LilvNode point = lilv_match_object(points); - SLV2Value value = slv2_plugin_get_unique( + LilvValue value = lilv_plugin_get_unique( p, point, p->world->rdf_value_node); - SLV2Value label = slv2_plugin_get_unique( + LilvValue label = lilv_plugin_get_unique( p, point, p->world->rdfs_label_node); if (value && label) { - slv2_array_append(ret, slv2_scale_point_new(value, label)); + lilv_array_append(ret, lilv_scale_point_new(value, label)); } } - slv2_match_end(points); + lilv_match_end(points); - assert(!ret || slv2_values_size(ret) > 0); + assert(!ret || lilv_values_size(ret) > 0); return ret; } -SLV2_API -SLV2Values -slv2_port_get_properties(SLV2Plugin p, - SLV2Port port) +LILV_API +LilvValues +lilv_port_get_properties(LilvPlugin p, + LilvPort port) { - SLV2Value pred = slv2_value_new_from_node( + LilvValue pred = lilv_value_new_from_node( p->world, p->world->lv2_portproperty_node); - SLV2Values ret = slv2_port_get_value(p, port, pred); - slv2_value_free(pred); + LilvValues ret = lilv_port_get_value(p, port, pred); + lilv_value_free(pred); return ret; } diff --git a/src/query.c b/src/query.c index cebefcd..b82256c 100644 --- a/src/query.c +++ b/src/query.c @@ -21,30 +21,30 @@ #include <stdlib.h> #include <string.h> -#include "slv2_internal.h" +#include "lilv_internal.h" -SLV2Matches -slv2_plugin_find_statements(SLV2Plugin plugin, - SLV2Node subject, - SLV2Node predicate, - SLV2Node object) +LilvMatches +lilv_plugin_find_statements(LilvPlugin plugin, + LilvNode subject, + LilvNode predicate, + LilvNode object) { - slv2_plugin_load_if_necessary(plugin); + lilv_plugin_load_if_necessary(plugin); SordQuad pat = { subject, predicate, object, NULL }; return sord_find(plugin->world->model, pat); } typedef enum { - SLV2_LANG_MATCH_NONE, ///< Language does not match at all - SLV2_LANG_MATCH_PARTIAL, ///< Partial (language, but not country) match - SLV2_LANG_MATCH_EXACT ///< Exact (language and country) match -} SLV2LangMatch; + LILV_LANG_MATCH_NONE, ///< Language does not match at all + LILV_LANG_MATCH_PARTIAL, ///< Partial (language, but not country) match + LILV_LANG_MATCH_EXACT ///< Exact (language and country) match +} LilvLangMatch; -static SLV2LangMatch -slv2_lang_matches(const char* a, const char* b) +static LilvLangMatch +lilv_lang_matches(const char* a, const char* b) { if (!strcmp(a, b)) { - return SLV2_LANG_MATCH_EXACT; + return LILV_LANG_MATCH_EXACT; } const char* a_dash = strchr(a, '-'); @@ -54,59 +54,59 @@ slv2_lang_matches(const char* a, const char* b) if (a_lang_len && b_lang_len) { if (a_lang_len == b_lang_len && !strncmp(a, b, a_lang_len)) { - return SLV2_LANG_MATCH_PARTIAL; // e.g. a="en-gb", b="en-ca" + return LILV_LANG_MATCH_PARTIAL; // e.g. a="en-gb", b="en-ca" } } else if (a_lang_len && !strncmp(a, b, a_lang_len)) { - return SLV2_LANG_MATCH_PARTIAL; // e.g. a="en", b="en-ca" + return LILV_LANG_MATCH_PARTIAL; // e.g. a="en", b="en-ca" } else if (b_lang_len && !strncmp(a, b, b_lang_len)) { - return SLV2_LANG_MATCH_PARTIAL; // e.g. a="en-ca", b="en" + return LILV_LANG_MATCH_PARTIAL; // e.g. a="en-ca", b="en" } - return SLV2_LANG_MATCH_NONE; + return LILV_LANG_MATCH_NONE; } -SLV2Values -slv2_values_from_stream_objects_i18n(SLV2Plugin p, - SLV2Matches stream) +LilvValues +lilv_values_from_stream_objects_i18n(LilvPlugin p, + LilvMatches stream) { - SLV2Values values = slv2_values_new(); - SLV2Node nolang = NULL; // Untranslated value - SLV2Node partial = NULL; // Partial language match - char* syslang = slv2_get_lang(); + LilvValues values = lilv_values_new(); + LilvNode nolang = NULL; // Untranslated value + LilvNode partial = NULL; // Partial language match + char* syslang = lilv_get_lang(); FOREACH_MATCH(stream) { - SLV2Node value = slv2_match_object(stream); + LilvNode value = lilv_match_object(stream); if (sord_node_get_type(value) == SORD_LITERAL) { const char* lang = sord_node_get_language(value); - SLV2LangMatch lm = SLV2_LANG_MATCH_NONE; + LilvLangMatch lm = LILV_LANG_MATCH_NONE; if (lang) { lm = (syslang) - ? slv2_lang_matches(lang, syslang) - : SLV2_LANG_MATCH_PARTIAL; + ? lilv_lang_matches(lang, syslang) + : LILV_LANG_MATCH_PARTIAL; } else { nolang = value; if (!syslang) { - lm = SLV2_LANG_MATCH_EXACT; + lm = LILV_LANG_MATCH_EXACT; } } - if (lm == SLV2_LANG_MATCH_EXACT) { + if (lm == LILV_LANG_MATCH_EXACT) { // Exact language match, add to results - slv2_array_append(values, slv2_value_new_from_node(p->world, value)); - } else if (lm == SLV2_LANG_MATCH_PARTIAL) { + lilv_array_append(values, lilv_value_new_from_node(p->world, value)); + } else if (lm == LILV_LANG_MATCH_PARTIAL) { // Partial language match, save in case we find no exact partial = value; } } else { - slv2_array_append(values, slv2_value_new_from_node(p->world, value)); + lilv_array_append(values, lilv_value_new_from_node(p->world, value)); } } - slv2_match_end(stream); + lilv_match_end(stream); free(syslang); - if (slv2_values_size(values) > 0) { + if (lilv_values_size(values) > 0) { return values; } - SLV2Node best = nolang; + LilvNode best = nolang; if (syslang && partial) { // Partial language match for system language best = partial; @@ -117,35 +117,35 @@ slv2_values_from_stream_objects_i18n(SLV2Plugin p, } if (best) { - slv2_array_append(values, slv2_value_new_from_node(p->world, best)); + lilv_array_append(values, lilv_value_new_from_node(p->world, best)); } else { // No matches whatsoever - slv2_values_free(values); + lilv_values_free(values); values = NULL; } return values; } -SLV2Values -slv2_values_from_stream_objects(SLV2Plugin p, - SLV2Matches stream) +LilvValues +lilv_values_from_stream_objects(LilvPlugin p, + LilvMatches stream) { - if (slv2_matches_end(stream)) { - slv2_match_end(stream); + if (lilv_matches_end(stream)) { + lilv_match_end(stream); return NULL; } else if (p->world->opt.filter_language) { - return slv2_values_from_stream_objects_i18n(p, stream); + return lilv_values_from_stream_objects_i18n(p, stream); } else { - SLV2Values values = slv2_values_new(); + LilvValues values = lilv_values_new(); FOREACH_MATCH(stream) { - slv2_array_append( + lilv_array_append( values, - slv2_value_new_from_node( + lilv_value_new_from_node( p->world, - slv2_match_object(stream))); + lilv_match_object(stream))); } - slv2_match_end(stream); + lilv_match_end(stream); return values; } } diff --git a/src/scalepoint.c b/src/scalepoint.c index 857b53e..aa27d04 100644 --- a/src/scalepoint.c +++ b/src/scalepoint.c @@ -14,36 +14,36 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "slv2_internal.h" +#include "lilv_internal.h" /** Ownership of value and label is taken */ -SLV2ScalePoint -slv2_scale_point_new(SLV2Value value, SLV2Value label) +LilvScalePoint +lilv_scale_point_new(LilvValue value, LilvValue label) { - SLV2ScalePoint point = (SLV2ScalePoint)malloc(sizeof(struct _SLV2ScalePoint)); + LilvScalePoint point = (LilvScalePoint)malloc(sizeof(struct _LilvScalePoint)); point->value = value; point->label = label; return point; } void -slv2_scale_point_free(SLV2ScalePoint point) +lilv_scale_point_free(LilvScalePoint point) { - slv2_value_free(point->value); - slv2_value_free(point->label); + lilv_value_free(point->value); + lilv_value_free(point->label); free(point); } -SLV2_API -SLV2Value -slv2_scale_point_get_value(SLV2ScalePoint p) +LILV_API +LilvValue +lilv_scale_point_get_value(LilvScalePoint p) { return p->value; } -SLV2_API -SLV2Value -slv2_scale_point_get_label(SLV2ScalePoint p) +LILV_API +LilvValue +lilv_scale_point_get_label(LilvScalePoint p) { return p->label; } diff --git a/src/slv2_internal.h b/src/slv2_internal.h deleted file mode 100644 index 2e89891..0000000 --- a/src/slv2_internal.h +++ /dev/null @@ -1,428 +0,0 @@ -/* - Copyright 2007-2011 David Robillard <http://drobilla.net> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#ifndef SLV2_INTERNAL_H -#define SLV2_INTERNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdbool.h> -#include <stddef.h> -#include <stdint.h> -#include <stdlib.h> - -#ifdef __WIN32__ -#include <windows.h> -#define dlopen(path, flags) LoadLibrary(path) -#define dlclose(lib) FreeLibrary(lib) -#define dlsym GetProcAddress -static inline char* dlerror(void) { return "Unknown error"; } -#else -#include <dlfcn.h> -#endif - -#include <glib.h> - -#include "serd/serd.h" -#include "sord/sord.h" - -#include "slv2-config.h" - -#ifdef SLV2_DYN_MANIFEST -#include "lv2/lv2plug.in/ns/ext/dyn-manifest/dyn-manifest.h" -#endif - -#ifdef HAVE_SUIL -#include "suil/suil.h" -#endif - -#include "slv2/slv2.h" - -#define SLV2_NS_DOAP (const uint8_t*)"http://usefulinc.com/ns/doap#" -#define SLV2_NS_RDFS (const uint8_t*)"http://www.w3.org/2000/01/rdf-schema#" -#define SLV2_NS_SLV2 (const uint8_t*)"http://drobilla.net/ns/slv2#" -#define SLV2_NS_LV2 (const uint8_t*)"http://lv2plug.in/ns/lv2core#" -#define SLV2_NS_XSD (const uint8_t*)"http://www.w3.org/2001/XMLSchema#" -#define SLV2_NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#" - -typedef SordIter* SLV2Matches; -typedef const SordNode* SLV2Node; - -#define FOREACH_MATCH(iter) \ - for (; !sord_iter_end(iter); sord_iter_next(iter)) - -static inline const SordNode* -slv2_match_subject(SLV2Matches iter) { - SordQuad tup; - sord_iter_get(iter, tup); - return tup[SORD_SUBJECT]; -} - -static inline const SordNode* -slv2_match_object(SLV2Matches iter) { - SordQuad tup; - sord_iter_get(iter, tup); - return tup[SORD_OBJECT]; -} - -static inline void -slv2_match_end(SLV2Matches iter) -{ - sord_iter_free(iter); -} - -/* ********* PORT ********* */ - -/** Reference to a port on some plugin. */ -struct _SLV2Port { - uint32_t index; ///< lv2:index - SLV2Value symbol; ///< lv2:symbol - SLV2Values classes; ///< rdf:type -}; - -SLV2Port slv2_port_new(SLV2World world, uint32_t index, const char* symbol); -void slv2_port_free(SLV2Port port); - -/* ********* Spec ********* */ - -struct _SLV2Spec { - SordNode* spec; - SordNode* bundle; - SLV2Values data_uris; -}; - -typedef struct _SLV2Spec* SLV2Spec; - -/* ********* Plugin ********* */ - -/** Header of an SLV2Plugin, SLV2PluginClass, or SLV2UI. - * Any of these structs may be safely casted to _SLV2Header, which is used to - * implement sequences without code duplication (see slv2_sequence_get_by_uri). - */ -struct _SLV2Header { - struct _SLV2World* world; - SLV2Value uri; -}; - -/** Record of an installed/available plugin. - * - * A simple reference to a plugin somewhere on the system. This just holds - * paths of relevant files, the actual data therein isn't loaded into memory. - */ -struct _SLV2Plugin { - struct _SLV2World* world; - SLV2Value plugin_uri; - SLV2Value bundle_uri; ///< Bundle directory plugin was loaded from - SLV2Value binary_uri; ///< lv2:binary - SLV2Value dynman_uri; ///< dynamic manifest binary - SLV2PluginClass plugin_class; - SLV2Values data_uris; ///< rdfs::seeAlso - SLV2Port* ports; - uint32_t num_ports; - bool loaded; - bool replaced; -}; - -SLV2Plugin slv2_plugin_new(SLV2World world, SLV2Value uri, SLV2Value bundle_uri); -void slv2_plugin_load_if_necessary(SLV2Plugin p); -void slv2_plugin_free(SLV2Plugin plugin); - -SLV2Value -slv2_plugin_get_unique(SLV2Plugin p, - SLV2Node subject, - SLV2Node predicate); - -/* ********* Plugins ********* */ - -SLV2Plugins -slv2_plugins_new(); - - -/** - Increment @a i to point at the next element in the collection. -*/ -SLV2Iter -slv2_iter_next(SLV2Iter i); - -/** - Return true iff @a i is at the end of the collection. -*/ -bool -slv2_iter_end(SLV2Iter i); - -SLV2Iter -slv2_collection_begin(SLV2Collection collection); - -void* -slv2_collection_get(SLV2Collection collection, - SLV2Iter i); - -/** - Free @a collection. -*/ -void -slv2_collection_free(SLV2Collection collection); - -/** - Get the number of elements in @a collection. -*/ -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 @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_DEPRECATED -void* -slv2_collection_get_at(SLV2Collection collection, - unsigned index); - -SLV2Values -slv2_values_new(void); - -SLV2ScalePoints -slv2_scale_points_new(void); - - -/* ********* Instance ********* */ - -/** Pimpl portion of SLV2Instance */ -struct _SLV2InstanceImpl { - void* lib_handle; -}; - -/* ********* Plugin Class ********* */ - -struct _SLV2PluginClass { - struct _SLV2World* world; - SLV2Value uri; - SLV2Value parent_uri; - SLV2Value label; -}; - -SLV2PluginClass slv2_plugin_class_new(SLV2World world, - SLV2Node parent_uri, - SLV2Node uri, - const char* label); - -void slv2_plugin_class_free(SLV2PluginClass plugin_class); - -/* ********* Plugin Classes ********* */ - -SLV2PluginClasses slv2_plugin_classes_new(); -void slv2_plugin_classes_free(); - -/* ********* World ********* */ - -typedef struct { - bool dyn_manifest; - bool filter_language; -} SLV2Options; - -/** Model of LV2 (RDF) data loaded from bundles. - */ -struct _SLV2World { - SordWorld* world; - SordModel* model; - SerdReader* reader; - SerdEnv* namespaces; - unsigned n_read_files; - SLV2PluginClass lv2_plugin_class; - SLV2PluginClasses plugin_classes; - GSList* specs; - SLV2Plugins plugins; - SordNode* dc_replaces_node; - SordNode* dyn_manifest_node; - SordNode* lv2_specification_node; - SordNode* lv2_plugin_node; - SordNode* lv2_binary_node; - SordNode* lv2_default_node; - SordNode* lv2_minimum_node; - SordNode* lv2_maximum_node; - SordNode* lv2_port_node; - SordNode* lv2_portproperty_node; - SordNode* lv2_reportslatency_node; - SordNode* lv2_index_node; - SordNode* lv2_symbol_node; - SordNode* rdf_a_node; - SordNode* rdf_value_node; - SordNode* rdfs_class_node; - SordNode* rdfs_label_node; - SordNode* rdfs_seealso_node; - SordNode* rdfs_subclassof_node; - SordNode* slv2_dmanifest_node; - SordNode* xsd_boolean_node; - SordNode* xsd_decimal_node; - SordNode* xsd_double_node; - SordNode* xsd_integer_node; - SLV2Value doap_name_val; - SLV2Value lv2_name_val; - SLV2Options opt; -}; - -const uint8_t* -slv2_world_blank_node_prefix(SLV2World world); -void -slv2_world_load_file(SLV2World world, const char* file_uri); - -/* ********* Plugin UI ********* */ - -struct _SLV2UI { - struct _SLV2World* world; - SLV2Value uri; - SLV2Value bundle_uri; - SLV2Value binary_uri; - SLV2Values classes; -}; - -SLV2UIs slv2_uis_new(); - -SLV2UI -slv2_ui_new(SLV2World world, - SLV2Value uri, - SLV2Value type_uri, - SLV2Value binary_uri); - -void slv2_ui_free(SLV2UI ui); - -/* ********* Value ********* */ - -typedef enum _SLV2ValueType { - SLV2_VALUE_URI, - SLV2_VALUE_QNAME_UNUSED, ///< FIXME: APIBREAK: remove - SLV2_VALUE_STRING, - SLV2_VALUE_INT, - SLV2_VALUE_FLOAT, - SLV2_VALUE_BOOL, - SLV2_VALUE_BLANK -} SLV2ValueType; - -struct _SLV2Value { - SLV2World world; - char* str_val; ///< always present - union { - int int_val; - float float_val; - bool bool_val; - SordNode* uri_val; - } val; - SLV2ValueType type; -}; - -SLV2Value slv2_value_new(SLV2World world, SLV2ValueType type, const char* val); -SLV2Value slv2_value_new_from_node(SLV2World world, SLV2Node node); -SLV2Node slv2_value_as_node(SLV2Value value); - -int -slv2_header_compare_by_uri(const void* a, const void* b, void* user_data); - -static inline void -slv2_sequence_insert(GSequence* seq, void* value) -{ - g_sequence_insert_sorted(seq, value, slv2_header_compare_by_uri, NULL); -} - -static inline void -slv2_array_append(GSequence* seq, void* value) { - g_sequence_append(seq, value); -} - -struct _SLV2Header* -slv2_sequence_get_by_uri(GSequence* seq, SLV2Value uri); - -static inline SordNode* slv2_node_copy(SLV2Node node) { - return sord_node_copy(node); -} - -static inline void slv2_node_free(SLV2World world, SordNode* node) { - sord_node_free(world->world, node); -} - -/* ********* Scale Points ********* */ - -struct _SLV2ScalePoint { - SLV2Value value; - SLV2Value label; -}; - -SLV2ScalePoint slv2_scale_point_new(SLV2Value value, SLV2Value label); -void slv2_scale_point_free(SLV2ScalePoint point); - -/* ********* Query Results ********* */ - -SLV2Matches slv2_plugin_find_statements(SLV2Plugin plugin, - SLV2Node subject, - SLV2Node predicate, - SLV2Node object); - -static inline bool slv2_matches_next(SLV2Matches matches) { - return sord_iter_next(matches); -} - -static inline bool slv2_matches_end(SLV2Matches matches) { - return sord_iter_end(matches); -} - -SLV2Values slv2_values_from_stream_objects(SLV2Plugin p, - SLV2Matches stream); - -/* ********* Utilities ********* */ - -char* slv2_strjoin(const char* first, ...); -char* slv2_strdup(const char* str); -char* slv2_get_lang(); -uint8_t* slv2_qname_expand(SLV2Plugin p, const char* qname); - -typedef void (*VoidFunc)(); - -/** dlsym wrapper to return a function pointer (without annoying warning) */ -static inline VoidFunc -slv2_dlfunc(void* handle, const char* symbol) -{ - typedef VoidFunc (*VoidFuncGetter)(void*, const char*); - VoidFuncGetter dlfunc = (VoidFuncGetter)dlsym; - return dlfunc(handle, symbol); -} - -/* ********* Dynamic Manifest ********* */ -#ifdef SLV2_DYN_MANIFEST -static const LV2_Feature* const dman_features = { NULL }; -#endif - -#define SLV2_ERROR(str) fprintf(stderr, "ERROR: %s: " str, __func__) -#define SLV2_ERRORF(fmt, ...) fprintf(stderr, "ERROR: %s: " fmt, __func__, __VA_ARGS__) - -#define SLV2_WARN(str) fprintf(stderr, "WARNING: %s: " str, __func__) -#define SLV2_WARNF(fmt, ...) fprintf(stderr, "WARNING: %s: " fmt, __func__, __VA_ARGS__) - -#ifdef __cplusplus -} -#endif - -#endif /* SLV2_INTERNAL_H */ @@ -21,10 +21,10 @@ #include <stdlib.h> #include <string.h> -#include "slv2_internal.h" +#include "lilv_internal.h" char* -slv2_strjoin(const char* first, ...) +lilv_strjoin(const char* first, ...) { size_t len = strlen(first); char* result = malloc(len + 1); @@ -51,7 +51,7 @@ slv2_strjoin(const char* first, ...) } char* -slv2_strdup(const char* str) +lilv_strdup(const char* str) { const size_t len = strlen(str); char* dup = malloc(len + 1); @@ -60,7 +60,7 @@ slv2_strdup(const char* str) } const char* -slv2_uri_to_path(const char* uri) +lilv_uri_to_path(const char* uri) { #ifdef __WIN32__ if (!strncmp(uri, "file:///", (size_t)8)) { @@ -78,7 +78,7 @@ slv2_uri_to_path(const char* uri) * For example, if LANG is set to "en_CA.utf-8", this returns "en-ca". */ char* -slv2_get_lang() +lilv_get_lang() { const char* const env_lang = getenv("LANG"); if (!env_lang || !strcmp(env_lang, "") @@ -102,7 +102,7 @@ slv2_get_lang() lang[i] = '\0'; break; } else { - SLV2_ERRORF("Illegal LANG `%s' ignored\n", env_lang); + LILV_ERRORF("Illegal LANG `%s' ignored\n", env_lang); free(lang); return NULL; } @@ -112,7 +112,7 @@ slv2_get_lang() } uint8_t* -slv2_qname_expand(SLV2Plugin p, const char* qname) +lilv_qname_expand(LilvPlugin p, const char* qname) { const size_t qname_len = strlen(qname); SerdNode qname_node = { (const uint8_t*)qname, @@ -129,7 +129,7 @@ slv2_qname_expand(SLV2Plugin p, const char* qname) uri[uri_len] = '\0'; return (uint8_t*)uri; } else { - SLV2_ERRORF("Failed to expand QName `%s'\n", qname); + LILV_ERRORF("Failed to expand QName `%s'\n", qname); return NULL; } } diff --git a/src/value.c b/src/value.c index 486182e..991f681 100644 --- a/src/value.c +++ b/src/value.c @@ -23,116 +23,116 @@ #include <glib.h> -#include "slv2_internal.h" +#include "lilv_internal.h" static void -slv2_value_set_numerics_from_string(SLV2Value val) +lilv_value_set_numerics_from_string(LilvValue val) { char* locale; char* endptr; switch (val->type) { - case SLV2_VALUE_URI: - case SLV2_VALUE_BLANK: - case SLV2_VALUE_QNAME_UNUSED: - case SLV2_VALUE_STRING: + case LILV_VALUE_URI: + case LILV_VALUE_BLANK: + case LILV_VALUE_QNAME_UNUSED: + case LILV_VALUE_STRING: break; - case SLV2_VALUE_INT: + case LILV_VALUE_INT: // FIXME: locale kludge, need a locale independent strtol - locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); + locale = lilv_strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "POSIX"); val->val.int_val = strtol(val->str_val, &endptr, 10); setlocale(LC_NUMERIC, locale); free(locale); break; - case SLV2_VALUE_FLOAT: + case LILV_VALUE_FLOAT: // FIXME: locale kludge, need a locale independent strtod - locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); + locale = lilv_strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "POSIX"); val->val.float_val = strtod(val->str_val, &endptr); setlocale(LC_NUMERIC, locale); free(locale); break; - case SLV2_VALUE_BOOL: + case LILV_VALUE_BOOL: val->val.bool_val = (!strcmp(val->str_val, "true")); break; } } /** Note that if @a type is numeric or boolean, the returned value is corrupt - * until slv2_value_set_numerics_from_string is called. It is not + * until lilv_value_set_numerics_from_string is called. It is not * automatically called from here to avoid overhead and imprecision when the * exact string value is known. */ -SLV2Value -slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) +LilvValue +lilv_value_new(LilvWorld world, LilvValueType type, const char* str) { - SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); + LilvValue val = (LilvValue)malloc(sizeof(struct _LilvValue)); val->world = world; val->type = type; switch (type) { - case SLV2_VALUE_URI: + case LILV_VALUE_URI: val->val.uri_val = sord_new_uri(world->world, (const uint8_t*)str); assert(val->val.uri_val); val->str_val = (char*)sord_node_get_string(val->val.uri_val); break; - case SLV2_VALUE_QNAME_UNUSED: - case SLV2_VALUE_BLANK: - case SLV2_VALUE_STRING: - case SLV2_VALUE_INT: - case SLV2_VALUE_FLOAT: - case SLV2_VALUE_BOOL: - val->str_val = slv2_strdup(str); + case LILV_VALUE_QNAME_UNUSED: + case LILV_VALUE_BLANK: + case LILV_VALUE_STRING: + case LILV_VALUE_INT: + case LILV_VALUE_FLOAT: + case LILV_VALUE_BOOL: + val->str_val = lilv_strdup(str); break; } return val; } -/** Create a new SLV2Value from @a node, or return NULL if impossible */ -SLV2Value -slv2_value_new_from_node(SLV2World world, const SordNode* node) +/** Create a new LilvValue from @a node, or return NULL if impossible */ +LilvValue +lilv_value_new_from_node(LilvWorld world, const SordNode* node) { - SLV2Value result = NULL; + LilvValue result = NULL; SordNode* datatype_uri = NULL; - SLV2ValueType type = SLV2_VALUE_STRING; + LilvValueType type = LILV_VALUE_STRING; switch (sord_node_get_type(node)) { case SORD_URI: - type = SLV2_VALUE_URI; - result = (SLV2Value)malloc(sizeof(struct _SLV2Value)); + type = LILV_VALUE_URI; + result = (LilvValue)malloc(sizeof(struct _LilvValue)); result->world = world; - result->type = SLV2_VALUE_URI; - result->val.uri_val = slv2_node_copy(node); + result->type = LILV_VALUE_URI; + result->val.uri_val = lilv_node_copy(node); result->str_val = (char*)sord_node_get_string(result->val.uri_val); break; case SORD_LITERAL: datatype_uri = sord_node_get_datatype(node); if (datatype_uri) { if (sord_node_equals(datatype_uri, world->xsd_boolean_node)) - type = SLV2_VALUE_BOOL; + type = LILV_VALUE_BOOL; else if (sord_node_equals(datatype_uri, world->xsd_decimal_node) || sord_node_equals(datatype_uri, world->xsd_double_node)) - type = SLV2_VALUE_FLOAT; + type = LILV_VALUE_FLOAT; else if (sord_node_equals(datatype_uri, world->xsd_integer_node)) - type = SLV2_VALUE_INT; + type = LILV_VALUE_INT; else - SLV2_ERRORF("Unknown datatype %s\n", sord_node_get_string(datatype_uri)); + LILV_ERRORF("Unknown datatype %s\n", sord_node_get_string(datatype_uri)); } - result = slv2_value_new(world, type, (const char*)sord_node_get_string(node)); + result = lilv_value_new(world, type, (const char*)sord_node_get_string(node)); switch (result->type) { - case SLV2_VALUE_INT: - case SLV2_VALUE_FLOAT: - case SLV2_VALUE_BOOL: - slv2_value_set_numerics_from_string(result); + case LILV_VALUE_INT: + case LILV_VALUE_FLOAT: + case LILV_VALUE_BOOL: + lilv_value_set_numerics_from_string(result); default: break; } break; case SORD_BLANK: - type = SLV2_VALUE_BLANK; - result = slv2_value_new(world, type, (const char*)sord_node_get_string(node)); + type = LILV_VALUE_BLANK; + result = lilv_value_new(world, type, (const char*)sord_node_get_string(node)); break; default: assert(false); @@ -141,80 +141,80 @@ slv2_value_new_from_node(SLV2World world, const SordNode* node) return result; } -SLV2_API -SLV2Value -slv2_value_new_uri(SLV2World world, const char* uri) +LILV_API +LilvValue +lilv_value_new_uri(LilvWorld world, const char* uri) { - return slv2_value_new(world, SLV2_VALUE_URI, uri); + return lilv_value_new(world, LILV_VALUE_URI, uri); } -SLV2_API -SLV2Value -slv2_value_new_string(SLV2World world, const char* str) +LILV_API +LilvValue +lilv_value_new_string(LilvWorld world, const char* str) { - return slv2_value_new(world, SLV2_VALUE_STRING, str); + return lilv_value_new(world, LILV_VALUE_STRING, str); } -SLV2_API -SLV2Value -slv2_value_new_int(SLV2World world, int val) +LILV_API +LilvValue +lilv_value_new_int(LilvWorld world, int val) { char str[32]; snprintf(str, sizeof(str), "%d", val); - SLV2Value ret = slv2_value_new(world, SLV2_VALUE_INT, str); + LilvValue ret = lilv_value_new(world, LILV_VALUE_INT, str); ret->val.int_val = val; return ret; } -SLV2_API -SLV2Value -slv2_value_new_float(SLV2World world, float val) +LILV_API +LilvValue +lilv_value_new_float(LilvWorld world, float val) { char str[32]; snprintf(str, sizeof(str), "%f", val); - SLV2Value ret = slv2_value_new(world, SLV2_VALUE_FLOAT, str); + LilvValue ret = lilv_value_new(world, LILV_VALUE_FLOAT, str); ret->val.float_val = val; return ret; } -SLV2_API -SLV2Value -slv2_value_new_bool(SLV2World world, bool val) +LILV_API +LilvValue +lilv_value_new_bool(LilvWorld world, bool val) { - SLV2Value ret = slv2_value_new(world, SLV2_VALUE_BOOL, val ? "true" : "false"); + LilvValue ret = lilv_value_new(world, LILV_VALUE_BOOL, val ? "true" : "false"); ret->val.bool_val = val; return ret; } -SLV2_API -SLV2Value -slv2_value_duplicate(SLV2Value val) +LILV_API +LilvValue +lilv_value_duplicate(LilvValue val) { if (val == NULL) return val; - SLV2Value result = (SLV2Value)malloc(sizeof(struct _SLV2Value)); + LilvValue result = (LilvValue)malloc(sizeof(struct _LilvValue)); result->world = val->world; result->type = val->type; - if (val->type == SLV2_VALUE_URI) { - result->val.uri_val = slv2_node_copy(val->val.uri_val); + if (val->type == LILV_VALUE_URI) { + result->val.uri_val = lilv_node_copy(val->val.uri_val); result->str_val = (char*)sord_node_get_string(result->val.uri_val); } else { - result->str_val = slv2_strdup(val->str_val); + result->str_val = lilv_strdup(val->str_val); result->val = val->val; } return result; } -SLV2_API +LILV_API void -slv2_value_free(SLV2Value val) +lilv_value_free(LilvValue val) { if (val) { - if (val->type == SLV2_VALUE_URI) { - slv2_node_free(val->world, val->val.uri_val); + if (val->type == LILV_VALUE_URI) { + lilv_node_free(val->world, val->val.uri_val); } else { free(val->str_val); } @@ -222,9 +222,9 @@ slv2_value_free(SLV2Value val) } } -SLV2_API +LILV_API bool -slv2_value_equals(SLV2Value value, SLV2Value other) +lilv_value_equals(LilvValue value, LilvValue other) { if (value == NULL && other == NULL) return true; @@ -234,60 +234,60 @@ slv2_value_equals(SLV2Value value, SLV2Value other) return false; switch (value->type) { - case SLV2_VALUE_URI: + case LILV_VALUE_URI: return sord_node_equals(value->val.uri_val, other->val.uri_val); - case SLV2_VALUE_BLANK: - case SLV2_VALUE_STRING: - case SLV2_VALUE_QNAME_UNUSED: + case LILV_VALUE_BLANK: + case LILV_VALUE_STRING: + case LILV_VALUE_QNAME_UNUSED: return !strcmp(value->str_val, other->str_val); - case SLV2_VALUE_INT: + case LILV_VALUE_INT: return (value->val.int_val == other->val.int_val); - case SLV2_VALUE_FLOAT: + case LILV_VALUE_FLOAT: return (value->val.float_val == other->val.float_val); - case SLV2_VALUE_BOOL: + case LILV_VALUE_BOOL: return (value->val.bool_val == other->val.bool_val); } return false; /* shouldn't get here */ } -SLV2_API +LILV_API char* -slv2_value_get_turtle_token(SLV2Value value) +lilv_value_get_turtle_token(LilvValue value) { size_t len = 0; char* result = NULL; char* locale = NULL; switch (value->type) { - case SLV2_VALUE_URI: + case LILV_VALUE_URI: len = strlen(value->str_val) + 3; result = calloc(len, 1); snprintf(result, len, "<%s>", value->str_val); break; - case SLV2_VALUE_BLANK: + case LILV_VALUE_BLANK: len = strlen(value->str_val) + 3; result = calloc(len, 1); snprintf(result, len, "_:%s", value->str_val); break; - case SLV2_VALUE_STRING: - case SLV2_VALUE_QNAME_UNUSED: - case SLV2_VALUE_BOOL: - result = slv2_strdup(value->str_val); + case LILV_VALUE_STRING: + case LILV_VALUE_QNAME_UNUSED: + case LILV_VALUE_BOOL: + result = lilv_strdup(value->str_val); break; - case SLV2_VALUE_INT: + case LILV_VALUE_INT: // INT64_MAX is 9223372036854775807 (19 digits) + 1 for sign // FIXME: locale kludge, need a locale independent snprintf - locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); + locale = lilv_strdup(setlocale(LC_NUMERIC, NULL)); len = 20; result = calloc(len, 1); setlocale(LC_NUMERIC, "POSIX"); snprintf(result, len, "%d", value->val.int_val); setlocale(LC_NUMERIC, locale); break; - case SLV2_VALUE_FLOAT: + case LILV_VALUE_FLOAT: // FIXME: locale kludge, need a locale independent snprintf - locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); + locale = lilv_strdup(setlocale(LC_NUMERIC, NULL)); len = 20; // FIXME: proper maximum value? result = calloc(len, 1); setlocale(LC_NUMERIC, "POSIX"); @@ -301,120 +301,120 @@ slv2_value_get_turtle_token(SLV2Value value) return result; } -SLV2_API +LILV_API bool -slv2_value_is_uri(SLV2Value value) +lilv_value_is_uri(LilvValue value) { - return (value && value->type == SLV2_VALUE_URI); + return (value && value->type == LILV_VALUE_URI); } -SLV2_API +LILV_API const char* -slv2_value_as_uri(SLV2Value value) +lilv_value_as_uri(LilvValue value) { - assert(slv2_value_is_uri(value)); + assert(lilv_value_is_uri(value)); return value->str_val; } -SLV2Node -slv2_value_as_node(SLV2Value value) +LilvNode +lilv_value_as_node(LilvValue value) { - assert(slv2_value_is_uri(value)); + assert(lilv_value_is_uri(value)); return value->val.uri_val; } -SLV2_API +LILV_API bool -slv2_value_is_blank(SLV2Value value) +lilv_value_is_blank(LilvValue value) { - return (value && value->type == SLV2_VALUE_BLANK); + return (value && value->type == LILV_VALUE_BLANK); } -SLV2_API +LILV_API const char* -slv2_value_as_blank(SLV2Value value) +lilv_value_as_blank(LilvValue value) { - assert(slv2_value_is_blank(value)); + assert(lilv_value_is_blank(value)); return value->str_val; } -SLV2_API +LILV_API bool -slv2_value_is_literal(SLV2Value value) +lilv_value_is_literal(LilvValue value) { if (!value) return false; switch (value->type) { - case SLV2_VALUE_STRING: - case SLV2_VALUE_INT: - case SLV2_VALUE_FLOAT: + case LILV_VALUE_STRING: + case LILV_VALUE_INT: + case LILV_VALUE_FLOAT: return true; default: return false; } } -SLV2_API +LILV_API bool -slv2_value_is_string(SLV2Value value) +lilv_value_is_string(LilvValue value) { - return (value && value->type == SLV2_VALUE_STRING); + return (value && value->type == LILV_VALUE_STRING); } -SLV2_API +LILV_API const char* -slv2_value_as_string(SLV2Value value) +lilv_value_as_string(LilvValue value) { return value->str_val; } -SLV2_API +LILV_API bool -slv2_value_is_int(SLV2Value value) +lilv_value_is_int(LilvValue value) { - return (value && value->type == SLV2_VALUE_INT); + return (value && value->type == LILV_VALUE_INT); } -SLV2_API +LILV_API int -slv2_value_as_int(SLV2Value value) +lilv_value_as_int(LilvValue value) { assert(value); - assert(slv2_value_is_int(value)); + assert(lilv_value_is_int(value)); return value->val.int_val; } -SLV2_API +LILV_API bool -slv2_value_is_float(SLV2Value value) +lilv_value_is_float(LilvValue value) { - return (value && value->type == SLV2_VALUE_FLOAT); + return (value && value->type == LILV_VALUE_FLOAT); } -SLV2_API +LILV_API float -slv2_value_as_float(SLV2Value value) +lilv_value_as_float(LilvValue value) { - assert(slv2_value_is_float(value) || slv2_value_is_int(value)); - if (slv2_value_is_float(value)) + assert(lilv_value_is_float(value) || lilv_value_is_int(value)); + if (lilv_value_is_float(value)) return value->val.float_val; - else // slv2_value_is_int(value) + else // lilv_value_is_int(value) return (float)value->val.int_val; } -SLV2_API +LILV_API bool -slv2_value_is_bool(SLV2Value value) +lilv_value_is_bool(LilvValue value) { - return (value && value->type == SLV2_VALUE_BOOL); + return (value && value->type == LILV_VALUE_BOOL); } -SLV2_API +LILV_API bool -slv2_value_as_bool(SLV2Value value) +lilv_value_as_bool(LilvValue value) { assert(value); - assert(slv2_value_is_bool(value)); + assert(lilv_value_is_bool(value)); return value->val.bool_val; } diff --git a/src/world.c b/src/world.c index 6970598..133185b 100644 --- a/src/world.c +++ b/src/world.c @@ -26,10 +26,10 @@ #include <wordexp.h> #endif -#include "slv2_internal.h" +#include "lilv_internal.h" static void -slv2_world_set_prefix(SLV2World world, const char* name, const char* uri) +lilv_world_set_prefix(LilvWorld world, const char* name, const char* uri) { const SerdNode name_node = serd_node_from_string(SERD_LITERAL, (const uint8_t*)name); @@ -38,11 +38,11 @@ slv2_world_set_prefix(SLV2World world, const char* name, const char* uri) serd_env_add(world->namespaces, &name_node, &uri_node); } -SLV2_API -SLV2World -slv2_world_new() +LILV_API +LilvWorld +lilv_world_new() { - SLV2World world = (SLV2World)malloc(sizeof(struct _SLV2World)); + LilvWorld world = (LilvWorld)malloc(sizeof(struct _LilvWorld)); world->world = sord_world_new(); if (!world->world) @@ -53,54 +53,54 @@ slv2_world_new() goto fail; world->specs = NULL; - world->plugin_classes = slv2_plugin_classes_new(); - world->plugins = slv2_plugins_new(); + world->plugin_classes = lilv_plugin_classes_new(); + world->plugins = lilv_plugins_new(); #define NS_DYNMAN (const uint8_t*)"http://lv2plug.in/ns/ext/dynmanifest#" #define NS_DC (const uint8_t*)"http://dublincore.org/documents/dcmi-namespace/" #define NEW_URI(uri) sord_new_uri(world->world, uri) -#define NEW_URI_VAL(uri) slv2_value_new_uri(world, (const char*)(uri)); +#define NEW_URI_VAL(uri) lilv_value_new_uri(world, (const char*)(uri)); world->dc_replaces_node = NEW_URI(NS_DC "replaces"); world->dyn_manifest_node = NEW_URI(NS_DYNMAN "DynManifest"); - world->lv2_specification_node = NEW_URI(SLV2_NS_LV2 "Specification"); - world->lv2_plugin_node = NEW_URI(SLV2_NS_LV2 "Plugin"); - world->lv2_binary_node = NEW_URI(SLV2_NS_LV2 "binary"); - world->lv2_default_node = NEW_URI(SLV2_NS_LV2 "default"); - world->lv2_minimum_node = NEW_URI(SLV2_NS_LV2 "minimum"); - world->lv2_maximum_node = NEW_URI(SLV2_NS_LV2 "maximum"); - world->lv2_port_node = NEW_URI(SLV2_NS_LV2 "port"); - world->lv2_portproperty_node = NEW_URI(SLV2_NS_LV2 "portProperty"); - world->lv2_reportslatency_node = NEW_URI(SLV2_NS_LV2 "reportsLatency"); - world->lv2_index_node = NEW_URI(SLV2_NS_LV2 "index"); - world->lv2_symbol_node = NEW_URI(SLV2_NS_LV2 "symbol"); - world->rdf_a_node = NEW_URI(SLV2_NS_RDF "type"); - world->rdf_value_node = NEW_URI(SLV2_NS_RDF "value"); - world->rdfs_class_node = NEW_URI(SLV2_NS_RDFS "Class"); - world->rdfs_label_node = NEW_URI(SLV2_NS_RDFS "label"); - world->rdfs_seealso_node = NEW_URI(SLV2_NS_RDFS "seeAlso"); - world->rdfs_subclassof_node = NEW_URI(SLV2_NS_RDFS "subClassOf"); - world->slv2_dmanifest_node = NEW_URI(SLV2_NS_SLV2 "dynamic-manifest"); - world->xsd_boolean_node = NEW_URI(SLV2_NS_XSD "boolean"); - world->xsd_decimal_node = NEW_URI(SLV2_NS_XSD "decimal"); - world->xsd_double_node = NEW_URI(SLV2_NS_XSD "double"); - world->xsd_integer_node = NEW_URI(SLV2_NS_XSD "integer"); - - world->doap_name_val = NEW_URI_VAL(SLV2_NS_DOAP "name"); - world->lv2_name_val = NEW_URI_VAL(SLV2_NS_LV2 "name"); - - world->lv2_plugin_class = slv2_plugin_class_new( + world->lv2_specification_node = NEW_URI(LILV_NS_LV2 "Specification"); + world->lv2_plugin_node = NEW_URI(LILV_NS_LV2 "Plugin"); + world->lv2_binary_node = NEW_URI(LILV_NS_LV2 "binary"); + world->lv2_default_node = NEW_URI(LILV_NS_LV2 "default"); + world->lv2_minimum_node = NEW_URI(LILV_NS_LV2 "minimum"); + world->lv2_maximum_node = NEW_URI(LILV_NS_LV2 "maximum"); + world->lv2_port_node = NEW_URI(LILV_NS_LV2 "port"); + world->lv2_portproperty_node = NEW_URI(LILV_NS_LV2 "portProperty"); + world->lv2_reportslatency_node = NEW_URI(LILV_NS_LV2 "reportsLatency"); + world->lv2_index_node = NEW_URI(LILV_NS_LV2 "index"); + world->lv2_symbol_node = NEW_URI(LILV_NS_LV2 "symbol"); + world->rdf_a_node = NEW_URI(LILV_NS_RDF "type"); + world->rdf_value_node = NEW_URI(LILV_NS_RDF "value"); + world->rdfs_class_node = NEW_URI(LILV_NS_RDFS "Class"); + world->rdfs_label_node = NEW_URI(LILV_NS_RDFS "label"); + world->rdfs_seealso_node = NEW_URI(LILV_NS_RDFS "seeAlso"); + world->rdfs_subclassof_node = NEW_URI(LILV_NS_RDFS "subClassOf"); + world->lilv_dmanifest_node = NEW_URI(LILV_NS_LILV "dynamic-manifest"); + world->xsd_boolean_node = NEW_URI(LILV_NS_XSD "boolean"); + world->xsd_decimal_node = NEW_URI(LILV_NS_XSD "decimal"); + world->xsd_double_node = NEW_URI(LILV_NS_XSD "double"); + world->xsd_integer_node = NEW_URI(LILV_NS_XSD "integer"); + + world->doap_name_val = NEW_URI_VAL(LILV_NS_DOAP "name"); + world->lv2_name_val = NEW_URI_VAL(LILV_NS_LV2 "name"); + + world->lv2_plugin_class = lilv_plugin_class_new( world, NULL, world->lv2_plugin_node, "Plugin"); assert(world->lv2_plugin_class); world->namespaces = serd_env_new(); - slv2_world_set_prefix(world, "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); - slv2_world_set_prefix(world, "rdfs", "http://www.w3.org/2000/01/rdf-schema#"); - slv2_world_set_prefix(world, "doap", "http://usefulinc.com/ns/doap#"); - slv2_world_set_prefix(world, "foaf", "http://xmlns.com/foaf/0.1/"); - slv2_world_set_prefix(world, "lv2", "http://lv2plug.in/ns/lv2core#"); - slv2_world_set_prefix(world, "lv2ev", "http://lv2plug.in/ns/ext/event#"); + lilv_world_set_prefix(world, "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); + lilv_world_set_prefix(world, "rdfs", "http://www.w3.org/2000/01/rdf-schema#"); + lilv_world_set_prefix(world, "doap", "http://usefulinc.com/ns/doap#"); + lilv_world_set_prefix(world, "foaf", "http://xmlns.com/foaf/0.1/"); + lilv_world_set_prefix(world, "lv2", "http://lv2plug.in/ns/lv2core#"); + lilv_world_set_prefix(world, "lv2ev", "http://lv2plug.in/ns/ext/event#"); world->n_read_files = 0; world->opt.filter_language = true; @@ -113,53 +113,53 @@ fail: return NULL; } -SLV2_API +LILV_API void -slv2_world_free(SLV2World world) +lilv_world_free(LilvWorld world) { - slv2_plugin_class_free(world->lv2_plugin_class); + lilv_plugin_class_free(world->lv2_plugin_class); world->lv2_plugin_class = NULL; - slv2_node_free(world, world->dc_replaces_node); - slv2_node_free(world, world->dyn_manifest_node); - slv2_node_free(world, world->lv2_specification_node); - slv2_node_free(world, world->lv2_plugin_node); - slv2_node_free(world, world->lv2_binary_node); - slv2_node_free(world, world->lv2_default_node); - slv2_node_free(world, world->lv2_minimum_node); - slv2_node_free(world, world->lv2_maximum_node); - slv2_node_free(world, world->lv2_port_node); - slv2_node_free(world, world->lv2_portproperty_node); - slv2_node_free(world, world->lv2_reportslatency_node); - slv2_node_free(world, world->lv2_index_node); - slv2_node_free(world, world->lv2_symbol_node); - slv2_node_free(world, world->rdf_a_node); - slv2_node_free(world, world->rdf_value_node); - slv2_node_free(world, world->rdfs_label_node); - slv2_node_free(world, world->rdfs_seealso_node); - slv2_node_free(world, world->rdfs_subclassof_node); - slv2_node_free(world, world->rdfs_class_node); - slv2_node_free(world, world->slv2_dmanifest_node); - slv2_node_free(world, world->xsd_boolean_node); - slv2_node_free(world, world->xsd_decimal_node); - slv2_node_free(world, world->xsd_double_node); - slv2_node_free(world, world->xsd_integer_node); - slv2_value_free(world->doap_name_val); - slv2_value_free(world->lv2_name_val); + lilv_node_free(world, world->dc_replaces_node); + lilv_node_free(world, world->dyn_manifest_node); + lilv_node_free(world, world->lv2_specification_node); + lilv_node_free(world, world->lv2_plugin_node); + lilv_node_free(world, world->lv2_binary_node); + lilv_node_free(world, world->lv2_default_node); + lilv_node_free(world, world->lv2_minimum_node); + lilv_node_free(world, world->lv2_maximum_node); + lilv_node_free(world, world->lv2_port_node); + lilv_node_free(world, world->lv2_portproperty_node); + lilv_node_free(world, world->lv2_reportslatency_node); + lilv_node_free(world, world->lv2_index_node); + lilv_node_free(world, world->lv2_symbol_node); + lilv_node_free(world, world->rdf_a_node); + lilv_node_free(world, world->rdf_value_node); + lilv_node_free(world, world->rdfs_label_node); + lilv_node_free(world, world->rdfs_seealso_node); + lilv_node_free(world, world->rdfs_subclassof_node); + lilv_node_free(world, world->rdfs_class_node); + lilv_node_free(world, world->lilv_dmanifest_node); + lilv_node_free(world, world->xsd_boolean_node); + lilv_node_free(world, world->xsd_decimal_node); + lilv_node_free(world, world->xsd_double_node); + lilv_node_free(world, world->xsd_integer_node); + lilv_value_free(world->doap_name_val); + lilv_value_free(world->lv2_name_val); for (GSList* l = world->specs; l; l = l->next) { - SLV2Spec spec = (SLV2Spec)l->data; - slv2_node_free(world, spec->spec); - slv2_node_free(world, spec->bundle); - slv2_values_free(spec->data_uris); + LilvSpec spec = (LilvSpec)l->data; + lilv_node_free(world, spec->spec); + lilv_node_free(world, spec->bundle); + lilv_values_free(spec->data_uris); free(spec); } g_slist_free(world->specs); world->specs = NULL; - SLV2_FOREACH(plugins, i, world->plugins) { - SLV2Plugin p = slv2_plugins_get(world->plugins, i); - slv2_plugin_free(p); + LILV_FOREACH(plugins, i, world->plugins) { + LilvPlugin p = lilv_plugins_get(world->plugins, i); + lilv_plugin_free(p); } g_sequence_free(world->plugins); world->plugins = NULL; @@ -178,40 +178,40 @@ slv2_world_free(SLV2World world) free(world); } -SLV2_API +LILV_API void -slv2_world_set_option(SLV2World world, +lilv_world_set_option(LilvWorld world, const char* option, - const SLV2Value value) + const LilvValue value) { - if (!strcmp(option, SLV2_OPTION_DYN_MANIFEST)) { - if (slv2_value_is_bool(value)) { - world->opt.dyn_manifest = slv2_value_as_bool(value); + if (!strcmp(option, LILV_OPTION_DYN_MANIFEST)) { + if (lilv_value_is_bool(value)) { + world->opt.dyn_manifest = lilv_value_as_bool(value); return; } - } else if (!strcmp(option, SLV2_OPTION_FILTER_LANG)) { - if (slv2_value_is_bool(value)) { - world->opt.filter_language = slv2_value_as_bool(value); + } else if (!strcmp(option, LILV_OPTION_FILTER_LANG)) { + if (lilv_value_is_bool(value)) { + world->opt.filter_language = lilv_value_as_bool(value); return; } } - SLV2_WARNF("Unrecognized or invalid option `%s'\n", option); + LILV_WARNF("Unrecognized or invalid option `%s'\n", option); } -static SLV2Matches -slv2_world_find_statements(SLV2World world, +static LilvMatches +lilv_world_find_statements(LilvWorld world, SordModel* model, - SLV2Node subject, - SLV2Node predicate, - SLV2Node object, - SLV2Node graph) + LilvNode subject, + LilvNode predicate, + LilvNode object, + LilvNode graph) { SordQuad pat = { subject, predicate, object, graph }; return sord_find(model, pat); } static SerdNode -slv2_new_uri_relative_to_base(const uint8_t* uri_str, +lilv_new_uri_relative_to_base(const uint8_t* uri_str, const uint8_t* base_uri_str) { SerdURI base_uri; @@ -224,7 +224,7 @@ slv2_new_uri_relative_to_base(const uint8_t* uri_str, } const uint8_t* -slv2_world_blank_node_prefix(SLV2World world) +lilv_world_blank_node_prefix(LilvWorld world) { static char str[32]; snprintf(str, sizeof(str), "%d", world->n_read_files++); @@ -233,38 +233,38 @@ slv2_world_blank_node_prefix(SLV2World world) /** Comparator for sequences (e.g. world->plugins). */ int -slv2_header_compare_by_uri(const void* a, const void* b, void* user_data) +lilv_header_compare_by_uri(const void* a, const void* b, void* user_data) { - const struct _SLV2Header* const header_a = (const struct _SLV2Header*)a; - const struct _SLV2Header* const header_b = (const struct _SLV2Header*)b; - return strcmp(slv2_value_as_uri(header_a->uri), - slv2_value_as_uri(header_b->uri)); + const struct _LilvHeader* const header_a = (const struct _LilvHeader*)a; + const struct _LilvHeader* const header_b = (const struct _LilvHeader*)b; + return strcmp(lilv_value_as_uri(header_a->uri), + lilv_value_as_uri(header_b->uri)); } -/** Get an element of a sequence of any object with an SLV2Header by URI. */ -struct _SLV2Header* -slv2_sequence_get_by_uri(GSequence* seq, - SLV2Value uri) +/** Get an element of a sequence of any object with an LilvHeader by URI. */ +struct _LilvHeader* +lilv_sequence_get_by_uri(GSequence* seq, + LilvValue uri) { - struct _SLV2Header key = { NULL, uri }; + struct _LilvHeader key = { NULL, uri }; GSequenceIter* i = g_sequence_search( - seq, &key, slv2_header_compare_by_uri, NULL); + seq, &key, lilv_header_compare_by_uri, NULL); // i points to where plugin would be inserted (not necessarily a match) if (!g_sequence_iter_is_end(i)) { - SLV2Plugin p = g_sequence_get(i); - if (slv2_value_equals(slv2_plugin_get_uri(p), uri)) { - return (struct _SLV2Header*)p; + LilvPlugin p = g_sequence_get(i); + if (lilv_value_equals(lilv_plugin_get_uri(p), uri)) { + return (struct _LilvHeader*)p; } } if (!g_sequence_iter_is_begin(i)) { // Check if i is just past a match i = g_sequence_iter_prev(i); - SLV2Plugin p = g_sequence_get(i); - if (slv2_value_equals(slv2_plugin_get_uri(p), uri)) { - return (struct _SLV2Header*)p; + LilvPlugin p = g_sequence_get(i); + if (lilv_value_equals(lilv_plugin_get_uri(p), uri)) { + return (struct _LilvHeader*)p; } } @@ -272,89 +272,89 @@ slv2_sequence_get_by_uri(GSequence* seq, } static void -slv2_world_add_spec(SLV2World world, - SLV2Node specification_node, - SLV2Node bundle_node) +lilv_world_add_spec(LilvWorld world, + LilvNode specification_node, + LilvNode bundle_node) { - SLV2Spec spec = malloc(sizeof(struct _SLV2Spec)); - spec->spec = slv2_node_copy(specification_node); - spec->bundle = slv2_node_copy(bundle_node); - spec->data_uris = slv2_values_new(); + LilvSpec spec = malloc(sizeof(struct _LilvSpec)); + spec->spec = lilv_node_copy(specification_node); + spec->bundle = lilv_node_copy(bundle_node); + spec->data_uris = lilv_values_new(); // Add all plugin data files (rdfs:seeAlso) - SLV2Matches files = slv2_world_find_statements( + LilvMatches files = lilv_world_find_statements( world, world->model, specification_node, world->rdfs_seealso_node, NULL, NULL); FOREACH_MATCH(files) { - SLV2Node file_node = slv2_match_object(files); - slv2_array_append(spec->data_uris, - slv2_value_new_from_node(world, file_node)); + LilvNode file_node = lilv_match_object(files); + lilv_array_append(spec->data_uris, + lilv_value_new_from_node(world, file_node)); } - slv2_match_end(files); + lilv_match_end(files); // Add specification to world specification sequence world->specs = g_slist_prepend(world->specs, spec); } static void -slv2_world_add_plugin(SLV2World world, - SLV2Node plugin_node, +lilv_world_add_plugin(LilvWorld world, + LilvNode plugin_node, SerdNode* manifest_uri, - SLV2Node dyn_manifest_lib, - SLV2Node bundle_node) + LilvNode dyn_manifest_lib, + LilvNode bundle_node) { - SLV2Value plugin_uri = slv2_value_new_from_node(world, plugin_node); + LilvValue plugin_uri = lilv_value_new_from_node(world, plugin_node); - SLV2Plugin last = slv2_plugins_get_by_uri(world->plugins, plugin_uri); + LilvPlugin last = lilv_plugins_get_by_uri(world->plugins, plugin_uri); if (last) { - SLV2_ERRORF("Duplicate plugin <%s>\n", slv2_value_as_uri(plugin_uri)); - SLV2_ERRORF("... found in %s\n", slv2_value_as_string( - slv2_plugin_get_bundle_uri(last))); - SLV2_ERRORF("... and %s\n", sord_node_get_string(bundle_node)); - slv2_value_free(plugin_uri); + LILV_ERRORF("Duplicate plugin <%s>\n", lilv_value_as_uri(plugin_uri)); + LILV_ERRORF("... found in %s\n", lilv_value_as_string( + lilv_plugin_get_bundle_uri(last))); + LILV_ERRORF("... and %s\n", sord_node_get_string(bundle_node)); + lilv_value_free(plugin_uri); return; } - // Create SLV2Plugin - SLV2Value bundle_uri = slv2_value_new_from_node(world, bundle_node); - SLV2Plugin plugin = slv2_plugin_new(world, plugin_uri, bundle_uri); + // Create LilvPlugin + LilvValue bundle_uri = lilv_value_new_from_node(world, bundle_node); + LilvPlugin plugin = lilv_plugin_new(world, plugin_uri, bundle_uri); // Add manifest as plugin data file (as if it were rdfs:seeAlso) - slv2_array_append(plugin->data_uris, - slv2_value_new_uri(world, (const char*)manifest_uri->buf)); + lilv_array_append(plugin->data_uris, + lilv_value_new_uri(world, (const char*)manifest_uri->buf)); // Set dynamic manifest library URI, if applicable if (dyn_manifest_lib) { - plugin->dynman_uri = slv2_value_new_from_node(world, dyn_manifest_lib); + plugin->dynman_uri = lilv_value_new_from_node(world, dyn_manifest_lib); } // Add all plugin data files (rdfs:seeAlso) - SLV2Matches files = slv2_world_find_statements( + LilvMatches files = lilv_world_find_statements( world, world->model, plugin_node, world->rdfs_seealso_node, NULL, NULL); FOREACH_MATCH(files) { - SLV2Node file_node = slv2_match_object(files); - slv2_array_append(plugin->data_uris, - slv2_value_new_from_node(world, file_node)); + LilvNode file_node = lilv_match_object(files); + lilv_array_append(plugin->data_uris, + lilv_value_new_from_node(world, file_node)); } - slv2_match_end(files); + lilv_match_end(files); // Add plugin to world plugin sequence - slv2_sequence_insert(world->plugins, plugin); + lilv_sequence_insert(world->plugins, plugin); } static void -slv2_world_load_dyn_manifest(SLV2World world, +lilv_world_load_dyn_manifest(LilvWorld world, SordNode* bundle_node, SerdNode manifest_uri) { -#ifdef SLV2_DYN_MANIFEST +#ifdef LILV_DYN_MANIFEST if (!world->opt.dyn_manifest) { return; } @@ -363,60 +363,60 @@ slv2_world_load_dyn_manifest(SLV2World world, LV2_Dyn_Manifest_Handle handle = NULL; // ?dman a dynman:DynManifest - SLV2Matches dmanifests = slv2_world_find_statements( + LilvMatches dmanifests = lilv_world_find_statements( world, world->model, NULL, world->rdf_a_node, world->dyn_manifest_node, bundle_node); FOREACH_MATCH(dmanifests) { - SLV2Node dmanifest = slv2_match_subject(dmanifests); + LilvNode dmanifest = lilv_match_subject(dmanifests); // ?dman lv2:binary ?binary - SLV2Matches binaries = slv2_world_find_statements( + LilvMatches binaries = lilv_world_find_statements( world, world->model, dmanifest, world->lv2_binary_node, NULL, bundle_node); - if (slv2_matches_end(binaries)) { - slv2_match_end(binaries); - SLV2_ERRORF("Dynamic manifest in <%s> has no binaries, ignored\n", + if (lilv_matches_end(binaries)) { + lilv_match_end(binaries); + LILV_ERRORF("Dynamic manifest in <%s> has no binaries, ignored\n", sord_node_get_string(bundle_node)); continue; } // Get binary path - SLV2Node binary = slv2_match_object(binaries); + LilvNode binary = lilv_match_object(binaries); const uint8_t* lib_uri = sord_node_get_string(binary); - const char* lib_path = slv2_uri_to_path((const char*)lib_uri); + const char* lib_path = lilv_uri_to_path((const char*)lib_uri); if (!lib_path) { - SLV2_ERROR("No dynamic manifest library path\n"); + LILV_ERROR("No dynamic manifest library path\n"); continue; } // Open library void* lib = dlopen(lib_path, RTLD_LAZY); if (!lib) { - SLV2_ERRORF("Failed to open dynamic manifest library `%s'\n", lib_path); + LILV_ERRORF("Failed to open dynamic manifest library `%s'\n", lib_path); continue; } // Open dynamic manifest typedef int (*OpenFunc)(LV2_Dyn_Manifest_Handle*, const LV2_Feature *const *); - OpenFunc open_func = (OpenFunc)slv2_dlfunc(lib, "lv2_dyn_manifest_open"); + OpenFunc open_func = (OpenFunc)lilv_dlfunc(lib, "lv2_dyn_manifest_open"); if (!open_func || open_func(&handle, &dman_features)) { - SLV2_ERRORF("Missing lv2_dyn_manifest_open in `%s'\n", lib_path); + LILV_ERRORF("Missing lv2_dyn_manifest_open in `%s'\n", lib_path); dlclose(lib); continue; } // Get subjects (the data that would be in manifest.ttl) typedef int (*GetSubjectsFunc)(LV2_Dyn_Manifest_Handle, FILE*); - GetSubjectsFunc get_subjects_func = (GetSubjectsFunc)slv2_dlfunc( + GetSubjectsFunc get_subjects_func = (GetSubjectsFunc)lilv_dlfunc( lib, "lv2_dyn_manifest_get_subjects"); if (!get_subjects_func) { - SLV2_ERRORF("Missing lv2_dyn_manifest_get_subjects in `%s'\n", lib_path); + LILV_ERRORF("Missing lv2_dyn_manifest_get_subjects in `%s'\n", lib_path); dlclose(lib); continue; } @@ -428,77 +428,77 @@ slv2_world_load_dyn_manifest(SLV2World world, // Parse generated data file sord_read_file_handle(world->model, fd, lib_uri, bundle_node, - slv2_world_blank_node_prefix(world)); + lilv_world_blank_node_prefix(world)); // Close (and automatically delete) temporary data file fclose(fd); // ?plugin a lv2:Plugin - SLV2Matches plug_results = slv2_world_find_statements( + LilvMatches plug_results = lilv_world_find_statements( world, world->model, NULL, world->rdf_a_node, world->lv2_plugin_node, bundle_node); FOREACH_MATCH(plug_results) { - SLV2Node plugin_node = slv2_match_subject(plug_results); - slv2_world_add_plugin(world, plugin_node, + LilvNode plugin_node = lilv_match_subject(plug_results); + lilv_world_add_plugin(world, plugin_node, &manifest_uri, binary, bundle_node); } - slv2_match_end(plug_results); + lilv_match_end(plug_results); dlclose(lib); } - slv2_match_end(dmanifests); -#endif // SLV2_DYN_MANIFEST + lilv_match_end(dmanifests); +#endif // LILV_DYN_MANIFEST } -SLV2_API +LILV_API void -slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri) +lilv_world_load_bundle(LilvWorld world, LilvValue bundle_uri) { - if (!slv2_value_is_uri(bundle_uri)) { - SLV2_ERROR("Bundle 'URI' is not a URI\n"); + if (!lilv_value_is_uri(bundle_uri)) { + LILV_ERROR("Bundle 'URI' is not a URI\n"); return; } SordNode* bundle_node = bundle_uri->val.uri_val; - SerdNode manifest_uri = slv2_new_uri_relative_to_base( + SerdNode manifest_uri = lilv_new_uri_relative_to_base( (const uint8_t*)"manifest.ttl", (const uint8_t*)sord_node_get_string(bundle_node)); sord_read_file(world->model, manifest_uri.buf, bundle_node, - slv2_world_blank_node_prefix(world)); + lilv_world_blank_node_prefix(world)); // ?plugin a lv2:Plugin - SLV2Matches plug_results = slv2_world_find_statements( + LilvMatches plug_results = lilv_world_find_statements( world, world->model, NULL, world->rdf_a_node, world->lv2_plugin_node, bundle_node); FOREACH_MATCH(plug_results) { - SLV2Node plugin_node = slv2_match_subject(plug_results); - slv2_world_add_plugin(world, plugin_node, + LilvNode plugin_node = lilv_match_subject(plug_results); + lilv_world_add_plugin(world, plugin_node, &manifest_uri, NULL, bundle_node); } - slv2_match_end(plug_results); + lilv_match_end(plug_results); - slv2_world_load_dyn_manifest(world, bundle_node, manifest_uri); + lilv_world_load_dyn_manifest(world, bundle_node, manifest_uri); // ?specification a lv2:Specification - SLV2Matches spec_results = slv2_world_find_statements( + LilvMatches spec_results = lilv_world_find_statements( world, world->model, NULL, world->rdf_a_node, world->lv2_specification_node, bundle_node); FOREACH_MATCH(spec_results) { - SLV2Node spec = slv2_match_subject(spec_results); - slv2_world_add_spec(world, spec, bundle_node); + LilvNode spec = lilv_match_subject(spec_results); + lilv_world_add_spec(world, spec, bundle_node); } - slv2_match_end(spec_results); + lilv_match_end(spec_results); serd_node_free(&manifest_uri); } @@ -513,13 +513,13 @@ expand(const char* path) wordexp(path, &p, 0); if (p.we_wordc == 0) { /* Literal directory path (e.g. no variables or ~) */ - ret = slv2_strdup(path); + ret = lilv_strdup(path); } else if (p.we_wordc == 1) { /* Directory path expands (e.g. contains ~ or $FOO) */ - ret = slv2_strdup(p.we_wordv[0]); + ret = lilv_strdup(p.we_wordv[0]); } else { /* Multiple expansions in a single directory path? */ - SLV2_ERRORF("malformed path `%s' ignored\n", path); + LILV_ERRORF("malformed path `%s' ignored\n", path); } wordfree(&p); #elif defined(__WIN32__) @@ -527,18 +527,18 @@ expand(const char* path) char* ret = malloc(len); ExpandEnvironmentStrings(path, ret, len); #else - char* ret = slv2_strdup(path); + char* ret = lilv_strdup(path); #endif return ret; } /** Load all bundles in the directory at @a dir_path. */ static void -slv2_world_load_directory(SLV2World world, const char* dir_path) +lilv_world_load_directory(LilvWorld world, const char* dir_path) { char* path = expand(dir_path); if (!path) { - SLV2_WARNF("empty path `%s'\n", path); + LILV_WARNF("empty path `%s'\n", path); return; } @@ -560,7 +560,7 @@ slv2_world_load_directory(SLV2World world, const char* dir_path) if (!strcmp(pfile->d_name, ".") || !strcmp(pfile->d_name, "..")) continue; - char* uri = slv2_strjoin(file_scheme, + char* uri = lilv_strjoin(file_scheme, path, "/", pfile->d_name, "/", NULL); @@ -568,11 +568,11 @@ slv2_world_load_directory(SLV2World world, const char* dir_path) DIR* const bundle_dir = opendir(uri + file_scheme_len); if (bundle_dir) { closedir(bundle_dir); - SLV2Value uri_val = slv2_value_new_uri(world, uri); - slv2_world_load_bundle(world, uri_val); - slv2_value_free(uri_val); + LilvValue uri_val = lilv_value_new_uri(world, uri); + lilv_world_load_bundle(world, uri_val); + lilv_value_free(uri_val); } else { - SLV2_WARNF("failed to open bundle `%s'\n", uri); + LILV_WARNF("failed to open bundle `%s'\n", uri); } free(uri); @@ -585,7 +585,7 @@ slv2_world_load_directory(SLV2World world, const char* dir_path) static bool is_path_sep(char c) { - return c == SLV2_PATH_SEP[0]; + return c == LILV_PATH_SEP[0]; } static const char* @@ -605,7 +605,7 @@ first_path_sep(const char* path) * parent directories of bundles, not a list of bundle directories). */ static void -slv2_world_load_path(SLV2World world, +lilv_world_load_path(LilvWorld world, const char* lv2_path) { while (lv2_path[0] != '\0') { @@ -615,64 +615,64 @@ slv2_world_load_path(SLV2World world, char* const dir = malloc(dir_len + 1); memcpy(dir, lv2_path, dir_len); dir[dir_len] = '\0'; - slv2_world_load_directory(world, dir); + lilv_world_load_directory(world, dir); free(dir); lv2_path += dir_len + 1; } else { - slv2_world_load_directory(world, lv2_path); + lilv_world_load_directory(world, lv2_path); lv2_path = "\0"; } } } static void -slv2_world_load_specifications(SLV2World world) +lilv_world_load_specifications(LilvWorld world) { for (GSList* l = world->specs; l; l = l->next) { - SLV2Spec spec = (SLV2Spec)l->data; - SLV2_FOREACH(values, f, spec->data_uris) { - SLV2Value file = slv2_collection_get(spec->data_uris, f); + LilvSpec spec = (LilvSpec)l->data; + LILV_FOREACH(values, f, spec->data_uris) { + LilvValue file = lilv_collection_get(spec->data_uris, f); sord_read_file(world->model, - (const uint8_t*)slv2_value_as_uri(file), + (const uint8_t*)lilv_value_as_uri(file), NULL, - slv2_world_blank_node_prefix(world)); + lilv_world_blank_node_prefix(world)); } } } static void -slv2_world_load_plugin_classes(SLV2World world) +lilv_world_load_plugin_classes(LilvWorld world) { /* FIXME: This loads all classes, not just lv2:Plugin subclasses. - However, if the host gets all the classes via slv2_plugin_class_get_children + However, if the host gets all the classes via lilv_plugin_class_get_children starting with lv2:Plugin as the root (which is e.g. how a host would build a menu), they won't be seen anyway... */ - SLV2Matches classes = slv2_world_find_statements( + LilvMatches classes = lilv_world_find_statements( world, world->model, NULL, world->rdf_a_node, world->rdfs_class_node, NULL); FOREACH_MATCH(classes) { - SLV2Node class_node = slv2_match_subject(classes); + LilvNode class_node = lilv_match_subject(classes); // Get parents (superclasses) - SLV2Matches parents = slv2_world_find_statements( + LilvMatches parents = lilv_world_find_statements( world, world->model, class_node, world->rdfs_subclassof_node, NULL, NULL); - if (slv2_matches_end(parents)) { - slv2_match_end(parents); + if (lilv_matches_end(parents)) { + lilv_match_end(parents); continue; } - SLV2Node parent_node = slv2_match_object(parents); - slv2_match_end(parents); + LilvNode parent_node = lilv_match_object(parents); + lilv_match_end(parents); if (!sord_node_get_type(parent_node) == SORD_URI) { // Class parent is not a resource, ignore (e.g. owl restriction) @@ -680,54 +680,54 @@ slv2_world_load_plugin_classes(SLV2World world) } // Get labels - SLV2Matches labels = slv2_world_find_statements( + LilvMatches labels = lilv_world_find_statements( world, world->model, class_node, world->rdfs_label_node, NULL, NULL); - if (slv2_matches_end(labels)) { - slv2_match_end(labels); + if (lilv_matches_end(labels)) { + lilv_match_end(labels); continue; } - SLV2Node label_node = slv2_match_object(labels); + LilvNode label_node = lilv_match_object(labels); const uint8_t* label = (const uint8_t*)sord_node_get_string(label_node); - slv2_match_end(labels); + lilv_match_end(labels); - SLV2PluginClasses classes = world->plugin_classes; - SLV2PluginClass pclass = slv2_plugin_class_new( + LilvPluginClasses classes = world->plugin_classes; + LilvPluginClass pclass = lilv_plugin_class_new( world, parent_node, class_node, (const char*)label); if (pclass) { - slv2_sequence_insert(classes, pclass); + lilv_sequence_insert(classes, pclass); } } - slv2_match_end(classes); + lilv_match_end(classes); } -SLV2_API +LILV_API void -slv2_world_load_all(SLV2World world) +lilv_world_load_all(LilvWorld world) { const char* lv2_path = getenv("LV2_PATH"); if (!lv2_path) - lv2_path = SLV2_DEFAULT_LV2_PATH; + lv2_path = LILV_DEFAULT_LV2_PATH; // Discover bundles and read all manifest files into model - slv2_world_load_path(world, lv2_path); + lilv_world_load_path(world, lv2_path); - SLV2_FOREACH(plugins, p, world->plugins) { - SLV2Plugin plugin = slv2_collection_get(world->plugins, p); - SLV2Value plugin_uri = slv2_plugin_get_uri(plugin); + LILV_FOREACH(plugins, p, world->plugins) { + LilvPlugin plugin = lilv_collection_get(world->plugins, p); + LilvValue plugin_uri = lilv_plugin_get_uri(plugin); // ?new dc:replaces plugin - SLV2Matches replacement = slv2_world_find_statements( + LilvMatches replacement = lilv_world_find_statements( world, world->model, NULL, world->dc_replaces_node, - slv2_value_as_node(plugin_uri), + lilv_value_as_node(plugin_uri), NULL); if (!sord_iter_end(replacement)) { /* TODO: Check if replacement is actually a known plugin, @@ -735,42 +735,42 @@ slv2_world_load_all(SLV2World world) */ plugin->replaced = true; } - slv2_match_end(replacement); + lilv_match_end(replacement); } // Query out things to cache - slv2_world_load_specifications(world); - slv2_world_load_plugin_classes(world); + lilv_world_load_specifications(world); + lilv_world_load_plugin_classes(world); } -SLV2_API -SLV2PluginClass -slv2_world_get_plugin_class(SLV2World world) +LILV_API +LilvPluginClass +lilv_world_get_plugin_class(LilvWorld world) { return world->lv2_plugin_class; } -SLV2_API -SLV2PluginClasses -slv2_world_get_plugin_classes(SLV2World world) +LILV_API +LilvPluginClasses +lilv_world_get_plugin_classes(LilvWorld world) { return world->plugin_classes; } -SLV2_API -SLV2Plugins -slv2_world_get_all_plugins(SLV2World world) +LILV_API +LilvPlugins +lilv_world_get_all_plugins(LilvWorld world) { return world->plugins; } -SLV2_API -SLV2Plugin -slv2_world_get_plugin_by_uri_string(SLV2World world, +LILV_API +LilvPlugin +lilv_world_get_plugin_by_uri_string(LilvWorld world, const char* uri) { - SLV2Value uri_val = slv2_value_new_uri(world, uri); - SLV2Plugin plugin = slv2_plugins_get_by_uri(world->plugins, uri_val); - slv2_value_free(uri_val); + LilvValue uri_val = lilv_value_new_uri(world, uri); + LilvPlugin plugin = lilv_plugins_get_by_uri(world->plugins, uri_val); + lilv_value_free(uri_val); return plugin; } |