summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lilv_internal.h19
-rw-r--r--src/plugin.c85
-rw-r--r--src/port.c22
-rw-r--r--src/query.c39
-rw-r--r--src/world.c20
5 files changed, 93 insertions, 92 deletions
diff --git a/src/lilv_internal.h b/src/lilv_internal.h
index ca553ca..6b118ee 100644
--- a/src/lilv_internal.h
+++ b/src/lilv_internal.h
@@ -344,10 +344,17 @@ void lilv_scale_point_free(LilvScalePoint* point);
/* ********* Query Results ********* */
-LilvMatches lilv_plugin_find_statements(const LilvPlugin* plugin,
- LilvNode subject,
- LilvNode predicate,
- LilvNode object);
+LilvMatches
+lilv_world_query(LilvWorld* world,
+ LilvNode subject,
+ LilvNode predicate,
+ LilvNode object);
+
+LilvValues*
+lilv_world_query_values(LilvWorld* world,
+ LilvNode subject,
+ LilvNode predicate,
+ LilvNode object);
static inline bool lilv_matches_next(LilvMatches matches) {
return sord_iter_next(matches);
@@ -357,8 +364,8 @@ static inline bool lilv_matches_end(LilvMatches matches) {
return sord_iter_end(matches);
}
-LilvValues* lilv_values_from_stream_objects(const LilvPlugin* p,
- LilvMatches stream);
+LilvValues* lilv_values_from_stream_objects(LilvWorld* w,
+ LilvMatches stream);
/* ********* Utilities ********* */
diff --git a/src/plugin.c b/src/plugin.c
index e91317f..224cd97 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -81,35 +81,11 @@ lilv_plugin_free(LilvPlugin* p)
free(p);
}
-static LilvValues*
-lilv_plugin_query_node(const LilvPlugin* p, LilvNode subject, LilvNode predicate)
-{
- lilv_plugin_load_if_necessary(p);
- // <subject> <predicate> ?value
- LilvMatches results = lilv_plugin_find_statements(
- p, subject, predicate, NULL);
-
- if (lilv_matches_end(results)) {
- lilv_match_end(results);
- return NULL;
- }
-
- LilvValues* result = lilv_values_new();
- FOREACH_MATCH(results) {
- LilvNode node = lilv_match_object(results);
- LilvValue* value = lilv_value_new_from_node(p->world, node);
- if (value)
- lilv_array_append(result, value);
- }
- lilv_match_end(results);
-
- return result;
-}
-
LilvValue*
lilv_plugin_get_unique(const LilvPlugin* p, LilvNode subject, LilvNode predicate)
{
- LilvValues* values = lilv_plugin_query_node(p, subject, predicate);
+ LilvValues* values = lilv_world_query_values(p->world,
+ subject, predicate, NULL);
if (!values || lilv_values_size(values) != 1) {
LILV_ERRORF("Port does not have exactly one `%s' property\n",
sord_node_get_string(predicate));
@@ -123,7 +99,8 @@ lilv_plugin_get_unique(const LilvPlugin* p, LilvNode subject, LilvNode predicate
static LilvValue*
lilv_plugin_get_one(const LilvPlugin* p, LilvNode subject, LilvNode predicate)
{
- LilvValues* values = lilv_plugin_query_node(p, subject, predicate);
+ LilvValues* values = lilv_world_query_values(p->world,
+ subject, predicate, NULL);
if (!values) {
return NULL;
}
@@ -200,8 +177,8 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p)
p->ports = malloc(sizeof(LilvPort*));
p->ports[0] = NULL;
- LilvMatches ports = lilv_plugin_find_statements(
- p,
+ LilvMatches ports = lilv_world_query(
+ p->world,
p->plugin_uri->val.uri_val,
p->world->lv2_port_node,
NULL);
@@ -245,8 +222,8 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p)
p->ports[this_index] = this_port;
}
- LilvMatches types = lilv_plugin_find_statements(
- p, port, p->world->rdf_a_node, NULL);
+ LilvMatches types = lilv_world_query(
+ p->world, port, p->world->rdf_a_node, NULL);
FOREACH_MATCH(types) {
LilvNode type = lilv_match_object(types);
if (sord_node_get_type(type) == SORD_URI) {
@@ -309,8 +286,8 @@ lilv_plugin_get_library_uri(const LilvPlugin* const_p)
lilv_plugin_load_if_necessary(p);
if (!p->binary_uri) {
// <plugin> lv2:binary ?binary
- LilvMatches results = lilv_plugin_find_statements(
- p,
+ LilvMatches results = lilv_world_query(
+ p->world,
p->plugin_uri->val.uri_val,
p->world->lv2_binary_node,
NULL);
@@ -345,8 +322,8 @@ lilv_plugin_get_class(const LilvPlugin* const_p)
lilv_plugin_load_if_necessary(p);
if (!p->plugin_class) {
// <plugin> a ?class
- LilvMatches results = lilv_plugin_find_statements(
- p,
+ LilvMatches results = lilv_world_query(
+ p->world,
p->plugin_uri->val.uri_val,
p->world->rdf_a_node,
NULL);
@@ -444,6 +421,7 @@ lilv_plugin_get_value_for_subject(const LilvPlugin* p,
const LilvValue* subject,
const LilvValue* predicate)
{
+ lilv_plugin_load_ports_if_necessary(p);
if ( ! lilv_value_is_uri(subject) && ! lilv_value_is_blank(subject)) {
LILV_ERROR("Subject is not a resource\n");
return NULL;
@@ -458,9 +436,10 @@ lilv_plugin_get_value_for_subject(const LilvPlugin* p,
: sord_new_blank(p->world->world,
(const uint8_t*)lilv_value_as_blank(subject));
- LilvValues* ret = lilv_plugin_query_node(p,
- subject_node,
- predicate->val.uri_val);
+ LilvValues* ret = lilv_world_query_values(p->world,
+ subject_node,
+ predicate->val.uri_val,
+ NULL);
lilv_node_free(p->world, subject_node);
return ret;
@@ -540,8 +519,9 @@ LILV_API
bool
lilv_plugin_has_latency(const LilvPlugin* p)
{
- LilvMatches ports = lilv_plugin_find_statements(
- p,
+ lilv_plugin_load_if_necessary(p);
+ LilvMatches ports = lilv_world_query(
+ p->world,
p->plugin_uri->val.uri_val,
p->world->lv2_port_node,
NULL);
@@ -549,8 +529,8 @@ lilv_plugin_has_latency(const LilvPlugin* p)
bool ret = false;
FOREACH_MATCH(ports) {
LilvNode port = lilv_match_object(ports);
- LilvMatches reports_latency = lilv_plugin_find_statements(
- p,
+ LilvMatches reports_latency = lilv_world_query(
+ p->world,
port,
p->world->lv2_portproperty_node,
p->world->lv2_reportslatency_node);
@@ -570,8 +550,9 @@ LILV_API
uint32_t
lilv_plugin_get_latency_port_index(const LilvPlugin* p)
{
- LilvMatches ports = lilv_plugin_find_statements(
- p,
+ lilv_plugin_load_if_necessary(p);
+ LilvMatches ports = lilv_world_query(
+ p->world,
p->plugin_uri->val.uri_val,
p->world->lv2_port_node,
NULL);
@@ -579,8 +560,8 @@ lilv_plugin_get_latency_port_index(const LilvPlugin* p)
uint32_t ret = 0;
FOREACH_MATCH(ports) {
LilvNode port = lilv_match_object(ports);
- LilvMatches reports_latency = lilv_plugin_find_statements(
- p,
+ LilvMatches reports_latency = lilv_world_query(
+ p->world,
port,
p->world->lv2_portproperty_node,
p->world->lv2_reportslatency_node);
@@ -678,11 +659,13 @@ lilv_plugin_get_port_by_symbol(const LilvPlugin* p,
static LilvNode
lilv_plugin_get_author(const LilvPlugin* p)
{
+ lilv_plugin_load_if_necessary(p);
+
SordNode* doap_maintainer = sord_new_uri(
p->world->world, NS_DOAP "maintainer");
- LilvMatches maintainers = lilv_plugin_find_statements(
- p,
+ LilvMatches maintainers = lilv_world_query(
+ p->world,
p->plugin_uri->val.uri_val,
doap_maintainer,
NULL);
@@ -749,12 +732,14 @@ LILV_API
LilvUIs*
lilv_plugin_get_uis(const LilvPlugin* p)
{
+ lilv_plugin_load_if_necessary(p);
+
SordNode* ui_ui_node = sord_new_uri(p->world->world, NS_UI "ui");
SordNode* ui_binary_node = sord_new_uri(p->world->world, NS_UI "binary");
LilvUIs* result = lilv_uis_new();
- LilvMatches uis = lilv_plugin_find_statements(
- p,
+ LilvMatches uis = lilv_world_query(
+ p->world,
p->plugin_uri->val.uri_val,
ui_ui_node,
NULL);
diff --git a/src/port.c b/src/port.c
index 2110e4d..3845d29 100644
--- a/src/port.c
+++ b/src/port.c
@@ -59,8 +59,8 @@ static LilvNode
lilv_port_get_node(const LilvPlugin* p,
const LilvPort* port)
{
- LilvMatches ports = lilv_plugin_find_statements(
- p,
+ LilvMatches ports = lilv_world_query(
+ p->world,
p->plugin_uri->val.uri_val,
p->world->lv2_port_node,
NULL);
@@ -94,8 +94,8 @@ lilv_port_has_property(const LilvPlugin* p,
{
assert(property);
LilvNode port_node = lilv_port_get_node(p, port);
- LilvMatches results = lilv_plugin_find_statements(
- p,
+ LilvMatches results = lilv_world_query(
+ p->world,
port_node,
p->world->lv2_portproperty_node,
lilv_value_as_node(property));
@@ -115,8 +115,8 @@ lilv_port_supports_event(const LilvPlugin* p,
assert(event);
LilvNode port_node = lilv_port_get_node(p, port);
- LilvMatches results = lilv_plugin_find_statements(
- p,
+ LilvMatches results = lilv_world_query(
+ p->world,
port_node,
sord_new_uri(p->world->world, NS_EV "supportsEvent"),
lilv_value_as_node(event));
@@ -134,13 +134,13 @@ lilv_port_get_value_by_node(const LilvPlugin* p,
assert(sord_node_get_type(predicate) == SORD_URI);
LilvNode port_node = lilv_port_get_node(p, port);
- LilvMatches results = lilv_plugin_find_statements(
- p,
+ LilvMatches results = lilv_world_query(
+ p->world,
port_node,
predicate,
NULL);
- return lilv_values_from_stream_objects(p, results);
+ return lilv_values_from_stream_objects(p->world, results);
}
LILV_API
@@ -238,8 +238,8 @@ lilv_port_get_scale_points(const LilvPlugin* p,
const LilvPort* port)
{
LilvNode port_node = lilv_port_get_node(p, port);
- LilvMatches points = lilv_plugin_find_statements(
- p,
+ LilvMatches points = lilv_world_query(
+ p->world,
port_node,
sord_new_uri(p->world->world, (const uint8_t*)LILV_NS_LV2 "scalePoint"),
NULL);
diff --git a/src/query.c b/src/query.c
index d84a20f..bea8788 100644
--- a/src/query.c
+++ b/src/query.c
@@ -23,17 +23,6 @@
#include "lilv_internal.h"
-LilvMatches
-lilv_plugin_find_statements(const LilvPlugin* plugin,
- LilvNode subject,
- LilvNode predicate,
- LilvNode object)
-{
- lilv_plugin_load_if_necessary(plugin);
- SordQuad pat = { subject, predicate, object, NULL };
- return sord_find(plugin->world->model, pat);
-}
-
typedef enum {
LILV_LANG_MATCH_NONE, ///< Language does not match at all
LILV_LANG_MATCH_PARTIAL, ///< Partial (language, but not country) match
@@ -65,8 +54,8 @@ lilv_lang_matches(const char* a, const char* b)
}
LilvValues*
-lilv_values_from_stream_objects_i18n(const LilvPlugin* p,
- LilvMatches stream)
+lilv_values_from_stream_objects_i18n(LilvWorld* world,
+ LilvMatches stream)
{
LilvValues* values = lilv_values_new();
LilvNode nolang = NULL; // Untranslated value
@@ -90,13 +79,13 @@ lilv_values_from_stream_objects_i18n(const LilvPlugin* p,
if (lm == LILV_LANG_MATCH_EXACT) {
// Exact language match, add to results
- lilv_array_append(values, lilv_value_new_from_node(p->world, value));
+ lilv_array_append(values, lilv_value_new_from_node(world, value));
} else if (lm == LILV_LANG_MATCH_PARTIAL) {
// Partial language match, save in case we find no exact
partial = value;
}
} else {
- lilv_array_append(values, lilv_value_new_from_node(p->world, value));
+ lilv_array_append(values, lilv_value_new_from_node(world, value));
}
}
lilv_match_end(stream);
@@ -117,7 +106,7 @@ lilv_values_from_stream_objects_i18n(const LilvPlugin* p,
}
if (best) {
- lilv_array_append(values, lilv_value_new_from_node(p->world, best));
+ lilv_array_append(values, lilv_value_new_from_node(world, best));
} else {
// No matches whatsoever
lilv_values_free(values);
@@ -128,22 +117,22 @@ lilv_values_from_stream_objects_i18n(const LilvPlugin* p,
}
LilvValues*
-lilv_values_from_stream_objects(const LilvPlugin* p,
- LilvMatches stream)
+lilv_values_from_stream_objects(LilvWorld* world,
+ LilvMatches stream)
{
if (lilv_matches_end(stream)) {
lilv_match_end(stream);
return NULL;
- } else if (p->world->opt.filter_language) {
- return lilv_values_from_stream_objects_i18n(p, stream);
+ } else if (world->opt.filter_language) {
+ return lilv_values_from_stream_objects_i18n(world, stream);
} else {
LilvValues* values = lilv_values_new();
FOREACH_MATCH(stream) {
- lilv_array_append(
- values,
- lilv_value_new_from_node(
- p->world,
- lilv_match_object(stream)));
+ LilvValue* value = lilv_value_new_from_node(
+ world, lilv_match_object(stream));
+ if (value) {
+ lilv_array_append(values, value);
+ }
}
lilv_match_end(stream);
return values;
diff --git a/src/world.c b/src/world.c
index 03570c0..4fba762 100644
--- a/src/world.c
+++ b/src/world.c
@@ -212,6 +212,26 @@ lilv_world_find_statements(LilvWorld* world,
return sord_find(model, pat);
}
+LilvMatches
+lilv_world_query(LilvWorld* world,
+ LilvNode subject,
+ LilvNode predicate,
+ LilvNode object)
+{
+ return lilv_world_find_statements(world, world->model,
+ subject, predicate, object, NULL);
+}
+
+LilvValues*
+lilv_world_query_values(LilvWorld* world,
+ LilvNode subject,
+ LilvNode predicate,
+ LilvNode object)
+{
+ return lilv_values_from_stream_objects(world,
+ lilv_world_query(world, subject, predicate, object));
+}
+
static SerdNode
lilv_new_uri_relative_to_base(const uint8_t* uri_str,
const uint8_t* base_uri_str)