diff options
author | David Robillard <d@drobilla.net> | 2023-05-12 09:15:44 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-05-12 09:15:44 -0400 |
commit | e659e4b33defc709fe3129b4a6420deaef67e6b4 (patch) | |
tree | eb68d8d3dc50f42b7716526516eb293973d77d87 | |
parent | 8987e2ab771b8494269387e57e670866307fe1bc (diff) | |
download | patchage-e659e4b33defc709fe3129b4a6420deaef67e6b4.tar.gz patchage-e659e4b33defc709fe3129b4a6420deaef67e6b4.tar.bz2 patchage-e659e4b33defc709fe3129b4a6420deaef67e6b4.zip |
Replace macro with typed constant
-rw-r--r-- | src/Configuration.cpp | 11 | ||||
-rw-r--r-- | src/Configuration.hpp | 10 |
2 files changed, 9 insertions, 12 deletions
diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 7bc2b20..5edbbf1 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -22,11 +22,8 @@ namespace patchage { -static const char* const port_type_names[N_PORT_TYPES] = {"JACK_AUDIO", - "JACK_MIDI", - "ALSA_MIDI", - "JACK_OSC", - "JACK_CV"}; +static const char* const port_type_names[Configuration::n_port_types] = + {"JACK_AUDIO", "JACK_MIDI", "ALSA_MIDI", "JACK_OSC", "JACK_CV"}; Configuration::Configuration(std::function<void(const Setting&)> on_change) : _on_change(std::move(on_change)) @@ -246,7 +243,7 @@ Configuration::load() file >> std::dec >> std::nouppercase; bool found = false; - for (int i = 0; i < N_PORT_TYPES; ++i) { + for (unsigned i = 0U; i < n_port_types; ++i) { if (type_name == port_type_names[i]) { _port_colors[i] = rgba; found = true; @@ -343,7 +340,7 @@ Configuration::save() file << "human_names " << get<setting::HumanNames>() << std::endl; file << std::hex << std::uppercase; - for (int i = 0; i < N_PORT_TYPES; ++i) { + for (unsigned i = 0U; i < n_port_types; ++i) { if (_port_colors[i] != _default_port_colors[i]) { file << "port_color " << port_type_names[i] << " " << _port_colors[i] << std::endl; diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 7837cd0..7b031b5 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -16,13 +16,13 @@ #include <string> #include <tuple> -#define N_PORT_TYPES 5 - namespace patchage { class Configuration { public: + static constexpr unsigned n_port_types = 5U; + explicit Configuration(std::function<void(const Setting&)> on_change); void load(); @@ -101,7 +101,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]}); } } @@ -120,8 +120,8 @@ private: 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, |