summaryrefslogtreecommitdiffstats
path: root/src/Patchage.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-28 22:23:54 +0100
committerDavid Robillard <d@drobilla.net>2020-11-28 22:49:10 +0100
commit924775a79c07a4f5798fcefddb523b189e473080 (patch)
tree6a201df93b109d10cb5c5cab018ee89448c00e00 /src/Patchage.cpp
parent5128bfab7ddb9504abf17375e910e5bc94af291e (diff)
downloadpatchage-924775a79c07a4f5798fcefddb523b189e473080.tar.gz
patchage-924775a79c07a4f5798fcefddb523b189e473080.tar.bz2
patchage-924775a79c07a4f5798fcefddb523b189e473080.zip
Abstract out sending of events
This removes the details of how events are handled from drivers, so the owner can set them up to do anything. For example, a driver could be run in the GUI thread and have its events simply dispatched immediately, but here everything is enqueued to the same queue which is drained later for simplicity.
Diffstat (limited to 'src/Patchage.cpp')
-rw-r--r--src/Patchage.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/Patchage.cpp b/src/Patchage.cpp
index e0b5dc7..5147c44 100644
--- a/src/Patchage.cpp
+++ b/src/Patchage.cpp
@@ -344,7 +344,9 @@ Patchage::Patchage(int argc, char** argv)
#endif
#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS)
- _jack_driver = new JackDriver(_log);
+ _jack_driver = new JackDriver(
+ _log, [this](const PatchageEvent& event) { on_driver_event(event); });
+
_connector.add_driver(PortID::Type::jack, _jack_driver);
_jack_driver->signal_detached.connect(
@@ -357,7 +359,9 @@ Patchage::Patchage(int argc, char** argv)
#endif
#ifdef HAVE_ALSA
- _alsa_driver = new AlsaDriver(_log);
+ _alsa_driver = new AlsaDriver(
+ _log, [this](const PatchageEvent& event) { on_driver_event(event); });
+
_connector.add_driver(PortID::Type::alsa, _alsa_driver);
#endif
@@ -443,19 +447,8 @@ Patchage::idle_callback()
_attach = false;
}
- // Process any JACK events
-#if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS)
- if (_jack_driver) {
- _jack_driver->process_events(this);
- }
-#endif
-
- // Process any ALSA events
-#ifdef HAVE_ALSA
- if (_alsa_driver) {
- _alsa_driver->process_events(this);
- }
-#endif
+ // Process any events from drivers
+ process_events();
// Do a full refresh
if (_refresh) {
@@ -615,6 +608,25 @@ Patchage::update_state()
_canvas->for_each_node(load_module_location, nullptr);
}
+void
+Patchage::on_driver_event(const PatchageEvent& event)
+{
+ std::lock_guard<std::mutex> lock{_events_mutex};
+
+ _driver_events.emplace(event);
+}
+
+void
+Patchage::process_events()
+{
+ std::lock_guard<std::mutex> lock{_events_mutex};
+
+ while (!_driver_events.empty()) {
+ handle_event(*this, _driver_events.front());
+ _driver_events.pop();
+ }
+}
+
/** Update the sensitivity status of menus to reflect the present.
*
* (eg. disable "Connect to Jack" when Patchage is already connected to Jack)