From 3ee28866cf4a3cd5f0c228bcd6eb1b50782f07ef Mon Sep 17 00:00:00 2001 From: Hanspeter Portner Date: Tue, 10 Aug 2021 22:44:36 +0200 Subject: [PATCH] mixer: properly parse 14bit MIDI messages. --- VERSION | 2 +- patchmatrix_mixer.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 4e8f395..83b4730 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.26.0 +0.27.1 diff --git a/patchmatrix_mixer.c b/patchmatrix_mixer.c index 243062a..55cdd35 100644 --- a/patchmatrix_mixer.c +++ b/patchmatrix_mixer.c @@ -54,6 +54,21 @@ _jack_on_info_shutdown_cb(jack_status_t code, const char *reason, void *arg) _close(shm); } +static inline void +_midi_handle_data(mixer_app_t *mixer, uint8_t chn) +{ + const uint8_t nrpn_msb = mixer->nrpn[chn] >> 7; + const uint8_t nrpn_lsb = mixer->nrpn[chn] & 0x7f; + mixer_shm_t *shm = mixer->shm; + + if( (nrpn_msb < shm->nsources) && (nrpn_lsb < shm->nsinks) ) + { + const int32_t mBFS = (float)(mixer->data[chn] - 0x1fff)/0x2000 * 3600.f; + + atomic_store_explicit(&shm->jgains[nrpn_msb][nrpn_lsb], mBFS, memory_order_relaxed); + } +} + static inline void _midi_handle(mixer_app_t *mixer, jack_midi_event_t *ev) { @@ -84,22 +99,15 @@ _midi_handle(mixer_app_t *mixer, jack_midi_event_t *ev) { mixer->data[chn] &= 0x3f80; mixer->data[chn] |= val; + + _midi_handle_data(mixer, chn); } break; case 0x06: // DATA_MSB { mixer->data[chn] &= 0x7f; mixer->data[chn] |= (val << 7); - const uint8_t nrpn_msb = mixer->nrpn[chn] >> 7; - const uint8_t nrpn_lsb = mixer->nrpn[chn] & 0x7f; - mixer_shm_t *shm = mixer->shm; - - if( (nrpn_msb < shm->nsources) && (nrpn_lsb < shm->nsinks) ) - { - const int32_t mBFS = (float)(mixer->data[chn] - 0x1fff)/0x2000 * 3600.f; - - atomic_store_explicit(&shm->jgains[nrpn_msb][nrpn_lsb], mBFS, memory_order_relaxed); - } + _midi_handle_data(mixer, chn); } break; } } -- 2.38.5