From 1f5d6935049fc0dd5a4dc257b84b36d2048f2d83 Mon Sep 17 00:00:00 2001 From: Hanspeter Portner Date: Sun, 15 Aug 2021 16:48:30 +0200 Subject: [PATCH] dsp: add support for channel pressure and MPE+ LSB. --- VERSION | 2 +- jit_dsp.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index b6689b5..044b095 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.421 +0.1.423 diff --git a/jit_dsp.c b/jit_dsp.c index f3ce6dd..f0cf23a 100644 --- a/jit_dsp.c +++ b/jit_dsp.c @@ -142,6 +142,7 @@ struct _plughandle_t { uint16_t gain [0x10]; uint16_t pressure [0x10]; uint16_t timbre [0x10]; + uint8_t mpe_plus_lsb [0x10]; float bend [0x10]; float range [0x10]; bool sustain [0x10]; @@ -846,15 +847,49 @@ _voice_send_event(plughandle_t *handle, dsp_t *dsp, jit_ev_type_t etype, } } +static inline void +_mpe_plus_lsb(plughandle_t *handle, uint8_t chn, uint16_t *tar) +{ + const uint8_t lsb = handle->mpe_plus_lsb[chn]; + + if(lsb) + { + *tar &= ~0x7f; + *tar |= lsb; + } + + handle->mpe_plus_lsb[chn] = 0x0; // always clear register after usage +} + static void -_handle_midi(plughandle_t *handle, dsp_t *dsp, - int64_t frames __attribute__((unused)), const uint8_t *msg, uint32_t len) +_handle_midi_2(plughandle_t *handle, dsp_t *dsp, + int64_t frames __attribute__((unused)), const uint8_t *msg) { - if(len < 3) + const uint8_t cmd = msg[0] & 0xf0; + const uint8_t chn = msg[0] & 0x0f; + + if(!dsp) { return; } + switch(cmd) + { + case LV2_MIDI_MSG_CHANNEL_PRESSURE: + { + handle->pressure[chn] = msg[1] << 7; + + _mpe_plus_lsb(handle, chn, &handle->pressure[chn]); + + _update_pressure(handle, dsp, chn); + } break; + } +} + +static void +_handle_midi_3(plughandle_t *handle, dsp_t *dsp, + int64_t frames __attribute__((unused)), const uint8_t *msg) +{ const uint8_t cmd = msg[0] & 0xf0; const uint8_t chn = msg[0] & 0x0f; @@ -1019,6 +1054,8 @@ _handle_midi(plughandle_t *handle, dsp_t *dsp, handle->pressure[chn] &= ~0x3f80; handle->pressure[chn] |= val << 7; + _mpe_plus_lsb(handle, chn, &handle->pressure[chn]); + _update_pressure(handle, dsp, chn); } break; case LV2_MIDI_CTL_SC5_BRIGHTNESS | 0x20: @@ -1033,13 +1070,36 @@ _handle_midi(plughandle_t *handle, dsp_t *dsp, handle->timbre[chn] &= ~0x3f80; handle->timbre[chn] |= val << 7; + _mpe_plus_lsb(handle, chn, &handle->timbre[chn]); + _update_timbre(handle, dsp, chn); } break; + case 0x57: // MPE+ LSB according to Haken Audio + { + handle->mpe_plus_lsb[chn] = val; + } break; } } break; } } +static void +_handle_midi(plughandle_t *handle, dsp_t *dsp, + int64_t frames, const uint8_t *msg, uint32_t len) +{ + switch(len) + { + case 2: + { + _handle_midi_2(handle, dsp, frames, msg); + } break; + case 3: + { + _handle_midi_3(handle, dsp, frames, msg); + } break; + } +} + static void run(LV2_Handle instance, uint32_t nsamples) { -- 2.38.5