diff options
Diffstat (limited to 'lv2/lv2.cc')
-rw-r--r-- | lv2/lv2.cc | 69 |
1 files changed, 42 insertions, 27 deletions
@@ -35,6 +35,12 @@ #include <hugin.hpp> +enum { + FREE_WHEEL_PORT = 0, + MIDI_PORT, + AUDIO_PORT_BASE +}; + #define DRUMGIZMO_URI "http://drumgizmo.org/lv2" #define NS_DG DRUMGIZMO_URI "/atom#" @@ -47,12 +53,11 @@ static DrumGizmo *dg_get_pci(LV2_Handle instance) return dglv2->dg; } -LV2_State_Status -dg_save(LV2_Handle instance, - LV2_State_Store_Function store, - LV2_State_Handle handle, - uint32_t flags, - const LV2_Feature *const * features) +LV2_State_Status dg_save(LV2_Handle instance, + LV2_State_Store_Function store, + LV2_State_Handle handle, + uint32_t flags, + const LV2_Feature *const * features) { DGLV2 *dglv2 = (DGLV2 *)instance; @@ -77,12 +82,11 @@ dg_save(LV2_Handle instance, return LV2_STATE_SUCCESS; } -LV2_State_Status -dg_restore(LV2_Handle instance, - LV2_State_Retrieve_Function retrieve, - LV2_State_Handle handle, - uint32_t flags, - const LV2_Feature *const * features) +LV2_State_Status dg_restore(LV2_Handle instance, + LV2_State_Retrieve_Function retrieve, + LV2_State_Handle handle, + uint32_t flags, + const LV2_Feature *const * features) { DGLV2 *dglv2 = (DGLV2 *)instance; @@ -127,6 +131,9 @@ LV2_Handle instantiate(const struct _LV2_Descriptor *descriptor, { DGLV2 *dglv2 = new DGLV2; + dglv2->free_wheel_port = NULL; // Not assigned + dglv2->pos = 0; // Start from the beginning + dglv2->map = NULL; for (int i = 0 ; features[i] ; i++) { if (!strcmp(features[i]->URI, LV2_URID_URI "#map")) { @@ -148,19 +155,22 @@ LV2_Handle instantiate(const struct _LV2_Descriptor *descriptor, return (LV2_Handle)dglv2; } -void connect_port(LV2_Handle instance, - uint32_t port, - void *data_location) +void connect_port(LV2_Handle instance, uint32_t port, void *data_location) { DGLV2 *dglv2 = (DGLV2 *)instance; - if(port == 0) {// MIDI in + if(port == FREE_WHEEL_PORT) { + dglv2->free_wheel_port = (float*)data_location; + } + + if(port == MIDI_PORT) { // MIDI in dglv2->in->eventPort = (LV2_Atom_Sequence*)data_location; - } else {// Audio Port - if(port - 1 < NUM_OUTPUTS) { - dglv2->out->outputPorts[port - 1].samples = (sample_t*)data_location; - dglv2->out->outputPorts[port - 1].size = 0; - } + } + + if(port >= AUDIO_PORT_BASE) { // Audio Port + uint32_t audio_port = port - AUDIO_PORT_BASE; + dglv2->out->outputPorts[audio_port].samples = (sample_t*)data_location; + dglv2->out->outputPorts[audio_port].size = 0; } } @@ -171,20 +181,25 @@ void activate(LV2_Handle instance) (void)dglv2; } -void run(LV2_Handle instance, - uint32_t sample_count) +void run(LV2_Handle instance, uint32_t sample_count) { - static size_t pos = 0; DGLV2 *dglv2 = (DGLV2 *)instance; - dglv2->dg->run(pos, dglv2->buffer, sample_count); + if(dglv2->free_wheel_port) { + dglv2->dg->setFreeWheel(*dglv2->free_wheel_port); + } + + if(dglv2->buffer_size != sample_count) { + dglv2->buffer_size = sample_count; + dglv2->dg->setFrameSize(sample_count); + } + dglv2->dg->run(dglv2->pos, dglv2->buffer, sample_count); - pos += sample_count; + dglv2->pos += sample_count; } void deactivate(LV2_Handle instance) { - // We don't really need to do anything here. DGLV2 *dglv2 = (DGLV2 *)instance; dglv2->dg->stop(); } |