diff options
Diffstat (limited to 'UI.h')
-rw-r--r-- | UI.h | 44 |
1 files changed, 42 insertions, 2 deletions
@@ -26,6 +26,46 @@ private: std::chrono::time_point<clock_type> m_checkpoint_timestamp{}; }; +template<typename T> +class AgeOutValue +{ +public: + AgeOutValue(std::chrono::milliseconds timeout): + m_timeout(timeout), + m_checkpoint_timestamp(clock_type::now()), + m_value{} + { + } + + bool is_current() + { + return clock_type::now() - m_checkpoint_timestamp < m_timeout; + } + + // returns value, or 0 if aged-out + T value() + { + T result{}; + + if (is_current()) { + result = m_value; + } + + return result; + } + + void update(const T& value) + { + m_value = value; + m_checkpoint_timestamp = clock_type::now(); + } + +private: + const std::chrono::milliseconds m_timeout; + std::chrono::time_point<clock_type> m_checkpoint_timestamp{}; + T m_value; +}; + class UI { public: @@ -66,8 +106,8 @@ private: uint64_t m_midi_timestamp; std::deque<std::pair<int,int>> m_midi_monitor; - int m_note_bpm; - int m_clock_bpm; + AgeOutValue<int> m_note_bpm; + AgeOutValue<int> m_clock_bpm; Touchpad m_touchpad; Temperature m_temperature; |