aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command.c27
-rw-r--r--src/replay_gain.c21
-rw-r--r--src/replay_gain.h16
3 files changed, 63 insertions, 1 deletions
diff --git a/src/command.c b/src/command.c
index 9a34093b6..0c6538ca9 100644
--- a/src/command.c
+++ b/src/command.c
@@ -44,6 +44,7 @@
#include "client.h"
#include "tag_print.h"
#include "path.h"
+#include "replay_gain.h"
#include "idle.h"
#include "config.h"
@@ -1522,6 +1523,28 @@ handle_listplaylists(struct client *client,
}
static enum command_return
+handle_replay_gain_mode(struct client *client,
+ G_GNUC_UNUSED int argc, char *argv[])
+{
+ if (!replay_gain_set_mode_string(argv[1])) {
+ command_error(client, ACK_ERROR_ARG,
+ "Unrecognized replay gain mode");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ return COMMAND_RETURN_OK;
+}
+
+static enum command_return
+handle_replay_gain_status(struct client *client,
+ G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
+{
+ client_printf(client, "replay_gain_mode: %s\n",
+ replay_gain_get_mode_string());
+ return COMMAND_RETURN_OK;
+}
+
+static enum command_return
handle_idle(struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{
@@ -1765,6 +1788,10 @@ static const struct command commands[] = {
{ "random", PERMISSION_CONTROL, 1, 1, handle_random },
{ "rename", PERMISSION_CONTROL, 2, 2, handle_rename },
{ "repeat", PERMISSION_CONTROL, 1, 1, handle_repeat },
+ { "replay_gain_mode", PERMISSION_CONTROL, 1, 1,
+ handle_replay_gain_mode },
+ { "replay_gain_status", PERMISSION_READ, 0, 0,
+ handle_replay_gain_status },
{ "rescan", PERMISSION_ADMIN, 0, 1, handle_rescan },
{ "rm", PERMISSION_CONTROL, 1, 1, handle_rm },
{ "save", PERMISSION_CONTROL, 1, 1, handle_save },
diff --git a/src/replay_gain.c b/src/replay_gain.c
index 5bfa765fe..a59cfa245 100644
--- a/src/replay_gain.c
+++ b/src/replay_gain.c
@@ -42,7 +42,26 @@ enum replay_gain_mode replay_gain_mode = REPLAY_GAIN_OFF;
static float replay_gain_preamp = 1.0;
static float replay_gain_missing_preamp = 1.0;
-static bool
+const char *
+replay_gain_get_mode_string(void)
+{
+ switch (replay_gain_mode) {
+ case REPLAY_GAIN_OFF:
+ return "off";
+
+ case REPLAY_GAIN_TRACK:
+ return "track";
+
+ case REPLAY_GAIN_ALBUM:
+ return "album";
+ }
+
+ /* unreachable */
+ assert(false);
+ return "off";
+}
+
+bool
replay_gain_set_mode_string(const char *p)
{
assert(p != NULL);
diff --git a/src/replay_gain.h b/src/replay_gain.h
index aa48f3f14..5d0492ad8 100644
--- a/src/replay_gain.h
+++ b/src/replay_gain.h
@@ -23,6 +23,8 @@
#ifndef MPD_REPLAY_GAIN_H
#define MPD_REPLAY_GAIN_H
+#include <stdbool.h>
+
enum replay_gain_mode {
REPLAY_GAIN_OFF = -1,
REPLAY_GAIN_ALBUM,
@@ -52,6 +54,20 @@ void replay_gain_info_free(struct replay_gain_info *info);
void replay_gain_global_init(void);
+/**
+ * Returns the current replay gain mode as a machine-readable string.
+ */
+const char *
+replay_gain_get_mode_string(void);
+
+/**
+ * Sets the replay gain mode, parsed from a string.
+ *
+ * @return true on success, false if the string could not be parsed
+ */
+bool
+replay_gain_set_mode_string(const char *p);
+
void
replay_gain_apply(struct replay_gain_info *info, char *buffer, int bufferSize,
const struct audio_format *format);