filter/ReplayGain: add method _set_mode()
Push the new mode to the filter instead of accessing global variables through replay_gain_get_real_mode().
This commit is contained in:
parent
7be33eba48
commit
1a8ef3cdab
@ -480,6 +480,8 @@ int mpd_main(int argc, char *argv[])
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(g_playlist.queue.random));
|
||||
|
||||
success = config_get_bool(CONF_AUTO_UPDATE, false);
|
||||
#ifdef ENABLE_INOTIFY
|
||||
if (success && mapper_has_music_directory())
|
||||
|
@ -273,6 +273,13 @@ audio_output_all_update(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
audio_output_all_set_replay_gain_mode(enum replay_gain_mode mode)
|
||||
{
|
||||
for (unsigned i = 0; i < num_audio_outputs; ++i)
|
||||
audio_output_set_replay_gain_mode(audio_outputs[i], mode);
|
||||
}
|
||||
|
||||
bool
|
||||
audio_output_all_play(struct music_chunk *chunk, GError **error_r)
|
||||
{
|
||||
|
@ -27,6 +27,7 @@ extern "C" {
|
||||
#include "mixer_control.h"
|
||||
#include "mixer_plugin.h"
|
||||
#include "notify.h"
|
||||
#include "filter/replay_gain_filter_plugin.h"
|
||||
}
|
||||
|
||||
#include "filter_plugin.h"
|
||||
@ -95,6 +96,14 @@ ao_lock_command(struct audio_output *ao, enum audio_output_command cmd)
|
||||
g_mutex_unlock(ao->mutex);
|
||||
}
|
||||
|
||||
void
|
||||
audio_output_set_replay_gain_mode(struct audio_output *ao,
|
||||
enum replay_gain_mode mode)
|
||||
{
|
||||
if (ao->replay_gain_filter != NULL)
|
||||
replay_gain_filter_set_mode(ao->replay_gain_filter, mode);
|
||||
}
|
||||
|
||||
void
|
||||
audio_output_enable(struct audio_output *ao)
|
||||
{
|
||||
|
@ -20,6 +20,8 @@
|
||||
#ifndef MPD_OUTPUT_CONTROL_HXX
|
||||
#define MPD_OUTPUT_CONTROL_HXX
|
||||
|
||||
#include "replay_gain_info.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <stddef.h>
|
||||
@ -36,6 +38,10 @@ audio_output_quark(void)
|
||||
return g_quark_from_static_string("audio_output");
|
||||
}
|
||||
|
||||
void
|
||||
audio_output_set_replay_gain_mode(struct audio_output *ao,
|
||||
enum replay_gain_mode mode);
|
||||
|
||||
/**
|
||||
* Enables the device.
|
||||
*/
|
||||
|
@ -31,6 +31,7 @@ extern "C" {
|
||||
#include "audio_format.h"
|
||||
#include "volume.h"
|
||||
#include "replay_gain_config.h"
|
||||
#include "output_all.h"
|
||||
}
|
||||
|
||||
#include "PlayerControl.hxx"
|
||||
@ -280,6 +281,7 @@ handle_random(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
||||
return COMMAND_RETURN_ERROR;
|
||||
|
||||
playlist_set_random(&client->playlist, client->player_control, status);
|
||||
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client->playlist.queue.random));
|
||||
return COMMAND_RETURN_OK;
|
||||
}
|
||||
|
||||
@ -386,6 +388,8 @@ handle_replay_gain_mode(Client *client,
|
||||
return COMMAND_RETURN_ERROR;
|
||||
}
|
||||
|
||||
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client->playlist.queue.random));
|
||||
|
||||
return COMMAND_RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -136,14 +136,15 @@ void replay_gain_global_init(void)
|
||||
replay_gain_limit = config_get_bool(CONF_REPLAYGAIN_LIMIT, DEFAULT_REPLAYGAIN_LIMIT);
|
||||
}
|
||||
|
||||
enum replay_gain_mode replay_gain_get_real_mode(void)
|
||||
enum replay_gain_mode
|
||||
replay_gain_get_real_mode(bool random_mode)
|
||||
{
|
||||
enum replay_gain_mode rgm;
|
||||
|
||||
rgm = replay_gain_mode;
|
||||
|
||||
if (rgm == REPLAY_GAIN_AUTO)
|
||||
rgm = g_playlist.queue.random ? REPLAY_GAIN_TRACK : REPLAY_GAIN_ALBUM;
|
||||
rgm = random_mode ? REPLAY_GAIN_TRACK : REPLAY_GAIN_ALBUM;
|
||||
|
||||
return rgm;
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ replay_gain_filter_init(G_GNUC_UNUSED const struct config_param *param,
|
||||
filter_init(&filter->filter, &replay_gain_filter_plugin);
|
||||
filter->mixer = NULL;
|
||||
|
||||
filter->mode = replay_gain_get_real_mode();
|
||||
filter->mode = REPLAY_GAIN_OFF;
|
||||
replay_gain_info_init(&filter->info);
|
||||
filter->volume = PCM_VOLUME_1;
|
||||
|
||||
@ -164,16 +164,6 @@ replay_gain_filter_filter(struct filter *_filter,
|
||||
(struct replay_gain_filter *)_filter;
|
||||
bool success;
|
||||
void *dest;
|
||||
enum replay_gain_mode rg_mode;
|
||||
|
||||
/* check if the mode has been changed since the last call */
|
||||
rg_mode = replay_gain_get_real_mode();
|
||||
|
||||
if (filter->mode != rg_mode) {
|
||||
g_debug("replay gain mode has changed %d->%d\n", filter->mode, rg_mode);
|
||||
filter->mode = rg_mode;
|
||||
replay_gain_filter_update(filter);
|
||||
}
|
||||
|
||||
*dest_size_r = src_size;
|
||||
|
||||
@ -243,3 +233,19 @@ replay_gain_filter_set_info(struct filter *_filter,
|
||||
|
||||
replay_gain_filter_update(filter);
|
||||
}
|
||||
|
||||
void
|
||||
replay_gain_filter_set_mode(struct filter *_filter, enum replay_gain_mode mode)
|
||||
{
|
||||
struct replay_gain_filter *filter =
|
||||
(struct replay_gain_filter *)_filter;
|
||||
|
||||
if (mode == filter->mode)
|
||||
/* no change */
|
||||
return;
|
||||
|
||||
g_debug("replay gain mode has changed %d->%d\n", filter->mode, mode);
|
||||
|
||||
filter->mode = mode;
|
||||
replay_gain_filter_update(filter);
|
||||
}
|
||||
|
@ -47,4 +47,7 @@ void
|
||||
replay_gain_filter_set_info(struct filter *filter,
|
||||
const struct replay_gain_info *info);
|
||||
|
||||
void
|
||||
replay_gain_filter_set_mode(struct filter *filter, enum replay_gain_mode mode);
|
||||
|
||||
#endif
|
||||
|
@ -26,6 +26,7 @@
|
||||
#ifndef OUTPUT_ALL_H
|
||||
#define OUTPUT_ALL_H
|
||||
|
||||
#include "replay_gain_info.h"
|
||||
#include "gerror.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
@ -102,6 +103,9 @@ audio_output_all_close(void);
|
||||
void
|
||||
audio_output_all_release(void);
|
||||
|
||||
void
|
||||
audio_output_all_set_replay_gain_mode(enum replay_gain_mode mode);
|
||||
|
||||
/**
|
||||
* Enqueue a #music_chunk object for playing, i.e. pushes it to a
|
||||
* #music_pipe.
|
||||
|
@ -50,6 +50,6 @@ replay_gain_set_mode_string(const char *p);
|
||||
* Returns the "real" mode according to the "auto" setting"
|
||||
*/
|
||||
enum replay_gain_mode
|
||||
replay_gain_get_real_mode(void);
|
||||
replay_gain_get_real_mode(bool random_mode);
|
||||
|
||||
#endif
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "pcm_volume.h"
|
||||
#include "idle.h"
|
||||
#include "mixer_control.h"
|
||||
#include "Playlist.hxx"
|
||||
#include "stdbin.h"
|
||||
|
||||
#include <glib.h>
|
||||
@ -35,8 +34,6 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct playlist g_playlist;
|
||||
|
||||
void
|
||||
idle_add(G_GNUC_UNUSED unsigned flags)
|
||||
{
|
||||
|
@ -32,7 +32,6 @@ extern "C" {
|
||||
#include "idle.h"
|
||||
}
|
||||
|
||||
#include "Playlist.hxx"
|
||||
#include "PlayerControl.hxx"
|
||||
#include "stdbin.h"
|
||||
|
||||
@ -43,8 +42,6 @@ extern "C" {
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct playlist g_playlist;
|
||||
|
||||
void
|
||||
idle_add(G_GNUC_UNUSED unsigned flags)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user