From 8bdfa4a26e1fe86e23f09801c91b57550a0a821c Mon Sep 17 00:00:00 2001 From: Kevin <68612569+diyelectromusic@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:37:02 +0100 Subject: [PATCH] Ensure msg only handled once by the first TG with a matching receiving MIDI channel. --- src/mididevice.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mididevice.cpp b/src/mididevice.cpp index 13f87b7..52ad624 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -258,7 +258,8 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign } // Process MIDI for each active Tone Generator - for (unsigned nTG = 0; nTG < m_pConfig->GetToneGenerators(); nTG++) + bool bSystemCCHandled = false; + for (unsigned nTG = 0; nTG < m_pConfig->GetToneGenerators() && !bSystemCCHandled; nTG++) { if (ucStatus == MIDI_SYSTEM_EXCLUSIVE_BEGIN) { @@ -398,15 +399,18 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign if (m_pConfig->GetToneGenerators() >= 8) { // This only makes sense when there are at least 8 TGs. // Note: If more than 8 TGs then only 8 TGs are controllable this way. - for (unsigned tg=0; tg<8; tg++) { + for (unsigned tg=0; tg<8 && !bSystemCCHandled; tg++) { if (m_nMIDISystemCCVol != 0) { if (pMessage[1] == MIDISystemCCMap[m_nMIDISystemCCVol][tg]) { m_pSynthesizer->SetVolume (pMessage[2], tg); + // Only need to process this once per MIDI msg for the first TG to receive it + bSystemCCHandled = true; } } if (m_nMIDISystemCCPan != 0) { if (pMessage[1] == MIDISystemCCMap[m_nMIDISystemCCPan][tg]) { m_pSynthesizer->SetPan (pMessage[2], tg); + bSystemCCHandled = true; } } if (m_nMIDISystemCCDetune != 0) { @@ -419,6 +423,7 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign { m_pSynthesizer->SetMasterTune (maplong (pMessage[2], 1, 127, -99, 99), tg); } + bSystemCCHandled = true; } } }