From 4d2d79c0f5cb548ba0a799b87ebbe7fbeea5ea3d Mon Sep 17 00:00:00 2001 From: Javier Nonis Date: Sat, 11 Jan 2025 13:53:40 -0300 Subject: [PATCH] LCD Update performance fix to avoid glitches on single core RPis --- src/minidexed.cpp | 5 ++++- src/userinterface.cpp | 16 ++++++++++++---- src/userinterface.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 8d78175..34e2643 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -701,7 +701,10 @@ void CMiniDexed::setInsertFXType (unsigned nType, unsigned nTG) } m_InsertFXSpinLock[nTG]->Acquire(); - delete m_InsertFX[nTG]; + if (m_InsertFX[nTG] != NULL) + { + delete m_InsertFX[nTG]; + } m_InsertFX[nTG] = newAudioEffect(nType, m_pConfig->GetSampleRate()); m_InsertFX[nTG]->setTempo(m_nTempo); m_InsertFXSpinLock[nTG]->Release(); diff --git a/src/userinterface.cpp b/src/userinterface.cpp index ca45d8e..1c83877 100644 --- a/src/userinterface.cpp +++ b/src/userinterface.cpp @@ -53,6 +53,7 @@ CUserInterface::~CUserInterface (void) bool CUserInterface::Initialize (void) { assert (m_pConfig); + nLastLCDUpdateTime = 0; if (m_pConfig->GetLCDEnabled ()) { @@ -152,7 +153,7 @@ bool CUserInterface::Initialize (void) } assert (m_pLCD); - m_pLCDBuffered = new CWriteBufferDevice (m_pLCD); + m_pLCDBuffered = new CWriteBufferDevice (m_pLCD, 256); assert (m_pLCDBuffered); LCDWrite ("\x1B[?25l\x1B""d+"); // cursor off, autopage mode @@ -202,10 +203,17 @@ bool CUserInterface::Initialize (void) void CUserInterface::Process (void) { - if (m_pLCDBuffered) + // Limit display updates to avoid glitches on sigle core RPis + unsigned nReadTime = CTimer::GetClockTicks (); + if (nReadTime - nLastLCDUpdateTime > 50000) { - m_pLCDBuffered->Update (); - } + if (m_pLCDBuffered) + { + // Limit updates to 16 bytes to avoid glitches on sigle core RPis + m_pLCDBuffered->Update (16); + } + nLastLCDUpdateTime = nReadTime; + } if (m_pUIButtons) { m_pUIButtons->Update(); diff --git a/src/userinterface.h b/src/userinterface.h index 8c5081c..c69896d 100644 --- a/src/userinterface.h +++ b/src/userinterface.h @@ -89,6 +89,7 @@ private: bool m_bSwitchPressed; unsigned m_nRotaryEncoderLastReadTime; int m_nRotaryEncoderCounter=0; + unsigned nLastLCDUpdateTime; CUIMenu m_Menu; };