diff --git a/src/Main.cxx b/src/Main.cxx index 40df1798b..8e576787b 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -57,6 +57,7 @@ #include "config/ConfigOption.hxx" #include "config/ConfigError.hxx" #include "Stats.hxx" +#include "util/RuntimeError.hxx" #ifdef ENABLE_DAEMON #include "unix/Daemon.hxx" @@ -331,6 +332,16 @@ initialize_decoder_and_player(void) buffered_chunks, buffered_before_play, replay_gain_config); + + try { + param = config_get_param(ConfigOption::REPLAYGAIN); + if (param != nullptr) + instance->partition->replay_gain_mode = + FromString(param->value.c_str()); + } catch (...) { + std::throw_with_nested(FormatRuntimeError("Failed to parse line %i", + param->line)); + } } void @@ -519,8 +530,6 @@ try { glue_state_file_init(); - instance->partition->UpdateEffectiveReplayGainMode(replay_gain_mode); - #ifdef ENABLE_DATABASE if (config_get_bool(ConfigOption::AUTO_UPDATE, false)) { #ifdef ENABLE_INOTIFY diff --git a/src/Partition.cxx b/src/Partition.cxx index 8a55e7d28..b3dc9b73d 100644 --- a/src/Partition.cxx +++ b/src/Partition.cxx @@ -36,6 +36,7 @@ Partition::Partition(Instance &_instance, pc(*this, outputs, buffer_chunks, buffered_before_play, replay_gain_config) { + UpdateEffectiveReplayGainMode(); } void @@ -45,8 +46,9 @@ Partition::EmitIdle(unsigned mask) } void -Partition::UpdateEffectiveReplayGainMode(ReplayGainMode mode) +Partition::UpdateEffectiveReplayGainMode() { + auto mode = replay_gain_mode; if (mode == ReplayGainMode::AUTO) mode = playlist.queue.random ? ReplayGainMode::TRACK diff --git a/src/Partition.hxx b/src/Partition.hxx index 161b6dbf5..c7fda3055 100644 --- a/src/Partition.hxx +++ b/src/Partition.hxx @@ -27,6 +27,7 @@ #include "mixer/Listener.hxx" #include "player/Control.hxx" #include "player/Listener.hxx" +#include "ReplayGainMode.hxx" #include "Chrono.hxx" #include "Compiler.h" @@ -52,6 +53,8 @@ struct Partition final : QueueListener, PlayerListener, MixerListener { PlayerControl pc; + ReplayGainMode replay_gain_mode = ReplayGainMode::OFF; + Partition(Instance &_instance, unsigned max_length, unsigned buffer_chunks, @@ -177,13 +180,16 @@ struct Partition final : QueueListener, PlayerListener, MixerListener { playlist.SetConsume(new_value); } + void SetReplayGainMode(ReplayGainMode mode) { + replay_gain_mode = mode; + UpdateEffectiveReplayGainMode(); + } + /** * Publishes the effective #ReplayGainMode to all subsystems. * #ReplayGainMode::AUTO is substituted. - * - * @param mode the configured mode */ - void UpdateEffectiveReplayGainMode(ReplayGainMode mode); + void UpdateEffectiveReplayGainMode(); #ifdef ENABLE_DATABASE /** diff --git a/src/ReplayGainGlobal.cxx b/src/ReplayGainGlobal.cxx index a345c82a0..a0c252306 100644 --- a/src/ReplayGainGlobal.cxx +++ b/src/ReplayGainGlobal.cxx @@ -28,7 +28,6 @@ #include #include -ReplayGainMode replay_gain_mode = ReplayGainMode::OFF; ReplayGainConfig replay_gain_config; static float @@ -60,17 +59,7 @@ ParsePreamp(const ConfigParam &p) void replay_gain_global_init(void) { - const auto *param = config_get_param(ConfigOption::REPLAYGAIN); - - try { - if (param != nullptr) - replay_gain_mode = FromString(param->value.c_str()); - } catch (...) { - std::throw_with_nested(FormatRuntimeError("Failed to parse line %i", - param->line)); - } - - param = config_get_param(ConfigOption::REPLAYGAIN_PREAMP); + const auto *param = config_get_param(ConfigOption::REPLAYGAIN_PREAMP); if (param) replay_gain_config.preamp = ParsePreamp(*param); diff --git a/src/ReplayGainGlobal.hxx b/src/ReplayGainGlobal.hxx index 9f73472e6..2fc881f06 100644 --- a/src/ReplayGainGlobal.hxx +++ b/src/ReplayGainGlobal.hxx @@ -21,12 +21,9 @@ #define MPD_REPLAY_GAIN_GLOBAL_HXX #include "check.h" -#include "ReplayGainMode.hxx" struct ReplayGainConfig; -extern ReplayGainMode replay_gain_mode; - extern ReplayGainConfig replay_gain_config; void diff --git a/src/command/PlayerCommands.cxx b/src/command/PlayerCommands.cxx index 76da257e1..ec4142b7b 100644 --- a/src/command/PlayerCommands.cxx +++ b/src/command/PlayerCommands.cxx @@ -30,7 +30,6 @@ #include "Instance.hxx" #include "Idle.hxx" #include "AudioFormat.hxx" -#include "ReplayGainGlobal.hxx" #include "util/ScopeExit.hxx" #ifdef ENABLE_DATABASE @@ -263,7 +262,7 @@ handle_random(Client &client, Request args, gcc_unused Response &r) { bool status = args.ParseBool(0); client.partition.SetRandom(status); - client.partition.UpdateEffectiveReplayGainMode(replay_gain_mode); + client.partition.UpdateEffectiveReplayGainMode(); return CommandResult::OK; } @@ -333,16 +332,17 @@ handle_mixrampdelay(Client &client, Request args, gcc_unused Response &r) CommandResult handle_replay_gain_mode(Client &client, Request args, Response &) { - replay_gain_mode = FromString(args.front()); - client.partition.UpdateEffectiveReplayGainMode(replay_gain_mode); + auto new_mode = FromString(args.front()); + client.partition.SetReplayGainMode(new_mode); client.partition.EmitIdle(IDLE_OPTIONS); return CommandResult::OK; } CommandResult -handle_replay_gain_status(gcc_unused Client &client, gcc_unused Request args, +handle_replay_gain_status(Client &client, gcc_unused Request args, Response &r) { - r.Format("replay_gain_mode: %s\n", ToString(replay_gain_mode)); + r.Format("replay_gain_mode: %s\n", + ToString(client.partition.replay_gain_mode)); return CommandResult::OK; }