diff options
Diffstat (limited to 'src/Reactor.cpp')
-rw-r--r-- | src/Reactor.cpp | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/src/Reactor.cpp b/src/Reactor.cpp index b48d85d..49cbe5a 100644 --- a/src/Reactor.cpp +++ b/src/Reactor.cpp @@ -1,21 +1,9 @@ -/* This file is part of Patchage. - * Copyright 2007-2021 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/>. - */ +// Copyright 2007-2021 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: GPL-3.0-or-later #include "Reactor.hpp" +#include "Action.hpp" #include "Canvas.hpp" #include "CanvasModule.hpp" #include "CanvasPort.hpp" @@ -26,34 +14,35 @@ #include "ILog.hpp" #include "PortID.hpp" #include "Setting.hpp" +#include "SignalDirection.hpp" #include "warnings.hpp" -#include "ganv/Module.hpp" #include "ganv/Port.hpp" PATCHAGE_DISABLE_FMT_WARNINGS #include <fmt/core.h> -#include <fmt/ostream.h> PATCHAGE_RESTORE_WARNINGS -#include <boost/variant/apply_visitor.hpp> - -#include <ostream> +#include <variant> namespace patchage { -inline std::ostream& -operator<<(std::ostream& os, const ClientType type) +class SettingVisitor { - switch (type) { - case ClientType::jack: - return os << "JACK"; - case ClientType::alsa: - return os << "ALSA"; +public: + explicit SettingVisitor(Configuration& conf) + : _conf{conf} + {} + + template<class S> + void operator()(const S& setting) const + { + _conf.set_setting(setting); } - return os; -} +private: + Configuration& _conf; +}; Reactor::Reactor(Configuration& conf, Drivers& drivers, @@ -66,6 +55,13 @@ Reactor::Reactor(Configuration& conf, {} void +Reactor::operator()(const action::ChangeSetting& action) +{ + const SettingVisitor visitor{_conf}; + std::visit(visitor, action.setting); +} + +void Reactor::operator()(const action::ConnectPorts& action) { if (action.tail.type() == action.head.type()) { @@ -112,7 +108,7 @@ Reactor::operator()(const action::DisconnectPorts& action) if (auto* d = _drivers.driver(action.tail.type())) { d->disconnect(action.tail, action.head); } else { - _log.error(fmt::format("No driver for {}", action.tail.type())); + _log.error(fmt::format("No driver available to disconnect ports")); } } else { _log.error("Unable to disconnect incompatible ports"); @@ -186,7 +182,7 @@ Reactor::operator()(const action::ZoomOut&) void Reactor::operator()(const Action& action) { - boost::apply_visitor(*this, action); + std::visit(*this, action); } std::string |