From 4bc87fd7773ba534e6535ce8a61dfb2b5f1df67d Mon Sep 17 00:00:00 2001 From: Javier Nonis Date: Thu, 13 Feb 2025 22:51:11 -0300 Subject: [PATCH] FX: Fix to avoid UI crashes for disabled Tone Generators --- src/minidexed.cpp | 28 ++++++++++++++++++++++++---- src/uimenu.cpp | 22 ++++++++++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index b68c6c7..faf5b0f 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -724,7 +724,12 @@ void CMiniDexed::setInsertFXType (unsigned nType, unsigned nTG) std::string CMiniDexed::getInsertFXName (unsigned nTG) { assert (nTG < CConfig::AllToneGenerators); - return m_InsertFX[nTG]->getName(); + if (nTG < m_nToneGenerators) + { + assert (m_InsertFX[nTG]); + return m_InsertFX[nTG]->getName(); + } + return ""; } void CMiniDexed::setMidiFXType (unsigned nType, unsigned nTG) @@ -751,7 +756,12 @@ void CMiniDexed::setMidiFXType (unsigned nType, unsigned nTG) std::string CMiniDexed::getMidiFXName (unsigned nTG) { assert (nTG < CConfig::AllToneGenerators); - return m_MidiArp[nTG]->getName(); + if (nTG < m_nToneGenerators) + { + assert (m_MidiArp[nTG]); + return m_MidiArp[nTG]->getName(); + } + return ""; } void CMiniDexed::setSendFX1Type (unsigned nType) @@ -1336,8 +1346,18 @@ int CMiniDexed::GetTGParameter (TTGParameter Parameter, unsigned nTG) case TGParameterMIDIChannel: return m_nMIDIChannel[nTG]; case TGParameterSendFX1: return m_nSendFX1[nTG]; case TGParameterReverbSend: return m_nSendFX2[nTG]; - case TGParameterInsertFXType: return m_InsertFX[nTG]->getId(); - case TGParameterMidiFXType: return m_MidiArp[nTG]->getId(); + case TGParameterInsertFXType: + if (nTG < m_nToneGenerators) + { + return m_InsertFX[nTG]->getId(); + } + return 0; + case TGParameterMidiFXType: + if (nTG < m_nToneGenerators) + { + return m_MidiArp[nTG]->getId(); + } + return 0; case TGParameterPitchBendRange: return m_nPitchBendRange[nTG]; case TGParameterPitchBendStep: return m_nPitchBendStep[nTG]; case TGParameterPortamentoMode: return m_nPortamentoMode[nTG]; diff --git a/src/uimenu.cpp b/src/uimenu.cpp index 21273a5..5a69e0d 100644 --- a/src/uimenu.cpp +++ b/src/uimenu.cpp @@ -1029,6 +1029,9 @@ void CUIMenu::MenuHandlerMidiFX (CUIMenu *pUIMenu, TMenuEvent Event) { pUIMenu->m_pCurrentMenu = s_MidiFX; } + + // Identify TG + unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; switch (Event) { @@ -1037,6 +1040,12 @@ void CUIMenu::MenuHandlerMidiFX (CUIMenu *pUIMenu, TMenuEvent Event) case MenuEventSelect: // push menu assert (pUIMenu->m_nCurrentMenuDepth < MaxMenuDepth); + + // Check if TG is enabled + if (nTG >= pUIMenu->m_pConfig->GetToneGenerators()) { + break; + } + pUIMenu->m_MenuStackParent[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_pParentMenu; pUIMenu->m_MenuStackMenu[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_pCurrentMenu; pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth] @@ -1082,8 +1091,6 @@ void CUIMenu::MenuHandlerMidiFX (CUIMenu *pUIMenu, TMenuEvent Event) if (pUIMenu->m_pCurrentMenu) // if this is another menu? { - // Identify TG - unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; // Create TG label string TG ("TG"); TG += to_string (nTG+1); @@ -1116,6 +1123,9 @@ void CUIMenu::MenuHandlerInsertFX (CUIMenu *pUIMenu, TMenuEvent Event) { pUIMenu->m_pCurrentMenu = s_InsertFX; } + + // Identify TG + unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; switch (Event) { @@ -1124,6 +1134,12 @@ void CUIMenu::MenuHandlerInsertFX (CUIMenu *pUIMenu, TMenuEvent Event) case MenuEventSelect: // push menu assert (pUIMenu->m_nCurrentMenuDepth < MaxMenuDepth); + + // Check if TG is enabled + if (nTG >= pUIMenu->m_pConfig->GetToneGenerators()) { + break; + } + pUIMenu->m_MenuStackParent[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_pParentMenu; pUIMenu->m_MenuStackMenu[pUIMenu->m_nCurrentMenuDepth] = pUIMenu->m_pCurrentMenu; pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth] @@ -1169,8 +1185,6 @@ void CUIMenu::MenuHandlerInsertFX (CUIMenu *pUIMenu, TMenuEvent Event) if (pUIMenu->m_pCurrentMenu) // if this is another menu? { - // Identify TG - unsigned nTG = pUIMenu->m_nMenuStackParameter[pUIMenu->m_nCurrentMenuDepth-1]; // Create TG label string TG ("TG"); TG += to_string (nTG+1);