Partition: add UpdateEffectiveReplayGainMode()

Move code from replay_gain_get_real_mode().
This commit is contained in:
Max Kellermann 2016-11-24 15:18:57 +01:00
parent 9b9144f25d
commit 0759d72108
6 changed files with 22 additions and 23 deletions

View File

@ -517,7 +517,7 @@ try {
glue_state_file_init(); glue_state_file_init();
instance->partition->outputs.SetReplayGainMode(replay_gain_get_real_mode(instance->partition->playlist.queue.random)); instance->partition->UpdateEffectiveReplayGainMode(replay_gain_mode);
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (config_get_bool(ConfigOption::AUTO_UPDATE, false)) { if (config_get_bool(ConfigOption::AUTO_UPDATE, false)) {

View File

@ -42,6 +42,17 @@ Partition::EmitIdle(unsigned mask)
instance.EmitIdle(mask); instance.EmitIdle(mask);
} }
void
Partition::UpdateEffectiveReplayGainMode(ReplayGainMode mode)
{
if (mode == REPLAY_GAIN_AUTO)
mode = playlist.queue.random
? REPLAY_GAIN_TRACK
: REPLAY_GAIN_ALBUM;
outputs.SetReplayGainMode(mode);
}
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Database * const Database *

View File

@ -176,6 +176,14 @@ struct Partition final : QueueListener, PlayerListener, MixerListener {
playlist.SetConsume(new_value); playlist.SetConsume(new_value);
} }
/**
* Publishes the effective #ReplayGainMode to all subsystems.
* #REPLAY_GAIN_AUTO is substituted.
*
* @param mode the configured mode
*/
void UpdateEffectiveReplayGainMode(ReplayGainMode mode);
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
/** /**
* Returns the global #Database instance. May return nullptr * Returns the global #Database instance. May return nullptr

View File

@ -131,16 +131,3 @@ void replay_gain_global_init(void)
replay_gain_limit = config_get_bool(ConfigOption::REPLAYGAIN_LIMIT, replay_gain_limit = config_get_bool(ConfigOption::REPLAYGAIN_LIMIT,
DEFAULT_REPLAYGAIN_LIMIT); DEFAULT_REPLAYGAIN_LIMIT);
} }
ReplayGainMode
replay_gain_get_real_mode(bool random_mode)
{
ReplayGainMode rgm;
rgm = replay_gain_mode;
if (rgm == REPLAY_GAIN_AUTO)
rgm = random_mode ? REPLAY_GAIN_TRACK : REPLAY_GAIN_ALBUM;
return rgm;
}

View File

@ -47,11 +47,4 @@ replay_gain_get_mode_string();
bool bool
replay_gain_set_mode_string(const char *p); replay_gain_set_mode_string(const char *p);
/**
* Returns the "real" mode according to the "auto" setting"
*/
gcc_pure
ReplayGainMode
replay_gain_get_real_mode(bool random_mode);
#endif #endif

View File

@ -263,7 +263,7 @@ handle_random(Client &client, Request args, gcc_unused Response &r)
{ {
bool status = args.ParseBool(0); bool status = args.ParseBool(0);
client.partition.SetRandom(status); client.partition.SetRandom(status);
client.partition.outputs.SetReplayGainMode(replay_gain_get_real_mode(client.partition.GetRandom())); client.partition.UpdateEffectiveReplayGainMode(replay_gain_mode);
return CommandResult::OK; return CommandResult::OK;
} }
@ -338,7 +338,7 @@ handle_replay_gain_mode(Client &client, Request args, Response &r)
return CommandResult::ERROR; return CommandResult::ERROR;
} }
client.partition.outputs.SetReplayGainMode(replay_gain_get_real_mode(client.playlist.queue.random)); client.partition.UpdateEffectiveReplayGainMode(replay_gain_mode);
client.partition.EmitIdle(IDLE_OPTIONS); client.partition.EmitIdle(IDLE_OPTIONS);
return CommandResult::OK; return CommandResult::OK;
} }