From 9da8cf983209e12308018e9c856181067aeb5a67 Mon Sep 17 00:00:00 2001 From: skylark Date: Sun, 10 Apr 2022 14:50:00 -0700 Subject: [PATCH] Respect MIDI channel on control change mappings --- Source/PluginData.cpp | 5 +++++ Source/PluginEditor.cpp | 2 +- Source/PluginProcessor.cpp | 9 +++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/PluginData.cpp b/Source/PluginData.cpp index d1590a45..00131699 100644 --- a/Source/PluginData.cpp +++ b/Source/PluginData.cpp @@ -472,6 +472,11 @@ void DexedAudioProcessor::setStateInformation(const void* source, int sizeInByte int cc = ccMapping->getIntAttribute("cc", -1); String target = ccMapping->getStringAttribute("target", ""); if ( target.isNotEmpty() && cc != -1 ) { + if ((cc >> 8) == 0) { + // Simple migration logic lets old mappings without channel + // work on channel 1. + cc |= 1 << 8; + } for(int i=0;ilabel == target) { TRACE("mapping CC=%d to %s", cc, target.toRawUTF8()); diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index c1c73b5d..62aec997 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -392,7 +392,7 @@ public : this->target = target; setMessage("Mapping: " + String(target->label) + ", waiting for midi controller change (CC) message..."); addButton("CANCEL", -1); - editor->processor->lastCCUsed.setValue(-1); + editor->processor->lastCCUsed.setValue(-1); editor->processor->lastCCUsed.addListener(this); } diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index fe13fda5..8ce24561 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -403,16 +403,17 @@ void DexedAudioProcessor::processMidiMessage(const MidiMessage *msg) { } break; default: - TRACE("handle CC %d %d", ctrl, value); - if ( mappedMidiCC.contains(ctrl) ) { - Ctrl *linkedCtrl = mappedMidiCC[ctrl]; + TRACE("handle channel %d CC %d = %d", channel, ctrl, value); + int channel_cc = (channel << 8) | ctrl; + if ( mappedMidiCC.contains(channel_cc) ) { + Ctrl *linkedCtrl = mappedMidiCC[channel_cc]; // We are not publishing this in the DSP thread, moving that in the // event thread linkedCtrl->publishValueAsync((float) value / 127); } // this is used to notify the dialog that a CC value was received. - lastCCUsed.setValue(ctrl); + lastCCUsed.setValue(channel_cc); } } return;