diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugin.c | 34 | ||||
-rw-r--r-- | src/pluginui.c | 6 | ||||
-rw-r--r-- | src/port.c | 28 | ||||
-rw-r--r-- | src/portsignature.c | 56 | ||||
-rw-r--r-- | src/query.c | 16 | ||||
-rw-r--r-- | src/slv2_internal.h | 45 | ||||
-rw-r--r-- | src/template.c | 114 | ||||
-rw-r--r-- | src/value.c | 71 | ||||
-rw-r--r-- | src/world.c | 21 |
10 files changed, 130 insertions, 263 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7a89f0c..4c192c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,10 +14,8 @@ libslv2_la_SOURCES = \ 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 2536277..accce8c 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -42,7 +42,6 @@ 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; @@ -68,9 +67,6 @@ 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; @@ -215,9 +211,6 @@ slv2_plugin_load(SLV2Plugin p) int num_ports = 0; int last_index = -1; - assert(!p->templt); - p->templt = slv2_template_new(); - while (!librdf_query_results_finished(results)) { librdf_node* type_node = librdf_query_results_get_binding_value(results, 0); @@ -228,26 +221,29 @@ slv2_plugin_load(SLV2Plugin p) 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* 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("PORT: %s %s %s\n", type, index, symbol); const int this_index = atoi(index); + SLV2Port this_port = NULL; // 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); + this_port = slv2_port_new((unsigned)atoi(index), symbol); + raptor_sequence_push(p->ports, this_port); ++num_ports; ++last_index; + } else { + this_port = slv2_plugin_get_port_by_index(p, this_index); } + + raptor_sequence_push(this_port->classes, slv2_value_new_librdf_uri(p->world, + librdf_node_get_uri(type_node))); - slv2_template_port_type(p->templt, this_index, type); - librdf_free_node(type_node); librdf_free_node(symbol_node); librdf_free_node(index_node); @@ -481,16 +477,6 @@ 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) { @@ -537,7 +523,7 @@ slv2_plugin_has_feature(SLV2Plugin p, assert(feature); SLV2Values features = slv2_plugin_get_supported_features(p); - SLV2Value val = slv2_value_new(SLV2_VALUE_URI, feature); + SLV2Value val = slv2_value_new(p->world, SLV2_VALUE_URI, feature); const bool ret = features && slv2_values_contains(features, val); diff --git a/src/pluginui.c b/src/pluginui.c index 1e358e9..01f512a 100644 --- a/src/pluginui.c +++ b/src/pluginui.c @@ -37,6 +37,7 @@ slv2_ui_new(SLV2World world, assert(binary_uri); struct _SLV2UI* ui = malloc(sizeof(struct _SLV2UI)); + ui->world = world; ui->uri = librdf_new_uri_from_uri(uri); ui->binary_uri = librdf_new_uri_from_uri(binary_uri); @@ -50,8 +51,7 @@ slv2_ui_new(SLV2World world, free(bundle); ui->types = slv2_values_new(); - raptor_sequence_push(ui->types, slv2_value_new(SLV2_VALUE_URI, - (const char*)librdf_uri_as_string(type_uri))); + raptor_sequence_push(ui->types, slv2_value_new_librdf_uri(world, type_uri)); return ui; } @@ -95,7 +95,7 @@ slv2_ui_get_types(SLV2UI ui) bool slv2_ui_is_type(SLV2UI ui, const char* type_uri) { - SLV2Value type = slv2_value_new(SLV2_VALUE_URI, type_uri); + SLV2Value type = slv2_value_new(ui->world, SLV2_VALUE_URI, type_uri); bool ret = slv2_values_contains(ui->types, type); slv2_value_free(type); return ret; @@ -36,6 +36,7 @@ slv2_port_new(uint32_t index, const char* symbol/*, const char* node_id*/) struct _SLV2Port* port = malloc(sizeof(struct _SLV2Port)); port->index = index; port->symbol = strdup(symbol); + port->classes = slv2_values_new(); //port->node_id = strdup(node_id); return port; } @@ -46,7 +47,7 @@ void slv2_port_free(SLV2Port port) { free(port->symbol); - //free(port->node_id); + slv2_values_free(port->classes); free(port); } @@ -58,11 +59,10 @@ slv2_port_duplicate(SLV2Port port) SLV2Port result = malloc(sizeof(struct _SLV2Port)); result->index = port->index; result->symbol = strdup(port->symbol); - //result->node_id = strdup(port->node_id); return result; } - +#if 0 SLV2PortDirection slv2_port_get_direction(SLV2Plugin p, SLV2Port port) @@ -123,6 +123,20 @@ slv2_port_get_data_type(SLV2Plugin p, return ret; } +#endif + +bool +slv2_port_is_a(SLV2Plugin plugin, + SLV2Port port, + SLV2Value port_class) +{ + for (unsigned i=0; i < slv2_values_size(port->classes); ++i) + if (slv2_value_equals(slv2_values_get_at(port->classes, i), port_class)) + return true; + + return false; +} + bool slv2_port_has_property(SLV2Plugin p, @@ -232,6 +246,14 @@ slv2_port_get_name(SLV2Plugin p, return name; } + +SLV2Values +slv2_port_get_classes(SLV2Plugin p, + SLV2Port port) +{ + return port->classes; +} + float slv2_port_get_default_value(SLV2Plugin p, diff --git a/src/portsignature.c b/src/portsignature.c deleted file mode 100644 index 7e2f535..0000000 --- a/src/portsignature.c +++ /dev/null @@ -1,56 +0,0 @@ -/* 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 6dbb47f..d1b947d 100644 --- a/src/query.c +++ b/src/query.c @@ -55,7 +55,8 @@ slv2_query_lang_filter(const char* variable) #endif SLV2Values -slv2_query_get_variable_bindings(librdf_query_results* results, +slv2_query_get_variable_bindings(SLV2World world, + librdf_query_results* results, int variable) { SLV2Values result = NULL; @@ -71,13 +72,14 @@ slv2_query_get_variable_bindings(librdf_query_results* results, librdf_uri* datatype_uri = NULL; SLV2ValueType type = SLV2_VALUE_STRING; + librdf_uri* uri_val = NULL; const char* str_val = NULL; switch (librdf_node_get_type(node)) { case LIBRDF_NODE_TYPE_RESOURCE: type = SLV2_VALUE_URI; - assert(librdf_node_get_uri(node)); - str_val = (const char*)librdf_uri_as_string(librdf_node_get_uri(node)); + uri_val = librdf_node_get_uri(node); + assert(uri_val); break; case LIBRDF_NODE_TYPE_LITERAL: datatype_uri = librdf_node_get_literal_value_datatype_uri(node); @@ -102,8 +104,10 @@ slv2_query_get_variable_bindings(librdf_query_results* results, break; } - if (str_val) - raptor_sequence_push(result, slv2_value_new(type, str_val)); + if (uri_val) + raptor_sequence_push(result, slv2_value_new_librdf_uri(world, uri_val)); + else if (str_val) + raptor_sequence_push(result, slv2_value_new(world, type, str_val)); librdf_free_node(node); @@ -168,7 +172,7 @@ slv2_plugin_simple_query(SLV2Plugin plugin, librdf_query_results* results = slv2_plugin_query(plugin, sparql_str); - SLV2Values ret = slv2_query_get_variable_bindings(results, (int)variable); + SLV2Values ret = slv2_query_get_variable_bindings(plugin->world, results, (int)variable); librdf_free_query_results(results); diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 36025fe..40677e7 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -37,8 +37,9 @@ extern "C" { /** Reference to a port on some plugin. */ struct _SLV2Port { - uint32_t index; ///< LV2 index - char* symbol; ///< LV2 symbol + uint32_t index; ///< lv2:index + char* symbol; ///< lv2:symbol + SLV2Values classes; ///< rdf:type }; @@ -62,7 +63,6 @@ struct _SLV2Plugin { 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; @@ -174,10 +174,11 @@ slv2_world_load_file(SLV2World world, librdf_uri* file_uri); /* ********* Plugin UI ********* */ struct _SLV2UI { - librdf_uri* uri; - librdf_uri* bundle_uri; - librdf_uri* binary_uri; - SLV2Values types; + struct _SLV2World* world; + librdf_uri* uri; + librdf_uri* bundle_uri; + librdf_uri* binary_uri; + SLV2Values types; }; SLV2UIs slv2_uis_new(); @@ -203,36 +204,16 @@ struct _SLV2Value { SLV2ValueType type; char* str_val; ///< always present union { - int int_val; - float float_val; + int int_val; + float float_val; + librdf_uri* uri_val; } val; }; -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); - +SLV2Value slv2_value_new(SLV2World world, SLV2ValueType type, const char* val); +SLV2Value slv2_value_new_librdf_uri(SLV2World world, librdf_uri* uri); -/* ********* 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 } diff --git a/src/template.c b/src/template.c deleted file mode 100644 index 0c179f7..0000000 --- a/src/template.c +++ /dev/null @@ -1,114 +0,0 @@ -/* 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; -} - diff --git a/src/value.c b/src/value.c index bccb375..85c9fd0 100644 --- a/src/value.c +++ b/src/value.c @@ -28,13 +28,20 @@ /* private */ SLV2Value -slv2_value_new(SLV2ValueType type, const char* str) +slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) { SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); - val->str_val = strdup(str); val->type = type; - //printf("New value, t=%d, %s\n", type, str); + if (type == SLV2_VALUE_URI) { + val->val.uri_val = librdf_new_uri(world->world, (const unsigned char*)str); + if (val->val.uri_val) + val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); + else + return NULL; + } else { + val->str_val = strdup(str); + } if (type == SLV2_VALUE_INT) { char* endptr = 0; @@ -42,29 +49,44 @@ slv2_value_new(SLV2ValueType type, const char* str) } else if (type == SLV2_VALUE_FLOAT) { char* endptr = 0; val->val.float_val = strtod(str, &endptr); - } else { - val->val.int_val = 0; } return val; } -/* +/* private */ +SLV2Value +slv2_value_new_librdf_uri(SLV2World world, librdf_uri* uri) +{ + SLV2Value val = (SLV2Value)malloc(sizeof(struct _SLV2Value)); + val->type = SLV2_VALUE_URI; + val->val.uri_val = librdf_new_uri_from_uri(uri); + val->str_val = (char*)librdf_uri_as_string(val->val.uri_val); + return val; +} + + SLV2Value -slv2_value_new_uri(const char* uri) +slv2_value_new_uri(SLV2World world, const char* uri) { - return slv2_value_new(SLV2_VALUE_URI, uri); + return slv2_value_new(world, SLV2_VALUE_URI, uri); } -*/ + SLV2Value slv2_value_duplicate(SLV2Value val) { SLV2Value result = (SLV2Value)malloc(sizeof(struct _SLV2Value)); - result->str_val = strdup(val->str_val); result->type = val->type; - result->val = val->val; + + if (val->type == SLV2_VALUE_URI) { + result->val.uri_val = librdf_new_uri_from_uri(val->val.uri_val); + } else { + result->str_val = strdup(val->str_val); + result->val = val->val; + } + return result; } @@ -73,7 +95,11 @@ void slv2_value_free(SLV2Value val) { if (val) { - free(val->str_val); + if (val->type == SLV2_VALUE_URI) + librdf_free_uri(val->val.uri_val); + else + free(val->str_val); + free(val); } } @@ -82,12 +108,25 @@ slv2_value_free(SLV2Value val) bool slv2_value_equals(SLV2Value value, SLV2Value other) { - if (value->type != other->type) + if (value == NULL && other == NULL) + return true; + else if (value == NULL || other == NULL) return false; - else if (value && other) + else if (value->type != other->type) + return false; + + switch (value->type) { + case SLV2_VALUE_URI: + return (librdf_uri_equals(value->val.uri_val, other->val.uri_val) != 0); + case SLV2_VALUE_STRING: return ! strcmp(value->str_val, other->str_val); - else - return true; + case SLV2_VALUE_INT: + return (value->val.int_val == other->val.int_val); + case SLV2_VALUE_FLOAT: + return (value->val.float_val == other->val.float_val); + } + + return false; /* shouldn't get here */ } diff --git a/src/world.c b/src/world.c index 3eb1834..08a1f83 100644 --- a/src/world.c +++ b/src/world.c @@ -67,7 +67,7 @@ slv2_world_new() (unsigned char*)"http://lv2plug.in/ns/lv2core#Specification"); world->lv2_plugin_node = librdf_new_node_from_uri_string(world->world, - (unsigned char*)"http://lv2plug.in/ns/lv2core#Plugin"); + (unsigned char*)lv2_plugin_uri); world->rdf_a_node = librdf_new_node_from_uri_string(world->world, (unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); @@ -115,7 +115,7 @@ slv2_world_new_using_rdf_world(librdf_world* rdf_world) (unsigned char*)"http://lv2plug.in/ns/lv2core#Specification"); world->lv2_plugin_node = librdf_new_node_from_uri_string(rdf_world, - (unsigned char*)"http://lv2plug.in/ns/lv2core#Plugin"); + (unsigned char*)lv2_plugin_uri); world->rdf_a_node = librdf_new_node_from_uri_string(rdf_world, (unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); @@ -139,6 +139,9 @@ slv2_world_free(SLV2World world) slv2_plugin_free(raptor_sequence_get_at(world->plugins, i)); raptor_free_sequence(world->plugins); world->plugins = NULL; + + slv2_plugin_class_free(world->lv2_plugin_class); + world->lv2_plugin_class = NULL; slv2_plugin_classes_free(world->plugin_classes); world->plugin_classes = NULL; @@ -202,7 +205,8 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) /* Query statement: ?plugin a lv2:Plugin */ librdf_statement* q = librdf_new_statement_from_nodes(world->world, - NULL, world->rdf_a_node, world->lv2_plugin_node); + NULL, librdf_new_node_from_node(world->rdf_a_node), + librdf_new_node_from_node(world->lv2_plugin_node)); librdf_stream* results = librdf_model_find_statements(manifest_model, q); @@ -232,11 +236,12 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) } librdf_free_stream(results); - free(q); + librdf_free_statement(q); /* Query statement: ?specification a lv2:Specification */ q = librdf_new_statement_from_nodes(world->world, - NULL, world->rdf_a_node, world->lv2_specification_node); + NULL, librdf_new_node_from_node(world->rdf_a_node), + librdf_new_node_from_node(world->lv2_specification_node)); results = librdf_model_find_statements(manifest_model, q); @@ -266,7 +271,7 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) } librdf_free_stream(results); - free(q); + librdf_free_statement(q); /* Join the temporary model to the main model */ librdf_stream* manifest_stream = librdf_model_as_stream(manifest_model); @@ -514,6 +519,8 @@ slv2_world_load_all(SLV2World world) assert(plugin_uri); assert(data_uri); + //printf("PLUGIN: %s\n", librdf_uri_as_string(plugin_uri)); + SLV2Plugin plugin = slv2_plugins_get_by_uri(world->plugins, (const char*)librdf_uri_as_string(plugin_uri)); @@ -529,7 +536,7 @@ slv2_world_load_all(SLV2World world) // FIXME: check for duplicates raptor_sequence_push(plugin->data_uris, - slv2_value_new(SLV2_VALUE_URI, (const char*)librdf_uri_as_string(data_uri))); + slv2_value_new_librdf_uri(plugin->world, data_uri)); librdf_free_node(plugin_node); librdf_free_node(data_node); |