From 75ee1ed27d5d2c60e867abef09ee920446ac13de Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 11 May 2021 12:04:36 -0400 Subject: Move drivers to a separate object Towards eliminating dependencies on the Patchage "god object". --- src/Drivers.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/Drivers.cpp (limited to 'src/Drivers.cpp') diff --git a/src/Drivers.cpp b/src/Drivers.cpp new file mode 100644 index 0000000..94ab6f9 --- /dev/null +++ b/src/Drivers.cpp @@ -0,0 +1,66 @@ +/* This file is part of Patchage. + * Copyright 2007-2021 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 "Drivers.hpp" + +#include "AudioDriver.hpp" +#include "Driver.hpp" +#include "Event.hpp" +#include "make_alsa_driver.hpp" +#include "make_jack_driver.hpp" + +#include +#include + +namespace patchage { + +Drivers::Drivers(ILog& log, Driver::EventSink emit_event) + : _log{log} + , _emit_event{std::move(emit_event)} + , _alsa_driver{make_alsa_driver( + log, + [this](const Event& event) { _emit_event(event); })} + , _jack_driver{make_jack_driver(_log, [this](const Event& event) { + _emit_event(event); + })} +{} + +void +Drivers::refresh() +{ + if (_alsa_driver) { + _alsa_driver->refresh(_emit_event); + } + + if (_jack_driver) { + _jack_driver->refresh(_emit_event); + } +} + +Driver* +Drivers::driver(const ClientType type) +{ + switch (type) { + case ClientType::jack: + return _jack_driver.get(); + case ClientType::alsa: + return _alsa_driver.get(); + } + + return nullptr; +} + +} // namespace patchage -- cgit v1.2.1