From 1988a63b41a0e81f348d5df3394d41d3248d442b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 5 Feb 2007 22:34:56 +0000 Subject: Reorganized tree in preparation for beta release. Split simple (example) jack host and more useful one (with midi). Working Jack/LV2 midi in lv2_jack_host. Added lv2_list. git-svn-id: http://svn.drobilla.net/lad/slv2@279 a436a847-0d15-0410-975c-d299462d15a1 --- Makefile.am | 2 +- configure.ac | 24 +- examples/Makefile.am | 2 - examples/hosts/Makefile.am | 37 --- examples/hosts/host.c | 341 --------------------- examples/hosts/lv2-midifunctions.h | 161 ---------- examples/hosts/lv2-miditype.h | 170 ---------- examples/hosts/simple_jack_host.c | 220 ------------- examples/hosts/test_host.c | 170 ---------- examples/plugins/Amp-onefile-slv2.lv2/Makefile | 10 - examples/plugins/Amp-onefile-slv2.lv2/amp.c | 108 ------- examples/plugins/Amp-onefile-slv2.lv2/manifest.ttl | 58 ---- 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/Makefile.am | 24 -- hosts/Makefile.am | 18 ++ hosts/lv2-midifunctions.h | 161 ++++++++++ hosts/lv2-miditype.h | 170 ++++++++++ hosts/lv2_jack_host.c | 338 ++++++++++++++++++++ hosts/lv2_simple_jack_host.c | 220 +++++++++++++ src/plugininstance.c | 8 +- src/pluginlist.c | 2 +- utils/Makefile.am | 13 +- utils/README | 3 + utils/ladspa2lv2.cc | 196 ------------ utils/ladspa2lv2.cpp | 199 ++++++++++++ utils/lv2_list.c | 43 +++ 29 files changed, 1178 insertions(+), 1706 deletions(-) delete mode 100644 examples/Makefile.am delete mode 100644 examples/hosts/Makefile.am delete mode 100644 examples/hosts/host.c delete mode 100644 examples/hosts/lv2-midifunctions.h delete mode 100644 examples/hosts/lv2-miditype.h delete mode 100644 examples/hosts/simple_jack_host.c delete mode 100644 examples/hosts/test_host.c delete mode 100644 examples/plugins/Amp-onefile-slv2.lv2/Makefile delete mode 100644 examples/plugins/Amp-onefile-slv2.lv2/amp.c delete mode 100644 examples/plugins/Amp-onefile-slv2.lv2/manifest.ttl delete mode 100644 examples/plugins/Amp-slv2.lv2/Makefile delete mode 100644 examples/plugins/Amp-slv2.lv2/amp.c delete mode 100644 examples/plugins/Amp-slv2.lv2/amp.ttl delete mode 100644 examples/plugins/Amp-slv2.lv2/manifest.ttl delete mode 100644 examples/plugins/Makefile.am create mode 100644 hosts/Makefile.am create mode 100644 hosts/lv2-midifunctions.h create mode 100644 hosts/lv2-miditype.h create mode 100644 hosts/lv2_jack_host.c create mode 100644 hosts/lv2_simple_jack_host.c create mode 100644 utils/README delete mode 100644 utils/ladspa2lv2.cc create mode 100644 utils/ladspa2lv2.cpp create mode 100644 utils/lv2_list.c diff --git a/Makefile.am b/Makefile.am index 5646891..66af074 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = src slv2 utils examples data doc +SUBDIRS = src slv2 utils hosts data doc pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libslv2.pc diff --git a/configure.ac b/configure.ac index 14fd78a..cde28b8 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,8 @@ AC_PREREQ(2.59) -AC_INIT([libslv2],[0.0.1],[drobilla@connect.carleton.ca]) +AC_INIT([libslv2],[0.0.1],[dave@drobilla.net]) AC_CONFIG_SRCDIR([src/plugin.c]) AC_CONFIG_SRCDIR([slv2/plugin.h]) -AC_CONFIG_SRCDIR([utils/ladspa2lv2.cc]) -AC_CONFIG_SRCDIR([examples/plugins/Amp-swh.lv2/amp.c]) -AC_CONFIG_SRCDIR([examples/hosts/test_host.c]) +AC_CONFIG_SRCDIR([utils/lv2_list.c]) AC_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE @@ -72,25 +70,23 @@ AC_ARG_WITH(lv2-dir, AC_MSG_RESULT($lv2dir) AC_SUBST(lv2dir) -# Build utilities? -build_utilities="no" -AC_ARG_ENABLE(utilities, - [AS_HELP_STRING(--enable-utilities, [Build utilities (no) - EXPERIMENTAL])], - [build_utilities="$enableval"]) -if test "$build_utilities" = "yes"; then +# Build ladspa converter? +build_ladspa2lv2="no" +AC_ARG_ENABLE(ladspa2lv2, + [AS_HELP_STRING(--enable-ladspa2lv2, [Build ladspa2lv2 (no) - BROKEN])], + [build_ladspa2lv2="$enableval"]) +if test "$build_ladspa2lv2" = "yes"; then AC_PROG_CXX PKG_CHECK_MODULES(RAUL, raul >= 0.0.0) fi -AM_CONDITIONAL(BUILD_UTILITIES, [test "$build_utilities" = "yes"]) +AM_CONDITIONAL(BUILD_LADSPA2SLV2, [test "$build_ladspa2lv2" = "yes"]) # Write output files AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([src/Makefile]) AC_CONFIG_FILES([slv2/Makefile]) AC_CONFIG_FILES([utils/Makefile]) -AC_CONFIG_FILES([examples/Makefile]) -AC_CONFIG_FILES([examples/plugins/Makefile]) -AC_CONFIG_FILES([examples/hosts/Makefile]) +AC_CONFIG_FILES([hosts/Makefile]) AC_CONFIG_FILES([data/Makefile]) AC_CONFIG_FILES([libslv2.pc]) AC_CONFIG_FILES([doc/Makefile]) diff --git a/examples/Makefile.am b/examples/Makefile.am deleted file mode 100644 index 94939c3..0000000 --- a/examples/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -SUBDIRS = plugins hosts - diff --git a/examples/hosts/Makefile.am b/examples/hosts/Makefile.am deleted file mode 100644 index f483161..0000000 --- a/examples/hosts/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -AM_CFLAGS = -std=c99 -I$(top_srcdir) @RASQAL_CFLAGS@ - -bin_PROGRAMS = slv2_test_host - -if WITH_JACK -bin_PROGRAMS += slv2_simple_jack_host slv2_host -endif - -slv2_test_host_DEPENDENCIES = ../../src/libslv2.la -slv2_test_host_LDADD = ../../src/libslv2.la - -slv2_test_host_SOURCES = \ - test_host.c - - -if WITH_JACK - -slv2_simple_jack_host_CFLAGS = @JACK_CFLAGS@ $(AM_CFLAGS) - -slv2_simple_jack_host_DEPENDENCIES = ../../src/libslv2.la -slv2_simple_jack_host_LDADD = ../../src/libslv2.la @JACK_LIBS@ @RASQAL_LIBS@ - -slv2_simple_jack_host_SOURCES = \ - simple_jack_host.c - - -slv2_host_CFLAGS = @JACK_CFLAGS@ $(AM_CFLAGS) - - -slv2_host_DEPENDENCIES = ../../src/libslv2.la -slv2_host_LDADD = ../../src/libslv2.la @JACK_LIBS@ @RASQAL_LIBS@ - -slv2_host_SOURCES = \ - host.c - - -endif # WITH_JACK diff --git a/examples/hosts/host.c b/examples/hosts/host.c deleted file mode 100644 index 97937a8..0000000 --- a/examples/hosts/host.c +++ /dev/null @@ -1,341 +0,0 @@ -/* LibSLV2 Jack Example Host - * Copyright (C) 2006 Dave Robillard - * - * This program 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 program 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 -#include -#include -#include -#include - -#define WITH_MIDI 1 -#define MIDI_BUFFER_SIZE 1024 - -#ifdef WITH_MIDI -#include -#include "lv2-miditype.h" -#include "lv2-midifunctions.h" -#endif // WITH_MIDI - -struct Port { - enum Direction { INPUT, OUTPUT} direction; - enum Type { UNKNOWN, FLOAT, MIDI } type; - - jack_port_t* jack_port; /**< For audio and MIDI ports, otherwise NULL */ - float control; /**< For control ports, otherwise 0.0f */ - LV2_MIDI* midi_buffer; /**< For midi ports, otherwise NULL */ -}; - - -/** This program's data */ -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) */ - uint32_t num_ports; /**< Size of the two following arrays: */ - struct Port* ports; /** Port array of size num_ports */ -}; - - -void die(const char* msg); -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); - - -int -main(int argc, char** argv) -{ - struct JackHost host; - host.jack_client = NULL; - host.num_ports = 0; - host.ports = NULL; - - /* Find all installed plugins */ - SLV2List plugins = slv2_list_new(); - slv2_list_load_all(plugins); - //slv2_list_load_bundle(plugins, "http://www.scs.carleton.ca/~drobilla/files/Amp-swh.lv2"); - - /* Find the plugin to run */ - const char* plugin_uri = (argc == 2) ? argv[1] : NULL; - - if (!plugin_uri) { - fprintf(stderr, "\nYou must specify a plugin URI to load.\n"); - fprintf(stderr, "\nKnown plugins:\n\n"); - list_plugins(plugins); - return EXIT_FAILURE; - } - - printf("URI:\t%s\n", plugin_uri); - host.plugin = slv2_list_get_plugin_by_uri(plugins, plugin_uri); - - if (!host.plugin) { - fprintf(stderr, "Failed to find plugin %s.\n", plugin_uri); - slv2_list_free(plugins); - return EXIT_FAILURE; - } - - /* Get the plugin's name */ - char* name = slv2_plugin_get_name(host.plugin); - printf("Name:\t%s\n", name); - - /* Connect to JACK (with plugin name as client name) */ - host.jack_client = jack_client_open(name, JackNullOption, NULL); - free(name); - if (!host.jack_client) - die("Failed to connect to JACK."); - else - printf("Connected to JACK.\n"); - - /* Instantiate the plugin */ - host.instance = slv2_plugin_instantiate( - host.plugin, jack_get_sample_rate(host.jack_client), NULL); - if (!host.instance) - die("Failed to instantiate plugin.\n"); - else - printf("Succesfully instantiated plugin.\n"); - - jack_set_process_callback(host.jack_client, &jack_process_cb, (void*)(&host)); - - /* Create ports */ - host.num_ports = slv2_plugin_get_num_ports(host.plugin); - host.ports = calloc((size_t)host.num_ports, sizeof(struct Port)); - - for (uint32_t i=0; i < host.num_ports; ++i) - create_port(&host, i); - - /* Activate plugin and JACK */ - slv2_instance_activate(host.instance); - jack_activate(host.jack_client); - - /* Run */ - printf("Press enter to quit: "); - getc(stdin); - printf("\n"); - - /* Deactivate plugin and JACK */ - slv2_instance_free(host.instance); - slv2_list_free(plugins); - - printf("Shutting down JACK.\n"); - for (unsigned long i=0; i < host.num_ports; ++i) { - if (host.ports[i].jack_port != NULL) { - jack_port_unregister(host.jack_client, host.ports[i].jack_port); - host.ports[i].jack_port = NULL; - } - if (host.ports[i].midi_buffer != NULL) { - lv2midi_free(host.ports[i].midi_buffer); - } - } - jack_client_close(host.jack_client); - - return 0; -} - - -/** Abort and exit on error */ -void -die(const char* msg) -{ - fprintf(stderr, "%s\n", msg); - exit(EXIT_FAILURE); -} - - -/** Creates a port and connects the plugin instance to it's data location. - * - * For audio ports, creates a jack port and connects plugin port to buffer. - * - * For control ports, sets controls array to default value and connects plugin - * port to that element. - */ -void -create_port(struct JackHost* host, - uint32_t port_index) -{ - //struct Port* port = (Port*)malloc(sizeof(Port)); - struct Port* const port = &host->ports[port_index]; - - port->type = UNKNOWN; - port->jack_port = NULL; - port->control = 0.0f; - port->midi_buffer = NULL; - - slv2_instance_connect_port(host->instance, port_index, NULL); - - char* type_str = slv2_port_get_data_type(host->plugin, port_index); - if (!strcmp(type_str, SLV2_DATA_TYPE_FLOAT)) - port->type = FLOAT; - else if (!strcmp(type_str, SLV2_DATA_TYPE_MIDI)) - port->type = MIDI; - - /* Get the port symbol (label) for console printing */ - char* symbol = slv2_port_get_symbol(host->plugin, port_index); - - /* Get the 'class' (not data type) of the port (control input, audio output, etc) */ - enum SLV2PortClass class = slv2_port_get_class(host->plugin, port_index); - - if (port->type == FLOAT) { - - /* Connect the port based on it's 'class' */ - switch (class) { - case SLV2_CONTROL_RATE_INPUT: - port->direction = INPUT; - port->control = slv2_port_get_default_value(host->plugin, port_index); - slv2_instance_connect_port(host->instance, port_index, &port->control); - printf("Set %s to %f\n", symbol, host->ports[port_index].control); - break; - case SLV2_CONTROL_RATE_OUTPUT: - port->direction = OUTPUT; - slv2_instance_connect_port(host->instance, port_index, &port->control); - break; - case SLV2_AUDIO_RATE_INPUT: - printf("AI!\n"); - port->direction = INPUT; - port->jack_port = jack_port_register(host->jack_client, - symbol, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - break; - case SLV2_AUDIO_RATE_OUTPUT: - printf("AO!\n"); - port->direction = OUTPUT; - port->jack_port = jack_port_register(host->jack_client, - symbol, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - break; - default: - fprintf(stderr, "ERROR: Unknown port class\n"); - } - - } else if (port->type == MIDI) { - - printf("MIDI! %s\n", symbol); - if (class == SLV2_CONTROL_RATE_INPUT) { - port->direction = INPUT; - port->jack_port = jack_port_register(host->jack_client, - symbol, JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); - port->midi_buffer = lv2midi_new(MIDI_BUFFER_SIZE); - slv2_instance_connect_port(host->instance, port_index, port->midi_buffer); - } else if (class == SLV2_CONTROL_RATE_OUTPUT) { - port->direction = OUTPUT; - port->jack_port = jack_port_register(host->jack_client, - symbol, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); - port->midi_buffer = lv2midi_new(MIDI_BUFFER_SIZE); - slv2_instance_connect_port(host->instance, port_index, port->midi_buffer); - } else { - fprintf(stderr, "ERROR: Audio rate MIDI port?? Ignoring.\n"); - } - - } else { - - fprintf(stderr, "Unrecognized data type %s for port %s, ignored.\n", - type_str, symbol); - fprintf(stderr, " %s\n", - SLV2_DATA_TYPE_MIDI); - - } - - free(symbol); - free(type_str); -} - - -/** Jack process callback. */ -int -jack_process_cb(jack_nframes_t nframes, void* data) -{ - struct JackHost* const host = (struct JackHost*)data; - - /* Connect inputs */ - for (uint32_t p=0; p < host->num_ports; ++p) { - if (!host->ports[p].jack_port) - continue; - - if (host->ports[p].type == FLOAT) { - slv2_instance_connect_port(host->instance, p, - jack_port_get_buffer(host->ports[p].jack_port, nframes)); - } else if (host->ports[p].type == MIDI) { - - void* jack_buffer = jack_port_get_buffer(host->ports[p].jack_port, nframes); - - LV2_MIDIState state; - lv2midi_reset_state(&state, host->ports[p].midi_buffer, nframes); - lv2midi_reset_buffer(state.midi); - - if (host->ports[p].direction == INPUT) { - jack_midi_event_t ev; - - const jack_nframes_t event_count - = jack_midi_get_event_count(jack_buffer, nframes); - - for (jack_nframes_t e=0; e < event_count; ++e) { - - jack_midi_event_get(&ev, jack_buffer, e, nframes); - - state.midi = host->ports[p].midi_buffer; - lv2midi_put_event(&state, (double)ev.time, ev.size, ev.buffer); - } - } - } - } - - - /* Run plugin for this cycle */ - slv2_instance_run(host->instance, nframes); - - - /* Deliver output */ - for (uint32_t p=0; p < host->num_ports; ++p) { - if (host->ports[p].jack_port - && host->ports[p].type == MIDI - && host->ports[p].direction == OUTPUT) { - - void* jack_buffer = jack_port_get_buffer(host->ports[p].jack_port, nframes); - - jack_midi_clear_buffer(jack_buffer, nframes); - - LV2_MIDIState state; - lv2midi_reset_state(&state, host->ports[p].midi_buffer, nframes); - - double timestamp = 0.0f; - uint32_t size = 0; - unsigned char* data = NULL; - - const uint32_t event_count = state.midi->event_count; - - for (uint32_t i=0; i < event_count; ++i) { - lv2midi_get_event(&state, ×tamp, &size, &data); - - jack_midi_event_write(jack_buffer, - (jack_nframes_t)timestamp, data, size, nframes); - - lv2midi_increment(&state); - } - - } - } - - return 0; -} - - -void -list_plugins(SLV2List list) -{ - 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/lv2-midifunctions.h b/examples/hosts/lv2-midifunctions.h deleted file mode 100644 index 68691f3..0000000 --- a/examples/hosts/lv2-midifunctions.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** - - lv2-midifunctions.h - support file for using MIDI in LV2 plugins - - Copyright (C) 2006 Lars Luthman - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA - -****************************************************************************/ - -#ifndef LV2_MIDIFUNCTIONS -#define LV2_MIDIFUNCTIONS - -#include - -#include "lv2-miditype.h" - - -/** This structure contains information about a MIDI port buffer, the - current period size, and the position in the MIDI data buffer that - we are currently reading from or writing to. It needs to be recreated - or at least reinitialised every process() call. */ -typedef struct { - - /** The MIDI port structure that we want to read or write. */ - LV2_MIDI* midi; - - /** The number of frames in this process cycle. */ - uint32_t frame_count; - - /** The current position in the data buffer. Should be initialised to 0. */ - uint32_t position; - -} LV2_MIDIState; - - -static LV2_MIDI* lv2midi_new(uint32_t capacity) -{ - LV2_MIDI* midi = malloc(sizeof(LV2_MIDI)); - - midi->event_count = 0; - midi->capacity = capacity; - midi->size = 0; - midi->data = malloc(sizeof(char) * capacity); - - return midi; -} - - -static void lv2midi_free(LV2_MIDI* midi) -{ - free(midi->data); - free(midi); -} - - -static void lv2midi_reset_buffer(LV2_MIDI* midi) -{ - midi->event_count = 0; - midi->size = 0; -} - -static void lv2midi_reset_state(LV2_MIDIState* state, LV2_MIDI* midi, uint32_t frame_count) -{ - state->midi = midi; - state->frame_count = frame_count; - state->position = 0; -} - - -/** This function advances the read/write position in @c state to the next - event and returns its timestamp, or the @c frame_count member of @c state - is there are no more events. */ -static double lv2midi_increment(LV2_MIDIState* state) { - - if (state->position + sizeof(double) + sizeof(size_t) >= state->midi->size) { - state->position = state->midi->size; - return state->frame_count; - } - - state->position += sizeof(double); - size_t size = *(size_t*)(state->midi->data + state->position); - state->position += sizeof(size_t); - state->position += size; - - if (state->position >= state->midi->size) - return state->frame_count; - - return *(double*)(state->midi->data + state->position); -} - - -/** This function reads one event from the port associated with the @c state - parameter and writes its timestamp, size and a pointer to its data bytes - into the parameters @c timestamp, @c size and @c data, respectively. - It does not advance the read position in the MIDI data buffer, two - subsequent calls to lv2midi_get_event() will read the same event. - - The function returns the timestamp for the read event, or the @c frame_count - member of @c state if there are no more events in the buffer. */ -static double lv2midi_get_event(LV2_MIDIState* state, - double* timestamp, - uint32_t* size, - unsigned char** data) { - - if (state->position >= state->midi->size) { - state->position = state->midi->size; - *timestamp = state->frame_count; - *size = 0; - *data = NULL; - return *timestamp; - } - - *timestamp = *(double*)(state->midi->data + state->position); - *size = *(size_t*)(state->midi->data + state->position + sizeof(double)); - *data = state->midi->data + state->position + - sizeof(double) + sizeof(size_t); - return *timestamp; -} - - -/** This function writes one MIDI event to the port buffer associated with - @c state. It returns 0 when the event was written successfully to the - buffer, and -1 when there was not enough room. The read/write position - is advanced automatically. */ -static int lv2midi_put_event(LV2_MIDIState* state, - double timestamp, - uint32_t size, - const unsigned char* data) { - - if (state->midi->capacity - state->midi->size < - sizeof(double) + sizeof(size_t) + size) - return -1; - - *(double*)(state->midi->data + state->midi->size) = timestamp; - state->midi->size += sizeof(double); - *(size_t*)(state->midi->data + state->midi->size) = size; - state->midi->size += sizeof(size_t); - memcpy(state->midi->data + state->midi->size, data, size); - state->midi->size += size; - - ++state->midi->event_count; - - return 0; -} - - -#endif - diff --git a/examples/hosts/lv2-miditype.h b/examples/hosts/lv2-miditype.h deleted file mode 100644 index 465d5d5..0000000 --- a/examples/hosts/lv2-miditype.h +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** - - lv2-miditype.h - header file for using MIDI in LV2 plugins - - Copyright (C) 2006 Lars Luthman - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA - -****************************************************************************/ - -#ifndef LV2_MIDITYPE_H -#define LV2_MIDITYPE_H - - -/** This data structure is used to contain the MIDI events for one run() - cycle. The port buffer for a LV2 port that has the datatype - should be a pointer - to an instance of this struct. - - To store two Note On events on MIDI channel 0 in a buffer, with timestamps - 12 and 35.5, you could use something like this code (assuming that - midi_data is a variable of type LV2_MIDI): - @code - - size_t buffer_offset = 0; - *(double*)(midi_data->data + buffer_offset) = 12; - buffer_offset += sizeof(double); - *(size_t*)(midi_data->data + buffer_offset) = 3; - buffer_offset += sizeof(size_t); - midi_data->data[buffer_offset++] = 0x90; - midi_data->data[buffer_offset++] = 0x48; - midi_data->data[buffer_offset++] = 0x64; - ++midi_data->event_count; - - *(double*)(midi_data->data + buffer_offset) = 35.5; - buffer_offset += sizeof(double); - *(size_t*)(midi_data->data + buffer_offset) = 3; - buffer_offset += sizeof(size_t); - midi_data->data[buffer_offset++] = 0x90; - midi_data->data[buffer_offset++] = 0x55; - midi_data->data[buffer_offset++] = 0x64; - ++midi_data->event_count; - - midi_data->size = buffer_offset; - - @endcode - - This would be done by the host in the case of an input port, and by the - plugin in the case of an output port. Whoever is writing events to the - buffer must also take care not to exceed the capacity of the data buffer. - - To read events from a buffer, you could do something like this: - @code - - size_t buffer_offset = 0; - uint32_t i; - for (i = 0; i < midi_data->event_count; ++i) { - double timestamp = *(double*)(midi_data->data + buffer_offset); - buffer_offset += sizeof(double); - size_t size = *(size_t*)(midi_data->data + buffer_offset); - buffer_offset += sizeof(size_t); - do_something_with_event(timestamp, size, - midi_data->data + buffer_offset); - buffer_offset += size; - } - - @endcode -*/ -typedef struct { - - /** The number of MIDI events in the data buffer. - INPUT PORTS: It's the host's responsibility to set this field to the - number of MIDI events contained in the data buffer before calling the - plugin's run() function. The plugin may not change this field. - OUTPUT PORTS: It's the plugin's responsibility to set this field to the - number of MIDI events it has stored in the data buffer before returning - from the run() function. Any initial value should be ignored by the - plugin. - */ - uint32_t event_count; - - /** The size of the data buffer in bytes. It is set by the host and may not - be changed by the plugin. The host is allowed to change this between - run() calls. - */ - uint32_t capacity; - - /** The size of the initial part of the data buffer that actually contains - data. - INPUT PORTS: It's the host's responsibility to set this field to the - number of bytes used by all MIDI events it has written to the buffer - (including timestamps and size fields) before calling the plugin's - run() function. The plugin may not change this field. - OUTPUT PORTS: It's the plugin's responsibility to set this field to - the number of bytes used by all MIDI events it has written to the - buffer (including timestamps and size fields) before returning from - the run() function. Any initial value should be ignored by the plugin. - */ - uint32_t size; - - /** The data buffer that is used to store MIDI events. The events are packed - after each other, and the format of each event is as follows: - - First there is a timestamp, which should have the type "double", - i.e. have the same bit size as a double and the same bit layout as a - double (whatever that is on the current platform). This timestamp gives - the offset from the beginning of the current cycle, in frames, that - the MIDI event occurs on. It must be strictly smaller than the 'nframes' - parameter to the current run() call. The MIDI events in the buffer must - be ordered by their timestamp, e.g. an event with a timestamp of 123.23 - must be stored after an event with a timestamp of 65.0. - - The second part of the event is a size field, which should have the type - "size_t" (as defined in the standard C header stddef.h). It should - contain the size of the MIDI data for this event, i.e. the number of - bytes used to store the actual MIDI event. The bytes used by the - timestamp and the size field should not be counted. - - The third part of the event is the actual MIDI data. There are some - requirements that must be followed: - - * Running status is not allowed. Every event must have its own status - byte. - * Note On events with velocity 0 are not allowed. These events are - equivalent to Note Off in standard MIDI streams, but in order to make - plugins and hosts easier to write, as well as more efficient, only - proper Note Off events are allowed as Note Off. - * "Realtime events" (status bytes 0xF8 to 0xFF) are allowed, but may not - occur inside other events like they are allowed to in hardware MIDI - streams. - * All events must be fully contained in a single data buffer, i.e. events - may not "wrap around" by storing the first few bytes in one buffer and - then wait for the next run() call to store the rest of the event. If - there isn't enough space in the current data buffer to store an event, - the event will either have to wait until next run() call, be ignored, - or compensated for in some more clever way. - * All events must be valid MIDI events. This means for example that - only the first byte in each event (the status byte) may have the eighth - bit set, that Note On and Note Off events are always 3 bytes long etc. - The MIDI writer (host or plugin) is responsible for writing valid MIDI - events to the buffer, and the MIDI reader (plugin or host) can assume - that all events are valid. - - On a platform where double is 8 bytes and size_t is 4 bytes, the data - buffer layout for a 3-byte event followed by a 4-byte event may look - something like this: - _______________________________________________________________ - | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... - |TIMESTAMP 1 |SIZE 1 |DATA |TIMESTAMP 2 |SIZE 2 |DATA | ... - - */ - unsigned char* data; - -} LV2_MIDI; - - - -#endif diff --git a/examples/hosts/simple_jack_host.c b/examples/hosts/simple_jack_host.c deleted file mode 100644 index 655c939..0000000 --- a/examples/hosts/simple_jack_host.c +++ /dev/null @@ -1,220 +0,0 @@ -/* LibSLV2 Jack Example Host - * Copyright (C) 2006 Dave Robillard - * - * This program 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 program 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 -#include -#include -#include -#include - - -/** This program's data */ -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) */ - uint32_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, uint32_t port_index); -int jack_process_cb(jack_nframes_t nframes, void* data); -void list_plugins(SLV2List list); - - -int -main(int argc, char** argv) -{ - struct JackHost host; - host.jack_client = NULL; - host.num_ports = 0; - host.jack_ports = NULL; - host.controls = NULL; - - /* Find all installed plugins */ - SLV2List plugins = slv2_list_new(); - slv2_list_load_all(plugins); - //slv2_list_load_bundle(plugins, "http://www.scs.carleton.ca/~drobilla/files/Amp-swh.lv2"); - - /* Find the plugin to run */ - const char* plugin_uri = (argc == 2) ? argv[1] : NULL; - - if (!plugin_uri) { - fprintf(stderr, "\nYou must specify a plugin URI to load.\n"); - fprintf(stderr, "\nKnown plugins:\n\n"); - list_plugins(plugins); - return EXIT_FAILURE; - } - - printf("URI:\t%s\n", plugin_uri); - host.plugin = slv2_list_get_plugin_by_uri(plugins, plugin_uri); - - if (!host.plugin) { - fprintf(stderr, "Failed to find plugin %s.\n", plugin_uri); - slv2_list_free(plugins); - return EXIT_FAILURE; - } - - /* Get the plugin's name */ - char* name = slv2_plugin_get_name(host.plugin); - printf("Name:\t%s\n", name); - - /* Connect to JACK (with plugin name as client name) */ - host.jack_client = jack_client_open(name, JackNullOption, NULL); - free(name); - if (!host.jack_client) - die("Failed to connect to JACK."); - else - printf("Connected to JACK.\n"); - - /* Instantiate the plugin */ - host.instance = slv2_plugin_instantiate( - host.plugin, jack_get_sample_rate(host.jack_client), NULL); - if (!host.instance) - die("Failed to instantiate plugin.\n"); - else - printf("Succesfully instantiated plugin.\n"); - - jack_set_process_callback(host.jack_client, &jack_process_cb, (void*)(&host)); - - /* Create ports */ - host.num_ports = slv2_plugin_get_num_ports(host.plugin); - host.jack_ports = calloc((size_t)host.num_ports, sizeof(jack_port_t*)); - host.controls = calloc((size_t)host.num_ports, sizeof(float*)); - - for (uint32_t i=0; i < host.num_ports; ++i) - create_port(&host, i); - - /* Activate plugin and JACK */ - slv2_instance_activate(host.instance); - jack_activate(host.jack_client); - - /* Run */ - printf("Press enter to quit: "); - getc(stdin); - printf("\n"); - - /* Deactivate plugin and JACK */ - slv2_instance_free(host.instance); - slv2_list_free(plugins); - - printf("Shutting down JACK.\n"); - for (unsigned long i=0; i < host.num_ports; ++i) { - if (host.jack_ports[i] != NULL) { - jack_port_unregister(host.jack_client, host.jack_ports[i]); - host.jack_ports[i] = NULL; - } - } - jack_client_close(host.jack_client); - - return 0; -} - - -/** Abort and exit on error */ -void -die(const char* msg) -{ - fprintf(stderr, "%s\n", msg); - exit(EXIT_FAILURE); -} - - -/** Creates a port and connects the plugin instance to it's data location. - * - * For audio ports, creates a jack port and connects plugin port to buffer. - * - * For control ports, sets controls array to default value and connects plugin - * port to that element. - */ -void -create_port(struct JackHost* host, - uint32_t port_index) -{ - /* Make sure this is a float port */ - 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); - - /* Get the port symbol (label) for console printing */ - char* symbol = slv2_port_get_symbol(host->plugin, port_index); - - /* Initialize the port array elements */ - host->jack_ports[port_index] = NULL; - host->controls[port_index] = 0.0f; - - /* Get the 'class' of the port (control input, audio output, etc) */ - enum SLV2PortClass class = slv2_port_get_class(host->plugin, port_index); - - /* Connect the port based on it's 'class' */ - switch (class) { - case SLV2_CONTROL_RATE_INPUT: - host->controls[port_index] = slv2_port_get_default_value(host->plugin, port_index); - slv2_instance_connect_port(host->instance, port_index, &host->controls[port_index]); - printf("Set %s to %f\n", symbol, host->controls[port_index]); - break; - case SLV2_CONTROL_RATE_OUTPUT: - slv2_instance_connect_port(host->instance, port_index, &host->controls[port_index]); - break; - case SLV2_AUDIO_RATE_INPUT: - host->jack_ports[port_index] = jack_port_register(host->jack_client, - symbol, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - break; - case SLV2_AUDIO_RATE_OUTPUT: - host->jack_ports[port_index] = jack_port_register(host->jack_client, - symbol, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - break; - default: - die("ERROR: Unknown port type, aborting messily!"); - } - - free(symbol); -} - - -/** Jack process callback. */ -int -jack_process_cb(jack_nframes_t nframes, void* data) -{ - struct JackHost* host = (struct JackHost*)data; - - /* Connect plugin ports directly to JACK buffers */ - for (uint32_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)); - - /* Run plugin for this cycle */ - slv2_instance_run(host->instance, nframes); - - return 0; -} - - -void -list_plugins(SLV2List list) -{ - 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 deleted file mode 100644 index 0eabee5..0000000 --- a/examples/hosts/test_host.c +++ /dev/null @@ -1,170 +0,0 @@ -/* LibSLV2 Test Host - * Copyright (C) 2006 Dave Robillard - * - * This program 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 program 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 -#include -#include -#include - -#include -#include -#include -#include -#include - - -void -create_control_input() -{ - printf("Control Input\n"); -} - - -void -create_control_output() -{ - printf("Control Output\n"); -} - - -void -create_audio_input() -{ - printf("Audio Input\n"); -} - - -void -create_audio_output() -{ - printf("Audio Output\n"); -} - - -void -create_port(SLV2Plugin* plugin, - uint32_t port_index) -{ - enum SLV2PortClass class = slv2_port_get_class(plugin, port_index); - - switch (class) { - case SLV2_CONTROL_RATE_INPUT: - create_control_input(port_index); - break; - case SLV2_CONTROL_RATE_OUTPUT: - create_control_output(port_index); - break; - case SLV2_AUDIO_RATE_INPUT: - create_audio_input(port_index); - break; - case SLV2_AUDIO_RATE_OUTPUT: - create_audio_output(port_index); - break; - default: - printf("Unknown port type, ignored.\n"); - } - //printf("Port %ld class: %d\n", i, slv2_port_get_class(p, i)); -} - - -int -main() -{ - //const char* path = "foo"; - - const char* path = "/home/dave/code/libslv2/examples/plugins"; - - SLV2List plugins = slv2_list_new(); - slv2_list_load_path(plugins, path); - - const char* plugin_uri = "http://plugin.org.uk/swh-plugins/amp"; - printf("URI:\t%s\n", plugin_uri); - - const SLV2Plugin* p = slv2_list_get_plugin_by_uri(plugins, plugin_uri); - if (p) { - /* Get the plugin's name */ - char* name = slv2_plugin_get_name(p); - printf("Name:\t%s\n", name); - free(name); - - uint32_t num_ports = slv2_plugin_get_num_ports(p); - //printf("Number of ports: %ld\n", num_ports); - - for (uint32_t i=0; i < num_ports; ++i) { - enum SLV2PortClass class = slv2_port_get_class(p, i); - - switch (class) { - case SLV2_CONTROL_RATE_INPUT: - create_control_input(i); - break; - case SLV2_CONTROL_RATE_OUTPUT: - create_control_output(i); - break; - case SLV2_AUDIO_RATE_INPUT: - create_audio_input(i); - break; - case SLV2_AUDIO_RATE_OUTPUT: - create_audio_output(i); - break; - default: - printf("Unknown port type, ignored.\n"); - } - //printf("Port %ld class: %d\n", i, slv2_port_get_class(p, i)); - - - } - - SLV2Property prop; - for (uint32_t i=0; i < num_ports; ++i) { - const char* property = "a"; - prop = slv2_port_get_property(p, i, property); - if (prop) - printf("Port %u %s = %s\n", i, property, prop->values[0]); - else - printf("No port %u %s.\n", i, property); - free(prop); - } - printf("\n"); - - SLV2Instance* i = slv2_plugin_instantiate(p, 48000, NULL); - if (i) { - printf("Succesfully instantiated plugin.\n"); - - float gain = 2.0f; - float input = 0.25f; - float output = 0.0f; - slv2_instance_connect_port(i, 0, &gain); - slv2_instance_connect_port(i, 1, &input); - slv2_instance_connect_port(i, 2, &output); - - slv2_instance_activate(i); - slv2_instance_run(i, 1); - slv2_instance_deactivate(i); - - printf("Gain: %f, Input: %f => Output: %f\n", gain, input, output); - slv2_instance_free(i); - } - } - - slv2_list_free(plugins); - - return 0; -} - diff --git a/examples/plugins/Amp-onefile-slv2.lv2/Makefile b/examples/plugins/Amp-onefile-slv2.lv2/Makefile deleted file mode 100644 index eb7dfe1..0000000 --- a/examples/plugins/Amp-onefile-slv2.lv2/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -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 diff --git a/examples/plugins/Amp-onefile-slv2.lv2/amp.c b/examples/plugins/Amp-onefile-slv2.lv2/amp.c deleted file mode 100644 index d52e8f4..0000000 --- a/examples/plugins/Amp-onefile-slv2.lv2/amp.c +++ /dev/null @@ -1,108 +0,0 @@ -#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/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; - } -} - diff --git a/examples/plugins/Amp-onefile-slv2.lv2/manifest.ttl b/examples/plugins/Amp-onefile-slv2.lv2/manifest.ttl deleted file mode 100644 index 8113dec..0000000 --- a/examples/plugins/Amp-onefile-slv2.lv2/manifest.ttl +++ /dev/null @@ -1,58 +0,0 @@ -@prefix rdf: . -@prefix rdfs: . -@prefix lv2: . -@prefix foaf: . -@prefix doap: . - - a lv2:Plugin ; - lv2:binary ; - a lv2:AmplifierPlugin ; - doap:maintainer [ - foaf:name "Dave Robillard"; - foaf:homepage ; - foaf:mbox - ] ; - doap:name "Simple Amplifier" ; - doap:name "Einfacher Verst¿¿rker"@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/Makefile b/examples/plugins/Amp-slv2.lv2/Makefile deleted file mode 100644 index eb7dfe1..0000000 --- a/examples/plugins/Amp-slv2.lv2/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -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 diff --git a/examples/plugins/Amp-slv2.lv2/amp.c b/examples/plugins/Amp-slv2.lv2/amp.c deleted file mode 100644 index c9d6b73..0000000 --- a/examples/plugins/Amp-slv2.lv2/amp.c +++ /dev/null @@ -1,108 +0,0 @@ -#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, 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; - } -} - diff --git a/examples/plugins/Amp-slv2.lv2/amp.ttl b/examples/plugins/Amp-slv2.lv2/amp.ttl deleted file mode 100644 index abc5b33..0000000 --- a/examples/plugins/Amp-slv2.lv2/amp.ttl +++ /dev/null @@ -1,57 +0,0 @@ -@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 Verst¿¿rker"@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 deleted file mode 100644 index 94456e6..0000000 --- a/examples/plugins/Amp-slv2.lv2/manifest.ttl +++ /dev/null @@ -1,11 +0,0 @@ -# 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/Makefile.am b/examples/plugins/Makefile.am deleted file mode 100644 index 8044bc9..0000000 --- a/examples/plugins/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -#AM_CFLAGS = -I$(top_srcdir)/include -#AM_LDFLAGS = -module -avoidversion -Wc,-nostartfiles -# -#plugindir = @umpdir@ -# -#plugin_LTLIBRARIES = \ -# test_plugin.la -# -## Stolen from swh-plugins, makes stupid libtool versions go away -#install-pluginLTLIBRARIES: $(plugin_LTLIBRARIES) -# mkdir -p @umpdir@ -# list='$(plugin_LTLIBRARIES)'; \ -# for file in $$list; do \ -# sofile=`basename $$file .la`.so; \ -# $(INSTALL_PROGRAM) .libs/$$sofile @umpdir@; \ -# done -# -#uninstall-pluginLTLIBRARIES: $(plugin_LTLIBRARIES) -# list='$(plugin_LTLIBRARIES)'; \ -# for file in $$list; do \ -# sofile=`basename $$file .la`.so; \ -# rm -f @umpdir@/$$sofile; \ -# done -# diff --git a/hosts/Makefile.am b/hosts/Makefile.am new file mode 100644 index 0000000..aa794c5 --- /dev/null +++ b/hosts/Makefile.am @@ -0,0 +1,18 @@ +AM_CFLAGS = -std=c99 -I$(top_srcdir) @RASQAL_CFLAGS@ + +if WITH_JACK + +bin_PROGRAMS = lv2_jack_host lv2_simple_jack_host + +lv2_jack_host_CFLAGS = @JACK_CFLAGS@ $(AM_CFLAGS) + +lv2_jack_host_DEPENDENCIES = ../src/libslv2.la +lv2_jack_host_LDADD = ../src/libslv2.la @JACK_LIBS@ @RASQAL_LIBS@ + +lv2_simple_jack_host_LDADD = ../src/libslv2.la @JACK_LIBS@ @RASQAL_LIBS@ + +lv2_jack_host_SOURCES = \ + lv2_jack_host.c + +endif + diff --git a/hosts/lv2-midifunctions.h b/hosts/lv2-midifunctions.h new file mode 100644 index 0000000..3a17395 --- /dev/null +++ b/hosts/lv2-midifunctions.h @@ -0,0 +1,161 @@ +/**************************************************************************** + + lv2-midifunctions.h - support file for using MIDI in LV2 plugins + + Copyright (C) 2006 Lars Luthman + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA + +****************************************************************************/ + +#ifndef LV2_MIDIFUNCTIONS +#define LV2_MIDIFUNCTIONS + +#include + +#include "lv2-miditype.h" + + +/** This structure contains information about a MIDI port buffer, the + current period size, and the position in the MIDI data buffer that + we are currently reading from or writing to. It needs to be recreated + or at least reinitialised every process() call. */ +typedef struct { + + /** The MIDI port structure that we want to read or write. */ + LV2_MIDI* midi; + + /** The number of frames in this process cycle. */ + uint32_t frame_count; + + /** The current position in the data buffer. Should be initialised to 0. */ + uint32_t position; + +} LV2_MIDIState; + + +static LV2_MIDI* lv2midi_new(uint32_t capacity) +{ + LV2_MIDI* midi = malloc(sizeof(LV2_MIDI)); + + midi->event_count = 0; + midi->capacity = capacity; + midi->size = 0; + midi->data = malloc(sizeof(char) * capacity); + + return midi; +} + + +static void lv2midi_free(LV2_MIDI* midi) +{ + free(midi->data); + free(midi); +} + + +static void lv2midi_reset_buffer(LV2_MIDI* midi) +{ + midi->event_count = 0; + midi->size = 0; +} + +static void lv2midi_reset_state(LV2_MIDIState* state, LV2_MIDI* midi, uint32_t frame_count) +{ + state->midi = midi; + state->frame_count = frame_count; + state->position = 0; +} + + +/** This function advances the read/write position in @c state to the next + event and returns its timestamp, or the @c frame_count member of @c state + is there are no more events. */ +static double lv2midi_increment(LV2_MIDIState* state) { + + if (state->position + sizeof(double) + sizeof(size_t) >= state->midi->size) { + state->position = state->midi->size; + return state->frame_count; + } + + state->position += sizeof(double); + size_t size = *(size_t*)(state->midi->data + state->position); + state->position += sizeof(size_t); + state->position += size; + + if (state->position >= state->midi->size) + return state->frame_count; + + return *(double*)(state->midi->data + state->position); +} + + +/** This function reads one event from the port associated with the @c state + parameter and writes its timestamp, size and a pointer to its data bytes + into the parameters @c timestamp, @c size and @c data, respectively. + It does not advance the read position in the MIDI data buffer, two + subsequent calls to lv2midi_get_event() will read the same event. + + The function returns the timestamp for the read event, or the @c frame_count + member of @c state if there are no more events in the buffer. */ +static double lv2midi_get_event(LV2_MIDIState* state, + double* timestamp, + uint32_t* size, + unsigned char** data) { + + if (state->position >= state->midi->size) { + state->position = state->midi->size; + *timestamp = state->frame_count; + *size = 0; + *data = NULL; + return *timestamp; + } + + *timestamp = *(double*)(state->midi->data + state->position); + *size = *(size_t*)(state->midi->data + state->position + sizeof(double)); + *data = state->midi->data + state->position + + sizeof(double) + sizeof(size_t); + return *timestamp; +} + + +/** This function writes one MIDI event to the port buffer associated with + @c state. It returns 0 when the event was written successfully to the + buffer, and -1 when there was not enough room. The read/write position + is advanced automatically. */ +static int lv2midi_put_event(LV2_MIDIState* state, + double timestamp, + uint32_t size, + const unsigned char* data) { + + if (state->midi->capacity - state->midi->size < + sizeof(double) + sizeof(size_t) + size) + return -1; + + *(double*)(state->midi->data + state->midi->size) = timestamp; + state->midi->size += sizeof(double); + *(size_t*)(state->midi->data + state->midi->size) = size; + state->midi->size += sizeof(size_t); + memcpy(state->midi->data + state->midi->size, data, (size_t)size); + state->midi->size += size; + + ++state->midi->event_count; + + return 0; +} + + +#endif + diff --git a/hosts/lv2-miditype.h b/hosts/lv2-miditype.h new file mode 100644 index 0000000..465d5d5 --- /dev/null +++ b/hosts/lv2-miditype.h @@ -0,0 +1,170 @@ +/**************************************************************************** + + lv2-miditype.h - header file for using MIDI in LV2 plugins + + Copyright (C) 2006 Lars Luthman + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA + +****************************************************************************/ + +#ifndef LV2_MIDITYPE_H +#define LV2_MIDITYPE_H + + +/** This data structure is used to contain the MIDI events for one run() + cycle. The port buffer for a LV2 port that has the datatype + should be a pointer + to an instance of this struct. + + To store two Note On events on MIDI channel 0 in a buffer, with timestamps + 12 and 35.5, you could use something like this code (assuming that + midi_data is a variable of type LV2_MIDI): + @code + + size_t buffer_offset = 0; + *(double*)(midi_data->data + buffer_offset) = 12; + buffer_offset += sizeof(double); + *(size_t*)(midi_data->data + buffer_offset) = 3; + buffer_offset += sizeof(size_t); + midi_data->data[buffer_offset++] = 0x90; + midi_data->data[buffer_offset++] = 0x48; + midi_data->data[buffer_offset++] = 0x64; + ++midi_data->event_count; + + *(double*)(midi_data->data + buffer_offset) = 35.5; + buffer_offset += sizeof(double); + *(size_t*)(midi_data->data + buffer_offset) = 3; + buffer_offset += sizeof(size_t); + midi_data->data[buffer_offset++] = 0x90; + midi_data->data[buffer_offset++] = 0x55; + midi_data->data[buffer_offset++] = 0x64; + ++midi_data->event_count; + + midi_data->size = buffer_offset; + + @endcode + + This would be done by the host in the case of an input port, and by the + plugin in the case of an output port. Whoever is writing events to the + buffer must also take care not to exceed the capacity of the data buffer. + + To read events from a buffer, you could do something like this: + @code + + size_t buffer_offset = 0; + uint32_t i; + for (i = 0; i < midi_data->event_count; ++i) { + double timestamp = *(double*)(midi_data->data + buffer_offset); + buffer_offset += sizeof(double); + size_t size = *(size_t*)(midi_data->data + buffer_offset); + buffer_offset += sizeof(size_t); + do_something_with_event(timestamp, size, + midi_data->data + buffer_offset); + buffer_offset += size; + } + + @endcode +*/ +typedef struct { + + /** The number of MIDI events in the data buffer. + INPUT PORTS: It's the host's responsibility to set this field to the + number of MIDI events contained in the data buffer before calling the + plugin's run() function. The plugin may not change this field. + OUTPUT PORTS: It's the plugin's responsibility to set this field to the + number of MIDI events it has stored in the data buffer before returning + from the run() function. Any initial value should be ignored by the + plugin. + */ + uint32_t event_count; + + /** The size of the data buffer in bytes. It is set by the host and may not + be changed by the plugin. The host is allowed to change this between + run() calls. + */ + uint32_t capacity; + + /** The size of the initial part of the data buffer that actually contains + data. + INPUT PORTS: It's the host's responsibility to set this field to the + number of bytes used by all MIDI events it has written to the buffer + (including timestamps and size fields) before calling the plugin's + run() function. The plugin may not change this field. + OUTPUT PORTS: It's the plugin's responsibility to set this field to + the number of bytes used by all MIDI events it has written to the + buffer (including timestamps and size fields) before returning from + the run() function. Any initial value should be ignored by the plugin. + */ + uint32_t size; + + /** The data buffer that is used to store MIDI events. The events are packed + after each other, and the format of each event is as follows: + + First there is a timestamp, which should have the type "double", + i.e. have the same bit size as a double and the same bit layout as a + double (whatever that is on the current platform). This timestamp gives + the offset from the beginning of the current cycle, in frames, that + the MIDI event occurs on. It must be strictly smaller than the 'nframes' + parameter to the current run() call. The MIDI events in the buffer must + be ordered by their timestamp, e.g. an event with a timestamp of 123.23 + must be stored after an event with a timestamp of 65.0. + + The second part of the event is a size field, which should have the type + "size_t" (as defined in the standard C header stddef.h). It should + contain the size of the MIDI data for this event, i.e. the number of + bytes used to store the actual MIDI event. The bytes used by the + timestamp and the size field should not be counted. + + The third part of the event is the actual MIDI data. There are some + requirements that must be followed: + + * Running status is not allowed. Every event must have its own status + byte. + * Note On events with velocity 0 are not allowed. These events are + equivalent to Note Off in standard MIDI streams, but in order to make + plugins and hosts easier to write, as well as more efficient, only + proper Note Off events are allowed as Note Off. + * "Realtime events" (status bytes 0xF8 to 0xFF) are allowed, but may not + occur inside other events like they are allowed to in hardware MIDI + streams. + * All events must be fully contained in a single data buffer, i.e. events + may not "wrap around" by storing the first few bytes in one buffer and + then wait for the next run() call to store the rest of the event. If + there isn't enough space in the current data buffer to store an event, + the event will either have to wait until next run() call, be ignored, + or compensated for in some more clever way. + * All events must be valid MIDI events. This means for example that + only the first byte in each event (the status byte) may have the eighth + bit set, that Note On and Note Off events are always 3 bytes long etc. + The MIDI writer (host or plugin) is responsible for writing valid MIDI + events to the buffer, and the MIDI reader (plugin or host) can assume + that all events are valid. + + On a platform where double is 8 bytes and size_t is 4 bytes, the data + buffer layout for a 3-byte event followed by a 4-byte event may look + something like this: + _______________________________________________________________ + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... + |TIMESTAMP 1 |SIZE 1 |DATA |TIMESTAMP 2 |SIZE 2 |DATA | ... + + */ + unsigned char* data; + +} LV2_MIDI; + + + +#endif diff --git a/hosts/lv2_jack_host.c b/hosts/lv2_jack_host.c new file mode 100644 index 0000000..e5e51a3 --- /dev/null +++ b/hosts/lv2_jack_host.c @@ -0,0 +1,338 @@ +/* jack_host - SLV2 Jack Host + * Copyright (C) 2007 Dave Robillard + * + * This program 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 program 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 +#include +#include +#include +#include + +#define WITH_MIDI 1 +#define MIDI_BUFFER_SIZE 1024 + +#ifdef WITH_MIDI +#include +#include "lv2-miditype.h" +#include "lv2-midifunctions.h" +#endif // WITH_MIDI + +struct Port { + enum Direction { INPUT, OUTPUT} direction; + enum Type { UNKNOWN, FLOAT, MIDI } type; + + jack_port_t* jack_port; /**< For audio and MIDI ports, otherwise NULL */ + float control; /**< For control ports, otherwise 0.0f */ + LV2_MIDI* midi_buffer; /**< For midi ports, otherwise NULL */ +}; + + +/** This program's data */ +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) */ + uint32_t num_ports; /**< Size of the two following arrays: */ + struct Port* ports; /** Port array of size num_ports */ +}; + + +void die(const char* msg); +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); + + +int +main(int argc, char** argv) +{ + struct JackHost host; + host.jack_client = NULL; + host.num_ports = 0; + host.ports = NULL; + + /* Find all installed plugins */ + SLV2List plugins = slv2_list_new(); + slv2_list_load_all(plugins); + //slv2_list_load_bundle(plugins, "http://www.scs.carleton.ca/~drobilla/files/Amp-swh.lv2"); + + /* Find the plugin to run */ + const char* plugin_uri = (argc == 2) ? argv[1] : NULL; + + if (!plugin_uri) { + fprintf(stderr, "\nYou must specify a plugin URI to load.\n"); + fprintf(stderr, "\nKnown plugins:\n\n"); + list_plugins(plugins); + return EXIT_FAILURE; + } + + printf("URI:\t%s\n", plugin_uri); + host.plugin = slv2_list_get_plugin_by_uri(plugins, plugin_uri); + + if (!host.plugin) { + fprintf(stderr, "Failed to find plugin %s.\n", plugin_uri); + slv2_list_free(plugins); + return EXIT_FAILURE; + } + + /* Get the plugin's name */ + char* name = slv2_plugin_get_name(host.plugin); + printf("Name:\t%s\n", name); + + /* Connect to JACK (with plugin name as client name) */ + host.jack_client = jack_client_open(name, JackNullOption, NULL); + free(name); + if (!host.jack_client) + die("Failed to connect to JACK."); + else + printf("Connected to JACK.\n"); + + /* Instantiate the plugin */ + host.instance = slv2_plugin_instantiate( + host.plugin, jack_get_sample_rate(host.jack_client), NULL); + if (!host.instance) + die("Failed to instantiate plugin.\n"); + else + printf("Succesfully instantiated plugin.\n"); + + jack_set_process_callback(host.jack_client, &jack_process_cb, (void*)(&host)); + + /* Create ports */ + host.num_ports = slv2_plugin_get_num_ports(host.plugin); + host.ports = calloc((size_t)host.num_ports, sizeof(struct Port)); + + for (uint32_t i=0; i < host.num_ports; ++i) + create_port(&host, i); + + /* Activate plugin and JACK */ + slv2_instance_activate(host.instance); + jack_activate(host.jack_client); + + /* Run */ + printf("Press enter to quit: "); + getc(stdin); + printf("\n"); + + /* Deactivate plugin and JACK */ + slv2_instance_free(host.instance); + slv2_list_free(plugins); + + printf("Shutting down JACK.\n"); + for (unsigned long i=0; i < host.num_ports; ++i) { + if (host.ports[i].jack_port != NULL) { + jack_port_unregister(host.jack_client, host.ports[i].jack_port); + host.ports[i].jack_port = NULL; + } + if (host.ports[i].midi_buffer != NULL) { + lv2midi_free(host.ports[i].midi_buffer); + } + } + jack_client_close(host.jack_client); + + return 0; +} + + +/** Abort and exit on error */ +void +die(const char* msg) +{ + fprintf(stderr, "%s\n", msg); + exit(EXIT_FAILURE); +} + + +/** Creates a port and connects the plugin instance to it's data location. + * + * For audio ports, creates a jack port and connects plugin port to buffer. + * + * For control ports, sets controls array to default value and connects plugin + * port to that element. + */ +void +create_port(struct JackHost* host, + uint32_t port_index) +{ + //struct Port* port = (Port*)malloc(sizeof(Port)); + struct Port* const port = &host->ports[port_index]; + + port->type = UNKNOWN; + port->jack_port = NULL; + port->control = 0.0f; + port->midi_buffer = NULL; + + slv2_instance_connect_port(host->instance, port_index, NULL); + + char* type_str = slv2_port_get_data_type(host->plugin, port_index); + if (!strcmp(type_str, SLV2_DATA_TYPE_FLOAT)) + port->type = FLOAT; + else if (!strcmp(type_str, SLV2_DATA_TYPE_MIDI)) + port->type = MIDI; + + /* Get the port symbol (label) for console printing */ + char* symbol = slv2_port_get_symbol(host->plugin, port_index); + + /* Get the 'class' (not data type) of the port (control input, audio output, etc) */ + enum SLV2PortClass class = slv2_port_get_class(host->plugin, port_index); + + if (port->type == FLOAT) { + + /* Connect the port based on it's 'class' */ + switch (class) { + case SLV2_CONTROL_RATE_INPUT: + port->direction = INPUT; + port->control = slv2_port_get_default_value(host->plugin, port_index); + slv2_instance_connect_port(host->instance, port_index, &port->control); + printf("Set %s to %f\n", symbol, host->ports[port_index].control); + break; + case SLV2_CONTROL_RATE_OUTPUT: + port->direction = OUTPUT; + slv2_instance_connect_port(host->instance, port_index, &port->control); + break; + case SLV2_AUDIO_RATE_INPUT: + port->direction = INPUT; + port->jack_port = jack_port_register(host->jack_client, + symbol, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); + break; + case SLV2_AUDIO_RATE_OUTPUT: + port->direction = OUTPUT; + port->jack_port = jack_port_register(host->jack_client, + symbol, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + break; + default: + fprintf(stderr, "ERROR: Unknown port class\n"); + } + + } else if (port->type == MIDI) { + + if (class == SLV2_CONTROL_RATE_INPUT) { + port->direction = INPUT; + port->jack_port = jack_port_register(host->jack_client, + symbol, JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); + port->midi_buffer = lv2midi_new(MIDI_BUFFER_SIZE); + slv2_instance_connect_port(host->instance, port_index, port->midi_buffer); + } else if (class == SLV2_CONTROL_RATE_OUTPUT) { + port->direction = OUTPUT; + port->jack_port = jack_port_register(host->jack_client, + symbol, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); + port->midi_buffer = lv2midi_new(MIDI_BUFFER_SIZE); + slv2_instance_connect_port(host->instance, port_index, port->midi_buffer); + } else { + fprintf(stderr, "ERROR: Audio rate MIDI port?? Ignoring.\n"); + } + + } else { + + fprintf(stderr, "Unrecognized data type %s for port %s, ignored.\n", + type_str, symbol); + fprintf(stderr, " %s\n", + SLV2_DATA_TYPE_MIDI); + + } + + free(symbol); + free(type_str); +} + + +/** Jack process callback. */ +int +jack_process_cb(jack_nframes_t nframes, void* data) +{ + struct JackHost* const host = (struct JackHost*)data; + + /* Connect inputs */ + for (uint32_t p=0; p < host->num_ports; ++p) { + if (!host->ports[p].jack_port) + continue; + + if (host->ports[p].type == FLOAT) { + slv2_instance_connect_port(host->instance, p, + jack_port_get_buffer(host->ports[p].jack_port, nframes)); + } else if (host->ports[p].type == MIDI) { + + void* jack_buffer = jack_port_get_buffer(host->ports[p].jack_port, nframes); + + LV2_MIDIState state; + lv2midi_reset_state(&state, host->ports[p].midi_buffer, nframes); + lv2midi_reset_buffer(state.midi); + + if (host->ports[p].direction == INPUT) { + jack_midi_event_t ev; + + const jack_nframes_t event_count + = jack_midi_get_event_count(jack_buffer, nframes); + + for (jack_nframes_t e=0; e < event_count; ++e) { + + jack_midi_event_get(&ev, jack_buffer, e, nframes); + + state.midi = host->ports[p].midi_buffer; + lv2midi_put_event(&state, (double)ev.time, ev.size, ev.buffer); + } + } + } + } + + + /* Run plugin for this cycle */ + slv2_instance_run(host->instance, nframes); + + + /* Deliver output */ + for (uint32_t p=0; p < host->num_ports; ++p) { + if (host->ports[p].jack_port + && host->ports[p].type == MIDI + && host->ports[p].direction == OUTPUT) { + + void* jack_buffer = jack_port_get_buffer(host->ports[p].jack_port, nframes); + + jack_midi_clear_buffer(jack_buffer, nframes); + + LV2_MIDIState state; + lv2midi_reset_state(&state, host->ports[p].midi_buffer, nframes); + + double timestamp = 0.0f; + uint32_t size = 0; + unsigned char* data = NULL; + + const uint32_t event_count = state.midi->event_count; + + for (uint32_t i=0; i < event_count; ++i) { + lv2midi_get_event(&state, ×tamp, &size, &data); + + jack_midi_event_write(jack_buffer, + (jack_nframes_t)timestamp, data, size, nframes); + + lv2midi_increment(&state); + } + + } + } + + return 0; +} + + +void +list_plugins(SLV2List list) +{ + 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/hosts/lv2_simple_jack_host.c b/hosts/lv2_simple_jack_host.c new file mode 100644 index 0000000..f0a266d --- /dev/null +++ b/hosts/lv2_simple_jack_host.c @@ -0,0 +1,220 @@ +/* SLV2 Simple Jack Host Example + * Copyright (C) 2007 Dave Robillard + * + * This program 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 program 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 +#include +#include +#include +#include + + +/** This program's data */ +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) */ + uint32_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, uint32_t port_index); +int jack_process_cb(jack_nframes_t nframes, void* data); +void list_plugins(SLV2List list); + + +int +main(int argc, char** argv) +{ + struct JackHost host; + host.jack_client = NULL; + host.num_ports = 0; + host.jack_ports = NULL; + host.controls = NULL; + + /* Find all installed plugins */ + SLV2List plugins = slv2_list_new(); + slv2_list_load_all(plugins); + //slv2_list_load_bundle(plugins, "http://www.scs.carleton.ca/~drobilla/files/Amp-swh.lv2"); + + /* Find the plugin to run */ + const char* plugin_uri = (argc == 2) ? argv[1] : NULL; + + if (!plugin_uri) { + fprintf(stderr, "\nYou must specify a plugin URI to load.\n"); + fprintf(stderr, "\nKnown plugins:\n\n"); + list_plugins(plugins); + return EXIT_FAILURE; + } + + printf("URI:\t%s\n", plugin_uri); + host.plugin = slv2_list_get_plugin_by_uri(plugins, plugin_uri); + + if (!host.plugin) { + fprintf(stderr, "Failed to find plugin %s.\n", plugin_uri); + slv2_list_free(plugins); + return EXIT_FAILURE; + } + + /* Get the plugin's name */ + char* name = slv2_plugin_get_name(host.plugin); + printf("Name:\t%s\n", name); + + /* Connect to JACK (with plugin name as client name) */ + host.jack_client = jack_client_open(name, JackNullOption, NULL); + free(name); + if (!host.jack_client) + die("Failed to connect to JACK."); + else + printf("Connected to JACK.\n"); + + /* Instantiate the plugin */ + host.instance = slv2_plugin_instantiate( + host.plugin, jack_get_sample_rate(host.jack_client), NULL); + if (!host.instance) + die("Failed to instantiate plugin.\n"); + else + printf("Succesfully instantiated plugin.\n"); + + jack_set_process_callback(host.jack_client, &jack_process_cb, (void*)(&host)); + + /* Create ports */ + host.num_ports = slv2_plugin_get_num_ports(host.plugin); + host.jack_ports = calloc((size_t)host.num_ports, sizeof(jack_port_t*)); + host.controls = calloc((size_t)host.num_ports, sizeof(float*)); + + for (uint32_t i=0; i < host.num_ports; ++i) + create_port(&host, i); + + /* Activate plugin and JACK */ + slv2_instance_activate(host.instance); + jack_activate(host.jack_client); + + /* Run */ + printf("Press enter to quit: "); + getc(stdin); + printf("\n"); + + /* Deactivate plugin and JACK */ + slv2_instance_free(host.instance); + slv2_list_free(plugins); + + printf("Shutting down JACK.\n"); + for (unsigned long i=0; i < host.num_ports; ++i) { + if (host.jack_ports[i] != NULL) { + jack_port_unregister(host.jack_client, host.jack_ports[i]); + host.jack_ports[i] = NULL; + } + } + jack_client_close(host.jack_client); + + return 0; +} + + +/** Abort and exit on error */ +void +die(const char* msg) +{ + fprintf(stderr, "%s\n", msg); + exit(EXIT_FAILURE); +} + + +/** Creates a port and connects the plugin instance to it's data location. + * + * For audio ports, creates a jack port and connects plugin port to buffer. + * + * For control ports, sets controls array to default value and connects plugin + * port to that element. + */ +void +create_port(struct JackHost* host, + uint32_t port_index) +{ + /* Make sure this is a float port */ + 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); + + /* Get the port symbol (label) for console printing */ + char* symbol = slv2_port_get_symbol(host->plugin, port_index); + + /* Initialize the port array elements */ + host->jack_ports[port_index] = NULL; + host->controls[port_index] = 0.0f; + + /* Get the 'class' of the port (control input, audio output, etc) */ + enum SLV2PortClass class = slv2_port_get_class(host->plugin, port_index); + + /* Connect the port based on it's 'class' */ + switch (class) { + case SLV2_CONTROL_RATE_INPUT: + host->controls[port_index] = slv2_port_get_default_value(host->plugin, port_index); + slv2_instance_connect_port(host->instance, port_index, &host->controls[port_index]); + printf("Set %s to %f\n", symbol, host->controls[port_index]); + break; + case SLV2_CONTROL_RATE_OUTPUT: + slv2_instance_connect_port(host->instance, port_index, &host->controls[port_index]); + break; + case SLV2_AUDIO_RATE_INPUT: + host->jack_ports[port_index] = jack_port_register(host->jack_client, + symbol, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); + break; + case SLV2_AUDIO_RATE_OUTPUT: + host->jack_ports[port_index] = jack_port_register(host->jack_client, + symbol, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + break; + default: + die("ERROR: Unknown port type, aborting messily!"); + } + + free(symbol); +} + + +/** Jack process callback. */ +int +jack_process_cb(jack_nframes_t nframes, void* data) +{ + struct JackHost* host = (struct JackHost*)data; + + /* Connect plugin ports directly to JACK buffers */ + for (uint32_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)); + + /* Run plugin for this cycle */ + slv2_instance_run(host->instance, nframes); + + return 0; +} + + +void +list_plugins(SLV2List list) +{ + 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/src/plugininstance.c b/src/plugininstance.c index edc6e4f..9c6bf15 100644 --- a/src/plugininstance.c +++ b/src/plugininstance.c @@ -48,14 +48,14 @@ slv2_plugin_instantiate(const SLV2Plugin* plugin, dlerror(); void* lib = dlopen((char*)lib_path, RTLD_NOW); if (!lib) { - printf("Unable to open library %s (%s)\n", lib_path, dlerror()); + fprintf(stderr, "Unable to open library %s (%s)\n", lib_path, dlerror()); return NULL; } LV2_Descriptor_Function df = dlsym(lib, "lv2_descriptor"); if (!df) { - printf("Could not find symbol 'lv2_descriptor', " + fprintf(stderr, "Could not find symbol 'lv2_descriptor', " "%s is not a LV2 plugin.\n", lib_path); dlclose(lib); return NULL; @@ -68,12 +68,12 @@ slv2_plugin_instantiate(const SLV2Plugin* plugin, const LV2_Descriptor* ld = df(i); if (!ld) { - printf("Did not find plugin %s in %s\n", + fprintf(stderr, "Did not find plugin %s in %s\n", plugin->plugin_uri, plugin->lib_url); dlclose(lib); break; // return NULL } else if (!strcmp(ld->URI, (char*)plugin->plugin_uri)) { - printf("Found %s at index %u in:\n\t%s\n\n", plugin->plugin_uri, i, lib_path); + //printf("Found %s at index %u in:\n\t%s\n\n", plugin->plugin_uri, i, lib_path); assert(ld->instantiate); diff --git a/src/pluginlist.c b/src/pluginlist.c index 6818cf5..18bb44f 100644 --- a/src/pluginlist.c +++ b/src/pluginlist.c @@ -64,7 +64,7 @@ slv2_list_load_all(SLV2List list) const char* const suffix = "/.lv2:/usr/local/lib/lv2:usr/lib/lv2"; slv2_path = strjoin(home, suffix, NULL); - printf("$LV2_PATH is unset. Using default path %s\n", slv2_path); + fprintf(stderr, "$LV2_PATH is unset. Using default path %s\n", slv2_path); slv2_list_load_path(list, slv2_path); free(slv2_path); diff --git a/utils/Makefile.am b/utils/Makefile.am index 8d23d38..36a06ec 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -1,9 +1,16 @@ -if BUILD_UTILITIES +AM_CFLAGS = -I$(top_srcdir) @RASQAL_CFLAGS@ -bin_PROGRAMS = ladspa2lv2 +bin_PROGRAMS = lv2_list + +lv2_list_SOURCES = lv2_list.c +lv2_list_LDADD = ../src/libslv2.la + +if BUILD_LADSPA2SLV2 + +bin_PROGRAMS += ladspa2lv2 ladspa2lv2_CXXFLAGS = @RAUL_CFLAGS@ @RAPTOR_CFLAGS@ ladspa2lv2_LDADD = -ldl @RAUL_LIBS@ @RAPTOR_LIBS@ -ladspa2lv2_SOURCES = ladspa2lv2.cc +ladspa2lv2_SOURCES = ladspa2lv2.cpp endif diff --git a/utils/README b/utils/README new file mode 100644 index 0000000..c7ded0e --- /dev/null +++ b/utils/README @@ -0,0 +1,3 @@ +This is still in development, and depends on Raptor 1.4.14. + +Soon.... diff --git a/utils/ladspa2lv2.cc b/utils/ladspa2lv2.cc deleted file mode 100644 index f3a4d14..0000000 --- a/utils/ladspa2lv2.cc +++ /dev/null @@ -1,196 +0,0 @@ -/* ladspa2lv2 - * Copyright (C) 2007 Dave Robillard - * - * This program 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 program 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 -#include -#include -#include -#include "raul/RDFWriter.h" - -#define U(x) ((const unsigned char*)(x)) - -using Raul::RDFWriter; -using Raul::RdfId; -using Raul::Atom; - -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; -} - -#if 0 -void -write_resource(raptor_serializer* serializer, - const char* subject_uri, - const char* predicate_uri, - const char* object_uri) -{ - raptor_statement triple; - - triple.subject = (void*)raptor_new_uri(U(subject_uri)); - triple.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; - - triple.predicate = (void*)raptor_new_uri(U(predicate_uri)); - triple.predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; - - //if (object.type() == RdfId::RESOURCE) { - triple.object = (void*)raptor_new_uri(U(object_uri)); - triple.object_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; - /*} else { - assert(object.type() == RdfId::ANONYMOUS); - triple.object = (unsigned char*)(strdup(object.to_string().c_str())); - triple.object_type = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS; - }*/ - - raptor_serialize_statement(serializer, &triple); -} -#endif - -void -write_lv2_turtle(LADSPA_Descriptor* descriptor, const char* uri, const char* filename) -{ -#if 0 - raptor_init(); - raptor_serializer* serializer = raptor_new_serializer("turtle"); - - // Set up namespaces - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://www.w3.org/1999/02/22-rdf-syntax-ns#")), U("rdf")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://www.w3.org/2000/01/rdf-schema#")), U("rdfs")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://www.w3.org/2001/XMLSchema")), U("xsd")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://usefulinc.com/ns/doap#")), U("doap")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://xmlns.com/foaf/0.1/")), U("foaf")); - raptor_serialize_set_namespace(serializer, raptor_new_uri( - U("http://lv2plug.in/ontology#")), U("lv2")); - - raptor_serialize_start_to_filename(serializer, filename); - - - // Write out plugin data - - write_resource(serializer, uri, - "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "lv2:Plugin"); - - write_resource(serializer, uri, - "http://usefulinc.com/ns/doap#name", descriptor->Name); - - - - raptor_serialize_end(serializer); - raptor_free_serializer(serializer); - raptor_finish(); -#endif - RDFWriter writer; - - writer.add_prefix("lv2", "http://lv2plug.in/ontology#"); - writer.add_prefix("doap", "http://usefulinc.com/ns/doap#"); - - writer.start_to_filename(filename); - - RdfId plugin_id = RdfId(RdfId::RESOURCE, uri); - - writer.write(plugin_id, - RdfId(RdfId::RESOURCE, "rdf:type"), - RdfId(RdfId::RESOURCE, "lv2:Plugin")); - - writer.write(plugin_id, - RdfId(RdfId::RESOURCE, "doap:name"), - Atom(descriptor->Name)); - - if (LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties)) - writer.write(plugin_id, - RdfId(RdfId::RESOURCE, "lv2:property"), - RdfId(RdfId::RESOURCE, "lv2:hardRTCapable")); - - for (uint32_t i=0; i < descriptor->PortCount; ++i) { - char index_str[32]; - snprintf(index_str, 32, "%u", i); - - RdfId port_id(RdfId::ANONYMOUS, index_str); - - writer.write(plugin_id, - RdfId(RdfId::RESOURCE, "lv2:port"), - port_id); - - writer.write(port_id, - RdfId(RdfId::RESOURCE, "lv2:index"), - Atom((int32_t)i)); - - writer.write(port_id, - RdfId(RdfId::RESOURCE, "lv2:dataType"), - RdfId(RdfId::RESOURCE, "lv2:float")); - - writer.write(port_id, - RdfId(RdfId::RESOURCE, "lv2:name"), - Atom(descriptor->PortNames[i])); - } - - writer.finish(); -} - - -void -print_usage() -{ - printf("Usage: ladspa2slv2 /path/to/laddspalib.so index lv2_uri\n\n"); -} - - -int -main(int argc, char** argv) -{ - if (argc != 4) { - print_usage(); - return 1; - } - - const char* const lib_path = argv[1]; - const unsigned long index = atol(argv[2]); - const char* const uri = argv[3]; - - - LADSPA_Descriptor* descriptor = load_ladspa_plugin(lib_path, index); - - if (descriptor) { - printf("Loaded %s : %lu\n", lib_path, index); - write_lv2_turtle(descriptor, uri, "ladspaplugin.ttl"); - } else { - printf("Failed to load %s : %lu\n", lib_path, index); - } - - return 0; -} diff --git a/utils/ladspa2lv2.cpp b/utils/ladspa2lv2.cpp new file mode 100644 index 0000000..23cd561 --- /dev/null +++ b/utils/ladspa2lv2.cpp @@ -0,0 +1,199 @@ +/* ladspa2lv2 + * Copyright (C) 2007 Dave Robillard + * + * This program 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 program 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 +#include +#include +#include +#include "raul/RDFWriter.h" + +#define U(x) ((const unsigned char*)(x)) + +using Raul::RDFWriter; +using Raul::RdfId; +using Raul::Atom; + +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; +} + +#if 0 +void +write_resource(raptor_serializer* serializer, + const char* subject_uri, + const char* predicate_uri, + const char* object_uri) +{ + raptor_statement triple; + + triple.subject = (void*)raptor_new_uri(U(subject_uri)); + triple.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + + triple.predicate = (void*)raptor_new_uri(U(predicate_uri)); + triple.predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + + //if (object.type() == RdfId::RESOURCE) { + triple.object = (void*)raptor_new_uri(U(object_uri)); + triple.object_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + /*} else { + assert(object.type() == RdfId::ANONYMOUS); + triple.object = (unsigned char*)(strdup(object.to_string().c_str())); + triple.object_type = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS; + }*/ + + raptor_serialize_statement(serializer, &triple); +} +#endif + +void +write_lv2_turtle(LADSPA_Descriptor* descriptor, const char* uri, const char* filename) +{ +#if 0 + raptor_init(); + raptor_serializer* serializer = raptor_new_serializer("turtle"); + + // Set up namespaces + raptor_serialize_set_namespace(serializer, raptor_new_uri( + U("http://www.w3.org/1999/02/22-rdf-syntax-ns#")), U("rdf")); + raptor_serialize_set_namespace(serializer, raptor_new_uri( + U("http://www.w3.org/2000/01/rdf-schema#")), U("rdfs")); + raptor_serialize_set_namespace(serializer, raptor_new_uri( + U("http://www.w3.org/2001/XMLSchema")), U("xsd")); + raptor_serialize_set_namespace(serializer, raptor_new_uri( + U("http://usefulinc.com/ns/doap#")), U("doap")); + raptor_serialize_set_namespace(serializer, raptor_new_uri( + U("http://xmlns.com/foaf/0.1/")), U("foaf")); + raptor_serialize_set_namespace(serializer, raptor_new_uri( + U("http://lv2plug.in/ontology#")), U("lv2")); + + raptor_serialize_start_to_filename(serializer, filename); + + + // Write out plugin data + + write_resource(serializer, uri, + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "lv2:Plugin"); + + write_resource(serializer, uri, + "http://usefulinc.com/ns/doap#name", descriptor->Name); + + + + raptor_serialize_end(serializer); + raptor_free_serializer(serializer); + raptor_finish(); +#endif + RDFWriter writer; + + writer.add_prefix("lv2", "http://lv2plug.in/ontology#"); + writer.add_prefix("doap", "http://usefulinc.com/ns/doap#"); + + writer.start_to_filename(filename); + + RdfId plugin_id = RdfId(RdfId::RESOURCE, uri); + + writer.write(plugin_id, + RdfId(RdfId::RESOURCE, "rdf:type"), + RdfId(RdfId::RESOURCE, "lv2:Plugin")); + + writer.write(plugin_id, + RdfId(RdfId::RESOURCE, "doap:name"), + Atom(descriptor->Name)); + + if (LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties)) + writer.write(plugin_id, + RdfId(RdfId::RESOURCE, "lv2:property"), + RdfId(RdfId::RESOURCE, "lv2:hardRTCapable")); + + for (uint32_t i=0; i < descriptor->PortCount; ++i) { + char index_str[32]; + snprintf(index_str, 32, "%u", i); + + RdfId port_id(RdfId::ANONYMOUS, index_str); + + writer.write(plugin_id, + RdfId(RdfId::RESOURCE, "lv2:port"), + port_id); + + writer.write(port_id, + RdfId(RdfId::RESOURCE, "lv2:index"), + Atom((int32_t)i)); + + writer.write(port_id, + RdfId(RdfId::RESOURCE, "lv2:dataType"), + RdfId(RdfId::RESOURCE, "lv2:float")); + + writer.write(port_id, + RdfId(RdfId::RESOURCE, "lv2:name"), + Atom(descriptor->PortNames[i])); + } + + writer.finish(); +} + + +void +print_usage() +{ + printf("Usage: ladspa2slv2 /path/to/laddspalib.so ladspa_index lv2_uri\n"); + printf("Partially convert a LADSPA plugin to an LV2 plugin."); + printf("(This is a utility for developers, it will not generate a usable\n"); + printf("LV2 plugin directly).\n\n"); +} + + +int +main(int argc, char** argv) +{ + if (argc != 4) { + print_usage(); + return 1; + } + + const char* const lib_path = argv[1]; + const unsigned long index = atol(argv[2]); + const char* const uri = argv[3]; + + + LADSPA_Descriptor* descriptor = load_ladspa_plugin(lib_path, index); + + if (descriptor) { + printf("Loaded %s : %lu\n", lib_path, index); + write_lv2_turtle(descriptor, uri, "ladspaplugin.ttl"); + } else { + printf("Failed to load %s : %lu\n", lib_path, index); + } + + return 0; +} diff --git a/utils/lv2_list.c b/utils/lv2_list.c new file mode 100644 index 0000000..e1cba6d --- /dev/null +++ b/utils/lv2_list.c @@ -0,0 +1,43 @@ +/* lv2_list - List system installed LV2 plugins. + * Copyright (C) 2007 Dave Robillard + * + * This program 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 program 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 +#include + + +void +list_plugins(SLV2List list) +{ + 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)); + } +} + + +int +main()//int argc, char** argv) +{ + SLV2List plugins = slv2_list_new(); + slv2_list_load_all(plugins); + + list_plugins(plugins); + + return 0; +} + -- cgit v1.2.1