Support for plugin data in manifest.ttl

git-svn-id: http://svn.drobilla.net/lad@112 a436a847-0d15-0410-975c-d299462d15a1
This commit is contained in:
dave 2006-09-03 04:02:34 +00:00
parent 8d3c9f7caa
commit d185fe8321
4 changed files with 199 additions and 21 deletions

View File

@ -0,0 +1,10 @@
CFLAGS = -Wall -I../../../include -fPIC -g -O0
all: amp.so
amp.so: amp.o
$(LD) amp.o -o amp.so -shared
rm amp.o
clean:
rm *.o amp.so

View File

@ -0,0 +1,108 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "lv2.h"
#ifdef WIN32
#define SYMBOL_EXPORT __declspec(dllexport)
#else
#define SYMBOL_EXPORT
#endif
#define AMP_URI "http://codeson.net/plugins/amponefile"
#define AMP_GAIN 0
#define AMP_INPUT 1
#define AMP_OUTPUT 2
static LV2_Descriptor *ampDescriptor = NULL;
typedef struct {
float *gain;
float *input;
float *output;
} Amp;
static void
cleanupAmp(LV2_Handle instance) {
free(instance);
}
static void
connectPortAmp(LV2_Handle instance, uint32_t port,
void *data) {
Amp *plugin = (Amp *)instance;
switch (port) {
case AMP_GAIN:
plugin->gain = data;
break;
case AMP_INPUT:
plugin->input = data;
break;
case AMP_OUTPUT:
plugin->output = data;
break;
}
}
static LV2_Handle
instantiateAmp(const LV2_Descriptor *descriptor,
uint32_t s_rate, const char *path , const LV2_Host_Feature **features) {
Amp *plugin_data = (Amp *)malloc(sizeof(Amp));
return (LV2_Handle)plugin_data;
}
#define DB_CO(g) ((g) > -90.0f ? powf(10.0f, (g) * 0.05f) : 0.0f)
static void
runAmp(LV2_Handle instance, uint32_t sample_count) {
Amp *plugin_data = (Amp *)instance;
const float gain = *(plugin_data->gain);
const float * const input = plugin_data->input;
float * const output = plugin_data->output;
uint32_t pos;
float coef = DB_CO(gain);
for (pos = 0; pos < sample_count; pos++) {
output[pos] = input[pos] * coef;
}
}
static void
init() {
ampDescriptor =
(LV2_Descriptor *)malloc(sizeof(LV2_Descriptor));
ampDescriptor->URI = AMP_URI;
ampDescriptor->activate = NULL;
ampDescriptor->cleanup = cleanupAmp;
ampDescriptor->connect_port = connectPortAmp;
ampDescriptor->deactivate = NULL;
ampDescriptor->instantiate = instantiateAmp;
ampDescriptor->run = runAmp;
}
SYMBOL_EXPORT
const LV2_Descriptor*
lv2_descriptor(uint32_t index) {
if (!ampDescriptor) init();
switch (index) {
case 0:
return ampDescriptor;
default:
return NULL;
}
}

View File

@ -0,0 +1,58 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix lv2: <http://lv2plug.in/ontology#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix doap: <http://usefulinc.com/ns/doap#> .
<http://codeson.net/plugins/amponefile> a lv2:Plugin ;
lv2:binary <amp.so> ;
a lv2:AmplifierPlugin ;
doap:maintainer [
foaf:name "Dave Robillard";
foaf:homepage <http://codeson.net/> ;
foaf:mbox <mailto:drobilla@connect.carleton.ca>
] ;
doap:name "Simple Amplifier" ;
doap:name "Einfacher Verst¿¿rker"@de ;
doap:licence <http://usefulinc.com/doap/licenses/gpl> ;
lv2:property lv2:hardRTCapable ;
lv2:port [
a lv2:ControlRateInputPort ;
lv2:datatype lv2:float ;
lv2:index 0 ;
lv2:symbol "gain" ;
lv2:name "Gain" ;
lv2:name "Gewinn"@de ;
lv2:default [ rdf:value 0.0 ] ;
lv2:minimum [ rdf:value -90.0 ] ;
lv2:maximum [ rdf:value 24.0 ] ;
lv2:scalePoint [
rdfs:label "+5" ;
rdf:value 5.0
] , [
rdfs:label "Unity" ;
rdf:value 1.0
] , [
rdfs:label "-5" ;
rdf:value -5.0
] , [
rdfs:label "-10" ;
rdf:value -10.0
]
] , [
a lv2:AudioRateInputPort ;
lv2:datatype lv2:float ;
lv2:index 1 ;
lv2:symbol "in" ;
lv2:name "Input"
] , [
a lv2:AudioRateOutputPort ;
lv2:datatype lv2:float ;
lv2:index 2 ;
lv2:symbol "out" ;
lv2:name "Output"
]
.

