diff --git a/src/mididevice.cpp b/src/mididevice.cpp index c1ccd2a..a339b33 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -819,13 +819,11 @@ 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); - // Defer performance config update to main loop + // Defer performance config update to main loop because it would be too slow to do it here if (m_pSynthesizer && m_pSynthesizer->GetPerformanceConfig()) { - uint8_t unpackedVoice[156]; - m_pSynthesizer->GetCurrentVoiceData(unpackedVoice, nTG); CMiniDexed* pMiniDexed = static_cast(m_pSynthesizer); if (pMiniDexed) { - pMiniDexed->SetPendingVoicePerformanceUpdate(unpackedVoice, nTG); + pMiniDexed->SetPendingVoicePerformanceUpdate(nTG); } } break; diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 6b21fe6..ae89c75 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -2505,8 +2505,17 @@ void CMiniDexed::GetCurrentVoiceData(uint8_t* dest, unsigned nTG) { } } -void CMiniDexed::SetPendingVoicePerformanceUpdate(const uint8_t* voiceData, uint8_t tg) { - m_PendingVoicePerformanceUpdate.pending = true; - memcpy(m_PendingVoicePerformanceUpdate.voiceData, voiceData, 156); - m_PendingVoicePerformanceUpdate.tg = tg; +void CMiniDexed::SetPendingVoicePerformanceUpdate(unsigned nTG) { + if (nTG < m_nToneGenerators && m_pTG[nTG]) { + // Get the current voice data from the synthesizer + uint8_t currentVoiceData[155]; + m_pTG[nTG]->getVoiceData(currentVoiceData); + // We need to set the voice data in the synthesizer's performance config + // to ensure that the performance is not changed back to the previous one + // when a parameter is changed. + // This is a workaround for the fact that the performance config + // is not updated when the voice data is changed because it would be + // too costly to do in the thread. + this->GetPerformanceConfig()->SetVoiceDataToTxt(currentVoiceData, nTG); + } } diff --git a/src/minidexed.h b/src/minidexed.h index 3f85bac..5fc380b 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -249,7 +249,7 @@ public: void GetCurrentVoiceData(uint8_t* dest, unsigned nTG); public: - void SetPendingVoicePerformanceUpdate(const uint8_t* voiceData, uint8_t tg); + void SetPendingVoicePerformanceUpdate(unsigned nTG); private: int16_t ApplyNoteLimits (int16_t pitch, unsigned nTG); // returns < 0 to ignore note