Skip to content

Commit

Permalink
Make performance bank select asynchronous to MIDI and UI to stop corr…
Browse files Browse the repository at this point in the history
…uptions on loading performances.
  • Loading branch information
diyelectromusic committed Jan 14, 2024
1 parent 66409c6 commit 07cdafc
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 16 deletions.
71 changes: 63 additions & 8 deletions src/minidexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,
m_bSavePerformance (false),
m_bSavePerformanceNewFile (false),
m_bSetNewPerformance (false),
m_bSetNewPerformanceBank (false),
m_bSetFirstPerformance (false),
m_bDeletePerformance (false),
m_bLoadPerformanceBusy(false)
m_bLoadPerformanceBusy(false),
m_bLoadPerformanceBankBusy(false)
{
assert (m_pConfig);

Expand Down Expand Up @@ -302,14 +305,30 @@ void CMiniDexed::Process (bool bPlugAndPlayUpdated)
m_bSavePerformanceNewFile = false;
}

if (m_bSetNewPerformance && !m_bLoadPerformanceBusy)
if (m_bSetNewPerformanceBank && !m_bLoadPerformanceBusy && !m_bLoadPerformanceBankBusy)
{
DoSetNewPerformanceBank ();
if (m_nSetNewPerformanceBankID == GetActualPerformanceBankID())
{
m_bSetNewPerformanceBank = false;
}

// If there is no pending SetNewPerformance already, then see if we need to find the first performance to load
// NB: If called from the UI, then there will not be a SetNewPerformance, so load the first existing one.
// If called from MIDI, there will probably be a SetNewPerformance alongside the Bank select.
if (!m_bSetNewPerformance && m_bSetFirstPerformance)
{
DoSetFirstPerformance();
}
}

if (m_bSetNewPerformance && !m_bSetNewPerformanceBank && !m_bLoadPerformanceBusy && !m_bLoadPerformanceBankBusy)
{
DoSetNewPerformance ();
if (m_nSetNewPerformanceID == GetActualPerformanceID())
{
m_bSetNewPerformance = false;
}

}

if(m_bDeletePerformance)
Expand Down Expand Up @@ -419,7 +438,7 @@ void CMiniDexed::BankSelectPerformance (unsigned nBank)
{
// Only change if we have the bank loaded
m_nVoiceBankIDPerformance = nBank;
GetPerformanceConfig ()->SetPerformanceBank (nBank);
SetNewPerformanceBank (nBank);

m_UI.ParameterChanged ();
}
Expand Down Expand Up @@ -1566,6 +1585,16 @@ void CMiniDexed::SetActualPerformanceID(unsigned nID)
m_PerformanceConfig.SetActualPerformanceID(nID);
}

unsigned CMiniDexed::GetActualPerformanceBankID()
{
return m_PerformanceConfig.GetActualPerformanceBankID();
}

void CMiniDexed::SetActualPerformanceBankID(unsigned nBankID)
{
m_PerformanceConfig.SetActualPerformanceBankID(nBankID);
}

bool CMiniDexed::SetNewPerformance(unsigned nID)
{
m_bSetNewPerformance = true;
Expand All @@ -1574,11 +1603,18 @@ bool CMiniDexed::SetNewPerformance(unsigned nID)
return true;
}

unsigned CMiniDexed::SetFirstPerformance(void)
bool CMiniDexed::SetNewPerformanceBank(unsigned nBankID)
{
unsigned nID = m_PerformanceConfig.FindFirstPerformance();
SetNewPerformance(nID);
return nID;
m_bSetNewPerformanceBank = true;
m_nSetNewPerformanceBankID = nBankID;

return true;
}

void CMiniDexed::SetFirstPerformance(void)
{
m_bSetFirstPerformance = true;
return;
}

bool CMiniDexed::DoSetNewPerformance (void)
Expand All @@ -1602,6 +1638,25 @@ bool CMiniDexed::DoSetNewPerformance (void)
}
}

bool CMiniDexed::DoSetNewPerformanceBank (void)
{
m_bLoadPerformanceBankBusy = true;

unsigned nBankID = m_nSetNewPerformanceBankID;
m_PerformanceConfig.SetNewPerformanceBank(nBankID);

m_bLoadPerformanceBankBusy = false;
return true;
}

void CMiniDexed::DoSetFirstPerformance(void)
{
unsigned nID = m_PerformanceConfig.FindFirstPerformance();
SetNewPerformance(nID);
m_bSetFirstPerformance = false;
return;
}

bool CMiniDexed::SavePerformanceNewFile ()
{
m_bSavePerformanceNewFile = m_PerformanceConfig.GetInternalFolderOk() && m_PerformanceConfig.CheckFreePerformanceSlot();
Expand Down
11 changes: 10 additions & 1 deletion src/minidexed.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ class CMiniDexed
unsigned GetLastPerformanceBank();
unsigned GetActualPerformanceID();
void SetActualPerformanceID(unsigned nID);
unsigned GetActualPerformanceBankID();
void SetActualPerformanceBankID(unsigned nBankID);
bool SetNewPerformance(unsigned nID);
unsigned SetFirstPerformance(void);
bool SetNewPerformanceBank(unsigned nBankID);
void SetFirstPerformance(void);
void DoSetFirstPerformance(void);
bool SavePerformanceNewFile ();

bool DoSavePerformanceNewFile (void);
bool DoSetNewPerformance (void);
bool DoSetNewPerformanceBank (void);
bool GetPerformanceSelectToLoad(void);
bool SavePerformance (bool bSaveAsDeault);
unsigned GetPerformanceSelectChannel (void);
Expand Down Expand Up @@ -317,9 +322,13 @@ class CMiniDexed
bool m_bSavePerformanceNewFile;
bool m_bSetNewPerformance;
unsigned m_nSetNewPerformanceID;
bool m_bSetNewPerformanceBank;
unsigned m_nSetNewPerformanceBankID;
bool m_bSetFirstPerformance;
bool m_bDeletePerformance;
unsigned m_nDeletePerformanceID;
bool m_bLoadPerformanceBusy;
bool m_bLoadPerformanceBankBusy;
bool m_bSaveAsDeault;
};

