summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slv2/plugin.h5
-rw-r--r--src/plugin.c29
-rw-r--r--src/port.c2
-rw-r--r--src/query.c8
-rw-r--r--src/slv2_internal.h3
-rw-r--r--utils/ladspa2lv2.c154
6 files changed, 153 insertions, 48 deletions
diff --git a/slv2/plugin.h b/slv2/plugin.h
index fa43be0..7e7c928 100644
--- a/slv2/plugin.h
+++ b/slv2/plugin.h
@@ -265,7 +265,8 @@ slv2_plugin_get_optional_features(SLV2Plugin p);
*
* \param plugin The plugin to query.
* \param sparql_str A SPARQL SELECT query.
- * \param variable The variable to return results for.
+ * \param variable The index of the variable to return results for
+ * (i.e. with "<code>SELECT ?foo ?bar</code>" foo is 0, and bar is 1).
* \return All matches for \a variable.
*
* Time = Query
@@ -273,7 +274,7 @@ slv2_plugin_get_optional_features(SLV2Plugin p);
SLV2Values
slv2_plugin_simple_query(SLV2Plugin plugin,
const char* sparql_str,
- const char* variable);
+ unsigned variable);
/** Query a plugin and return the number of results found.
diff --git a/src/plugin.c b/src/plugin.c
index 19418fe..6919513 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -350,7 +350,7 @@ slv2_plugin_get_value(SLV2Plugin p,
"<> ", predicate, " ?value .\n"
"}\n", NULL);
- SLV2Values result = slv2_plugin_simple_query(p, query, "value");
+ SLV2Values result = slv2_plugin_simple_query(p, query, 0);
free(query);
@@ -370,7 +370,7 @@ slv2_plugin_get_value_for_subject(SLV2Plugin p,
subject, " ", predicate, " ?value .\n"
"}\n", NULL);
- SLV2Values result = slv2_plugin_simple_query(p, query, "value");
+ SLV2Values result = slv2_plugin_simple_query(p, query, 0);
free(query);
@@ -404,20 +404,19 @@ slv2_plugin_has_latency(SLV2Plugin p)
{
const char* const query =
"ASK WHERE {\n"
- " <> lv2:port ?port .\n"
+ " <> lv2:port ?port .\n"
" ?port lv2:portHint lv2:reportsLatency ;\n"
" lv2:index ?index .\n"
"}\n";
- SLV2Values results = slv2_plugin_simple_query(p, query, "port");
+ librdf_query_results* results = slv2_plugin_query(p, query);
+ assert(librdf_query_results_is_boolean(results));
- if (results) {
- bool exists = (results && slv2_values_size(results) > 0);
- slv2_values_free(results);
- return exists;
- } else {
- return false;
- }
+ bool ret = (librdf_query_results_get_boolean(results) > 0);
+
+ librdf_free_query_results(results);
+
+ return ret;
}
@@ -431,7 +430,7 @@ slv2_plugin_get_latency_port(SLV2Plugin p)
" lv2:index ?index .\n"
"}\n";
- SLV2Values result = slv2_plugin_simple_query(p, query, "index");
+ SLV2Values result = slv2_plugin_simple_query(p, query, 0);
// FIXME: need a sane error handling strategy
assert(slv2_values_size(result) > 0);
@@ -452,7 +451,7 @@ slv2_plugin_get_supported_features(SLV2Plugin p)
" { <> lv2:requiredHostFeature ?feature }\n"
"}\n";
- SLV2Values result = slv2_plugin_simple_query(p, query, "feature");
+ SLV2Values result = slv2_plugin_simple_query(p, query, 0);
return result;
}
@@ -466,7 +465,7 @@ slv2_plugin_get_optional_features(SLV2Plugin p)
" <> lv2:optionalHostFeature ?feature .\n"
"}\n";
- SLV2Values result = slv2_plugin_simple_query(p, query, "feature");
+ SLV2Values result = slv2_plugin_simple_query(p, query, 0);
return result;
}
@@ -480,7 +479,7 @@ slv2_plugin_get_required_features(SLV2Plugin p)
" <> lv2:requiredHostFeature ?feature .\n"
"}\n";
- SLV2Values result = slv2_plugin_simple_query(p, query, "feature");
+ SLV2Values result = slv2_plugin_simple_query(p, query, 0);
return result;
}
diff --git a/src/port.c b/src/port.c
index 6744274..635b4b6 100644
--- a/src/port.c
+++ b/src/port.c
@@ -128,7 +128,7 @@ slv2_port_get_value(SLV2Plugin p,
"?port lv2:symbol \"", port->symbol, "\";\n\t",
property, " ?value .\n}", 0);
- result = slv2_plugin_simple_query(p, query, "value");
+ result = slv2_plugin_simple_query(p, query, 0);
free(query);
diff --git a/src/query.c b/src/query.c
index bc1a7dc..b7eae2d 100644
--- a/src/query.c
+++ b/src/query.c
@@ -53,7 +53,7 @@ slv2_query_lang_filter(const char* variable)
SLV2Values
slv2_query_get_variable_bindings(librdf_query_results* results,
- const char* variable)
+ int variable)
{
SLV2Values result = NULL;
@@ -63,7 +63,7 @@ slv2_query_get_variable_bindings(librdf_query_results* results,
while (!librdf_query_results_finished(results)) {
librdf_node* node =
- librdf_query_results_get_binding_value_by_name(results, variable);
+ librdf_query_results_get_binding_value(results, variable);
librdf_uri* datatype_uri = NULL;
SLV2ValueType type = SLV2_VALUE_STRING;
@@ -94,7 +94,7 @@ slv2_query_get_variable_bindings(librdf_query_results* results,
break;
case LIBRDF_NODE_TYPE_UNKNOWN:
default:
- fprintf(stderr, "Unknown variable binding type for ?%s\n", variable);
+ fprintf(stderr, "Unknown variable binding type %d\n", variable);
break;
}
@@ -158,7 +158,7 @@ slv2_plugin_query(SLV2Plugin plugin,
SLV2Values
slv2_plugin_simple_query(SLV2Plugin plugin,
const char* sparql_str,
- const char* variable)
+ unsigned variable)
{
librdf_query_results* results = slv2_plugin_query(plugin, sparql_str);
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index 180f07d..dba9832 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -66,6 +66,9 @@ SLV2Plugin slv2_plugin_new(SLV2World world, librdf_uri* uri, const char* binary_
void slv2_plugin_load(SLV2Plugin p);
void slv2_plugin_free(SLV2Plugin plugin);
+librdf_query_results* slv2_plugin_query(SLV2Plugin plugin,
+ const char* sparql_str);
+
/** Create a new, empty plugin list.
*
diff --git a/utils/ladspa2lv2.c b/utils/ladspa2lv2.c
index 713481f..304f70d 100644
--- a/utils/ladspa2lv2.c
+++ b/utils/ladspa2lv2.c
@@ -16,9 +16,13 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
+#include <stdbool.h>
+#include <float.h>
+#include <math.h>
#include <ladspa.h>
#include <dlfcn.h>
#include <librdf.h>
@@ -30,26 +34,6 @@
librdf_world* world = NULL;
-LADSPA_Descriptor*
-load_ladspa_plugin(const char* lib_path, unsigned long index)
-{
- void* const handle = dlopen(lib_path, RTLD_LAZY);
- if (handle == NULL)
- return NULL;
-
- LADSPA_Descriptor_Function df
- = (LADSPA_Descriptor_Function)dlsym(handle, "ladspa_descriptor");
-
- if (df == NULL) {
- dlclose(handle);
- return NULL;
- }
-
- LADSPA_Descriptor* const descriptor = (LADSPA_Descriptor*)df(index);
-
- return descriptor;
-}
-
void
add_resource(librdf_model* model,
@@ -149,6 +133,126 @@ add_float(librdf_model* model,
}
+LADSPA_Descriptor*
+load_ladspa_plugin(const char* lib_path, unsigned long index)
+{
+ void* const handle = dlopen(lib_path, RTLD_LAZY);
+ if (handle == NULL)
+ return NULL;
+
+ LADSPA_Descriptor_Function df
+ = (LADSPA_Descriptor_Function)dlsym(handle, "ladspa_descriptor");
+
+ if (df == NULL) {
+ dlclose(handle);
+ return NULL;
+ }
+
+ LADSPA_Descriptor* const descriptor = (LADSPA_Descriptor*)df(index);
+
+ return descriptor;
+}
+
+
+void
+add_port_range(LADSPA_Descriptor* plugin,
+ unsigned long port_index,
+ librdf_model* model,
+ librdf_node* port)
+{
+ LADSPA_PortRangeHintDescriptor hint_descriptor
+ = plugin->PortRangeHints[port_index].HintDescriptor;
+
+ bool range_valid = false;
+ float upper, lower, normal;
+
+ /* Convert hints */
+
+ if (LADSPA_IS_HINT_SAMPLE_RATE(hint_descriptor)) {
+ add_resource(model, port, NS_LV2("portHint"), NS_LV2("sampleRate"));
+ upper = plugin->PortRangeHints[port_index].UpperBound;
+ lower = plugin->PortRangeHints[port_index].LowerBound;
+ range_valid = true;
+ }
+
+ if (LADSPA_IS_HINT_INTEGER(hint_descriptor)) {
+ add_resource(model, port, NS_LV2("portHint"), NS_LV2("integer"));
+ upper = plugin->PortRangeHints[port_index].UpperBound;
+ lower = plugin->PortRangeHints[port_index].LowerBound;
+ range_valid = true;
+ }
+
+ if (LADSPA_IS_HINT_TOGGLED(hint_descriptor)) {
+ add_resource(model, port, NS_LV2("portHint"), NS_LV2("toggled"));
+ upper = 1.0;
+ lower = 0.0;
+ range_valid = true;
+ }
+
+ if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
+ /* FLT_EPSILON is defined as the different between 1.0 and the minimum
+ * float greater than 1.0. So, if lower is < FLT_EPSILON, it will be 1.0
+ * and the logarithmic control will have a base of 1 and thus not change
+ */
+ if (range_valid && lower < FLT_EPSILON)
+ lower = FLT_EPSILON;
+ }
+
+
+ if (LADSPA_IS_HINT_HAS_DEFAULT(hint_descriptor)) {
+
+ bool valid = true;
+
+ if (range_valid && LADSPA_IS_HINT_DEFAULT_MINIMUM(hint_descriptor)) {
+ normal = lower;
+ } else if (range_valid && LADSPA_IS_HINT_DEFAULT_LOW(hint_descriptor)) {
+ if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
+ normal = exp(log(lower) * 0.75 + log(upper) * 0.25);
+ } else {
+ normal = lower * 0.75 + upper * 0.25;
+ }
+ } else if (range_valid && LADSPA_IS_HINT_DEFAULT_MIDDLE(hint_descriptor)) {
+ if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
+ normal = exp(log(lower) * 0.5 + log(upper) * 0.5);
+ } else {
+ normal = lower * 0.5 + upper * 0.5;
+ }
+ } else if (range_valid && LADSPA_IS_HINT_DEFAULT_HIGH(hint_descriptor)) {
+ if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
+ normal = exp(log(lower) * 0.25 + log(upper) * 0.75);
+ } else {
+ normal = lower * 0.25 + upper * 0.75;
+ }
+ } else if (range_valid && LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint_descriptor)) {
+ normal = upper;
+ } else if (LADSPA_IS_HINT_DEFAULT_0(hint_descriptor)) {
+ normal = 0.0;
+ } else if (LADSPA_IS_HINT_DEFAULT_1(hint_descriptor)) {
+ normal = 1.0;
+ } else if (LADSPA_IS_HINT_DEFAULT_100(hint_descriptor)) {
+ normal = 100.0;
+ } else if (LADSPA_IS_HINT_DEFAULT_440(hint_descriptor)) {
+ normal = 440.0;
+ } else {
+ valid = false;
+ }
+
+ if (valid)
+ add_float(model, port, NS_LV2("default"), normal);
+
+ } else { // No default hint
+
+ if (range_valid && LADSPA_IS_HINT_BOUNDED_BELOW(hint_descriptor)) {
+ normal = lower;
+ add_float(model, port, NS_LV2("default"), normal);
+ } else if (range_valid && LADSPA_IS_HINT_BOUNDED_ABOVE(hint_descriptor)) {
+ normal = upper;
+ add_float(model, port, NS_LV2("default"), normal);
+ }
+ }
+}
+
+
void
write_lv2_turtle(LADSPA_Descriptor* descriptor, const char* plugin_uri, const char* filename)
{
@@ -203,10 +307,6 @@ write_lv2_turtle(LADSPA_Descriptor* descriptor, const char* plugin_uri, const ch
NS_LV2("index"),
(int)i);
- add_resource(model, port_node,
- NS_RDF("type"),
- NS_LV2("Port"));
-
if (LADSPA_IS_PORT_INPUT(port_descriptor))
add_resource(model, port_node,
NS_RDF("type"),
@@ -219,15 +319,17 @@ write_lv2_turtle(LADSPA_Descriptor* descriptor, const char* plugin_uri, const ch
if (LADSPA_IS_PORT_AUDIO(port_descriptor))
add_resource(model, port_node,
NS_RDF("type"),
- NS_LV2("ControlPort"));
+ NS_LV2("AudioPort"));
else
add_resource(model, port_node,
NS_RDF("type"),
- NS_LV2("AudioPort"));
+ NS_LV2("ControlPort"));
add_string(model, port_node,
NS_LV2("name"),
descriptor->PortNames[i]);
+
+ add_port_range(descriptor, i, model, port_node);
}
librdf_serializer_serialize_model_to_file(serializer, filename, NULL, model);