diff options
author | David Robillard <d@drobilla.net> | 2021-05-11 12:04:36 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-05-11 13:35:16 -0400 |
commit | 75ee1ed27d5d2c60e867abef09ee920446ac13de (patch) | |
tree | 7c711813cf6282de24f08c96fd6e5465ea7414e5 /src/Reactor.cpp | |
parent | 37ede19b4d1e924f954d8b16d3e071a4768ce278 (diff) | |
download | patchage-75ee1ed27d5d2c60e867abef09ee920446ac13de.tar.gz patchage-75ee1ed27d5d2c60e867abef09ee920446ac13de.tar.bz2 patchage-75ee1ed27d5d2c60e867abef09ee920446ac13de.zip |
Move drivers to a separate object
Towards eliminating dependencies on the Patchage "god object".
Diffstat (limited to 'src/Reactor.cpp')
-rw-r--r-- | src/Reactor.cpp | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/src/Reactor.cpp b/src/Reactor.cpp index f8504a1..b875eb2 100644 --- a/src/Reactor.cpp +++ b/src/Reactor.cpp @@ -21,6 +21,7 @@ #include "CanvasPort.hpp" #include "Configuration.hpp" #include "Driver.hpp" +#include "Drivers.hpp" #include "ILog.hpp" #include "Patchage.hpp" #include "PortID.hpp" @@ -35,37 +36,27 @@ PATCHAGE_RESTORE_WARNINGS #include <boost/variant/apply_visitor.hpp> #include <memory> -#include <unordered_map> -#include <utility> namespace patchage { Reactor::Reactor(Patchage& patchage) : _patchage{patchage} , _log{patchage.log()} + , _drivers{patchage.drivers()} {} void -Reactor::add_driver(PortID::Type type, Driver* driver) -{ - _drivers.emplace(type, driver); -} - -void Reactor::operator()(const action::ConnectPorts& action) { - if (action.tail.type() != action.head.type()) { + if (action.tail.type() == action.head.type()) { + if (auto* d = _drivers.driver(action.tail.type())) { + d->connect(action.tail, action.head); + } else { + _log.error(fmt::format("No driver for port type {}", action.tail.type())); + } + } else { _log.warning("Unable to connect incompatible port types"); - return; - } - - auto d = _drivers.find(action.tail.type()); - if (d == _drivers.end()) { - _log.error(fmt::format("No driver for port type {}", action.tail.type())); - return; } - - d->second->connect(action.tail, action.head); } void @@ -89,18 +80,15 @@ Reactor::operator()(const action::DisconnectPort& action) void Reactor::operator()(const action::DisconnectPorts& action) { - if (action.tail.type() != action.head.type()) { + if (action.tail.type() == action.head.type()) { + if (auto* d = _drivers.driver(action.tail.type())) { + d->disconnect(action.tail, action.head); + } else { + _log.error(fmt::format("No driver for port type {}", action.tail.type())); + } + } else { _log.error("Unable to disconnect incompatible port types"); - return; } - - auto d = _drivers.find(action.tail.type()); - if (d == _drivers.end()) { - _log.error("No driver for port type"); - return; - } - - d->second->disconnect(action.tail, action.head); } void |