From dda521a150cd52c64ecbacac8eb06c48fae124be Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Dec 2021 23:04:39 +0100 Subject: [PATCH] ReplayGain{Config,Global}: move to config/ --- meson.build | 2 +- src/ReplayGainGlobal.hxx | 29 --------------- src/ReplayGainInfo.cxx | 2 +- src/config/PlayerConfig.cxx | 4 +-- .../ReplayGainConfig.cxx} | 36 ++++++++----------- src/{ => config}/ReplayGainConfig.hxx | 11 +++--- src/decoder/Control.hxx | 2 +- src/filter/plugins/ReplayGainFilterPlugin.cxx | 2 +- 8 files changed, 26 insertions(+), 62 deletions(-) delete mode 100644 src/ReplayGainGlobal.hxx rename src/{ReplayGainGlobal.cxx => config/ReplayGainConfig.cxx} (69%) rename src/{ => config}/ReplayGainConfig.hxx (89%) diff --git a/meson.build b/meson.build index 1716898c7..829dbcbe9 100644 --- a/meson.build +++ b/meson.build @@ -281,6 +281,7 @@ sources = [ 'src/command/CommandListBuilder.cxx', 'src/config/PartitionConfig.cxx', 'src/config/PlayerConfig.cxx', + 'src/config/ReplayGainConfig.cxx', 'src/Idle.cxx', 'src/IdleFlags.cxx', 'src/decoder/Thread.cxx', @@ -336,7 +337,6 @@ sources = [ 'src/queue/PlaylistEdit.cxx', 'src/queue/PlaylistTag.cxx', 'src/queue/PlaylistState.cxx', - 'src/ReplayGainGlobal.cxx', 'src/LocateUri.cxx', 'src/SongUpdate.cxx', 'src/SongLoader.cxx', diff --git a/src/ReplayGainGlobal.hxx b/src/ReplayGainGlobal.hxx deleted file mode 100644 index bb4c413a7..000000000 --- a/src/ReplayGainGlobal.hxx +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2003-2021 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_REPLAY_GAIN_GLOBAL_HXX -#define MPD_REPLAY_GAIN_GLOBAL_HXX - -struct ConfigData; -struct ReplayGainConfig; - -ReplayGainConfig -LoadReplayGainConfig(const ConfigData &config); - -#endif diff --git a/src/ReplayGainInfo.cxx b/src/ReplayGainInfo.cxx index 1e2dfa0df..dfe0eb266 100644 --- a/src/ReplayGainInfo.cxx +++ b/src/ReplayGainInfo.cxx @@ -18,7 +18,7 @@ */ #include "ReplayGainInfo.hxx" -#include "ReplayGainConfig.hxx" +#include "config/ReplayGainConfig.hxx" #include diff --git a/src/config/PlayerConfig.cxx b/src/config/PlayerConfig.cxx index 206420949..80e4319e3 100644 --- a/src/config/PlayerConfig.cxx +++ b/src/config/PlayerConfig.cxx @@ -25,13 +25,13 @@ #include "util/RuntimeError.hxx" #include "Log.hxx" #include "MusicChunk.hxx" -#include "ReplayGainGlobal.hxx" static constexpr size_t MIN_BUFFER_SIZE = std::max(CHUNK_SIZE * 32, 64 * KILOBYTE); PlayerConfig::PlayerConfig(const ConfigData &config) + :replay_gain(config) { size_t buffer_size = PlayerConfig::DEFAULT_BUFFER_SIZE; if (auto *param = config.GetParam(ConfigOption::AUDIO_BUFFER_SIZE)) { @@ -62,6 +62,4 @@ PlayerConfig::PlayerConfig(const ConfigData &config) return ParseAudioFormat(s, true); }); - - replay_gain = LoadReplayGainConfig(config); } diff --git a/src/ReplayGainGlobal.cxx b/src/config/ReplayGainConfig.cxx similarity index 69% rename from src/ReplayGainGlobal.cxx rename to src/config/ReplayGainConfig.cxx index 1267962cb..a4839e33e 100644 --- a/src/ReplayGainGlobal.cxx +++ b/src/config/ReplayGainConfig.cxx @@ -17,9 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "ReplayGainGlobal.hxx" #include "ReplayGainConfig.hxx" -#include "config/Data.hxx" +#include "Data.hxx" #include #include @@ -42,25 +41,18 @@ ParsePreamp(const char *s) return std::pow(10.0f, f / 20.0f); } -ReplayGainConfig -LoadReplayGainConfig(const ConfigData &config) +ReplayGainConfig::ReplayGainConfig(const ConfigData &config) + :preamp(config.With(ConfigOption::REPLAYGAIN_PREAMP, [](const char *s){ + return s != nullptr + ? ParsePreamp(s) + : 1.0f; + })), + missing_preamp(config.With(ConfigOption::REPLAYGAIN_MISSING_PREAMP, [](const char *s){ + return s != nullptr + ? ParsePreamp(s) + : 1.0f; + })), + limit(config.GetBool(ConfigOption::REPLAYGAIN_LIMIT, + ReplayGainConfig::DEFAULT_LIMIT)) { - ReplayGainConfig replay_gain_config; - - replay_gain_config.preamp = config.With(ConfigOption::REPLAYGAIN_PREAMP, [](const char *s){ - return s != nullptr - ? ParsePreamp(s) - : 1.0f; - }); - - replay_gain_config.missing_preamp = config.With(ConfigOption::REPLAYGAIN_MISSING_PREAMP, [](const char *s){ - return s != nullptr - ? ParsePreamp(s) - : 1.0f; - }); - - replay_gain_config.limit = config.GetBool(ConfigOption::REPLAYGAIN_LIMIT, - ReplayGainConfig::DEFAULT_LIMIT); - - return replay_gain_config; } diff --git a/src/ReplayGainConfig.hxx b/src/config/ReplayGainConfig.hxx similarity index 89% rename from src/ReplayGainConfig.hxx rename to src/config/ReplayGainConfig.hxx index 8f9194a91..2adfe2f2e 100644 --- a/src/ReplayGainConfig.hxx +++ b/src/config/ReplayGainConfig.hxx @@ -17,8 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef MPD_REPLAY_GAIN_CONFIG_HXX -#define MPD_REPLAY_GAIN_CONFIG_HXX +#pragma once + +struct ConfigData; struct ReplayGainConfig { static constexpr bool DEFAULT_LIMIT = true; @@ -28,6 +29,8 @@ struct ReplayGainConfig { float missing_preamp = 1.0; bool limit = DEFAULT_LIMIT; -}; -#endif + ReplayGainConfig() = default; + + explicit ReplayGainConfig(const ConfigData &config); +}; diff --git a/src/decoder/Control.hxx b/src/decoder/Control.hxx index 27d302875..26ff047d2 100644 --- a/src/decoder/Control.hxx +++ b/src/decoder/Control.hxx @@ -28,7 +28,7 @@ #include "thread/Cond.hxx" #include "thread/Thread.hxx" #include "Chrono.hxx" -#include "ReplayGainConfig.hxx" +#include "config/ReplayGainConfig.hxx" #include "ReplayGainMode.hxx" #include diff --git a/src/filter/plugins/ReplayGainFilterPlugin.cxx b/src/filter/plugins/ReplayGainFilterPlugin.cxx index 3c2f6b351..7706be8ad 100644 --- a/src/filter/plugins/ReplayGainFilterPlugin.cxx +++ b/src/filter/plugins/ReplayGainFilterPlugin.cxx @@ -21,7 +21,7 @@ #include "filter/Filter.hxx" #include "filter/Prepared.hxx" #include "ReplayGainInfo.hxx" -#include "ReplayGainConfig.hxx" +#include "config/ReplayGainConfig.hxx" #include "mixer/MixerControl.hxx" #include "pcm/AudioFormat.hxx" #include "pcm/Volume.hxx"