Skip to content

Commit

Permalink
Start of subdirectory implementation for performance banks.
Browse files Browse the repository at this point in the history
  • Loading branch information
diyelectromusic committed Dec 9, 2023
1 parent 4940051 commit a025153
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/mididevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,31 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign
else
{
// Perform any MiniDexed level MIDI handling before specific Tone Generators
unsigned nPerfCh = m_pSynthesizer->GetPerformanceSelectChannel();
switch (ucType)
{
case MIDI_CONTROL_CHANGE:
// Check for performance PC messages
if (nPerfCh != Disabled)
{
if ((ucChannel == nPerfCh) || (nPerfCh == OmniMode))
{
if (pMessage[1] == MIDI_CC_BANK_SELECT_MSB)
{
m_pSynthesizer->BankSelectMSBPerformance (pMessage[2]);
}
else if (pMessage[1] == MIDI_CC_BANK_SELECT_LSB)
{
m_pSynthesizer->BankSelectLSBPerformance (pMessage[2]);
}
else
{
// Ignore any other CC messages at this time
}
}
}
break;

case MIDI_NOTE_OFF:
case MIDI_NOTE_ON:
if (nLength < 3)
Expand All @@ -195,11 +217,11 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign
}
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))
Expand Down
34 changes: 34 additions & 0 deletions src/minidexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,22 @@ void CMiniDexed::BankSelect (unsigned nBank, unsigned nTG)
}
}

void CMiniDexed::BankSelectPerformance (unsigned nBank)
{
nBank=constrain((int)nBank,0,16383);

if (m_nParameter[ParameterPerformanceSelectChannel] != CMIDIDevice::Disabled)
{
// if (GetSysExFileLoader ()->IsValidBank(nBank))
{
// Only change if we have the bank loaded
m_nVoiceBankIDPerformance = nBank;

m_UI.ParameterChanged ();
}
}
}

void CMiniDexed::BankSelectMSB (unsigned nBankMSB, unsigned nTG)
{
nBankMSB=constrain((int)nBankMSB,0,127);
Expand All @@ -422,6 +438,12 @@ void CMiniDexed::BankSelectMSB (unsigned nBankMSB, unsigned nTG)
m_nVoiceBankIDMSB[nTG] = nBankMSB;
}

void CMiniDexed::BankSelectMSBPerformance (unsigned nBankMSB)
{
nBankMSB=constrain((int)nBankMSB,0,127);
m_nVoiceBankIDMSBPerformance = nBankMSB;
}

void CMiniDexed::BankSelectLSB (unsigned nBankLSB, unsigned nTG)
{
nBankLSB=constrain((int)nBankLSB,0,127);
Expand All @@ -435,6 +457,18 @@ void CMiniDexed::BankSelectLSB (unsigned nBankLSB, unsigned nTG)
BankSelect(nBank, nTG);
}

void CMiniDexed::BankSelectLSBPerformance (unsigned nBankLSB)
{
nBankLSB=constrain((int)nBankLSB,0,127);

unsigned nBank = m_nVoiceBankIDPerformance;
unsigned nBankMSB = m_nVoiceBankIDMSBPerformance;
nBank = (nBankMSB << 7) + nBankLSB;

// Now should have both MSB and LSB so enable the BankSelect
BankSelectPerformance(nBank);
}

void CMiniDexed::ProgramChange (unsigned nProgram, unsigned nTG)
{
assert (m_pConfig);
Expand Down
5 changes: 5 additions & 0 deletions src/minidexed.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ class CMiniDexed
CSysExFileLoader *GetSysExFileLoader (void);

void BankSelect (unsigned nBank, unsigned nTG);
void BankSelectPerformance (unsigned nBank);
void BankSelectMSB (unsigned nBankMSB, unsigned nTG);
void BankSelectMSBPerformance (unsigned nBankMSB);
void BankSelectLSB (unsigned nBankLSB, unsigned nTG);
void BankSelectLSBPerformance (unsigned nBankLSB);
void ProgramChange (unsigned nProgram, unsigned nTG);
void ProgramChangePerformance (unsigned nProgram);
void SetVolume (unsigned nVolume, unsigned nTG);
Expand Down Expand Up @@ -239,6 +242,8 @@ class CMiniDexed

unsigned m_nVoiceBankID[CConfig::ToneGenerators];
unsigned m_nVoiceBankIDMSB[CConfig::ToneGenerators];
unsigned m_nVoiceBankIDPerformance;
unsigned m_nVoiceBankIDMSBPerformance;
unsigned m_nProgram[CConfig::ToneGenerators];
unsigned m_nVolume[CConfig::ToneGenerators];
unsigned m_nPan[CConfig::ToneGenerators];
Expand Down
121 changes: 121 additions & 0 deletions src/performanceconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,8 @@ bool CPerformanceConfig::ListPerformances()

LOGNOTE ("Last Performance: %d", nLastPerformance + 1); // Show "user facing" index

ListPerformanceBanks();

return nInternalFolderOk;
}

