diff options
Diffstat (limited to 'src/Configuration.cpp')
-rw-r--r-- | src/Configuration.cpp | 95 |
1 files changed, 42 insertions, 53 deletions
diff --git a/src/Configuration.cpp b/src/Configuration.cpp index e498487..9bb2ac6 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -1,21 +1,9 @@ -/* 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 #include "Configuration.hpp" +#include "Coord.hpp" #include "PortType.hpp" #include "Setting.hpp" #include "SignalDirection.hpp" @@ -24,19 +12,48 @@ #include <cctype> #include <cstdlib> #include <fstream> -#include <ios> #include <iostream> #include <limits> #include <utility> #include <vector> +// IWYU pragma: no_include <algorithm> + namespace patchage { +namespace { + +/// Return a vector of filenames in descending order by preference +std::vector<std::string> +get_filenames() +{ + std::vector<std::string> filenames; + const std::string prefix; + + const char* xdg_config_home = getenv("XDG_CONFIG_HOME"); + const char* home = getenv("HOME"); + + // XDG spec + if (xdg_config_home) { + filenames.push_back(std::string(xdg_config_home) + "/patchagerc"); + } else if (home) { + filenames.push_back(std::string(home) + "/.config/patchagerc"); + } + + // Old location + if (home) { + filenames.push_back(std::string(home) + "/.patchagerc"); + } + + // Current directory (bundle or last-ditch effort) + filenames.emplace_back("patchagerc"); + + return filenames; +} -static const char* const port_type_names[N_PORT_TYPES] = {"JACK_AUDIO", - "JACK_MIDI", - "ALSA_MIDI", - "JACK_OSC", - "JACK_CV"}; +} // namespace + +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)) @@ -46,7 +63,7 @@ Configuration::Configuration(std::function<void(const Setting&)> on_change) std::get<setting::WindowSize>(_settings).value = Coord{960.0, 540.0}; std::get<setting::Zoom>(_settings).value = 1.0f; -#ifdef PATCHAGE_USE_LIGHT_THEME +#if PATCHAGE_USE_LIGHT_THEME _port_colors[static_cast<unsigned>(PortType::jack_audio)] = _default_port_colors[static_cast<unsigned>(PortType::jack_audio)] = 0xA4BC8CFF; @@ -166,34 +183,6 @@ Configuration::set_module_split(const std::string& name, bool split) } } -/** Return a vector of filenames in descending order by preference. */ -static std::vector<std::string> -get_filenames() -{ - std::vector<std::string> filenames; - std::string prefix; - - const char* xdg_config_home = getenv("XDG_CONFIG_HOME"); - const char* home = getenv("HOME"); - - // XDG spec - if (xdg_config_home) { - filenames.push_back(std::string(xdg_config_home) + "/patchagerc"); - } else if (home) { - filenames.push_back(std::string(home) + "/.config/patchagerc"); - } - - // Old location - if (home) { - filenames.push_back(std::string(home) + "/.patchagerc"); - } - - // Current directory (bundle or last-ditch effort) - filenames.emplace_back("patchagerc"); - - return filenames; -} - void Configuration::load() { @@ -256,7 +245,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; @@ -308,7 +297,7 @@ Configuration::load() file.close(); } -static inline void +inline void write_module_position(std::ofstream& os, const std::string& name, const char* type, @@ -353,7 +342,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; |