diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/eg-sampler.lv2/sampler.c | 89 | ||||
-rw-r--r-- | plugins/eg-sampler.lv2/sampler.ttl | 18 | ||||
-rw-r--r-- | plugins/eg-sampler.lv2/wscript | 11 |
3 files changed, 50 insertions, 68 deletions
diff --git a/plugins/eg-sampler.lv2/sampler.c b/plugins/eg-sampler.lv2/sampler.c index b7b63bd..33e8e3e 100644 --- a/plugins/eg-sampler.lv2/sampler.c +++ b/plugins/eg-sampler.lv2/sampler.c @@ -41,9 +41,9 @@ #include <sndfile.h> -#include "lv2/lv2plug.in/ns/ext/event/event-helpers.h" +#include "lv2/lv2plug.in/ns/ext/atom/atom-buffer.h" #include "lv2/lv2plug.in/ns/ext/persist/persist.h" -#include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h" +#include "lv2/lv2plug.in/ns/ext/urid/urid.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" #define NS_ATOM "http://lv2plug.in/ns/ext/atom#" @@ -68,7 +68,7 @@ typedef struct { typedef struct { /* Features */ - LV2_URI_Map_Feature* uri_map; + LV2_URID_Mapper* mapper; /* Sample */ SampleFile* samp; @@ -78,10 +78,9 @@ typedef struct { int pending_sample_ready; /* Ports */ - float* outputPort; - LV2_Event_Buffer* eventPort; - LV2_Event_Feature* event_ref; - int midi_event_id; + float* output_port; + LV2_Atom_Buffer* event_port; + LV2_URID midi_event_id; /* Playback state */ bool play; @@ -170,10 +169,10 @@ connect_port(LV2_Handle instance, switch (port) { case SAMPLER_CONTROL: - plugin->eventPort = (LV2_Event_Buffer*)data; + plugin->event_port = (LV2_Atom_Buffer*)data; break; case SAMPLER_OUT: - plugin->outputPort = (float*)data; + plugin->output_port = (float*)data; break; default: break; @@ -186,19 +185,19 @@ instantiate(const LV2_Descriptor* descriptor, const char* path, const LV2_Feature* const* features) { - Sampler* plugin = (Sampler*)malloc(sizeof(Sampler)); - assert(plugin); - memset(plugin, 0, sizeof(Sampler)); + Sampler* plugin = (Sampler*)malloc(sizeof(Sampler)); + plugin->samp = (SampleFile*)malloc(sizeof(SampleFile)); + plugin->pending_samp = (SampleFile*)malloc(sizeof(SampleFile)); + + if (!plugin || !plugin->samp || !plugin->pending_samp) { + return NULL; + } - plugin->samp = (SampleFile*)malloc(sizeof(SampleFile)); - assert(plugin->samp); + memset(plugin, 0, sizeof(Sampler)); memset(plugin->samp, 0, sizeof(SampleFile)); - plugin->pending_samp = (SampleFile*)malloc(sizeof(SampleFile)); - assert(plugin->pending_samp); memset(plugin->pending_samp, 0, sizeof(SampleFile)); plugin->midi_event_id = -1; - plugin->event_ref = 0; /* Initialise mutexes and conditions for the worker thread */ if (pthread_mutex_init(&plugin->pending_samp_mutex, 0)) { @@ -214,21 +213,17 @@ instantiate(const LV2_Descriptor* descriptor, goto fail; } - /* Scan host features for event and uri-map */ + /* Scan host features for uri mapper */ for (int i = 0; features[i]; ++i) { - if (strcmp(features[i]->URI, LV2_URI_MAP_URI) == 0) { - plugin->uri_map = (LV2_URI_Map_Feature*)features[i]->data; - plugin->midi_event_id = plugin->uri_map->uri_to_id( - plugin->uri_map->callback_data, - LV2_EVENT_URI, MIDI_EVENT_URI); - } else if (strcmp(features[i]->URI, LV2_EVENT_URI) == 0) { - plugin->event_ref = (LV2_Event_Feature*)features[i]->data; + if (!strcmp(features[i]->URI, LV2_URID_URI "#Mapper")) { + plugin->mapper = (LV2_URID_Mapper*)features[i]->data; + plugin->midi_event_id = plugin->mapper->map_uri( + plugin->mapper->handle, MIDI_EVENT_URI); } } - if (plugin->midi_event_id == -1) { - /* Host does not support uri-map extension */ - fprintf(stderr, "Host does not support uri-map extension.\n"); + if (!plugin->mapper) { + fprintf(stderr, "Host does not support urid:Mapper.\n"); goto fail; } @@ -250,29 +245,19 @@ static void run(LV2_Handle instance, uint32_t sample_count) { - Sampler* plugin = (Sampler*)instance; - LV2_Event* ev = NULL; - + Sampler* plugin = (Sampler*)instance; sf_count_t start_frame = 0; sf_count_t pos = 0; - float* output = plugin->outputPort; + float* output = plugin->output_port; /* Read incoming events */ - LV2_Event_Iterator iterator; - for (lv2_event_begin(&iterator, plugin->eventPort); - lv2_event_is_valid(&iterator); - lv2_event_increment(&iterator)) { - - ev = lv2_event_get(&iterator, NULL); + for (LV2_Atom_Buffer_Iterator i = lv2_atom_buffer_begin(plugin->event_port); + lv2_atom_buffer_is_valid(i); + i = lv2_atom_buffer_next(i)) { - if (ev->type == 0) { - if (plugin->event_ref) { - plugin->event_ref->lv2_event_unref( - plugin->event_ref->callback_data, ev); - } - } else if (ev->type == plugin->midi_event_id) { + LV2_Atom_Event* const ev = lv2_atom_buffer_get(i); + if (ev->body.type == plugin->midi_event_id) { uint8_t* const data = (uint8_t* const)(ev + 1); - if ((data[0] & 0xF0) == 0x90) { start_frame = ev->frames; plugin->frame = 0; @@ -330,16 +315,14 @@ run(LV2_Handle instance, /* Add zeros to end if sample not long enough (or not playing) */ for (; pos < sample_count; ++pos) { - output[pos] = 0; + output[pos] = 0.0f; } } static uint32_t -uri_to_id(Sampler* plugin, const char* uri) +map_uri(Sampler* plugin, const char* uri) { - return plugin->uri_map->uri_to_id(plugin->uri_map->callback_data, - NULL, - uri); + return plugin->mapper->map_uri(plugin->mapper->handle, uri); } static void @@ -349,10 +332,10 @@ save(LV2_Handle instance, { Sampler* plugin = (Sampler*)instance; store(callback_data, - uri_to_id(plugin, FILENAME_URI), + map_uri(plugin, FILENAME_URI), plugin->samp->filepath, strlen(plugin->samp->filepath) + 1, - uri_to_id(plugin, NS_ATOM "String"), + map_uri(plugin, NS_ATOM "String"), LV2_PERSIST_IS_POD | LV2_PERSIST_IS_PORTABLE); } @@ -369,7 +352,7 @@ restore(LV2_Handle instance, const void* value = retrieve( callback_data, - uri_to_id(plugin, FILENAME_URI), + map_uri(plugin, FILENAME_URI), &size, &type, &flags); if (value) { diff --git a/plugins/eg-sampler.lv2/sampler.ttl b/plugins/eg-sampler.lv2/sampler.ttl index f411206..a7cf6e4 100644 --- a/plugins/eg-sampler.lv2/sampler.ttl +++ b/plugins/eg-sampler.lv2/sampler.ttl @@ -1,7 +1,7 @@ # LV2 Sampler Example Plugin -# Copyright 2011 Gabriel M. Beddingfield <gabriel@teuton.org>, -# James Morris <jwm.art.net@gmail.com>, -# David Robillard <d@drobilla.net> +# Copyright 2011 Gabriel M. Beddingfield <gabriel@teuton.org> +# Copyright 2011 James Morris <jwm.art.net@gmail.com> +# Copyright 2011 David Robillard <d@drobilla.net> # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -15,25 +15,25 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +@prefix atom: <http://lv2plug.in/ns/ext/atom#> . @prefix doap: <http://usefulinc.com/ns/doap#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix lv2: <http://lv2plug.in/ns/lv2core#> . -@prefix lv2ev: <http://lv2plug.in/ns/ext/event#> . @prefix ui: <http://lv2plug.in/ns/extensions/ui#> . <http://lv2plug.in/plugins/eg-sampler> a lv2:Plugin ; - doap:name "Simple Sampler" ; + doap:name "Example Sampler" ; doap:license <http://opensource.org/licenses/isc-license> ; - lv2:requiredFeature <http://lv2plug.in/ns/ext/uri-map> ; + lv2:requiredFeature <http://lv2plug.in/ns/ext/urid#Mapper> ; lv2:optionalFeature lv2:hardRtCapable , <http://lv2plug.in/ns/ext/event> , - <http://lv2plug.in/ns/ext/persist> ; + <http://lv2plug.in/ns/ext/state> ; ui:ui <http://lv2plug.in/plugins/eg-sampler#ui> ; lv2:port [ a lv2:InputPort , - lv2ev:EventPort ; - lv2ev:supportsEvent <http://lv2plug.in/ns/ext/midi#MidiEvent> ; + atom:EventPort ; + atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ; lv2:index 0 ; lv2:symbol "control" ; lv2:name "Control" diff --git a/plugins/eg-sampler.lv2/wscript b/plugins/eg-sampler.lv2/wscript index 9dd0b61..70273c3 100644 --- a/plugins/eg-sampler.lv2/wscript +++ b/plugins/eg-sampler.lv2/wscript @@ -13,19 +13,18 @@ top = '.' out = 'build' def options(opt): - autowaf.set_options(opt) opt.load('compiler_c') + autowaf.set_options(opt) def configure(conf): - autowaf.configure(conf) - + conf.load('compiler_c') conf.line_just = 51 + autowaf.configure(conf) autowaf.display_header('Sampler Configuration') - conf.load('compiler_c') autowaf.check_header(conf, 'c', 'lv2/lv2plug.in/ns/lv2core/lv2.h') - autowaf.check_header(conf, 'c', 'lv2/lv2plug.in/ns/ext/event/event-helpers.h') - autowaf.check_header(conf, 'c', 'lv2/lv2plug.in/ns/ext/uri-map/uri-map.h') + autowaf.check_header(conf, 'c', 'lv2/lv2plug.in/ns/ext/atom/atom-buffer.h') + autowaf.check_header(conf, 'c', 'lv2/lv2plug.in/ns/ext/urid/urid.h') autowaf.check_header(conf, 'c', 'lv2/lv2plug.in/ns/ext/persist/persist.h') autowaf.check_pkg(conf, 'sndfile', uselib_store='SNDFILE', atleast_version='1.0.0', mandatory=True) |