From 51ddff2dcbef633a16120fcb83480ff88ca2e74b Mon Sep 17 00:00:00 2001 From: Kevin <68612569+diyelectromusic@users.noreply.github.com> Date: Sat, 12 Aug 2023 08:57:26 -0700 Subject: [PATCH] Changed config setting to match description in original manuals: Performance Select Channel. Also now accepts 1-16 or Omni as values. --- src/config.cpp | 6 ++-- src/config.h | 4 +-- src/mididevice.cpp | 25 ++++++++++--- src/minidexed.cpp | 90 ++++++++++++++++++++++++++-------------------- src/minidexed.h | 10 +++--- src/minidexed.ini | 20 +++++------ src/uimenu.cpp | 40 +++------------------ src/uimenu.h | 1 - 8 files changed, 97 insertions(+), 99 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 30e6605..d06a84a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -149,7 +149,7 @@ void CConfig::Load (void) m_bMIDIDumpEnabled = m_Properties.GetNumber ("MIDIDumpEnabled", 0) != 0; m_bProfileEnabled = m_Properties.GetNumber ("ProfileEnabled", 0) != 0; m_bPerformanceSelectToLoad = m_Properties.GetNumber ("PerformanceSelectToLoad", 1) != 0; - m_bPerformanceProgramChange = m_Properties.GetNumber ("PerformanceProgramChange", 0) != 0; + m_bPerformanceSelectChannel = m_Properties.GetNumber ("PerformanceSelectChannel", 0); } const char *CConfig::GetSoundDevice (void) const @@ -492,7 +492,7 @@ bool CConfig::GetPerformanceSelectToLoad (void) const return m_bPerformanceSelectToLoad; } -bool CConfig::GetPerformanceProgramChange (void) const +unsigned CConfig::GetPerformanceSelectChannel (void) const { - return m_bPerformanceProgramChange; + return m_bPerformanceSelectChannel; } diff --git a/src/config.h b/src/config.h index db735d4..c088461 100644 --- a/src/config.h +++ b/src/config.h @@ -163,7 +163,7 @@ public: // Load performance mode. 0 for load just rotating encoder, 1 load just when Select is pushed bool GetPerformanceSelectToLoad (void) const; - bool GetPerformanceProgramChange (void) const; + unsigned GetPerformanceSelectChannel (void) const; private: CPropertiesFatFsFile m_Properties; @@ -246,7 +246,7 @@ private: bool m_bMIDIDumpEnabled; bool m_bProfileEnabled; bool m_bPerformanceSelectToLoad; - bool m_bPerformanceProgramChange; + unsigned m_bPerformanceSelectChannel; }; #endif diff --git a/src/mididevice.cpp b/src/mididevice.cpp index f4ccf6e..5f231d6 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -191,10 +191,25 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign case MIDI_NOTE_ON: if (nLength < 3) { - break; + break; } m_pUI->UIMIDICmdHandler (ucChannel, ucStatus & 0xF0, pMessage[1], pMessage[2]); break; + case MIDI_PROGRAM_CHANGE: + // Check for performance PC messages + if( m_pConfig->GetMIDIRXProgramChange() ) + { + unsigned nPerfCh = m_pSynthesizer->GetPerformanceSelectChannel(); + if( nPerfCh != Disabled) + { + if ((ucChannel == nPerfCh) || (nPerfCh == OmniMode)) + { + //printf("Performance Select Channel %d\n", nPerfCh); + m_pSynthesizer->ProgramChangePerformance (pMessage[1]); + } + } + } + break; } // Process MIDI for each Tone Generator @@ -336,9 +351,11 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign break; case MIDI_PROGRAM_CHANGE: - // do program change only if enabled in config - if( m_pConfig->GetMIDIRXProgramChange() ) - m_pSynthesizer->ProgramChangePerformance (pMessage[1], nTG); + // do program change only if enabled in config and not in "Performance Select Channel" mode + if( m_pConfig->GetMIDIRXProgramChange() && ( m_pSynthesizer->GetPerformanceSelectChannel() == Disabled) ) { + //printf("Program Change to %d (%d)\n", ucChannel, m_pSynthesizer->GetPerformanceSelectChannel()); + m_pSynthesizer->ProgramChange (pMessage[1], nTG); + } break; case MIDI_PITCH_BEND: { diff --git a/src/minidexed.cpp b/src/minidexed.cpp index bebb32f..b8a6ace 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -57,8 +57,8 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt, m_bLoadPerformanceBusy(false) { assert (m_pConfig); - - m_bPerformanceProgramChange = m_pConfig->GetPerformanceProgramChange(); + + SetPerformanceSelectChannel(m_pConfig->GetPerformanceSelectChannel()); for (unsigned i = 0; i < CConfig::ToneGenerators; i++) { @@ -181,6 +181,20 @@ bool CMiniDexed::Initialize (void) m_bUseSerial = true; } + + if (m_pConfig->GetMIDIRXProgramChange()) + { + int nPerfCh = GetParameter(ParameterPerformanceSelectChannel); + if (nPerfCh == CMIDIDevice::Disabled) { + LOGNOTE("Program Change: Enabled for Voices"); + } else if (nPerfCh == CMIDIDevice::OmniMode) { + LOGNOTE("Program Change: Enabled for Performances (Omni)"); + } else { + LOGNOTE("Program Change: Enabled for Performances (CH %d)", nPerfCh+1); + } + } else { + LOGNOTE("Program Change: Disabled"); + } for (unsigned i = 0; i < CConfig::ToneGenerators; i++) { @@ -461,38 +475,20 @@ void CMiniDexed::ProgramChange (unsigned nProgram, unsigned nTG) m_UI.ParameterChanged (); } -void CMiniDexed::ProgramChangePerformance (unsigned nProgram, unsigned nTG) +void CMiniDexed::ProgramChangePerformance (unsigned nProgram) { - assert (m_pConfig); - - if (m_bPerformanceProgramChange) + if (m_nParameter[ParameterPerformanceSelectChannel] != CMIDIDevice::Disabled) { // Program Change messages change Performances. - // - // Only pay attention to PCs received on the MIDI channel - // associated with TG1. - // - // Note: as performances store the MIDI channnel, if - // the MIDI channel for TG1 changes, then further - // PCs will only be actioned on the new channel number... - if (nTG == 0) - { - unsigned nLastPerformance = m_PerformanceConfig.GetLastPerformance(); + unsigned nLastPerformance = m_PerformanceConfig.GetLastPerformance(); - // GetLastPerformance actually returns 1-indexed, number of performances - if (nProgram < nLastPerformance - 1) - { - SetNewPerformance(nProgram); - } + // GetLastPerformance actually returns 1-indexed, number of performances + if (nProgram < nLastPerformance - 1) + { + SetNewPerformance(nProgram); } + m_UI.ParameterChanged (); } - else - { - // Program Change messages change voice on specified TG - ProgramChange(nProgram, nTG); - } - - m_UI.ParameterChanged (); } void CMiniDexed::SetVolume (unsigned nVolume, unsigned nTG) @@ -791,6 +787,10 @@ void CMiniDexed::SetParameter (TParameter Parameter, int nValue) m_ReverbSpinLock.Release (); break; + case ParameterPerformanceSelectChannel: + // Nothing more to do + break; + default: assert (0); break; @@ -1146,6 +1146,30 @@ void CMiniDexed::ProcessSound (void) #endif +unsigned CMiniDexed::GetPerformanceSelectChannel (void) +{ + // Stores and returns Select Channel using MIDI Device Channel definitions + return (unsigned) GetParameter (ParameterPerformanceSelectChannel); +} + +void CMiniDexed::SetPerformanceSelectChannel (unsigned uCh) +{ + // Turns a configuration setting to MIDI Device Channel definitions + // Mirrors the logic in Performance Config for handling MIDI channel configuration + if (uCh == 0) + { + SetParameter (ParameterPerformanceSelectChannel, CMIDIDevice::Disabled); + } + else if (uCh < CMIDIDevice::Channels) + { + SetParameter (ParameterPerformanceSelectChannel, uCh - 1); + } + else + { + SetParameter (ParameterPerformanceSelectChannel, CMIDIDevice::OmniMode); + } +} + bool CMiniDexed::SavePerformance (bool bSaveAsDeault) { m_bSavePerformance = true; @@ -1468,16 +1492,6 @@ unsigned CMiniDexed::GetLastPerformance() return m_PerformanceConfig.GetLastPerformance(); } -bool CMiniDexed::GetPerformanceProgramChange (void) -{ - return m_bPerformanceProgramChange; -} - -void CMiniDexed::SetPerformanceProgramChange (bool bPerfPC) -{ - m_bPerformanceProgramChange = bPerfPC; -} - unsigned CMiniDexed::GetActualPerformanceID() { return m_PerformanceConfig.GetActualPerformanceID(); diff --git a/src/minidexed.h b/src/minidexed.h index 8a05a34..1aa3096 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -67,7 +67,7 @@ public: void BankSelectMSB (unsigned nBankMSB, unsigned nTG); void BankSelectLSB (unsigned nBankLSB, unsigned nTG); void ProgramChange (unsigned nProgram, unsigned nTG); - void ProgramChangePerformance (unsigned nProgram, unsigned nTG); + void ProgramChangePerformance (unsigned nProgram); void SetVolume (unsigned nVolume, unsigned nTG); void SetPan (unsigned nPan, unsigned nTG); // 0 .. 127 void SetMasterTune (int nMasterTune, unsigned nTG); // -99 .. 99 @@ -126,9 +126,9 @@ public: bool DoSetNewPerformance (void); bool GetPerformanceSelectToLoad(void); bool SavePerformance (bool bSaveAsDeault); - bool GetPerformanceProgramChange (void); - void SetPerformanceProgramChange (bool bPerfPC); - + unsigned GetPerformanceSelectChannel (void); + void SetPerformanceSelectChannel (unsigned uCh); + // Must match the order in CUIMenu::TParameter enum TParameter { @@ -140,6 +140,7 @@ public: ParameterReverbLowPass, ParameterReverbDiffusion, ParameterReverbLevel, + ParameterPerformanceSelectChannel, ParameterUnknown }; @@ -308,7 +309,6 @@ private: unsigned m_nDeletePerformanceID; bool m_bLoadPerformanceBusy; bool m_bSaveAsDeault; - bool m_bPerformanceProgramChange; }; #endif diff --git a/src/minidexed.ini b/src/minidexed.ini index 33b3513..cd5ea1a 100644 --- a/src/minidexed.ini +++ b/src/minidexed.ini @@ -16,24 +16,24 @@ EngineType=1 # MIDI MIDIBaudRate=31250 #MIDIThru=umidi1,ttyS1 -MIDIRXProgramChange=1 IgnoreAllNotesOff=0 MIDIAutoVoiceDumpOnPC=1 HeaderlessSysExVoices=0 +# Program Change enable +# 0 = Ignore all Program Change messages. +# 1 = Respond to Program Change messages. +MIDIRXProgramChange=1 # Program Change mode # 0 = Only recognise Program Change 0-31. # 1 = Support 0-127 across four consecutive banks. -# NB: Ignored if PerformanceProgramChange=1 +# NB: Only relevant if PerformanceSelectChannel=0 ExpandPCAcrossBanks=1 # Program Change action: -# 0 = Select voices -# 1 = Select performances -# -# NB: If Perfromances, then only reacts to Program Change -# messages received on the MIDI channel for TG1. -# Warning: Make sure all perfromances use the same MIDI -# channel for TG1 and that MIDI is enabled. -PerformanceProgramChange=0 +# 0 = Program Change messages select voices on the channel associated with each TG. +# 1-16 = Program Change messages on this channel select performances. +# >16 = Program Change messages on ANY channel select performances. +# NB: In performance mode, all Program Change messages on other channels are ignored. +PerformanceSelectChannel=0 # HD44780 LCD LCDEnabled=1 diff --git a/src/uimenu.cpp b/src/uimenu.cpp index 82652cf..6561e9d 100644 --- a/src/uimenu.cpp +++ b/src/uimenu.cpp @@ -213,7 +213,8 @@ const CUIMenu::TParameter CUIMenu::s_GlobalParameter[CMiniDexed::ParameterUnknow {0, 99, 1}, // ParameterReverbLowDamp {0, 99, 1}, // ParameterReverbLowPass {0, 99, 1}, // ParameterReverbDiffusion - {0, 99, 1} // ParameterReverbLevel + {0, 99, 1}, // ParameterReverbLevel + {0, CMIDIDevice::ChannelUnknown-1, 1, ToMIDIChannel} // ParameterPerformanceSelectChannel }; // must match CMiniDexed::TTGParameter @@ -325,7 +326,7 @@ const CUIMenu::TMenuItem CUIMenu::s_PerformanceMenu[] = {"Load", PerformanceMenu, 0, 0}, {"Save", MenuHandler, s_SaveMenu}, {"Delete", PerformanceMenu, 0, 1}, - {"Program Change", EditPerformanceProgramChange, 0, 0}, + {"MIDI PC", EditGlobalParameter, 0, CMiniDexed::ParameterPerformanceSelectChannel}, {0} }; @@ -1204,7 +1205,7 @@ void CUIMenu::OPShortcutHandler (TMenuEvent Event) void CUIMenu::PgmUpDownHandler (TMenuEvent Event) { - if (m_pMiniDexed->GetPerformanceProgramChange()) + if (m_pMiniDexed->GetParameter (CMiniDexed::ParameterPerformanceSelectChannel) > 0) { // Program Up/Down acts on performances unsigned nLastPerformance = m_pMiniDexed->GetLastPerformance(); @@ -1490,39 +1491,6 @@ void CUIMenu::PerformanceMenu (CUIMenu *pUIMenu, TMenuEvent Event) } } -void CUIMenu::EditPerformanceProgramChange (CUIMenu *pUIMenu, TMenuEvent Event) -{ - bool bPerfPC = pUIMenu->m_pMiniDexed->GetPerformanceProgramChange(); - switch (Event) - { - case MenuEventUpdate: - break; - - case MenuEventStepDown: - case MenuEventStepUp: - bPerfPC = !bPerfPC; - pUIMenu->m_pMiniDexed->SetPerformanceProgramChange(bPerfPC); - break; - - default: - return; - } - - string PPC (" ="); - string Value; - if (bPerfPC) { - Value = "Performance"; - } else { - Value = "Voices"; - } - - pUIMenu->m_pUI->DisplayWrite (PPC.c_str (), - pUIMenu->m_pParentMenu[pUIMenu->m_nCurrentMenuItem].Name, - Value.c_str (), - true, true); -} - - void CUIMenu::InputTxt (CUIMenu *pUIMenu, TMenuEvent Event) { unsigned nTG=0; diff --git a/src/uimenu.h b/src/uimenu.h index 059c1ae..2b70cfe 100644 --- a/src/uimenu.h +++ b/src/uimenu.h @@ -91,7 +91,6 @@ private: static void EditTGParameterModulation (CUIMenu *pUIMenu, TMenuEvent Event); static void PerformanceMenu (CUIMenu *pUIMenu, TMenuEvent Event); static void SavePerformanceNewFile (CUIMenu *pUIMenu, TMenuEvent Event); - static void EditPerformanceProgramChange (CUIMenu *pUIMenu, TMenuEvent Event); static std::string GetGlobalValueString (unsigned nParameter, int nValue); static std::string GetTGValueString (unsigned nTGParameter, int nValue);