View File

@ -75,54 +75,56 @@ slv2_list_load_all(SLV2List list)
/* This is the parser for manifest.ttl */
void
slv2_list_load_bundle(SLV2List list,
const char* bundle_base_uri)
const char* bundle_base_url)
{
unsigned char* manifest_uri = malloc(
(strlen((char*)bundle_base_uri) + strlen("manifest.ttl") + 2) * sizeof(unsigned char));
memcpy(manifest_uri, bundle_base_uri, strlen((char*)bundle_base_uri)+1 * sizeof(unsigned char));
if (bundle_base_uri[strlen(bundle_base_uri)-1] == '/')
strcat((char*)manifest_uri, "manifest.ttl");
unsigned char* manifest_url = malloc(
(strlen((char*)bundle_base_url) + strlen("manifest.ttl") + 2) * sizeof(unsigned char));
memcpy(manifest_url, bundle_base_url, strlen((char*)bundle_base_url)+1 * sizeof(unsigned char));
if (bundle_base_url[strlen(bundle_base_url)-1] == '/')
strcat((char*)manifest_url, "manifest.ttl");
else
strcat((char*)manifest_uri, "/manifest.ttl");
strcat((char*)manifest_url, "/manifest.ttl");
rasqal_init();
rasqal_query_results *results;
raptor_uri *base_uri = raptor_new_uri(manifest_uri);
rasqal_query *rq = rasqal_new_query("sparql", (unsigned char*)base_uri);
raptor_uri *base_url = raptor_new_uri(manifest_url);
rasqal_query *rq = rasqal_new_query("sparql", (unsigned char*)base_url);
char* query_string =
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
"PREFIX : <http://lv2plug.in/ontology#> \n\n"
"SELECT DISTINCT $plugin_uri $data_url $lib_url FROM <> WHERE { \n"
"$plugin_uri :binary $lib_url ; \n"
" rdfs:seeAlso $data_url . \n"
"$plugin_uri :binary $lib_url . \n"
"OPTIONAL { $plugin_uri rdfs:seeAlso $data_url } \n"
"} \n";
//printf("%s\n\n", query_string);
rasqal_query_prepare(rq, (unsigned char*)query_string, base_uri);
rasqal_query_prepare(rq, (unsigned char*)query_string, base_url);
results = rasqal_query_execute(rq);
while (!rasqal_query_results_finished(results)) {
// Create a new plugin
struct _Plugin* new_plugin = malloc(sizeof(struct _Plugin));
new_plugin->bundle_url = strdup(bundle_base_uri);
new_plugin->bundle_url = strdup(bundle_base_url);
rasqal_literal* literal = NULL;
literal = rasqal_query_results_get_binding_value_by_name(results, (const unsigned char*)"plugin_uri");
if (literal)
new_plugin->plugin_uri = strdup((const char*)rasqal_literal_as_string(literal));
assert(literal);
new_plugin->plugin_uri = strdup((const char*)rasqal_literal_as_string(literal));
literal = rasqal_query_results_get_binding_value_by_name(results, (const unsigned char*)"lib_url");
assert(literal);
new_plugin->lib_url = strdup((const char*)rasqal_literal_as_string(literal));
literal = rasqal_query_results_get_binding_value_by_name(results, (const unsigned char*)"data_url");
if (literal)
new_plugin->data_url = strdup((const char*)rasqal_literal_as_string(literal));
literal = rasqal_query_results_get_binding_value_by_name(results, (const unsigned char*)"lib_url");
if (literal)
new_plugin->lib_url = strdup((const char*)rasqal_literal_as_string(literal));
else
new_plugin->data_url = strdup((const char*)manifest_url);
/* Add the plugin if it's valid */
if (new_plugin->lib_url && new_plugin->data_url && new_plugin->plugin_uri
@ -142,11 +144,11 @@ slv2_list_load_bundle(SLV2List list,
if (results) {
rasqal_free_query_results(results);
//rasqal_free_query(rq); // FIXME: crashes? leak?
raptor_free_uri(base_uri); // FIXME: leak?
raptor_free_uri(base_url);
}
rasqal_finish();
free(manifest_uri);
free(manifest_url);
}