Expand Down Expand Up @@ -1013,3 +1015,122 @@ bool CPerformanceConfig::DeletePerformance(unsigned nID)
}
return bOK;
}

bool CPerformanceConfig::ListPerformanceBanks()
{
// Open performance directory
DIR Directory;
FILINFO FileInfo;
FRESULT Result;
Result = f_opendir (&Directory, "SD:/" PERFORMANCE_DIR);
if (Result != FR_OK)
{
// No performance directory, so no performance banks.
// So nothing else to do here
return false;
}

LOGNOTE ("Performance Directory Found");

unsigned nNumBanks = 0;
unsigned nHighestBank = 0;

// List directories with names in format 01_Perf Bank Name
Result = f_findfirst (&Directory, &FileInfo, "SD:/" PERFORMANCE_DIR, "*");
for (unsigned i = 0; Result == FR_OK && FileInfo.fname[0]; i++)
{
// Check to see if it is a directory
if ((FileInfo.fattrib & AM_DIR) != 0)
{
// Looking for Performance banks of the form: 01_Perf Bank Name
// So positions 0,1 = decimal digit
// position 2 = "_"
// positions 3.. = actual name
//
std::string OriFileName = FileInfo.fname;
size_t nLen = OriFileName.length();
if ( nLen > 3 && nLen <26 && strcmp(OriFileName.substr(2,1).c_str(), "_")==0)
{
unsigned nBankIndex = stoi(OriFileName.substr(0,2));
// Recall user index numbered 01..NUM_PERFORMANCE_BANKS
if ((nBankIndex > 0) && (nBankIndex <= NUM_PERFORMANCE_BANKS))
{
// Convert from "user facing" 1..indexed number to internal 0..indexed
nBankIndex = nBankIndex-1;
if (m_nPerformanceBankName[nBankIndex].empty())
{
std::string BankName = OriFileName.substr(3,nLen);

m_nPerformanceBankName[nBankIndex] = BankName;
//LOGNOTE ("Found performance bank %s (%d, %s)", OriFileName.c_str(), nBankIndex, BankName.c_str());
nNumBanks++;
if (nBankIndex > nHighestBank)
{
nHighestBank = nBankIndex;
}
}
else
{
LOGNOTE ("Duplicate Performance Bank: %s", FileInfo.fname);
}
}
else
{
LOGNOTE ("Performance Bank number out of range: %s", FileInfo.fname);
}
}
else
{
//LOGNOTE ("Skipping: %s", FileInfo.fname);
}
}

Result = f_findnext (&Directory, &FileInfo);
}

if (nNumBanks > 0)
{
LOGNOTE ("Number of Performance Banks: %d (last = %d)", nNumBanks, nHighestBank+1);
}
return true;
}

void CPerformanceConfig::SetPerformanceBank(unsigned nBankID)
{
assert (nBankID < NUM_PERFORMANCE_BANKS);
if (IsValidPerformanceBank(nBankID))
{
// Construct performance bank directory name
// Change directory
// Reload performances from that directory
nPerformanceBank = nBankID;
}
}

unsigned CPerformanceConfig::GetPerformanceBank(void)
{
return nPerformanceBank;
}

std::string CPerformanceConfig::GetPerformanceBankName(unsigned nBankID)
{
assert (nBankID < NUM_PERFORMANCE_BANKS);
if (IsValidPerformanceBank(nBankID))
{
return m_nPerformanceBankName[nBankID];
}
else
{
return "Default";
}
}

bool CPerformanceConfig::IsValidPerformanceBank(unsigned nBankID)
{
assert (nBankID < NUM_PERFORMANCE_BANKS);
if (m_nPerformanceBankName[nBankID].empty())
{
return false;
}
return true;
}
9 changes: 9 additions & 0 deletions src/performanceconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define NUM_VOICE_PARAM 156
#define PERFORMANCE_DIR "performance"
#define NUM_PERFORMANCES 256
#define NUM_PERFORMANCE_BANKS 8

class CPerformanceConfig // Performance configuration
{
Expand Down Expand Up @@ -136,6 +137,12 @@ class CPerformanceConfig // Performance configuration
bool CheckFreePerformanceSlot(void);
bool IsValidPerformance(unsigned nID);

bool ListPerformanceBanks(void);
void SetPerformanceBank(unsigned nBankID);
unsigned GetPerformanceBank(void);
std::string GetPerformanceBankName(unsigned nBankID);
bool IsValidPerformanceBank(unsigned nBankID);

private:
CPropertiesFatFsFile m_Properties;

Expand Down Expand Up @@ -170,8 +177,10 @@ class CPerformanceConfig // Performance configuration

unsigned nLastPerformance;
unsigned nActualPerformance = 0;
unsigned nPerformanceBank;
//unsigned nMenuSelectedPerformance = 0;
std::string m_nPerformanceFileName[NUM_PERFORMANCES];
std::string m_nPerformanceBankName[NUM_PERFORMANCE_BANKS];
FATFS *m_pFileSystem;

bool nInternalFolderOk=false;
Expand Down

0 comments on commit a025153

Please sign in to comment.