summaryrefslogtreecommitdiffstats
path: root/src/PatchageEvent.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-28 16:12:41 +0100
committerDavid Robillard <d@drobilla.net>2020-11-28 17:39:10 +0100
commit8889e2c2d03a414c9e917a598ebfb213c5a28503 (patch)
treededb31032cb8a46e71a5b7f44f94ff9ba05fcc67 /src/PatchageEvent.cpp
parent0f8bd14d3487c35280c33bbfd133dd9e37c8f07e (diff)
downloadpatchage-8889e2c2d03a414c9e917a598ebfb213c5a28503.tar.gz
patchage-8889e2c2d03a414c9e917a598ebfb213c5a28503.tar.bz2
patchage-8889e2c2d03a414c9e917a598ebfb213c5a28503.zip
Move handle_event() to separate files
Diffstat (limited to 'src/PatchageEvent.cpp')
-rw-r--r--src/PatchageEvent.cpp136
1 files changed, 0 insertions, 136 deletions
diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp
deleted file mode 100644
index 0896b49..0000000
--- a/src/PatchageEvent.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/* This file is part of Patchage.
- * Copyright 2007-2020 David Robillard <d@drobilla.net>
- *
- * Patchage is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option)
- * any later version.
- *
- * Patchage is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Patchage. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "PatchageEvent.hpp"
-
-#include "patchage_config.h"
-
-#include "Driver.hpp"
-#include "Patchage.hpp"
-#include "PatchageCanvas.hpp"
-#include "PatchageModule.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 <fmt/core.h>
-#include <fmt/ostream.h>
-PATCHAGE_RESTORE_WARNINGS
-
-namespace {
-
-class EventHandler
-{
-public:
- using result_type = void; ///< For boost::apply_visitor
-
- explicit EventHandler(Patchage& patchage)
- : _patchage{patchage}
- {}
-
- void operator()(const NoopEvent&) {}
-
- void operator()(const ClientCreationEvent&)
- {
- // Don't create empty modules, they will be created when ports are added
- }
-
- void operator()(const ClientDestructionEvent& event)
- {
- _patchage.canvas()->remove_module(event.id);
- }
-
- 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
- }
-
- 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 {
- _patchage.log().error(
- fmt::format("Unknown type for port \"{}\"", event.id));
- }
- }
-
- void operator()(const PortDestructionEvent& event)
- {
- _patchage.canvas()->remove_port(event.id);
- }
-
- void operator()(const ConnectionEvent& event)
- {
- PatchagePort* port_1 = _patchage.canvas()->find_port(event.tail);
- PatchagePort* port_2 = _patchage.canvas()->find_port(event.head);
-
- if (!port_1) {
- _patchage.log().error(fmt::format(
- "Unable to find port \"{}\" to connect", event.tail));
- } else if (!port_2) {
- _patchage.log().error(fmt::format(
- "Unable to find port \"{}\" to connect", event.head));
- } else {
- _patchage.canvas()->make_connection(port_1, port_2);
- }
- }
-
- void operator()(const DisconnectionEvent& event)
- {
- PatchagePort* port_1 = _patchage.canvas()->find_port(event.tail);
- PatchagePort* port_2 = _patchage.canvas()->find_port(event.head);
-
- if (!port_1) {
- _patchage.log().error(fmt::format(
- "Unable to find port \"{}\" to disconnect", event.tail));
- } else if (!port_2) {
- _patchage.log().error(fmt::format(
- "Unable to find port \"{}\" to disconnect", event.head));
- } else {
- _patchage.canvas()->remove_edge_between(port_1, port_2);
- }
- }
-
-private:
- Patchage& _patchage;
-};
-
-} // namespace
-
-void
-handle_event(Patchage& patchage, const PatchageEvent& event)
-{
- EventHandler handler{patchage};
- boost::apply_visitor(handler, event);
-}