summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slv2/pluginclass.h22
-rw-r--r--slv2/pluginclasses.h3
-rw-r--r--slv2/types.h4
-rw-r--r--slv2/world.h8
-rw-r--r--src/plugin.c18
-rw-r--r--src/pluginclass.c31
-rw-r--r--src/private_types.h9
-rw-r--r--src/world.c38
8 files changed, 103 insertions, 30 deletions
diff --git a/slv2/pluginclass.h b/slv2/pluginclass.h
index 1124bd8..7260d7d 100644
--- a/slv2/pluginclass.h
+++ b/slv2/pluginclass.h
@@ -30,6 +30,15 @@ extern "C" {
*/
+/** Get the URI of this class' superclass.
+ *
+ * Returned value is owned by \a plugin_class and must not be freed by caller.
+ *
+ * Time = O(1)
+ */
+const char* 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.
@@ -39,7 +48,7 @@ extern "C" {
const char* slv2_plugin_class_get_uri(SLV2PluginClass plugin_class);
-/** Get the label of this plugin_class, ie "Oscillators".
+/** Get the label of this plugin class, ie "Oscillators".
*
* Returned value is owned by \a plugin_class and must not be freed by caller.
*
@@ -47,6 +56,17 @@ const char* slv2_plugin_class_get_uri(SLV2PluginClass plugin_class);
*/
const char* 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.
+ *
+ * Time = O(nclasses)
+ */
+SLV2PluginClasses
+slv2_plugin_class_get_children(SLV2PluginClass plugin_class);
+
+
#if 0
/** Get the path of this plugin_class, ie "Plugins/Generators/Oscillators".
*
diff --git a/slv2/pluginclasses.h b/slv2/pluginclasses.h
index 39177b8..a9dbdc5 100644
--- a/slv2/pluginclasses.h
+++ b/slv2/pluginclasses.h
@@ -26,9 +26,6 @@ extern "C" {
#endif
-typedef void* SLV2PluginClasses;
-
-
/** \defgroup plugin_classes Plugin classes (categories)
*
* @{
diff --git a/slv2/types.h b/slv2/types.h
index 42f2e59..7e965be 100644
--- a/slv2/types.h
+++ b/slv2/types.h
@@ -60,6 +60,10 @@ typedef struct _World* SLV2World;
typedef struct _PluginClass* SLV2PluginClass;
+/** A collection of plugin classes. Opaque, but valid to compare to NULL. */
+typedef void* SLV2PluginClasses;
+
+
#ifdef __cplusplus
}
#endif
diff --git a/slv2/world.h b/slv2/world.h
index 59b0adc..08acd2b 100644
--- a/slv2/world.h
+++ b/slv2/world.h
@@ -103,6 +103,14 @@ slv2_world_load_bundle(SLV2World world,
const char* bundle_uri);
+/** Get the parent of all other plugin classes, lv2:Plugin.
+ *
+ * Time = O(1)
+ */
+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.
diff --git a/src/plugin.c b/src/plugin.c
index 6216ab7..6d8dc87 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -172,7 +172,7 @@ slv2_plugin_load(SLV2Plugin p)
}
if (p->plugin_class == NULL)
- fprintf(stderr, "Warning: Unclassy plugin: %s\n", slv2_plugin_get_uri(p));
+ p->plugin_class = raptor_sequence_get_at(p->world->plugin_classes, 0); // lv2:Plugin
// Load ports
query = (const unsigned char*)
@@ -247,9 +247,12 @@ slv2_plugin_get_library_uri(SLV2Plugin p)
SLV2PluginClass
-slv2_plugin_get_plugin_class(SLV2Plugin p)
+slv2_plugin_get_class(SLV2Plugin p)
{
- if (!p->plugin_class)
+ // FIXME: Typical use case this will bring every single plugin model
+ // into memory
+
+ if (!p->rdf)
slv2_plugin_load(p);
return p->plugin_class;
@@ -329,15 +332,6 @@ slv2_plugin_get_name(SLV2Plugin plugin)
}
-/** Get the class this plugin belongs to (ie Filters).
- */
-SLV2PluginClass
-slv2_plugin_get_class(SLV2Plugin plugin)
-{
- return plugin->plugin_class;
-}
-
-
SLV2Strings
slv2_plugin_get_value(SLV2Plugin p,
const char* predicate)
diff --git a/src/pluginclass.c b/src/pluginclass.c
index 3669b9b..80e96c4 100644
--- a/src/pluginclass.c
+++ b/src/pluginclass.c
@@ -25,9 +25,14 @@
SLV2PluginClass
-slv2_plugin_class_new(const char* uri, const char* label)
+slv2_plugin_class_new(SLV2World world, const char* parent_uri, const char* uri, const char* label)
{
SLV2PluginClass plugin_class = (SLV2PluginClass)malloc(sizeof(struct _PluginClass));
+ plugin_class->world = world;
+ if (parent_uri)
+ plugin_class->parent_uri = strdup(parent_uri);
+ else
+ plugin_class->parent_uri = NULL;
plugin_class->uri = strdup(uri);
plugin_class->label = strdup(label);
return plugin_class;
@@ -44,6 +49,13 @@ slv2_plugin_class_free(SLV2PluginClass plugin_class)
const char*
+slv2_plugin_class_get_parent_uri(SLV2PluginClass plugin_class)
+{
+ return plugin_class->parent_uri;
+}
+
+
+const char*
slv2_plugin_class_get_uri(SLV2PluginClass plugin_class)
{
return plugin_class->uri;
@@ -55,3 +67,20 @@ slv2_plugin_class_get_label(SLV2PluginClass plugin_class)
{
return plugin_class->label;
}
+
+
+SLV2PluginClasses
+slv2_plugin_class_get_children(SLV2PluginClass plugin_class)
+{
+ // Returned list doesn't own categories
+ SLV2PluginClasses result = raptor_new_sequence(NULL, NULL);
+
+ for (int i=0; i < raptor_sequence_size(plugin_class->world->plugin_classes); ++i) {
+ SLV2PluginClass c = raptor_sequence_get_at(plugin_class->world->plugin_classes, i);
+ const char* parent = slv2_plugin_class_get_parent_uri(c);
+ if (parent && !strcmp(slv2_plugin_class_get_uri(plugin_class), parent))
+ raptor_sequence_push(result, c);
+ }
+
+ return result;
+}
diff --git a/src/private_types.h b/src/private_types.h
index a0337ac..baf5100 100644
--- a/src/private_types.h
+++ b/src/private_types.h
@@ -81,11 +81,14 @@ struct _InstanceImpl {
struct _PluginClass {
- char* uri;
- char* label;
+ struct _World* world;
+ char* parent_uri;
+ char* uri;
+ char* label;
};
-SLV2PluginClass slv2_plugin_class_new(const char* uri, const char* label);
+SLV2PluginClass slv2_plugin_class_new(SLV2World world,
+ const char* parent_uri, const char* uri, const char* label);
void slv2_plugin_class_free(SLV2PluginClass class);
SLV2PluginClasses slv2_plugin_classes_new();
diff --git a/src/world.c b/src/world.c
index d4d47b2..90a604f 100644
--- a/src/world.c
+++ b/src/world.c
@@ -46,6 +46,11 @@ slv2_world_new()
world->plugin_classes = slv2_plugin_classes_new();
+ // Add the ever-present lv2:Plugin to classes
+ static const char* lv2_plugin_uri = "http://lv2plug.in/ontology#Plugin";
+ raptor_sequence_push(world->plugin_classes, slv2_plugin_class_new(
+ world, NULL, lv2_plugin_uri, "Plugin"));
+
world->plugins = slv2_plugins_new();
return world;
@@ -169,12 +174,14 @@ slv2_world_load_plugin_classes(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 plugin_classes)
+ // FIXME: This loads things that aren't plugin 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 ?class ?label WHERE {\n"
+ "SELECT DISTINCT ?class ?parent ?label WHERE {\n"
//" ?plugin a :Plugin; a ?class .\n"
- " ?class a rdfs:Class; rdfs:label ?label\n"
+ " ?class a rdfs:Class; rdfs:subClassOf ?parent; rdfs:label ?label\n"
"} ORDER BY ?class\n";
librdf_query* q = librdf_new_query(world->world, "sparql",
@@ -183,21 +190,25 @@ slv2_world_load_plugin_classes(SLV2World world)
librdf_query_results* results = librdf_query_execute(q, world->model);
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);
- 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("CLASS: %s (%s)\n", librdf_uri_as_string(class_uri), label);
+ librdf_node* class_node = librdf_query_results_get_binding_value(results, 0);
+ librdf_uri* class_uri = librdf_node_get_uri(class_node);
+ librdf_node* parent_node = librdf_query_results_get_binding_value(results, 1);
+ librdf_uri* parent_uri = librdf_node_get_uri(parent_node);
+ librdf_node* label_node = librdf_query_results_get_binding_value(results, 2);
+ const char* label = (const char*)librdf_node_get_literal_value(label_node);
+
+ printf("CLASS: %s / %s\n", librdf_uri_as_string(parent_uri), librdf_uri_as_string(class_uri));
- SLV2PluginClass plugin_class = slv2_plugin_class_new(
+ SLV2PluginClass plugin_class = slv2_plugin_class_new(world,
+ (const char*)librdf_uri_as_string(parent_uri),
(const char*)librdf_uri_as_string(class_uri),
label);
raptor_sequence_push(world->plugin_classes, plugin_class);
librdf_query_results_next(results);
}
-
+
+ // FIXME: filter list here
}
@@ -309,6 +320,13 @@ slv2_world_serialize(const char* filename)
#endif
+SLV2PluginClass
+slv2_world_get_plugin_class(SLV2World world)
+{
+ return raptor_sequence_get_at(world->plugin_classes, 0);
+}
+
+
SLV2PluginClasses
slv2_world_get_plugin_classes(SLV2World world)
{