Bugfixes for legacy cases when no performance directory exists plus some extra checks for saving and deleting performances.

pull/581/head
Kevin 1 year ago
parent f06a125e31
commit 5e910a5201
  1. 14
      src/minidexed.cpp
  2. 48
      src/performanceconfig.cpp
  3. 2
      src/uimenu.cpp

@ -1218,12 +1218,19 @@ void CMiniDexed::SetPerformanceSelectChannel (unsigned uCh)
} }
bool CMiniDexed::SavePerformance (bool bSaveAsDeault) bool CMiniDexed::SavePerformance (bool bSaveAsDeault)
{
if (m_PerformanceConfig.GetInternalFolderOk())
{ {
m_bSavePerformance = true; m_bSavePerformance = true;
m_bSaveAsDeault=bSaveAsDeault; m_bSaveAsDeault=bSaveAsDeault;
return true; return true;
} }
else
{
return false;
}
}
bool CMiniDexed::DoSavePerformance (void) bool CMiniDexed::DoSavePerformance (void)
{ {
@ -1701,12 +1708,19 @@ void CMiniDexed::SetVoiceName (std::string VoiceName, unsigned nTG)
} }
bool CMiniDexed::DeletePerformance(unsigned nID) bool CMiniDexed::DeletePerformance(unsigned nID)
{
if (m_PerformanceConfig.IsValidPerformance(nID) && m_PerformanceConfig.GetInternalFolderOk())
{ {
m_bDeletePerformance = true; m_bDeletePerformance = true;
m_nDeletePerformanceID = nID; m_nDeletePerformanceID = nID;
return true; return true;
} }
else
{
return false;
}
}
bool CMiniDexed::DoDeletePerformance(void) bool CMiniDexed::DoDeletePerformance(void)
{ {

@ -29,7 +29,7 @@
LOGMODULE ("Performance"); LOGMODULE ("Performance");
//#define VERBOSE_DEBUG #define VERBOSE_DEBUG
#define PERFORMANCE_DIR "performance" #define PERFORMANCE_DIR "performance"
#define DEFAULT_PERFORMANCE_FILENAME "performance.ini" #define DEFAULT_PERFORMANCE_FILENAME "performance.ini"
@ -795,20 +795,30 @@ std::string CPerformanceConfig::GetPerformanceFullFilePath(unsigned nID)
FileN += DEFAULT_PERFORMANCE_FILENAME; FileN += DEFAULT_PERFORMANCE_FILENAME;
} }
else else
{
if (m_bPerformanceDirectoryExists)
{ {
FileN += PERFORMANCE_DIR; FileN += PERFORMANCE_DIR;
FileN += AddPerformanceBankDirName(m_nPerformanceBank); FileN += AddPerformanceBankDirName(m_nPerformanceBank);
FileN += "/"; FileN += "/";
FileN += GetPerformanceFileName(nID); FileN += GetPerformanceFileName(nID);
} }
}
return FileN; return FileN;
} }
std::string CPerformanceConfig::GetPerformanceName(unsigned nID) std::string CPerformanceConfig::GetPerformanceName(unsigned nID)
{ {
assert (nID < NUM_PERFORMANCES); assert (nID < NUM_PERFORMANCES);
if ((m_nPerformanceBank==0) && (nID == 0)) // in order to assure retrocompatibility
{
return DEFAULT_PERFORMANCE_NAME;
}
else
{
return m_PerformanceFileName[nID]; return m_PerformanceFileName[nID];
} }
}
unsigned CPerformanceConfig::GetLastPerformance() unsigned CPerformanceConfig::GetLastPerformance()
{ {
@ -852,7 +862,7 @@ bool CPerformanceConfig::IsValidPerformance(unsigned nID)
bool CPerformanceConfig::CheckFreePerformanceSlot(void) bool CPerformanceConfig::CheckFreePerformanceSlot(void)
{ {
if (m_nLastPerformance < NUM_PERFORMANCES) if (m_nLastPerformance < NUM_PERFORMANCES-1)
{ {
// There is a free slot... // There is a free slot...
return true; return true;
@ -865,6 +875,12 @@ bool CPerformanceConfig::CheckFreePerformanceSlot(void)
bool CPerformanceConfig::CreateNewPerformanceFile(void) bool CPerformanceConfig::CreateNewPerformanceFile(void)
{ {
if (!m_bPerformanceDirectoryExists)
{
// Nothing can be done if there is no performance directory
LOGNOTE("Performance directory does not exist");
return false;
}
if (m_nLastPerformance >= NUM_PERFORMANCES) { if (m_nLastPerformance >= NUM_PERFORMANCES) {
// No space left for new performances // No space left for new performances
LOGWARN ("No space left for new performance"); LOGWARN ("No space left for new performance");
@ -1076,6 +1092,12 @@ void CPerformanceConfig::SetNewPerformanceName(std::string nName)
bool CPerformanceConfig::DeletePerformance(unsigned nID) bool CPerformanceConfig::DeletePerformance(unsigned nID)
{ {
if (!m_bPerformanceDirectoryExists)
{
// Nothing can be done if there is no performance directory
LOGNOTE("Performance directory does not exist");
return false;
}
bool bOK = false; bool bOK = false;
if((m_nPerformanceBank == 0) && (nID == 0)){return bOK;} // default (performance.ini at root directory) can't be deleted if((m_nPerformanceBank == 0) && (nID == 0)){return bOK;} // default (performance.ini at root directory) can't be deleted
DIR Directory; DIR Directory;
@ -1096,6 +1118,15 @@ bool CPerformanceConfig::DeletePerformance(unsigned nID)
m_nActualPerformance =0; m_nActualPerformance =0;
//nMenuSelectedPerformance=0; //nMenuSelectedPerformance=0;
m_PerformanceFileName[nID].clear(); m_PerformanceFileName[nID].clear();
// If this was the last performance in the bank...
if (nID == m_nLastPerformance)
{
do
{
// Find the new last performance
m_nLastPerformance--;
} while (!IsValidPerformance(m_nLastPerformance) && (m_nLastPerformance > 0));
}
bOK=true; bOK=true;
} }
else else
@ -1108,6 +1139,10 @@ bool CPerformanceConfig::DeletePerformance(unsigned nID)
bool CPerformanceConfig::ListPerformanceBanks() bool CPerformanceConfig::ListPerformanceBanks()
{ {
m_nPerformanceBank = 0;
m_nLastPerformance = 0;
m_nLastPerformanceBank = 0;
// Open performance directory // Open performance directory
DIR Directory; DIR Directory;
FILINFO FileInfo; FILINFO FileInfo;
@ -1117,11 +1152,12 @@ bool CPerformanceConfig::ListPerformanceBanks()
{ {
// No performance directory, so no performance banks. // No performance directory, so no performance banks.
// So nothing else to do here // So nothing else to do here
LOGNOTE ("No performance banks detected");
m_bPerformanceDirectoryExists = false;
return false; return false;
} }
unsigned nNumBanks = 0; unsigned nNumBanks = 0;
m_nLastPerformanceBank = 0;
// Add in the default performance directory as the first bank // Add in the default performance directory as the first bank
m_PerformanceBankName[0] = DEFAULT_PERFORMANCE_BANK_NAME; m_PerformanceBankName[0] = DEFAULT_PERFORMANCE_BANK_NAME;
@ -1210,6 +1246,12 @@ void CPerformanceConfig::SetPerformanceBank(unsigned nBankID)
m_nPerformanceBank = nBankID; m_nPerformanceBank = nBankID;
ListPerformances(); ListPerformances();
} }
else
{
#ifdef VERBOSE_DEBUG
LOGNOTE("Not selecting invalid Performance Bank: %d", nBankID+1);
#endif
}
} }
unsigned CPerformanceConfig::GetPerformanceBank(void) unsigned CPerformanceConfig::GetPerformanceBank(void)

@ -1460,7 +1460,7 @@ void CUIMenu::PerformanceMenu (CUIMenu *pUIMenu, TMenuEvent Event)
break; break;
case 1: case 1:
if (pUIMenu->m_nSelectedPerformanceID != 0) if (pUIMenu->m_pMiniDexed->IsValidPerformance(pUIMenu->m_nSelectedPerformanceID))
{ {
pUIMenu->m_bPerformanceDeleteMode=true; pUIMenu->m_bPerformanceDeleteMode=true;
pUIMenu->m_bConfirmDeletePerformance=false; pUIMenu->m_bConfirmDeletePerformance=false;

Loading…
Cancel
Save