From 377b7bb983b90862c6794adb1b71cd81d119c4c6 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 17 Jan 2022 11:28:24 +0000 Subject: [PATCH] Added SYSEX function/parameter change. Currently only saving the state... --- src/dexed.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/dexed.h | 3 +- 2 files changed, 114 insertions(+), 4 deletions(-) diff --git a/src/dexed.cpp b/src/dexed.cpp index d51a229..fb22083 100644 --- a/src/dexed.cpp +++ b/src/dexed.cpp @@ -546,8 +546,117 @@ void Dexed::GetSamples(uint32_t n_samples, float* buffer) } } -bool Dexed::ProcessSysEx(const uint8_t *buf, uint32_t buf_size) { - ; +bool Dexed::ProcessSysEx(const uint8_t *sysex, uint32_t len) { + if (sysex[len - 1] != 0xf7) + { + TRACE("SysEx end status byte not detected."); + return(false); + } + + TRACE("SysEx ID=%d",sysex[1]); + TRACE("SysEx substatus=%d",(sysex[2] & 0x70) >> 4); + + if (len == 7) + { + // parameter change + if (((sysex[3] & 0x7c) >> 2) != 0 && ((sysex[3] & 0x7c) >> 2) != 2) + { + TRACE("Not a SysEx parameter or function parameter change: %d", sysex[3] & 0x7c); + return(false); + } + else + return(ProcessSysExParameterChange(sysex,len)); + } + + return(true); +} + +bool Dexed::ProcessSysExParameterChange(const uint8_t *sysex, uint32_t len) { + if ((sysex[3] & 0x7c) >> 2 == 0) + return(ProcessSysExVoiceParameterChange(sysex,len)); + else if ((sysex[3] & 0x7c) >> 2 == 2) + return(ProcessSysExFunctionParameterChange(sysex,len)); + + return(true); +} + +bool Dexed::ProcessSysExVoiceParameterChange(const uint8_t *sysex, uint32_t len) { + sysex[4] &= 0x7f; + sysex[5] &= 0x7f; + + TRACE("SysEx Voice parameter: #%d = %d",sysex[4] + (sysex[3] & 0x03) * 128, sysex[5]); + + onParam(sysex[4] + ((sysex[3] & 0x03) * 128), sysex[5]); + + return(true); +} + +bool Dexed::ProcessSysExFunctionParameterChange(const uint8_t *sysex, uint32_t len) { + sysex[4] &= 0x7f; + sysex[5] &= 0x7f; + + TRACE("SysEx Function parameter: #%d = %d",sysex[4], sysex[5]); + + switch (sysex[4]) + { + case 65: + controllers.values_[kControllerPitchRange] = sysex[5]; + break; + case 66: + controllers.values_[kControllerPitchStep] = sysex[5]; + break; + case 67: + portamento_mode = sysex[5]; + break; + case 68: + portamento_glissando = sysex[5]; + break; + case 69: + controllers.portamento_cc = = sysex[5]; +if (portamento_time > 0) + controllers.portamento_enable_cc = true; + else + controllers.portamento_enable_cc = false; + + controllers.values_[kControllerPortamentoGlissando] = portamento_glissando; + break; + case 70: + controllers.wheel.setRange(sysex[5]); + break; + case 71: + controllers.wheel.setTarget(sysex[5]); + break; + case 72: + controllers.foot.setRange(sysex[5]); + break; + case 73: + controllers.foot.setTarget(sysex[5]); + break; + case 74: + controllers.breath.setRange(sysex[5]); + break; + case 75: + controllers.breath.setTarget(sysex[5]); + break; + case 76: + controllers.at.setRange(sysex[5]); + break; + case 77: + controllers.at.setTarget(sysex[5]); + break; + default: + onParam(sysex[4], sysex[5]); + break; + } + controllers.refresh(); + } + else + { + TRACE("Unknown SysEx voice or function: #%d = %d",sysex[4],sysex[5]); + return(false); + } + + return(true); } bool Dexed::ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size) { @@ -631,7 +740,7 @@ bool Dexed::ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size) { // sysex TRACE("MIDI sysex event: cmd=%d, size=%d",buf[0],size); if(buf[1]==0x43) - ProcessSysEx(buf, size); + ProcessSysEx(buf, buf_size); else TRACE("Ignoring MIDI sysex ID (ID=%d): unknwon",buf[1]); break; diff --git a/src/dexed.h b/src/dexed.h index 885efa7..8421368 100644 --- a/src/dexed.h +++ b/src/dexed.h @@ -92,7 +92,8 @@ class Dexed : public lvtk::Synth VoiceStatus voiceStatus; protected: - bool ProcessSysEx(const uint8_t *buf, uint32_t buf_size); + bool ProcessSysEx(const uint8_t *sysex, uint32_t len); + bool ProcessSysExParameterChange(const uint8_t *sysex, uint32_t len); bool ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size); void onParam(uint8_t param_num,float param_val); void keyup(uint8_t pitch);