From 8889e2c2d03a414c9e917a598ebfb213c5a28503 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 28 Nov 2020 16:12:41 +0100 Subject: Move handle_event() to separate files --- src/AlsaDriver.cpp | 1 + src/Driver.hpp | 1 + src/JackDbusDriver.cpp | 1 + src/JackDriver.cpp | 2 + src/Patchage.cpp | 1 + src/PatchageEvent.cpp | 136 ----------------------------------------------- src/PatchageEvent.hpp | 9 +--- src/handle_event.cpp | 139 +++++++++++++++++++++++++++++++++++++++++++++++++ src/handle_event.hpp | 28 ++++++++++ wscript | 2 +- 10 files changed, 175 insertions(+), 145 deletions(-) delete mode 100644 src/PatchageEvent.cpp create mode 100644 src/handle_event.cpp create mode 100644 src/handle_event.hpp diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 702cc00..ec5b24d 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -21,6 +21,7 @@ #include "PatchageCanvas.hpp" #include "PatchageModule.hpp" #include "PatchagePort.hpp" +#include "handle_event.hpp" PATCHAGE_DISABLE_FMT_WARNINGS #include diff --git a/src/Driver.hpp b/src/Driver.hpp index 664ed94..116b29f 100644 --- a/src/Driver.hpp +++ b/src/Driver.hpp @@ -23,6 +23,7 @@ #include +class Patchage; class PatchagePort; class PatchageCanvas; diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp index 211b6ae..001b582 100644 --- a/src/JackDbusDriver.cpp +++ b/src/JackDbusDriver.cpp @@ -24,6 +24,7 @@ #include "PatchageCanvas.hpp" #include "PatchageEvent.hpp" #include "PatchageModule.hpp" +#include "PatchagePort.hpp" #include "PortNames.hpp" PATCHAGE_DISABLE_FMT_WARNINGS diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 36dfa47..7f2e4cb 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -22,7 +22,9 @@ #include "PatchageCanvas.hpp" #include "PatchageEvent.hpp" #include "PatchageModule.hpp" +#include "PatchagePort.hpp" #include "PortNames.hpp" +#include "handle_event.hpp" #include "patchage_config.h" #ifdef HAVE_JACK_METADATA diff --git a/src/Patchage.cpp b/src/Patchage.cpp index fdd0ce9..915a4a1 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -20,6 +20,7 @@ #include "Legend.hpp" #include "PatchageCanvas.hpp" #include "PatchageEvent.hpp" +#include "PatchagePort.hpp" #include "UIFile.hpp" #include "patchage_config.h" #include "warnings.hpp" 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 - * - * 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 . - */ - -#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 -#include -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); -} diff --git a/src/PatchageEvent.hpp b/src/PatchageEvent.hpp index f2fa99d..02d224a 100644 --- a/src/PatchageEvent.hpp +++ b/src/PatchageEvent.hpp @@ -17,15 +17,12 @@ #ifndef PATCHAGE_PATCHAGEEVENT_HPP #define PATCHAGE_PATCHAGEEVENT_HPP -#include "PatchagePort.hpp" +#include "ClientID.hpp" #include "PortID.hpp" #include #include -#include - -class Patchage; struct NoopEvent {}; @@ -71,8 +68,4 @@ using PatchageEvent = boost::variant; -/// Handle an event in the GUI -void -handle_event(Patchage& patchage, const PatchageEvent& event); - #endif // PATCHAGE_PATCHAGEEVENT_HPP diff --git a/src/handle_event.cpp b/src/handle_event.cpp new file mode 100644 index 0000000..acd2420 --- /dev/null +++ b/src/handle_event.cpp @@ -0,0 +1,139 @@ +/* This file is part of Patchage. + * Copyright 2007-2020 David Robillard + * + * 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 . + */ + +#include "handle_event.hpp" + +#include "PatchageEvent.hpp" + +#include "patchage_config.h" + +#include "Driver.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 +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); +} diff --git a/src/handle_event.hpp b/src/handle_event.hpp new file mode 100644 index 0000000..b08bab2 --- /dev/null +++ b/src/handle_event.hpp @@ -0,0 +1,28 @@ +/* This file is part of Patchage. + * Copyright 2007-2020 David Robillard + * + * 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 . + */ + +#ifndef PATCHAGE_HANDLE_EVENT_HPP +#define PATCHAGE_HANDLE_EVENT_HPP + +#include "PatchageEvent.hpp" + +class Patchage; + +/// Handle an event in the GUI +void +handle_event(Patchage& patchage, const PatchageEvent& event); + +#endif // PATCHAGE_HANDLE_EVENT_HPP diff --git a/wscript b/wscript index 7bf05e3..f305e3b 100644 --- a/wscript +++ b/wscript @@ -244,9 +244,9 @@ def build(bld): src/Legend.cpp src/Patchage.cpp src/PatchageCanvas.cpp - src/PatchageEvent.cpp src/PatchageModule.cpp src/TextViewLog.cpp + src/handle_event.cpp src/main.cpp ''' if bld.is_defined('HAVE_JACK_DBUS'): -- cgit v1.2.1