From b4f4e8fdd4f80df9b8883e7a01d819198f8c4353 Mon Sep 17 00:00:00 2001 From: probonopd Date: Thu, 15 May 2025 00:41:38 +0200 Subject: [PATCH] No more crackle after voice uploading --- src/mididevice.cpp | 7 +++++-- src/minidexed.cpp | 6 ++++++ src/minidexed.h | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/mididevice.cpp b/src/mididevice.cpp index 185a31c..c1ccd2a 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -819,11 +819,14 @@ void CMIDIDevice::HandleSystemExclusive(const uint8_t* pMessage, const size_t nL // Load sysex-data into voice memory LOGDBG("One Voice bulk upload"); m_pSynthesizer->loadVoiceParameters(pMessage,nTG); - // Also update performance config so the new voice is not lost + // Defer performance config update to main loop if (m_pSynthesizer && m_pSynthesizer->GetPerformanceConfig()) { uint8_t unpackedVoice[156]; m_pSynthesizer->GetCurrentVoiceData(unpackedVoice, nTG); - m_pSynthesizer->GetPerformanceConfig()->SetVoiceDataToTxt(unpackedVoice, nTG); + CMiniDexed* pMiniDexed = static_cast(m_pSynthesizer); + if (pMiniDexed) { + pMiniDexed->SetPendingVoicePerformanceUpdate(unpackedVoice, nTG); + } } break; case 200: diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 6c4c11e..6b21fe6 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -2504,3 +2504,9 @@ void CMiniDexed::GetCurrentVoiceData(uint8_t* dest, unsigned nTG) { m_pTG[nTG]->getVoiceData(dest); } } + +void CMiniDexed::SetPendingVoicePerformanceUpdate(const uint8_t* voiceData, uint8_t tg) { + m_PendingVoicePerformanceUpdate.pending = true; + memcpy(m_PendingVoicePerformanceUpdate.voiceData, voiceData, 156); + m_PendingVoicePerformanceUpdate.tg = tg; +} diff --git a/src/minidexed.h b/src/minidexed.h index 55f45e8..3f85bac 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -248,6 +248,9 @@ public: void GetCurrentVoiceData(uint8_t* dest, unsigned nTG); +public: + void SetPendingVoicePerformanceUpdate(const uint8_t* voiceData, uint8_t tg); + private: int16_t ApplyNoteLimits (int16_t pitch, unsigned nTG); // returns < 0 to ignore note uint8_t m_uchOPMask[CConfig::AllToneGenerators]; @@ -367,6 +370,13 @@ private: bool m_bLoadPerformanceBusy; bool m_bLoadPerformanceBankBusy; bool m_bSaveAsDeault; + + // Add for deferred performance update after SysEx voice load + struct PendingVoicePerformanceUpdate { + bool pending = false; + uint8_t voiceData[156]; + uint8_t tg = 0; + } m_PendingVoicePerformanceUpdate; }; #endif