summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugin.c40
-rw-r--r--utils/lv2_inspect.c5
2 files changed, 16 insertions, 29 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 6bc232a..21239f3 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -131,48 +131,31 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
"?port a ?type ;\n"
" :symbol ?symbol ;\n"
" :index ?index .\n"
- "} ORDER BY (?index)";
+ "}";
librdf_query* q = librdf_new_query(p->world->world, "sparql",
NULL, query, slv2_value_as_librdf_uri(p->plugin_uri));
librdf_query_results* results = librdf_query_execute(q, p->rdf);
- int num_ports = 0;
- int last_index = -1;
-
while (!librdf_query_results_finished(results)) {
-
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_literal(symbol_node));
- assert(librdf_node_is_literal(index_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);
-
- const int this_index = atoi(index);
- SLV2Port this_port = NULL;
+ if (librdf_node_is_literal(symbol_node) &&librdf_node_is_literal(index_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);
- // ORDER BY guarantees order
- assert(this_index <= num_ports);
+ const int this_index = atoi(index);
+ SLV2Port this_port = raptor_sequence_get_at(p->ports, this_index);
- // Create a new SLV2Port, and add to template
- if (this_index == num_ports) {
- assert(this_index == last_index + 1);
- this_port = slv2_port_new(p->world, (unsigned)atoi(index), symbol);
- raptor_sequence_push(p->ports, this_port);
- ++num_ports;
- ++last_index;
-
- // More information about a port we already created
- } else if (this_index < num_ports) {
- this_port = slv2_plugin_get_port_by_index(p, this_index);
- }
+ // Havn't seen this port yet, add it to sequence
+ if (!this_port) {
+ this_port = slv2_port_new(p->world, this_index, symbol);
+ raptor_sequence_set_at(p->ports, this_index, this_port);
+ }
- if (this_port) {
raptor_sequence_push(this_port->classes,
slv2_value_new_librdf_uri(p->world, librdf_node_get_uri(type_node)));
}
@@ -180,7 +163,6 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
librdf_free_node(type_node);
librdf_free_node(symbol_node);
librdf_free_node(index_node);
-
librdf_query_results_next(results);
}
diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c
index 263374c..7b3d594 100644
--- a/utils/lv2_inspect.c
+++ b/utils/lv2_inspect.c
@@ -34,6 +34,11 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
printf("\n\tPort %d:\n", index);
+ if (!port) {
+ printf("\t\tERROR: Illegal/nonexistent port\n");
+ return;
+ }
+
SLV2Values classes = slv2_port_get_classes(p, port);
printf("\t\tClasses:\n");