From 2cd84e4209633e59439c445f821bed8410347bab Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 26 Jul 2006 03:25:08 +0000 Subject: - Removed all the unsigned char garbage from the API - Updated types in lv2.h to be non-machine-dependant (removed unsigned long in favour of uint32_t) - Updated schema - Updated example plugin to work with the above (partially) git-svn-id: http://svn.drobilla.net/lad/libslv2@101 a436a847-0d15-0410-975c-d299462d15a1 --- examples/hosts/jack_host.c | 15 ++-- examples/hosts/test_host.c | 69 ++---------------- examples/plugins/Amp-slv2.lv2/Makefile | 10 +++ examples/plugins/Amp-slv2.lv2/amp.c | 108 +++++++++++++++++++++++++++++ examples/plugins/Amp-slv2.lv2/amp.ttl | 57 +++++++++++++++ examples/plugins/Amp-slv2.lv2/manifest.ttl | 11 +++ examples/plugins/Amp-swh.lv2/Makefile | 10 --- examples/plugins/Amp-swh.lv2/amp.c | 96 ------------------------- examples/plugins/Amp-swh.lv2/amp.ttl | 68 ------------------ examples/plugins/Amp-swh.lv2/manifest.ttl | 9 --- 10 files changed, 199 insertions(+), 254 deletions(-) create mode 100644 examples/plugins/Amp-slv2.lv2/Makefile create mode 100644 examples/plugins/Amp-slv2.lv2/amp.c create mode 100644 examples/plugins/Amp-slv2.lv2/amp.ttl create mode 100644 examples/plugins/Amp-slv2.lv2/manifest.ttl delete mode 100644 examples/plugins/Amp-swh.lv2/Makefile delete mode 100644 examples/plugins/Amp-swh.lv2/amp.c delete mode 100644 examples/plugins/Amp-swh.lv2/amp.ttl delete mode 100644 examples/plugins/Amp-swh.lv2/manifest.ttl (limited to 'examples') diff --git a/examples/hosts/jack_host.c b/examples/hosts/jack_host.c index 1be62b8..a29fb13 100644 --- a/examples/hosts/jack_host.c +++ b/examples/hosts/jack_host.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -27,14 +28,14 @@ struct JackHost { jack_client_t* jack_client; /**< Jack client */ SLV2Plugin* plugin; /**< Plugin "class" (actually just a few strings) */ SLV2Instance* instance; /**< Plugin "instance" (loaded shared lib) */ - unsigned long num_ports; /**< Size of the two following arrays: */ + size_t num_ports; /**< Size of the two following arrays: */ jack_port_t** jack_ports; /**< For audio ports, otherwise NULL */ float* controls; /**< For control ports, otherwise 0.0f */ }; void die(const char* msg); -void create_port(struct JackHost* host, unsigned long port_index); +void create_port(struct JackHost* host, uint32_t port_index); int jack_process_cb(jack_nframes_t nframes, void* data); void list_plugins(SLV2List list); @@ -99,7 +100,7 @@ main(int argc, char** argv) host.jack_ports = calloc(host.num_ports, sizeof(jack_port_t*)); host.controls = calloc(host.num_ports, sizeof(float*)); - for (unsigned long i=0; i < host.num_ports; ++i) + for (size_t i=0; i < host.num_ports; ++i) create_port(&host, i); /* Activate plugin and JACK */ @@ -146,10 +147,10 @@ die(const char* msg) */ void create_port(struct JackHost* host, - unsigned long port_index) + uint32_t port_index) { /* Make sure this is a float port */ - uchar* type = slv2_port_get_data_type(host->plugin, port_index); + char* type = slv2_port_get_data_type(host->plugin, port_index); if (strcmp(type, SLV2_DATA_TYPE_FLOAT)) die("Unrecognized data type, aborting."); free(type); @@ -197,7 +198,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) struct JackHost* host = (struct JackHost*)data; /* Connect plugin ports directly to JACK buffers */ - for (unsigned long i=0; i < host->num_ports; ++i) + for (size_t i=0; i < host->num_ports; ++i) if (host->jack_ports[i] != NULL) slv2_instance_connect_port(host->instance, i, jack_port_get_buffer(host->jack_ports[i], nframes)); @@ -212,7 +213,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) void list_plugins(SLV2List list) { - for (int i=0; i < slv2_list_get_length(list); ++i) { + for (size_t i=0; i < slv2_list_get_length(list); ++i) { const SLV2Plugin* const p = slv2_list_get_plugin_by_index(list, i); printf("%s\n", slv2_plugin_get_uri(p)); } diff --git a/examples/hosts/test_host.c b/examples/hosts/test_host.c index 16efa11..97df831 100644 --- a/examples/hosts/test_host.c +++ b/examples/hosts/test_host.c @@ -61,7 +61,7 @@ create_audio_output() void create_port(SLV2Plugin* plugin, SLV2Instance* instance, - unsigned long port_index) + uint32_t port_index) { enum SLV2PortClass class = slv2_port_get_class(plugin, port_index); @@ -102,14 +102,14 @@ main() const SLV2Plugin* p = slv2_list_get_plugin_by_uri(plugins, plugin_uri); if (p) { /* Get the plugin's name */ - unsigned char* name = slv2_plugin_get_name(p); + char* name = slv2_plugin_get_name(p); printf("Name:\t%s\n", name); free(name); - unsigned long num_ports = slv2_plugin_get_num_ports(p); + uint32_t num_ports = slv2_plugin_get_num_ports(p); //printf("Number of ports: %ld\n", num_ports); - for (unsigned long i=0; i < num_ports; ++i) { + for (uint32_t i=0; i < num_ports; ++i) { enum SLV2PortClass class = slv2_port_get_class(p, i); switch (class) { @@ -134,7 +134,7 @@ main() } SLV2Property prop; - for (unsigned long i=0; i < num_ports; ++i) { + for (uint32_t i=0; i < num_ports; ++i) { const char* property = "a"; prop = slv2_port_get_property(p, i, property); if (prop) @@ -167,65 +167,6 @@ main() slv2_list_free(plugins); -#if 0 - /* Display all plugins found in path */ - if (plugins) - printf("Plugins found: %ld\n", slv2_list_get_size(plugins)); - else - printf("No plugins found in %s\n", path); - - for (unsigned long i=0; 1; ++i) { - const SLV2Plugin* p = - slv2_list_get_plugin_by_index(plugins, i); - - if (!p) - break; - else - printf("\t%s\n", slv2_plugin_get_uri(p)); - } -#endif - -#if 0 - const uchar* bundle_url = (const uchar*)"file:/home/dave/code/ladspa2/ladspa2_sdk/examples/plugins/Amp-swh.ladspa2/"; - LV2Bundle* b = slv2_bundle_load(bundle_url); - - if (b != NULL) { - printf("Loaded bundle %s\n", slv2_bundle_get_url(b)); - - for (unsigned long i=0; i < slv2_bundle_get_num_plugins(b); ++i) { - const SLV2Plugin* p = slv2_bundle_get_plugin_by_index(b, i); - //printf("Plugin: %s\n", p->plugin_uri); - //printf("Lib: %s\n", p->lib_url); - //printf("Data: %s\n", p->data_url); - - printf("\n"); - const uchar* property = (uchar*)"doap:name"; - printf("%s\t%s\n", slv2_plugin_get_uri(p), property); - struct SLV2Property* result = slv2_plugin_get_property(p, property); - - if (result) { - for (int i=0; i < result->num_values; ++i) - printf("\t%s\n", result->values[i]); - } else { - printf("No results.\n"); - } - printf("\n"); - - /* Instantiate plugin */ - SLV2PluginInstance* instance = slv2_plugin_instantiate( - p, 48000, NULL); - if (instance != NULL) { - printf("Successfully instantiated %s\n", slv2_plugin_get_uri(p)); - slv2_plugin_instance_free(instance); - } - - } - - } else { - printf("Failed to load bundle %s\n", bundle_url); - } -#endif - return 0; } diff --git a/examples/plugins/Amp-slv2.lv2/Makefile b/examples/plugins/Amp-slv2.lv2/Makefile new file mode 100644 index 0000000..55180c2 --- /dev/null +++ b/examples/plugins/Amp-slv2.lv2/Makefile @@ -0,0 +1,10 @@ +CFLAGS = -Wall -I../../../include -fPIC + +all: amp.so + +amp.so: amp.o + $(LD) amp.o -o amp.so -shared + rm amp.o + +clean: + rm *.o amp.so diff --git a/examples/plugins/Amp-slv2.lv2/amp.c b/examples/plugins/Amp-slv2.lv2/amp.c new file mode 100644 index 0000000..e6b891e --- /dev/null +++ b/examples/plugins/Amp-slv2.lv2/amp.c @@ -0,0 +1,108 @@ +#include +#include + +#include + +#include "lv2.h" + +#ifdef WIN32 +#define SYMBOL_EXPORT __declspec(dllexport) +#else +#define SYMBOL_EXPORT +#endif + +#define AMP_URI "http://codeson.net/plugins/amp" +#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, unsigned long 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, + unsigned long 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, unsigned long 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; + + unsigned long 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(unsigned long index) { + if (!ampDescriptor) init(); + + switch (index) { + case 0: + return ampDescriptor; + default: + return NULL; + } +} + diff --git a/examples/plugins/Amp-slv2.lv2/amp.ttl b/examples/plugins/Amp-slv2.lv2/amp.ttl new file mode 100644 index 0000000..abc5b33 --- /dev/null +++ b/examples/plugins/Amp-slv2.lv2/amp.ttl @@ -0,0 +1,57 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix lv2: . +@prefix foaf: . +@prefix doap: . + + a lv2:Plugin ; + a lv2:AmplifierPlugin ; + doap:maintainer [ + foaf:name "Dave Robillard"; + foaf:homepage ; + foaf:mbox + ] ; + doap:name "Simple Amplifier" ; + doap:name "Einfacher Verstrker"@de ; + doap:licence ; + + 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" + ] +. + diff --git a/examples/plugins/Amp-slv2.lv2/manifest.ttl b/examples/plugins/Amp-slv2.lv2/manifest.ttl new file mode 100644 index 0000000..94456e6 --- /dev/null +++ b/examples/plugins/Amp-slv2.lv2/manifest.ttl @@ -0,0 +1,11 @@ +# LV2 Plugin Manifest +# Lists where plugins' data files and shared objects reside. + +@prefix lv2: . +@prefix rdfs: . + + + lv2:binary ; + rdfs:seeAlso . + + diff --git a/examples/plugins/Amp-swh.lv2/Makefile b/examples/plugins/Amp-swh.lv2/Makefile deleted file mode 100644 index 55180c2..0000000 --- a/examples/plugins/Amp-swh.lv2/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CFLAGS = -Wall -I../../../include -fPIC - -all: amp.so - -amp.so: amp.o - $(LD) amp.o -o amp.so -shared - rm amp.o - -clean: - rm *.o amp.so diff --git a/examples/plugins/Amp-swh.lv2/amp.c b/examples/plugins/Amp-swh.lv2/amp.c deleted file mode 100644 index a30c4bd..0000000 --- a/examples/plugins/Amp-swh.lv2/amp.c +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include - -#include - -#include "lv2.h" - -#ifdef WIN32 -#define SYMBOL_EXPORT __declspec(dllexport) -#else -#define SYMBOL_EXPORT -#endif - -#define AMP_URI "http://plugin.org.uk/swh-plugins/amp"; -#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, unsigned long 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, - unsigned long 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, unsigned long 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; - - unsigned long 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(unsigned long index) { - if (!ampDescriptor) init(); - - switch (index) { - case 0: - return ampDescriptor; - default: - return NULL; - } -} - diff --git a/examples/plugins/Amp-swh.lv2/amp.ttl b/examples/plugins/Amp-swh.lv2/amp.ttl deleted file mode 100644 index d44c0b9..0000000 --- a/examples/plugins/Amp-swh.lv2/amp.ttl +++ /dev/null @@ -1,68 +0,0 @@ -@prefix lv2: . -@prefix foaf: . -@prefix doap: . - - a lv2:Plugin ; - a lv2:AmplifierPlugin ; - doap:maintainer [ - foaf:name "Steve Harris"; - foaf:homepage ; - foaf:mbox ; - ] ; - doap:name "Simple amplifier" ; - doap:name "简单放大器"@ch ; - doap:name "Einfacher Verstärker"@de ; - doap:name "Simple amp"@en-gb ; - doap:name "Amplificador simple"@es ; - doap:name "Amplificateur de base"@fr ; - doap:name "Amplificatore semplice"@it ; - doap:name "簡単なアンプ"@jp ; - doap:name "Просто усилитель"@ru ; - doap:licence ; - lv2:property lv2:hardRtCapable ; - - lv2:port [ - a lv2:InputControlRatePort ; - lv2:datatype lv2:float ; - lv2:index 0 ; - lv2:symbol "gain" ; - lv2:name "gain" ; - lv2:name "收益"@ch ; - lv2:name "gewinn"@de ; - lv2:name "gain"@en-gb ; - lv2:name "aumento"@es ; - lv2:name "gain"@fr ; - lv2:name "guadagno"@it ; - lv2:name "利益"@jp ; - lv2:name "увеличение"@ru ; - lv2:default 0.0 ; - lv2:minimum -90.0 ; - lv2:maximum 24.0 ; - lv2:scalePoint [ - lv2:label "+5" ; - lv2:value 5.0 ; - ] , [ - lv2:label "0" ; - lv2:value 0.0 ; - ] , [ - lv2:label "-5" ; - lv2:value -5.0 ; - ] , [ - lv2:label "-10" ; - lv2:value -10.0 ; - ] - ] , [ - a lv2:InputAudioRatePort ; - lv2:datatype lv2:float ; - lv2:index 1 ; - lv2:symbol "in" ; - lv2:name "in" ; - ] , [ - a lv2:OutputAudioRatePort ; - lv2:datatype lv2:float ; - lv2:index 2 ; - lv2:symbol "out" ; - lv2:name "out" ; - ] -. - diff --git a/examples/plugins/Amp-swh.lv2/manifest.ttl b/examples/plugins/Amp-swh.lv2/manifest.ttl deleted file mode 100644 index a26f506..0000000 --- a/examples/plugins/Amp-swh.lv2/manifest.ttl +++ /dev/null @@ -1,9 +0,0 @@ -# LV2 Plugin Manifest -# Lists where plugins' data files and shared objects reside. - -@prefix lv2: . -@prefix rdfs: . - - lv2:binary ; - rdfs:seeAlso . - -- cgit v1.2.1