From 2199208d340f111dfc3a644737d31464ba4308ae Mon Sep 17 00:00:00 2001 From: Rene Stange Date: Mon, 21 Mar 2022 21:58:49 +0100 Subject: [PATCH] Load performance config from performance.ini (#54) --- src/Makefile | 2 +- src/kernel.cpp | 3 +- src/minidexed.cpp | 20 ++++++- src/minidexed.h | 5 +- src/performance.ini | 75 +++++++++++++++++++++++ src/performanceconfig.cpp | 122 ++++++++++++++++++++++++++++++++++++++ src/performanceconfig.h | 57 ++++++++++++++++++ 7 files changed, 279 insertions(+), 5 deletions(-) create mode 100644 src/performance.ini create mode 100644 src/performanceconfig.cpp create mode 100644 src/performanceconfig.h diff --git a/src/Makefile b/src/Makefile index a5010e6..b9f2195 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ CMSIS_DIR = ../CMSIS_5/CMSIS OBJS = main.o kernel.o minidexed.o config.o userinterface.o \ mididevice.o midikeyboard.o serialmididevice.o pckeyboard.o \ - sysexfileloader.o perftimer.o + sysexfileloader.o performanceconfig.o perftimer.o include ./Synth_Dexed.mk include ./Rules.mk diff --git a/src/kernel.cpp b/src/kernel.cpp index 1c9ed77..1617845 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -64,7 +64,8 @@ bool CKernel::Initialize (void) m_Config.Load (); - m_pDexed = new CMiniDexed (&m_Config, &mInterrupt, &m_GPIOManager, &m_I2CMaster); + m_pDexed = new CMiniDexed (&m_Config, &mInterrupt, &m_GPIOManager, &m_I2CMaster, + &mFileSystem); assert (m_pDexed); if (!m_pDexed->Initialize ()) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index a8284d1..066ce05 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -30,13 +30,14 @@ LOGMODULE ("minidexed"); CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt, - CGPIOManager *pGPIOManager, CI2CMaster *pI2CMaster) + CGPIOManager *pGPIOManager, CI2CMaster *pI2CMaster, FATFS *pFileSystem) : #ifdef ARM_ALLOW_MULTI_CORE CMultiCoreSupport (CMemorySystem::Get ()), #endif m_pConfig (pConfig), m_UI (this, pGPIOManager, pConfig), + m_PerformanceConfig (pFileSystem), m_PCKeyboard (this, pConfig), m_SerialMIDI (this, pInterrupt, pConfig), m_bUseSerial (false), @@ -137,7 +138,22 @@ bool CMiniDexed::Initialize (void) m_pTG[i]->setMWController (99, 7, 0); } - SetMIDIChannel (CMIDIDevice::OmniMode, 0); + if (m_PerformanceConfig.Load ()) + { + for (unsigned nTG = 0; nTG < CConfig::ToneGenerators; nTG++) + { + BankSelectLSB (m_PerformanceConfig.GetBankNumber (nTG), nTG); + ProgramChange (m_PerformanceConfig.GetVoiceNumber (nTG), nTG); + SetMIDIChannel (m_PerformanceConfig.GetMIDIChannel (nTG), nTG); + SetVolume (m_PerformanceConfig.GetVolume (nTG), nTG); + SetPan (m_PerformanceConfig.GetPan (nTG), nTG); + SetMasterTune (m_PerformanceConfig.GetDetune (nTG), nTG); + } + } + else + { + SetMIDIChannel (CMIDIDevice::OmniMode, 0); + } // setup and start the sound device if (!m_pSoundDevice->AllocateQueueFrames (m_pConfig->GetChunkSize ())) diff --git a/src/minidexed.h b/src/minidexed.h index daf9acb..d0f31de 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -24,10 +24,12 @@ #include "config.h" #include "userinterface.h" #include "sysexfileloader.h" +#include "performanceconfig.h" #include "midikeyboard.h" #include "pckeyboard.h" #include "serialmididevice.h" #include "perftimer.h" +#include #include #include #include @@ -44,7 +46,7 @@ class CMiniDexed { public: CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt, - CGPIOManager *pGPIOManager, CI2CMaster *pI2CMaster); + CGPIOManager *pGPIOManager, CI2CMaster *pI2CMaster, FATFS *pFileSystem); bool Initialize (void); @@ -96,6 +98,7 @@ private: CUserInterface m_UI; CSysExFileLoader m_SysExFileLoader; + CPerformanceConfig m_PerformanceConfig; CMIDIKeyboard *m_pMIDIKeyboard[CConfig::MaxUSBMIDIDevices]; CPCKeyboard m_PCKeyboard; diff --git a/src/performance.ini b/src/performance.ini new file mode 100644 index 0000000..93555d1 --- /dev/null +++ b/src/performance.ini @@ -0,0 +1,75 @@ +# +# performance.ini +# + +# TG# +#BankNumber#=0 # 0 .. 127 +#VoiceNumber#=1 # 1 .. 32 +#MIDIChannel#=1 # 1 .. 16, 0: off, >16: omni mode +#Volume#=100 # 0 .. 127 +#Pan#=64 # 0 .. 127 +#Detune#=0 # -99 .. 99 + +# TG1 +BankNumber1=0 +VoiceNumber1=1 +MIDIChannel1=255 +Volume1=100 +Pan1=64 +Detune1=0 + +# TG2 +BankNumber2=0 +VoiceNumber2=1 +MIDIChannel2=0 +Volume2=100 +Pan2=64 +Detune2=0 + +# TG3 +BankNumber3=0 +VoiceNumber3=1 +MIDIChannel3=0 +Volume3=100 +Pan3=64 +Detune3=0 + +# TG4 +BankNumber4=0 +VoiceNumber4=1 +MIDIChannel4=0 +Volume4=100 +Pan4=64 +Detune4=0 + +# TG5 +BankNumber5=0 +VoiceNumber5=1 +MIDIChannel5=0 +Volume5=100 +Pan5=64 +Detune5=0 + +# TG6 +BankNumber6=0 +VoiceNumber6=1 +MIDIChannel6=0 +Volume6=100 +Pan6=64 +Detune6=0 + +# TG7 +BankNumber7=0 +VoiceNumber7=1 +MIDIChannel7=0 +Volume7=100 +Pan7=64 +Detune7=0 + +# TG8 +BankNumber8=0 +VoiceNumber8=1 +MIDIChannel8=0 +Volume8=100 +Pan8=64 +Detune8=0 diff --git a/src/performanceconfig.cpp b/src/performanceconfig.cpp new file mode 100644 index 0000000..4d35398 --- /dev/null +++ b/src/performanceconfig.cpp @@ -0,0 +1,122 @@ +// +// performanceconfig.cpp +// +// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi +// Copyright (C) 2022 The MiniDexed Team +// +// Original author of this class: +// R. Stange +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +#include "performanceconfig.h" +#include "mididevice.h" + +CPerformanceConfig::CPerformanceConfig (FATFS *pFileSystem) +: m_Properties ("performance.ini", pFileSystem) +{ +} + +CPerformanceConfig::~CPerformanceConfig (void) +{ +} + +bool CPerformanceConfig::Load (void) +{ + if (!m_Properties.Load ()) + { + return false; + } + + bool bResult = false; + + for (unsigned nTG = 0; nTG < CConfig::ToneGenerators; nTG++) + { + CString PropertyName; + + PropertyName.Format ("BankNumber%u", nTG+1); + m_nBankNumber[nTG] = m_Properties.GetNumber (PropertyName, 0); + + PropertyName.Format ("VoiceNumber%u", nTG+1); + m_nVoiceNumber[nTG] = m_Properties.GetNumber (PropertyName, 1); + if (m_nVoiceNumber[nTG] > 0) + { + m_nVoiceNumber[nTG]--; + } + + PropertyName.Format ("MIDIChannel%u", nTG+1); + unsigned nMIDIChannel = m_Properties.GetNumber (PropertyName, 255); + if (nMIDIChannel == 0) + { + m_nMIDIChannel[nTG] = CMIDIDevice::Disabled; + } + else if (nMIDIChannel <= CMIDIDevice::Channels) + { + m_nMIDIChannel[nTG] = nMIDIChannel-1; + bResult = true; + } + else + { + m_nMIDIChannel[nTG] = CMIDIDevice::OmniMode; + bResult = true; + } + + PropertyName.Format ("Volume%u", nTG+1); + m_nVolume[nTG] = m_Properties.GetNumber (PropertyName, 100); + + PropertyName.Format ("Pan%u", nTG+1); + m_nPan[nTG] = m_Properties.GetNumber (PropertyName, 64); + + PropertyName.Format ("Detune%u", nTG+1); + m_nDetune[nTG] = m_Properties.GetSignedNumber (PropertyName, 0); + } + + return bResult; +} + +unsigned CPerformanceConfig::GetBankNumber (unsigned nTG) const +{ + assert (nTG < CConfig::ToneGenerators); + return m_nBankNumber[nTG]; +} + +unsigned CPerformanceConfig::GetVoiceNumber (unsigned nTG) const +{ + assert (nTG < CConfig::ToneGenerators); + return m_nVoiceNumber[nTG]; +} + +unsigned CPerformanceConfig::GetMIDIChannel (unsigned nTG) const +{ + assert (nTG < CConfig::ToneGenerators); + return m_nMIDIChannel[nTG]; +} + +unsigned CPerformanceConfig::GetVolume (unsigned nTG) const +{ + assert (nTG < CConfig::ToneGenerators); + return m_nVolume[nTG]; +} + +unsigned CPerformanceConfig::GetPan (unsigned nTG) const +{ + assert (nTG < CConfig::ToneGenerators); + return m_nPan[nTG]; +} + +int CPerformanceConfig::GetDetune (unsigned nTG) const +{ + assert (nTG < CConfig::ToneGenerators); + return m_nDetune[nTG]; +} diff --git a/src/performanceconfig.h b/src/performanceconfig.h new file mode 100644 index 0000000..b6ebb78 --- /dev/null +++ b/src/performanceconfig.h @@ -0,0 +1,57 @@ +// +// performanceconfig.h +// +// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi +// Copyright (C) 2022 The MiniDexed Team +// +// Original author of this class: +// R. Stange +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +#ifndef _performanceconfig_h +#define _performanceconfig_h + +#include "config.h" +#include +#include + +class CPerformanceConfig // Performance configuration +{ +public: + CPerformanceConfig (FATFS *pFileSystem); + ~CPerformanceConfig (void); + + bool Load (void); + + // TG# + unsigned GetBankNumber (unsigned nTG) const; // 0 .. 127 + unsigned GetVoiceNumber (unsigned nTG) const; // 0 .. 31 + unsigned GetMIDIChannel (unsigned nTG) const; // 0 .. 15, omni, off + unsigned GetVolume (unsigned nTG) const; // 0 .. 127 + unsigned GetPan (unsigned nTG) const; // 0 .. 127 + int GetDetune (unsigned nTG) const; // -99 .. 99 + +private: + CPropertiesFatFsFile m_Properties; + + unsigned m_nBankNumber[CConfig::ToneGenerators]; + unsigned m_nVoiceNumber[CConfig::ToneGenerators]; + unsigned m_nMIDIChannel[CConfig::ToneGenerators]; + unsigned m_nVolume[CConfig::ToneGenerators]; + unsigned m_nPan[CConfig::ToneGenerators]; + int m_nDetune[CConfig::ToneGenerators]; +}; + +#endif