summaryrefslogtreecommitdiffstats
path: root/src/Reactor.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-05-11 13:45:26 -0400
committerDavid Robillard <d@drobilla.net>2021-05-11 13:45:26 -0400
commitdf0fdf362347495531bc3a5d19233220721d846b (patch)
treee3631d08630d4d6651eb24aa53c9fc49157778ab /src/Reactor.cpp
parentc6ae340c6222240dc45e9bba714c722cebece186 (diff)
downloadpatchage-df0fdf362347495531bc3a5d19233220721d846b.tar.gz
patchage-df0fdf362347495531bc3a5d19233220721d846b.tar.bz2
patchage-df0fdf362347495531bc3a5d19233220721d846b.zip
Refactor most functionality around actions and settings
This moves more code into general places, and completely eliminates dependencies on the Patchage "god object".
Diffstat (limited to 'src/Reactor.cpp')
-rw-r--r--src/Reactor.cpp104
1 files changed, 82 insertions, 22 deletions
diff --git a/src/Reactor.cpp b/src/Reactor.cpp
index b875eb2..858a877 100644
--- a/src/Reactor.cpp
+++ b/src/Reactor.cpp
@@ -23,8 +23,8 @@
#include "Driver.hpp"
#include "Drivers.hpp"
#include "ILog.hpp"
-#include "Patchage.hpp"
#include "PortID.hpp"
+#include "Setting.hpp"
#include "warnings.hpp"
#include "ganv/Port.hpp"
@@ -35,14 +35,16 @@ PATCHAGE_RESTORE_WARNINGS
#include <boost/variant/apply_visitor.hpp>
-#include <memory>
-
namespace patchage {
-Reactor::Reactor(Patchage& patchage)
- : _patchage{patchage}
- , _log{patchage.log()}
- , _drivers{patchage.drivers()}
+Reactor::Reactor(Configuration& conf,
+ Drivers& drivers,
+ Canvas& canvas,
+ ILog& log)
+ : _conf{conf}
+ , _drivers{drivers}
+ , _canvas{canvas}
+ , _log{log}
{}
void
@@ -60,6 +62,12 @@ Reactor::operator()(const action::ConnectPorts& action)
}
void
+Reactor::operator()(const action::DecreaseFontSize&)
+{
+ _conf.set<setting::FontSize>(_conf.get<setting::FontSize>() - 1.0);
+}
+
+void
Reactor::operator()(const action::DisconnectClient& action)
{
if (CanvasModule* mod = find_module(action.client, action.direction)) {
@@ -92,31 +100,67 @@ Reactor::operator()(const action::DisconnectPorts& action)
}
void
+Reactor::operator()(const action::IncreaseFontSize&)
+{
+ _conf.set<setting::FontSize>(_conf.get<setting::FontSize>() + 1.0);
+}
+
+void
Reactor::operator()(const action::MoveModule& action)
{
- if (CanvasModule* mod = find_module(action.client, action.direction)) {
- _patchage.conf().set_module_location(
- mod->name(), action.direction, {action.x, action.y});
- }
+ _conf.set_module_location(
+ module_name(action.client), action.direction, {action.x, action.y});
+}
+
+void
+Reactor::operator()(const action::Refresh&)
+{
+ _drivers.refresh();
+}
+
+void
+Reactor::operator()(const action::ResetFontSize&)
+{
+ _conf.set<setting::FontSize>(_canvas.get_default_font_size());
}
void
Reactor::operator()(const action::SplitModule& action)
{
- if (CanvasModule* mod = find_module(action.client, SignalDirection::duplex)) {
- _patchage.conf().set_module_split(mod->name(), true);
- _patchage.refresh();
- }
+ _conf.set_module_split(module_name(action.client), true);
+ _drivers.refresh();
}
void
Reactor::operator()(const action::UnsplitModule& action)
{
- CanvasModule* mod = find_module(action.client, SignalDirection::input);
- if (mod || (mod = find_module(action.client, SignalDirection::output))) {
- _patchage.conf().set_module_split(mod->name(), false);
- _patchage.refresh();
- }
+ _conf.set_module_split(module_name(action.client), false);
+ _drivers.refresh();
+}
+
+void
+Reactor::operator()(const action::ZoomFull&)
+{
+ _canvas.zoom_full();
+ _conf.set<setting::Zoom>(_canvas.get_zoom());
+}
+
+void
+Reactor::operator()(const action::ZoomIn&)
+{
+ _conf.set<setting::Zoom>(_conf.get<setting::Zoom>() * 1.25);
+}
+
+void
+Reactor::operator()(const action::ZoomNormal&)
+{
+ _conf.set<setting::Zoom>(1.0);
+}
+
+void
+Reactor::operator()(const action::ZoomOut&)
+{
+ _conf.set<setting::Zoom>(_conf.get<setting::Zoom>() * 0.75);
}
void
@@ -125,16 +169,32 @@ Reactor::operator()(const Action& action)
boost::apply_visitor(*this, action);
}
+std::string
+Reactor::module_name(const ClientID& client)
+{
+ // Note that split modules always have the same name
+
+ if (CanvasModule* mod = find_module(client, SignalDirection::input)) {
+ return mod->name();
+ }
+
+ if (CanvasModule* mod = find_module(client, SignalDirection::output)) {
+ return mod->name();
+ }
+
+ return std::string{};
+}
+
CanvasModule*
Reactor::find_module(const ClientID& client, const SignalDirection type)
{
- return _patchage.canvas()->find_module(client, type);
+ return _canvas.find_module(client, type);
}
CanvasPort*
Reactor::find_port(const PortID& port)
{
- return _patchage.canvas()->find_port(port);
+ return _canvas.find_port(port);
}
} // namespace patchage