From 35fa23cbf139a87ba3dbcf1cce42b75a0a354cce Mon Sep 17 00:00:00 2001 From: diyelectromusic <68612569+diyelectromusic@users.noreply.github.com> Date: Sat, 1 Apr 2023 15:35:00 +0100 Subject: [PATCH] Implement option to allow MIDI Program Change messages to select aross four consecutive banks as discussed in Issue #391. Note: It does not check if consecutive banks are loaded. That is down to the user. The default is "enabled". --- src/config.cpp | 6 ++++++ src/config.h | 2 ++ src/minidexed.cpp | 25 +++++++++++++++++++++++-- src/minidexed.ini | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 44ac32f..c40d29a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -72,6 +72,7 @@ void CConfig::Load (void) m_bIgnoreAllNotesOff = m_Properties.GetNumber ("IgnoreAllNotesOff", 0) != 0; m_bMIDIAutoVoiceDumpOnPC = m_Properties.GetNumber ("MIDIAutoVoiceDumpOnPC", 1) != 0; m_bHeaderlessSysExVoices = m_Properties.GetNumber ("HeaderlessSysExVoices", 0) != 0; + m_bExpandPCAcrossBanks = m_Properties.GetNumber ("ExpandPCAcrossBanks", 1) != 0; m_bLCDEnabled = m_Properties.GetNumber ("LCDEnabled", 0) != 0; m_nLCDPinEnable = m_Properties.GetNumber ("LCDPinEnable", 4); @@ -185,6 +186,11 @@ bool CConfig::GetHeaderlessSysExVoices (void) const return m_bHeaderlessSysExVoices; } +bool CConfig::GetExpandPCAcrossBanks (void) const +{ + return m_bExpandPCAcrossBanks; +} + bool CConfig::GetLCDEnabled (void) const { return m_bLCDEnabled; diff --git a/src/config.h b/src/config.h index bc5e7c6..a316be8 100644 --- a/src/config.h +++ b/src/config.h @@ -78,6 +78,7 @@ public: bool GetIgnoreAllNotesOff (void) const; bool GetMIDIAutoVoiceDumpOnPC (void) const; // true if not specified bool GetHeaderlessSysExVoices (void) const; // false if not specified + bool GetExpandPCAcrossBanks (void) const; // true if not specified // HD44780 LCD // GPIO pin numbers are chip numbers, not header positions @@ -159,6 +160,7 @@ private: bool m_bIgnoreAllNotesOff; bool m_bMIDIAutoVoiceDumpOnPC; bool m_bHeaderlessSysExVoices; + bool m_bExpandPCAcrossBanks; bool m_bLCDEnabled; unsigned m_nLCDPinEnable; diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 6acda43..0bb7c14 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -413,13 +413,34 @@ void CMiniDexed::ProgramChange (unsigned nProgram, unsigned nTG) { assert (m_pConfig); - nProgram=constrain((int)nProgram,0,31); + unsigned nBankOffset; + bool bPCAcrossBanks = m_pConfig->GetExpandPCAcrossBanks(); + if (bPCAcrossBanks) + { + // Note: This doesn't actually change the bank in use + // but will allow PC messages of 0..127 + // to select across four consecutive banks of voices. + // + // So if the current bank = 5 then: + // PC 0-31 = Bank 5, Program 0-31 + // PC 32-63 = Bank 6, Program 0-31 + // PC 64-95 = Bank 7, Program 0-31 + // PC 96-127 = Bank 8, Program 0-31 + nProgram=constrain((int)nProgram,0,127); + nBankOffset = nProgram >> 5; + nProgram = nProgram % 32; + } + else + { + nBankOffset = 0; + nProgram=constrain((int)nProgram,0,31); + } assert (nTG < CConfig::ToneGenerators); m_nProgram[nTG] = nProgram; uint8_t Buffer[156]; - m_SysExFileLoader.GetVoice (m_nVoiceBankID[nTG], nProgram, Buffer); + m_SysExFileLoader.GetVoice (m_nVoiceBankID[nTG]+nBankOffset, nProgram, Buffer); assert (m_pTG[nTG]); m_pTG[nTG]->loadVoiceParameters (Buffer); diff --git a/src/minidexed.ini b/src/minidexed.ini index 2f5ce5b..27d622c 100644 --- a/src/minidexed.ini +++ b/src/minidexed.ini @@ -18,6 +18,7 @@ MIDIRXProgramChange=1 IgnoreAllNotesOff=0 MIDIAutoVoiceDumpOnPC=1 HeaderlessSysExVoices=0 +ExpandPCAcrossBanks=1 # HD44780 LCD LCDEnabled=1