Expand Down
18 changes: 15 additions & 3 deletions src/performanceconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ bool CPerformanceConfig::Init (void)
{
if (!m_PerformanceBankName[i].empty())
{
SetPerformanceBank(i);
SetNewPerformanceBank(i);
SetNewPerformance(0);
}
}
#endif
// Set to default initial bank
SetPerformanceBank(0);
SetNewPerformanceBank(0);
SetNewPerformance(0);

LOGNOTE ("Loaded Default Performance Bank - Last Performance: %d", m_nLastPerformance + 1); // Show "user facing" index
Expand Down Expand Up @@ -840,6 +840,17 @@ void CPerformanceConfig::SetActualPerformanceID(unsigned nID)
m_nActualPerformance = nID;
}

unsigned CPerformanceConfig::GetActualPerformanceBankID()
{
return m_nActualPerformanceBank;
}

void CPerformanceConfig::SetActualPerformanceBankID(unsigned nBankID)
{
assert (nBankID < NUM_PERFORMANCE_BANKS);
m_nActualPerformanceBank = nBankID;
}

bool CPerformanceConfig::GetInternalFolderOk()
{
return m_bPerformanceDirectoryExists;
Expand Down Expand Up @@ -1230,7 +1241,7 @@ bool CPerformanceConfig::ListPerformanceBanks()
return true;
}

void CPerformanceConfig::SetPerformanceBank(unsigned nBankID)
void CPerformanceConfig::SetNewPerformanceBank(unsigned nBankID)
{
assert (nBankID < NUM_PERFORMANCE_BANKS);
if (IsValidPerformanceBank(nBankID))
Expand All @@ -1239,6 +1250,7 @@ void CPerformanceConfig::SetPerformanceBank(unsigned nBankID)
LOGNOTE("Selecting Performance Bank: %d", nBankID+1);
#endif
m_nPerformanceBank = nBankID;
m_nActualPerformanceBank = nBankID;
ListPerformances();
}
else
Expand Down
5 changes: 4 additions & 1 deletion src/performanceconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class CPerformanceConfig // Performance configuration
unsigned GetLastPerformanceBank();
void SetActualPerformanceID(unsigned nID);
unsigned GetActualPerformanceID();
void SetActualPerformanceBankID(unsigned nBankID);
unsigned GetActualPerformanceBankID();
bool CreateNewPerformanceFile(void);
bool GetInternalFolderOk();
std::string GetNewPerformanceDefaultName(void);
Expand All @@ -142,7 +144,7 @@ class CPerformanceConfig // Performance configuration
bool IsValidPerformance(unsigned nID);

bool ListPerformanceBanks(void);
void SetPerformanceBank(unsigned nBankID);
void SetNewPerformanceBank(unsigned nBankID);
unsigned GetPerformanceBank(void);
std::string GetPerformanceBankName(unsigned nBankID);
bool IsValidPerformanceBank(unsigned nBankID);
Expand Down Expand Up @@ -181,6 +183,7 @@ class CPerformanceConfig // Performance configuration

unsigned m_nLastPerformance;
unsigned m_nActualPerformance = 0;
unsigned m_nActualPerformanceBank = 0;
unsigned m_nPerformanceBank;
unsigned m_nLastPerformanceBank;
bool m_bPerformanceDirectoryExists;
Expand Down
6 changes: 3 additions & 3 deletions src/uimenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ void CUIMenu::EditPerformanceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event)
{
// Switch to the new bank and select the first performance voice
pUIMenu->m_pMiniDexed->SetParameter (CMiniDexed::ParameterPerformanceBank, nValue);
pUIMenu->m_nSelectedPerformanceID = pUIMenu->m_pMiniDexed->SetFirstPerformance();
pUIMenu->m_pMiniDexed->SetFirstPerformance();
}
break;

Expand All @@ -1590,15 +1590,15 @@ void CUIMenu::EditPerformanceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event)
if (!bPerformanceSelectToLoad)
{
pUIMenu->m_pMiniDexed->SetParameter (CMiniDexed::ParameterPerformanceBank, nValue);
pUIMenu->m_nSelectedPerformanceID = pUIMenu->m_pMiniDexed->SetFirstPerformance();
pUIMenu->m_pMiniDexed->SetFirstPerformance();
}
break;

case MenuEventSelect:
if (bPerformanceSelectToLoad)
{
pUIMenu->m_pMiniDexed->SetParameter (CMiniDexed::ParameterPerformanceBank, nValue);
pUIMenu->m_nSelectedPerformanceID = pUIMenu->m_pMiniDexed->SetFirstPerformance();
pUIMenu->m_pMiniDexed->SetFirstPerformance();
}
break;

Expand Down

0 comments on commit 07cdafc

Please sign in to comment.