summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-04-20 21:25:38 +0000
committerDavid Robillard <d@drobilla.net>2007-04-20 21:25:38 +0000
commit09e5c017b096bc84bbbc0b273baffd221144213a (patch)
tree9a591b9b23132cd0e98e5ec85a20256290e5a141
parent500fab47e5e9aadb6e09a71a6c3447e97f3a6d6a (diff)
downloadlilv-09e5c017b096bc84bbbc0b273baffd221144213a.tar.gz
lilv-09e5c017b096bc84bbbc0b273baffd221144213a.tar.bz2
lilv-09e5c017b096bc84bbbc0b273baffd221144213a.zip
Preliminary categories support.
git-svn-id: http://svn.drobilla.net/lad/slv2@465 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--data/lv2.ttl55
-rw-r--r--slv2/Makefile.am2
-rw-r--r--slv2/categories.h80
-rw-r--r--slv2/category.h70
-rw-r--r--slv2/plugin.h6
-rw-r--r--slv2/slv2.h1
-rw-r--r--slv2/types.h4
-rw-r--r--src/Makefile.am2
-rw-r--r--src/categories.c90
-rw-r--r--src/category.c57
-rw-r--r--src/plugin.c41
-rw-r--r--src/pluginlist.c6
-rw-r--r--src/private_types.h24
-rw-r--r--src/query.c21
-rw-r--r--src/world.c67
-rw-r--r--utils/lv2_inspect.c3
16 files changed, 458 insertions, 71 deletions
diff --git a/data/lv2.ttl b/data/lv2.ttl
index d0d9f94..91f6fd2 100644
--- a/data/lv2.ttl
+++ b/data/lv2.ttl
@@ -1,7 +1,7 @@
# RDF Schema for LV2 plugins
# *** PROVISIONAL ***
#
-# *** PROPOSED Revision 2007-02-19 ***
+# *** PROPOSED Revision 2007-04-20 ***
#
# This document describes the classes and properties that are defined by the
# core LV2 specification. See <http://lv2plug.in> for more information.
@@ -41,8 +41,8 @@
doap:shortdesc "An audio processing plugin specification" ;
doap:programming-language "C" ;
doap:release [
- doap:revision "1.0beta1" ;
- doap:created "2007-02-03"
+ doap:revision "1.0beta2" ;
+ doap:created "2007-04-20"
] ;
doap:maintainer [
a foaf:Person ;
@@ -52,7 +52,8 @@
] , [
a foaf:Person ;
foaf:name "Dave Robillard" ;
- rdfs:seeAlso <http://drobilla.net/drobilla.ttl>
+ foaf:homepage <http://drobilla.net/> ;
+ rdfs:seeAlso <http://drobilla.net/drobilla.xrdf>
].
@@ -468,32 +469,32 @@ A plugin MUST operate reasonably even if such a port has a non-integer input.
:UtilityPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Utilities" ;
+ rdfs:label "Utility" ;
rdfs:comment """
Includes things like mathematical functions and non-musical delays.
""" .
:GeneratorPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Generators" ;
+ rdfs:label "Generator" ;
rdfs:comment """
Any plugin that generates sound internally, rather than processing its input.
""" .
:InstrumentPlugin a rdfs:Class ;
rdfs:subClassOf :GeneratorPlugin ;
- rdfs:label "Instruments" ;
+ rdfs:label "Instrument" ;
rdfs:comment """
Any plugin that is intended to be played as a musical instrument.
""" .
:OscillatorPlugin a rdfs:Class ;
rdfs:subClassOf :GeneratorPlugin ;
- rdfs:label "Oscillators" .
+ rdfs:label "Oscillator" .
:SimulatorPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Simulators" ;
+ rdfs:label "Simulator" ;
rdfs:comment """
Plugins that aim to duplicate the effect of some environmental effect or
musical equipment.
@@ -501,18 +502,18 @@ musical equipment.
:DelayPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Delays" ;
+ rdfs:label "Delay" ;
rdfs:comment """
Plugins that intentionally delay their input signal as an effect.
""" .
:PhaserPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Phasers" .
+ rdfs:label "Phaser" .
:FlangerPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Flangers" .
+ rdfs:label "Flanger" .
:ChorusPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
@@ -526,7 +527,7 @@ Plugins that intentionally delay their input signal as an effect.
:FilterPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Filters" .
+ rdfs:label "Filter" .
:LowpassPlugin a rdfs:Class ;
rdfs:subClassOf :FilterPlugin ;
@@ -542,7 +543,7 @@ Plugins that intentionally delay their input signal as an effect.
:CombPlugin a rdfs:Class ;
rdfs:subClassOf :FilterPlugin ;
- rdfs:label "Combs" .
+ rdfs:label "Comb" .
:AllpassPlugin a rdfs:Class ;
rdfs:subClassOf :FilterPlugin ;
@@ -550,55 +551,55 @@ Plugins that intentionally delay their input signal as an effect.
:EQPlugin a rdfs:Class ;
rdfs:subClassOf :FilterPlugin ;
- rdfs:label "Equalisers" .
+ rdfs:label "Equaliser" .
:ParaEQPlugin a rdfs:Class ;
rdfs:subClassOf :EQPlugin ;
- rdfs:label "Parametrics" .
+ rdfs:label "Parametric" .
:MultiEQPlugin a rdfs:Class ;
rdfs:subClassOf :EQPlugin ;
- rdfs:label "Multibands" .
+ rdfs:label "Multiband" .
:PitchPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Pitch Shifters" .
+ rdfs:label "Pitch Shifter" .
:AmplifierPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Amplifiers" .
+ rdfs:label "Amplifier" .
:WaveshaperPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Waveshapers" .
+ rdfs:label "Waveshaper" .
:ModulatorPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Modulators" .
+ rdfs:label "Modulator" .
:DistortionPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Distortions" .
+ rdfs:label "Distortion" .
:DynamicsPlugin a rdfs:Class ;
rdfs:subClassOf :Plugin ;
- rdfs:label "Dynamics processors" ;
+ rdfs:label "Dynamics processor" ;
rdfs:comment """
Plugins that alter the envelope or dynamic range of the processed audio.
""" .
:CompressorPlugin a rdfs:Class ;
rdfs:subClassOf :DynamicsPlugin ;
- rdfs:label "Compressors" .
+ rdfs:label "Compressor" .
:ExpanderPlugin a rdfs:Class ;
rdfs:subClassOf :DynamicsPlugin ;
- rdfs:label "Expanders" .
+ rdfs:label "Expander" .
:LimiterPlugin a rdfs:Class ;
rdfs:subClassOf :DynamicsPlugin ;
- rdfs:label "Limiters" .
+ rdfs:label "Limiter" .
:GatePlugin a rdfs:Class ;
rdfs:subClassOf :DynamicsPlugin ;
- rdfs:label "Gates" .
+ rdfs:label "Gate" .
diff --git a/slv2/Makefile.am b/slv2/Makefile.am
index e20cde8..8e1b827 100644
--- a/slv2/Makefile.am
+++ b/slv2/Makefile.am
@@ -5,6 +5,8 @@ slv2include_HEADERS = \
types.h \
slv2.h \
world.h \
+ category.h \
+ categories.h \
plugin.h \
port.h \
pluginlist.h \
diff --git a/slv2/categories.h b/slv2/categories.h
new file mode 100644
index 0000000..44b9aee
--- /dev/null
+++ b/slv2/categories.h
@@ -0,0 +1,80 @@
+/* SLV2
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * 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.
+ */
+
+#ifndef __SLV2_CATEGORIES_H__
+#define __SLV2_CATEGORIES_H__
+
+#include <slv2/category.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef void* SLV2Categories;
+
+
+/** \defgroup categories Categories
+ *
+ * @{
+ */
+
+/** Get the number of plugins in the list.
+ */
+unsigned
+slv2_categories_size(SLV2Categories list);
+
+
+/** Get a category from the list by URI.
+ *
+ * Return value is shared (stored in \a list) and must not be freed or
+ * modified by the caller in any way.
+ *
+ * Time = O(log2(n))
+ *
+ * \return NULL if plugin with \a url not found in \a list.
+ */
+SLV2Category
+slv2_categories_get_by_uri(SLV2Categories list,
+ const char* uri);
+
+
+/** Get a plugin from the list by index.
+ *
+ * \a index has no significance other than as an index into this list.
+ * Any \a index not less than slv2_categories_get_length(list) will return NULL,
+ * so all categories in a list can be enumerated by repeated calls
+ * to this function starting with \a index = 0.
+ *
+ * Time = O(1)
+ *
+ * \return NULL if \a index out of range.
+ */
+SLV2Category
+slv2_categories_get_at(SLV2Categories list,
+ unsigned index);
+
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SLV2_CATEGORIES_H__ */
+
diff --git a/slv2/category.h b/slv2/category.h
new file mode 100644
index 0000000..1d0159f
--- /dev/null
+++ b/slv2/category.h
@@ -0,0 +1,70 @@
+/* SLV2
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * 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.
+ */
+
+#ifndef __SLV2_CATEGORY_H__
+#define __SLV2_CATEGORY_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <slv2/types.h>
+
+/** \addtogroup data
+ * @{
+ */
+
+
+/** Get the URI of this category.
+ *
+ * Returned value is owned by \a category and must not be freed by caller.
+ *
+ * Time = O(1)
+ */
+const char* slv2_category_get_uri(SLV2Category category);
+
+
+/** Get the label of this category, ie "Oscillators".
+ *
+ * Returned value is owned by \a category and must not be freed by caller.
+ *
+ * Time = O(1)
+ */
+const char* slv2_category_get_label(SLV2Category category);
+
+#if 0
+/** Get the path of this category, ie "Plugins/Generators/Oscillators".
+ *
+ * SLV2 automatically generates an ideal category heirarchy given the plugins
+ * present. The last fragment of the path is the category's label,
+ * as returned by slv2_category_get_label.
+ *
+ * Returned value is owned by \a category and must not be freed by caller.
+ *
+ * Time = O(1)
+ */
+const char* slv2_category_get_path(SLV2Category category);
+#endif
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SLV2_CATEGORY_H__ */
diff --git a/slv2/plugin.h b/slv2/plugin.h
index 30394d3..4db5130 100644
--- a/slv2/plugin.h
+++ b/slv2/plugin.h
@@ -134,6 +134,12 @@ char*
slv2_plugin_get_name(SLV2Plugin plugin);
+/** Get the category this plugin belongs to.
+ */
+SLV2Category
+slv2_plugin_get_category(SLV2Plugin plugin);
+
+
/** Get a value associated with the plugin in a plugin's data files.
*
* Returns the ?object of all triples found of the form:
diff --git a/slv2/slv2.h b/slv2/slv2.h
index 431bd17..a052e56 100644
--- a/slv2/slv2.h
+++ b/slv2/slv2.h
@@ -25,6 +25,7 @@ extern "C" {
#include <slv2/types.h>
#include <slv2/world.h>
+#include <slv2/category.h>
#include <slv2/plugin.h>
#include <slv2/port.h>
#include <slv2/pluginlist.h>
diff --git a/slv2/types.h b/slv2/types.h
index c22b2be..f595dd1 100644
--- a/slv2/types.h
+++ b/slv2/types.h
@@ -56,6 +56,10 @@ typedef struct _Plugin* SLV2Plugin;
typedef struct _World* SLV2World;
+/** A plugin category. Opaque, but valid to compare to NULL. */
+typedef struct _Category* SLV2Category;
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 8009ff8..cc5a774 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,8 @@ libslv2_la_LIBADD = @REDLAND_LIBS@
libslv2_la_SOURCES = \
private_types.h \
world.c \
+ category.c \
+ categories.c \
plugin.c \
query.c \
port.c \
diff --git a/src/categories.c b/src/categories.c
new file mode 100644
index 0000000..133e7ee
--- /dev/null
+++ b/src/categories.c
@@ -0,0 +1,90 @@
+/* SLV2
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * 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 500
+
+#include <string.h>
+#include <limits.h>
+#include <librdf.h>
+#include <slv2/category.h>
+#include <slv2/categories.h>
+#include "private_types.h"
+
+
+SLV2Categories
+slv2_categories_new()
+{
+ return raptor_new_sequence((void (*)(void*))&slv2_category_free, NULL);
+}
+
+
+void
+slv2_categories_free(SLV2Categories list)
+{
+ //if (list != world->categories)
+ raptor_free_sequence(list);
+}
+
+
+unsigned
+slv2_categories_size(SLV2Categories list)
+{
+ return raptor_sequence_size(list);
+}
+
+
+SLV2Category
+slv2_categories_get_by_uri(SLV2Categories list, const char* uri)
+{
+ // good old fashioned binary search
+
+ int lower = 0;
+ int upper = raptor_sequence_size(list) - 1;
+ int i;
+
+ if (upper == 0)
+ return NULL;
+
+ while (upper >= lower) {
+ i = lower + ((upper - lower) / 2);
+
+ SLV2Category p = raptor_sequence_get_at(list, i);
+
+ int cmp = strcmp(slv2_category_get_uri(p), uri);
+
+ if (cmp == 0)
+ return p;
+ else if (cmp > 0)
+ upper = i - 1;
+ else
+ lower = i + 1;
+ }
+
+ return NULL;
+}
+
+
+SLV2Category
+slv2_categories_get_at(SLV2Categories list, unsigned index)
+{
+ if (index > INT_MAX)
+ return NULL;
+ else
+ return (SLV2Category)raptor_sequence_get_at(list, (int)index);
+}
+
diff --git a/src/category.c b/src/category.c
new file mode 100644
index 0000000..5eae2af
--- /dev/null
+++ b/src/category.c
@@ -0,0 +1,57 @@
+/* SLV2
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * 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 500
+
+#include <stdlib.h>
+#include <string.h>
+#include <slv2/category.h>
+#include "private_types.h"
+
+
+SLV2Category
+slv2_category_new(const char* uri, const char* label)
+{
+ SLV2Category category = (SLV2Category)malloc(sizeof(struct _Category));
+ category->uri = strdup(uri);
+ category->label = strdup(label);
+ return category;
+}
+
+
+void
+slv2_category_free(SLV2Category category)
+{
+ free(category->uri);
+ free(category->label);
+ free(category);
+}
+
+
+const char*
+slv2_category_get_uri(SLV2Category category)
+{
+ return category->uri;
+}
+
+
+const char*
+slv2_category_get_label(SLV2Category category)
+{
+ return category->label;
+}
diff --git a/src/plugin.c b/src/plugin.c
index 722caa1..7fe8e1d 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -37,6 +37,7 @@ slv2_plugin_new(SLV2World world, librdf_uri* uri, const char* binary_uri)
plugin->world = world;
plugin->plugin_uri = librdf_new_uri_from_uri(uri);
plugin->binary_uri = strdup(binary_uri);
+ plugin->category = NULL;
plugin->data_uris = slv2_strings_new();
plugin->ports = raptor_new_sequence((void (*)(void*))&slv2_port_free, NULL);
plugin->storage = NULL;
@@ -145,8 +146,32 @@ slv2_plugin_load(SLV2Plugin p)
librdf_free_uri(data_uri);
}
- // Load ports
+ // Load category
const unsigned char* query = (const unsigned char*)
+ "SELECT DISTINCT ?class WHERE { <> a ?class }";
+
+ librdf_query* q = librdf_new_query(p->world->world, "sparql",
+ NULL, query, p->plugin_uri);
+
+ librdf_query_results* results = librdf_query_execute(q, p->rdf);
+
+ while (!librdf_query_results_finished(results)) {
+ librdf_node* class_node = librdf_query_results_get_binding_value(results, 0);
+ librdf_uri* class_uri = librdf_node_get_uri(class_node);
+ const char* class_uri_str = (const char*)librdf_uri_as_string(class_uri);
+
+ SLV2Category category = slv2_categories_get_by_uri(p->world->categories, class_uri_str);
+
+ if (category) {
+ p->category = category;
+ break;
+ }
+
+ librdf_query_results_next(results);
+ }
+
+ // Load ports
+ query = (const unsigned char*)
"PREFIX : <http://lv2plug.in/ontology#>\n"
"SELECT DISTINCT ?port ?symbol ?index WHERE {\n"
"<> :port ?port .\n"
@@ -154,10 +179,10 @@ slv2_plugin_load(SLV2Plugin p)
" :index ?index .\n"
"}";
- librdf_query* q = librdf_new_query(p->world->world, "sparql",
+ q = librdf_new_query(p->world->world, "sparql",
NULL, query, p->plugin_uri);
- librdf_query_results* results = librdf_query_execute(q, p->rdf);
+ results = librdf_query_execute(q, p->rdf);
while (!librdf_query_results_finished(results)) {
@@ -217,6 +242,16 @@ slv2_plugin_get_library_uri(SLV2Plugin p)
}
+SLV2Category
+slv2_plugin_get_category(SLV2Plugin p)
+{
+ if (!p->category)
+ slv2_plugin_load(p);
+
+ return p->category;
+}
+
+
bool
slv2_plugin_verify(SLV2Plugin plugin)
{
diff --git a/src/pluginlist.c b/src/pluginlist.c
index d4cd058..da003a5 100644
--- a/src/pluginlist.c
+++ b/src/pluginlist.c
@@ -17,13 +17,11 @@
*/
#define _XOPEN_SOURCE 500
-#include <limits.h>
#include <string.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/types.h>
#include <assert.h>
-#include <dirent.h>
#include <librdf.h>
#include <slv2/types.h>
#include <slv2/plugin.h>
@@ -308,8 +306,6 @@ slv2_plugins_get_by_uri(SLV2Plugins list, const char* uri)
SLV2Plugin
slv2_plugins_get_at(SLV2Plugins list, unsigned index)
{
- assert(list);
-
if (index > INT_MAX)
return NULL;
else
diff --git a/src/private_types.h b/src/private_types.h
index 48bed0a..ff4580c 100644
--- a/src/private_types.h
+++ b/src/private_types.h
@@ -27,6 +27,7 @@ extern "C" {
#include <stddef.h>
#include <librdf.h>
#include <slv2/pluginlist.h>
+#include <slv2/categories.h>
/** Reference to a port on some plugin.
@@ -53,6 +54,7 @@ struct _Plugin {
librdf_uri* plugin_uri;
// char* bundle_url; // Bundle directory plugin was loaded from
char* binary_uri; // lv2:binary
+ SLV2Category category;
raptor_sequence* data_uris; // rdfs::seeAlso
raptor_sequence* ports;
librdf_storage* storage;
@@ -78,14 +80,26 @@ struct _InstanceImpl {
};
+struct _Category {
+ char* uri;
+ char* label;
+};
+
+SLV2Category slv2_category_new(const char* uri, const char* label);
+void slv2_category_free(SLV2Category category);
+
+SLV2Categories slv2_categories_new();
+void slv2_categories_free();
+
/** Model of LV2 (RDF) data loaded from bundles.
*/
struct _World {
- librdf_world* world;
- librdf_storage* storage;
- librdf_model* model;
- librdf_parser* parser;
- SLV2Plugins plugins;
+ librdf_world* world;
+ librdf_storage* storage;
+ librdf_model* model;
+ librdf_parser* parser;
+ SLV2Categories categories;
+ SLV2Plugins plugins;
};
/** Load all bundles found in \a search_path.
diff --git a/src/query.c b/src/query.c
index 968834c..56a7412 100644
--- a/src/query.c
+++ b/src/query.c
@@ -132,19 +132,6 @@ slv2_plugin_query(SLV2Plugin plugin,
return NULL;
}
- // Add LV2 ontology to query sources
- //librdf_query_add_data_graph(rq, slv2_ontology_uri,
- // NULL, RASQAL_DATA_GRAPH_BACKGROUND);
-
- // Add all plugin data files to query sources
- /*for (unsigned i=0; i < slv2_strings_size(plugin->data_uris); ++i) {
- const char* file_uri_str = slv2_strings_get_at(plugin->data_uris, i);
- raptor_uri* file_uri = raptor_new_uri((const unsigned char*)file_uri_str);
- librdf_query_add_data_graph(rq, file_uri,
- NULL, RASQAL_DATA_GRAPH_BACKGROUND);
- raptor_free_uri(file_uri);
- }*/
-
librdf_query_results* results = librdf_query_execute(rq, plugin->rdf);
librdf_free_query(rq);
@@ -190,7 +177,7 @@ slv2_plugin_query_count(SLV2Plugin plugin,
}
}
-
+/*
size_t
slv2_query_count_results(SLV2Plugin p,
const char* query)
@@ -205,10 +192,6 @@ slv2_query_count_results(SLV2Plugin p,
//printf("Query: \n%s\n\n", query_str);
- // Add LV2 ontology to query sources
- //librdf_query_add_data_graph(rq, slv2_ontology_uri,
- // NULL, RASQAL_DATA_GRAPH_BACKGROUND);
-
librdf_query_results* results = librdf_query_execute(rq, p->world->model);
assert(results);
@@ -221,4 +204,4 @@ slv2_query_count_results(SLV2Plugin p,
return count;
}
-
+*/
diff --git a/src/world.c b/src/world.c
index a682a35..c8735ea 100644
--- a/src/world.c
+++ b/src/world.c
@@ -44,11 +44,10 @@ slv2_world_new()
world->parser = librdf_new_parser(world->world, "turtle", NULL, NULL);
+ world->categories = slv2_categories_new();
+
world->plugins = slv2_plugins_new();
- /*slv2_ontology_uri = raptor_new_uri((const unsigned char*)
- "file://" LV2_TTL_PATH);*/
-
return world;
}
@@ -56,14 +55,14 @@ slv2_world_new()
void
slv2_world_free(SLV2World world)
{
- /*raptor_free_uri(slv2_ontology_uri);
- slv2_ontology_uri = NULL;*/
-
for (int i=0; i < raptor_sequence_size(world->plugins); ++i)
slv2_plugin_free(raptor_sequence_get_at(world->plugins, i));
raptor_free_sequence(world->plugins);
world->plugins = NULL;
+ slv2_categories_free(world->categories);
+ world->categories = NULL;
+
librdf_free_parser(world->parser);
world->parser = NULL;
@@ -163,29 +162,73 @@ slv2_plugin_compare_by_uri(const void* a, const void* b)
}
*/
+
+void
+slv2_world_load_categories(SLV2World world)
+{
+ // FIXME: This will need to be a bit more clever when more data is around
+ // then the ontology (ie classes which aren't LV2 categories)
+
+ unsigned char* query_string = (unsigned char*)
+ "PREFIX : <http://lv2plug.in/ontology#>\n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
+ "SELECT DISTINCT ?category ?label\n"
+ "WHERE { ?category a rdfs:Class; rdfs:label ?label }\n"
+ "ORDER BY ?category\n";
+
+ librdf_query* q = librdf_new_query(world->world, "sparql",
+ NULL, query_string, NULL);
+
+ librdf_query_results* results = librdf_query_execute(q, world->model);
+
+ while (!librdf_query_results_finished(results)) {
+ librdf_node* category_node = librdf_query_results_get_binding_value(results, 0);
+ librdf_uri* category_uri = librdf_node_get_uri(category_node);
+ librdf_node* label_node = librdf_query_results_get_binding_value(results, 1);
+ const char* label = (const char*)librdf_node_get_literal_value(label_node);
+
+ //printf("CATEGORY: %s (%s)\n", librdf_uri_as_string(category_uri), label);
+ SLV2Category category = slv2_category_new(
+ (const char*)librdf_uri_as_string(category_uri),
+ label);
+ raptor_sequence_push(world->categories, category);
+
+ librdf_query_results_next(results);
+ }
+
+}
+
+
void
slv2_world_load_all(SLV2World world)
{
char* lv2_path = getenv("LV2_PATH");
- /* 1. Read all manifest files into model */
+ /* 1. Read LV2 ontology into model */
+ librdf_uri* ontology_uri = librdf_new_uri(world->world,
+ (const unsigned char*)"file://" LV2_TTL_PATH);
+ librdf_parser_parse_into_model(world->parser, ontology_uri, NULL, world->model);
+ librdf_free_uri(ontology_uri);
+
+
+ /* 2. Read all manifest files into model */
if (lv2_path) {
slv2_world_load_path(world, lv2_path);
} else {
const char* const home = getenv("HOME");
- const char* const suffix = "/.lv2:/usr/local/lib/lv2:usr/lib/lv2";
+ const char* const suffix = "/.lv2:/usr/local/lib/lv2:/usr/lib/lv2";
lv2_path = slv2_strjoin(home, suffix, NULL);
- //fprintf(stderr, "$LV2_PATH is unset. Using default path %s\n", lv2_path);
-
slv2_world_load_path(world, lv2_path);
free(lv2_path);
}
- /* 2. Query out things to cache */
+ /* 3. Query out things to cache */
+
+ slv2_world_load_categories(world);
// Find all plugins and associated data files
unsigned char* query_string = (unsigned char*)
@@ -233,7 +276,7 @@ slv2_world_load_all(SLV2World world)
librdf_query_results_next(results);
}
- // ORDER BY should (and appears to actually) guarantee this
+ // 'ORDER BY ?plugin' guarantees this
//raptor_sequence_sort(world->plugins, slv2_plugin_compare_by_uri);
if (results)
diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c
index 710b791..75b6fac 100644
--- a/utils/lv2_inspect.c
+++ b/utils/lv2_inspect.c
@@ -96,6 +96,9 @@ print_plugin(SLV2Plugin p)
str = slv2_plugin_get_name(p);
printf("\tName: %s\n\n", str);
free(str);
+
+ const char* class_label = slv2_category_get_label(slv2_plugin_get_category(p));
+ printf("\tClass: %s\n\n", class_label);
if (slv2_plugin_has_latency(p))
printf("\tHas latency: yes\n\n");