From 5128bfab7ddb9504abf17375e910e5bc94af291e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 28 Nov 2020 21:41:26 +0100 Subject: Refresh by emitting events This decouples drivers from the rest of the application, in particular the horrible situation where they were working with the canvas directly, by having them always communicate changes by emitting events. --- src/handle_event.cpp | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) (limited to 'src/handle_event.cpp') diff --git a/src/handle_event.cpp b/src/handle_event.cpp index 2bd3609..200f819 100644 --- a/src/handle_event.cpp +++ b/src/handle_event.cpp @@ -15,26 +15,19 @@ */ #include "handle_event.hpp" +#include "event_to_string.hpp" #include "PatchageEvent.hpp" #include "patchage_config.h" -#include "Driver.hpp" +#include "event_to_string.hpp" + #include "Patchage.hpp" #include "PatchageCanvas.hpp" #include "PatchageModule.hpp" #include "PatchagePort.hpp" -#if defined(HAVE_JACK_DBUS) -# include "JackDbusDriver.hpp" -#elif defined(PATCHAGE_LIBJACK) -# include "JackDriver.hpp" -#endif -#ifdef HAVE_ALSA -# include "AlsaDriver.hpp" -#endif - PATCHAGE_DISABLE_FMT_WARNINGS #include #include @@ -65,27 +58,14 @@ public: void operator()(const PortCreationEvent& event) { - Driver* driver = nullptr; - if (event.id.type() == PortID::Type::jack) { -#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) - driver = _patchage.jack_driver(); -#endif -#ifdef HAVE_ALSA - } else if (event.id.type() == PortID::Type::alsa) { - driver = _patchage.alsa_driver(); -#endif - } _patchage.metadata().set_port(event.id, event.info); - if (driver) { - PatchagePort* port = driver->create_port_view(&_patchage, event.id); - if (!port) { - _patchage.log().error(fmt::format( - "Unable to create view for port \"{}\"", event.id)); - } - } else { + auto* const port = + _patchage.canvas()->create_port(_patchage, event.id, event.info); + + if (!port) { _patchage.log().error( - fmt::format("Unknown type for port \"{}\"", event.id)); + fmt::format("Unable to create view for port \"{}\"", event.id)); } } -- cgit v1.2.1