summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-01-27 07:49:37 +0000
committerDavid Robillard <d@drobilla.net>2008-01-27 07:49:37 +0000
commit6de587b04154f2efdc2a94c0a78225f7adc88ff9 (patch)
treea25b1b2e1e80fe8d7fe9a16336d9077d3b0d64b2 /src
parent6f4460aee9962a49ae872eef42ba75a439ea6e59 (diff)
downloadlilv-6de587b04154f2efdc2a94c0a78225f7adc88ff9.tar.gz
lilv-6de587b04154f2efdc2a94c0a78225f7adc88ff9.tar.bz2
lilv-6de587b04154f2efdc2a94c0a78225f7adc88ff9.zip
Packaging stuff.
Add scale points API. Display scale points in lv2_inspect. Fix bugs resulting in returning empty collections. git-svn-id: http://svn.drobilla.net/lad/slv2@1114 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/plugin.c2
-rw-r--r--src/port.c45
-rw-r--r--src/query.c2
-rw-r--r--src/scalepoint.c63
-rw-r--r--src/scalepoints.c57
-rw-r--r--src/slv2_internal.h11
7 files changed, 180 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4c192c8..148fafb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,6 +15,8 @@ libslv2_la_SOURCES = \
pluginuis.c \
port.c \
query.c \
+ scalepoint.c \
+ scalepoints.c \
slv2_internal.h \
util.c \
value.c \
diff --git a/src/plugin.c b/src/plugin.c
index 6ab21b4..437bcb6 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -339,7 +339,7 @@ slv2_plugin_get_name(SLV2Plugin plugin)
// FIXME: lang?
- if (results && slv2_values_size(results) > 0) {
+ if (results) {
SLV2Value val = slv2_values_get_at(results, 0);
if (slv2_value_is_string(val))
ret = slv2_value_duplicate(val);
diff --git a/src/port.c b/src/port.c
index a76bf7b..9166fcc 100644
--- a/src/port.c
+++ b/src/port.c
@@ -26,6 +26,7 @@
#include <slv2/types.h>
#include <slv2/util.h>
#include <slv2/values.h>
+#include <slv2/scalepoints.h>
#include "slv2_internal.h"
@@ -230,6 +231,50 @@ slv2_port_get_range(SLV2Plugin p,
}
+SLV2ScalePoints
+slv2_port_get_scale_points(SLV2Plugin p,
+ SLV2Port port)
+{
+ char* query = slv2_strjoin(
+ "SELECT DISTINCT ?value ?label WHERE {\n"
+ "<", slv2_value_as_uri(p->plugin_uri), "> lv2:port ?port .\n"
+ "?port lv2:symbol \"", slv2_value_as_string(port->symbol), "\" ;\n",
+ " lv2:scalePoint ?point .\n"
+ "?point rdf:value ?value ;\n"
+ " rdfs:label ?label .\n"
+ "\n} ORDER BY ?value", NULL);
+
+ librdf_query_results* results = slv2_plugin_query(p, query);
+
+ SLV2ScalePoints ret = NULL;
+
+ if (!librdf_query_results_finished(results))
+ ret = slv2_scale_points_new();
+
+ while (!librdf_query_results_finished(results)) {
+
+ librdf_node* value_node = librdf_query_results_get_binding_value(results, 0);
+ librdf_node* label_node = librdf_query_results_get_binding_value(results, 1);
+
+ SLV2Value value = slv2_value_new_librdf_node(p->world, value_node);
+ SLV2Value label = slv2_value_new_librdf_node(p->world, label_node);
+
+ raptor_sequence_push(ret, slv2_scale_point_new(value, label));
+
+ librdf_query_results_next(results);
+ }
+
+ librdf_free_query_results(results);
+
+ free(query);
+
+ assert(!ret || slv2_values_size(ret) > 0);
+
+ return ret;
+}
+
+
+
SLV2Values
slv2_port_get_properties(SLV2Plugin p,
SLV2Port port)
diff --git a/src/query.c b/src/query.c
index cc1349a..75e85e9 100644
--- a/src/query.c
+++ b/src/query.c
@@ -45,7 +45,7 @@ slv2_query_get_variable_bindings(SLV2World world,
{
SLV2Values result = NULL;
- if (librdf_query_results_get_bindings_count(results) > 0)
+ if (!librdf_query_results_finished(results))
result = slv2_values_new();
while (!librdf_query_results_finished(results)) {
diff --git a/src/scalepoint.c b/src/scalepoint.c
new file mode 100644
index 0000000..a22fef6
--- /dev/null
+++ b/src/scalepoint.c
@@ -0,0 +1,63 @@
+/* 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 <assert.h>
+#include <locale.h>
+#include <raptor.h>
+#include <slv2/value.h>
+#include "slv2_internal.h"
+
+
+/* private - ownership of value and label is taken */
+SLV2ScalePoint
+slv2_scale_point_new(SLV2Value value, SLV2Value label)
+{
+ SLV2ScalePoint point = (SLV2ScalePoint)malloc(sizeof(struct _SLV2ScalePoint));
+ point->value = value;
+ point->label= label;
+ return point;
+}
+
+
+/* private */
+void
+slv2_scale_point_free(SLV2ScalePoint point)
+{
+ slv2_value_free(point->value);
+ slv2_value_free(point->label);
+ free(point);
+}
+
+
+SLV2Value
+slv2_scale_point_get_value(SLV2ScalePoint p)
+{
+ return p->value;
+}
+
+
+SLV2Value
+slv2_scale_point_get_label(SLV2ScalePoint p)
+{
+ return p->label;
+}
+
diff --git a/src/scalepoints.c b/src/scalepoints.c
new file mode 100644
index 0000000..cecd3d5
--- /dev/null
+++ b/src/scalepoints.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.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <raptor.h>
+#include <slv2/scalepoints.h>
+#include "slv2_internal.h"
+
+
+SLV2ScalePoints
+slv2_scale_points_new()
+{
+ return raptor_new_sequence((void (*)(void*))&slv2_scale_point_free, NULL);
+}
+
+
+void
+slv2_scale_points_free(SLV2ScalePoints points)
+{
+ if (points)
+ raptor_free_sequence(points);
+}
+
+
+unsigned
+slv2_scale_points_size(SLV2ScalePoints points)
+{
+ return (points ? raptor_sequence_size(points) : 0);
+}
+
+
+SLV2ScalePoint
+slv2_scale_points_get_at(SLV2ScalePoints points, unsigned index)
+{
+ if (index > INT_MAX)
+ return NULL;
+ else
+ return (SLV2ScalePoint)raptor_sequence_get_at(points, (int)index);
+}
+
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index eda0abd..d38daa4 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -225,6 +225,17 @@ librdf_uri* slv2_value_as_librdf_uri(SLV2Value value);
void slv2_values_set_at(SLV2Values list, unsigned index, void* value);
+/* ********* Scale Points ********* */
+
+struct _SLV2ScalePoint {
+ SLV2Value value;
+ SLV2Value label;
+};
+
+SLV2ScalePoint slv2_scale_point_new(SLV2Value value, SLV2Value label);
+void slv2_scale_point_free(SLV2ScalePoint point);
+
+
/* String utility functions */
char* slv2_strjoin(const char* first, ...);