From cbc7c912ddd056ce444efe045fd579b979e2fa72 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 11 May 2021 19:43:44 +0200 Subject: [PATCH] Rate-limit volume meter updates --- plugins/editor/src/editor/GUIComponents.cpp | 18 +++++++++++++++++- plugins/editor/src/editor/GUIComponents.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/editor/src/editor/GUIComponents.cpp b/plugins/editor/src/editor/GUIComponents.cpp index 88e48609..769503fc 100644 --- a/plugins/editor/src/editor/GUIComponents.cpp +++ b/plugins/editor/src/editor/GUIComponents.cpp @@ -991,7 +991,23 @@ void SLevelMeter::setValue(float value) return; value_ = value; - invalid(); + + // instantiate the timer lazily + if (!timer_) { + const uint32_t interval = 10; + timer_ = makeOwned( + [this](CVSTGUITimer* timer) { + timer->stop(); + timerArmed_ = false; + invalid(); + }, interval, false); + } + + // defer the update, but do not rearm the timer + if (!timerArmed_) { + timerArmed_ = true; + timer_->start(); + } } void SLevelMeter::draw(CDrawContext* dc) diff --git a/plugins/editor/src/editor/GUIComponents.h b/plugins/editor/src/editor/GUIComponents.h index dfbd0be4..8161154f 100644 --- a/plugins/editor/src/editor/GUIComponents.h +++ b/plugins/editor/src/editor/GUIComponents.h @@ -402,6 +402,8 @@ private: CColor dangerFillColor_; CColor backColor_; CCoord radius_ = 5.0; + SharedPointer timer_; + bool timerArmed_ = false; }; ///