Fix Issue #338 - implement wraparound for voices and banks and limit bank select to loaded banks only. (#392)

Co-authored-by: diyelectromusic <68612569+diyelectromusic@users.noreply.github.com>
pull/420/head
probonopd 2 years ago committed by GitHub
parent 484671de86
commit 4a8241226d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/sysexfileloader.cpp
  2. 3
      src/sysexfileloader.h
  3. 26
      src/uimenu.cpp

@ -65,6 +65,7 @@ CSysExFileLoader::CSysExFileLoader (const char *pDirName)
: m_DirName (pDirName) : m_DirName (pDirName)
{ {
m_DirName += "/voice"; m_DirName += "/voice";
m_nNumLoadedBanks = 0;
for (unsigned i = 0; i <= MaxVoiceBankID; i++) for (unsigned i = 0; i <= MaxVoiceBankID; i++)
{ {
@ -82,7 +83,9 @@ CSysExFileLoader::~CSysExFileLoader (void)
void CSysExFileLoader::Load (void) void CSysExFileLoader::Load (void)
{ {
DIR *pDirectory = opendir (m_DirName.c_str ()); m_nNumLoadedBanks = 0;
DIR *pDirectory = opendir (m_DirName.c_str ());
if (!pDirectory) if (!pDirectory)
{ {
LOGWARN ("Directory %s not found", m_DirName.c_str ()); LOGWARN ("Directory %s not found", m_DirName.c_str ());
@ -138,6 +141,7 @@ void CSysExFileLoader::Load (void)
LOGDBG ("Bank #%u successfully loaded", nBank); LOGDBG ("Bank #%u successfully loaded", nBank);
m_BankFileName[nBank] = pEntry->d_name; m_BankFileName[nBank] = pEntry->d_name;
m_nNumLoadedBanks++;
} }
else else
{ {
@ -184,6 +188,11 @@ std::string CSysExFileLoader::GetBankName (unsigned nBankID)
return "NO NAME"; return "NO NAME";
} }
unsigned CSysExFileLoader::GetNumLoadedBanks (void)
{
return m_nNumLoadedBanks;
}
void CSysExFileLoader::GetVoice (unsigned nBankID, unsigned nVoiceID, uint8_t *pVoiceData) void CSysExFileLoader::GetVoice (unsigned nBankID, unsigned nVoiceID, uint8_t *pVoiceData)
{ {
if ( nBankID <= MaxVoiceBankID if ( nBankID <= MaxVoiceBankID

@ -57,6 +57,7 @@ public:
void Load (void); void Load (void);
std::string GetBankName (unsigned nBankID); // 0 .. 127 std::string GetBankName (unsigned nBankID); // 0 .. 127
unsigned GetNumLoadedBanks (); // 0 .. MaxVoiceBankID
void GetVoice (unsigned nBankID, // 0 .. 127 void GetVoice (unsigned nBankID, // 0 .. 127
unsigned nVoiceID, // 0 .. 31 unsigned nVoiceID, // 0 .. 31
@ -68,6 +69,8 @@ private:
private: private:
std::string m_DirName; std::string m_DirName;
unsigned m_nNumLoadedBanks;
TVoiceBank *m_pVoiceBank[MaxVoiceBankID+1]; TVoiceBank *m_pVoiceBank[MaxVoiceBankID+1];
std::string m_BankFileName[MaxVoiceBankID+1]; std::string m_BankFileName[MaxVoiceBankID+1];

@ -486,6 +486,7 @@ void CUIMenu::EditGlobalParameter (CUIMenu *pUIMenu, TMenuEvent Event)
void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event) void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event)
{ {
unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1];
int nLoadedBanks = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNumLoadedBanks();
int nValue = pUIMenu->m_pMiniDexed->GetTGParameter (CMiniDexed::TGParameterVoiceBank, nTG); int nValue = pUIMenu->m_pMiniDexed->GetTGParameter (CMiniDexed::TGParameterVoiceBank, nTG);
@ -504,9 +505,9 @@ void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event)
break; break;
case MenuEventStepUp: case MenuEventStepUp:
if (++nValue > (int) CSysExFileLoader::MaxVoiceBankID) if (++nValue > (int) nLoadedBanks-1)
{ {
nValue = CSysExFileLoader::MaxVoiceBankID; nValue = nLoadedBanks-1;
} }
pUIMenu->m_pMiniDexed->SetTGParameter ( pUIMenu->m_pMiniDexed->SetTGParameter (
CMiniDexed::TGParameterVoiceBank, nValue, nTG); CMiniDexed::TGParameterVoiceBank, nValue, nTG);
@ -536,6 +537,7 @@ void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event)
void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event) void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event)
{ {
unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1];
int nLoadedBanks = pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetNumLoadedBanks();
int nValue = pUIMenu->m_pMiniDexed->GetTGParameter (CMiniDexed::TGParameterProgram, nTG); int nValue = pUIMenu->m_pMiniDexed->GetTGParameter (CMiniDexed::TGParameterProgram, nTG);
@ -547,7 +549,15 @@ void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event)
case MenuEventStepDown: case MenuEventStepDown:
if (--nValue < 0) if (--nValue < 0)
{ {
nValue = 0; // 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 = nLoadedBanks-1;
}
pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterVoiceBank, nVB, nTG);
} }
pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterProgram, nValue, nTG); pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterProgram, nValue, nTG);
break; break;
@ -555,7 +565,15 @@ void CUIMenu::EditProgramNumber (CUIMenu *pUIMenu, TMenuEvent Event)
case MenuEventStepUp: case MenuEventStepUp:
if (++nValue > (int) CSysExFileLoader::VoicesPerBank-1) if (++nValue > (int) CSysExFileLoader::VoicesPerBank-1)
{ {
nValue = CSysExFileLoader::VoicesPerBank-1; // 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)
{
// Wrap around to first bank
nVB = 0;
}
pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterVoiceBank, nVB, nTG);
} }
pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterProgram, nValue, nTG); pUIMenu->m_pMiniDexed->SetTGParameter (CMiniDexed::TGParameterProgram, nValue, nTG);
break; break;

Loading…
Cancel
Save