From 655b20bae493a517bd2163a1af379fd57abd3457 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 11 May 2021 12:09:17 -0400 Subject: Add Cleared event for implementing refresh without a race --- src/Drivers.cpp | 2 ++ src/Event.hpp | 5 ++++- src/Patchage.cpp | 2 +- src/event_to_string.cpp | 2 ++ src/handle_event.cpp | 2 ++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Drivers.cpp b/src/Drivers.cpp index 94ab6f9..4f57f34 100644 --- a/src/Drivers.cpp +++ b/src/Drivers.cpp @@ -41,6 +41,8 @@ Drivers::Drivers(ILog& log, Driver::EventSink emit_event) void Drivers::refresh() { + _emit_event(event::Cleared{}); + if (_alsa_driver) { _alsa_driver->refresh(_emit_event); } diff --git a/src/Event.hpp b/src/Event.hpp index 378f35eb..233d1a1 100644 --- a/src/Event.hpp +++ b/src/Event.hpp @@ -28,6 +28,8 @@ namespace patchage { namespace event { +struct Cleared {}; + struct ClientCreated { ClientID id; ClientInfo info; @@ -67,7 +69,8 @@ struct PortsDisconnected { } // namespace event /// An event from drivers that represents a change to the system -using Event = boost::variantclear(); + sink(event::Cleared{}); if (_drivers.jack()) { _drivers.jack()->refresh(sink); diff --git a/src/event_to_string.cpp b/src/event_to_string.cpp index 4b23875..c8a6c42 100644 --- a/src/event_to_string.cpp +++ b/src/event_to_string.cpp @@ -56,6 +56,8 @@ struct EventPrinter { PATCHAGE_UNREACHABLE(); } + std::string operator()(const event::Cleared&) { return "Cleared"; } + std::string operator()(const event::DriverAttached& event) { return fmt::format("Attached to {}", (*this)(event.type)); diff --git a/src/handle_event.cpp b/src/handle_event.cpp index fa11ec3..65f4705 100644 --- a/src/handle_event.cpp +++ b/src/handle_event.cpp @@ -48,6 +48,8 @@ public: : _patchage{patchage} {} + void operator()(const event::Cleared&) { _patchage.canvas()->clear(); } + void operator()(const event::DriverAttached& event) { _patchage.driver_attached(event.type); -- cgit v1.2.1