From 990caaf5104b2ebcd1c520af94eb28b94ccaf504 Mon Sep 17 00:00:00 2001 From: Nick Lanham Date: Thu, 22 Mar 2012 14:15:00 +0100 Subject: [PATCH] Move to using atom instead of event. So far just pass midi via atom. --- CMakeLists.txt | 9 +++++- drmr.c | 80 +++++++++++++++++++++++--------------------------- drmr.h | 15 +++++----- drmr.ttl | 16 ++++++---- 4 files changed, 63 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6d7b9d..5b6e7ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,8 +51,15 @@ target_link_libraries(drmr_ui ${LV2_LIBRARIES} ${GTK2_LIBRARIES} ${SNDFILE_LIBRA add_definitions ( -DPIC ) +set_target_properties (drmr + PROPERTIES + COMPILE_FLAGS "-std=gnu99" +) + +set (ui_compile_flags "-std=gnu99") + if (NOT USE_NKNOB) - set (ui_compile_flags "-DNO_NKNOB") + set (ui_compile_flags "${ui_compile_flags} -DNO_NKNOB") endif (NOT USE_NKNOB) if (SAMP_ZERO_POS GREATER "-1" AND SAMP_ZERO_POS LESS "4") diff --git a/drmr.c b/drmr.c index 42c2096..6570807 100644 --- a/drmr.c +++ b/drmr.c @@ -81,17 +81,16 @@ instantiate(const LV2_Descriptor* descriptor, // Map midi uri while(*features) { - if (!strcmp((*features)->URI, LV2_URI_MAP_URI)) { - drmr->map = (LV2_URI_Map_Feature *)((*features)->data); - drmr->uris.midi_event = drmr->map->uri_to_id - (drmr->map->callback_data, - "http://lv2plug.in/ns/ext/event", - "http://lv2plug.in/ns/ext/midi#MidiEvent"); + if (!strcmp((*features)->URI, LV2_URID_URI "#map")) { + drmr->map = (LV2_URID_Map *)((*features)->data); + drmr->uris.midi_event = + drmr->map->map(drmr->map->handle, + "http://lv2plug.in/ns/ext/midi#MidiEvent"); } features++; } if (!drmr->map) { - fprintf(stderr, "LV2 host does not support uri-map.\n"); + fprintf(stderr, "LV2 host does not support urid#map.\n"); free(drmr); return 0; } @@ -126,8 +125,8 @@ connect_port(LV2_Handle instance, DrMr* drmr = (DrMr*)instance; DrMrPortIndex port_index = (DrMrPortIndex)port; switch (port_index) { - case DRMR_MIDI: - drmr->midi_port = (LV2_Event_Buffer*)data; + case DRMR_CONTROL: + drmr->control_port = (LV2_Atom_Sequence*)data; break; case DRMR_LEFT: drmr->left = (float*)data; @@ -191,42 +190,37 @@ static void run(LV2_Handle instance, uint32_t n_samples) { if (kitInt != drmr->curKit) // requested a new kit pthread_cond_signal(&drmr->load_cond); - LV2_Event_Iterator eit; - if (drmr->midi_port && lv2_event_begin(&eit,drmr->midi_port)) { // if we have any events - LV2_Event *cur_ev; - uint8_t* data; - while (lv2_event_is_valid(&eit)) { - cur_ev = lv2_event_get(&eit,&data); - if (cur_ev->type == drmr->uris.midi_event) { - //int channel = *data & 15; - switch ((*data) >> 4) { - case 8: // ignore note-offs for now, should probably be a setting - //if (drmr->cur_samp) drmr->cur_samp->active = 0; - break; - case 9: { - uint8_t nn = data[1]; - nn-=baseNote; - // need to mutex this to avoid getting the samples array - // changed after the check that the midi-note is valid - pthread_mutex_lock(&drmr->load_mutex); - if (nn >= 0 && nn < drmr->num_samples) { - if (drmr->samples[nn].layer_count > 0) { - layer_to_sample(drmr->samples+nn,*(drmr->gains[nn])); - if (drmr->samples[nn].limit == 0) - fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]); - } - drmr->samples[nn].active = 1; - drmr->samples[nn].offset = 0; + LV2_SEQUENCE_FOREACH(drmr->control_port, i) { + LV2_Atom_Event* const ev = lv2_sequence_iter_get(i); + if (ev->body.type == drmr->uris.midi_event) { + uint8_t* const data = (uint8_t* const)(ev + 1); + //int channel = *data & 15; + switch ((*data) >> 4) { + case 8: // ignore note-offs for now, should probably be a setting + //if (drmr->cur_samp) drmr->cur_samp->active = 0; + break; + case 9: { + uint8_t nn = data[1]; + nn-=baseNote; + // need to mutex this to avoid getting the samples array + // changed after the check that the midi-note is valid + pthread_mutex_lock(&drmr->load_mutex); + if (nn >= 0 && nn < drmr->num_samples) { + if (drmr->samples[nn].layer_count > 0) { + layer_to_sample(drmr->samples+nn,*(drmr->gains[nn])); + if (drmr->samples[nn].limit == 0) + fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]); } - pthread_mutex_unlock(&drmr->load_mutex); - break; + drmr->samples[nn].active = 1; + drmr->samples[nn].offset = 0; } - default: - printf("Unhandeled status: %i\n",(*data)>>4); - } - } else printf("unrecognized event\n"); - lv2_event_increment(&eit); - } + pthread_mutex_unlock(&drmr->load_mutex); + break; + } + default: + printf("Unhandeled status: %i\n",(*data)>>4); + } + } else printf("unrecognized event\n"); } for(i = 0;i #include +#include "lv2/lv2plug.in/ns/ext/atom/forge.h" +// util includes atom.h +#include "lv2/lv2plug.in/ns/ext/atom/util.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" -#include "lv2/lv2plug.in/ns/ext/event/event.h" -#include "lv2/lv2plug.in/ns/ext/event/event-helpers.h" -#include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h" +#include "lv2/lv2plug.in/ns/ext/urid/urid.h" // drumkit scanned from a hydrogen xml file typedef struct { @@ -67,7 +68,7 @@ typedef struct { #define GAIN_MAX 6.0f typedef enum { - DRMR_MIDI = 0, + DRMR_CONTROL = 0, DRMR_LEFT, DRMR_RIGHT, DRMR_KITNUM, @@ -143,7 +144,7 @@ typedef struct { // Ports float* left; float* right; - LV2_Event_Buffer *midi_port; + LV2_Atom_Sequence *control_port; // params float** gains; @@ -153,9 +154,9 @@ typedef struct { double rate; // URIs - LV2_URI_Map_Feature* map; + LV2_URID_Map* map; struct { - uint32_t midi_event; + LV2_URID midi_event; } uris; // Available kits diff --git a/drmr.ttl b/drmr.ttl index bbe4100..6f70fc6 100644 --- a/drmr.ttl +++ b/drmr.ttl @@ -1,10 +1,11 @@ @prefix lv2: . -@prefix ev: . @prefix foaf: . @prefix doap: . @prefix rdf: . @prefix rdfs: . @prefix ui: . +@prefix atom: . +@prefix urid: . a lv2:InstrumentPlugin, lv2:Plugin; @@ -15,14 +16,17 @@ foaf:homepage ; foaf:mbox ] ; - doap:license ; + doap:license ; + lv2:requiredFeature urid:map ; ui:ui ; lv2:port [ - a ev:EventPort, lv2:InputPort; + a lv2:InputPort , atom:MessagePort; + atom:bufferType atom:Sequence ; + atom:supports , + ; lv2:index 0; - ev:supportsEvent ; - lv2:symbol "midi"; - lv2:name "MIDI"; + lv2:symbol "control"; + lv2:name "Control"; ], [ a lv2:AudioPort, lv2:OutputPort;