ReplayGainGlobal: move replay_gain_mode to struct Partition
This commit is contained in:
parent
fc30e1d559
commit
3472208c05
13
src/Main.cxx
13
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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
/**
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user