From 809f5ae5999901be62f9d0cc1eb8a2d0f4806780 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 28 Apr 2011 21:56:29 +0000 Subject: Rename slv2 to lilv. API breakage was proving too much of a hassle, and would be even further of a mess after release and packaging. Best to make a clean break now, and fix installation to support parallel installs and prevent this kind of problem in the future. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3217 a436a847-0d15-0410-975c-d299462d15a1 --- ChangeLog | 136 +---- README | 6 +- doc/reference.doxygen.in | 12 +- lilv.pc.in | 10 + lilv.ttl | 29 + lilv/lilv.h | 1364 ++++++++++++++++++++++++++++++++++++++++++ lilv/lilvmm.hpp | 264 +++++++++ slv2.pc.in | 10 - slv2.ttl | 29 - slv2/slv2.h | 1401 -------------------------------------------- slv2/slv2mm.hpp | 264 --------- src/collections.c | 182 +++--- src/lilv_internal.h | 407 +++++++++++++ src/plugin.c | 576 +++++++++--------- src/pluginclass.c | 62 +- src/plugininstance.c | 46 +- src/pluginui.c | 88 ++- src/port.c | 252 ++++---- src/query.c | 100 ++-- src/scalepoint.c | 26 +- src/slv2_internal.h | 428 -------------- src/util.c | 16 +- src/value.c | 280 ++++----- src/world.c | 504 ++++++++-------- swig/lilv.i | 48 ++ swig/slv2.i | 48 -- test/lilv_test.c | 970 ++++++++++++++++++++++++++++++ test/slv2_test.c | 976 ------------------------------ utils/lilv.bash_completion | 59 ++ utils/lilv_bench.c | 55 ++ utils/lv2_inspect.c | 250 ++++---- utils/lv2_jack_host.c | 150 ++--- utils/lv2_list.c | 28 +- utils/slv2.bash_completion | 59 -- utils/slv2_bench.c | 55 -- waf | Bin 87718 -> 87343 bytes wscript | 159 +++-- 37 files changed, 4554 insertions(+), 4795 deletions(-) create mode 100644 lilv.pc.in create mode 100644 lilv.ttl create mode 100644 lilv/lilv.h create mode 100644 lilv/lilvmm.hpp delete mode 100644 slv2.pc.in delete mode 100644 slv2.ttl delete mode 100644 slv2/slv2.h delete mode 100644 slv2/slv2mm.hpp create mode 100644 src/lilv_internal.h delete mode 100644 src/slv2_internal.h create mode 100644 swig/lilv.i delete mode 100644 swig/slv2.i create mode 100644 test/lilv_test.c delete mode 100644 test/slv2_test.c create mode 100644 utils/lilv.bash_completion create mode 100644 utils/lilv_bench.c delete mode 100644 utils/slv2.bash_completion delete mode 100644 utils/slv2_bench.c diff --git a/ChangeLog b/ChangeLog index 385cd46..e1e3f1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,136 +1,4 @@ -slv2 (UNRELEASED) unstable; urgency=low - * Parse all files with their own URI as a base URI (allowing proper - reference to other things in the same bundle) - * Support relative URIs returned from lv2_descriptor in libraries - * Remove nonsensical slv2_plugin_get_properties and slv2_plugin_get_hints - * Remove all use of SPARQL (including API that provided SPARQL support) - * Remove use of redland (librdf) in favour of Serd and Sord - * Remove slv2_world_new_using_rdf_world and slv2_plugin_query_sparql - * Remove separate i18n versions of functions and implement i18n everywhere - * Add slv2_world_set_option for runtime configuration of SLV2 features. - * Add SLV2_OPTION_FILTER_LANG option (to optionally disable i18n). - * Document entire API in single header file / page. - * Add new collections and iterator API (and deprecate index based API) - * Remove the questionable slv2_world_get_plugins_by_filter. - * Add slv2_plugin_is_replaced to allow hosts to hide old plugins. - * Switch to 2-clause BSD license. - * *** API BREAK *** +lilv (UNRELEASED) unstable; urgency=low + * Initial version (forked from SLV2) -- David Robillard (UNRELEASED) - -slv2 (0.6.6) unstable; urgency=low - - * Add manual pages for utilities - * Reduce plugin load overhead (on-demand querying with finer granularity) - * Fix compilation on Mac OS X - - -- David Robillard Mon, 25 May 2009 23:30:49 -0400 - -slv2 (0.6.4) unstable; urgency=low - - * Add generic query interface to allow arbitrary querying of data - * Combine similar headers (reduce code duplication) - * Upgrade to waf 1.5.6 - * Add man pages for utilities - - -- David Robillard Mon, 04 May 2009 18:11:06 -0400 - -slv2 (0.6.3) unstable; urgency=low - - * Fix illegal output of slv2_value_get_turtle_token for floats. - * Fix slv2_plugin_get_value_for_subject - * Add test suite and coverage instrumentation - * Upgrade to waf 1.5.1 - - -- David Robillard Sat, 13 Dec 2008 14:13:43 -0500 - -slv2 (0.6.2) unstable; urgency=high - - * Fix bug introduced with I18N in 0.6.1 which broke feature detection. - * Add waf configure --no-jack option to avoid building Jack clients. - - -- David Robillard Sun, 30 Nov 2008 19:40:27 -0500 - -slv2 (0.6.1) unstable; urgency=low - - * I18N support. - * Add slv2_port_get_value (analogous to slv2_plugin_get_value). - * Add slv2_instance_get_extension_data. - * Fix slv2_plugin_get_supported_features (previously non-functional). - - -- David Robillard Sat, 08 Nov 2008 14:27:10 -0500 - -slv2 (0.6.0) unstable; urgency=low - - * Rework API to reduce dependence of SLV2 on specific LV2 features - * Use SLV2Value most everywhere in the API for type safety and - performance reasons - * Typical use case performance improvements - * Add support for scale points - * Use new Redland "trees" store for dramatic performance improvements - * *** API BREAK *** - - -- David Robillard Sun, 06 Jul 2008 13:11:15 -0400 - -slv2 (0.5.0) unstable; urgency=low - - * Update LV2 UI header (API break) - * *** API BREAK *** - - -- David Robillard Thu, 17 Jan 2008 18:34:29 -0500 - -slv2 (0.4.5) unstable; urgency=low - - * Fix redland librdf_free_query_results warning - * Use "memory" store instead of "hashes" store for plugin RDF data, - resulting in extreme speedups in some cases. - - -- David Robillard Tue, 15 Jan 2008 19:22:21 -0500 - -slv2 (0.4.4) unstable; urgency=low - - * Add slv2_port_has_property - * Add slv2_plugin_has_feature - * Add plugin template and port signature interface for much faster plugin - discovery with port input/output/type inspection. - - -- David Robillard Tue, 15 Jan 2008 10:43:00 -0500 - -slv2 (0.4.3) unstable; urgency=low - - * Fix lv2_inspect command line handling bug (always prints help) - * Fix case where multiple plugins are described in the same file - (avoid port symbol clashing). - - -- David Robillard Thu, 10 Jan 2008 20:03:19 -0500 - -slv2 (0.4.2) unstable; urgency=low - - * Update for LV2 specification release 1 - - -- David Robillard Tue, 08 Jan 2008 20:16:56 -0500 - -slv2 (0.4.1) unstable; urgency=low - - * Debian packaging (no functional changes) - - -- David Robillard Sun, 6 Jan 2008 18:39:57 -0500 - -slv2 (0.4.0) unstable; urgency=low - - * Update for most recent LV2 GUI specification - * Fix plugin detection bugs - - -- David Robillard Sun, 6 Jan 2008 17:11:18 -0500 - -slv2 (0.3.2) unstable; urgency=low - - * Build man pages - - -- David Robillard Wed, 30 Nov 2007 18:19:00 -0500 - -slv2 (0.3.1) unstable; urgency=low - - * Initial Debian Release. - - -- David Robillard Wed, 14 Nov 2007 22:29:49 -0500 diff --git a/README b/README index 68b76b5..00e1530 100644 --- a/README +++ b/README @@ -1,11 +1,11 @@ -SLV2 +Lilv ---- -SLV2 is a library for LV2 hosts intended to make using LV2 Plugins as simple +Lilv is a library for LV2 hosts intended to make using LV2 Plugins as simple as possible (without sacrificing capabilities). More information about LV2 plugins can be found at . -More information about SLV2 can be found at . +More information about Lilv can be found at . -- David Robillard diff --git a/doc/reference.doxygen.in b/doc/reference.doxygen.in index 7d92ff0..97cb0e7 100644 --- a/doc/reference.doxygen.in +++ b/doc/reference.doxygen.in @@ -25,20 +25,20 @@ DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = SLV2 +PROJECT_NAME = Lilv # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = @SLV2_VERSION@ +PROJECT_NUMBER = @LILV_VERSION@ # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. -OUTPUT_DIRECTORY = @SLV2_DOC_DIR@ +OUTPUT_DIRECTORY = @LILV_DOC_DIR@ # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output @@ -506,7 +506,7 @@ FILE_VERSION_FILTER = # file name after the option, if omitted DoxygenLayout.xml will be used as the name # of the layout file. -LAYOUT_FILE = @SLV2_SRCDIR@/doc/layout.xml +LAYOUT_FILE = @LILV_SRCDIR@/doc/layout.xml #--------------------------------------------------------------------------- # configuration options related to warning and progress messages @@ -568,7 +568,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = @SLV2_SRCDIR@/slv2/slv2.h +INPUT = @LILV_SRCDIR@/lilv/lilv.h # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is @@ -794,7 +794,7 @@ HTML_FOOTER = # the style sheet file to the HTML output directory, so don't put your own # stylesheet in the HTML output directory as well, or it will be erased! -HTML_STYLESHEET = @SLV2_SRCDIR@/doc/style.css +HTML_STYLESHEET = @LILV_SRCDIR@/doc/style.css # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, # files or namespaces will be aligned in HTML using tables. If set to diff --git a/lilv.pc.in b/lilv.pc.in new file mode 100644 index 0000000..4f40b57 --- /dev/null +++ b/lilv.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Lilv +Version: @LILV_VERSION@ +Description: Simple C library for hosting LV2 plugins +Libs: @GLIB_LIBS@ @SORD_LIBS@ -L${libdir} -llilv-@LILV_MAJOR_VERSION@ -ldl +Cflags: @GLIB_CFLAGS@ @SORD_CFLAGS@ -I${includedir}/lilv-@LILV_MAJOR_VERSION@ diff --git a/lilv.ttl b/lilv.ttl new file mode 100644 index 0000000..edfb0e5 --- /dev/null +++ b/lilv.ttl @@ -0,0 +1,29 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix : . +@prefix foaf: . + + + a :Project ; + :bug-database ; + :developer [ + a foaf:Person ; + rdfs:seeAlso ; + foaf:homepage ; + foaf:mbox_sha1sum "253b3c58086250260bac1232d744d150274ad308" ; + foaf:name "David Robillard" + ] ; + :download-page ; + :homepage ; + :license ; + :name "LILV" ; + :programming-language "C", "Turtle" ; + :repository [ + :browse ; + :location ; + a :SVNRepository + ] ; + :shortdesc "Library for simple use of LV2 plugins" ; + :shortname "LILV" . + + diff --git a/lilv/lilv.h b/lilv/lilv.h new file mode 100644 index 0000000..161c01b --- /dev/null +++ b/lilv/lilv.h @@ -0,0 +1,1364 @@ +/* + Copyright 2007-2011 David Robillard + + 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. +*/ + +/** + @file lilv.h API for Lilv, a lightweight LV2 host library. +*/ + +#ifndef LILV_LILV_H +#define LILV_LILV_H + +#include +#include +#include + +#include "lv2/lv2plug.in/ns/lv2core/lv2.h" + +#ifdef LILV_SHARED +# ifdef __WIN32__ +# define LILV_LIB_IMPORT __declspec(dllimport) +# define LILV_LIB_EXPORT __declspec(dllexport) +# else +# define LILV_LIB_IMPORT __attribute__((visibility("default"))) +# define LILV_LIB_EXPORT __attribute__((visibility("default"))) +# endif +# ifdef LILV_INTERNAL +# define LILV_API LILV_LIB_EXPORT +# else +# define LILV_API LILV_LIB_IMPORT +# endif +#else +# define LILV_API +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define LILV_NAMESPACE_LV2 "http://lv2plug.in/ns/lv2core#" +#define LILV_PORT_CLASS_PORT "http://lv2plug.in/ns/lv2core#Port" +#define LILV_PORT_CLASS_INPUT "http://lv2plug.in/ns/lv2core#InputPort" +#define LILV_PORT_CLASS_OUTPUT "http://lv2plug.in/ns/lv2core#OutputPort" +#define LILV_PORT_CLASS_CONTROL "http://lv2plug.in/ns/lv2core#ControlPort" +#define LILV_PORT_CLASS_AUDIO "http://lv2plug.in/ns/lv2core#AudioPort" +#define LILV_PORT_CLASS_EVENT "http://lv2plug.in/ns/ext/event#EventPort" +#define LILV_EVENT_CLASS_MIDI "http://lv2plug.in/ns/ext/midi#MidiEvent" + +typedef struct _LilvPlugin* LilvPlugin; /**< LV2 Plugin. */ +typedef struct _LilvPluginClass* LilvPluginClass; /**< Plugin Class. */ +typedef struct _LilvPort* LilvPort; /**< Port. */ +typedef struct _LilvScalePoint* LilvScalePoint; /**< Scale Point (Notch). */ +typedef struct _LilvUI* LilvUI; /**< Plugin UI. */ +typedef struct _LilvValue* LilvValue; /**< Typed Value. */ +typedef struct _LilvWorld* LilvWorld; /**< Lilv World. */ +typedef struct _LilvUIInstance* LilvUIInstance; /**< Plugin UI Instance. */ + +typedef void* LilvPluginClasses; /**< set. */ +typedef void* LilvPlugins; /**< set. */ +typedef void* LilvScalePoints; /**< set. */ +typedef void* LilvUIs; /**< set. */ +typedef void* LilvValues; /**< set. */ + +/** + @defgroup lilv Lilv + Lilv is a simple yet powerful C API for using LV2 plugins. + + For more information about LV2, see . + For more information about Lilv, see . + @{ +*/ + +/** + @name Value + @{ +*/ + +/** + Convert a file URI string to a local path string. + For example, "file://foo/bar/baz.ttl" returns "/foo/bar/baz.ttl". + Return value is shared and must not be deleted by caller. + @return @a uri converted to a path, or NULL on failure (URI is not local). +*/ +LILV_API +const char* +lilv_uri_to_path(const char* uri); + +/** + Create a new URI value. + Returned value must be freed by caller with lilv_value_free. +*/ +LILV_API +LilvValue +lilv_value_new_uri(LilvWorld world, const char* uri); + +/** + Create a new string value (with no language). + Returned value must be freed by caller with lilv_value_free. +*/ +LILV_API +LilvValue +lilv_value_new_string(LilvWorld world, const char* str); + +/** + Create a new integer value. + Returned value must be freed by caller with lilv_value_free. +*/ +LILV_API +LilvValue +lilv_value_new_int(LilvWorld world, int val); + +/** + Create a new floating point value. + Returned value must be freed by caller with lilv_value_free. +*/ +LILV_API +LilvValue +lilv_value_new_float(LilvWorld world, float val); + +/** + Create a new boolean value. + Returned value must be freed by caller with lilv_value_free. +*/ +LILV_API +LilvValue +lilv_value_new_bool(LilvWorld world, bool val); + +/** + Free an LilvValue. +*/ +LILV_API +void +lilv_value_free(LilvValue val); + +/** + Duplicate an LilvValue. +*/ +LILV_API +LilvValue +lilv_value_duplicate(LilvValue val); + +/** + Return whether two values are equivalent. +*/ +LILV_API +bool +lilv_value_equals(LilvValue value, LilvValue other); + +/** + Return this value as a Turtle/SPARQL token. + Returned value must be freed by caller with lilv_value_free. + + + + + + + + +
Example Turtle Tokens
URI<http://example.org/foo >
QNamedoap:name
String"this is a string"
Float1.0
Integer1
Booleantrue
+*/ +LILV_API +char* +lilv_value_get_turtle_token(LilvValue value); + +/** + Return whether the value is a URI (resource). +*/ +LILV_API +bool +lilv_value_is_uri(LilvValue value); + +/** + Return this value as a URI string, e.g. "http://example.org/foo". + Valid to call only if lilv_value_is_uri(@a value) returns true. + Returned value is owned by @a value and must not be freed by caller. +*/ +LILV_API +const char* +lilv_value_as_uri(LilvValue value); + +/** + Return whether the value is a blank node (resource with no URI). +*/ +LILV_API +bool +lilv_value_is_blank(LilvValue value); + +/** + Return this value as a blank node identifier, e.g. "genid03". + Valid to call only if lilv_value_is_blank(@a value) returns true. + Returned value is owned by @a value and must not be freed by caller. +*/ +LILV_API +const char* +lilv_value_as_blank(LilvValue value); + +/** + Return whether this value is a literal (i.e. not a URI). + Returns true if @a value is a string or numeric value. +*/ +LILV_API +bool +lilv_value_is_literal(LilvValue value); + +/** + Return whether this value is a string literal. + Returns true if @a value is a string value (and not numeric). +*/ +LILV_API +bool +lilv_value_is_string(LilvValue value); + +/** + Return @a value as a string. +*/ +LILV_API +const char* +lilv_value_as_string(LilvValue value); + +/** + Return whether this value is a decimal literal. +*/ +LILV_API +bool +lilv_value_is_float(LilvValue value); + +/** + Return @a value as a float. + Valid to call only if lilv_value_is_float(@a value) or + lilv_value_is_int(@a value) returns true. +*/ +LILV_API +float +lilv_value_as_float(LilvValue value); + +/** + Return whether this value is an integer literal. +*/ +LILV_API +bool +lilv_value_is_int(LilvValue value); + +/** + Return @a value as an integer. + Valid to call only if lilv_value_is_int(@a value) returns true. +*/ +LILV_API +int +lilv_value_as_int(LilvValue value); + +/** + Return whether this value is a boolean. +*/ +LILV_API +bool +lilv_value_is_bool(LilvValue value); + +/** + Return @a value as a bool. + Valid to call only if lilv_value_is_bool(@a value) returns true. +*/ +LILV_API +bool +lilv_value_as_bool(LilvValue value); + +/** + @} + @name Collections + Lilv has several collection types for holding various types of value: +
    +
  • LilvPlugins (function prefix "lilv_plugins_")
  • +
  • LilvPluginClasses (function prefix "lilv_plugin_classes_")
  • +
  • LilvScalePoints (function prefix "lilv_scale_points_")
  • +
  • LilvValues (function prefix "lilv_values_")
  • +
  • LilvUIs (function prefix "lilv_uis_")
  • +
+ + Each collection type supports a similar basic API: +
    +
  • void PREFIX_free (coll)
  • +
  • unsigned PREFIX_size (coll)
  • +
  • LilvIter PREFIX_begin (coll)
  • +
+ @{ +*/ + +/* Collections */ + +typedef void* LilvIter; + +/** + Iterate over each element of a collection. + @code + LILV_FOREACH(plugin_classes, i, classes) { + LilvPluginClass c = lilv_plugin_classes_get(classes, i); + // ... + } + @endcode +*/ +#define LILV_FOREACH(colltype, iter, collection) \ + for (LilvIter (iter) = lilv_ ## colltype ## _begin(collection); \ + !lilv_ ## colltype ## _is_end(collection, iter); \ + (iter) = lilv_ ## colltype ## _next(collection, iter)) + +/* LilvPluginClasses */ + +LILV_API +void +lilv_plugin_classes_free(LilvPluginClasses collection); + +LILV_API +unsigned +lilv_plugin_classes_size(LilvPluginClasses collection); + +LILV_API +LilvIter +lilv_plugin_classes_begin(LilvPluginClasses collection); + +LILV_API +LilvPluginClass +lilv_plugin_classes_get(LilvPluginClasses collection, LilvIter i); + +LILV_API +LilvIter +lilv_plugin_classes_next(LilvPluginClasses collection, LilvIter i); + +LILV_API +bool +lilv_plugin_classes_is_end(LilvPluginClasses collection, LilvIter i); + +/** + Get a plugin class from @a classes by URI. + Return value is shared (stored in @a classes) and must not be freed or + modified by the caller in any way. + @return NULL if no plugin class with @a uri is found in @a classes. +*/ +LILV_API +LilvPluginClass +lilv_plugin_classes_get_by_uri(LilvPluginClasses classes, + LilvValue uri); + +/* ScalePoints */ + +LILV_API +void +lilv_scale_points_free(LilvScalePoints collection); + +LILV_API +unsigned +lilv_scale_points_size(LilvScalePoints collection); + +LILV_API +LilvIter +lilv_scale_points_begin(LilvScalePoints collection); + +LILV_API +LilvScalePoint +lilv_scale_points_get(LilvScalePoints collection, LilvIter i); + +LILV_API +LilvIter +lilv_scale_points_next(LilvScalePoints collection, LilvIter i); + +LILV_API +bool +lilv_scale_points_is_end(LilvScalePoints collection, LilvIter i); + +/* UIs */ + +LILV_API +void +lilv_uis_free(LilvUIs collection); + +LILV_API +unsigned +lilv_uis_size(LilvUIs collection); + +LILV_API +LilvIter +lilv_uis_begin(LilvUIs collection); + +LILV_API +LilvUI +lilv_uis_get(LilvUIs collection, LilvIter i); + +LILV_API +LilvIter +lilv_uis_next(LilvUIs collection, LilvIter i); + +LILV_API +bool +lilv_uis_is_end(LilvUIs collection, LilvIter i); + +/** + Get a UI from @a uis by URI. + Return value is shared (stored in @a uis) and must not be freed or + modified by the caller in any way. + @return NULL if no UI with @a uri is found in @a list. +*/ +LILV_API +LilvUI +lilv_uis_get_by_uri(LilvUIs uis, + LilvValue uri); + +/* Values */ + +LILV_API +void +lilv_values_free(LilvValues collection); + +LILV_API +unsigned +lilv_values_size(LilvValues collection); + +LILV_API +LilvIter +lilv_values_begin(LilvValues collection); + +LILV_API +LilvValue +lilv_values_get(LilvValues collection, LilvIter i); + +LILV_API +LilvIter +lilv_values_next(LilvValues collection, LilvIter i); + +LILV_API +bool +lilv_values_is_end(LilvValues collection, LilvIter i); + +LILV_API +LilvValue +lilv_values_get_first(LilvValues collection); + +/** + Return whether @a values contains @a value. +*/ +LILV_API +bool +lilv_values_contains(LilvValues values, LilvValue value); + +/* Plugins */ + +LILV_API +unsigned +lilv_plugins_size(LilvPlugins collection); + +LILV_API +LilvIter +lilv_plugins_begin(LilvPlugins collection); + +LILV_API +LilvPlugin +lilv_plugins_get(LilvPlugins collection, LilvIter i); + +LILV_API +LilvIter +lilv_plugins_next(LilvPlugins collection, LilvIter i); + +LILV_API +bool +lilv_plugins_is_end(LilvPlugins collection, LilvIter i); + +LILV_API +void +lilv_plugins_free(LilvWorld world, LilvPlugins plugins); + +/** + Get a plugin from @a plugins by URI. + Return value is shared (stored in @a plugins) and must not be freed or + modified by the caller in any way. + @return NULL if no plugin with @a uri is found in @a plugins. +*/ +LILV_API +LilvPlugin +lilv_plugins_get_by_uri(LilvPlugins plugins, + LilvValue uri); + +/** + @} + @name World + The "world" represents all Lilv state, and is used to discover/load/cache + LV2 data (plugins, UIs, and extensions). + Normal hosts which just need to load plugins by URI should simply use + @ref lilv_world_load_all to discover/load the system's LV2 resources. + @{ +*/ + +/** + Initialize a new, empty world. + If initialization fails, NULL is returned. +*/ +LILV_API +LilvWorld +lilv_world_new(void); + +/** + Enable/disable language filtering. + Language filtering applies to any functions that return (a) value(s). + With filtering enabled, Lilv will automatically return the best value(s) + for the current LANG. With filtering disabled, all matching values will + be returned regardless of language tag. Filtering is enabled by default. +*/ +#define LILV_OPTION_FILTER_LANG "http://drobilla.net/ns/lilv#filter-lang" + +/** + Enable/disable dynamic manifest support. + Dynamic manifest data will only be loaded if this option is true. +*/ +#define LILV_OPTION_DYN_MANIFEST "http://drobilla.net/ns/lilv#dyn-manifest" + +/** + Set an option option for @a world. + + Currently recognized options: + @ref LILV_OPTION_FILTER_LANG + @ref LILV_OPTION_DYN_MANIFEST +*/ +LILV_API +void +lilv_world_set_option(LilvWorld world, + const char* uri, + const LilvValue value); + +/** + Destroy the world, mwahaha. + Note that destroying @a world will destroy all the objects it contains + (e.g. instances of LilvPlugin). Do not destroy the world until you are + finished with all objects that came from it. +*/ +LILV_API +void +lilv_world_free(LilvWorld world); + +/** + Load all installed LV2 bundles on the system. + This is the recommended way for hosts to load LV2 data. It implements the + established/standard best practice for discovering all LV2 data on the + system. The environment variable LV2_PATH may be used to control where + this function will look for bundles. + + Hosts should use this function rather than explicitly load bundles, except + in special circumstances (e.g. development utilities, or hosts that ship + with special plugin bundles which are installed to a known location). +*/ +LILV_API +void +lilv_world_load_all(LilvWorld world); + +/** + Load a specific bundle. + @a bundle_uri must be a fully qualified URI to the bundle directory, + with the trailing slash, eg. file:///usr/lib/lv2/foo.lv2/ + + Normal hosts should not need this function (use lilv_world_load_all). + + Hosts MUST NOT attach any long-term significance to bundle paths + (e.g. in save files), since there are no guarantees they will remain + unchanged between (or even during) program invocations. Plugins (among + other things) MUST be identified by URIs (not paths) in save files. +*/ +LILV_API +void +lilv_world_load_bundle(LilvWorld world, + LilvValue bundle_uri); + +/** + Get the parent of all other plugin classes, lv2:Plugin. +*/ +LILV_API +LilvPluginClass +lilv_world_get_plugin_class(LilvWorld world); + +/** + Return a list of all found plugin classes. + Returned list is owned by world and must not be freed by the caller. +*/ +LILV_API +LilvPluginClasses +lilv_world_get_plugin_classes(LilvWorld world); + +/** + Return a list of all found plugins. + The returned list contains just enough references to query + or instantiate plugins. The data for a particular plugin will not be + loaded into memory until a call to an lilv_plugin_* function results in + a query (at which time the data is cached with the LilvPlugin so future + queries are very fast). + + The returned list and the plugins it contains are owned by @a world + and must not be freed by caller. +*/ +LILV_API +LilvPlugins +lilv_world_get_all_plugins(LilvWorld world); + +/** + Return the plugin with the given @a uri, or NULL if not found. +*/ +LILV_API +LilvPlugin +lilv_world_get_plugin_by_uri_string(LilvWorld world, + const char* uri); + +/** + @} + @name Plugin + @{ +*/ + +/** + Check if @a plugin is valid. + This is not a rigorous validator, but can be used to reject some malformed + plugins that could cause bugs (e.g. plugins with missing required fields). + + Note that normal hosts do NOT need to use this - lilv does not + load invalid plugins into plugin lists. This is included for plugin + testing utilities, etc. + @return true iff @a plugin is valid. +*/ +LILV_API +bool +lilv_plugin_verify(LilvPlugin plugin); + +/** + Get the URI of @a plugin. + Any serialization that refers to plugins should refer to them by this. + Hosts SHOULD NOT save any filesystem paths, plugin indexes, etc. in saved + files; save only the URI. + + The URI is a globally unique identifier for one specific plugin. Two + plugins with the same URI are compatible in port signature, and should + be guaranteed to work in a compatible and consistent way. If a plugin + is upgraded in an incompatible way (eg if it has different ports), it + MUST have a different URI than it's predecessor. + + @return A shared URI value which must not be modified or freed. +*/ +LILV_API +LilvValue +lilv_plugin_get_uri(LilvPlugin plugin); + +/** + Get the (resolvable) URI of the plugin's "main" bundle. + This returns the URI of the bundle where the plugin itself was found. + Note that the data for a plugin may be spread over many bundles, that is, + lilv_plugin_get_data_uris may return URIs which are not within this bundle. + + Typical hosts should not need to use this function. + Note this always returns a fully qualified URI. If you want a local + filesystem path, use lilv_uri_to_path. + @return a shared string which must not be modified or freed. +*/ +LILV_API +LilvValue +lilv_plugin_get_bundle_uri(LilvPlugin plugin); + +/** + Get the (resolvable) URIs of the RDF data files that define a plugin. + Typical hosts should not need to use this function. + Note this always returns fully qualified URIs. If you want local + filesystem paths, use lilv_uri_to_path. + @return a list of complete URLs eg. "file:///foo/ABundle.lv2/aplug.ttl", + which is shared and must not be modified or freed. +*/ +LILV_API +LilvValues +lilv_plugin_get_data_uris(LilvPlugin plugin); + +/** + Get the (resolvable) URI of the shared library for @a plugin. + Note this always returns a fully qualified URI. If you want a local + filesystem path, use lilv_uri_to_path. + @return a shared string which must not be modified or freed. +*/ +LILV_API +LilvValue +lilv_plugin_get_library_uri(LilvPlugin plugin); + +/** + Get the name of @a plugin. + This returns the name (doap:name) of the plugin. The name may be + translated according to the current locale, this value MUST NOT be used + as a plugin identifier (use the URI for that). + Returned value must be freed by the caller. +*/ +LILV_API +LilvValue +lilv_plugin_get_name(LilvPlugin plugin); + +/** + Get the class this plugin belongs to (ie Filters). +*/ +LILV_API +LilvPluginClass +lilv_plugin_get_class(LilvPlugin plugin); + +/** + Get a value associated with the plugin in a plugin's data files. + @a predicate must be either a URI or a QName. + + Returns the ?object of all triples found of the form: + + <plugin-uri> predicate ?object + + May return NULL if the property was not found, or if object(s) is not + sensibly represented as an LilvValues (e.g. blank nodes). + Return value must be freed by caller with lilv_values_free. +*/ +LILV_API +LilvValues +lilv_plugin_get_value(LilvPlugin p, + LilvValue predicate); + +/** + Get a value associated with the plugin in a plugin's data files. + This function is identical to lilv_plugin_get_value, but takes a QName + string parameter for a predicate instead of an LilvValue, which may be + more convenient. +*/ +LILV_API +LilvValues +lilv_plugin_get_value_by_qname(LilvPlugin p, + const char* predicate); + +/** + Get a value associated with some subject in a plugin's data files. + @a predicate must be either a URI or a QName. + + Returns the ?object of all triples found of the form: + + subject predicate ?object + + This can be used to investigate URIs returned by lilv_plugin_get_value + (if information about it is contained in the plugin's data files). + + May return NULL if the property was not found, or if object is not + sensibly represented as an LilvValues (e.g. blank nodes). + Return value must be freed by caller with lilv_values_free. +*/ +LILV_API +LilvValues +lilv_plugin_get_value_for_subject(LilvPlugin p, + LilvValue subject_uri, + LilvValue predicate_uri); + +/** + Return whether a feature is supported by a plugin. + This will return true if the feature is an optional or required feature + of the plugin. +*/ +LILV_API +bool +lilv_plugin_has_feature(LilvPlugin p, + LilvValue feature_uri); + +/** + Get the LV2 Features supported (required or optionally) by a plugin. + A feature is "supported" by a plugin if it is required OR optional. + + Since required features have special rules the host must obey, this function + probably shouldn't be used by normal hosts. Using lilv_plugin_get_optional_features + and lilv_plugin_get_required_features separately is best in most cases. + + Returned value must be freed by caller with lilv_values_free. +*/ +LILV_API +LilvValues +lilv_plugin_get_supported_features(LilvPlugin p); + +/** + Get the LV2 Features required by a plugin. + If a feature is required by a plugin, hosts MUST NOT use the plugin if they do not + understand (or are unable to support) that feature. + + All values returned here MUST be passed to the plugin's instantiate method + (along with data, if necessary, as defined by the feature specification) + or plugin instantiation will fail. + + Return value must be freed by caller with lilv_values_free. +*/ +LILV_API +LilvValues +lilv_plugin_get_required_features(LilvPlugin p); + +/** + Get the LV2 Features optionally supported by a plugin. + Hosts MAY ignore optional plugin features for whatever reasons. Plugins + MUST operate (at least somewhat) if they are instantiated without being + passed optional features. + + Return value must be freed by caller with lilv_values_free. +*/ +LILV_API +LilvValues +lilv_plugin_get_optional_features(LilvPlugin p); + +/** + Get the number of ports on this plugin. +*/ +LILV_API +uint32_t +lilv_plugin_get_num_ports(LilvPlugin p); + +/** + Get the port ranges (minimum, maximum and default values) for all ports. + @a min_values, @a max_values and @a def_values must either point to an array + of N floats, where N is the value returned by lilv_plugin_get_num_ports() + for this plugin, or NULL. The elements of the array will be set to the + the minimum, maximum and default values of the ports on this plugin, + with array index corresponding to port index. If a port doesn't have a + minimum, maximum or default value, or the port's type is not float, the + corresponding array element will be set to NAN. + + This is a convenience method for the common case of getting the range of + all float ports on a plugin, and may be significantly faster than + repeated calls to lilv_port_get_range. +*/ +LILV_API +void +lilv_plugin_get_port_ranges_float(LilvPlugin p, + float* min_values, + float* max_values, + float* def_values); + +/** + Get the number of ports on this plugin that are members of some class(es). + Note that this is a varargs function so ports fitting any type 'profile' + desired can be found quickly. REMEMBER TO TERMINATE THE PARAMETER LIST + OF THIS FUNCTION WITH NULL OR VERY NASTY THINGS WILL HAPPEN. +*/ +LILV_API +uint32_t +lilv_plugin_get_num_ports_of_class(LilvPlugin p, + LilvValue class_1, ...); + +/** + Return whether or not the plugin introduces (and reports) latency. + The index of the latency port can be found with lilv_plugin_get_latency_port + ONLY if this function returns true. +*/ +LILV_API +bool +lilv_plugin_has_latency(LilvPlugin p); + +/** + Return the index of the plugin's latency port. + It is a fatal error to call this on a plugin without checking if the port + exists by first calling lilv_plugin_has_latency. + + Any plugin that introduces unwanted latency that should be compensated for + (by hosts with the ability/need) MUST provide this port, which is a control + rate output port that reports the latency for each cycle in frames. +*/ +LILV_API +uint32_t +lilv_plugin_get_latency_port_index(LilvPlugin p); + +/** + Get a port on @a plugin by @a index. +*/ +LILV_API +LilvPort +lilv_plugin_get_port_by_index(LilvPlugin plugin, + uint32_t index); + +/** + Get a port on @a plugin by @a symbol. + Note this function is slower than lilv_plugin_get_port_by_index, + especially on plugins with a very large number of ports. +*/ +LILV_API +LilvPort +lilv_plugin_get_port_by_symbol(LilvPlugin plugin, + LilvValue symbol); + +/** + Get the full name of the plugin's author. + Returns NULL if author name is not present. + Returned value must be freed by caller. +*/ +LILV_API +LilvValue +lilv_plugin_get_author_name(LilvPlugin plugin); + +/** + Get the email address of the plugin's author. + Returns NULL if author email address is not present. + Returned value must be freed by caller. +*/ +LILV_API +LilvValue +lilv_plugin_get_author_email(LilvPlugin plugin); + +/** + Get the email address of the plugin's author. + Returns NULL if author homepage is not present. + Returned value must be freed by caller. +*/ +LILV_API +LilvValue +lilv_plugin_get_author_homepage(LilvPlugin plugin); + +/** + Return true iff @a plugin has been replaced by another plugin. + + The plugin will still be usable, but hosts should hide them from their + user interfaces to prevent users from using deprecated plugins. +*/ +LILV_API +bool +lilv_plugin_is_replaced(LilvPlugin plugin); + +/** + @} + @name Port + @{ +*/ + +/** + Port analog of lilv_plugin_get_value. +*/ +LILV_API +LilvValues +lilv_port_get_value(LilvPlugin plugin, + LilvPort port, + LilvValue predicate); + +/** + Port analog of lilv_plugin_get_value_by_qname. +*/ +LILV_API +LilvValues +lilv_port_get_value_by_qname(LilvPlugin plugin, + LilvPort port, + const char* predicate); + +/** + Return the LV2 port properties of a port. +*/ +LILV_API +LilvValues +lilv_port_get_properties(LilvPlugin plugin, + LilvPort port); + +/** + Return whether a port has a certain property. +*/ +LILV_API +bool +lilv_port_has_property(LilvPlugin p, + LilvPort port, + LilvValue property_uri); + +/** + Return whether a port is an event port and supports a certain event type. +*/ +LILV_API +bool +lilv_port_supports_event(LilvPlugin p, + LilvPort port, + LilvValue event_uri); + +/** + Get the symbol of a port. + The 'symbol' is a short string, a valid C identifier. + Returned value is owned by @a port and must not be freed. +*/ +LILV_API +LilvValue +lilv_port_get_symbol(LilvPlugin plugin, + LilvPort port); + +/** + Get the name of a port. + This is guaranteed to return the untranslated name (the doap:name in the + data file without a language tag). Returned value must be freed by + the caller. +*/ +LILV_API +LilvValue +lilv_port_get_name(LilvPlugin plugin, + LilvPort port); + +/** + Get all the classes of a port. + This can be used to determine if a port is an input, output, audio, + control, midi, etc, etc, though it's simpler to use lilv_port_is_a. + The returned list does not include lv2:Port, which is implied. + Returned value is shared and must not be destroyed by caller. +*/ +LILV_API +LilvValues +lilv_port_get_classes(LilvPlugin plugin, + LilvPort port); + +/** + Determine if a port is of a given class (input, output, audio, etc). + For convenience/performance/extensibility reasons, hosts are expected to + create an LilvValue for each port class they "care about". Well-known type + URI strings are defined (e.g. LILV_PORT_CLASS_INPUT) for convenience, but + this function is designed so that Lilv is usable with any port types + without requiring explicit support in Lilv. +*/ +LILV_API +bool +lilv_port_is_a(LilvPlugin plugin, + LilvPort port, + LilvValue port_class); + +/** + Get the default, minimum, and maximum values of a port. + @a def, @a min, and @a max are outputs, pass pointers to uninitialized + (i.e. NOT created with lilv_value_new) LilvValue variables. These will + be set to point at new values (which must be freed by the caller using + lilv_value_free), or NULL if the value does not exist. +*/ +LILV_API +void +lilv_port_get_range(LilvPlugin plugin, + LilvPort port, + LilvValue* deflt, + LilvValue* min, + LilvValue* max); + +/** + Get the scale points (enumeration values) of a port. + This returns a collection of 'interesting' named values of a port + (e.g. appropriate entries for a UI selector associated with this port). + Returned value may be NULL if @a port has no scale points, otherwise it + must be freed by caller with lilv_scale_points_free. +*/ +LILV_API +LilvScalePoints +lilv_port_get_scale_points(LilvPlugin plugin, + LilvPort port); + +/** + @} + @name Scale Point + @{ +*/ + +/** + Get the label of this scale point (enumeration value) + Returned value is owned by @a point and must not be freed. +*/ +LILV_API +LilvValue +lilv_scale_point_get_label(LilvScalePoint point); + +/** + Get the value of this scale point (enumeration value) + Returned value is owned by @a point and must not be freed. +*/ +LILV_API +LilvValue +lilv_scale_point_get_value(LilvScalePoint point); + +/** + @} + @name Plugin Class + @{ +*/ + +/** + Get the URI of this class' superclass. + Returned value is owned by @a plugin_class and must not be freed by caller. + Returned value may be NULL, if class has no parent. +*/ +LILV_API +LilvValue +lilv_plugin_class_get_parent_uri(LilvPluginClass plugin_class); + +/** + Get the URI of this plugin class. + Returned value is owned by @a plugin_class and must not be freed by caller. +*/ +LILV_API +LilvValue +lilv_plugin_class_get_uri(LilvPluginClass plugin_class); + +/** + Get the label of this plugin class, ie "Oscillators". + Returned value is owned by @a plugin_class and must not be freed by caller. +*/ +LILV_API +LilvValue lilv_plugin_class_get_label(LilvPluginClass plugin_class); + +/** + Get the subclasses of this plugin class. + Returned value must be freed by caller with lilv_plugin_classes_free. +*/ +LILV_API +LilvPluginClasses +lilv_plugin_class_get_children(LilvPluginClass plugin_class); + +/** + @} + @name Plugin Instance + @{ +*/ + +typedef struct _LilvInstanceImpl* LilvInstanceImpl; + +/** + @cond 0 +*/ + +/* Instance of a plugin. + This is exposed in the ABI to allow inlining of performance critical + functions like lilv_instance_run (simple wrappers of functions in lv2.h). + This is for performance reasons, user code should not use this definition + in any way (which is why it is not machine documented). + Truly private implementation details are hidden via @a ref pimpl. +*/ +typedef struct _Instance { + const LV2_Descriptor* lv2_descriptor; + LV2_Handle lv2_handle; + LilvInstanceImpl pimpl; +}* LilvInstance; + +/** + @endcond +*/ + +/** + Instantiate a plugin. + The returned value is a lightweight handle for an LV2 plugin instance, + it does not refer to @a plugin, or any other Lilv state. The caller must + eventually free it with lilv_instance_free. + @a features is a NULL-terminated array of features the host supports. + NULL may be passed if the host supports no additional features. + @return NULL if instantiation failed. +*/ +LILV_API +LilvInstance +lilv_plugin_instantiate(LilvPlugin plugin, + double sample_rate, + const LV2_Feature*const* features); + +/** + Free a plugin instance. + @a instance is invalid after this call. +*/ +LILV_API +void +lilv_instance_free(LilvInstance instance); + +#ifndef LILV_INTERNAL + +/** + Get the URI of the plugin which @a instance is an instance of. + Returned string is shared and must not be modified or deleted. +*/ +static inline const char* +lilv_instance_get_uri(LilvInstance instance) +{ + return instance->lv2_descriptor->URI; +} + +/** + Connect a port to a data location. + This may be called regardless of whether the plugin is activated, + activation and deactivation does not destroy port connections. +*/ +static inline void +lilv_instance_connect_port(LilvInstance instance, + uint32_t port_index, + void* data_location) +{ + instance->lv2_descriptor->connect_port + (instance->lv2_handle, port_index, data_location); +} + +/** + Activate a plugin instance. + This resets all state information in the plugin, except for port data + locations (as set by lilv_instance_connect_port). This MUST be called + before calling lilv_instance_run. +*/ +static inline void +lilv_instance_activate(LilvInstance instance) +{ + if (instance->lv2_descriptor->activate) + instance->lv2_descriptor->activate(instance->lv2_handle); +} + +/** + Run @a instance for @a sample_count frames. + If the hint lv2:hardRTCapable is set for this plugin, this function is + guaranteed not to block. +*/ +static inline void +lilv_instance_run(LilvInstance instance, + uint32_t sample_count) +{ + instance->lv2_descriptor->run(instance->lv2_handle, sample_count); +} + +/** + Deactivate a plugin instance. + Note that to run the plugin after this you must activate it, which will + reset all state information (except port connections). +*/ +static inline void +lilv_instance_deactivate(LilvInstance instance) +{ + if (instance->lv2_descriptor->deactivate) + instance->lv2_descriptor->deactivate(instance->lv2_handle); +} + +/** + Get extension data from the plugin instance. + The type and semantics of the data returned is specific to the particular + extension, though in all cases it is shared and must not be deleted. +*/ +static inline const void* +lilv_instance_get_extension_data(LilvInstance instance, + const char* uri) +{ + if (instance->lv2_descriptor->extension_data) + return instance->lv2_descriptor->extension_data(uri); + else + return NULL; +} + +/** + Get the LV2_Descriptor of the plugin instance. + Normally hosts should not need to access the LV2_Descriptor directly, + use the lilv_instance_* functions. + + The returned descriptor is shared and must not be deleted. +*/ +static inline const LV2_Descriptor* +lilv_instance_get_descriptor(LilvInstance instance) +{ + return instance->lv2_descriptor; +} + +/** + Get the LV2_Handle of the plugin instance. + Normally hosts should not need to access the LV2_Handle directly, + use the lilv_instance_* functions. + + The returned handle is shared and must not be deleted. +*/ +static inline LV2_Handle +lilv_instance_get_handle(LilvInstance instance) +{ + return instance->lv2_handle; +} + +#endif /* LILV_INTERNAL */ + +/** + @} + @name Plugin UI + @{ +*/ + +/** + Get all UIs for @a plugin. + Returned value must be freed by caller using lilv_uis_free. +*/ +LILV_API +LilvUIs +lilv_plugin_get_uis(LilvPlugin plugin); + +/** + Get the URI of a Plugin UI. + @param ui The Plugin UI + @return a shared value which must not be modified or freed. +*/ +LILV_API +LilvValue +lilv_ui_get_uri(LilvUI ui); + +/** + Get the types (URIs of RDF classes) of a Plugin UI. + @param ui The Plugin UI + @return a shared value which must not be modified or freed. + + Note that in most cases lilv_ui_is_supported should be used which finds the + UI type, avoding the need to use this function (and type specific logic). +*/ +LILV_API +LilvValues +lilv_ui_get_classes(LilvUI ui); + +/** + Check whether a plugin UI has a given type. + @param ui The Plugin UI + @param class_uri The URI of the LV2 UI type to check this UI against +*/ +LILV_API +bool +lilv_ui_is_a(LilvUI ui, LilvValue class_uri); + +/** + Function to determine whether a UI type is supported. + + This is provided by the user and must return non-zero iff using a UI of type + @c ui_type_uri in a container of type @c container_type_uri is supported. +*/ +typedef unsigned (*LilvUISupportedFunc)(const char* container_type_uri, + const char* ui_type_uri); + +/** + Return true iff a Plugin UI is supported as a given widget type. + @param ui The Plugin UI + @param supported_func User provided supported predicate. + @param container_type The widget type to host the UI within. + @param ui_type (Output) If non-NULL, set to the native type of the UI + which the caller must free with lilv_value_free. + @return The embedding quality level returned by @c supported_func. +*/ +LILV_API +unsigned +lilv_ui_is_supported(LilvUI ui, + LilvUISupportedFunc supported_func, + LilvValue container_type, + LilvValue* ui_type); + +/** + Get the URI for a Plugin UI's bundle. + @param ui The Plugin UI + @return a shared value which must not be modified or freed. +*/ +LILV_API +LilvValue +lilv_ui_get_bundle_uri(LilvUI ui); + +/** + Get the URI for a Plugin UI's shared library. + @param ui The Plugin UI + @return a shared value which must not be modified or freed. +*/ +LILV_API +LilvValue +lilv_ui_get_binary_uri(LilvUI ui); + +/** + @} + @} +*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* LILV_LILV_H */ diff --git a/lilv/lilvmm.hpp b/lilv/lilvmm.hpp new file mode 100644 index 0000000..7f25d33 --- /dev/null +++ b/lilv/lilvmm.hpp @@ -0,0 +1,264 @@ +/* + Copyright 2007-2011 David Robillard + + 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_LILVMM_HPP +#define LILV_LILVMM_HPP + +#include "lilv/lilv.h" + +namespace Lilv { + +const char* uri_to_path(const char* uri) { return lilv_uri_to_path(uri); } + +#define LILV_WRAP0(RT, prefix, name) \ + inline RT name () { return lilv_ ## prefix ## _ ## name (me); } + +#define LILV_WRAP0_VOID(prefix, name) \ + inline void name () { lilv_ ## prefix ## _ ## name (me); } + +#define LILV_WRAP1(RT, prefix, name, T1, a1) \ + inline RT name (T1 a1) { return lilv_ ## prefix ## _ ## name (me, a1); } + +#define LILV_WRAP1_VOID(prefix, name, T1, a1) \ + inline void name (T1 a1) { lilv_ ## prefix ## _ ## name (me, a1); } + +#define LILV_WRAP2(RT, prefix, name, T1, a1, T2, a2) \ + inline RT name (T1 a1, T2 a2) { return lilv_ ## prefix ## _ ## name (me, a1, a2); } + +#define LILV_WRAP2_VOID(prefix, name, T1, a1, T2, a2) \ + inline void name (T1 a1, T2 a2) { lilv_ ## prefix ## _ ## name (me, a1, a2); } + +#ifndef SWIG +#define LILV_WRAP_CONVERSION(CT) \ + inline operator CT() const { return me; } +#else +#define LILV_WRAP_CONVERSION(CT) +#endif + +struct Value { + inline Value(LilvValue value) : me(value) {} + inline Value(const Value& copy) : me(lilv_value_duplicate(copy.me)) {} + + inline ~Value() { /*lilv_value_free(me);*/ } + + inline bool equals(const Value& other) const { + return lilv_value_equals(me, other.me); + } + + inline bool operator==(const Value& other) const { return equals(other); } + + LILV_WRAP_CONVERSION(LilvValue); + + LILV_WRAP0(char*, value, get_turtle_token); + LILV_WRAP0(bool, value, is_uri); + LILV_WRAP0(const char*, value, as_uri); + LILV_WRAP0(bool, value, is_blank); + LILV_WRAP0(const char*, value, as_blank); + LILV_WRAP0(bool, value, is_literal); + LILV_WRAP0(bool, value, is_string); + LILV_WRAP0(const char*, value, as_string); + LILV_WRAP0(bool, value, is_float); + LILV_WRAP0(float, value, as_float); + LILV_WRAP0(bool, value, is_int); + LILV_WRAP0(int, value, as_int); + LILV_WRAP0(bool, value, is_bool); + LILV_WRAP0(bool, value, as_bool); + + LilvValue me; +}; + +struct ScalePoint { + inline ScalePoint(LilvScalePoint c_obj) : me(c_obj) {} + LILV_WRAP_CONVERSION(LilvScalePoint); + + LILV_WRAP0(LilvValue, scale_point, get_label); + LILV_WRAP0(LilvValue, scale_point, get_value); + + LilvScalePoint me; +}; + +struct PluginClass { + inline PluginClass(LilvPluginClass c_obj) : me(c_obj) {} + LILV_WRAP_CONVERSION(LilvPluginClass); + + LILV_WRAP0(Value, plugin_class, get_parent_uri); + LILV_WRAP0(Value, plugin_class, get_uri); + LILV_WRAP0(Value, plugin_class, get_label); + + inline LilvPluginClasses get_children() { + return lilv_plugin_class_get_children(me); + } + + LilvPluginClass me; +}; + +#define LILV_WRAP_COLL(CT, ET, prefix) \ + struct CT { \ + inline CT(Lilv ## CT c_obj) : me(c_obj) {} \ + LILV_WRAP_CONVERSION(Lilv ## CT); \ + LILV_WRAP0(unsigned, prefix, size); \ + LILV_WRAP1(ET, prefix, get, LilvIter, i); \ + Lilv ## CT me; \ + }; \ + +LILV_WRAP_COLL(PluginClasses, PluginClass, plugin_classes); +LILV_WRAP_COLL(ScalePoints, ScalePoint, scale_points); +LILV_WRAP_COLL(Values, Value, values); + +struct Plugins { + inline Plugins(LilvPlugins c_obj) : me(c_obj) {} + LILV_WRAP_CONVERSION(LilvPlugins); + + LilvPlugins me; +}; + +struct World { + inline World() : me(lilv_world_new()) {} + inline ~World() { /*lilv_world_free(me);*/ } + + inline LilvValue new_uri(const char* uri) { + return lilv_value_new_uri(me, uri); + } + inline LilvValue new_string(const char* str) { + return lilv_value_new_string(me, str); + } + inline LilvValue new_int(int val) { + return lilv_value_new_int(me, val); + } + inline LilvValue new_float(float val) { + return lilv_value_new_float(me, val); + } + inline LilvValue new_bool(bool val) { + return lilv_value_new_bool(me, val); + } + + LILV_WRAP2_VOID(world, set_option, const char*, uri, LilvValue, value); + LILV_WRAP0_VOID(world, free); + LILV_WRAP0_VOID(world, load_all); + LILV_WRAP1_VOID(world, load_bundle, LilvValue, bundle_uri); + LILV_WRAP0(LilvPluginClass, world, get_plugin_class); + LILV_WRAP0(LilvPluginClasses, world, get_plugin_classes); + LILV_WRAP0(Plugins, world, get_all_plugins); + //LILV_WRAP1(Plugin, world, get_plugin_by_uri_string, const char*, uri); + + LilvWorld me; +}; + +struct Port { + inline Port(LilvPlugin p, LilvPort c_obj) : parent(p), me(c_obj) {} + LILV_WRAP_CONVERSION(LilvPort); + +#define LILV_PORT_WRAP0(RT, name) \ + inline RT name () { return lilv_port_ ## name (parent, me); } + +#define LILV_PORT_WRAP1(RT, name, T1, a1) \ + inline RT name (T1 a1) { return lilv_port_ ## name (parent, me, a1); } + + LILV_PORT_WRAP1(LilvValues, get_value, LilvValue, predicate); + LILV_PORT_WRAP1(LilvValues, get_value_by_qname, const char*, predicate); + LILV_PORT_WRAP0(LilvValues, get_properties) + LILV_PORT_WRAP1(bool, has_property, LilvValue, property_uri); + LILV_PORT_WRAP1(bool, supports_event, LilvValue, event_uri); + LILV_PORT_WRAP0(LilvValue, get_symbol); + LILV_PORT_WRAP0(LilvValue, get_name); + LILV_PORT_WRAP0(LilvValues, get_classes); + LILV_PORT_WRAP1(bool, is_a, LilvValue, port_class); + LILV_PORT_WRAP0(LilvScalePoints, get_scale_points); + + // TODO: get_range (output parameters) + + LilvPlugin parent; + LilvPort me; +}; + +struct Plugin { + inline Plugin(LilvPlugin c_obj) : me(c_obj) {} + LILV_WRAP_CONVERSION(LilvPlugin); + + LILV_WRAP0(bool, plugin, verify); + LILV_WRAP0(Value, plugin, get_uri); + LILV_WRAP0(Value, plugin, get_bundle_uri); + LILV_WRAP0(Values, plugin, get_data_uris); + LILV_WRAP0(Value, plugin, get_library_uri); + LILV_WRAP0(Value, plugin, get_name); + LILV_WRAP0(PluginClass, plugin, get_class); + LILV_WRAP1(Values, plugin, get_value, Value, pred); + LILV_WRAP1(Values, plugin, get_value_by_qname, const char*, predicate); + LILV_WRAP2(Values, plugin, get_value_for_subject, Value, subject, + Value, predicate); + LILV_WRAP1(bool, plugin, has_feature, Value, feature_uri); + LILV_WRAP0(Values, plugin, get_supported_features); + LILV_WRAP0(Values, plugin, get_required_features); + LILV_WRAP0(Values, plugin, get_optional_features); + LILV_WRAP0(unsigned, plugin, get_num_ports); + LILV_WRAP0(bool, plugin, has_latency); + LILV_WRAP0(unsigned, plugin, get_latency_port_index); + LILV_WRAP0(Value, plugin, get_author_name); + LILV_WRAP0(Value, plugin, get_author_email); + LILV_WRAP0(Value, plugin, get_author_homepage); + + inline Port get_port_by_index(unsigned index) { + return Port(me, lilv_plugin_get_port_by_index(me, index)); + } + + inline Port get_port_by_symbol(LilvValue symbol) { + return Port(me, lilv_plugin_get_port_by_symbol(me, symbol)); + } + + inline void get_port_ranges_float(float* min_values, + float* max_values, + float* def_values) { + return lilv_plugin_get_port_ranges_float( + me, min_values, max_values, def_values); + } + + inline unsigned get_num_ports_of_class(LilvValue class_1, + LilvValue class_2) { + // TODO: varargs + return lilv_plugin_get_num_ports_of_class(me, class_1, class_2, NULL); + } + + LilvPlugin me; +}; + +struct Instance { + inline Instance(Plugin plugin, double sample_rate) { + // TODO: features + me = lilv_plugin_instantiate(plugin, sample_rate, NULL); + } + + LILV_WRAP_CONVERSION(LilvInstance); + + LILV_WRAP2_VOID(instance, connect_port, + unsigned, port_index, + void*, data_location); + + LILV_WRAP0_VOID(instance, activate); + LILV_WRAP1_VOID(instance, run, unsigned, sample_count); + LILV_WRAP0_VOID(instance, deactivate); + + // TODO: get_extension_data + + inline const LV2_Descriptor* get_descriptor() { + return lilv_instance_get_descriptor(me); + } + + LilvInstance me; +}; + +} /* namespace Lilv */ + +#endif /* LILV_LILVMM_HPP */ diff --git a/slv2.pc.in b/slv2.pc.in deleted file mode 100644 index cf9e973..0000000 --- a/slv2.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libslv2 -Version: @SLV2_VERSION@ -Description: Simple C library for hosting LV2 plugins -Libs: @GLIB_LIBS@ @SORD_LIBS@ -lsuil -L${libdir} -lslv2 -ldl -Cflags: @GLIB_CFLAGS@ @SORD_CFLAGS@ -I${includedir} diff --git a/slv2.ttl b/slv2.ttl deleted file mode 100644 index 3ef133b..0000000 --- a/slv2.ttl +++ /dev/null @@ -1,29 +0,0 @@ -@prefix rdf: . -@prefix rdfs: . -@prefix : . -@prefix foaf: . - - - a :Project ; - :bug-database ; - :developer [ - a foaf:Person ; - rdfs:seeAlso ; - foaf:homepage ; - foaf:mbox_sha1sum "253b3c58086250260bac1232d744d150274ad308" ; - foaf:name "David Robillard" - ] ; - :download-page ; - :homepage ; - :license ; - :name "SLV2" ; - :programming-language "C", "Turtle" ; - :repository [ - :browse ; - :location ; - a :SVNRepository - ] ; - :shortdesc "Library for simple use of LV2 plugins" ; - :shortname "SLV2" . - - diff --git a/slv2/slv2.h b/slv2/slv2.h deleted file mode 100644 index 9fbbae7..0000000 --- a/slv2/slv2.h +++ /dev/null @@ -1,1401 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - 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. -*/ - -/** - @file slv2.h API for SLV2, a lightweight LV2 host library. -*/ - -#ifndef SLV2_SLV2_H -#define SLV2_SLV2_H - -#include -#include -#include - -#include "lv2/lv2plug.in/ns/lv2core/lv2.h" - -#ifdef SLV2_SHARED -# ifdef __WIN32__ -# define SLV2_LIB_IMPORT __declspec(dllimport) -# define SLV2_LIB_EXPORT __declspec(dllexport) -# else -# define SLV2_LIB_IMPORT __attribute__((visibility("default"))) -# define SLV2_LIB_EXPORT __attribute__((visibility("default"))) -# endif -# ifdef SLV2_INTERNAL -# define SLV2_API SLV2_LIB_EXPORT -# else -# define SLV2_API SLV2_LIB_IMPORT -# endif -#else -# define SLV2_API -#endif - -#ifdef __GNUC__ -# ifdef SLV2_INTERNAL -# define SLV2_DEPRECATED -# else -# define SLV2_DEPRECATED __attribute__((__deprecated__)) -# endif -#else -# define SLV2_DEPRECATED -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define SLV2_NAMESPACE_LV2 "http://lv2plug.in/ns/lv2core#" -#define SLV2_PORT_CLASS_PORT "http://lv2plug.in/ns/lv2core#Port" -#define SLV2_PORT_CLASS_INPUT "http://lv2plug.in/ns/lv2core#InputPort" -#define SLV2_PORT_CLASS_OUTPUT "http://lv2plug.in/ns/lv2core#OutputPort" -#define SLV2_PORT_CLASS_CONTROL "http://lv2plug.in/ns/lv2core#ControlPort" -#define SLV2_PORT_CLASS_AUDIO "http://lv2plug.in/ns/lv2core#AudioPort" -#define SLV2_PORT_CLASS_EVENT "http://lv2plug.in/ns/ext/event#EventPort" -#define SLV2_EVENT_CLASS_MIDI "http://lv2plug.in/ns/ext/midi#MidiEvent" - -typedef struct _SLV2Plugin* SLV2Plugin; /**< LV2 Plugin. */ -typedef struct _SLV2PluginClass* SLV2PluginClass; /**< Plugin Class. */ -typedef struct _SLV2Port* SLV2Port; /**< Port. */ -typedef struct _SLV2ScalePoint* SLV2ScalePoint; /**< Scale Point (Notch). */ -typedef struct _SLV2UI* SLV2UI; /**< Plugin UI. */ -typedef struct _SLV2Value* SLV2Value; /**< Typed Value. */ -typedef struct _SLV2World* SLV2World; /**< SLV2 World. */ -typedef struct _SLV2UIInstance* SLV2UIInstance; /**< Plugin UI Instance. */ - -typedef void* SLV2PluginClasses; /**< set. */ -typedef void* SLV2Plugins; /**< set. */ -typedef void* SLV2ScalePoints; /**< set. */ -typedef void* SLV2UIs; /**< set. */ -typedef void* SLV2Values; /**< set. */ - -/** - @defgroup slv2 SLV2 - SLV2 is a simple yet powerful C API for using LV2 plugins. - - For more information about LV2, see . - For more information about SLV2, see . - @{ -*/ - -/** - @name Value - @{ -*/ - -/** - Convert a file URI string to a local path string. - For example, "file://foo/bar/baz.ttl" returns "/foo/bar/baz.ttl". - Return value is shared and must not be deleted by caller. - @return @a uri converted to a path, or NULL on failure (URI is not local). -*/ -SLV2_API -const char* -slv2_uri_to_path(const char* uri); - -/** - Create a new URI value. - Returned value must be freed by caller with slv2_value_free. -*/ -SLV2_API -SLV2Value -slv2_value_new_uri(SLV2World world, const char* uri); - -/** - Create a new string value (with no language). - Returned value must be freed by caller with slv2_value_free. -*/ -SLV2_API -SLV2Value -slv2_value_new_string(SLV2World world, const char* str); - -/** - Create a new integer value. - Returned value must be freed by caller with slv2_value_free. -*/ -SLV2_API -SLV2Value -slv2_value_new_int(SLV2World world, int val); - -/** - Create a new floating point value. - Returned value must be freed by caller with slv2_value_free. -*/ -SLV2_API -SLV2Value -slv2_value_new_float(SLV2World world, float val); - -/** - Create a new boolean value. - Returned value must be freed by caller with slv2_value_free. -*/ -SLV2_API -SLV2Value -slv2_value_new_bool(SLV2World world, bool val); - -/** - Free an SLV2Value. -*/ -SLV2_API -void -slv2_value_free(SLV2Value val); - -/** - Duplicate an SLV2Value. -*/ -SLV2_API -SLV2Value -slv2_value_duplicate(SLV2Value val); - -/** - Return whether two values are equivalent. -*/ -SLV2_API -bool -slv2_value_equals(SLV2Value value, SLV2Value other); - -/** - Return this value as a Turtle/SPARQL token. - Returned value must be freed by caller with slv2_value_free. - - - - - - - - -
Example Turtle Tokens
URI<http://example.org/foo >
QNamedoap:name
String"this is a string"
Float1.0
Integer1
Booleantrue
-*/ -SLV2_API -char* -slv2_value_get_turtle_token(SLV2Value value); - -/** - Return whether the value is a URI (resource). -*/ -SLV2_API -bool -slv2_value_is_uri(SLV2Value value); - -/** - Return this value as a URI string, e.g. "http://example.org/foo". - Valid to call only if slv2_value_is_uri(@a value) returns true. - Returned value is owned by @a value and must not be freed by caller. -*/ -SLV2_API -const char* -slv2_value_as_uri(SLV2Value value); - -/** - Return whether the value is a blank node (resource with no URI). -*/ -SLV2_API -bool -slv2_value_is_blank(SLV2Value value); - -/** - Return this value as a blank node identifier, e.g. "genid03". - Valid to call only if slv2_value_is_blank(@a value) returns true. - Returned value is owned by @a value and must not be freed by caller. -*/ -SLV2_API -const char* -slv2_value_as_blank(SLV2Value value); - -/** - Return whether this value is a literal (i.e. not a URI). - Returns true if @a value is a string or numeric value. -*/ -SLV2_API -bool -slv2_value_is_literal(SLV2Value value); - -/** - Return whether this value is a string literal. - Returns true if @a value is a string value (and not numeric). -*/ -SLV2_API -bool -slv2_value_is_string(SLV2Value value); - -/** - Return @a value as a string. -*/ -SLV2_API -const char* -slv2_value_as_string(SLV2Value value); - -/** - Return whether this value is a decimal literal. -*/ -SLV2_API -bool -slv2_value_is_float(SLV2Value value); - -/** - Return @a value as a float. - Valid to call only if slv2_value_is_float(@a value) or - slv2_value_is_int(@a value) returns true. -*/ -SLV2_API -float -slv2_value_as_float(SLV2Value value); - -/** - Return whether this value is an integer literal. -*/ -SLV2_API -bool -slv2_value_is_int(SLV2Value value); - -/** - Return @a value as an integer. - Valid to call only if slv2_value_is_int(@a value) returns true. -*/ -SLV2_API -int -slv2_value_as_int(SLV2Value value); - -/** - Return whether this value is a boolean. -*/ -SLV2_API -bool -slv2_value_is_bool(SLV2Value value); - -/** - Return @a value as a bool. - Valid to call only if slv2_value_is_bool(@a value) returns true. -*/ -SLV2_API -bool -slv2_value_as_bool(SLV2Value value); - -/** - @} - @name Collections - SLV2 has several collection types for holding various types of value: -
    -
  • SLV2Plugins (function prefix "slv2_plugins_")
  • -
  • SLV2PluginClasses (function prefix "slv2_plugin_classes_")
  • -
  • SLV2ScalePoints (function prefix "slv2_scale_points_")
  • -
  • SLV2Values (function prefix "slv2_values_")
  • -
  • SLV2UIs (function prefix "slv2_uis_")
  • -
- - Each collection type supports a similar basic API: -
    -
  • void PREFIX_free (coll)
  • -
  • unsigned PREFIX_size (coll)
  • -
  • SLV2Iter PREFIX_begin (coll)
  • -
  • ELEM PREFIX_get_at (coll, index) (DEPRECATED)
  • -
- @{ -*/ - -/* Collections */ - -typedef void* SLV2Iter; -typedef void* SLV2Collection; - -/** - Iterate over each element of a collection. - @code - SLV2_FOREACH(plugin_classes, i, classes) { - SLV2PluginClass c = slv2_plugin_classes_get(classes, i); - // ... - } - @endcode -*/ -#define SLV2_FOREACH(colltype, iter, collection) \ - for (SLV2Iter (iter) = slv2_ ## colltype ## _begin(collection); \ - !slv2_ ## colltype ## _is_end(collection, iter); \ - (iter) = slv2_ ## colltype ## _next(collection, iter)) - -/* SLV2PluginClasses */ - -SLV2_API -void -slv2_plugin_classes_free(SLV2PluginClasses collection); - -SLV2_API -unsigned -slv2_plugin_classes_size(SLV2PluginClasses collection); - -SLV2_API -SLV2Iter -slv2_plugin_classes_begin(SLV2PluginClasses collection); - -SLV2_API -SLV2PluginClass -slv2_plugin_classes_get(SLV2PluginClasses collection, SLV2Iter i); - -SLV2_API -SLV2Iter -slv2_plugin_classes_next(SLV2PluginClasses collection, SLV2Iter i); - -SLV2_API -bool -slv2_plugin_classes_is_end(SLV2PluginClasses collection, SLV2Iter i); - -SLV2_DEPRECATED -SLV2_API -SLV2PluginClass -slv2_plugin_classes_get_at(SLV2PluginClasses collection, unsigned index); - -/** - Get a plugin class from @a classes by URI. - Return value is shared (stored in @a classes) and must not be freed or - modified by the caller in any way. - @return NULL if no plugin class with @a uri is found in @a classes. -*/ -SLV2_API -SLV2PluginClass -slv2_plugin_classes_get_by_uri(SLV2PluginClasses classes, - SLV2Value uri); - -/* ScalePoints */ - -SLV2_API -void -slv2_scale_points_free(SLV2ScalePoints collection); - -SLV2_API -unsigned -slv2_scale_points_size(SLV2ScalePoints collection); - -SLV2_API -SLV2Iter -slv2_scale_points_begin(SLV2ScalePoints collection); - -SLV2_API -SLV2ScalePoint -slv2_scale_points_get(SLV2ScalePoints collection, SLV2Iter i); - -SLV2_API -SLV2Iter -slv2_scale_points_next(SLV2ScalePoints collection, SLV2Iter i); - -SLV2_API -bool -slv2_scale_points_is_end(SLV2ScalePoints collection, SLV2Iter i); - -SLV2_DEPRECATED -SLV2_API -SLV2ScalePoint -slv2_scale_points_get_at(SLV2ScalePoints collection, unsigned index); - -/* UIs */ - -SLV2_API -void -slv2_uis_free(SLV2UIs collection); - -SLV2_API -unsigned -slv2_uis_size(SLV2UIs collection); - -SLV2_API -SLV2Iter -slv2_uis_begin(SLV2UIs collection); - -SLV2_API -SLV2UI -slv2_uis_get(SLV2UIs collection, SLV2Iter i); - -SLV2_API -SLV2Iter -slv2_uis_next(SLV2UIs collection, SLV2Iter i); - -SLV2_API -bool -slv2_uis_is_end(SLV2UIs collection, SLV2Iter i); - -SLV2_DEPRECATED -SLV2_API -SLV2UI -slv2_uis_get_at(SLV2UIs collection, unsigned index); - -/** - Get a UI from @a uis by URI. - Return value is shared (stored in @a uis) and must not be freed or - modified by the caller in any way. - @return NULL if no UI with @a uri is found in @a list. -*/ -SLV2_API -SLV2UI -slv2_uis_get_by_uri(SLV2UIs uis, - SLV2Value uri); - -/* Values */ - -SLV2_API -void -slv2_values_free(SLV2Values collection); - -SLV2_API -unsigned -slv2_values_size(SLV2Values collection); - -SLV2_API -SLV2Iter -slv2_values_begin(SLV2Values collection); - -SLV2_API -SLV2Value -slv2_values_get(SLV2Values collection, SLV2Iter i); - -SLV2_API -SLV2Iter -slv2_values_next(SLV2Values collection, SLV2Iter i); - -SLV2_API -bool -slv2_values_is_end(SLV2Values collection, SLV2Iter i); - -SLV2_API -SLV2Value -slv2_values_get_first(SLV2Values collection); - -SLV2_DEPRECATED -SLV2_API -SLV2Value -slv2_values_get_at(SLV2Values collection, unsigned index); - -/** - Return whether @a values contains @a value. -*/ -SLV2_API -bool -slv2_values_contains(SLV2Values values, SLV2Value value); - -/* Plugins */ - -SLV2_API -unsigned -slv2_plugins_size(SLV2Plugins collection); - -SLV2_API -SLV2Iter -slv2_plugins_begin(SLV2Plugins collection); - -SLV2_API -SLV2Plugin -slv2_plugins_get(SLV2Plugins collection, SLV2Iter i); - -SLV2_API -SLV2Iter -slv2_plugins_next(SLV2Plugins collection, SLV2Iter i); - -SLV2_API -bool -slv2_plugins_is_end(SLV2Plugins collection, SLV2Iter i); - -SLV2_DEPRECATED -SLV2_API -SLV2Plugin -slv2_plugins_get_at(SLV2Plugins collection, unsigned index); - -SLV2_API -void -slv2_plugins_free(SLV2World world, SLV2Plugins plugins); - -/** - Get a plugin from @a plugins by URI. - Return value is shared (stored in @a plugins) and must not be freed or - modified by the caller in any way. - @return NULL if no plugin with @a uri is found in @a plugins. -*/ -SLV2_API -SLV2Plugin -slv2_plugins_get_by_uri(SLV2Plugins plugins, - SLV2Value uri); - -/** - @} - @name World - The "world" represents all SLV2 state, and is used to discover/load/cache - LV2 data (plugins, UIs, and extensions). - Normal hosts which just need to load plugins by URI should simply use - @ref slv2_world_load_all to discover/load the system's LV2 resources. - @{ -*/ - -/** - Initialize a new, empty world. - If initialization fails, NULL is returned. -*/ -SLV2_API -SLV2World -slv2_world_new(void); - -/** - Enable/disable language filtering. - Language filtering applies to any functions that return (a) value(s). - With filtering enabled, SLV2 will automatically return the best value(s) - for the current LANG. With filtering disabled, all matching values will - be returned regardless of language tag. Filtering is enabled by default. -*/ -#define SLV2_OPTION_FILTER_LANG "http://drobilla.net/ns/slv2#filter-lang" - -/** - Enable/disable dynamic manifest support. - Dynamic manifest data will only be loaded if this option is true. -*/ -#define SLV2_OPTION_DYN_MANIFEST "http://drobilla.net/ns/slv2#dyn-manifest" - -/** - Set an SLV2 option for @a world. - - Currently recognized options: - @ref SLV2_OPTION_FILTER_LANG - @ref SLV2_OPTION_DYN_MANIFEST -*/ -SLV2_API -void -slv2_world_set_option(SLV2World world, - const char* uri, - const SLV2Value value); - -/** - Destroy the world, mwahaha. - Note that destroying @a world will destroy all the objects it contains - (e.g. instances of SLV2Plugin). Do not destroy the world until you are - finished with all objects that came from it. -*/ -SLV2_API -void -slv2_world_free(SLV2World world); - -/** - Load all installed LV2 bundles on the system. - This is the recommended way for hosts to load LV2 data. It implements the - established/standard best practice for discovering all LV2 data on the - system. The environment variable LV2_PATH may be used to control where - this function will look for bundles. - - Hosts should use this function rather than explicitly load bundles, except - in special circumstances (e.g. development utilities, or hosts that ship - with special plugin bundles which are installed to a known location). -*/ -SLV2_API -void -slv2_world_load_all(SLV2World world); - -/** - Load a specific bundle. - @a bundle_uri must be a fully qualified URI to the bundle directory, - with the trailing slash, eg. file:///usr/lib/lv2/foo.lv2/ - - Normal hosts should not need this function (use slv2_world_load_all). - - Hosts MUST NOT attach any long-term significance to bundle paths - (e.g. in save files), since there are no guarantees they will remain - unchanged between (or even during) program invocations. Plugins (among - other things) MUST be identified by URIs (not paths) in save files. -*/ -SLV2_API -void -slv2_world_load_bundle(SLV2World world, - SLV2Value bundle_uri); - -/** - Get the parent of all other plugin classes, lv2:Plugin. -*/ -SLV2_API -SLV2PluginClass -slv2_world_get_plugin_class(SLV2World world); - -/** - Return a list of all found plugin classes. - Returned list is owned by world and must not be freed by the caller. -*/ -SLV2_API -SLV2PluginClasses -slv2_world_get_plugin_classes(SLV2World world); - -/** - Return a list of all found plugins. - The returned list contains just enough references to query - or instantiate plugins. The data for a particular plugin will not be - loaded into memory until a call to an slv2_plugin_* function results in - a query (at which time the data is cached with the SLV2Plugin so future - queries are very fast). - - The returned list and the plugins it contains are owned by @a world - and must not be freed by caller. -*/ -SLV2_API -SLV2Plugins -slv2_world_get_all_plugins(SLV2World world); - -/** - Return the plugin with the given @a uri, or NULL if not found. -*/ -SLV2_API -SLV2Plugin -slv2_world_get_plugin_by_uri_string(SLV2World world, - const char* uri); - -/** - @} - @name Plugin - @{ -*/ - -/** - Check if @a plugin is valid. - This is not a rigorous validator, but can be used to reject some malformed - plugins that could cause bugs (e.g. plugins with missing required fields). - - Note that normal hosts do NOT need to use this - slv2 does not - load invalid plugins into plugin lists. This is included for plugin - testing utilities, etc. - @return true iff @a plugin is valid. -*/ -SLV2_API -bool -slv2_plugin_verify(SLV2Plugin plugin); - -/** - Get the URI of @a plugin. - Any serialization that refers to plugins should refer to them by this. - Hosts SHOULD NOT save any filesystem paths, plugin indexes, etc. in saved - files; save only the URI. - - The URI is a globally unique identifier for one specific plugin. Two - plugins with the same URI are compatible in port signature, and should - be guaranteed to work in a compatible and consistent way. If a plugin - is upgraded in an incompatible way (eg if it has different ports), it - MUST have a different URI than it's predecessor. - - @return A shared URI value which must not be modified or freed. -*/ -SLV2_API -SLV2Value -slv2_plugin_get_uri(SLV2Plugin plugin); - -/** - Get the (resolvable) URI of the plugin's "main" bundle. - This returns the URI of the bundle where the plugin itself was found. - Note that the data for a plugin may be spread over many bundles, that is, - slv2_plugin_get_data_uris may return URIs which are not within this bundle. - - Typical hosts should not need to use this function. - Note this always returns a fully qualified URI. If you want a local - filesystem path, use slv2_uri_to_path. - @return a shared string which must not be modified or freed. -*/ -SLV2_API -SLV2Value -slv2_plugin_get_bundle_uri(SLV2Plugin plugin); - -/** - Get the (resolvable) URIs of the RDF data files that define a plugin. - Typical hosts should not need to use this function. - Note this always returns fully qualified URIs. If you want local - filesystem paths, use slv2_uri_to_path. - @return a list of complete URLs eg. "file:///foo/ABundle.lv2/aplug.ttl", - which is shared and must not be modified or freed. -*/ -SLV2_API -SLV2Values -slv2_plugin_get_data_uris(SLV2Plugin plugin); - -/** - Get the (resolvable) URI of the shared library for @a plugin. - Note this always returns a fully qualified URI. If you want a local - filesystem path, use slv2_uri_to_path. - @return a shared string which must not be modified or freed. -*/ -SLV2_API -SLV2Value -slv2_plugin_get_library_uri(SLV2Plugin plugin); - -/** - Get the name of @a plugin. - This returns the name (doap:name) of the plugin. The name may be - translated according to the current locale, this value MUST NOT be used - as a plugin identifier (use the URI for that). - Returned value must be freed by the caller. -*/ -SLV2_API -SLV2Value -slv2_plugin_get_name(SLV2Plugin plugin); - -/** - Get the class this plugin belongs to (ie Filters). -*/ -SLV2_API -SLV2PluginClass -slv2_plugin_get_class(SLV2Plugin plugin); - -/** - Get a value associated with the plugin in a plugin's data files. - @a predicate must be either a URI or a QName. - - Returns the ?object of all triples found of the form: - - <plugin-uri> predicate ?object - - May return NULL if the property was not found, or if object(s) is not - sensibly represented as an SLV2Values (e.g. blank nodes). - Return value must be freed by caller with slv2_values_free. -*/ -SLV2_API -SLV2Values -slv2_plugin_get_value(SLV2Plugin p, - SLV2Value predicate); - -/** - Get a value associated with the plugin in a plugin's data files. - This function is identical to slv2_plugin_get_value, but takes a QName - string parameter for a predicate instead of an SLV2Value, which may be - more convenient. -*/ -SLV2_API -SLV2Values -slv2_plugin_get_value_by_qname(SLV2Plugin p, - const char* predicate); - -/** - Get a value associated with some subject in a plugin's data files. - @a predicate must be either a URI or a QName. - - Returns the ?object of all triples found of the form: - - subject predicate ?object - - This can be used to investigate URIs returned by slv2_plugin_get_value - (if information about it is contained in the plugin's data files). - - May return NULL if the property was not found, or if object is not - sensibly represented as an SLV2Values (e.g. blank nodes). - Return value must be freed by caller with slv2_values_free. -*/ -SLV2_API -SLV2Values -slv2_plugin_get_value_for_subject(SLV2Plugin p, - SLV2Value subject_uri, - SLV2Value predicate_uri); - -/** - Return whether a feature is supported by a plugin. - This will return true if the feature is an optional or required feature - of the plugin. -*/ -SLV2_API -bool -slv2_plugin_has_feature(SLV2Plugin p, - SLV2Value feature_uri); - -/** - Get the LV2 Features supported (required or optionally) by a plugin. - A feature is "supported" by a plugin if it is required OR optional. - - Since required features have special rules the host must obey, this function - probably shouldn't be used by normal hosts. Using slv2_plugin_get_optional_features - and slv2_plugin_get_required_features separately is best in most cases. - - Returned value must be freed by caller with slv2_values_free. -*/ -SLV2_API -SLV2Values -slv2_plugin_get_supported_features(SLV2Plugin p); - -/** - Get the LV2 Features required by a plugin. - If a feature is required by a plugin, hosts MUST NOT use the plugin if they do not - understand (or are unable to support) that feature. - - All values returned here MUST be passed to the plugin's instantiate method - (along with data, if necessary, as defined by the feature specification) - or plugin instantiation will fail. - - Return value must be freed by caller with slv2_values_free. -*/ -SLV2_API -SLV2Values -slv2_plugin_get_required_features(SLV2Plugin p); - -/** - Get the LV2 Features optionally supported by a plugin. - Hosts MAY ignore optional plugin features for whatever reasons. Plugins - MUST operate (at least somewhat) if they are instantiated without being - passed optional features. - - Return value must be freed by caller with slv2_values_free. -*/ -SLV2_API -SLV2Values -slv2_plugin_get_optional_features(SLV2Plugin p); - -/** - Get the number of ports on this plugin. -*/ -SLV2_API -uint32_t -slv2_plugin_get_num_ports(SLV2Plugin p); - -/** - Get the port ranges (minimum, maximum and default values) for all ports. - @a min_values, @a max_values and @a def_values must either point to an array - of N floats, where N is the value returned by slv2_plugin_get_num_ports() - for this plugin, or NULL. The elements of the array will be set to the - the minimum, maximum and default values of the ports on this plugin, - with array index corresponding to port index. If a port doesn't have a - minimum, maximum or default value, or the port's type is not float, the - corresponding array element will be set to NAN. - - This is a convenience method for the common case of getting the range of - all float ports on a plugin, and may be significantly faster than - repeated calls to slv2_port_get_range. -*/ -SLV2_API -void -slv2_plugin_get_port_ranges_float(SLV2Plugin p, - float* min_values, - float* max_values, - float* def_values); - -/** - Get the number of ports on this plugin that are members of some class(es). - Note that this is a varargs function so ports fitting any type 'profile' - desired can be found quickly. REMEMBER TO TERMINATE THE PARAMETER LIST - OF THIS FUNCTION WITH NULL OR VERY NASTY THINGS WILL HAPPEN. -*/ -SLV2_API -uint32_t -slv2_plugin_get_num_ports_of_class(SLV2Plugin p, - SLV2Value class_1, ...); - -/** - Return whether or not the plugin introduces (and reports) latency. - The index of the latency port can be found with slv2_plugin_get_latency_port - ONLY if this function returns true. -*/ -SLV2_API -bool -slv2_plugin_has_latency(SLV2Plugin p); - -/** - Return the index of the plugin's latency port. - It is a fatal error to call this on a plugin without checking if the port - exists by first calling slv2_plugin_has_latency. - - Any plugin that introduces unwanted latency that should be compensated for - (by hosts with the ability/need) MUST provide this port, which is a control - rate output port that reports the latency for each cycle in frames. -*/ -SLV2_API -uint32_t -slv2_plugin_get_latency_port_index(SLV2Plugin p); - -/** - Get a port on @a plugin by @a index. -*/ -SLV2_API -SLV2Port -slv2_plugin_get_port_by_index(SLV2Plugin plugin, - uint32_t index); - -/** - Get a port on @a plugin by @a symbol. - Note this function is slower than slv2_plugin_get_port_by_index, - especially on plugins with a very large number of ports. -*/ -SLV2_API -SLV2Port -slv2_plugin_get_port_by_symbol(SLV2Plugin plugin, - SLV2Value symbol); - -/** - Get the full name of the plugin's author. - Returns NULL if author name is not present. - Returned value must be freed by caller. -*/ -SLV2_API -SLV2Value -slv2_plugin_get_author_name(SLV2Plugin plugin); - -/** - Get the email address of the plugin's author. - Returns NULL if author email address is not present. - Returned value must be freed by caller. -*/ -SLV2_API -SLV2Value -slv2_plugin_get_author_email(SLV2Plugin plugin); - -/** - Get the email address of the plugin's author. - Returns NULL if author homepage is not present. - Returned value must be freed by caller. -*/ -SLV2_API -SLV2Value -slv2_plugin_get_author_homepage(SLV2Plugin plugin); - -/** - Return true iff @a plugin has been replaced by another plugin. - - The plugin will still be usable, but hosts should hide them from their - user interfaces to prevent users from using deprecated plugins. -*/ -SLV2_API -bool -slv2_plugin_is_replaced(SLV2Plugin plugin); - -/** - @} - @name Port - @{ -*/ - -/** - Port analog of slv2_plugin_get_value. -*/ -SLV2_API -SLV2Values -slv2_port_get_value(SLV2Plugin plugin, - SLV2Port port, - SLV2Value predicate); - -/** - Port analog of slv2_plugin_get_value_by_qname. -*/ -SLV2_API -SLV2Values -slv2_port_get_value_by_qname(SLV2Plugin plugin, - SLV2Port port, - const char* predicate); - -/** - Return the LV2 port properties of a port. -*/ -SLV2_API -SLV2Values -slv2_port_get_properties(SLV2Plugin plugin, - SLV2Port port); - -/** - Return whether a port has a certain property. -*/ -SLV2_API -bool -slv2_port_has_property(SLV2Plugin p, - SLV2Port port, - SLV2Value property_uri); - -/** - Return whether a port is an event port and supports a certain event type. -*/ -SLV2_API -bool -slv2_port_supports_event(SLV2Plugin p, - SLV2Port port, - SLV2Value event_uri); - -/** - Get the symbol of a port. - The 'symbol' is a short string, a valid C identifier. - Returned value is owned by @a port and must not be freed. -*/ -SLV2_API -SLV2Value -slv2_port_get_symbol(SLV2Plugin plugin, - SLV2Port port); - -/** - Get the name of a port. - This is guaranteed to return the untranslated name (the doap:name in the - data file without a language tag). Returned value must be freed by - the caller. -*/ -SLV2_API -SLV2Value -slv2_port_get_name(SLV2Plugin plugin, - SLV2Port port); - -/** - Get all the classes of a port. - This can be used to determine if a port is an input, output, audio, - control, midi, etc, etc, though it's simpler to use slv2_port_is_a. - The returned list does not include lv2:Port, which is implied. - Returned value is shared and must not be destroyed by caller. -*/ -SLV2_API -SLV2Values -slv2_port_get_classes(SLV2Plugin plugin, - SLV2Port port); - -/** - Determine if a port is of a given class (input, output, audio, etc). - For convenience/performance/extensibility reasons, hosts are expected to - create an SLV2Value for each port class they "care about". Well-known type - URI strings are defined (e.g. SLV2_PORT_CLASS_INPUT) for convenience, but - this function is designed so that SLV2 is usable with any port types - without requiring explicit support in SLV2. -*/ -SLV2_API -bool -slv2_port_is_a(SLV2Plugin plugin, - SLV2Port port, - SLV2Value port_class); - -/** - Get the default, minimum, and maximum values of a port. - @a def, @a min, and @a max are outputs, pass pointers to uninitialized - (i.e. NOT created with slv2_value_new) SLV2Value variables. These will - be set to point at new values (which must be freed by the caller using - slv2_value_free), or NULL if the value does not exist. -*/ -SLV2_API -void -slv2_port_get_range(SLV2Plugin plugin, - SLV2Port port, - SLV2Value* deflt, - SLV2Value* min, - SLV2Value* max); - -/** - Get the scale points (enumeration values) of a port. - This returns a collection of 'interesting' named values of a port - (e.g. appropriate entries for a UI selector associated with this port). - Returned value may be NULL if @a port has no scale points, otherwise it - must be freed by caller with slv2_scale_points_free. -*/ -SLV2_API -SLV2ScalePoints -slv2_port_get_scale_points(SLV2Plugin plugin, - SLV2Port port); - -/** - @} - @name Scale Point - @{ -*/ - -/** - Get the label of this scale point (enumeration value) - Returned value is owned by @a point and must not be freed. -*/ -SLV2_API -SLV2Value -slv2_scale_point_get_label(SLV2ScalePoint point); - -/** - Get the value of this scale point (enumeration value) - Returned value is owned by @a point and must not be freed. -*/ -SLV2_API -SLV2Value -slv2_scale_point_get_value(SLV2ScalePoint point); - -/** - @} - @name Plugin Class - @{ -*/ - -/** - Get the URI of this class' superclass. - Returned value is owned by @a plugin_class and must not be freed by caller. - Returned value may be NULL, if class has no parent. -*/ -SLV2_API -SLV2Value -slv2_plugin_class_get_parent_uri(SLV2PluginClass plugin_class); - -/** - Get the URI of this plugin class. - Returned value is owned by @a plugin_class and must not be freed by caller. -*/ -SLV2_API -SLV2Value -slv2_plugin_class_get_uri(SLV2PluginClass plugin_class); - -/** - Get the label of this plugin class, ie "Oscillators". - Returned value is owned by @a plugin_class and must not be freed by caller. -*/ -SLV2_API -SLV2Value slv2_plugin_class_get_label(SLV2PluginClass plugin_class); - -/** - Get the subclasses of this plugin class. - Returned value must be freed by caller with slv2_plugin_classes_free. -*/ -SLV2_API -SLV2PluginClasses -slv2_plugin_class_get_children(SLV2PluginClass plugin_class); - -/** - @} - @name Plugin Instance - @{ -*/ - -typedef struct _SLV2InstanceImpl* SLV2InstanceImpl; - -/** - @cond 0 -*/ - -/* Instance of a plugin. - This is exposed in the ABI to allow inlining of performance critical - functions like slv2_instance_run (simple wrappers of functions in lv2.h). - This is for performance reasons, user code should not use this definition - in any way (which is why it is not machine documented). - Truly private implementation details are hidden via @a ref pimpl. -*/ -typedef struct _Instance { - const LV2_Descriptor* lv2_descriptor; - LV2_Handle lv2_handle; - SLV2InstanceImpl pimpl; -}* SLV2Instance; - -/** - @endcond -*/ - -/** - Instantiate a plugin. - The returned value is a lightweight handle for an LV2 plugin instance, - it does not refer to @a plugin, or any other SLV2 state. The caller must - eventually free it with slv2_instance_free. - @a features is a NULL-terminated array of features the host supports. - NULL may be passed if the host supports no additional features. - @return NULL if instantiation failed. -*/ -SLV2_API -SLV2Instance -slv2_plugin_instantiate(SLV2Plugin plugin, - double sample_rate, - const LV2_Feature*const* features); - -/** - Free a plugin instance. - @a instance is invalid after this call. -*/ -SLV2_API -void -slv2_instance_free(SLV2Instance instance); - -#ifndef SLV2_INTERNAL - -/** - Get the URI of the plugin which @a instance is an instance of. - Returned string is shared and must not be modified or deleted. -*/ -static inline const char* -slv2_instance_get_uri(SLV2Instance instance) -{ - return instance->lv2_descriptor->URI; -} - -/** - Connect a port to a data location. - This may be called regardless of whether the plugin is activated, - activation and deactivation does not destroy port connections. -*/ -static inline void -slv2_instance_connect_port(SLV2Instance instance, - uint32_t port_index, - void* data_location) -{ - instance->lv2_descriptor->connect_port - (instance->lv2_handle, port_index, data_location); -} - -/** - Activate a plugin instance. - This resets all state information in the plugin, except for port data - locations (as set by slv2_instance_connect_port). This MUST be called - before calling slv2_instance_run. -*/ -static inline void -slv2_instance_activate(SLV2Instance instance) -{ - if (instance->lv2_descriptor->activate) - instance->lv2_descriptor->activate(instance->lv2_handle); -} - -/** - Run @a instance for @a sample_count frames. - If the hint lv2:hardRTCapable is set for this plugin, this function is - guaranteed not to block. -*/ -static inline void -slv2_instance_run(SLV2Instance instance, - uint32_t sample_count) -{ - instance->lv2_descriptor->run(instance->lv2_handle, sample_count); -} - -/** - Deactivate a plugin instance. - Note that to run the plugin after this you must activate it, which will - reset all state information (except port connections). -*/ -static inline void -slv2_instance_deactivate(SLV2Instance instance) -{ - if (instance->lv2_descriptor->deactivate) - instance->lv2_descriptor->deactivate(instance->lv2_handle); -} - -/** - Get extension data from the plugin instance. - The type and semantics of the data returned is specific to the particular - extension, though in all cases it is shared and must not be deleted. -*/ -static inline const void* -slv2_instance_get_extension_data(SLV2Instance instance, - const char* uri) -{ - if (instance->lv2_descriptor->extension_data) - return instance->lv2_descriptor->extension_data(uri); - else - return NULL; -} - -/** - Get the LV2_Descriptor of the plugin instance. - Normally hosts should not need to access the LV2_Descriptor directly, - use the slv2_instance_* functions. - - The returned descriptor is shared and must not be deleted. -*/ -static inline const LV2_Descriptor* -slv2_instance_get_descriptor(SLV2Instance instance) -{ - return instance->lv2_descriptor; -} - -/** - Get the LV2_Handle of the plugin instance. - Normally hosts should not need to access the LV2_Handle directly, - use the slv2_instance_* functions. - - The returned handle is shared and must not be deleted. -*/ -static inline LV2_Handle -slv2_instance_get_handle(SLV2Instance instance) -{ - return instance->lv2_handle; -} - -#endif /* SLV2_INTERNAL */ - -/** - @} - @name Plugin UI - @{ -*/ - -/** - Get all UIs for @a plugin. - Returned value must be freed by caller using slv2_uis_free. -*/ -SLV2_API -SLV2UIs -slv2_plugin_get_uis(SLV2Plugin plugin); - -/** - Get the URI of a Plugin UI. - @param ui The Plugin UI - @return a shared value which must not be modified or freed. -*/ -SLV2_API -SLV2Value -slv2_ui_get_uri(SLV2UI ui); - -/** - Get the types (URIs of RDF classes) of a Plugin UI. - @param ui The Plugin UI - @return a shared value which must not be modified or freed. - - Note that in most cases slv2_ui_is_supported should be used which finds the - UI type, avoding the need to use this function (and type specific logic). -*/ -SLV2_API -SLV2Values -slv2_ui_get_classes(SLV2UI ui); - -/** - Check whether a plugin UI has a given type. - @param ui The Plugin UI - @param class_uri The URI of the LV2 UI type to check this UI against -*/ -SLV2_API -bool -slv2_ui_is_a(SLV2UI ui, SLV2Value class_uri); - -/** - Function to determine whether a UI type is supported. - - This is provided by the user and must return non-zero iff using a UI of type - @c ui_type_uri in a container of type @c container_type_uri is supported. -*/ -typedef unsigned (*SLV2UISupportedFunc)(const char* container_type_uri, - const char* ui_type_uri); - -/** - Return true iff a Plugin UI is supported as a given widget type. - @param ui The Plugin UI - @param supported_func User provided supported predicate. - @param container_type The widget type to host the UI within. - @param ui_type (Output) If non-NULL, set to the native type of the UI - which the caller must free with slv2_value_free. - @return The embedding quality level returned by @c supported_func. -*/ -SLV2_API -unsigned -slv2_ui_is_supported(SLV2UI ui, - SLV2UISupportedFunc supported_func, - SLV2Value container_type, - SLV2Value* ui_type); - -/** - Get the URI for a Plugin UI's bundle. - @param ui The Plugin UI - @return a shared value which must not be modified or freed. -*/ -SLV2_API -SLV2Value -slv2_ui_get_bundle_uri(SLV2UI ui); - -/** - Get the URI for a Plugin UI's shared library. - @param ui The Plugin UI - @return a shared value which must not be modified or freed. -*/ -SLV2_API -SLV2Value -slv2_ui_get_binary_uri(SLV2UI ui); - -/** - @} - @} -*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* SLV2_SLV2_H */ diff --git a/slv2/slv2mm.hpp b/slv2/slv2mm.hpp deleted file mode 100644 index ed9b6d4..0000000 --- a/slv2/slv2mm.hpp +++ /dev/null @@ -1,264 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - 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_SLV2MM_HPP -#define SLV2_SLV2MM_HPP - -#include "slv2/slv2.h" - -namespace SLV2 { - -const char* uri_to_path(const char* uri) { return slv2_uri_to_path(uri); } - -#define SLV2_WRAP0(RT, prefix, name) \ - inline RT name () { return slv2_ ## prefix ## _ ## name (me); } - -#define SLV2_WRAP0_VOID(prefix, name) \ - inline void name () { slv2_ ## prefix ## _ ## name (me); } - -#define SLV2_WRAP1(RT, prefix, name, T1, a1) \ - inline RT name (T1 a1) { return slv2_ ## prefix ## _ ## name (me, a1); } - -#define SLV2_WRAP1_VOID(prefix, name, T1, a1) \ - inline void name (T1 a1) { slv2_ ## prefix ## _ ## name (me, a1); } - -#define SLV2_WRAP2(RT, prefix, name, T1, a1, T2, a2) \ - inline RT name (T1 a1, T2 a2) { return slv2_ ## prefix ## _ ## name (me, a1, a2); } - -#define SLV2_WRAP2_VOID(prefix, name, T1, a1, T2, a2) \ - inline void name (T1 a1, T2 a2) { slv2_ ## prefix ## _ ## name (me, a1, a2); } - -#ifndef SWIG -#define SLV2_WRAP_CONVERSION(CT) \ - inline operator CT() const { return me; } -#else -#define SLV2_WRAP_CONVERSION(CT) -#endif - -struct Value { - inline Value(SLV2Value value) : me(value) {} - inline Value(const Value& copy) : me(slv2_value_duplicate(copy.me)) {} - - inline ~Value() { /*slv2_value_free(me);*/ } - - inline bool equals(const Value& other) const { - return slv2_value_equals(me, other.me); - } - - inline bool operator==(const Value& other) const { return equals(other); } - - SLV2_WRAP_CONVERSION(SLV2Value); - - SLV2_WRAP0(char*, value, get_turtle_token); - SLV2_WRAP0(bool, value, is_uri); - SLV2_WRAP0(const char*, value, as_uri); - SLV2_WRAP0(bool, value, is_blank); - SLV2_WRAP0(const char*, value, as_blank); - SLV2_WRAP0(bool, value, is_literal); - SLV2_WRAP0(bool, value, is_string); - SLV2_WRAP0(const char*, value, as_string); - SLV2_WRAP0(bool, value, is_float); - SLV2_WRAP0(float, value, as_float); - SLV2_WRAP0(bool, value, is_int); - SLV2_WRAP0(int, value, as_int); - SLV2_WRAP0(bool, value, is_bool); - SLV2_WRAP0(bool, value, as_bool); - - SLV2Value me; -}; - -struct ScalePoint { - inline ScalePoint(SLV2ScalePoint c_obj) : me(c_obj) {} - SLV2_WRAP_CONVERSION(SLV2ScalePoint); - - SLV2_WRAP0(SLV2Value, scale_point, get_label); - SLV2_WRAP0(SLV2Value, scale_point, get_value); - - SLV2ScalePoint me; -}; - -struct PluginClass { - inline PluginClass(SLV2PluginClass c_obj) : me(c_obj) {} - SLV2_WRAP_CONVERSION(SLV2PluginClass); - - SLV2_WRAP0(Value, plugin_class, get_parent_uri); - SLV2_WRAP0(Value, plugin_class, get_uri); - SLV2_WRAP0(Value, plugin_class, get_label); - - inline SLV2PluginClasses get_children() { - return slv2_plugin_class_get_children(me); - } - - SLV2PluginClass me; -}; - -#define SLV2_WRAP_COLL(CT, ET, prefix) \ - struct CT { \ - inline CT(SLV2 ## CT c_obj) : me(c_obj) {} \ - SLV2_WRAP_CONVERSION(SLV2 ## CT); \ - SLV2_WRAP0(unsigned, prefix, size); \ - SLV2_WRAP1(ET, prefix, get, SLV2Iter, i); \ - SLV2 ## CT me; \ - }; \ - -SLV2_WRAP_COLL(PluginClasses, PluginClass, plugin_classes); -SLV2_WRAP_COLL(ScalePoints, ScalePoint, scale_points); -SLV2_WRAP_COLL(Values, Value, values); - -struct Plugins { - inline Plugins(SLV2Plugins c_obj) : me(c_obj) {} - SLV2_WRAP_CONVERSION(SLV2Plugins); - - SLV2Plugins me; -}; - -struct World { - inline World() : me(slv2_world_new()) {} - inline ~World() { /*slv2_world_free(me);*/ } - - inline SLV2Value new_uri(const char* uri) { - return slv2_value_new_uri(me, uri); - } - inline SLV2Value new_string(const char* str) { - return slv2_value_new_string(me, str); - } - inline SLV2Value new_int(int val) { - return slv2_value_new_int(me, val); - } - inline SLV2Value new_float(float val) { - return slv2_value_new_float(me, val); - } - inline SLV2Value new_bool(bool val) { - return slv2_value_new_bool(me, val); - } - - SLV2_WRAP2_VOID(world, set_option, const char*, uri, SLV2Value, value); - SLV2_WRAP0_VOID(world, free); - SLV2_WRAP0_VOID(world, load_all); - SLV2_WRAP1_VOID(world, load_bundle, SLV2Value, bundle_uri); - SLV2_WRAP0(SLV2PluginClass, world, get_plugin_class); - SLV2_WRAP0(SLV2PluginClasses, world, get_plugin_classes); - SLV2_WRAP0(Plugins, world, get_all_plugins); - //SLV2_WRAP1(Plugin, world, get_plugin_by_uri_string, const char*, uri); - - SLV2World me; -}; - -struct Port { - inline Port(SLV2Plugin p, SLV2Port c_obj) : parent(p), me(c_obj) {} - SLV2_WRAP_CONVERSION(SLV2Port); - -#define SLV2_PORT_WRAP0(RT, name) \ - inline RT name () { return slv2_port_ ## name (parent, me); } - -#define SLV2_PORT_WRAP1(RT, name, T1, a1) \ - inline RT name (T1 a1) { return slv2_port_ ## name (parent, me, a1); } - - SLV2_PORT_WRAP1(SLV2Values, get_value, SLV2Value, predicate); - SLV2_PORT_WRAP1(SLV2Values, get_value_by_qname, const char*, predicate); - SLV2_PORT_WRAP0(SLV2Values, get_properties) - SLV2_PORT_WRAP1(bool, has_property, SLV2Value, property_uri); - SLV2_PORT_WRAP1(bool, supports_event, SLV2Value, event_uri); - SLV2_PORT_WRAP0(SLV2Value, get_symbol); - SLV2_PORT_WRAP0(SLV2Value, get_name); - SLV2_PORT_WRAP0(SLV2Values, get_classes); - SLV2_PORT_WRAP1(bool, is_a, SLV2Value, port_class); - SLV2_PORT_WRAP0(SLV2ScalePoints, get_scale_points); - - // TODO: get_range (output parameters) - - SLV2Plugin parent; - SLV2Port me; -}; - -struct Plugin { - inline Plugin(SLV2Plugin c_obj) : me(c_obj) {} - SLV2_WRAP_CONVERSION(SLV2Plugin); - - SLV2_WRAP0(bool, plugin, verify); - SLV2_WRAP0(Value, plugin, get_uri); - SLV2_WRAP0(Value, plugin, get_bundle_uri); - SLV2_WRAP0(Values, plugin, get_data_uris); - SLV2_WRAP0(Value, plugin, get_library_uri); - SLV2_WRAP0(Value, plugin, get_name); - SLV2_WRAP0(PluginClass, plugin, get_class); - SLV2_WRAP1(Values, plugin, get_value, Value, pred); - SLV2_WRAP1(Values, plugin, get_value_by_qname, const char*, predicate); - SLV2_WRAP2(Values, plugin, get_value_for_subject, Value, subject, - Value, predicate); - SLV2_WRAP1(bool, plugin, has_feature, Value, feature_uri); - SLV2_WRAP0(Values, plugin, get_supported_features); - SLV2_WRAP0(Values, plugin, get_required_features); - SLV2_WRAP0(Values, plugin, get_optional_features); - SLV2_WRAP0(unsigned, plugin, get_num_ports); - SLV2_WRAP0(bool, plugin, has_latency); - SLV2_WRAP0(unsigned, plugin, get_latency_port_index); - SLV2_WRAP0(Value, plugin, get_author_name); - SLV2_WRAP0(Value, plugin, get_author_email); - SLV2_WRAP0(Value, plugin, get_author_homepage); - - inline Port get_port_by_index(unsigned index) { - return Port(me, slv2_plugin_get_port_by_index(me, index)); - } - - inline Port get_port_by_symbol(SLV2Value symbol) { - return Port(me, slv2_plugin_get_port_by_symbol(me, symbol)); - } - - inline void get_port_ranges_float(float* min_values, - float* max_values, - float* def_values) { - return slv2_plugin_get_port_ranges_float( - me, min_values, max_values, def_values); - } - - inline unsigned get_num_ports_of_class(SLV2Value class_1, - SLV2Value class_2) { - // TODO: varargs - return slv2_plugin_get_num_ports_of_class(me, class_1, class_2, NULL); - } - - SLV2Plugin me; -}; - -struct Instance { - inline Instance(Plugin plugin, double sample_rate) { - // TODO: features - me = slv2_plugin_instantiate(plugin, sample_rate, NULL); - } - - SLV2_WRAP_CONVERSION(SLV2Instance); - - SLV2_WRAP2_VOID(instance, connect_port, - unsigned, port_index, - void*, data_location); - - SLV2_WRAP0_VOID(instance, activate); - SLV2_WRAP1_VOID(instance, run, unsigned, sample_count); - SLV2_WRAP0_VOID(instance, deactivate); - - // TODO: get_extension_data - - inline const LV2_Descriptor* get_descriptor() { - return slv2_instance_get_descriptor(me); - } - - SLV2Instance me; -}; - -} /* namespace SLV2 */ - -#endif /* SLV2_SLV2MM_HPP */ 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 -#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 + + 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 +#include +#include +#include + +#ifdef __WIN32__ +#include +#define dlopen(path, flags) LoadLibrary(path) +#define dlclose(lib) FreeLibrary(lib) +#define dlsym GetProcAddress +static inline char* dlerror(void) { return "Unknown error"; } +#else +#include +#endif + +#include + +#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 #include -#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); // ?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) { // 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) { // 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 #include -#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 #include -#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 #include -#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); diff --git a/src/port.c b/src/port.c index 8937fa9..6be5d7e 100644 --- a/src/port.c +++ b/src/port.c @@ -22,286 +22,286 @@ #include #include -#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 #include -#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 - - 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 -#include -#include -#include - -#ifdef __WIN32__ -#include -#define dlopen(path, flags) LoadLibrary(path) -#define dlclose(lib) FreeLibrary(lib) -#define dlsym GetProcAddress -static inline char* dlerror(void) { return "Unknown error"; } -#else -#include -#endif - -#include - -#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 */ diff --git a/src/util.c b/src/util.c index c3cd23c..a1689a4 100644 --- a/src/util.c +++ b/src/util.c @@ -21,10 +21,10 @@ #include #include -#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 -#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 #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; } diff --git a/swig/lilv.i b/swig/lilv.i new file mode 100644 index 0000000..c3943dd --- /dev/null +++ b/swig/lilv.i @@ -0,0 +1,48 @@ +%module lilv +%{ +#include "lilv/lilv.h" +#include "lilv/lilvmm.hpp" +%} + +%include "lilv/lilv.h" +%include "lilv/lilvmm.hpp" + +namespace Lilv { + +%extend Plugins { +%pythoncode %{ + def __iter__(self): + class Iterator(object): + def __init__(self, plugins): + self.plugins = plugins + self.index = 0 + + def __iter__(self): + return self + + def next(self): + self.index += 1 + if self.index < lilv_plugins_size(self.plugins.me): + return Plugin(lilv_plugins_get_at(self.plugins.me, self.index)) + else: + raise StopIteration + + return Iterator(self) +%} +}; + +%extend Value { +%pythoncode %{ + def __str__(self): + return lilv_value_get_turtle_token(self.me) +%} +}; + +%extend World { +%pythoncode %{ + def get_plugin(self, uri_str): + return Plugin(lilv_world_get_plugin_by_uri_string(self.me, uri_str)) +%} +}; + +} /* namespace Lilv */ diff --git a/swig/slv2.i b/swig/slv2.i deleted file mode 100644 index bff9f70..0000000 --- a/swig/slv2.i +++ /dev/null @@ -1,48 +0,0 @@ -%module slv2 -%{ -#include "slv2/slv2.h" -#include "slv2/slv2mm.hpp" -%} - -%include "slv2/slv2.h" -%include "slv2/slv2mm.hpp" - -namespace SLV2 { - -%extend Plugins { -%pythoncode %{ - def __iter__(self): - class Iterator(object): - def __init__(self, plugins): - self.plugins = plugins - self.index = 0 - - def __iter__(self): - return self - - def next(self): - self.index += 1 - if self.index < slv2_plugins_size(self.plugins.me): - return Plugin(slv2_plugins_get_at(self.plugins.me, self.index)) - else: - raise StopIteration - - return Iterator(self) -%} -}; - -%extend Value { -%pythoncode %{ - def __str__(self): - return slv2_value_get_turtle_token(self.me) -%} -}; - -%extend World { -%pythoncode %{ - def get_plugin(self, uri_str): - return Plugin(slv2_world_get_plugin_by_uri_string(self.me, uri_str)) -%} -}; - -} /* namespace SLV2 */ diff --git a/test/lilv_test.c b/test/lilv_test.c new file mode 100644 index 0000000..3c1396a --- /dev/null +++ b/test/lilv_test.c @@ -0,0 +1,970 @@ +/* Lilv Tests + * Copyright 2008-2011 David Robillard + * Copyright 2008 Krzysztof Foltman + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "lilv/lilv.h" + +#define TEST_PATH_MAX 1024 + +static char bundle_dir_name[TEST_PATH_MAX]; +static char bundle_dir_uri[TEST_PATH_MAX]; +static char manifest_name[TEST_PATH_MAX]; +static char content_name[TEST_PATH_MAX]; + +static LilvWorld world; + +int test_count = 0; +int error_count = 0; + +void +delete_bundle() +{ + unlink(content_name); + unlink(manifest_name); + rmdir(bundle_dir_name); +} + +void +init_tests() +{ + strncpy(bundle_dir_name, getenv("HOME"), 900); + strcat(bundle_dir_name, "/.lv2/lilv-test.lv2"); + sprintf(bundle_dir_uri, "file://%s/", bundle_dir_name); + sprintf(manifest_name, "%s/manifest.ttl", bundle_dir_name); + sprintf(content_name, "%s/plugin.ttl", bundle_dir_name); + + delete_bundle(); +} + +void +fatal_error(const char *err, const char *arg) +{ + /* TODO: possibly change to vfprintf later */ + fprintf(stderr, err, arg); + /* IMHO, the bundle should be left in place after an error, for possible investigation */ + /* delete_bundle(); */ + exit(1); +} + +void +write_file(const char *name, const char *content) +{ + FILE* f = fopen(name, "w"); + size_t len = strlen(content); + if (fwrite(content, 1, len, f) != len) + fatal_error("Cannot write file %s\n", name); + fclose(f); +} + +int +init_world() +{ + world = lilv_world_new(); + return world != NULL; +} + +int +load_all_bundles() +{ + if (!init_world()) + return 0; + lilv_world_load_all(world); + return 1; +} + +void +create_bundle(char *manifest, char *content) +{ + if (mkdir(bundle_dir_name, 0700)) + fatal_error("Cannot create directory %s\n", bundle_dir_name); + write_file(manifest_name, manifest); + write_file(content_name, content); +} + +int +start_bundle(char *manifest, char *content) +{ + create_bundle(manifest, content); + return load_all_bundles(); +} + +void +unload_bundle() +{ + if (world) + lilv_world_free(world); + world = NULL; +} + +void +cleanup() +{ + delete_bundle(); +} + +/*****************************************************************************/ + +#define TEST_CASE(name) { #name, test_##name } +#define TEST_ASSERT(check) do {\ + test_count++;\ + if (!(check)) {\ + error_count++;\ + fprintf(stderr, "Failure at lilv_test.c:%d: %s\n", __LINE__, #check);\ + }\ +} while (0) + +typedef int (*TestFunc)(); + +struct TestCase { + const char *title; + TestFunc func; +}; + +#define PREFIX_LINE "@prefix : .\n" +#define PREFIX_LV2 "@prefix lv2: .\n" +#define PREFIX_LV2EV "@prefix lv2ev: . \n" +#define PREFIX_LV2UI "@prefix lv2ui: .\n" +#define PREFIX_RDF "@prefix rdf: .\n" +#define PREFIX_RDFS "@prefix rdfs: .\n" +#define PREFIX_FOAF "@prefix foaf: .\n" +#define PREFIX_DOAP "@prefix doap: .\n" + +#define MANIFEST_PREFIXES PREFIX_LINE PREFIX_LV2 PREFIX_RDFS +#define BUNDLE_PREFIXES PREFIX_LINE PREFIX_LV2 PREFIX_RDF PREFIX_RDFS PREFIX_FOAF PREFIX_DOAP +#define PLUGIN_NAME(name) "doap:name \"" name "\"" +#define LICENSE_GPL "doap:license " + +static char *uris_plugin = "http://example.org/plug"; +static LilvValue plugin_uri_value, plugin2_uri_value; + +/*****************************************************************************/ + +void +init_uris() +{ + plugin_uri_value = lilv_value_new_uri(world, uris_plugin); + plugin2_uri_value = lilv_value_new_uri(world, "http://example.org/foobar"); + TEST_ASSERT(plugin_uri_value); + TEST_ASSERT(plugin2_uri_value); +} + +void +cleanup_uris() +{ + lilv_value_free(plugin2_uri_value); + lilv_value_free(plugin_uri_value); + plugin2_uri_value = NULL; + plugin_uri_value = NULL; +} + +/*****************************************************************************/ + +int +test_utils() +{ + TEST_ASSERT(!strcmp(lilv_uri_to_path("file:///tmp/blah"), "/tmp/blah")); + TEST_ASSERT(!lilv_uri_to_path("file:/example.org/blah")); + TEST_ASSERT(!lilv_uri_to_path("http://example.org/blah")); + return 1; +} + +/*****************************************************************************/ + +int +test_value() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES + ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "lv2:port [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; " + "] .")) + return 0; + + init_uris(); + + LilvValue uval = lilv_value_new_uri(world, "http://example.org"); + LilvValue sval = lilv_value_new_string(world, "Foo"); + LilvValue ival = lilv_value_new_int(world, 42); + LilvValue fval = lilv_value_new_float(world, 1.6180); + + TEST_ASSERT(lilv_value_is_uri(uval)); + TEST_ASSERT(lilv_value_is_string(sval)); + TEST_ASSERT(lilv_value_is_int(ival)); + TEST_ASSERT(lilv_value_is_float(fval)); + + TEST_ASSERT(!lilv_value_is_literal(uval)); + TEST_ASSERT(lilv_value_is_literal(sval)); + TEST_ASSERT(lilv_value_is_literal(ival)); + TEST_ASSERT(lilv_value_is_literal(fval)); + + TEST_ASSERT(!strcmp(lilv_value_as_uri(uval), "http://example.org")); + TEST_ASSERT(!strcmp(lilv_value_as_string(sval), "Foo")); + TEST_ASSERT(lilv_value_as_int(ival) == 42); + TEST_ASSERT(fabs(lilv_value_as_float(fval) - 1.6180) < FLT_EPSILON); + + char* tok = lilv_value_get_turtle_token(uval); + TEST_ASSERT(!strcmp(tok, "")); + free(tok); + tok = lilv_value_get_turtle_token(sval); + TEST_ASSERT(!strcmp(tok, "Foo")); + free(tok); + tok = lilv_value_get_turtle_token(ival); + TEST_ASSERT(!strcmp(tok, "42")); + free(tok); + tok = lilv_value_get_turtle_token(fval); + TEST_ASSERT(!strncmp(tok, "1.6180", 6)); + free(tok); + + LilvValue uval_e = lilv_value_new_uri(world, "http://example.org"); + LilvValue sval_e = lilv_value_new_string(world, "Foo"); + LilvValue ival_e = lilv_value_new_int(world, 42); + LilvValue fval_e = lilv_value_new_float(world, 1.6180); + LilvValue uval_ne = lilv_value_new_uri(world, "http://no-example.org"); + LilvValue sval_ne = lilv_value_new_string(world, "Bar"); + LilvValue ival_ne = lilv_value_new_int(world, 24); + LilvValue fval_ne = lilv_value_new_float(world, 3.14159); + + TEST_ASSERT(lilv_value_equals(uval, uval_e)); + TEST_ASSERT(lilv_value_equals(sval, sval_e)); + TEST_ASSERT(lilv_value_equals(ival, ival_e)); + TEST_ASSERT(lilv_value_equals(fval, fval_e)); + + TEST_ASSERT(!lilv_value_equals(uval, uval_ne)); + TEST_ASSERT(!lilv_value_equals(sval, sval_ne)); + TEST_ASSERT(!lilv_value_equals(ival, ival_ne)); + TEST_ASSERT(!lilv_value_equals(fval, fval_ne)); + + TEST_ASSERT(!lilv_value_equals(uval, sval)); + TEST_ASSERT(!lilv_value_equals(sval, ival)); + TEST_ASSERT(!lilv_value_equals(ival, fval)); + + LilvValue uval_dup = lilv_value_duplicate(uval); + TEST_ASSERT(lilv_value_equals(uval, uval_dup)); + + LilvValue ifval = lilv_value_new_float(world, 42.0); + TEST_ASSERT(!lilv_value_equals(ival, ifval)); + lilv_value_free(ifval); + + LilvValue nil = NULL; + TEST_ASSERT(!lilv_value_equals(uval, nil)); + TEST_ASSERT(!lilv_value_equals(nil, uval)); + TEST_ASSERT(lilv_value_equals(nil, nil)); + + LilvValue nil2 = lilv_value_duplicate(nil); + TEST_ASSERT(lilv_value_equals(nil, nil2)); + + lilv_value_free(uval); + lilv_value_free(sval); + lilv_value_free(ival); + lilv_value_free(fval); + lilv_value_free(uval_e); + lilv_value_free(sval_e); + lilv_value_free(ival_e); + lilv_value_free(fval_e); + lilv_value_free(uval_ne); + lilv_value_free(sval_ne); + lilv_value_free(ival_ne); + lilv_value_free(fval_ne); + lilv_value_free(uval_dup); + lilv_value_free(nil2); + + cleanup_uris(); + return 1; +} + +/*****************************************************************************/ + +static int discovery_plugin_found = 0; + +static void +discovery_verify_plugin(LilvPlugin plugin) +{ + LilvValue value = lilv_plugin_get_uri(plugin); + if (lilv_value_equals(value, plugin_uri_value)) { + LilvValue lib_uri = NULL; + TEST_ASSERT(!lilv_value_equals(value, plugin2_uri_value)); + discovery_plugin_found = 1; + lib_uri = lilv_plugin_get_library_uri(plugin); + TEST_ASSERT(lib_uri); + TEST_ASSERT(lilv_value_is_uri(lib_uri)); + TEST_ASSERT(lilv_value_as_uri(lib_uri)); + TEST_ASSERT(strstr(lilv_value_as_uri(lib_uri), "foo.so")); + TEST_ASSERT(lilv_plugin_verify(plugin)); + } +} + +int +test_discovery() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES + ":plug a lv2:Plugin ;" + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "lv2:port [ a lv2:ControlPort ; a lv2:InputPort ;" + " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; ] .")) + return 0; + + init_uris(); + + LilvPlugins plugins = lilv_world_get_all_plugins(world); + TEST_ASSERT(lilv_plugins_size(plugins) > 0); + + LilvPlugin explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); + TEST_ASSERT(explug != NULL); + LilvPlugin explug2 = lilv_plugins_get_by_uri(plugins, plugin2_uri_value); + TEST_ASSERT(explug2 == NULL); + + if (explug) { + LilvValue name = lilv_plugin_get_name(explug); + TEST_ASSERT(!strcmp(lilv_value_as_string(name), "Test plugin")); + lilv_value_free(name); + } + + discovery_plugin_found = 0; + LILV_FOREACH(plugins, i, plugins) + discovery_verify_plugin(lilv_plugins_get(plugins, i)); + + TEST_ASSERT(discovery_plugin_found); + plugins = NULL; + + cleanup_uris(); + + return 1; +} + +/*****************************************************************************/ + +int +test_verify() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES + ":plug a lv2:Plugin ; " + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "lv2:port [ a lv2:ControlPort ; a lv2:InputPort ;" + " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ] .")) + return 0; + + init_uris(); + LilvPlugins plugins = lilv_world_get_all_plugins(world); + LilvPlugin explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); + TEST_ASSERT(explug); + TEST_ASSERT(lilv_plugin_verify(explug)); + cleanup_uris(); + return 1; +} + +/*****************************************************************************/ + +int +test_no_verify() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES + ":plug a lv2:Plugin . ")) + return 0; + + init_uris(); + LilvPlugins plugins = lilv_world_get_all_plugins(world); + LilvPlugin explug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); + TEST_ASSERT(explug); + TEST_ASSERT(!lilv_plugin_verify(explug)); + cleanup_uris(); + return 1; +} + +/*****************************************************************************/ + +int +test_classes() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES + ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "lv2:port [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; " + "] .")) + return 0; + + init_uris(); + LilvPluginClass plugin = lilv_world_get_plugin_class(world); + LilvPluginClasses classes = lilv_world_get_plugin_classes(world); + LilvPluginClasses children = lilv_plugin_class_get_children(plugin); + + TEST_ASSERT(lilv_plugin_class_get_parent_uri(plugin) == NULL); + TEST_ASSERT(lilv_plugin_classes_size(classes) > lilv_plugin_classes_size(children)); + TEST_ASSERT(!strcmp(lilv_value_as_string(lilv_plugin_class_get_label(plugin)), "Plugin")); + TEST_ASSERT(!strcmp(lilv_value_as_string(lilv_plugin_class_get_uri(plugin)), + "http://lv2plug.in/ns/lv2core#Plugin")); + + LILV_FOREACH(plugin_classes, i, children) { + TEST_ASSERT(lilv_value_equals( + lilv_plugin_class_get_parent_uri(lilv_plugin_classes_get(children, i)), + lilv_plugin_class_get_uri(plugin))); + } + + LilvValue some_uri = lilv_value_new_uri(world, "http://example.org/whatever"); + TEST_ASSERT(lilv_plugin_classes_get_by_uri(classes, some_uri) == NULL); + lilv_value_free(some_uri); + + lilv_plugin_classes_free(children); + + cleanup_uris(); + return 1; +} + +/*****************************************************************************/ + +int +test_plugin() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES + ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "lv2:optionalFeature lv2:hardRTCapable ; " + "lv2:requiredFeature ; " + ":foo 1.6180 ; " + ":bar true ; " + ":baz false ; " + "doap:maintainer [ foaf:name \"David Robillard\" ; " + " foaf:homepage ; foaf:mbox ] ; " + "lv2:port [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; " + " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 " + "] , [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; " + " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 " + "] , [ " + " a lv2:ControlPort ; a lv2:OutputPort ; " + " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; " + " lv2:portProperty lv2:reportsLatency " + "] . \n" + ":thing doap:name \"Something else\" .\n")) + return 0; + + init_uris(); + LilvPlugins plugins = lilv_world_get_all_plugins(world); + LilvPlugin plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); + TEST_ASSERT(plug); + + LilvPluginClass class = lilv_plugin_get_class(plug); + LilvValue class_uri = lilv_plugin_class_get_uri(class); + TEST_ASSERT(!strcmp(lilv_value_as_string(class_uri), + "http://lv2plug.in/ns/lv2core#CompressorPlugin")); + + LilvValue plug_bundle_uri = lilv_plugin_get_bundle_uri(plug); + TEST_ASSERT(!strcmp(lilv_value_as_string(plug_bundle_uri), bundle_dir_uri)); + + LilvValues data_uris = lilv_plugin_get_data_uris(plug); + TEST_ASSERT(lilv_values_size(data_uris) == 2); + + char* manifest_uri = (char*)malloc(TEST_PATH_MAX); + char* data_uri = (char*)malloc(TEST_PATH_MAX); + snprintf(manifest_uri, TEST_PATH_MAX, "%s%s", + lilv_value_as_string(plug_bundle_uri), "manifest.ttl"); + snprintf(data_uri, TEST_PATH_MAX, "%s%s", + lilv_value_as_string(plug_bundle_uri), "plugin.ttl"); + + LilvValue manifest_uri_val = lilv_value_new_uri(world, manifest_uri); + TEST_ASSERT(lilv_values_contains(data_uris, manifest_uri_val)); + lilv_value_free(manifest_uri_val); + + LilvValue data_uri_val = lilv_value_new_uri(world, data_uri); + TEST_ASSERT(lilv_values_contains(data_uris, data_uri_val)); + lilv_value_free(data_uri_val); + + free(manifest_uri); + free(data_uri); + + float mins[1]; + float maxs[1]; + float defs[1]; + lilv_plugin_get_port_ranges_float(plug, mins, maxs, defs); + TEST_ASSERT(mins[0] == -1.0f); + TEST_ASSERT(maxs[0] == 1.0f); + TEST_ASSERT(defs[0] == 0.5f); + + LilvValue audio_class = lilv_value_new_uri(world, + "http://lv2plug.in/ns/lv2core#AudioPort"); + LilvValue control_class = lilv_value_new_uri(world, + "http://lv2plug.in/ns/lv2core#ControlPort"); + LilvValue in_class = lilv_value_new_uri(world, + "http://lv2plug.in/ns/lv2core#InputPort"); + LilvValue out_class = lilv_value_new_uri(world, + "http://lv2plug.in/ns/lv2core#OutputPort"); + + TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, NULL) == 3); + TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, NULL) == 0); + TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, in_class, NULL) == 2); + TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, out_class, NULL) == 1); + TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, in_class, NULL) == 2); + TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, control_class, out_class, NULL) == 1); + TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, in_class, NULL) == 0); + TEST_ASSERT(lilv_plugin_get_num_ports_of_class(plug, audio_class, out_class, NULL) == 0); + + TEST_ASSERT(lilv_plugin_has_latency(plug)); + TEST_ASSERT(lilv_plugin_get_latency_port_index(plug) == 2); + + LilvValue rt_feature = lilv_value_new_uri(world, + "http://lv2plug.in/ns/lv2core#hardRTCapable"); + LilvValue event_feature = lilv_value_new_uri(world, + "http://lv2plug.in/ns/ext/event"); + LilvValue pretend_feature = lilv_value_new_uri(world, + "http://example.org/solvesWorldHunger"); + + TEST_ASSERT(lilv_plugin_has_feature(plug, rt_feature)); + TEST_ASSERT(lilv_plugin_has_feature(plug, event_feature)); + TEST_ASSERT(!lilv_plugin_has_feature(plug, pretend_feature)); + + lilv_value_free(rt_feature); + lilv_value_free(event_feature); + lilv_value_free(pretend_feature); + + LilvValues supported = lilv_plugin_get_supported_features(plug); + LilvValues required = lilv_plugin_get_required_features(plug); + LilvValues optional = lilv_plugin_get_optional_features(plug); + TEST_ASSERT(lilv_values_size(supported) == 2); + TEST_ASSERT(lilv_values_size(required) == 1); + TEST_ASSERT(lilv_values_size(optional) == 1); + lilv_values_free(supported); + lilv_values_free(required); + lilv_values_free(optional); + + LilvValue foo_p = lilv_value_new_uri(world, "http://example.org/foo"); + LilvValues foos = lilv_plugin_get_value(plug, foo_p); + TEST_ASSERT(lilv_values_size(foos) == 1); + TEST_ASSERT(fabs(lilv_value_as_float(lilv_values_get_first(foos)) - 1.6180) < FLT_EPSILON); + lilv_value_free(foo_p); + lilv_values_free(foos); + + LilvValue bar_p = lilv_value_new_uri(world, "http://example.org/bar"); + LilvValues bars = lilv_plugin_get_value(plug, bar_p); + TEST_ASSERT(lilv_values_size(bars) == 1); + TEST_ASSERT(lilv_value_as_bool(lilv_values_get_first(bars)) == true); + lilv_value_free(bar_p); + lilv_values_free(bars); + + LilvValue baz_p = lilv_value_new_uri(world, "http://example.org/baz"); + LilvValues bazs = lilv_plugin_get_value(plug, baz_p); + TEST_ASSERT(lilv_values_size(bazs) == 1); + TEST_ASSERT(lilv_value_as_bool(lilv_values_get_first(bazs)) == false); + lilv_value_free(baz_p); + lilv_values_free(bazs); + + LilvValue author_name = lilv_plugin_get_author_name(plug); + TEST_ASSERT(!strcmp(lilv_value_as_string(author_name), "David Robillard")); + lilv_value_free(author_name); + + LilvValue author_email = lilv_plugin_get_author_email(plug); + TEST_ASSERT(!strcmp(lilv_value_as_string(author_email), "mailto:d@drobilla.net")); + lilv_value_free(author_email); + + LilvValue author_homepage = lilv_plugin_get_author_homepage(plug); + TEST_ASSERT(!strcmp(lilv_value_as_string(author_homepage), "http://drobilla.net")); + lilv_value_free(author_homepage); + + LilvValue thing_uri = lilv_value_new_uri(world, "http://example.org/thing"); + LilvValue name_p = lilv_value_new_uri(world, "http://usefulinc.com/ns/doap#name"); + LilvValues thing_names = lilv_plugin_get_value_for_subject(plug, thing_uri, name_p); + TEST_ASSERT(lilv_values_size(thing_names) == 1); + LilvValue thing_name = lilv_values_get_first(thing_names); + TEST_ASSERT(thing_name); + TEST_ASSERT(lilv_value_is_string(thing_name)); + TEST_ASSERT(!strcmp(lilv_value_as_string(thing_name), "Something else")); + + LilvUIs uis = lilv_plugin_get_uis(plug); + TEST_ASSERT(lilv_uis_size(uis) == 0); + lilv_uis_free(uis); + + lilv_values_free(thing_names); + lilv_value_free(thing_uri); + lilv_value_free(name_p); + lilv_value_free(control_class); + lilv_value_free(audio_class); + lilv_value_free(in_class); + lilv_value_free(out_class); + cleanup_uris(); + return 1; +} + +/*****************************************************************************/ + +int +test_port() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES PREFIX_LV2EV + ":plug a lv2:Plugin ; " + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "doap:homepage ; " + "lv2:port [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 0 ; lv2:symbol \"foo\" ; " + " lv2:name \"store\" ; " + " lv2:name \"dépanneur\"@fr-ca ; lv2:name \"épicerie\"@fr-fr ; " + " lv2:name \"tienda\"@es ; " + " lv2:portProperty lv2:integer ; " + " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 ; " + " lv2:scalePoint [ rdfs:label \"Sin\"; rdf:value 3 ] ; " + " lv2:scalePoint [ rdfs:label \"Cos\"; rdf:value 4 ] " + "] , [\n" + " a lv2:EventPort ; a lv2:InputPort ; " + " lv2:index 1 ; lv2:symbol \"event_in\" ; " + " lv2:name \"Event Input\" ; " + " lv2ev:supportsEvent " + "] .")) + return 0; + + init_uris(); + LilvPlugins plugins = lilv_world_get_all_plugins(world); + LilvPlugin plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); + TEST_ASSERT(plug); + + LilvValue psym = lilv_value_new_string(world, "foo"); + LilvPort p = lilv_plugin_get_port_by_index(plug, 0); + LilvPort p2 = lilv_plugin_get_port_by_symbol(plug, psym); + lilv_value_free(psym); + TEST_ASSERT(p != NULL); + TEST_ASSERT(p2 != NULL); + TEST_ASSERT(p == p2); + + LilvValue nopsym = lilv_value_new_string(world, "thisaintnoportfoo"); + LilvPort p3 = lilv_plugin_get_port_by_symbol(plug, nopsym); + TEST_ASSERT(p3 == NULL); + lilv_value_free(nopsym); + + LilvValue audio_class = lilv_value_new_uri(world, + "http://lv2plug.in/ns/lv2core#AudioPort"); + LilvValue control_class = lilv_value_new_uri(world, + "http://lv2plug.in/ns/lv2core#ControlPort"); + LilvValue in_class = lilv_value_new_uri(world, + "http://lv2plug.in/ns/lv2core#InputPort"); + + TEST_ASSERT(lilv_values_size(lilv_port_get_classes(plug, p)) == 2); + TEST_ASSERT(lilv_plugin_get_num_ports(plug) == 2); + TEST_ASSERT(lilv_port_is_a(plug, p, control_class)); + TEST_ASSERT(lilv_port_is_a(plug, p, in_class)); + TEST_ASSERT(!lilv_port_is_a(plug, p, audio_class)); + + LilvValues port_properties = lilv_port_get_properties(plug, p); + TEST_ASSERT(lilv_values_size(port_properties) == 1); + lilv_values_free(port_properties); + + // Untranslated name (current locale is set to "C" in main) + TEST_ASSERT(!strcmp(lilv_value_as_string(lilv_port_get_symbol(plug, p)), "foo")); + LilvValue name = lilv_port_get_name(plug, p); + TEST_ASSERT(!strcmp(lilv_value_as_string(name), "store")); + lilv_value_free(name); + + // Exact language match + setenv("LANG", "fr_FR", 1); + name = lilv_port_get_name(plug, p); + TEST_ASSERT(!strcmp(lilv_value_as_string(name), "épicerie")); + lilv_value_free(name); + + // Exact language match (with charset suffix) + setenv("LANG", "fr_CA.utf8", 1); + name = lilv_port_get_name(plug, p); + TEST_ASSERT(!strcmp(lilv_value_as_string(name), "dépanneur")); + lilv_value_free(name); + + // Partial language match (choose value translated for different country) + setenv("LANG", "fr_BE", 1); + name = lilv_port_get_name(plug, p); + TEST_ASSERT((!strcmp(lilv_value_as_string(name), "dépanneur")) + ||(!strcmp(lilv_value_as_string(name), "épicerie"))); + lilv_value_free(name); + + // Partial language match (choose country-less language tagged value) + setenv("LANG", "es_MX", 1); + name = lilv_port_get_name(plug, p); + TEST_ASSERT(!strcmp(lilv_value_as_string(name), "tienda")); + lilv_value_free(name); + + setenv("LANG", "C", 1); // Reset locale + + LilvScalePoints points = lilv_port_get_scale_points(plug, p); + TEST_ASSERT(lilv_scale_points_size(points) == 2); + + LilvIter sp_iter = lilv_scale_points_begin(points); + LilvScalePoint sp0 = lilv_scale_points_get(points, sp_iter); + TEST_ASSERT(sp0); + lilv_scale_points_next(points, sp_iter); + LilvScalePoint sp1 = lilv_scale_points_get(points, sp_iter); + TEST_ASSERT(sp1); + + TEST_ASSERT(!strcmp(lilv_value_as_string(lilv_scale_point_get_label(sp0)), "Sin")); + TEST_ASSERT(lilv_value_as_float(lilv_scale_point_get_value(sp0)) == 3); + TEST_ASSERT(!strcmp(lilv_value_as_string(lilv_scale_point_get_label(sp1)), "Cos")); + TEST_ASSERT(lilv_value_as_float(lilv_scale_point_get_value(sp1)) == 4); + + LilvValue homepage_p = lilv_value_new_uri(world, "http://usefulinc.com/ns/doap#homepage"); + LilvValues homepages = lilv_plugin_get_value(plug, homepage_p); + TEST_ASSERT(lilv_values_size(homepages) == 1); + TEST_ASSERT(!strcmp(lilv_value_as_string(lilv_values_get_first(homepages)), + "http://example.org/someplug")); + + LilvValue min, max, def; + lilv_port_get_range(plug, p, &def, &min, &max); + TEST_ASSERT(def); + TEST_ASSERT(min); + TEST_ASSERT(max); + TEST_ASSERT(lilv_value_as_float(def) == 0.5); + TEST_ASSERT(lilv_value_as_float(min) == -1.0); + TEST_ASSERT(lilv_value_as_float(max) == 1.0); + + LilvValue integer_prop = lilv_value_new_uri(world, "http://lv2plug.in/ns/lv2core#integer"); + LilvValue toggled_prop = lilv_value_new_uri(world, "http://lv2plug.in/ns/lv2core#toggled"); + + TEST_ASSERT(lilv_port_has_property(plug, p, integer_prop)); + TEST_ASSERT(!lilv_port_has_property(plug, p, toggled_prop)); + + LilvPort ep = lilv_plugin_get_port_by_index(plug, 1); + + LilvValue event_type = lilv_value_new_uri(world, "http://example.org/event"); + LilvValue event_type_2 = lilv_value_new_uri(world, "http://example.org/otherEvent"); + TEST_ASSERT(lilv_port_supports_event(plug, ep, event_type)); + TEST_ASSERT(!lilv_port_supports_event(plug, ep, event_type_2)); + + LilvValue name_p = lilv_value_new_uri(world, "http://lv2plug.in/ns/lv2core#name"); + LilvValues names = lilv_port_get_value(plug, p, name_p); + TEST_ASSERT(lilv_values_size(names) == 1); + TEST_ASSERT(!strcmp(lilv_value_as_string(lilv_values_get_first(names)), + "store")); + lilv_values_free(names); + + LilvValue true_val = lilv_value_new_bool(world, true); + LilvValue false_val = lilv_value_new_bool(world, false); + + lilv_world_set_option(world, LILV_OPTION_FILTER_LANG, false_val); + names = lilv_port_get_value(plug, p, name_p); + TEST_ASSERT(lilv_values_size(names) == 4); + lilv_values_free(names); + lilv_world_set_option(world, LILV_OPTION_FILTER_LANG, true_val); + + lilv_value_free(false_val); + lilv_value_free(true_val); + + names = lilv_port_get_value(plug, ep, name_p); + TEST_ASSERT(lilv_values_size(names) == 1); + TEST_ASSERT(!strcmp(lilv_value_as_string(lilv_values_get_first(names)), + "Event Input")); + lilv_values_free(names); + lilv_value_free(name_p); + + lilv_value_free(integer_prop); + lilv_value_free(toggled_prop); + lilv_value_free(event_type); + lilv_value_free(event_type_2); + + lilv_value_free(min); + lilv_value_free(max); + lilv_value_free(def); + + lilv_value_free(homepage_p); + lilv_values_free(homepages); + + lilv_scale_points_free(points); + lilv_value_free(control_class); + lilv_value_free(audio_class); + lilv_value_free(in_class); + cleanup_uris(); + return 1; +} + +/*****************************************************************************/ + +int +test_ui() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES PREFIX_LV2UI + ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "lv2:optionalFeature lv2:hardRTCapable ; " + "lv2:requiredFeature ; " + "lv2ui:ui :ui , :ui2 , :ui3 , :ui4 ; " + "doap:maintainer [ foaf:name \"David Robillard\" ; " + " foaf:homepage ; foaf:mbox ] ; " + "lv2:port [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; " + " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 " + "] , [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; " + " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 " + "] , [ " + " a lv2:ControlPort ; a lv2:OutputPort ; " + " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; " + " lv2:portProperty lv2:reportsLatency " + "] .\n" + ":ui a lv2ui:GtkUI ; " + " lv2ui:requiredFeature lv2ui:makeResident ; " + " lv2ui:binary ; " + " lv2ui:optionalFeature lv2ui:ext_presets . " + ":ui2 a lv2ui:GtkUI ; lv2ui:binary . " + ":ui3 a lv2ui:GtkUI ; lv2ui:binary . " + ":ui4 a lv2ui:GtkUI ; lv2ui:binary . ")) + return 0; + + init_uris(); + LilvPlugins plugins = lilv_world_get_all_plugins(world); + LilvPlugin plug = lilv_plugins_get_by_uri(plugins, plugin_uri_value); + TEST_ASSERT(plug); + + LilvUIs uis = lilv_plugin_get_uis(plug); + TEST_ASSERT(lilv_uis_size(uis) == 4); + + LilvUI ui0 = lilv_uis_get(uis, lilv_uis_begin(uis)); + TEST_ASSERT(ui0); + + LilvValue ui_uri = lilv_value_new_uri(world, "http://example.org/ui"); + LilvValue ui2_uri = lilv_value_new_uri(world, "http://example.org/ui3"); + LilvValue ui3_uri = lilv_value_new_uri(world, "http://example.org/ui4"); + LilvValue noui_uri = lilv_value_new_uri(world, "http://example.org/notaui"); + + LilvUI ui0_2 = lilv_uis_get_by_uri(uis, ui_uri); + TEST_ASSERT(ui0 == ui0_2); + + LilvUI ui2 = lilv_uis_get_by_uri(uis, ui2_uri); + TEST_ASSERT(ui2 != ui0); + + LilvUI ui3 = lilv_uis_get_by_uri(uis, ui3_uri); + TEST_ASSERT(ui3 != ui0); + + LilvUI noui = lilv_uis_get_by_uri(uis, noui_uri); + TEST_ASSERT(noui == NULL); + + LilvValues classes = lilv_ui_get_classes(ui0); + TEST_ASSERT(lilv_values_size(classes) == 1); + + LilvValue ui_class_uri = lilv_value_new_uri(world, + "http://lv2plug.in/ns/extensions/ui#GtkUI"); + + TEST_ASSERT(lilv_value_equals(lilv_values_get_first(classes), ui_class_uri)); + TEST_ASSERT(lilv_ui_is_a(ui0, ui_class_uri)); + + LilvValue plug_bundle_uri = lilv_plugin_get_bundle_uri(plug); + LilvValue ui_bundle_uri = lilv_ui_get_bundle_uri(ui0); + TEST_ASSERT(lilv_value_equals(plug_bundle_uri, ui_bundle_uri)); + + char* ui_binary_uri_str = (char*)malloc(TEST_PATH_MAX); + snprintf(ui_binary_uri_str, TEST_PATH_MAX, "%s%s", + lilv_value_as_string(plug_bundle_uri), "ui.so"); + + LilvValue ui_binary_uri = lilv_ui_get_binary_uri(ui0); + + LilvValue expected_uri = lilv_value_new_uri(world, ui_binary_uri_str); + TEST_ASSERT(lilv_value_equals(expected_uri, ui_binary_uri)); + + free(ui_binary_uri_str); + lilv_value_free(ui_class_uri); + lilv_value_free(ui_uri); + lilv_value_free(ui2_uri); + lilv_value_free(ui3_uri); + lilv_value_free(noui_uri); + lilv_value_free(expected_uri); + lilv_uis_free(uis); + + cleanup_uris(); + return 1; +} + +/*****************************************************************************/ + +/* add tests here */ +static struct TestCase tests[] = { + TEST_CASE(utils), + TEST_CASE(value), + TEST_CASE(verify), + TEST_CASE(no_verify), + TEST_CASE(discovery), + TEST_CASE(classes), + TEST_CASE(plugin), + TEST_CASE(port), + TEST_CASE(ui), + { NULL, NULL } +}; + +void +run_tests() +{ + int i; + for (i = 0; tests[i].title; i++) { + printf("*** Test %s\n", tests[i].title); + if (!tests[i].func()) { + printf("\nTest failed\n"); + /* test case that wasn't able to be executed at all counts as 1 test + 1 error */ + error_count++; + test_count++; + } + unload_bundle(); + cleanup(); + } +} + +int +main(int argc, char *argv[]) +{ + if (argc != 1) { + printf("Syntax: %s\n", argv[0]); + return 0; + } + setenv("LANG", "C", 1); + init_tests(); + run_tests(); + cleanup(); + printf("\n*** Test Results: %d tests, %d errors\n\n", test_count, error_count); + return error_count ? 1 : 0; +} diff --git a/test/slv2_test.c b/test/slv2_test.c deleted file mode 100644 index 0c2ad2e..0000000 --- a/test/slv2_test.c +++ /dev/null @@ -1,976 +0,0 @@ -/* SLV2 Tests - * Copyright 2008-2011 David Robillard - * Copyright 2008 Krzysztof Foltman - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#define _XOPEN_SOURCE 600 - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "slv2/slv2.h" - -#define TEST_PATH_MAX 1024 - -static char bundle_dir_name[TEST_PATH_MAX]; -static char bundle_dir_uri[TEST_PATH_MAX]; -static char manifest_name[TEST_PATH_MAX]; -static char content_name[TEST_PATH_MAX]; - -static SLV2World world; - -int test_count = 0; -int error_count = 0; - -void -delete_bundle() -{ - unlink(content_name); - unlink(manifest_name); - rmdir(bundle_dir_name); -} - -void -init_tests() -{ - strncpy(bundle_dir_name, getenv("HOME"), 900); - strcat(bundle_dir_name, "/.lv2/slv2-test.lv2"); - sprintf(bundle_dir_uri, "file://%s/", bundle_dir_name); - sprintf(manifest_name, "%s/manifest.ttl", bundle_dir_name); - sprintf(content_name, "%s/plugin.ttl", bundle_dir_name); - - delete_bundle(); -} - -void -fatal_error(const char *err, const char *arg) -{ - /* TODO: possibly change to vfprintf later */ - fprintf(stderr, err, arg); - /* IMHO, the bundle should be left in place after an error, for possible investigation */ - /* delete_bundle(); */ - exit(1); -} - -void -write_file(const char *name, const char *content) -{ - FILE* f = fopen(name, "w"); - size_t len = strlen(content); - if (fwrite(content, 1, len, f) != len) - fatal_error("Cannot write file %s\n", name); - fclose(f); -} - -int -init_world() -{ - world = slv2_world_new(); - return world != NULL; -} - -int -load_all_bundles() -{ - if (!init_world()) - return 0; - slv2_world_load_all(world); - return 1; -} - -void -create_bundle(char *manifest, char *content) -{ - if (mkdir(bundle_dir_name, 0700)) - fatal_error("Cannot create directory %s\n", bundle_dir_name); - write_file(manifest_name, manifest); - write_file(content_name, content); -} - -int -start_bundle(char *manifest, char *content) -{ - create_bundle(manifest, content); - return load_all_bundles(); -} - -void -unload_bundle() -{ - if (world) - slv2_world_free(world); - world = NULL; -} - -void -cleanup() -{ - delete_bundle(); -} - -/*****************************************************************************/ - -#define TEST_CASE(name) { #name, test_##name } -#define TEST_ASSERT(check) do {\ - test_count++;\ - if (!(check)) {\ - error_count++;\ - fprintf(stderr, "Failure at slv2_test.c:%d: %s\n", __LINE__, #check);\ - }\ -} while (0) - -typedef int (*TestFunc)(); - -struct TestCase { - const char *title; - TestFunc func; -}; - -#define PREFIX_LINE "@prefix : .\n" -#define PREFIX_LV2 "@prefix lv2: .\n" -#define PREFIX_LV2EV "@prefix lv2ev: . \n" -#define PREFIX_LV2UI "@prefix lv2ui: .\n" -#define PREFIX_RDF "@prefix rdf: .\n" -#define PREFIX_RDFS "@prefix rdfs: .\n" -#define PREFIX_FOAF "@prefix foaf: .\n" -#define PREFIX_DOAP "@prefix doap: .\n" - -#define MANIFEST_PREFIXES PREFIX_LINE PREFIX_LV2 PREFIX_RDFS -#define BUNDLE_PREFIXES PREFIX_LINE PREFIX_LV2 PREFIX_RDF PREFIX_RDFS PREFIX_FOAF PREFIX_DOAP -#define PLUGIN_NAME(name) "doap:name \"" name "\"" -#define LICENSE_GPL "doap:license " - -static char *uris_plugin = "http://example.org/plug"; -static SLV2Value plugin_uri_value, plugin2_uri_value; - -/*****************************************************************************/ - -void -init_uris() -{ - plugin_uri_value = slv2_value_new_uri(world, uris_plugin); - plugin2_uri_value = slv2_value_new_uri(world, "http://example.org/foobar"); - TEST_ASSERT(plugin_uri_value); - TEST_ASSERT(plugin2_uri_value); -} - -void -cleanup_uris() -{ - slv2_value_free(plugin2_uri_value); - slv2_value_free(plugin_uri_value); - plugin2_uri_value = NULL; - plugin_uri_value = NULL; -} - -/*****************************************************************************/ - -int -test_utils() -{ - TEST_ASSERT(!strcmp(slv2_uri_to_path("file:///tmp/blah"), "/tmp/blah")); - TEST_ASSERT(!slv2_uri_to_path("file:/example.org/blah")); - TEST_ASSERT(!slv2_uri_to_path("http://example.org/blah")); - return 1; -} - -/*****************************************************************************/ - -int -test_value() -{ - if (!start_bundle(MANIFEST_PREFIXES - ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", - BUNDLE_PREFIXES - ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " - PLUGIN_NAME("Test plugin") " ; " - LICENSE_GPL " ; " - "lv2:port [ " - " a lv2:ControlPort ; a lv2:InputPort ; " - " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; " - "] .")) - return 0; - - init_uris(); - - SLV2Value uval = slv2_value_new_uri(world, "http://example.org"); - SLV2Value sval = slv2_value_new_string(world, "Foo"); - SLV2Value ival = slv2_value_new_int(world, 42); - SLV2Value fval = slv2_value_new_float(world, 1.6180); - - TEST_ASSERT(slv2_value_is_uri(uval)); - TEST_ASSERT(slv2_value_is_string(sval)); - TEST_ASSERT(slv2_value_is_int(ival)); - TEST_ASSERT(slv2_value_is_float(fval)); - - TEST_ASSERT(!slv2_value_is_literal(uval)); - TEST_ASSERT(slv2_value_is_literal(sval)); - TEST_ASSERT(slv2_value_is_literal(ival)); - TEST_ASSERT(slv2_value_is_literal(fval)); - - TEST_ASSERT(!strcmp(slv2_value_as_uri(uval), "http://example.org")); - TEST_ASSERT(!strcmp(slv2_value_as_string(sval), "Foo")); - TEST_ASSERT(slv2_value_as_int(ival) == 42); - TEST_ASSERT(fabs(slv2_value_as_float(fval) - 1.6180) < FLT_EPSILON); - - char* tok = slv2_value_get_turtle_token(uval); - TEST_ASSERT(!strcmp(tok, "")); - free(tok); - tok = slv2_value_get_turtle_token(sval); - TEST_ASSERT(!strcmp(tok, "Foo")); - free(tok); - tok = slv2_value_get_turtle_token(ival); - TEST_ASSERT(!strcmp(tok, "42")); - free(tok); - tok = slv2_value_get_turtle_token(fval); - TEST_ASSERT(!strncmp(tok, "1.6180", 6)); - free(tok); - - SLV2Value uval_e = slv2_value_new_uri(world, "http://example.org"); - SLV2Value sval_e = slv2_value_new_string(world, "Foo"); - SLV2Value ival_e = slv2_value_new_int(world, 42); - SLV2Value fval_e = slv2_value_new_float(world, 1.6180); - SLV2Value uval_ne = slv2_value_new_uri(world, "http://no-example.org"); - SLV2Value sval_ne = slv2_value_new_string(world, "Bar"); - SLV2Value ival_ne = slv2_value_new_int(world, 24); - SLV2Value fval_ne = slv2_value_new_float(world, 3.14159); - - TEST_ASSERT(slv2_value_equals(uval, uval_e)); - TEST_ASSERT(slv2_value_equals(sval, sval_e)); - TEST_ASSERT(slv2_value_equals(ival, ival_e)); - TEST_ASSERT(slv2_value_equals(fval, fval_e)); - - TEST_ASSERT(!slv2_value_equals(uval, uval_ne)); - TEST_ASSERT(!slv2_value_equals(sval, sval_ne)); - TEST_ASSERT(!slv2_value_equals(ival, ival_ne)); - TEST_ASSERT(!slv2_value_equals(fval, fval_ne)); - - TEST_ASSERT(!slv2_value_equals(uval, sval)); - TEST_ASSERT(!slv2_value_equals(sval, ival)); - TEST_ASSERT(!slv2_value_equals(ival, fval)); - - SLV2Value uval_dup = slv2_value_duplicate(uval); - TEST_ASSERT(slv2_value_equals(uval, uval_dup)); - - SLV2Value ifval = slv2_value_new_float(world, 42.0); - TEST_ASSERT(!slv2_value_equals(ival, ifval)); - slv2_value_free(ifval); - - SLV2Value nil = NULL; - TEST_ASSERT(!slv2_value_equals(uval, nil)); - TEST_ASSERT(!slv2_value_equals(nil, uval)); - TEST_ASSERT(slv2_value_equals(nil, nil)); - - SLV2Value nil2 = slv2_value_duplicate(nil); - TEST_ASSERT(slv2_value_equals(nil, nil2)); - - slv2_value_free(uval); - slv2_value_free(sval); - slv2_value_free(ival); - slv2_value_free(fval); - slv2_value_free(uval_e); - slv2_value_free(sval_e); - slv2_value_free(ival_e); - slv2_value_free(fval_e); - slv2_value_free(uval_ne); - slv2_value_free(sval_ne); - slv2_value_free(ival_ne); - slv2_value_free(fval_ne); - slv2_value_free(uval_dup); - slv2_value_free(nil2); - - cleanup_uris(); - return 1; -} - -/*****************************************************************************/ - -static int discovery_plugin_found = 0; - -static void -discovery_verify_plugin(SLV2Plugin plugin) -{ - SLV2Value value = slv2_plugin_get_uri(plugin); - if (slv2_value_equals(value, plugin_uri_value)) { - SLV2Value lib_uri = NULL; - TEST_ASSERT(!slv2_value_equals(value, plugin2_uri_value)); - discovery_plugin_found = 1; - lib_uri = slv2_plugin_get_library_uri(plugin); - TEST_ASSERT(lib_uri); - TEST_ASSERT(slv2_value_is_uri(lib_uri)); - TEST_ASSERT(slv2_value_as_uri(lib_uri)); - TEST_ASSERT(strstr(slv2_value_as_uri(lib_uri), "foo.so")); - TEST_ASSERT(slv2_plugin_verify(plugin)); - } -} - -int -test_discovery() -{ - if (!start_bundle(MANIFEST_PREFIXES - ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", - BUNDLE_PREFIXES - ":plug a lv2:Plugin ;" - PLUGIN_NAME("Test plugin") " ; " - LICENSE_GPL " ; " - "lv2:port [ a lv2:ControlPort ; a lv2:InputPort ;" - " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; ] .")) - return 0; - - init_uris(); - - SLV2Plugins plugins = slv2_world_get_all_plugins(world); - TEST_ASSERT(slv2_plugins_size(plugins) > 0); - - SLV2Plugin explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); - TEST_ASSERT(explug != NULL); - SLV2Plugin explug2 = slv2_plugins_get_by_uri(plugins, plugin2_uri_value); - TEST_ASSERT(explug2 == NULL); - - if (explug) { - SLV2Value name = slv2_plugin_get_name(explug); - TEST_ASSERT(!strcmp(slv2_value_as_string(name), "Test plugin")); - slv2_value_free(name); - } - - discovery_plugin_found = 0; - for (size_t i = 0; i < slv2_plugins_size(plugins); i++) - discovery_verify_plugin(slv2_plugins_get_at(plugins, i)); - - TEST_ASSERT(discovery_plugin_found); - plugins = NULL; - - TEST_ASSERT(slv2_plugins_get_at(plugins, (unsigned)INT_MAX + 1) == NULL); - - cleanup_uris(); - - return 1; -} - -/*****************************************************************************/ - -int -test_verify() -{ - if (!start_bundle(MANIFEST_PREFIXES - ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", - BUNDLE_PREFIXES - ":plug a lv2:Plugin ; " - PLUGIN_NAME("Test plugin") " ; " - LICENSE_GPL " ; " - "lv2:port [ a lv2:ControlPort ; a lv2:InputPort ;" - " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ] .")) - return 0; - - init_uris(); - SLV2Plugins plugins = slv2_world_get_all_plugins(world); - SLV2Plugin explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); - TEST_ASSERT(explug); - TEST_ASSERT(slv2_plugin_verify(explug)); - cleanup_uris(); - return 1; -} - -/*****************************************************************************/ - -int -test_no_verify() -{ - if (!start_bundle(MANIFEST_PREFIXES - ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", - BUNDLE_PREFIXES - ":plug a lv2:Plugin . ")) - return 0; - - init_uris(); - SLV2Plugins plugins = slv2_world_get_all_plugins(world); - SLV2Plugin explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); - TEST_ASSERT(explug); - TEST_ASSERT(!slv2_plugin_verify(explug)); - cleanup_uris(); - return 1; -} - -/*****************************************************************************/ - -int -test_classes() -{ - if (!start_bundle(MANIFEST_PREFIXES - ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", - BUNDLE_PREFIXES - ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " - PLUGIN_NAME("Test plugin") " ; " - LICENSE_GPL " ; " - "lv2:port [ " - " a lv2:ControlPort ; a lv2:InputPort ; " - " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"Foo\" ; " - "] .")) - return 0; - - init_uris(); - SLV2PluginClass plugin = slv2_world_get_plugin_class(world); - SLV2PluginClasses classes = slv2_world_get_plugin_classes(world); - SLV2PluginClasses children = slv2_plugin_class_get_children(plugin); - - TEST_ASSERT(slv2_plugin_class_get_parent_uri(plugin) == NULL); - TEST_ASSERT(slv2_plugin_classes_size(classes) > slv2_plugin_classes_size(children)); - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_plugin_class_get_label(plugin)), "Plugin")); - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_plugin_class_get_uri(plugin)), - "http://lv2plug.in/ns/lv2core#Plugin")); - - for (unsigned i = 0; i < slv2_plugin_classes_size(children); ++i) { - TEST_ASSERT(slv2_value_equals( - slv2_plugin_class_get_parent_uri(slv2_plugin_classes_get_at(children, i)), - slv2_plugin_class_get_uri(plugin))); - } - - SLV2Value some_uri = slv2_value_new_uri(world, "http://example.org/whatever"); - TEST_ASSERT(slv2_plugin_classes_get_by_uri(classes, some_uri) == NULL); - slv2_value_free(some_uri); - - TEST_ASSERT(slv2_plugin_classes_get_at(classes, (unsigned)INT_MAX + 1) == NULL); - - slv2_plugin_classes_free(children); - - cleanup_uris(); - return 1; -} - -/*****************************************************************************/ - -int -test_plugin() -{ - if (!start_bundle(MANIFEST_PREFIXES - ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", - BUNDLE_PREFIXES - ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " - PLUGIN_NAME("Test plugin") " ; " - LICENSE_GPL " ; " - "lv2:optionalFeature lv2:hardRTCapable ; " - "lv2:requiredFeature ; " - ":foo 1.6180 ; " - ":bar true ; " - ":baz false ; " - "doap:maintainer [ foaf:name \"David Robillard\" ; " - " foaf:homepage ; foaf:mbox ] ; " - "lv2:port [ " - " a lv2:ControlPort ; a lv2:InputPort ; " - " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; " - " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 " - "] , [ " - " a lv2:ControlPort ; a lv2:InputPort ; " - " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; " - " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 " - "] , [ " - " a lv2:ControlPort ; a lv2:OutputPort ; " - " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; " - " lv2:portProperty lv2:reportsLatency " - "] . \n" - ":thing doap:name \"Something else\" .\n")) - return 0; - - init_uris(); - SLV2Plugins plugins = slv2_world_get_all_plugins(world); - SLV2Plugin plug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); - TEST_ASSERT(plug); - - SLV2PluginClass class = slv2_plugin_get_class(plug); - SLV2Value class_uri = slv2_plugin_class_get_uri(class); - TEST_ASSERT(!strcmp(slv2_value_as_string(class_uri), - "http://lv2plug.in/ns/lv2core#CompressorPlugin")); - - SLV2Value plug_bundle_uri = slv2_plugin_get_bundle_uri(plug); - TEST_ASSERT(!strcmp(slv2_value_as_string(plug_bundle_uri), bundle_dir_uri)); - - SLV2Values data_uris = slv2_plugin_get_data_uris(plug); - TEST_ASSERT(slv2_values_size(data_uris) == 2); - - char* manifest_uri = (char*)malloc(TEST_PATH_MAX); - char* data_uri = (char*)malloc(TEST_PATH_MAX); - snprintf(manifest_uri, TEST_PATH_MAX, "%s%s", - slv2_value_as_string(plug_bundle_uri), "manifest.ttl"); - snprintf(data_uri, TEST_PATH_MAX, "%s%s", - slv2_value_as_string(plug_bundle_uri), "plugin.ttl"); - - SLV2Value manifest_uri_val = slv2_value_new_uri(world, manifest_uri); - TEST_ASSERT(slv2_values_contains(data_uris, manifest_uri_val)); - slv2_value_free(manifest_uri_val); - - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(data_uris, 0)), manifest_uri)); - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(data_uris, 1)), data_uri)); - - free(manifest_uri); - free(data_uri); - - float mins[1]; - float maxs[1]; - float defs[1]; - slv2_plugin_get_port_ranges_float(plug, mins, maxs, defs); - TEST_ASSERT(mins[0] == -1.0f); - TEST_ASSERT(maxs[0] == 1.0f); - TEST_ASSERT(defs[0] == 0.5f); - - SLV2Value audio_class = slv2_value_new_uri(world, - "http://lv2plug.in/ns/lv2core#AudioPort"); - SLV2Value control_class = slv2_value_new_uri(world, - "http://lv2plug.in/ns/lv2core#ControlPort"); - SLV2Value in_class = slv2_value_new_uri(world, - "http://lv2plug.in/ns/lv2core#InputPort"); - SLV2Value out_class = slv2_value_new_uri(world, - "http://lv2plug.in/ns/lv2core#OutputPort"); - - TEST_ASSERT(slv2_plugin_get_num_ports_of_class(plug, control_class, NULL) == 3); - TEST_ASSERT(slv2_plugin_get_num_ports_of_class(plug, audio_class, NULL) == 0); - TEST_ASSERT(slv2_plugin_get_num_ports_of_class(plug, in_class, NULL) == 2); - TEST_ASSERT(slv2_plugin_get_num_ports_of_class(plug, out_class, NULL) == 1); - TEST_ASSERT(slv2_plugin_get_num_ports_of_class(plug, control_class, in_class, NULL) == 2); - TEST_ASSERT(slv2_plugin_get_num_ports_of_class(plug, control_class, out_class, NULL) == 1); - TEST_ASSERT(slv2_plugin_get_num_ports_of_class(plug, audio_class, in_class, NULL) == 0); - TEST_ASSERT(slv2_plugin_get_num_ports_of_class(plug, audio_class, out_class, NULL) == 0); - - TEST_ASSERT(slv2_plugin_has_latency(plug)); - TEST_ASSERT(slv2_plugin_get_latency_port_index(plug) == 2); - - SLV2Value rt_feature = slv2_value_new_uri(world, - "http://lv2plug.in/ns/lv2core#hardRTCapable"); - SLV2Value event_feature = slv2_value_new_uri(world, - "http://lv2plug.in/ns/ext/event"); - SLV2Value pretend_feature = slv2_value_new_uri(world, - "http://example.org/solvesWorldHunger"); - - TEST_ASSERT(slv2_plugin_has_feature(plug, rt_feature)); - TEST_ASSERT(slv2_plugin_has_feature(plug, event_feature)); - TEST_ASSERT(!slv2_plugin_has_feature(plug, pretend_feature)); - - slv2_value_free(rt_feature); - slv2_value_free(event_feature); - slv2_value_free(pretend_feature); - - SLV2Values supported = slv2_plugin_get_supported_features(plug); - SLV2Values required = slv2_plugin_get_required_features(plug); - SLV2Values optional = slv2_plugin_get_optional_features(plug); - TEST_ASSERT(slv2_values_size(supported) == 2); - TEST_ASSERT(slv2_values_size(required) == 1); - TEST_ASSERT(slv2_values_size(optional) == 1); - slv2_values_free(supported); - slv2_values_free(required); - slv2_values_free(optional); - - SLV2Value foo_p = slv2_value_new_uri(world, "http://example.org/foo"); - SLV2Values foos = slv2_plugin_get_value(plug, foo_p); - TEST_ASSERT(slv2_values_size(foos) == 1); - TEST_ASSERT(fabs(slv2_value_as_float(slv2_values_get_at(foos, 0)) - 1.6180) < FLT_EPSILON); - slv2_value_free(foo_p); - slv2_values_free(foos); - - SLV2Value bar_p = slv2_value_new_uri(world, "http://example.org/bar"); - SLV2Values bars = slv2_plugin_get_value(plug, bar_p); - TEST_ASSERT(slv2_values_size(bars) == 1); - TEST_ASSERT(slv2_value_as_bool(slv2_values_get_at(bars, 0)) == true); - slv2_value_free(bar_p); - slv2_values_free(bars); - - SLV2Value baz_p = slv2_value_new_uri(world, "http://example.org/baz"); - SLV2Values bazs = slv2_plugin_get_value(plug, baz_p); - TEST_ASSERT(slv2_values_size(bazs) == 1); - TEST_ASSERT(slv2_value_as_bool(slv2_values_get_at(bazs, 0)) == false); - slv2_value_free(baz_p); - slv2_values_free(bazs); - - SLV2Value author_name = slv2_plugin_get_author_name(plug); - TEST_ASSERT(!strcmp(slv2_value_as_string(author_name), "David Robillard")); - slv2_value_free(author_name); - - SLV2Value author_email = slv2_plugin_get_author_email(plug); - TEST_ASSERT(!strcmp(slv2_value_as_string(author_email), "mailto:d@drobilla.net")); - slv2_value_free(author_email); - - SLV2Value author_homepage = slv2_plugin_get_author_homepage(plug); - TEST_ASSERT(!strcmp(slv2_value_as_string(author_homepage), "http://drobilla.net")); - slv2_value_free(author_homepage); - - SLV2Value thing_uri = slv2_value_new_uri(world, "http://example.org/thing"); - SLV2Value name_p = slv2_value_new_uri(world, "http://usefulinc.com/ns/doap#name"); - SLV2Values thing_names = slv2_plugin_get_value_for_subject(plug, thing_uri, name_p); - TEST_ASSERT(slv2_values_size(thing_names) == 1); - SLV2Value thing_name = slv2_values_get_at(thing_names, 0); - TEST_ASSERT(thing_name); - TEST_ASSERT(slv2_value_is_string(thing_name)); - TEST_ASSERT(!strcmp(slv2_value_as_string(thing_name), "Something else")); - - SLV2UIs uis = slv2_plugin_get_uis(plug); - TEST_ASSERT(slv2_uis_size(uis) == 0); - slv2_uis_free(uis); - - slv2_values_free(thing_names); - slv2_value_free(thing_uri); - slv2_value_free(name_p); - slv2_value_free(control_class); - slv2_value_free(audio_class); - slv2_value_free(in_class); - slv2_value_free(out_class); - cleanup_uris(); - return 1; -} - -/*****************************************************************************/ - -int -test_port() -{ - if (!start_bundle(MANIFEST_PREFIXES - ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", - BUNDLE_PREFIXES PREFIX_LV2EV - ":plug a lv2:Plugin ; " - PLUGIN_NAME("Test plugin") " ; " - LICENSE_GPL " ; " - "doap:homepage ; " - "lv2:port [ " - " a lv2:ControlPort ; a lv2:InputPort ; " - " lv2:index 0 ; lv2:symbol \"foo\" ; " - " lv2:name \"store\" ; " - " lv2:name \"dépanneur\"@fr-ca ; lv2:name \"épicerie\"@fr-fr ; " - " lv2:name \"tienda\"@es ; " - " lv2:portProperty lv2:integer ; " - " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 ; " - " lv2:scalePoint [ rdfs:label \"Sin\"; rdf:value 3 ] ; " - " lv2:scalePoint [ rdfs:label \"Cos\"; rdf:value 4 ] " - "] , [\n" - " a lv2:EventPort ; a lv2:InputPort ; " - " lv2:index 1 ; lv2:symbol \"event_in\" ; " - " lv2:name \"Event Input\" ; " - " lv2ev:supportsEvent " - "] .")) - return 0; - - init_uris(); - SLV2Plugins plugins = slv2_world_get_all_plugins(world); - SLV2Plugin plug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); - TEST_ASSERT(plug); - - SLV2Value psym = slv2_value_new_string(world, "foo"); - SLV2Port p = slv2_plugin_get_port_by_index(plug, 0); - SLV2Port p2 = slv2_plugin_get_port_by_symbol(plug, psym); - slv2_value_free(psym); - TEST_ASSERT(p != NULL); - TEST_ASSERT(p2 != NULL); - TEST_ASSERT(p == p2); - - SLV2Value nopsym = slv2_value_new_string(world, "thisaintnoportfoo"); - SLV2Port p3 = slv2_plugin_get_port_by_symbol(plug, nopsym); - TEST_ASSERT(p3 == NULL); - slv2_value_free(nopsym); - - SLV2Value audio_class = slv2_value_new_uri(world, - "http://lv2plug.in/ns/lv2core#AudioPort"); - SLV2Value control_class = slv2_value_new_uri(world, - "http://lv2plug.in/ns/lv2core#ControlPort"); - SLV2Value in_class = slv2_value_new_uri(world, - "http://lv2plug.in/ns/lv2core#InputPort"); - - TEST_ASSERT(slv2_values_size(slv2_port_get_classes(plug, p)) == 2); - TEST_ASSERT(slv2_plugin_get_num_ports(plug) == 2); - TEST_ASSERT(slv2_values_get_at(slv2_port_get_classes(plug, p), (unsigned)INT_MAX+1) == NULL); - TEST_ASSERT(slv2_port_is_a(plug, p, control_class)); - TEST_ASSERT(slv2_port_is_a(plug, p, in_class)); - TEST_ASSERT(!slv2_port_is_a(plug, p, audio_class)); - - SLV2Values port_properties = slv2_port_get_properties(plug, p); - TEST_ASSERT(slv2_values_size(port_properties) == 1); - slv2_values_free(port_properties); - - // Untranslated name (current locale is set to "C" in main) - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_port_get_symbol(plug, p)), "foo")); - SLV2Value name = slv2_port_get_name(plug, p); - TEST_ASSERT(!strcmp(slv2_value_as_string(name), "store")); - slv2_value_free(name); - - // Exact language match - setenv("LANG", "fr_FR", 1); - name = slv2_port_get_name(plug, p); - TEST_ASSERT(!strcmp(slv2_value_as_string(name), "épicerie")); - slv2_value_free(name); - - // Exact language match (with charset suffix) - setenv("LANG", "fr_CA.utf8", 1); - name = slv2_port_get_name(plug, p); - TEST_ASSERT(!strcmp(slv2_value_as_string(name), "dépanneur")); - slv2_value_free(name); - - // Partial language match (choose value translated for different country) - setenv("LANG", "fr_BE", 1); - name = slv2_port_get_name(plug, p); - TEST_ASSERT((!strcmp(slv2_value_as_string(name), "dépanneur")) - ||(!strcmp(slv2_value_as_string(name), "épicerie"))); - slv2_value_free(name); - - // Partial language match (choose country-less language tagged value) - setenv("LANG", "es_MX", 1); - name = slv2_port_get_name(plug, p); - TEST_ASSERT(!strcmp(slv2_value_as_string(name), "tienda")); - slv2_value_free(name); - - setenv("LANG", "C", 1); // Reset locale - - SLV2ScalePoints points = slv2_port_get_scale_points(plug, p); - TEST_ASSERT(slv2_scale_points_size(points) == 2); - - TEST_ASSERT(slv2_scale_points_get_at(points, (unsigned)INT_MAX+1) == NULL); - TEST_ASSERT(slv2_scale_points_get_at(points, 2) == NULL); - SLV2ScalePoint sp0 = slv2_scale_points_get_at(points, 0); - TEST_ASSERT(sp0); - SLV2ScalePoint sp1 = slv2_scale_points_get_at(points, 1); - TEST_ASSERT(sp1); - - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_scale_point_get_label(sp0)), "Sin")); - TEST_ASSERT(slv2_value_as_float(slv2_scale_point_get_value(sp0)) == 3); - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_scale_point_get_label(sp1)), "Cos")); - TEST_ASSERT(slv2_value_as_float(slv2_scale_point_get_value(sp1)) == 4); - - SLV2Value homepage_p = slv2_value_new_uri(world, "http://usefulinc.com/ns/doap#homepage"); - SLV2Values homepages = slv2_plugin_get_value(plug, homepage_p); - TEST_ASSERT(slv2_values_size(homepages) == 1); - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(homepages, 0)), - "http://example.org/someplug")); - - SLV2Value min, max, def; - slv2_port_get_range(plug, p, &def, &min, &max); - TEST_ASSERT(def); - TEST_ASSERT(min); - TEST_ASSERT(max); - TEST_ASSERT(slv2_value_as_float(def) == 0.5); - TEST_ASSERT(slv2_value_as_float(min) == -1.0); - TEST_ASSERT(slv2_value_as_float(max) == 1.0); - - SLV2Value integer_prop = slv2_value_new_uri(world, "http://lv2plug.in/ns/lv2core#integer"); - SLV2Value toggled_prop = slv2_value_new_uri(world, "http://lv2plug.in/ns/lv2core#toggled"); - - TEST_ASSERT(slv2_port_has_property(plug, p, integer_prop)); - TEST_ASSERT(!slv2_port_has_property(plug, p, toggled_prop)); - - SLV2Port ep = slv2_plugin_get_port_by_index(plug, 1); - - SLV2Value event_type = slv2_value_new_uri(world, "http://example.org/event"); - SLV2Value event_type_2 = slv2_value_new_uri(world, "http://example.org/otherEvent"); - TEST_ASSERT(slv2_port_supports_event(plug, ep, event_type)); - TEST_ASSERT(!slv2_port_supports_event(plug, ep, event_type_2)); - - SLV2Value name_p = slv2_value_new_uri(world, "http://lv2plug.in/ns/lv2core#name"); - SLV2Values names = slv2_port_get_value(plug, p, name_p); - TEST_ASSERT(slv2_values_size(names) == 1); - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(names, 0)), - "store")); - slv2_values_free(names); - - SLV2Value true_val = slv2_value_new_bool(world, true); - SLV2Value false_val = slv2_value_new_bool(world, false); - - slv2_world_set_option(world, SLV2_OPTION_FILTER_LANG, false_val); - names = slv2_port_get_value(plug, p, name_p); - TEST_ASSERT(slv2_values_size(names) == 4); - slv2_values_free(names); - slv2_world_set_option(world, SLV2_OPTION_FILTER_LANG, true_val); - - slv2_value_free(false_val); - slv2_value_free(true_val); - - names = slv2_port_get_value(plug, ep, name_p); - TEST_ASSERT(slv2_values_size(names) == 1); - TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_values_get_at(names, 0)), - "Event Input")); - slv2_values_free(names); - slv2_value_free(name_p); - - slv2_value_free(integer_prop); - slv2_value_free(toggled_prop); - slv2_value_free(event_type); - slv2_value_free(event_type_2); - - slv2_value_free(min); - slv2_value_free(max); - slv2_value_free(def); - - slv2_value_free(homepage_p); - slv2_values_free(homepages); - - slv2_scale_points_free(points); - slv2_value_free(control_class); - slv2_value_free(audio_class); - slv2_value_free(in_class); - cleanup_uris(); - return 1; -} - -/*****************************************************************************/ - -int -test_ui() -{ - if (!start_bundle(MANIFEST_PREFIXES - ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", - BUNDLE_PREFIXES PREFIX_LV2UI - ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " - PLUGIN_NAME("Test plugin") " ; " - LICENSE_GPL " ; " - "lv2:optionalFeature lv2:hardRTCapable ; " - "lv2:requiredFeature ; " - "lv2ui:ui :ui , :ui2 , :ui3 , :ui4 ; " - "doap:maintainer [ foaf:name \"David Robillard\" ; " - " foaf:homepage ; foaf:mbox ] ; " - "lv2:port [ " - " a lv2:ControlPort ; a lv2:InputPort ; " - " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; " - " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 " - "] , [ " - " a lv2:ControlPort ; a lv2:InputPort ; " - " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; " - " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 " - "] , [ " - " a lv2:ControlPort ; a lv2:OutputPort ; " - " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; " - " lv2:portProperty lv2:reportsLatency " - "] .\n" - ":ui a lv2ui:GtkUI ; " - " lv2ui:requiredFeature lv2ui:makeResident ; " - " lv2ui:binary ; " - " lv2ui:optionalFeature lv2ui:ext_presets . " - ":ui2 a lv2ui:GtkUI ; lv2ui:binary . " - ":ui3 a lv2ui:GtkUI ; lv2ui:binary . " - ":ui4 a lv2ui:GtkUI ; lv2ui:binary . ")) - return 0; - - init_uris(); - SLV2Plugins plugins = slv2_world_get_all_plugins(world); - SLV2Plugin plug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); - TEST_ASSERT(plug); - - SLV2UIs uis = slv2_plugin_get_uis(plug); - TEST_ASSERT(slv2_uis_size(uis) == 4); - - TEST_ASSERT(slv2_uis_get_at(uis, (unsigned)INT_MAX + 1) == NULL); - - SLV2UI ui0 = slv2_uis_get_at(uis, 0); - TEST_ASSERT(ui0); - - SLV2Value ui_uri = slv2_value_new_uri(world, "http://example.org/ui"); - SLV2Value ui2_uri = slv2_value_new_uri(world, "http://example.org/ui3"); - SLV2Value ui3_uri = slv2_value_new_uri(world, "http://example.org/ui4"); - SLV2Value noui_uri = slv2_value_new_uri(world, "http://example.org/notaui"); - - SLV2UI ui0_2 = slv2_uis_get_by_uri(uis, ui_uri); - TEST_ASSERT(ui0 == ui0_2); - - SLV2UI ui2 = slv2_uis_get_by_uri(uis, ui2_uri); - TEST_ASSERT(ui2 != ui0); - - SLV2UI ui3 = slv2_uis_get_by_uri(uis, ui3_uri); - TEST_ASSERT(ui3 != ui0); - - SLV2UI noui = slv2_uis_get_by_uri(uis, noui_uri); - TEST_ASSERT(noui == NULL); - - SLV2Values classes = slv2_ui_get_classes(ui0); - TEST_ASSERT(slv2_values_size(classes) == 1); - - SLV2Value ui_class_uri = slv2_value_new_uri(world, - "http://lv2plug.in/ns/extensions/ui#GtkUI"); - - TEST_ASSERT(slv2_value_equals(slv2_values_get_at(classes, 0), ui_class_uri)); - TEST_ASSERT(slv2_ui_is_a(ui0, ui_class_uri)); - - SLV2Value plug_bundle_uri = slv2_plugin_get_bundle_uri(plug); - SLV2Value ui_bundle_uri = slv2_ui_get_bundle_uri(ui0); - TEST_ASSERT(slv2_value_equals(plug_bundle_uri, ui_bundle_uri)); - - char* ui_binary_uri_str = (char*)malloc(TEST_PATH_MAX); - snprintf(ui_binary_uri_str, TEST_PATH_MAX, "%s%s", - slv2_value_as_string(plug_bundle_uri), "ui.so"); - - SLV2Value ui_binary_uri = slv2_ui_get_binary_uri(ui0); - - SLV2Value expected_uri = slv2_value_new_uri(world, ui_binary_uri_str); - TEST_ASSERT(slv2_value_equals(expected_uri, ui_binary_uri)); - - free(ui_binary_uri_str); - slv2_value_free(ui_class_uri); - slv2_value_free(ui_uri); - slv2_value_free(ui2_uri); - slv2_value_free(ui3_uri); - slv2_value_free(noui_uri); - slv2_value_free(expected_uri); - slv2_uis_free(uis); - - cleanup_uris(); - return 1; -} - -/*****************************************************************************/ - -/* add tests here */ -static struct TestCase tests[] = { - TEST_CASE(utils), - TEST_CASE(value), - TEST_CASE(verify), - TEST_CASE(no_verify), - TEST_CASE(discovery), - TEST_CASE(classes), - TEST_CASE(plugin), - TEST_CASE(port), - TEST_CASE(ui), - { NULL, NULL } -}; - -void -run_tests() -{ - int i; - for (i = 0; tests[i].title; i++) { - printf("*** Test %s\n", tests[i].title); - if (!tests[i].func()) { - printf("\nTest failed\n"); - /* test case that wasn't able to be executed at all counts as 1 test + 1 error */ - error_count++; - test_count++; - } - unload_bundle(); - cleanup(); - } -} - -int -main(int argc, char *argv[]) -{ - if (argc != 1) { - printf("Syntax: %s\n", argv[0]); - return 0; - } - setenv("LANG", "C", 1); - init_tests(); - run_tests(); - cleanup(); - printf("\n*** Test Results: %d tests, %d errors\n\n", test_count, error_count); - return error_count ? 1 : 0; -} diff --git a/utils/lilv.bash_completion b/utils/lilv.bash_completion new file mode 100644 index 0000000..921087a --- /dev/null +++ b/utils/lilv.bash_completion @@ -0,0 +1,59 @@ +# Bash auto-completion script written for lv2_inspect, lv2_jack_host +# and lv2_simple_jack_host. Could be adapted to any other program +# that takes an LV2 plugin URI as parameter. + +# Written by Lars Luthman on 2009-10-12. +# No copyright claimed for this script. Do what you want with it. + +# For some reason Bash splits the command line not only at whitespace +# but also at ':' signs before putting the parts into COMP_WORDS. +# Since ':' is used in all URIs, which are what we want to complete, +# we have to put the URI back together before we can complete it +# and then cut off the parts we prepended from the completions. +# It probably breaks in some special cases but for most common uses +# it should work fine. + +function _lv2_inspect() { + local uri cur opts w wn raw_reply len type + opts=`lv2_list | xargs -n1 echo -n " "` + + # This is the last "word", as split by Bash. + cur="${COMP_WORDS[COMP_CWORD]}" + w="$cur" + + # Add the previous word while it or this one is a word break character + for i in `seq $(( $COMP_CWORD - 1 )) -1 1`; do + wn="${COMP_WORDS[i]}" + if expr "$COMP_WORDBREAKS" : ".*$wn" > /dev/null; then + if expr "$COMP_WORDBREAKS" : ".*$w" > /dev/null; then + break + fi + fi + w="$wn" + uri="$w$uri" + done + + # Check the length of the words we prepend + len=${#uri} + uri="$uri$cur" + raw_reply="$(compgen -W "${opts}" -- ${uri})" + + # If we are listing alternatives, just print the full URIs. + type=`echo $COMP_TYPE | awk '{ printf "%c", $1 }'` + if expr "?!@%" : ".*$type" > /dev/null; then + COMPREPLY=( $raw_reply ) + return 0 + fi + + # Otherwise, strip the prepended words from all completion suggestions. + COMPREPLY=() + for i in $raw_reply; do + COMPREPLY=( ${COMPREPLY[@]} ${i:len} ) + done +} + +complete -F _lv2_inspect lv2_inspect + +# And the same for lv2_jack_host and lv2_simple_jack_host. +complete -F _lv2_inspect lv2_jack_host +complete -F _lv2_inspect lv2_simple_jack_host diff --git a/utils/lilv_bench.c b/utils/lilv_bench.c new file mode 100644 index 0000000..2920fb5 --- /dev/null +++ b/utils/lilv_bench.c @@ -0,0 +1,55 @@ +/* + Copyright 2007-2011 David Robillard + + 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. +*/ + +#include + +#include "lilv/lilv.h" + +#include "lilv-config.h" + +void +print_version() +{ + printf("lilv_bench (lilv) " LILV_VERSION "\n"); + printf("Copyright 2011-2011 David Robillard \n"); + printf("License: \n"); + printf("This is free software: you are free to change and redistribute it.\n"); + printf("There is NO WARRANTY, to the extent permitted by law.\n"); +} + +void +print_usage() +{ + printf("Usage: lilv_bench\n"); + printf("Load all discovered LV2 plugins.\n"); +} + +int +main(int argc, char** argv) +{ + LilvWorld world = lilv_world_new(); + lilv_world_load_all(world); + + LilvPlugins plugins = lilv_world_get_all_plugins(world); + LILV_FOREACH(plugins, p, plugins) { + LilvPlugin plugin = lilv_plugins_get(plugins, p); + lilv_plugin_get_class(plugin); + } + + lilv_world_free(world); + + return 0; +} diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c index 5c7342d..20b5a3c 100644 --- a/utils/lv2_inspect.c +++ b/utils/lv2_inspect.c @@ -20,29 +20,29 @@ #include #include -#include "slv2/slv2.h" +#include "lilv/lilv.h" -#include "slv2-config.h" +#include "lilv-config.h" -SLV2Value event_class = NULL; -SLV2Value control_class = NULL; -SLV2Value in_group_pred = NULL; -SLV2Value role_pred = NULL; -SLV2Value preset_pred = NULL; -SLV2Value title_pred = NULL; +LilvValue event_class = NULL; +LilvValue control_class = NULL; +LilvValue in_group_pred = NULL; +LilvValue role_pred = NULL; +LilvValue preset_pred = NULL; +LilvValue title_pred = NULL; void -print_group(SLV2Plugin p, SLV2Value group, SLV2Value type, SLV2Value symbol) +print_group(LilvPlugin p, LilvValue group, LilvValue type, LilvValue symbol) { - printf("\n\tGroup %s:\n", slv2_value_as_string(group)); - printf("\t\tType: %s\n", slv2_value_as_string(type)); - printf("\t\tSymbol: %s\n", slv2_value_as_string(symbol)); + printf("\n\tGroup %s:\n", lilv_value_as_string(group)); + printf("\t\tType: %s\n", lilv_value_as_string(type)); + printf("\t\tSymbol: %s\n", lilv_value_as_string(symbol)); } void -print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defaults) +print_port(LilvPlugin p, uint32_t index, float* mins, float* maxes, float* defaults) { - SLV2Port port = slv2_plugin_get_port_by_index(p, index); + LilvPort port = lilv_plugin_get_port_by_index(p, index); printf("\n\tPort %d:\n", index); @@ -53,63 +53,63 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau bool first = true; - SLV2Values classes = slv2_port_get_classes(p, port); + LilvValues classes = lilv_port_get_classes(p, port); printf("\t\tType: "); - SLV2_FOREACH(values, i, classes) { - SLV2Value value = slv2_values_get(classes, i); + LILV_FOREACH(values, i, classes) { + LilvValue value = lilv_values_get(classes, i); if (!first) { printf("\n\t\t "); } - printf("%s", slv2_value_as_uri(value)); + printf("%s", lilv_value_as_uri(value)); first = false; } - if (slv2_port_is_a(p, port, event_class)) { - SLV2Values supported = slv2_port_get_value_by_qname(p, port, + if (lilv_port_is_a(p, port, event_class)) { + LilvValues supported = lilv_port_get_value_by_qname(p, port, "lv2ev:supportsEvent"); - if (slv2_values_size(supported) > 0) { + if (lilv_values_size(supported) > 0) { printf("\n\t\tSupported events:\n"); - SLV2_FOREACH(values, i, supported) { - SLV2Value value = slv2_values_get(supported, i); - printf("\t\t\t%s\n", slv2_value_as_uri(value)); + LILV_FOREACH(values, i, supported) { + LilvValue value = lilv_values_get(supported, i); + printf("\t\t\t%s\n", lilv_value_as_uri(value)); } } - slv2_values_free(supported); + lilv_values_free(supported); } - SLV2ScalePoints points = slv2_port_get_scale_points(p, port); + LilvScalePoints points = lilv_port_get_scale_points(p, port); if (points) printf("\n\t\tScale Points:\n"); - SLV2_FOREACH(scale_points, i, points) { - SLV2ScalePoint p = slv2_scale_points_get(points, i); + LILV_FOREACH(scale_points, i, points) { + LilvScalePoint p = lilv_scale_points_get(points, i); printf("\t\t\t%s = \"%s\"\n", - slv2_value_as_string(slv2_scale_point_get_value(p)), - slv2_value_as_string(slv2_scale_point_get_label(p))); + lilv_value_as_string(lilv_scale_point_get_value(p)), + lilv_value_as_string(lilv_scale_point_get_label(p))); } - slv2_scale_points_free(points); + lilv_scale_points_free(points); - SLV2Value val = slv2_port_get_symbol(p, port); - printf("\n\t\tSymbol: %s\n", slv2_value_as_string(val)); + LilvValue val = lilv_port_get_symbol(p, port); + printf("\n\t\tSymbol: %s\n", lilv_value_as_string(val)); - val = slv2_port_get_name(p, port); - printf("\t\tName: %s\n", slv2_value_as_string(val)); - slv2_value_free(val); + val = lilv_port_get_name(p, port); + printf("\t\tName: %s\n", lilv_value_as_string(val)); + lilv_value_free(val); - SLV2Values groups = slv2_port_get_value(p, port, in_group_pred); - if (slv2_values_size(groups) > 0) + LilvValues groups = lilv_port_get_value(p, port, in_group_pred); + if (lilv_values_size(groups) > 0) printf("\t\tGroup: %s\n", - slv2_value_as_string( - slv2_values_get(groups, slv2_values_begin(groups)))); - slv2_values_free(groups); + lilv_value_as_string( + lilv_values_get(groups, lilv_values_begin(groups)))); + lilv_values_free(groups); - SLV2Values roles = slv2_port_get_value(p, port, role_pred); - if (slv2_values_size(roles) > 0) + LilvValues roles = lilv_port_get_value(p, port, role_pred); + if (lilv_values_size(roles) > 0) printf("\t\tRole: %s\n", - slv2_value_as_string( - slv2_values_get(roles, slv2_values_begin(roles)))); - slv2_values_free(roles); + lilv_value_as_string( + lilv_values_get(roles, lilv_values_begin(roles)))); + lilv_values_free(roles); - if (slv2_port_is_a(p, port, control_class)) { + if (lilv_port_is_a(p, port, control_class)) { if (!isnan(mins[index])) printf("\t\tMinimum: %f\n", mins[index]); if (!isnan(mins[index])) @@ -118,165 +118,165 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau printf("\t\tDefault: %f\n", defaults[index]); } - SLV2Values properties = slv2_port_get_properties(p, port); - if (slv2_values_size(properties) > 0) + LilvValues properties = lilv_port_get_properties(p, port); + if (lilv_values_size(properties) > 0) printf("\t\tProperties: "); first = true; - SLV2_FOREACH(values, i, properties) { + LILV_FOREACH(values, i, properties) { if (!first) { printf("\t\t "); } - printf("%s\n", slv2_value_as_uri(slv2_values_get(properties, i))); + printf("%s\n", lilv_value_as_uri(lilv_values_get(properties, i))); first = false; } - if (slv2_values_size(properties) > 0) + if (lilv_values_size(properties) > 0) printf("\n"); - slv2_values_free(properties); + lilv_values_free(properties); } void -print_plugin(SLV2Plugin p) +print_plugin(LilvPlugin p) { - SLV2Value val = NULL; + LilvValue val = NULL; - printf("%s\n\n", slv2_value_as_uri(slv2_plugin_get_uri(p))); + printf("%s\n\n", lilv_value_as_uri(lilv_plugin_get_uri(p))); - val = slv2_plugin_get_name(p); + val = lilv_plugin_get_name(p); if (val) { - printf("\tName: %s\n", slv2_value_as_string(val)); - slv2_value_free(val); + printf("\tName: %s\n", lilv_value_as_string(val)); + lilv_value_free(val); } - SLV2Value class_label = slv2_plugin_class_get_label(slv2_plugin_get_class(p)); + LilvValue class_label = lilv_plugin_class_get_label(lilv_plugin_get_class(p)); if (class_label) { - printf("\tClass: %s\n", slv2_value_as_string(class_label)); + printf("\tClass: %s\n", lilv_value_as_string(class_label)); } - val = slv2_plugin_get_author_name(p); + val = lilv_plugin_get_author_name(p); if (val) { - printf("\tAuthor: %s\n", slv2_value_as_string(val)); - slv2_value_free(val); + printf("\tAuthor: %s\n", lilv_value_as_string(val)); + lilv_value_free(val); } - val = slv2_plugin_get_author_email(p); + val = lilv_plugin_get_author_email(p); if (val) { - printf("\tAuthor Email: %s\n", slv2_value_as_uri(val)); - slv2_value_free(val); + printf("\tAuthor Email: %s\n", lilv_value_as_uri(val)); + lilv_value_free(val); } - val = slv2_plugin_get_author_homepage(p); + val = lilv_plugin_get_author_homepage(p); if (val) { - printf("\tAuthor Homepage: %s\n", slv2_value_as_uri(val)); - slv2_value_free(val); + printf("\tAuthor Homepage: %s\n", lilv_value_as_uri(val)); + lilv_value_free(val); } - if (slv2_plugin_has_latency(p)) { - uint32_t latency_port = slv2_plugin_get_latency_port_index(p); + if (lilv_plugin_has_latency(p)) { + uint32_t latency_port = lilv_plugin_get_latency_port_index(p); printf("\tHas latency: yes, reported by port %d\n", latency_port); } else { printf("\tHas latency: no\n"); } printf("\tBundle: %s\n", - slv2_value_as_uri(slv2_plugin_get_bundle_uri(p))); + lilv_value_as_uri(lilv_plugin_get_bundle_uri(p))); - SLV2Value binary_uri = slv2_plugin_get_library_uri(p); + LilvValue binary_uri = lilv_plugin_get_library_uri(p); if (binary_uri) { printf("\tBinary: %s\n", - slv2_value_as_uri(slv2_plugin_get_library_uri(p))); + lilv_value_as_uri(lilv_plugin_get_library_uri(p))); } - SLV2UIs uis = slv2_plugin_get_uis(p); - if (slv2_values_size(uis) > 0) { + LilvUIs uis = lilv_plugin_get_uis(p); + if (lilv_values_size(uis) > 0) { printf("\tUI: "); - SLV2_FOREACH(uis, i, uis) { - SLV2UI ui = slv2_uis_get(uis, i); - printf("%s\n", slv2_value_as_uri(slv2_ui_get_uri(ui))); + LILV_FOREACH(uis, i, uis) { + LilvUI ui = lilv_uis_get(uis, i); + printf("%s\n", lilv_value_as_uri(lilv_ui_get_uri(ui))); - const char* binary = slv2_value_as_uri(slv2_ui_get_binary_uri(ui)); + const char* binary = lilv_value_as_uri(lilv_ui_get_binary_uri(ui)); - SLV2Values types = slv2_ui_get_classes(ui); - SLV2_FOREACH(values, i, types) { + LilvValues types = lilv_ui_get_classes(ui); + LILV_FOREACH(values, i, types) { printf("\t Class: %s\n", - slv2_value_as_uri(slv2_values_get(types, i))); + lilv_value_as_uri(lilv_values_get(types, i))); } if (binary) printf("\t Binary: %s\n", binary); printf("\t Bundle: %s\n", - slv2_value_as_uri(slv2_ui_get_bundle_uri(ui))); + lilv_value_as_uri(lilv_ui_get_bundle_uri(ui))); } } - slv2_uis_free(uis); + lilv_uis_free(uis); printf("\tData URIs: "); - SLV2Values data_uris = slv2_plugin_get_data_uris(p); + LilvValues data_uris = lilv_plugin_get_data_uris(p); bool first = true; - SLV2_FOREACH(values, i, data_uris) { + LILV_FOREACH(values, i, data_uris) { if (!first) { printf("\n\t "); } - printf("%s", slv2_value_as_uri(slv2_values_get(data_uris, i))); + printf("%s", lilv_value_as_uri(lilv_values_get(data_uris, i))); first = false; } printf("\n"); /* Required Features */ - SLV2Values features = slv2_plugin_get_required_features(p); + LilvValues features = lilv_plugin_get_required_features(p); if (features) printf("\tRequired Features: "); first = true; - SLV2_FOREACH(values, i, features) { + LILV_FOREACH(values, i, features) { if (!first) { printf("\n\t "); } - printf("%s", slv2_value_as_uri(slv2_values_get(features, i))); + printf("%s", lilv_value_as_uri(lilv_values_get(features, i))); first = false; } if (features) printf("\n"); - slv2_values_free(features); + lilv_values_free(features); /* Optional Features */ - features = slv2_plugin_get_optional_features(p); + features = lilv_plugin_get_optional_features(p); if (features) printf("\tOptional Features: "); first = true; - SLV2_FOREACH(values, i, features) { + LILV_FOREACH(values, i, features) { if (!first) { printf("\n\t "); } - printf("%s", slv2_value_as_uri(slv2_values_get(features, i))); + printf("%s", lilv_value_as_uri(lilv_values_get(features, i))); first = false; } if (features) printf("\n"); - slv2_values_free(features); + lilv_values_free(features); /* Presets */ - SLV2Values presets = slv2_plugin_get_value(p, preset_pred); + LilvValues presets = lilv_plugin_get_value(p, preset_pred); if (presets) printf("\tPresets: \n"); - SLV2_FOREACH(values, i, presets) { - SLV2Values titles = slv2_plugin_get_value_for_subject( - p, slv2_values_get(presets, i), title_pred); + LILV_FOREACH(values, i, presets) { + LilvValues titles = lilv_plugin_get_value_for_subject( + p, lilv_values_get(presets, i), title_pred); if (titles) { - SLV2Value title = slv2_values_get(titles, slv2_values_begin(titles)); - printf("\t %s\n", slv2_value_as_string(title)); + LilvValue title = lilv_values_get(titles, lilv_values_begin(titles)); + printf("\t %s\n", lilv_value_as_string(title)); } } /* Ports */ - const uint32_t num_ports = slv2_plugin_get_num_ports(p); + const uint32_t num_ports = lilv_plugin_get_num_ports(p); float* mins = calloc(num_ports, sizeof(float)); float* maxes = calloc(num_ports, sizeof(float)); float* defaults = calloc(num_ports, sizeof(float)); - slv2_plugin_get_port_ranges_float(p, mins, maxes, defaults); + lilv_plugin_get_port_ranges_float(p, mins, maxes, defaults); for (uint32_t i = 0; i < num_ports; ++i) print_port(p, i, mins, maxes, defaults); @@ -290,7 +290,7 @@ void print_version() { printf( - "lv2_inspect (slv2) " SLV2_VERSION "\n" + "lv2_inspect (slv2) " LILV_VERSION "\n" "Copyright 2007-2011 David Robillard \n" "License: \n" "This is free software: you are free to change and redistribute it.\n" @@ -310,19 +310,19 @@ main(int argc, char** argv) int ret = 0; setlocale (LC_ALL, ""); - SLV2World world = slv2_world_new(); - slv2_world_load_all(world); + LilvWorld world = lilv_world_new(); + lilv_world_load_all(world); #define NS_DC "http://dublincore.org/documents/dcmi-namespace/" #define NS_PG "http://lv2plug.in/ns/ext/port-groups#" #define NS_PSET "http://lv2plug.in/ns/ext/presets#" - control_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_CONTROL); - event_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_EVENT); - in_group_pred = slv2_value_new_uri(world, NS_PG "inGroup"); - preset_pred = slv2_value_new_uri(world, NS_PSET "hasPreset"); - role_pred = slv2_value_new_uri(world, NS_PG "role"); - title_pred = slv2_value_new_uri(world, NS_DC "title"); + control_class = lilv_value_new_uri(world, LILV_PORT_CLASS_CONTROL); + event_class = lilv_value_new_uri(world, LILV_PORT_CLASS_EVENT); + in_group_pred = lilv_value_new_uri(world, NS_PG "inGroup"); + preset_pred = lilv_value_new_uri(world, NS_PSET "hasPreset"); + role_pred = lilv_value_new_uri(world, NS_PG "role"); + title_pred = lilv_value_new_uri(world, NS_DC "title"); if (argc != 2) { print_usage(); @@ -344,10 +344,10 @@ main(int argc, char** argv) goto done; } - SLV2Plugins plugins = slv2_world_get_all_plugins(world); - SLV2Value uri = slv2_value_new_uri(world, argv[1]); + LilvPlugins plugins = lilv_world_get_all_plugins(world); + LilvValue uri = lilv_value_new_uri(world, argv[1]); - SLV2Plugin p = slv2_plugins_get_by_uri(plugins, uri); + LilvPlugin p = lilv_plugins_get_by_uri(plugins, uri); if (p) { print_plugin(p); @@ -357,16 +357,16 @@ main(int argc, char** argv) ret = (p != NULL ? 0 : -1); - slv2_value_free(uri); + lilv_value_free(uri); done: - slv2_value_free(title_pred); - slv2_value_free(role_pred); - slv2_value_free(preset_pred); - slv2_value_free(in_group_pred); - slv2_value_free(event_class); - slv2_value_free(control_class); - slv2_world_free(world); + lilv_value_free(title_pred); + lilv_value_free(role_pred); + lilv_value_free(preset_pred); + lilv_value_free(in_group_pred); + lilv_value_free(event_class); + lilv_value_free(control_class); + lilv_world_free(world); return ret; } diff --git a/utils/lv2_jack_host.c b/utils/lv2_jack_host.c index 5e0bca8..20c9ad7 100644 --- a/utils/lv2_jack_host.c +++ b/utils/lv2_jack_host.c @@ -30,17 +30,17 @@ #include "lv2/lv2plug.in/ns/ext/event/event.h" #include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h" -#include "slv2/slv2.h" +#include "lilv/lilv.h" -#include "slv2-config.h" +#include "lilv-config.h" -#ifdef SLV2_JACK_SESSION +#ifdef LILV_JACK_SESSION #include #include GMutex* exit_mutex; GCond* exit_cond; -#endif /* SLV2_JACK_SESSION */ +#endif /* LILV_JACK_SESSION */ #define MIDI_BUFFER_SIZE 1024 @@ -51,7 +51,7 @@ enum PortType { }; struct Port { - SLV2Port slv2_port; + LilvPort lilv_port; enum PortType type; jack_port_t* jack_port; /**< For audio/MIDI ports, otherwise NULL */ float control; /**< For control ports, otherwise 0.0f */ @@ -62,17 +62,17 @@ struct Port { /** This program's data */ struct JackHost { jack_client_t* jack_client; /**< Jack client */ - SLV2Plugin plugin; /**< Plugin "class" (actually just a few strings) */ - SLV2Instance instance; /**< Plugin "instance" (loaded shared lib) */ + LilvPlugin plugin; /**< Plugin "class" (actually just a few strings) */ + LilvInstance instance; /**< Plugin "instance" (loaded shared lib) */ uint32_t num_ports; /**< Size of the two following arrays: */ struct Port* ports; /**< Port array of size num_ports */ - SLV2Value input_class; /**< Input port class (URI) */ - SLV2Value output_class; /**< Output port class (URI) */ - SLV2Value control_class; /**< Control port class (URI) */ - SLV2Value audio_class; /**< Audio port class (URI) */ - SLV2Value event_class; /**< Event port class (URI) */ - SLV2Value midi_class; /**< MIDI event class (URI) */ - SLV2Value optional; /**< lv2:connectionOptional port property */ + LilvValue input_class; /**< Input port class (URI) */ + LilvValue output_class; /**< Output port class (URI) */ + LilvValue control_class; /**< Control port class (URI) */ + LilvValue audio_class; /**< Audio port class (URI) */ + LilvValue event_class; /**< Event port class (URI) */ + LilvValue midi_class; /**< MIDI event class (URI) */ + LilvValue optional; /**< lv2:connectionOptional port property */ }; /** URI map feature, for event types (we use only MIDI) */ @@ -83,7 +83,7 @@ uri_to_id(LV2_URI_Map_Callback_Data callback_data, const char* uri) { /* Note a non-trivial host needs to use an actual dictionary here */ - if (!strcmp(map, LV2_EVENT_URI) && !strcmp(uri, SLV2_EVENT_CLASS_MIDI)) + if (!strcmp(map, LV2_EVENT_URI) && !strcmp(uri, LILV_EVENT_CLASS_MIDI)) return MIDI_EVENT_ID; else return 0; /* Refuse to map ID */ @@ -118,45 +118,45 @@ create_port(struct JackHost* host, { struct Port* const port = &host->ports[port_index]; - port->slv2_port = slv2_plugin_get_port_by_index(host->plugin, port_index); + port->lilv_port = lilv_plugin_get_port_by_index(host->plugin, port_index); port->jack_port = NULL; port->control = 0.0f; port->ev_buffer = NULL; - slv2_instance_connect_port(host->instance, port_index, NULL); + lilv_instance_connect_port(host->instance, port_index, NULL); /* Get the port symbol for console printing */ - SLV2Value symbol = slv2_port_get_symbol(host->plugin, port->slv2_port); - const char* symbol_str = slv2_value_as_string(symbol); + LilvValue symbol = lilv_port_get_symbol(host->plugin, port->lilv_port); + const char* symbol_str = lilv_value_as_string(symbol); enum JackPortFlags jack_flags = 0; - if (slv2_port_is_a(host->plugin, port->slv2_port, host->input_class)) { + if (lilv_port_is_a(host->plugin, port->lilv_port, host->input_class)) { jack_flags = JackPortIsInput; port->is_input = true; - } else if (slv2_port_is_a(host->plugin, port->slv2_port, host->output_class)) { + } else if (lilv_port_is_a(host->plugin, port->lilv_port, host->output_class)) { jack_flags = JackPortIsOutput; port->is_input = false; - } else if (slv2_port_has_property(host->plugin, port->slv2_port, host->optional)) { - slv2_instance_connect_port(host->instance, port_index, NULL); + } else if (lilv_port_has_property(host->plugin, port->lilv_port, host->optional)) { + lilv_instance_connect_port(host->instance, port_index, NULL); } else { die("Mandatory port has unknown type (neither input or output)"); } /* Set control values */ - if (slv2_port_is_a(host->plugin, port->slv2_port, host->control_class)) { + if (lilv_port_is_a(host->plugin, port->lilv_port, host->control_class)) { port->type = CONTROL; port->control = isnan(default_value) ? 0.0 : default_value; printf("%s = %f\n", symbol_str, host->ports[port_index].control); - } else if (slv2_port_is_a(host->plugin, port->slv2_port, host->audio_class)) { + } else if (lilv_port_is_a(host->plugin, port->lilv_port, host->audio_class)) { port->type = AUDIO; - } else if (slv2_port_is_a(host->plugin, port->slv2_port, host->event_class)) { + } else if (lilv_port_is_a(host->plugin, port->lilv_port, host->event_class)) { port->type = EVENT; } /* Connect the port based on its type */ switch (port->type) { case CONTROL: - slv2_instance_connect_port(host->instance, port_index, &port->control); + lilv_instance_connect_port(host->instance, port_index, &port->control); break; case AUDIO: port->jack_port = jack_port_register( @@ -166,11 +166,11 @@ create_port(struct JackHost* host, port->jack_port = jack_port_register( host->jack_client, symbol_str, JACK_DEFAULT_MIDI_TYPE, jack_flags, 0); port->ev_buffer = lv2_event_buffer_new(MIDI_BUFFER_SIZE, LV2_EVENT_AUDIO_STAMP); - slv2_instance_connect_port(host->instance, port_index, port->ev_buffer); + lilv_instance_connect_port(host->instance, port_index, port->ev_buffer); break; default: /* FIXME: check if port connection is optional and die if not */ - slv2_instance_connect_port(host->instance, port_index, NULL); + lilv_instance_connect_port(host->instance, port_index, NULL); fprintf(stderr, "WARNING: Unknown port type, port not connected.\n"); } } @@ -188,7 +188,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) if (host->ports[p].type == AUDIO) { /* Connect plugin port directly to Jack port buffer. */ - slv2_instance_connect_port( + lilv_instance_connect_port( host->instance, p, jack_port_get_buffer(host->ports[p].jack_port, nframes)); @@ -217,7 +217,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) } /* Run plugin for this cycle */ - slv2_instance_run(host->instance, nframes); + lilv_instance_run(host->instance, nframes); /* Deliver MIDI output */ for (uint32_t p = 0; p < host->num_ports; ++p) { @@ -245,7 +245,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) return 0; } -#ifdef SLV2_JACK_SESSION +#ifdef LILV_JACK_SESSION void jack_session_cb(jack_session_event_t* event, void* arg) { @@ -253,7 +253,7 @@ jack_session_cb(jack_session_event_t* event, void* arg) char cmd[256]; snprintf(cmd, sizeof(cmd), "lv2_jack_host %s %s", - slv2_value_as_uri(slv2_plugin_get_uri(host->plugin)), + lilv_value_as_uri(lilv_plugin_get_uri(host->plugin)), event->client_uuid); event->command_line = strdup(cmd); @@ -273,12 +273,12 @@ jack_session_cb(jack_session_event_t* event, void* arg) jack_session_event_free(event); } -#endif /* SLV2_JACK_SESSION */ +#endif /* LILV_JACK_SESSION */ static void signal_handler(int ignored) { -#ifdef SLV2_JACK_SESSION +#ifdef LILV_JACK_SESSION g_mutex_lock(exit_mutex); g_cond_signal(exit_cond); g_mutex_unlock(exit_mutex); @@ -293,7 +293,7 @@ main(int argc, char** argv) host.num_ports = 0; host.ports = NULL; -#ifdef SLV2_JACK_SESSION +#ifdef LILV_JACK_SESSION if (!g_thread_supported()) { g_thread_init(NULL); } @@ -305,28 +305,28 @@ main(int argc, char** argv) signal(SIGTERM, signal_handler); /* Find all installed plugins */ - SLV2World world = slv2_world_new(); - slv2_world_load_all(world); - SLV2Plugins plugins = slv2_world_get_all_plugins(world); + LilvWorld world = lilv_world_new(); + lilv_world_load_all(world); + LilvPlugins plugins = lilv_world_get_all_plugins(world); /* Set up the port classes this app supports */ - host.input_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_INPUT); - host.output_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_OUTPUT); - host.control_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_CONTROL); - host.audio_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_AUDIO); - host.event_class = slv2_value_new_uri(world, SLV2_PORT_CLASS_EVENT); - host.midi_class = slv2_value_new_uri(world, SLV2_EVENT_CLASS_MIDI); - host.optional = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 + host.input_class = lilv_value_new_uri(world, LILV_PORT_CLASS_INPUT); + host.output_class = lilv_value_new_uri(world, LILV_PORT_CLASS_OUTPUT); + host.control_class = lilv_value_new_uri(world, LILV_PORT_CLASS_CONTROL); + host.audio_class = lilv_value_new_uri(world, LILV_PORT_CLASS_AUDIO); + host.event_class = lilv_value_new_uri(world, LILV_PORT_CLASS_EVENT); + host.midi_class = lilv_value_new_uri(world, LILV_EVENT_CLASS_MIDI); + host.optional = lilv_value_new_uri(world, LILV_NAMESPACE_LV2 "connectionOptional"); -#ifdef SLV2_JACK_SESSION +#ifdef LILV_JACK_SESSION if (argc != 2 && argc != 3) { fprintf(stderr, "Usage: %s PLUGIN_URI [JACK_UUID]\n", argv[0]); #else if (argc != 2) { fprintf(stderr, "Usage: %s PLUGIN_URI\n", argv[0]); #endif - slv2_world_free(world); + lilv_world_free(world); return EXIT_FAILURE; } @@ -334,19 +334,19 @@ main(int argc, char** argv) printf("Plugin: %s\n", plugin_uri_str); - SLV2Value plugin_uri = slv2_value_new_uri(world, plugin_uri_str); - host.plugin = slv2_plugins_get_by_uri(plugins, plugin_uri); - slv2_value_free(plugin_uri); + LilvValue plugin_uri = lilv_value_new_uri(world, plugin_uri_str); + host.plugin = lilv_plugins_get_by_uri(plugins, plugin_uri); + lilv_value_free(plugin_uri); if (!host.plugin) { fprintf(stderr, "Failed to find plugin %s.\n", plugin_uri_str); - slv2_world_free(world); + lilv_world_free(world); return EXIT_FAILURE; } /* Get the plugin's name */ - SLV2Value name = slv2_plugin_get_name(host.plugin); - const char* name_str = slv2_value_as_string(name); + LilvValue name = lilv_plugin_get_name(host.plugin); + const char* name_str = lilv_value_as_string(name); /* Truncate plugin name to suit JACK (if necessary) */ char* jack_name = NULL; @@ -359,7 +359,7 @@ main(int argc, char** argv) /* Connect to JACK */ printf("JACK Name: %s\n\n", jack_name); -#ifdef SLV2_JACK_SESSION +#ifdef LILV_JACK_SESSION const char* const jack_uuid_str = (argc > 2) ? argv[2] : NULL; if (jack_uuid_str) { host.jack_client = jack_client_open(jack_name, JackSessionID, NULL, @@ -372,28 +372,28 @@ main(int argc, char** argv) } free(jack_name); - slv2_value_free(name); + lilv_value_free(name); if (!host.jack_client) die("Failed to connect to JACK.\n"); /* Instantiate the plugin */ - host.instance = slv2_plugin_instantiate( + host.instance = lilv_plugin_instantiate( host.plugin, jack_get_sample_rate(host.jack_client), features); if (!host.instance) die("Failed to instantiate plugin.\n"); jack_set_process_callback(host.jack_client, &jack_process_cb, (void*)(&host)); -#ifdef SLV2_JACK_SESSION +#ifdef LILV_JACK_SESSION jack_set_session_callback(host.jack_client, &jack_session_cb, (void*)(&host)); #endif /* Create ports */ - host.num_ports = slv2_plugin_get_num_ports(host.plugin); + host.num_ports = lilv_plugin_get_num_ports(host.plugin); host.ports = calloc((size_t)host.num_ports, sizeof(struct Port)); - float* default_values = calloc(slv2_plugin_get_num_ports(host.plugin), + float* default_values = calloc(lilv_plugin_get_num_ports(host.plugin), sizeof(float)); - slv2_plugin_get_port_ranges_float(host.plugin, NULL, NULL, default_values); + lilv_plugin_get_port_ranges_float(host.plugin, NULL, NULL, default_values); for (uint32_t i = 0; i < host.num_ports; ++i) create_port(&host, i, default_values[i]); @@ -401,11 +401,11 @@ main(int argc, char** argv) free(default_values); /* Activate plugin and JACK */ - slv2_instance_activate(host.instance); + lilv_instance_activate(host.instance); jack_activate(host.jack_client); /* Run */ -#ifdef SLV2_JACK_SESSION +#ifdef LILV_JACK_SESSION printf("\nPress Ctrl-C to quit: "); fflush(stdout); g_cond_wait(exit_cond, exit_mutex); @@ -431,21 +431,21 @@ main(int argc, char** argv) jack_client_close(host.jack_client); /* Deactivate plugin */ - slv2_instance_deactivate(host.instance); - slv2_instance_free(host.instance); + lilv_instance_deactivate(host.instance); + lilv_instance_free(host.instance); /* Clean up */ free(host.ports); - slv2_value_free(host.input_class); - slv2_value_free(host.output_class); - slv2_value_free(host.control_class); - slv2_value_free(host.audio_class); - slv2_value_free(host.event_class); - slv2_value_free(host.midi_class); - slv2_value_free(host.optional); - slv2_world_free(world); - -#ifdef SLV2_JACK_SESSION + lilv_value_free(host.input_class); + lilv_value_free(host.output_class); + lilv_value_free(host.control_class); + lilv_value_free(host.audio_class); + lilv_value_free(host.event_class); + lilv_value_free(host.midi_class); + lilv_value_free(host.optional); + lilv_world_free(world); + +#ifdef LILV_JACK_SESSION g_mutex_free(exit_mutex); g_cond_free(exit_cond); #endif diff --git a/utils/lv2_list.c b/utils/lv2_list.c index d62699a..88769ae 100644 --- a/utils/lv2_list.c +++ b/utils/lv2_list.c @@ -18,21 +18,21 @@ #include #include -#include "slv2/slv2.h" +#include "lilv/lilv.h" -#include "slv2-config.h" +#include "lilv-config.h" void -list_plugins(SLV2Plugins list, bool show_names) +list_plugins(LilvPlugins list, bool show_names) { - SLV2_FOREACH(plugins, i, list) { - SLV2Plugin p = slv2_plugins_get(list, i); + LILV_FOREACH(plugins, i, list) { + LilvPlugin p = lilv_plugins_get(list, i); if (show_names) { - SLV2Value n = slv2_plugin_get_name(p); - printf("%s\n", slv2_value_as_string(n)); - slv2_value_free(n); + LilvValue n = lilv_plugin_get_name(p); + printf("%s\n", lilv_value_as_string(n)); + lilv_value_free(n); } else { - printf("%s\n", slv2_value_as_uri(slv2_plugin_get_uri(p))); + printf("%s\n", lilv_value_as_uri(lilv_plugin_get_uri(p))); } } } @@ -41,7 +41,7 @@ void print_version() { printf( - "lv2_list (slv2) " SLV2_VERSION "\n" + "lv2_list (lilv) " LILV_VERSION "\n" "Copyright 2007-2011 David Robillard \n" "License: \n" "This is free software: you are free to change and redistribute it.\n" @@ -81,14 +81,14 @@ main(int argc, char** argv) } } - SLV2World world = slv2_world_new(); - slv2_world_load_all(world); + LilvWorld world = lilv_world_new(); + lilv_world_load_all(world); - SLV2Plugins plugins = slv2_world_get_all_plugins(world); + LilvPlugins plugins = lilv_world_get_all_plugins(world); list_plugins(plugins, show_names); - slv2_world_free(world); + lilv_world_free(world); return 0; } diff --git a/utils/slv2.bash_completion b/utils/slv2.bash_completion deleted file mode 100644 index 921087a..0000000 --- a/utils/slv2.bash_completion +++ /dev/null @@ -1,59 +0,0 @@ -# Bash auto-completion script written for lv2_inspect, lv2_jack_host -# and lv2_simple_jack_host. Could be adapted to any other program -# that takes an LV2 plugin URI as parameter. - -# Written by Lars Luthman on 2009-10-12. -# No copyright claimed for this script. Do what you want with it. - -# For some reason Bash splits the command line not only at whitespace -# but also at ':' signs before putting the parts into COMP_WORDS. -# Since ':' is used in all URIs, which are what we want to complete, -# we have to put the URI back together before we can complete it -# and then cut off the parts we prepended from the completions. -# It probably breaks in some special cases but for most common uses -# it should work fine. - -function _lv2_inspect() { - local uri cur opts w wn raw_reply len type - opts=`lv2_list | xargs -n1 echo -n " "` - - # This is the last "word", as split by Bash. - cur="${COMP_WORDS[COMP_CWORD]}" - w="$cur" - - # Add the previous word while it or this one is a word break character - for i in `seq $(( $COMP_CWORD - 1 )) -1 1`; do - wn="${COMP_WORDS[i]}" - if expr "$COMP_WORDBREAKS" : ".*$wn" > /dev/null; then - if expr "$COMP_WORDBREAKS" : ".*$w" > /dev/null; then - break - fi - fi - w="$wn" - uri="$w$uri" - done - - # Check the length of the words we prepend - len=${#uri} - uri="$uri$cur" - raw_reply="$(compgen -W "${opts}" -- ${uri})" - - # If we are listing alternatives, just print the full URIs. - type=`echo $COMP_TYPE | awk '{ printf "%c", $1 }'` - if expr "?!@%" : ".*$type" > /dev/null; then - COMPREPLY=( $raw_reply ) - return 0 - fi - - # Otherwise, strip the prepended words from all completion suggestions. - COMPREPLY=() - for i in $raw_reply; do - COMPREPLY=( ${COMPREPLY[@]} ${i:len} ) - done -} - -complete -F _lv2_inspect lv2_inspect - -# And the same for lv2_jack_host and lv2_simple_jack_host. -complete -F _lv2_inspect lv2_jack_host -complete -F _lv2_inspect lv2_simple_jack_host diff --git a/utils/slv2_bench.c b/utils/slv2_bench.c deleted file mode 100644 index de1be4e..0000000 --- a/utils/slv2_bench.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright 2007-2011 David Robillard - - 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. -*/ - -#include - -#include "slv2/slv2.h" - -#include "slv2-config.h" - -void -print_version() -{ - printf("slv2_bench (slv2) " SLV2_VERSION "\n"); - printf("Copyright 2011-2011 David Robillard \n"); - printf("License: \n"); - printf("This is free software: you are free to change and redistribute it.\n"); - printf("There is NO WARRANTY, to the extent permitted by law.\n"); -} - -void -print_usage() -{ - printf("Usage: slv2_bench\n"); - printf("Load all discovered LV2 plugins.\n"); -} - -int -main(int argc, char** argv) -{ - SLV2World world = slv2_world_new(); - slv2_world_load_all(world); - - SLV2Plugins plugins = slv2_world_get_all_plugins(world); - SLV2_FOREACH(plugins, p, plugins) { - SLV2Plugin plugin = slv2_plugins_get(plugins, p); - slv2_plugin_get_class(plugin); - } - - slv2_world_free(world); - - return 0; -} diff --git a/waf b/waf index 86ffb67..0b6e94c 100755 Binary files a/waf and b/waf differ diff --git a/wscript b/wscript index 79c7361..f809612 100644 --- a/wscript +++ b/wscript @@ -6,36 +6,19 @@ from waflib.extras import autowaf as autowaf import waflib.Options as Options # Version of this package (even if built as a child) -SLV2_VERSION = '0.7.3' +LILV_VERSION = '0.0.0' +LILV_MAJOR_VERSION = '0' # Library version (UNIX style major, minor, micro) # major increment <=> incompatible changes # minor increment <=> compatible changes (additions) # micro increment <=> no interface changes -# Version history: -# 0.0.1 = 0,0,0 -# 0.1.0 = 2,0,0 -# 0.2.0 = 3,0,0 -# 0.3.0 = 4,0,0 -# 0.3.1 = 4,0,0 -# 0.3.2 = 5,0,1 -# 0.4.0 = 6,0,0 -# 0.4.1 = 6,0,0 (oops, should have been 6,1,0) -# 0.4.2 = 6,0,0 (oops, should have been 6,2,0) -# 0.4.3 = 6,0,0 (oops, should have been 6,3,0) -# 0.4.4 = 7,0,1 -# 0.4.5 = 7,0,1 -# 0.5.0 = 8,0,0 -# 0.6.0 = 9,0,0 (SVN r1282) -# 0.6.1 = 9,1,0 -# 0.6.2 = 9,1,1 -# 0.6.4 = 9,2,0 -# 0.6.6 = 9,2,0 -SLV2_LIB_VERSION = '10.0.0' +# Lilv uses the same version number for both library and package +LILV_LIB_VERSION = LILV_VERSION # Variables for 'waf dist' -APPNAME = 'slv2' -VERSION = SLV2_VERSION +APPNAME = 'lilv' +VERSION = LILV_VERSION # Mandatory variables top = '.' @@ -68,7 +51,7 @@ def options(opt): def configure(conf): conf.line_just = max(conf.line_just, 59) autowaf.configure(conf) - autowaf.display_header('SLV2 Configuration') + autowaf.display_header('Lilv Configuration') conf.load('compiler_cc') conf.load('python') @@ -76,7 +59,7 @@ def configure(conf): try: conf.load('swig python') conf.check_python_headers() - autowaf.define(conf, 'SLV2_SWIG', 1); + autowaf.define(conf, 'LILV_SWIG', 1); except: pass @@ -85,16 +68,14 @@ def configure(conf): atleast_version='2.0.0', mandatory=True) autowaf.check_pkg(conf, 'gthread-2.0', uselib_store='GTHREAD', atleast_version='2.0.0', mandatory=False) - autowaf.check_pkg(conf, 'serd', uselib_store='SERD', - atleast_version='0.1.0', mandatory=True) - autowaf.check_pkg(conf, 'sord', uselib_store='SORD', - atleast_version='0.1.0', mandatory=True) + autowaf.check_pkg(conf, 'serd-0', uselib_store='SERD', + atleast_version='0.2.0', mandatory=True) + autowaf.check_pkg(conf, 'sord-0', uselib_store='SORD', + atleast_version='0.2.0', mandatory=True) autowaf.check_pkg(conf, 'jack', uselib_store='JACK', atleast_version='0.107.0', mandatory=False) autowaf.check_pkg(conf, 'jack', uselib_store='NEW_JACK', atleast_version='0.120.0', mandatory=False) - autowaf.check_pkg(conf, 'suil', uselib_store='SUIL', - atleast_version='0.0.0', mandatory=True) conf.check(function_name='wordexp', header_name='wordexp.h', @@ -105,44 +86,44 @@ def configure(conf): if not Options.options.no_jack_session: if conf.is_defined('HAVE_NEW_JACK') and conf.is_defined('HAVE_GTHREAD'): - autowaf.define(conf, 'SLV2_JACK_SESSION', 1) + autowaf.define(conf, 'LILV_JACK_SESSION', 1) conf.env.append_value('CFLAGS', '-std=c99') - autowaf.define(conf, 'SLV2_VERSION', SLV2_VERSION) + autowaf.define(conf, 'LILV_VERSION', LILV_VERSION) if not Options.options.no_dyn_manifest: - autowaf.define(conf, 'SLV2_DYN_MANIFEST', 1) + autowaf.define(conf, 'LILV_DYN_MANIFEST', 1) - slv2_path_sep = ':' - slv2_dir_sep = '/' + lilv_path_sep = ':' + lilv_dir_sep = '/' if sys.platform == 'win32': - slv2_path_sep = ';' - slv2_dir_sep = '\\\\' + lilv_path_sep = ';' + lilv_dir_sep = '\\\\' - autowaf.define(conf, 'SLV2_PATH_SEP', slv2_path_sep) - autowaf.define(conf, 'SLV2_DIR_SEP', slv2_dir_sep) + autowaf.define(conf, 'LILV_PATH_SEP', lilv_path_sep) + autowaf.define(conf, 'LILV_DIR_SEP', lilv_dir_sep) if Options.options.default_lv2_path == '': if Options.platform == 'darwin': - Options.options.default_lv2_path = slv2_path_sep.join([ + Options.options.default_lv2_path = lilv_path_sep.join([ '~/Library/Audio/Plug-Ins/LV2', '~/.lv2', '/usr/local/lib/lv2', '/usr/lib/lv2', '/Library/Audio/Plug-Ins/LV2']) elif Options.platform == 'haiku': - Options.options.default_lv2_path = slv2_path_sep.join([ + Options.options.default_lv2_path = lilv_path_sep.join([ '~/.lv2', '/boot/common/add-ons/lv2']) elif Options.platform == 'win32': Options.options.default_lv2_path = '%APPDATA%\\\\LV2;%PROGRAMFILES%\\\\LV2' else: libdirname = os.path.basename(conf.env['LIBDIR']) - Options.options.default_lv2_path = slv2_path_sep.join([ + Options.options.default_lv2_path = lilv_path_sep.join([ '~/.lv2', '/usr/%s/lv2' % libdirname, '/usr/local/%s/lv2' % libdirname]) - autowaf.define(conf, 'SLV2_DEFAULT_LV2_PATH', Options.options.default_lv2_path) + autowaf.define(conf, 'LILV_DEFAULT_LV2_PATH', Options.options.default_lv2_path) conf.env['BUILD_TESTS'] = Options.options.build_tests conf.env['BUILD_UTILS'] = not Options.options.no_utils @@ -158,35 +139,35 @@ def configure(conf): if (conf.is_defined('HAVE_LV2_EVENT') and conf.is_defined('HAVE_LV2_EVENT_HELPERS') and conf.is_defined('HAVE_LV2_URI_MAP')): - autowaf.define(conf, 'SLV2_USE_JACK', 1) + autowaf.define(conf, 'LILV_USE_JACK', 1) - conf.write_config_header('slv2-config.h', remove=False) + conf.write_config_header('lilv-config.h', remove=False) autowaf.display_msg(conf, "Default LV2_PATH", - conf.env['SLV2_DEFAULT_LV2_PATH']) + conf.env['LILV_DEFAULT_LV2_PATH']) autowaf.display_msg(conf, "Utilities", bool(conf.env['BUILD_UTILS'])) autowaf.display_msg(conf, "Jack clients", - bool(conf.is_defined('SLV2_USE_JACK'))) + bool(conf.is_defined('LILV_USE_JACK'))) autowaf.display_msg(conf, "Jack session support", - bool(conf.env['SLV2_JACK_SESSION'])) + bool(conf.env['LILV_JACK_SESSION'])) autowaf.display_msg(conf, "Unit tests", bool(conf.env['BUILD_TESTS'])) autowaf.display_msg(conf, "Dynamic manifest support", - bool(conf.env['SLV2_DYN_MANIFEST'])) + bool(conf.env['LILV_DYN_MANIFEST'])) autowaf.display_msg(conf, "Python bindings", - conf.is_defined('SLV2_SWIG')) - autowaf.display_msg(conf, "UI wrapping support (via Suil)", - bool(conf.is_defined('HAVE_SUIL'))) + conf.is_defined('LILV_SWIG')) print('') def build(bld): # C/C++ Headers - bld.install_files('${INCLUDEDIR}/slv2', bld.path.ant_glob('slv2/*.h')) - bld.install_files('${INCLUDEDIR}/slv2', bld.path.ant_glob('slv2/*.hpp')) + includedir = '${INCLUDEDIR}/lilv-%s/lilv' % LILV_MAJOR_VERSION + bld.install_files(includedir, bld.path.ant_glob('lilv/*.h')) + bld.install_files(includedir, bld.path.ant_glob('lilv/*.hpp')) # Pkgconfig file - autowaf.build_pc(bld, 'SLV2', SLV2_VERSION, ['SORD','GLIB']) + autowaf.build_pc(bld, 'LILV', LILV_VERSION, LILV_MAJOR_VERSION, ['SORD','GLIB'], + {'LILV_MAJOR_VERSION' : LILV_MAJOR_VERSION}) lib_source = ''' src/collections.c @@ -213,36 +194,36 @@ def build(bld): export_includes = ['.'], source = lib_source, includes = ['.', './src'], - name = 'libslv2', - target = 'slv2', - vnum = SLV2_LIB_VERSION, + name = 'liblilv', + target = 'lilv-%s' % LILV_MAJOR_VERSION, + vnum = LILV_LIB_VERSION, install_path = '${LIBDIR}', cflags = libflags + [ - '-DSLV2_SHARED', - '-DSLV2_INTERNAL' ], + '-DLILV_SHARED', + '-DLILV_INTERNAL' ], linkflags = linkflags) - autowaf.use_lib(bld, obj, 'SORD SERD LV2CORE GLIB SUIL') + autowaf.use_lib(bld, obj, 'SORD SERD LV2CORE GLIB') if bld.env['BUILD_TESTS']: # Static library (for unit test code coverage) obj = bld(features = 'c cstlib', source = lib_source, includes = ['.', './src'], - name = 'libslv2_static', - target = 'slv2_static', + name = 'liblilv_static', + target = 'lilv_static', install_path = '', - cflags = [ '-fprofile-arcs', '-ftest-coverage', '-DSLV2_INTERNAL' ], + cflags = [ '-fprofile-arcs', '-ftest-coverage', '-DLILV_INTERNAL' ], linkflags = linkflags) - autowaf.use_lib(bld, obj, 'SORD SERD LV2CORE GLIB SUIL') + autowaf.use_lib(bld, obj, 'SORD SERD LV2CORE GLIB') # Unit test program obj = bld(features = 'c cprogram', - source = 'test/slv2_test.c', + source = 'test/lilv_test.c', includes = ['.', './src'], - use = 'libslv2_static', + use = 'liblilv_static', uselib = 'SORD SERD LV2CORE', linkflags = linkflags + ['-lgcov'], - target = 'test/slv2_test', + target = 'test/lilv_test', install_path = '', cflags = [ '-fprofile-arcs', '-ftest-coverage' ]) @@ -251,66 +232,66 @@ def build(bld): utils = ''' utils/lv2_inspect utils/lv2_list - utils/slv2_bench + utils/lilv_bench ''' for i in utils.split(): obj = bld(features = 'c cprogram', source = i + '.c', includes = ['.', './src', './utils'], - use = 'libslv2', + use = 'liblilv', target = i, install_path = '${BINDIR}') # JACK Host - if bld.is_defined('SLV2_USE_JACK'): + if bld.is_defined('LILV_USE_JACK'): obj = bld(features = 'c cprogram', source = 'utils/lv2_jack_host.c', includes = ['.', './src', './utils'], uselib = 'JACK', - use = 'libslv2', + use = 'liblilv', target = 'utils/lv2_jack_host', install_path = '${BINDIR}') - if bld.is_defined('SLV2_JACK_SESSION'): + if bld.is_defined('LILV_JACK_SESSION'): autowaf.use_lib(bld, obj, 'GLIB GTHREAD') # Documentation - autowaf.build_dox(bld, 'SLV2', SLV2_VERSION, top, out) + autowaf.build_dox(bld, 'LILV', LILV_VERSION, top, out) # Bash completion if bld.env['BASH_COMPLETION']: bld.install_as( - '/etc/bash_completion.d/slv2', 'utils/slv2.bash_completion') + '/etc/bash_completion.d/lilv', 'utils/lilv.bash_completion') - if bld.is_defined('SLV2_SWIG'): + if bld.is_defined('LILV_SWIG'): # Python Wrapper obj = bld(features = 'cxx cxxshlib pyext', - source = 'swig/slv2.i', - target = 'swig/_slv2', + source = 'swig/lilv.i', + target = 'swig/_lilv', includes = ['..'], - swig_flags = '-c++ -python -Wall -I.. -lslv2 -features autodoc=1', - vnum = SLV2_LIB_VERSION, - use = 'libslv2') - autowaf.use_lib(bld, obj, 'SLV2') + swig_flags = '-c++ -python -Wall -I.. -llilv -features autodoc=1', + vnum = LILV_LIB_VERSION, + use = 'liblilv') + autowaf.use_lib(bld, obj, 'LILV') - bld.install_files('${PYTHONDIR}', 'swig/slv2.py') + bld.install_files('${PYTHONDIR}', 'swig/lilv.py') bld.add_post_fun(autowaf.run_ldconfig) def fix_docs(ctx): try: os.chdir('build/doc/html') - os.system("sed -i 's/SLV2_API //' group__slv2.html") - os.system("sed -i 's/SLV2_DEPRECATED //' group__slv2.html") + os.system("sed -i 's/LILV_API //' group__lilv.html") + os.system("sed -i 's/LILV_DEPRECATED //' group__lilv.html") os.remove('index.html') - os.symlink('group__slv2.html', + os.symlink('group__lilv.html', 'index.html') except Exception, e: Logs.error("Failed to fix up Doxygen documentation (%s)\n" % e) def upload_docs(ctx): - os.system("rsync -avz --delete -e ssh build/doc/html/* drobilla@drobilla.net:~/drobilla.net/docs/slv2") + os.system("rsync -avz --delete -e ssh build/doc/html/* drobilla@drobilla.net:~/drobilla.net/docs/lilv") def test(ctx): autowaf.pre_test(ctx, APPNAME) - autowaf.run_tests(ctx, APPNAME, ['test/slv2_test'], dirs=['./src','./test']) + autowaf.run_tests(ctx, APPNAME, ['test/lilv_test'], dirs=['./src','./test']) autowaf.post_test(ctx, APPNAME) -- cgit v1.2.1