// Copyright 2007-2020 David Robillard // SPDX-License-Identifier: GPL-3.0-or-later #ifndef PATCHAGE_CONFIGURATION_HPP #define PATCHAGE_CONFIGURATION_HPP #include "Coord.hpp" #include "PortType.hpp" #include "Setting.hpp" #include "SignalDirection.hpp" #include #include #include #include #include #include #include #define N_PORT_TYPES 5 namespace patchage { class Configuration { public: explicit Configuration(std::function on_change); void load(); void save(); bool get_module_location(const std::string& name, SignalDirection type, Coord& loc) const; void set_module_location(const std::string& name, SignalDirection type, Coord loc); void set_module_split(const std::string& name, bool split); bool get_module_split(const std::string& name, bool default_val) const; uint32_t get_port_color(PortType type) const { return _port_colors[static_cast(type)]; } void set_port_color(PortType type, uint32_t rgba) { _port_colors[static_cast(type)] = rgba; _on_change(setting::PortColor{type, rgba}); } // Set a global configuration setting template void set(decltype(S::value) value) { S& setting = std::get(_settings); if (setting.value != value) { setting.value = std::move(value); _on_change(setting); } } // Get a global configuration setting template const decltype(S::value) get() const { return std::get(_settings).value; } /// Call `visitor` once with each configuration setting template void each(Visitor visitor) { visitor(std::get(_settings)); visitor(std::get(_settings)); visitor(std::get(_settings)); visitor(std::get(_settings)); visitor(std::get(_settings)); visitor(std::get(_settings)); visitor(std::get(_settings)); visitor(std::get(_settings)); visitor(std::get(_settings)); visitor(std::get(_settings)); for (auto i = 0u; i < N_PORT_TYPES; ++i) { visitor(setting::PortColor{static_cast(i), _port_colors[i]}); } } private: struct ModuleSettings { explicit ModuleSettings(bool s = false) : split(s) {} boost::optional input_location; boost::optional output_location; boost::optional inout_location; bool split; }; std::map _module_settings; uint32_t _default_port_colors[N_PORT_TYPES] = {}; uint32_t _port_colors[N_PORT_TYPES] = {}; using Settings = std::tuple; Settings _settings; std::function _on_change; }; } // namespace patchage #endif // PATCHAGE_CONFIGURATION_HPP