From b5e7187954e5690c9792acefeef174ef86cd3eec Mon Sep 17 00:00:00 2001 From: Rene Stange Date: Tue, 5 Apr 2022 19:52:49 +0200 Subject: [PATCH] uimenu: Add "Save > Performance" function * Saves the performance config to performance.ini * Comments in an existing file will be overwritten * Function displays "Completed" and returns to "Save" menu --- src/minidexed.cpp | 28 +++++++ src/minidexed.h | 2 + src/performanceconfig.cpp | 156 ++++++++++++++++++++++++++++++++++++++ src/performanceconfig.h | 21 +++++ src/uimenu.cpp | 36 +++++++++ src/uimenu.h | 5 ++ 6 files changed, 248 insertions(+) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index cc501e4..eb4ba12 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -788,3 +788,31 @@ void CMiniDexed::ProcessSound (void) } #endif + +bool CMiniDexed::SavePerformance (void) +{ + for (unsigned nTG = 0; nTG < CConfig::ToneGenerators; nTG++) + { + m_PerformanceConfig.SetBankNumber (m_nVoiceBankID[nTG], nTG); + m_PerformanceConfig.SetVoiceNumber (m_nProgram[nTG], nTG); + m_PerformanceConfig.SetMIDIChannel (m_nMIDIChannel[nTG], nTG); + m_PerformanceConfig.SetVolume (m_nVolume[nTG], nTG); + m_PerformanceConfig.SetPan (m_nPan[nTG], nTG); + m_PerformanceConfig.SetDetune (m_nMasterTune[nTG], nTG); + + m_PerformanceConfig.SetNoteLimitLow (m_nNoteLimitLow[nTG], nTG); + m_PerformanceConfig.SetNoteLimitHigh (m_nNoteLimitHigh[nTG], nTG); + m_PerformanceConfig.SetNoteShift (m_nNoteShift[nTG], nTG); + } + + m_PerformanceConfig.SetCompressorEnable (!!m_nParameter[ParameterCompressorEnable]); + m_PerformanceConfig.SetReverbEnable (!!m_nParameter[ParameterReverbEnable]); + m_PerformanceConfig.SetReverbSize (m_nParameter[ParameterReverbSize]); + m_PerformanceConfig.SetReverbHighDamp (m_nParameter[ParameterReverbHighDamp]); + m_PerformanceConfig.SetReverbLowDamp (m_nParameter[ParameterReverbLowDamp]); + m_PerformanceConfig.SetReverbLowPass (m_nParameter[ParameterReverbLowPass]); + m_PerformanceConfig.SetReverbDiffusion (m_nParameter[ParameterReverbDiffusion]); + m_PerformanceConfig.SetReverbSend (m_nParameter[ParameterReverbSend]); + + return m_PerformanceConfig.Save (); +} diff --git a/src/minidexed.h b/src/minidexed.h index e59922f..2104091 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -112,6 +112,8 @@ public: std::string GetVoiceName (unsigned nTG); + bool SavePerformance (void); + private: int16_t ApplyNoteLimits (int16_t pitch, unsigned nTG); // returns < 0 to ignore note diff --git a/src/performanceconfig.cpp b/src/performanceconfig.cpp index 927e2e6..ac1a47b 100644 --- a/src/performanceconfig.cpp +++ b/src/performanceconfig.cpp @@ -104,6 +104,68 @@ bool CPerformanceConfig::Load (void) return bResult; } +bool CPerformanceConfig::Save (void) +{ + m_Properties.RemoveAll (); + + for (unsigned nTG = 0; nTG < CConfig::ToneGenerators; nTG++) + { + CString PropertyName; + + PropertyName.Format ("BankNumber%u", nTG+1); + m_Properties.SetNumber (PropertyName, m_nBankNumber[nTG]); + + PropertyName.Format ("VoiceNumber%u", nTG+1); + m_Properties.SetNumber (PropertyName, m_nVoiceNumber[nTG]+1); + + PropertyName.Format ("MIDIChannel%u", nTG+1); + unsigned nMIDIChannel = m_nMIDIChannel[nTG]; + if (nMIDIChannel < CMIDIDevice::Channels) + { + nMIDIChannel++; + } + else if (nMIDIChannel == CMIDIDevice::OmniMode) + { + nMIDIChannel = 255; + } + else + { + nMIDIChannel = 0; + } + m_Properties.SetNumber (PropertyName, nMIDIChannel); + + PropertyName.Format ("Volume%u", nTG+1); + m_Properties.SetNumber (PropertyName, m_nVolume[nTG]); + + PropertyName.Format ("Pan%u", nTG+1); + m_Properties.SetNumber (PropertyName, m_nPan[nTG]); + + PropertyName.Format ("Detune%u", nTG+1); + m_Properties.SetSignedNumber (PropertyName, m_nDetune[nTG]); + + PropertyName.Format ("NoteLimitLow%u", nTG+1); + m_Properties.SetNumber (PropertyName, m_nNoteLimitLow[nTG]); + + PropertyName.Format ("NoteLimitHigh%u", nTG+1); + m_Properties.SetNumber (PropertyName, m_nNoteLimitHigh[nTG]); + + PropertyName.Format ("NoteShift%u", nTG+1); + m_Properties.SetSignedNumber (PropertyName, m_nNoteShift[nTG]); + } + + m_Properties.SetNumber ("CompressorEnable", m_bCompressorEnable ? 1 : 0); + + m_Properties.SetNumber ("ReverbEnable", m_bReverbEnable ? 1 : 0); + m_Properties.SetNumber ("ReverbSize", m_nReverbSize); + m_Properties.SetNumber ("ReverbHighDamp", m_nReverbHighDamp); + m_Properties.SetNumber ("ReverbLowDamp", m_nReverbLowDamp); + m_Properties.SetNumber ("ReverbLowPass", m_nReverbLowPass); + m_Properties.SetNumber ("ReverbDiffusion", m_nReverbDiffusion); + m_Properties.SetNumber ("ReverbSend", m_nReverbSend); + + return m_Properties.Save (); +} + unsigned CPerformanceConfig::GetBankNumber (unsigned nTG) const { assert (nTG < CConfig::ToneGenerators); @@ -158,6 +220,60 @@ int CPerformanceConfig::GetNoteShift (unsigned nTG) const return m_nNoteShift[nTG]; } +void CPerformanceConfig::SetBankNumber (unsigned nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nBankNumber[nTG] = nValue; +} + +void CPerformanceConfig::SetVoiceNumber (unsigned nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nVoiceNumber[nTG] = nValue; +} + +void CPerformanceConfig::SetMIDIChannel (unsigned nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nMIDIChannel[nTG] = nValue; +} + +void CPerformanceConfig::SetVolume (unsigned nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nVolume[nTG] = nValue; +} + +void CPerformanceConfig::SetPan (unsigned nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nPan[nTG] = nValue; +} + +void CPerformanceConfig::SetDetune (int nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nDetune[nTG] = nValue; +} + +void CPerformanceConfig::SetNoteLimitLow (unsigned nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nNoteLimitLow[nTG] = nValue; +} + +void CPerformanceConfig::SetNoteLimitHigh (unsigned nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nNoteLimitHigh[nTG] = nValue; +} + +void CPerformanceConfig::SetNoteShift (int nValue, unsigned nTG) +{ + assert (nTG < CConfig::ToneGenerators); + m_nNoteShift[nTG] = nValue; +} + bool CPerformanceConfig::GetCompressorEnable (void) const { return m_bCompressorEnable; @@ -197,3 +313,43 @@ unsigned CPerformanceConfig::GetReverbSend (void) const { return m_nReverbSend; } + +void CPerformanceConfig::SetCompressorEnable (bool bValue) +{ + m_bCompressorEnable = bValue; +} + +void CPerformanceConfig::SetReverbEnable (bool bValue) +{ + m_bReverbEnable = bValue; +} + +void CPerformanceConfig::SetReverbSize (unsigned nValue) +{ + m_nReverbSize = nValue; +} + +void CPerformanceConfig::SetReverbHighDamp (unsigned nValue) +{ + m_nReverbHighDamp = nValue; +} + +void CPerformanceConfig::SetReverbLowDamp (unsigned nValue) +{ + m_nReverbLowDamp = nValue; +} + +void CPerformanceConfig::SetReverbLowPass (unsigned nValue) +{ + m_nReverbLowPass = nValue; +} + +void CPerformanceConfig::SetReverbDiffusion (unsigned nValue) +{ + m_nReverbDiffusion = nValue; +} + +void CPerformanceConfig::SetReverbSend (unsigned nValue) +{ + m_nReverbSend = nValue; +} diff --git a/src/performanceconfig.h b/src/performanceconfig.h index b29d90b..3a03219 100644 --- a/src/performanceconfig.h +++ b/src/performanceconfig.h @@ -35,6 +35,8 @@ public: bool Load (void); + bool Save (void); + // TG# unsigned GetBankNumber (unsigned nTG) const; // 0 .. 127 unsigned GetVoiceNumber (unsigned nTG) const; // 0 .. 31 @@ -46,6 +48,16 @@ public: unsigned GetNoteLimitHigh (unsigned nTG) const; // 0 .. 127 int GetNoteShift (unsigned nTG) const; // -24 .. 24 + void SetBankNumber (unsigned nValue, unsigned nTG); + void SetVoiceNumber (unsigned nValue, unsigned nTG); + void SetMIDIChannel (unsigned nValue, unsigned nTG); + void SetVolume (unsigned nValue, unsigned nTG); + void SetPan (unsigned nValue, unsigned nTG); + void SetDetune (int nValue, unsigned nTG); + void SetNoteLimitLow (unsigned nValue, unsigned nTG); + void SetNoteLimitHigh (unsigned nValue, unsigned nTG); + void SetNoteShift (int nValue, unsigned nTG); + // Effects bool GetCompressorEnable (void) const; bool GetReverbEnable (void) const; @@ -56,6 +68,15 @@ public: unsigned GetReverbDiffusion (void) const; // 0 .. 99 unsigned GetReverbSend (void) const; // 0 .. 99 + void SetCompressorEnable (bool bValue); + void SetReverbEnable (bool bValue); + void SetReverbSize (unsigned nValue); + void SetReverbHighDamp (unsigned nValue); + void SetReverbLowDamp (unsigned nValue); + void SetReverbLowPass (unsigned nValue); + void SetReverbDiffusion (unsigned nValue); + void SetReverbSend (unsigned nValue); + private: CPropertiesFatFsFile m_Properties; diff --git a/src/uimenu.cpp b/src/uimenu.cpp index 2b1ddc7..640f31d 100644 --- a/src/uimenu.cpp +++ b/src/uimenu.cpp @@ -50,6 +50,7 @@ const CUIMenu::TMenuItem CUIMenu::s_MainMenu[] = {"TG8", MenuHandler, s_TGMenu, 7}, #endif {"Effects", MenuHandler, s_EffectsMenu}, + {"Save", MenuHandler, s_SaveMenu}, {0} }; @@ -148,6 +149,12 @@ const CUIMenu::TMenuItem CUIMenu::s_OperatorMenu[] = {0} }; +const CUIMenu::TMenuItem CUIMenu::s_SaveMenu[] = +{ + {"Performance", SavePerformance}, + {0} +}; + // must match CMiniDexed::TParameter const CUIMenu::TParameter CUIMenu::s_GlobalParameter[CMiniDexed::ParameterUnknown] = { @@ -622,6 +629,27 @@ void CUIMenu::EditOPParameter (CUIMenu *pUIMenu, TMenuEvent Event) nValue > rParam.Minimum, nValue < rParam.Maximum); } +void CUIMenu::SavePerformance (CUIMenu *pUIMenu, TMenuEvent Event) +{ + if (Event != MenuEventUpdate) + { + return; + } + + bool bOK = pUIMenu->m_pMiniDexed->SavePerformance (); + + const char *pMenuName = + pUIMenu->m_MenuStackParent[pUIMenu->m_nCurrentMenuDepth-1] + [pUIMenu->m_nMenuStackItem[pUIMenu->m_nCurrentMenuDepth-1]].Name; + + pUIMenu->m_pUI->DisplayWrite (pMenuName, + pUIMenu->m_pParentMenu[pUIMenu->m_nCurrentMenuItem].Name, + bOK ? "Completed" : "Error", + false, false); + + CTimer::Get ()->StartKernelTimer (MSEC2HZ (1500), TimerHandler, 0, pUIMenu); +} + string CUIMenu::GetGlobalValueString (unsigned nParameter, int nValue) { string Result; @@ -808,3 +836,11 @@ string CUIMenu::ToOscillatorDetune (int nValue) return Result; } + +void CUIMenu::TimerHandler (TKernelTimerHandle hTimer, void *pParam, void *pContext) +{ + CUIMenu *pThis = static_cast (pContext); + assert (pThis); + + pThis->EventHandler (MenuEventBack); +} diff --git a/src/uimenu.h b/src/uimenu.h index a590a82..d43a7b7 100644 --- a/src/uimenu.h +++ b/src/uimenu.h @@ -24,6 +24,7 @@ #define _uimenu_h #include +#include class CMiniDexed; class CUserInterface; @@ -79,6 +80,7 @@ private: static void EditTGParameter (CUIMenu *pUIMenu, TMenuEvent Event); static void EditVoiceParameter (CUIMenu *pUIMenu, TMenuEvent Event); static void EditOPParameter (CUIMenu *pUIMenu, TMenuEvent Event); + static void SavePerformance (CUIMenu *pUIMenu, TMenuEvent Event); static std::string GetGlobalValueString (unsigned nParameter, int nValue); static std::string GetTGValueString (unsigned nTGParameter, int nValue); @@ -98,6 +100,8 @@ private: static std::string ToOscillatorMode (int nValue); static std::string ToOscillatorDetune (int nValue); + static void TimerHandler (TKernelTimerHandle hTimer, void *pParam, void *pContext); + private: CUserInterface *m_pUI; CMiniDexed *m_pMiniDexed; @@ -122,6 +126,7 @@ private: static const TMenuItem s_ReverbMenu[]; static const TMenuItem s_EditVoiceMenu[]; static const TMenuItem s_OperatorMenu[]; + static const TMenuItem s_SaveMenu[]; static const TParameter s_GlobalParameter[]; static const TParameter s_TGParameter[];