diff options
author | David Robillard <d@drobilla.net> | 2020-11-28 21:41:26 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-28 22:49:10 +0100 |
commit | 5128bfab7ddb9504abf17375e910e5bc94af291e (patch) | |
tree | 79cc0953718e1f79ed47282b9f11f9f087edc3bc /src/Patchage.cpp | |
parent | 0f25dd575f9c74cc34a54e64468f07e6c631750d (diff) | |
download | patchage-5128bfab7ddb9504abf17375e910e5bc94af291e.tar.gz patchage-5128bfab7ddb9504abf17375e910e5bc94af291e.tar.bz2 patchage-5128bfab7ddb9504abf17375e910e5bc94af291e.zip |
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.
Diffstat (limited to 'src/Patchage.cpp')
-rw-r--r-- | src/Patchage.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 7613935..e0b5dc7 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -22,6 +22,8 @@ #include "PatchageEvent.hpp" #include "PatchagePort.hpp" #include "UIFile.hpp" +#include "event_to_string.hpp" +#include "handle_event.hpp" #include "patchage_config.h" #include "warnings.hpp" @@ -342,7 +344,7 @@ Patchage::Patchage(int argc, char** argv) #endif #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) - _jack_driver = new JackDriver(this, _log); + _jack_driver = new JackDriver(_log); _connector.add_driver(PortID::Type::jack, _jack_driver); _jack_driver->signal_detached.connect( @@ -355,7 +357,7 @@ Patchage::Patchage(int argc, char** argv) #endif #ifdef HAVE_ALSA - _alsa_driver = new AlsaDriver(this, _log); + _alsa_driver = new AlsaDriver(_log); _connector.add_driver(PortID::Type::alsa, _alsa_driver); #endif @@ -461,12 +463,19 @@ Patchage::idle_callback() } else if (_driver_detached) { #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) if (_jack_driver && !_jack_driver->is_attached()) { - _jack_driver->destroy_all(); + _canvas->remove_ports([](const PatchagePort* port) { + return (port->type() == PortType::jack_audio || + port->type() == PortType::jack_midi || + port->type() == PortType::jack_osc || + port->type() == PortType::jack_cv); + }); } #endif #ifdef HAVE_ALSA if (_alsa_driver && !_alsa_driver->is_attached()) { - _alsa_driver->destroy_all(); + _canvas->remove_ports([](const PatchagePort* port) { + return port->type() == PortType::alsa_midi; + }); } #endif } @@ -542,18 +551,22 @@ Patchage::zoom(double z) void Patchage::refresh() { + auto sink = [this](const PatchageEvent& event) { + handle_event(*this, event); + }; + if (_canvas && _enable_refresh) { _canvas->clear(); #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) if (_jack_driver) { - _jack_driver->refresh(); + _jack_driver->refresh(sink); } #endif #ifdef HAVE_ALSA if (_alsa_driver) { - _alsa_driver->refresh(); + _alsa_driver->refresh(sink); } #endif } @@ -762,7 +775,8 @@ void Patchage::menu_alsa_connect() { _alsa_driver->attach(false); - _alsa_driver->refresh(); + _alsa_driver->refresh( + [this](const PatchageEvent& event) { handle_event(*this, event); }); } void |