diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/plugin.c | 132 | ||||
-rw-r--r-- | src/port.c | 43 | ||||
-rw-r--r-- | src/portsignature.c | 56 | ||||
-rw-r--r-- | src/query.c | 1 | ||||
-rw-r--r-- | src/slv2_internal.h | 40 | ||||
-rw-r--r-- | src/template.c | 114 |
7 files changed, 345 insertions, 49 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ec2a617..7a89f0c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,14 +8,16 @@ libslv2_la_SOURCES = \ plugin.c \ pluginclass.c \ pluginclasses.c \ - pluginui.c \ - pluginuis.c \ - pluginuiinstance.c \ plugininstance.c \ plugins.c \ + pluginui.c \ + pluginuiinstance.c \ + pluginuis.c \ port.c \ + portsignature.c \ query.c \ slv2_internal.h \ + template.c \ util.c \ value.c \ values.c \ diff --git a/src/plugin.c b/src/plugin.c index bdfd457..bd7f89e 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -42,6 +42,7 @@ slv2_plugin_new(SLV2World world, librdf_uri* uri, librdf_uri* bundle_uri, librdf plugin->bundle_uri = librdf_new_uri_from_uri(bundle_uri); plugin->binary_uri = librdf_new_uri_from_uri(binary_uri); plugin->plugin_class = NULL; + plugin->templt = NULL; plugin->data_uris = slv2_values_new(); plugin->ports = raptor_new_sequence((void (*)(void*))&slv2_port_free, NULL); plugin->storage = NULL; @@ -67,6 +68,9 @@ slv2_plugin_free(SLV2Plugin p) raptor_free_sequence(p->ports); p->ports = NULL; + slv2_template_free(p->templt); + p->templt = NULL; + if (p->rdf) { librdf_free_model(p->rdf); p->rdf = NULL; @@ -195,37 +199,55 @@ slv2_plugin_load(SLV2Plugin p) // Load ports query = (const unsigned char*) "PREFIX : <http://lv2plug.in/ns/lv2core#>\n" - "SELECT DISTINCT ?port ?symbol ?index WHERE {\n" - "<> :port ?port .\n" - "?port :symbol ?symbol ;\n" - " :index ?index .\n" - "}"; + "SELECT DISTINCT ?type ?symbol ?index WHERE {\n" + "<> :port ?port .\n" + "?port a ?type ;\n" + " :symbol ?symbol ;\n" + " :index ?index .\n" + "} ORDER BY (?index)"; q = librdf_new_query(p->world->world, "sparql", NULL, query, p->plugin_uri); results = librdf_query_execute(q, p->rdf); + int num_ports = 0; + int last_index = -1; + + assert(!p->templt); + p->templt = slv2_template_new(); + while (!librdf_query_results_finished(results)) { - //librdf_node* port_node = librdf_query_results_get_binding_value(results, 0); + librdf_node* type_node = librdf_query_results_get_binding_value(results, 0); librdf_node* symbol_node = librdf_query_results_get_binding_value(results, 1); librdf_node* index_node = librdf_query_results_get_binding_value(results, 2); - //assert(librdf_node_is_blank(port_node)); assert(librdf_node_is_literal(symbol_node)); assert(librdf_node_is_literal(index_node)); //const char* id = (const char*)librdf_node_get_blank_identifier(port_node); + const char* type = (const char*)librdf_uri_as_string(librdf_node_get_uri(type_node)); const char* symbol = (const char*)librdf_node_get_literal_value(symbol_node); const char* index = (const char*)librdf_node_get_literal_value(index_node); - //printf("%s: PORT: %s %s\n", p->plugin_uri, index, symbol); + //printf("PORT: %s %s %s\n", type, index, symbol); + + const int this_index = atoi(index); - // Create a new SLV2Port - SLV2Port port = slv2_port_new((unsigned)atoi(index), symbol); - raptor_sequence_push(p->ports, port); + // Create a new SLV2Port, and add to template + if (this_index == num_ports) { + assert(this_index == last_index + 1); + SLV2Port port = slv2_port_new((unsigned)atoi(index), symbol); + raptor_sequence_push(p->ports, port); + slv2_template_add_port(p->templt); + ++num_ports; + ++last_index; + } + + slv2_template_port_type(p->templt, this_index, type); + librdf_free_node(type_node); librdf_free_node(symbol_node); librdf_free_node(index_node); @@ -458,6 +480,16 @@ slv2_plugin_get_num_ports(SLV2Plugin p) } +SLV2Template +slv2_plugin_get_template(SLV2Plugin p) +{ + if (!p->rdf) + slv2_plugin_load(p); + + return p->templt; +} + + bool slv2_plugin_has_latency(SLV2Plugin p) { @@ -556,6 +588,84 @@ slv2_plugin_get_port_by_symbol(SLV2Plugin p, } +char* +slv2_plugin_get_author_name(SLV2Plugin plugin) +{ + char* ret = NULL; + + const char* const query = + "SELECT DISTINCT ?name WHERE {\n" + " <> doap:maintainer ?maint . \n" + " ?maint foaf:name ?name . \n" + "}\n"; + + SLV2Values result = slv2_plugin_simple_query(plugin, query, 0); + + if (result && slv2_values_size(result) > 0) { + SLV2Value val = slv2_values_get_at(result, 0); + if (slv2_value_is_string(val)) + ret = strdup(slv2_value_as_string(val)); + } + + if (result) + slv2_values_free(result); + + return ret; +} + + +char* +slv2_plugin_get_author_email(SLV2Plugin plugin) +{ + char* ret = NULL; + + const char* const query = + "SELECT DISTINCT ?email WHERE {\n" + " <> doap:maintainer ?maint . \n" + " ?maint foaf:mbox ?email . \n" + "}\n"; + + SLV2Values result = slv2_plugin_simple_query(plugin, query, 0); + + if (result && slv2_values_size(result) > 0) { + SLV2Value val = slv2_values_get_at(result, 0); + if (slv2_value_is_string(val)) + ret = strdup(slv2_value_as_string(val)); + } + + if (result) + slv2_values_free(result); + + return ret; +} + + +char* +slv2_plugin_get_author_homepage(SLV2Plugin plugin) +{ + char* ret = NULL; + + const char* const query = + "SELECT DISTINCT ?email WHERE {\n" + " <> doap:maintainer ?maint . \n" + " ?maint foaf:homepage ?email . \n" + "}\n"; + + SLV2Values result = slv2_plugin_simple_query(plugin, query, 0); + + if (result && slv2_values_size(result) > 0) { + SLV2Value val = slv2_values_get_at(result, 0); + if (slv2_value_is_string(val)) + ret = strdup(slv2_value_as_string(val)); + } + + if (result) + slv2_values_free(result); + + return ret; +} + + SLV2UIs slv2_plugin_get_uis(SLV2Plugin plugin) { @@ -122,40 +122,31 @@ slv2_port_get_data_type(SLV2Plugin p, return ret; } -#if 0 bool -slv2_port_has_property(SLV2Plugin p, - SLV2Port port, - SLV2Value hint) +slv2_port_has_property(SLV2Plugin p, + SLV2Port port, + const char* property) { - /* FIXME: Add SLV2Value QName stuff to make this not suck to use */ + assert(property); - SLV2Values hints = slv2_port_get_value(p, port, "lv2:portHint"); + SLV2Values result = NULL; - if (!hints) - return false; - - for (unsigned i=0; i < slv2_values_size(type); ++i) { - const SLV2Value val = slv2_values_get_at(type, i); - if (slv2_value_is_uri(val)) { - const char* uri = slv2_value_as_uri(val); - if (!strcmp(uri, "http://lv2plug.in/ns/lv2core#connectionOptional")) - return true; - ret = SLV2_PORT_DATA_TYPE_CONTROL; - else if (!strcmp(uri, "http://lv2plug.in/ns/lv2core#AudioPort")) - ret = SLV2_PORT_DATA_TYPE_AUDIO; - else if (!strcmp(uri, "http://ll-plugins.nongnu.org/lv2/ext/MidiPort")) - ret = SLV2_PORT_DATA_TYPE_MIDI; - else if (!strcmp(uri, "http://drobilla.net/ns/lv2ext/osc/0#OSCPort")) - ret = SLV2_PORT_DATA_TYPE_OSC; - } - } + char* query = slv2_strjoin( + "SELECT DISTINCT ?port WHERE {\n" + "<", librdf_uri_as_string(p->plugin_uri), "> lv2:port ?port ." + "?port lv2:symbol \"", port->symbol, "\";\n", + " lv2:portProperty <", property, "> .\n}", NULL); + + result = slv2_plugin_simple_query(p, query, 0); - slv2_values_free(type); + const bool ret = (slv2_values_size(result) > 0); + free(query); + free(result); + return ret; } -#endif + SLV2Values slv2_port_get_value(SLV2Plugin p, diff --git a/src/portsignature.c b/src/portsignature.c new file mode 100644 index 0000000..7e2f535 --- /dev/null +++ b/src/portsignature.c @@ -0,0 +1,56 @@ +/* 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. + */ + +#include <stdlib.h> +#include <slv2/types.h> +#include "slv2_internal.h" + + +/* private */ +SLV2PortSignature +slv2_port_signature_new(SLV2PortDirection direction, + SLV2PortDataType type) +{ + struct _SLV2PortSignature* ret = malloc(sizeof(struct _SLV2PortSignature)); + ret->direction = direction; + ret->type = type; + return ret; +} + + +/* private */ +void +slv2_port_signature_free(SLV2PortSignature sig) +{ + free(sig); +} + + +SLV2PortDirection +slv2_port_signature_get_direction(SLV2PortSignature sig) +{ + return sig->direction; +} + + +SLV2PortDataType +slv2_port_signature_get_type(SLV2PortSignature sig) +{ + return sig->type; +} + diff --git a/src/query.c b/src/query.c index 00f08e6..b226f04 100644 --- a/src/query.c +++ b/src/query.c @@ -32,6 +32,7 @@ static const char* slv2_query_prefixes = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" "PREFIX doap: <http://usefulinc.com/ns/doap#>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" "PREFIX lv2: <http://lv2plug.in/ns/lv2core#>\n"; #if 0 diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 2f66670..07df8f5 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -58,14 +58,15 @@ void slv2_port_free(SLV2Port port); */ struct _SLV2Plugin { struct _SLV2World* world; - librdf_uri* plugin_uri; - librdf_uri* bundle_uri; ///< Bundle directory plugin was loaded from - librdf_uri* binary_uri; ///< lv2:binary - SLV2PluginClass plugin_class; - raptor_sequence* data_uris; ///< rdfs::seeAlso - raptor_sequence* ports; - librdf_storage* storage; - librdf_model* rdf; + librdf_uri* plugin_uri; + librdf_uri* bundle_uri; ///< Bundle directory plugin was loaded from + librdf_uri* binary_uri; ///< lv2:binary + SLV2PluginClass plugin_class; + SLV2Template templt; + raptor_sequence* data_uris; ///< rdfs::seeAlso + raptor_sequence* ports; + librdf_storage* storage; + librdf_model* rdf; }; SLV2Plugin slv2_plugin_new(SLV2World world, librdf_uri* uri, librdf_uri* bundle_uri, librdf_uri* binary_uri); @@ -191,7 +192,6 @@ void slv2_ui_free(SLV2UI ui); /* ********* Value ********* */ - typedef enum _SLV2ValueType { SLV2_VALUE_URI, SLV2_VALUE_STRING, @@ -212,6 +212,28 @@ SLV2Value slv2_value_new(SLV2ValueType type, const char* val); +/* ********* PortSignature ********* */ + +struct _SLV2PortSignature { + SLV2PortDirection direction; + SLV2PortDataType type; +}; + +SLV2PortSignature slv2_port_signature_new(SLV2PortDirection direction, + SLV2PortDataType type); + +void slv2_port_signature_free(SLV2PortSignature val); + + +/* ********* Template ********* */ + +SLV2Template slv2_template_new(); +void slv2_template_free(SLV2Template t); +void slv2_template_add_port(SLV2Template t); +void slv2_template_port_type(SLV2Template t, + uint32_t port_index, + const char* type_uri); + #ifdef __cplusplus } #endif diff --git a/src/template.c b/src/template.c new file mode 100644 index 0000000..0c179f7 --- /dev/null +++ b/src/template.c @@ -0,0 +1,114 @@ +/* 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. + */ + +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <raptor.h> +#include <slv2/types.h> +#include <slv2/template.h> +#include "slv2_internal.h" + + +/* private */ +SLV2Template +slv2_template_new() +{ + return raptor_new_sequence((void (*)(void*))&slv2_port_signature_free, NULL); +} + + +/* private */ +void +slv2_template_add_port(SLV2Template t) +{ + SLV2PortSignature sig = slv2_port_signature_new( + SLV2_PORT_DIRECTION_UNKNOWN, + SLV2_PORT_DATA_TYPE_UNKNOWN); + + raptor_sequence_push(t, sig); +} + + +/* private */ +void slv2_template_port_type(SLV2Template t, + uint32_t port_index, + const char* type_uri) +{ + SLV2PortSignature sig = slv2_template_get_port(t, port_index); + + if (sig) { + if (!strcmp(type_uri, "http://lv2plug.in/ns/lv2core#InputPort")) + sig->direction = SLV2_PORT_DIRECTION_INPUT; + else if (!strcmp(type_uri, "http://lv2plug.in/ns/lv2core#OutputPort")) + sig->direction = SLV2_PORT_DIRECTION_OUTPUT; + else if (!strcmp(type_uri, "http://lv2plug.in/ns/lv2core#ControlPort")) + sig->type = SLV2_PORT_DATA_TYPE_CONTROL; + else if (!strcmp(type_uri, "http://lv2plug.in/ns/lv2core#AudioPort")) + sig->type = SLV2_PORT_DATA_TYPE_AUDIO; + else if (!strcmp(type_uri, "http://ll-plugins.nongnu.org/lv2/ext/MidiPort")) + sig->type = SLV2_PORT_DATA_TYPE_MIDI; + else if (!strcmp(type_uri, "http://drobilla.net/ns/lv2ext/osc/0#OSCPort")) + sig->type = SLV2_PORT_DATA_TYPE_OSC; + } +} + + +SLV2PortSignature +slv2_template_get_port(SLV2Template t, + uint32_t index) +{ + if (index > INT_MAX) + return NULL; + else + return (SLV2PortSignature)raptor_sequence_get_at(t, (int)index); +} + + + +void +slv2_template_free(SLV2Template t) +{ + if (t) + raptor_free_sequence(t); +} + + +uint32_t +slv2_template_get_num_ports(SLV2Template t) +{ + return raptor_sequence_size(t); +} + + +uint32_t +slv2_template_get_num_ports_of_type(SLV2Template t, + SLV2PortDirection direction, + SLV2PortDataType type) +{ + uint32_t ret = 0; + + for (unsigned i=0; i < slv2_template_get_num_ports(t); ++i) { + SLV2PortSignature sig = slv2_template_get_port(t, i); + if (sig->direction == direction && sig->type == type) + ++ret; + } + + return ret; +} + |