From c487ffd28fe5383745020c8cbf20e88606f338c7 Mon Sep 17 00:00:00 2001 From: diyelectromusic <68612569+diyelectromusic@users.noreply.github.com> Date: Fri, 31 Mar 2023 20:03:55 +0100 Subject: [PATCH] Fix for Issue #457 - changed m_nNumLoadedBanks to be m_nNumHighestBank and updated functionality in menus accordingly. --- src/sysexfileloader.cpp | 14 +++++++++----- src/sysexfileloader.h | 4 ++-- src/uimenu.cpp | 12 ++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/sysexfileloader.cpp b/src/sysexfileloader.cpp index ffba8f5..82d7a49 100644 --- a/src/sysexfileloader.cpp +++ b/src/sysexfileloader.cpp @@ -65,7 +65,7 @@ CSysExFileLoader::CSysExFileLoader (const char *pDirName) : m_DirName (pDirName) { m_DirName += "/voice"; - m_nNumLoadedBanks = 0; + m_nNumHighestBank = 0; for (unsigned i = 0; i <= MaxVoiceBankID; i++) { @@ -83,7 +83,7 @@ CSysExFileLoader::~CSysExFileLoader (void) void CSysExFileLoader::Load (void) { - m_nNumLoadedBanks = 0; + m_nNumHighestBank = 0; DIR *pDirectory = opendir (m_DirName.c_str ()); if (!pDirectory) @@ -141,7 +141,11 @@ void CSysExFileLoader::Load (void) LOGDBG ("Bank #%u successfully loaded", nBank); m_BankFileName[nBank] = pEntry->d_name; - m_nNumLoadedBanks++; + if (nBank > m_nNumHighestBank) + { + // This is the bank ID of the highest loaded bank + m_nNumHighestBank = nBank; + } } else { @@ -188,9 +192,9 @@ std::string CSysExFileLoader::GetBankName (unsigned nBankID) return "NO NAME"; } -unsigned CSysExFileLoader::GetNumLoadedBanks (void) +unsigned CSysExFileLoader::GetNumHighestBank (void) { - return m_nNumLoadedBanks; + return m_nNumHighestBank; } void CSysExFileLoader::GetVoice (unsigned nBankID, unsigned nVoiceID, uint8_t *pVoiceData) diff --git a/src/sysexfileloader.h b/src/sysexfileloader.h index 5954bfe..9cd1ecc 100644 --- a/src/sysexfileloader.h +++ b/src/sysexfileloader.h @@ -57,7 +57,7 @@ public: void Load (void); std::string GetBankName (unsigned nBankID); // 0 .. 127 - unsigned GetNumLoadedBanks (); // 0 .. MaxVoiceBankID + unsigned GetNumHighestBank (); // 0 .. MaxVoiceBankID void GetVoice (unsigned nBankID, // 0 .. 127 unsigned nVoiceID, // 0 .. 31 @@ -69,7 +69,7 @@ private: private: std::string m_DirName; - unsigned m_nNumLoadedBanks; + unsigned m_nNumHighestBank; TVoiceBank *m_pVoiceBank[MaxVoiceBankID+1]; std::string m_BankFileName[MaxVoiceBankID+1]; diff --git a/src/uimenu.cpp b/src/uimenu.cpp index a1d44ce..ba41dcc 100644 --- a/src/uimenu.cpp +++ b/src/uimenu.cpp @@ -486,7 +486,7 @@ void CUIMenu::EditGlobalParameter (CUIMenu *pUIMenu, TMenuEvent Event) void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event) { unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; - int nLoadedBanks = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNumLoadedBanks(); + int nHighestBank = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNumHighestBank(); int nValue = pUIMenu->m_pMiniDexed->GetTGParameter (CMiniDexed::TGParameterVoiceBank, nTG); @@ -505,9 +505,9 @@ void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event) break; case MenuEventStepUp: - if (++nValue > (int) nLoadedBanks-1) + if (++nValue > (int) nHighestBank) { - nValue = nLoadedBanks-1; + nValue = nHighestBank; } pUIMenu->m_pMiniDexed->SetTGParameter ( CMiniDexed::TGParameterVoiceBank, nValue, nTG); @@ -537,7 +537,7 @@ void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event) void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event) { unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; - int nLoadedBanks = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNumLoadedBanks(); + int nHighestBank = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNumHighestBank(); int nValue = pUIMenu->m_pMiniDexed->GetTGParameter (CMiniDexed::TGParameterProgram, nTG); @@ -555,7 +555,7 @@ void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event) if (--nVB < 0) { // Wrap around to last loaded bank - nVB = nLoadedBanks-1; + nVB = nHighestBank; } pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterVoiceBank, nVB, nTG); } @@ -568,7 +568,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) nLoadedBanks-1) + if (++nVB > (int) nHighestBank) { // Wrap around to first bank nVB = 0;