diff options
author | David Robillard <d@drobilla.net> | 2021-05-11 13:07:21 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-05-11 13:37:52 -0400 |
commit | c6ae340c6222240dc45e9bba714c722cebece186 (patch) | |
tree | 9721a06a4303e0fd50f31b05b143922ba8775745 /src/Configuration.hpp | |
parent | 0f1e403b0cab6d364abfb894ed209082429a74dd (diff) | |
download | patchage-c6ae340c6222240dc45e9bba714c722cebece186.tar.gz patchage-c6ae340c6222240dc45e9bba714c722cebece186.tar.bz2 patchage-c6ae340c6222240dc45e9bba714c722cebece186.zip |
Add general configuration setting mechanism
Diffstat (limited to 'src/Configuration.hpp')
-rw-r--r-- | src/Configuration.hpp | 90 |
1 files changed, 53 insertions, 37 deletions
diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 75fdcfc..110a4fb 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -19,6 +19,7 @@ #include "Coord.hpp" #include "PortType.hpp" +#include "Setting.hpp" #include "SignalDirection.hpp" #include <boost/optional/optional.hpp> @@ -26,6 +27,7 @@ #include <cstdint> #include <map> #include <string> +#include <tuple> #define N_PORT_TYPES 5 @@ -34,7 +36,7 @@ namespace patchage { class Configuration { public: - Configuration(); + explicit Configuration(); void load(); void save(); @@ -50,44 +52,54 @@ public: void set_module_split(const std::string& name, bool split); bool get_module_split(const std::string& name, bool default_val) const; - float get_zoom() const { return _zoom; } - void set_zoom(float zoom) { _zoom = zoom; } - float get_font_size() const { return _font_size; } - void set_font_size(float font_size) { _font_size = font_size; } - - float get_show_toolbar() const { return _show_toolbar; } - void set_show_toolbar(float show_toolbar) { _show_toolbar = show_toolbar; } - - float get_sprung_layout() const { return _sprung_layout; } - void set_sprung_layout(float sprung_layout) + uint32_t get_port_color(PortType type) const { - _sprung_layout = sprung_layout; + return _port_colors[static_cast<unsigned>(type)]; } - bool get_show_messages() const { return _show_messages; } - void set_show_messages(bool show_messages) { _show_messages = show_messages; } + void set_port_color(PortType type, uint32_t rgba) + { + _port_colors[static_cast<unsigned>(type)] = rgba; + } - bool get_sort_ports() const { return _sort_ports; } - void set_sort_ports(bool sort_ports) { _sort_ports = sort_ports; } + // Set a global configuration setting + template<class S> + void set(typename S::Value value) + { + S& setting = std::get<S>(_settings); - int get_messages_height() const { return _messages_height; } - void set_messages_height(int height) { _messages_height = height; } + if (setting.value != value) { + setting.value = std::move(value); + } + } - uint32_t get_port_color(PortType type) const + // Get a global configuration setting + template<class S> + typename S::Value get() const { - return _port_colors[static_cast<unsigned>(type)]; + return std::get<S>(_settings).value; } - void set_port_color(PortType type, uint32_t rgba) + /// Call `visitor` once with each configuration setting + template<class Visitor> + void each(Visitor visitor) { - _port_colors[static_cast<unsigned>(type)] = rgba; + visitor(std::get<setting::FontSize>(_settings)); + visitor(std::get<setting::HumanNames>(_settings)); + visitor(std::get<setting::MessagesHeight>(_settings)); + visitor(std::get<setting::MessagesVisible>(_settings)); + visitor(std::get<setting::SortedPorts>(_settings)); + visitor(std::get<setting::SprungLayout>(_settings)); + visitor(std::get<setting::ToolbarVisible>(_settings)); + visitor(std::get<setting::WindowLocation>(_settings)); + visitor(std::get<setting::WindowSize>(_settings)); + visitor(std::get<setting::Zoom>(_settings)); + + for (auto i = 0u; i < N_PORT_TYPES; ++i) { + visitor(setting::PortColor{static_cast<PortType>(i), _port_colors[i]}); + } } - Coord get_window_location() { return _window_location; } - void set_window_location(Coord loc) { _window_location = loc; } - Coord get_window_size() { return _window_size; } - void set_window_size(Coord size) { _window_size = size; } - private: struct ModuleSettings { explicit ModuleSettings(bool s = false) @@ -105,16 +117,20 @@ private: uint32_t _default_port_colors[N_PORT_TYPES] = {}; uint32_t _port_colors[N_PORT_TYPES] = {}; - Coord _window_location{0.0, 0.0}; - Coord _window_size{960.0, 540.0}; - - float _zoom = 1.0f; - float _font_size = 12.0f; - int _messages_height = 0; - bool _show_toolbar = true; - bool _sprung_layout = false; - bool _show_messages = false; - bool _sort_ports = true; + using Settings = std::tuple<setting::AlsaAttached, + setting::FontSize, + setting::HumanNames, + setting::JackAttached, + setting::MessagesHeight, + setting::MessagesVisible, + setting::SortedPorts, + setting::SprungLayout, + setting::ToolbarVisible, + setting::WindowLocation, + setting::WindowSize, + setting::Zoom>; + + Settings _settings; }; } // namespace patchage |