From 6740c8f3cb24ce6b00f33ba0fafddaf50317f825 Mon Sep 17 00:00:00 2001 From: Hanspeter Portner Date: Tue, 10 Aug 2021 22:41:09 +0200 Subject: [PATCH] dsp: properly parse 14bit MIDI messages. --- VERSION | 2 +- mystery_curve.c | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 74799d8..e164af0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.127 +0.1.141 diff --git a/mystery_curve.c b/mystery_curve.c index b199540..d7e6a85 100644 --- a/mystery_curve.c +++ b/mystery_curve.c @@ -148,6 +148,7 @@ struct _plughandle_t { uint16_t rpn_lsb [0x10]; uint16_t rpn_msb [0x10]; uint16_t data_lsb [0x10]; + uint16_t data_msb [0x10]; float bend [0x10]; float range [0x10]; bool sustain [0x10]; @@ -613,6 +614,19 @@ _update_frequency(plughandle_t *handle, uint8_t chn) } } +static inline void +_update_bend_range(plughandle_t *handle, uint8_t chn) +{ + if( (handle->rpn_msb[chn] == 0x0) && (handle->rpn_lsb[chn] == 0x0) ) + { + const uint8_t semi = handle->data_msb[chn]; + const uint8_t cent = handle->data_lsb[chn]; + + handle->range[chn] = (float)semi + cent*0.01f; + _update_frequency(handle, chn); + } +} + static void _midi(plughandle_t *handle, uint32_t size, const uint8_t *msg) { @@ -721,18 +735,14 @@ _midi(plughandle_t *handle, uint32_t size, const uint8_t *msg) case LV2_MIDI_CTL_LSB_DATA_ENTRY: { handle->data_lsb[chn] = val; + + _update_bend_range(handle, chn); } break; case LV2_MIDI_CTL_MSB_DATA_ENTRY: { - // pitch-bend range - if( (handle->rpn_msb[chn] == 0x0) && (handle->rpn_lsb[chn] == 0x0) ) - { - const uint8_t semi = val; - const uint8_t cent = handle->data_lsb[chn]; + handle->data_msb[chn] = val; - handle->range[chn] = (float)semi + cent*0.01f; - _update_frequency(handle, chn); - } + _update_bend_range(handle, chn); } break; } } break; -- 2.38.5