From af0420edfa45c4058c6ee0d1141c2c03ffd7936a Mon Sep 17 00:00:00 2001 From: Kevin <68612569+diyelectromusic@users.noreply.github.com> Date: Sat, 13 May 2023 11:16:07 +0100 Subject: [PATCH 1/3] Issue491 fix - Bank number auto-switching and bank number skipping issues in UI (#492) * Fix for bank numbering to ensure voice/bank wrap around works as expected for first and last banks from the UI. * Also as part of #491 fixes bank selection menu when selecting between skipped bank numbers up or down. --- src/sysexfileloader.cpp | 10 +++++----- src/uimenu.cpp | 13 ++----------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/sysexfileloader.cpp b/src/sysexfileloader.cpp index d72bc7de..ea5ba5c6 100644 --- a/src/sysexfileloader.cpp +++ b/src/sysexfileloader.cpp @@ -99,7 +99,7 @@ void CSysExFileLoader::Load (bool bHeaderlessSysExVoices) { LoadBank(m_DirName.c_str (), pEntry->d_name, bHeaderlessSysExVoices, 0); } - LOGDBG ("%u Banks loaded. Highest Bank loaded: #%u", m_nBanksLoaded, m_nNumHighestBank); + LOGDBG ("%u Banks loaded. Highest Bank loaded: #%u", m_nBanksLoaded, m_nNumHighestBank+1); closedir (pDirectory); } @@ -189,10 +189,10 @@ void CSysExFileLoader::LoadBank (const char * sDirName, const char * sBankName, //LOGDBG ("Bank #%u successfully loaded", nBank); m_BankFileName[nBankIdx] = sBankName; - if (nBank > m_nNumHighestBank) + if (nBankIdx > m_nNumHighestBank) { // This is the bank ID of the highest loaded bank - m_nNumHighestBank = nBank; + m_nNumHighestBank = nBankIdx; } m_nBanksLoaded++; bBankLoaded = true; @@ -221,10 +221,10 @@ void CSysExFileLoader::LoadBank (const char * sDirName, const char * sBankName, m_pVoiceBank[nBankIdx]->StatusEnd = 0xF7; m_BankFileName[nBankIdx] = sBankName; - if (nBank > m_nNumHighestBank) + if (nBankIdx > m_nNumHighestBank) { // This is the bank ID of the highest loaded bank - m_nNumHighestBank = nBank; + m_nNumHighestBank = nBankIdx; } bBankLoaded = true; m_nBanksLoaded++; diff --git a/src/uimenu.cpp b/src/uimenu.cpp index 035822f7..360a5b0b 100644 --- a/src/uimenu.cpp +++ b/src/uimenu.cpp @@ -563,7 +563,6 @@ void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event) void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event) { unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; - int nHighestBank = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNumHighestBank(); int nValue = pUIMenu->m_pMiniDexed->GetTGParameter (CMiniDexed::TGParameterProgram, nTG); @@ -578,11 +577,7 @@ void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event) // Switch down a voice bank and set to the last voice nValue = CSysExFileLoader::VoicesPerBank-1; int nVB = pUIMenu->m_pMiniDexed->GetTGParameter(CMiniDexed::TGParameterVoiceBank, nTG); - if (--nVB < 0) - { - // Wrap around to last loaded bank - nVB = nHighestBank; - } + nVB = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNextBankDown(nVB); pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterVoiceBank, nVB, nTG); } pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterProgram, nValue, nTG); @@ -594,11 +589,7 @@ void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event) // Switch up a voice bank and reset to voice 0 nValue = 0; int nVB = pUIMenu->m_pMiniDexed->GetTGParameter(CMiniDexed::TGParameterVoiceBank, nTG); - if (++nVB > (int) nHighestBank) - { - // Wrap around to first bank - nVB = 0; - } + nVB = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNextBankUp(nVB); pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterVoiceBank, nVB, nTG); } pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterProgram, nValue, nTG); From bb50d022f38b640512af9da15bd1d8cf1d73f53c Mon Sep 17 00:00:00 2001 From: Kevin <68612569+diyelectromusic@users.noreply.github.com> Date: Sat, 13 May 2023 11:27:51 +0100 Subject: [PATCH 2/3] Fix for Issue #471 Ignore MIDI All Notes Off in Omni mode (#493) Co-authored-by: probonopd --- src/mididevice.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mididevice.cpp b/src/mididevice.cpp index 64fc009a..e1f983ca 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -324,7 +324,10 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign break; case MIDI_CC_ALL_NOTES_OFF: - if (!m_pConfig->GetIgnoreAllNotesOff ()) + // As per "MIDI 1.0 Detailed Specification" v4.2 + // From "ALL NOTES OFF" states: + // "Receivers should ignore an All Notes Off message while Omni is on (Modes 1 & 2)" + if (!m_pConfig->GetIgnoreAllNotesOff () && m_ChannelMap[nTG] != OmniMode) { m_pSynthesizer->notesOff (pMessage[2], nTG); } From 87dc5ce43213ccf9a3a5813c72cbafcb0c4bed8b Mon Sep 17 00:00:00 2001 From: Kevin <68612569+diyelectromusic@users.noreply.github.com> Date: Sun, 14 May 2023 14:29:47 +0100 Subject: [PATCH 3/3] Issue470 fix - Performance file bounds checking and error handling (#494) * Fix for Issue #470 to introduce bounds checking on loading performance files and when saving a new performance. * Reduce number of performances to 256 and include some better error handling for when there are no performances free for saving. --- src/minidexed.cpp | 2 +- src/performanceconfig.cpp | 56 +++++++++++++++++++++++++++++---------- src/performanceconfig.h | 4 ++- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 0bb7c149..fafeff81 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -1474,7 +1474,7 @@ bool CMiniDexed::DoSetNewPerformance (void) bool CMiniDexed::SavePerformanceNewFile () { - m_bSavePerformanceNewFile = m_PerformanceConfig.GetInternalFolderOk(); + m_bSavePerformanceNewFile = m_PerformanceConfig.GetInternalFolderOk() && m_PerformanceConfig.CheckFreePerformanceSlot(); return m_bSavePerformanceNewFile; } diff --git a/src/performanceconfig.cpp b/src/performanceconfig.cpp index 72490035..853ccf51 100644 --- a/src/performanceconfig.cpp +++ b/src/performanceconfig.cpp @@ -20,10 +20,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // +#include #include "performanceconfig.h" #include "mididevice.h" #include -#include +#include + +LOGMODULE ("Performance"); CPerformanceConfig::CPerformanceConfig (FATFS *pFileSystem) : m_Properties ("performance.ini", pFileSystem) @@ -747,8 +750,27 @@ bool CPerformanceConfig::GetInternalFolderOk() return nInternalFolderOk; } +bool CPerformanceConfig::CheckFreePerformanceSlot(void) +{ + if (nLastPerformance < NUM_PERFORMANCES) + { + // There is a free slot... + return true; + } + else + { + return false; + } +} + bool CPerformanceConfig::CreateNewPerformanceFile(void) { + if (nLastPerformance >= NUM_PERFORMANCES) { + // No space left for new performances + LOGWARN ("No space left for new performance"); + return false; + } + std::string sPerformanceName = NewPerformanceName; NewPerformanceName=""; nActualPerformance=nLastPerformance; @@ -829,19 +851,23 @@ bool CPerformanceConfig::ListPerformances() Result = f_findfirst (&Directory, &FileInfo, "SD:/" PERFORMANCE_DIR, "*.ini"); for (unsigned i = 0; Result == FR_OK && FileInfo.fname[0]; i++) { - if (!(FileInfo.fattrib & (AM_HID | AM_SYS))) - { - std::string FileName = FileInfo.fname; - size_t nLen = FileName.length(); - if ( nLen > 8 && nLen <26 && strcmp(FileName.substr(6,1).c_str(), "_")==0) - { - nPIndex=stoi(FileName.substr(0,6)); - if(nPIndex > nLastFileIndex) - { - nLastFileIndex=nPIndex; - } - - m_nPerformanceFileName[nLastPerformance++]= FileName; + if (nLastPerformance >= NUM_PERFORMANCES) { + LOGNOTE ("Skipping performance %s", FileInfo.fname); + } else { + if (!(FileInfo.fattrib & (AM_HID | AM_SYS))) + { + std::string FileName = FileInfo.fname; + size_t nLen = FileName.length(); + if ( nLen > 8 && nLen <26 && strcmp(FileName.substr(6,1).c_str(), "_")==0) + { + nPIndex=stoi(FileName.substr(0,6)); + if(nPIndex > nLastFileIndex) + { + nLastFileIndex=nPIndex; + } + + m_nPerformanceFileName[nLastPerformance++]= FileName; + } } } @@ -854,6 +880,8 @@ bool CPerformanceConfig::ListPerformances() } } + LOGNOTE ("Number of Performances: %d", nLastPerformance); + return nInternalFolderOk; } diff --git a/src/performanceconfig.h b/src/performanceconfig.h index ec325985..c151c7aa 100644 --- a/src/performanceconfig.h +++ b/src/performanceconfig.h @@ -28,6 +28,7 @@ #include #define NUM_VOICE_PARAM 156 #define PERFORMANCE_DIR "performance" +#define NUM_PERFORMANCES 256 class CPerformanceConfig // Performance configuration { @@ -131,6 +132,7 @@ class CPerformanceConfig // Performance configuration std::string GetNewPerformanceDefaultName(void); void SetNewPerformanceName(std::string nName); bool DeletePerformance(unsigned nID); + bool CheckFreePerformanceSlot(void); private: CPropertiesFatFsFile m_Properties; @@ -168,7 +170,7 @@ class CPerformanceConfig // Performance configuration unsigned nLastFileIndex; unsigned nActualPerformance = 0; //unsigned nMenuSelectedPerformance = 0; - std::string m_nPerformanceFileName[1024]; + std::string m_nPerformanceFileName[NUM_PERFORMANCES]; FATFS *m_pFileSystem; bool nInternalFolderOk=false;