From 91f1c291c3223f43d51494393b9057fea530eeab Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Thu, 1 Feb 2024 04:39:13 +0100 Subject: [PATCH] daisy seed midi cc mapping --- templates/daisy-seed/src/data.h | 10 ++++++++++ templates/daisy-seed/src/main.cpp | 27 ++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/templates/daisy-seed/src/data.h b/templates/daisy-seed/src/data.h index b027cb6..39093ec 100644 --- a/templates/daisy-seed/src/data.h +++ b/templates/daisy-seed/src/data.h @@ -40,4 +40,14 @@ static struct { {{~}} }; +# if MIDI_BUS_IN >= 0 + +# define HAS_MIDI_CC_MAPS {{=it.daisy_seed.midiCCMaps ? 1 : 0}} + +# if HAS_MIDI_CC_MAPS +static int midi_cc_maps[NUM_PARAMETERS] = { {{~it.daisy_seed.midiCCMaps :p}}{{=p}} ,{{~}} }; +# endif + +# endif + #endif diff --git a/templates/daisy-seed/src/main.cpp b/templates/daisy-seed/src/main.cpp index d36dd5b..76add43 100644 --- a/templates/daisy-seed/src/main.cpp +++ b/templates/daisy-seed/src/main.cpp @@ -46,13 +46,15 @@ static float parameterAdjust(int i, float v) { return clampf(v, param_data[i].min, param_data[i].max); } +static void setParameter(int i, float v) { + plugin_set_parameter(&instance, i, parameterAdjust(i, v)); +} + static void readADCs() { for (int i = 0, j = 0; i < NUM_PARAMETERS; i++) { if (param_data[i].out || param_data[i].pin < 0) continue; - float v = hardware.adc.GetFloat(j); - v = parameterAdjust(i, parameterMap(i, v)); - plugin_set_parameter(&instance, i, v); + setParameter(i, parameterMap(i, hardware.adc.GetFloat(j))); j++; } } @@ -127,13 +129,10 @@ int main() { plugin_mem_set(&instance, (void *)0xc0000000); #if NUM_PARAMETERS > 0 - for (int i = 0, j = 0; i < NUM_PARAMETERS; i++) { + for (int i = 0; i < NUM_PARAMETERS; i++) { if (param_data[i].out) continue; - float v = param_data[i].def; - v = parameterAdjust(i, parameterMap(i, v)); - plugin_set_parameter(&instance, i, v); - j++; + setParameter(i, param_data[i].def); } #endif @@ -167,7 +166,13 @@ int main() { data[0] = 0xa0; break; case ControlChange: - //TODO: CC to param mapping +# if NUM_PARAMETERS > 0 && HAS_MIDI_CC_MAPS + for (int i = 0; i < NUM_PARAMETERS; i++) + if (midi_cc_maps[i] == data[1]) { + setParameter(i, (1.f / 127.f) * data[2]); + goto loopNext; + } +# endif case ChannelMode: data[0] = 0xb0; break; @@ -188,6 +193,10 @@ int main() { data[1] = ev.data[1]; data[2] = ev.data[2]; plugin_midi_msg_in(&instance, MIDI_BUS_IN, data); +# if NUM_PARAMETERS > 0 && HAS_MIDI_CC_MAPS +loopNext: + (void)data; // something to make this file build +# endif } #else const float avgLoad = loadMeter.GetAvgCpuLoad();