From ce6f3348fa9e176d82b37f2829678106fe466072 Mon Sep 17 00:00:00 2001 From: probonopd Date: Mon, 14 Apr 2025 22:35:25 +0200 Subject: [PATCH] setOperatorMask --- src/minidexed.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 1236923..72edb6f 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -1672,7 +1672,7 @@ void CMiniDexed::setBreathControllerTarget(uint8_t target, uint8_t nTG) assert (m_pTG[nTG]); - m_nBreathControlTarget[nTG]=target; + m_nBreathControlTarget[nTG] = target; m_pTG[nTG]->setBreathControllerTarget(constrain(target, 0, 7)); m_pTG[nTG]->ControllersRefresh(); @@ -2185,17 +2185,28 @@ unsigned CMiniDexed::getModController (unsigned controller, unsigned parameter, } -void CMiniDexed::setOperatorMute(uint8_t operatorIndex, unsigned nTG) { - if (nTG >= CConfig::AllToneGenerators || operatorIndex >= 6) { - LOGERR("Invalid tone generator or operator index: TG=%u, Operator=%u", nTG, operatorIndex); +void CMiniDexed::setOperatorMask(uint8_t operatorMask, unsigned nTG) { + if (nTG >= CConfig::AllToneGenerators) { + LOGERR("Invalid tone generator: TG=%u", nTG); return; } - // Toggle the operator mask for the specified operator - m_uchOPMask[nTG] ^= (1 << operatorIndex); - - LOGDBG("Operator %u mute toggled for TG %u. New mask: 0x%02X", operatorIndex, nTG, m_uchOPMask[nTG]); + // According to Yamaha DX7/TX SysEx format: + // Bit 0 = OP6, Bit 1 = OP5, Bit 2 = OP4, Bit 3 = OP3, Bit 4 = OP2, Bit 5 = OP1 + // For MiniDexed: Bit 0 = OP1, Bit 1 = OP2, etc. - need to reverse the bit order to match + + uint8_t reversedMask = 0; + for (int i = 0; i < 6; i++) { + if (operatorMask & (1 << i)) { + reversedMask |= (1 << (5 - i)); + } + } + + m_uchOPMask[nTG] = reversedMask; + LOGDBG("Set operator mask for TG %u: Yamaha=0x%02X, Reversed=0x%02X", nTG, operatorMask, reversedMask); // Apply the updated operator mask to the tone generator - m_pTG[nTG]->setOPAll(m_uchOPMask[nTG]); + if (nTG < m_nToneGenerators) { + m_pTG[nTG]->setOPAll(m_uchOPMask[nTG]); + } }