From 6c77b369f7452fb9c3d6a287e62bee31e0973274 Mon Sep 17 00:00:00 2001 From: diyelectromusic <68612569+diyelectromusic@users.noreply.github.com> Date: Thu, 6 Apr 2023 14:53:54 +0100 Subject: [PATCH] Update to fix bank numbers. Bank file numbers now start from 00001 and show as 1-indexed in the UI. But internally and via MIDI are still 0-indexed as per MIDI spec. --- src/sysexfileloader.cpp | 54 +++++++++++++++++++++++------------------ src/uimenu.cpp | 2 +- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/sysexfileloader.cpp b/src/sysexfileloader.cpp index 1088966..d72bc7d 100644 --- a/src/sysexfileloader.cpp +++ b/src/sysexfileloader.cpp @@ -143,23 +143,29 @@ void CSysExFileLoader::LoadBank (const char * sDirName, const char * sBankName, return; } + + // File and UI handling requires banks to be 1..indexed. + // Internally (and via MIDI) we need 0..indexed. + // Any mention of a BankID internally is assumed to be 0..indexed. + unsigned nBankIdx = nBank - 1; - if (nBank > MaxVoiceBankID) + // BankIdx goes from 0 to MaxVoiceBankID inclusive + if (nBankIdx > MaxVoiceBankID) { LOGWARN ("Bank #%u is not supported", nBank); return; } - if (m_pVoiceBank[nBank]) + if (m_pVoiceBank[nBankIdx]) { LOGWARN ("Bank #%u already loaded", nBank); return; } - m_pVoiceBank[nBank] = new TVoiceBank; - assert (m_pVoiceBank[nBank]); + m_pVoiceBank[nBankIdx] = new TVoiceBank; + assert (m_pVoiceBank[nBankIdx]); assert (sizeof(TVoiceBank) == VoiceSysExHdrSize + VoiceSysExSize); std::string Filename (sDirName); @@ -170,11 +176,11 @@ void CSysExFileLoader::LoadBank (const char * sDirName, const char * sBankName, if (pFile) { bool bBankLoaded = false; - if ( fread (m_pVoiceBank[nBank], VoiceSysExHdrSize+VoiceSysExSize, 1, pFile) == 1 - && m_pVoiceBank[nBank]->StatusStart == 0xF0 - && m_pVoiceBank[nBank]->CompanyID == 0x43 - && m_pVoiceBank[nBank]->Format == 0x09 - && m_pVoiceBank[nBank]->StatusEnd == 0xF7) + if ( fread (m_pVoiceBank[nBankIdx], VoiceSysExHdrSize+VoiceSysExSize, 1, pFile) == 1 + && m_pVoiceBank[nBankIdx]->StatusStart == 0xF0 + && m_pVoiceBank[nBankIdx]->CompanyID == 0x43 + && m_pVoiceBank[nBankIdx]->Format == 0x09 + && m_pVoiceBank[nBankIdx]->StatusEnd == 0xF7) { if (m_nBanksLoaded % 100 == 0) { @@ -182,7 +188,7 @@ void CSysExFileLoader::LoadBank (const char * sDirName, const char * sBankName, } //LOGDBG ("Bank #%u successfully loaded", nBank); - m_BankFileName[nBank] = sBankName; + m_BankFileName[nBankIdx] = sBankName; if (nBank > m_nNumHighestBank) { // This is the bank ID of the highest loaded bank @@ -196,7 +202,7 @@ void CSysExFileLoader::LoadBank (const char * sDirName, const char * sBankName, // Config says to accept headerless SysEx Voice Banks // so reset file pointer and try again. fseek (pFile, 0, SEEK_SET); - if (fread (m_pVoiceBank[nBank]->Voice, VoiceSysExSize, 1, pFile) == 1) + if (fread (m_pVoiceBank[nBankIdx]->Voice, VoiceSysExSize, 1, pFile) == 1) { if (m_nBanksLoaded % 100 == 0) { @@ -206,15 +212,15 @@ void CSysExFileLoader::LoadBank (const char * sDirName, const char * sBankName, // Add in the missing header items. // Naturally it isn't possible to validate these! - m_pVoiceBank[nBank]->StatusStart = 0xF0; - m_pVoiceBank[nBank]->CompanyID = 0x43; - m_pVoiceBank[nBank]->Format = 0x09; - m_pVoiceBank[nBank]->ByteCountMS = 0x20; - m_pVoiceBank[nBank]->ByteCountLS = 0x00; - m_pVoiceBank[nBank]->Checksum = 0x00; - m_pVoiceBank[nBank]->StatusEnd = 0xF7; - - m_BankFileName[nBank] = sBankName; + m_pVoiceBank[nBankIdx]->StatusStart = 0xF0; + m_pVoiceBank[nBankIdx]->CompanyID = 0x43; + m_pVoiceBank[nBankIdx]->Format = 0x09; + m_pVoiceBank[nBankIdx]->ByteCountMS = 0x20; + m_pVoiceBank[nBankIdx]->ByteCountLS = 0x00; + m_pVoiceBank[nBankIdx]->Checksum = 0x00; + m_pVoiceBank[nBankIdx]->StatusEnd = 0xF7; + + m_BankFileName[nBankIdx] = sBankName; if (nBank > m_nNumHighestBank) { // This is the bank ID of the highest loaded bank @@ -229,16 +235,16 @@ void CSysExFileLoader::LoadBank (const char * sDirName, const char * sBankName, { LOGWARN ("%s: Invalid size or format", Filename.c_str ()); - delete m_pVoiceBank[nBank]; - m_pVoiceBank[nBank] = nullptr; + delete m_pVoiceBank[nBankIdx]; + m_pVoiceBank[nBankIdx] = nullptr; } fclose (pFile); } else { - delete m_pVoiceBank[nBank]; - m_pVoiceBank[nBank] = nullptr; + delete m_pVoiceBank[nBankIdx]; + m_pVoiceBank[nBankIdx] = nullptr; } } diff --git a/src/uimenu.cpp b/src/uimenu.cpp index e863606..cc1d670 100644 --- a/src/uimenu.cpp +++ b/src/uimenu.cpp @@ -519,7 +519,7 @@ void CUIMenu::EditVoiceBankNumber (CUIMenu *pUIMenu, TMenuEvent Event) string TG ("TG"); TG += to_string (nTG+1); - string Value = to_string (nValue) + "=" + string Value = to_string (nValue+1) + "=" + pUIMenu->m_pMiniDexed->GetSysExFileLoader ()->GetBankName (nValue); pUIMenu->m_pUI->DisplayWrite (TG.c_str (),