summaryrefslogtreecommitdiffstats
path: root/src/Configuration.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Configuration.hpp')
-rw-r--r--src/Configuration.hpp65
1 files changed, 34 insertions, 31 deletions
diff --git a/src/Configuration.hpp b/src/Configuration.hpp
index d98968f..a92d4af 100644
--- a/src/Configuration.hpp
+++ b/src/Configuration.hpp
@@ -1,43 +1,29 @@
-/* This file is part of Patchage.
- * Copyright 2007-2020 David Robillard <d@drobilla.net>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
+// Copyright 2007-2020 David Robillard <d@drobilla.net>
+// 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 <boost/optional/optional.hpp>
#include <cstdint>
#include <functional>
#include <map>
+#include <optional>
#include <string>
#include <tuple>
-#include <utility>
-
-#define N_PORT_TYPES 5
namespace patchage {
+enum class SignalDirection;
+enum class PortType;
+
class Configuration
{
public:
+ static constexpr unsigned n_port_types = 5U;
+
explicit Configuration(std::function<void(const Setting&)> on_change);
void load();
@@ -67,7 +53,7 @@ public:
// Set a global configuration setting
template<class S>
- void set(typename S::Value value)
+ void set(decltype(S::value) value)
{
S& setting = std::get<S>(_settings);
@@ -77,9 +63,26 @@ public:
}
}
+ // Set a global configuration setting
+ template<class S>
+ void set_setting(S new_setting)
+ {
+ set<S>(new_setting.value);
+ }
+
+ // Set a global port color setting
+ void set_setting(setting::PortColor new_setting)
+ {
+ auto& color = _port_colors[static_cast<unsigned>(new_setting.type)];
+
+ if (color != new_setting.color) {
+ set_port_color(new_setting.type, new_setting.color);
+ }
+ }
+
// Get a global configuration setting
template<class S>
- typename S::Value get() const
+ decltype(S::value) get() const
{
return std::get<S>(_settings).value;
}
@@ -99,7 +102,7 @@ public:
visitor(std::get<setting::WindowSize>(_settings));
visitor(std::get<setting::Zoom>(_settings));
- for (auto i = 0u; i < N_PORT_TYPES; ++i) {
+ for (auto i = 0u; i < n_port_types; ++i) {
visitor(setting::PortColor{static_cast<PortType>(i), _port_colors[i]});
}
}
@@ -110,16 +113,16 @@ private:
: split(s)
{}
- boost::optional<Coord> input_location;
- boost::optional<Coord> output_location;
- boost::optional<Coord> inout_location;
- bool split;
+ std::optional<Coord> input_location;
+ std::optional<Coord> output_location;
+ std::optional<Coord> inout_location;
+ bool split;
};
std::map<std::string, ModuleSettings> _module_settings;
- uint32_t _default_port_colors[N_PORT_TYPES] = {};
- uint32_t _port_colors[N_PORT_TYPES] = {};
+ uint32_t _default_port_colors[n_port_types] = {};
+ uint32_t _port_colors[n_port_types] = {};
using Settings = std::tuple<setting::AlsaAttached,
setting::FontSize,