aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-07-06 07:37:37 +0200
committerMax Kellermann <max@duempel.org>2009-07-06 07:37:37 +0200
commit89d4f438c04ad88789322e7cdecb456879c720a7 (patch)
tree48dee3ddcb4c001344193a0e2276f8fb237d90e2
parent8bd7b5b607028f16893871660769e8cbba5a3def (diff)
downloadmpd-89d4f438c04ad88789322e7cdecb456879c720a7.tar.gz
mpd-89d4f438c04ad88789322e7cdecb456879c720a7.tar.xz
mpd-89d4f438c04ad88789322e7cdecb456879c720a7.zip
mixer_type: moved volume_mixer_type from volume.c
-rw-r--r--Makefile.am2
-rw-r--r--src/mixer_type.c38
-rw-r--r--src/mixer_type.h47
-rw-r--r--src/volume.c43
-rw-r--r--src/volume.h4
5 files changed, 109 insertions, 25 deletions
diff --git a/Makefile.am b/Makefile.am
index 92ddcfdf6..3d16ca77d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -94,6 +94,7 @@ mpd_headers = \
src/mixer_list.h \
src/event_pipe.h \
src/mixer_plugin.h \
+ src/mixer_type.h \
src/daemon.h \
src/normalize.h \
src/compress.h \
@@ -515,6 +516,7 @@ OUTPUT_SRC = \
MIXER_API_SRC = \
src/mixer_control.c \
+ src/mixer_type.c \
src/mixer_all.c \
src/mixer_api.c
diff --git a/src/mixer_type.c b/src/mixer_type.c
new file mode 100644
index 000000000..6cf007856
--- /dev/null
+++ b/src/mixer_type.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "mixer_type.h"
+
+#include <assert.h>
+#include <string.h>
+
+enum mixer_type
+mixer_type_parse(const char *input)
+{
+ assert(input != NULL);
+
+ if (strcmp(input, "none") == 0 || strcmp(input, "disabled") == 0)
+ return MIXER_TYPE_NONE;
+ else if (strcmp(input, "hardware") == 0)
+ return MIXER_TYPE_HARDWARE;
+ else if (strcmp(input, "software") == 0)
+ return MIXER_TYPE_SOFTWARE;
+ else
+ return MIXER_TYPE_UNKNOWN;
+}
diff --git a/src/mixer_type.h b/src/mixer_type.h
new file mode 100644
index 000000000..ec3cbf9cc
--- /dev/null
+++ b/src/mixer_type.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_MIXER_TYPE_H
+#define MPD_MIXER_TYPE_H
+
+enum mixer_type {
+ /** parser error */
+ MIXER_TYPE_UNKNOWN,
+
+ /** mixer disabled */
+ MIXER_TYPE_NONE,
+
+ /** software mixer with pcm_volume() */
+ MIXER_TYPE_SOFTWARE,
+
+ /** hardware mixer (output's plugin) */
+ MIXER_TYPE_HARDWARE,
+};
+
+/**
+ * Parses a "mixer_type" setting from the configuration file.
+ *
+ * @param input the configured string value; must not be NULL
+ * @return a #mixer_type value; MIXER_TYPE_UNKNOWN means #input could
+ * not be parsed
+ */
+enum mixer_type
+mixer_type_parse(const char *input);
+
+#endif
diff --git a/src/volume.c b/src/volume.c
index cd3cf9e4b..938a51ac1 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -26,6 +26,7 @@
#include "output_all.h"
#include "mixer_control.h"
#include "mixer_all.h"
+#include "mixer_type.h"
#include <glib.h>
@@ -39,11 +40,7 @@
#define SW_VOLUME_STATE "sw_volume: "
-static enum {
- VOLUME_MIXER_TYPE_SOFTWARE,
- VOLUME_MIXER_TYPE_HARDWARE,
- VOLUME_MIXER_TYPE_DISABLED,
-} volume_mixer_type = VOLUME_MIXER_TYPE_HARDWARE;
+static enum mixer_type volume_mixer_type = MIXER_TYPE_HARDWARE;
static int volume_software_set = 100;
@@ -54,7 +51,7 @@ static GTimer *hardware_volume_timer;
void volume_finish(void)
{
- if (volume_mixer_type == VOLUME_MIXER_TYPE_HARDWARE)
+ if (volume_mixer_type == MIXER_TYPE_HARDWARE)
g_timer_destroy(hardware_volume_timer);
}
@@ -63,21 +60,24 @@ void volume_init(void)
const struct config_param *param = config_get_param(CONF_MIXER_TYPE);
//hw mixing is by default
if (param) {
- if (strcmp(param->value, VOLUME_MIXER_SOFTWARE) == 0) {
- volume_mixer_type = VOLUME_MIXER_TYPE_SOFTWARE;
+ volume_mixer_type = mixer_type_parse(param->value);
+ switch (volume_mixer_type) {
+ case MIXER_TYPE_NONE:
+ case MIXER_TYPE_SOFTWARE:
mixer_disable_all();
- } else if (strcmp(param->value, VOLUME_MIXER_DISABLED) == 0) {
- volume_mixer_type = VOLUME_MIXER_TYPE_DISABLED;
- mixer_disable_all();
- } else if (strcmp(param->value, VOLUME_MIXER_HARDWARE) == 0) {
+ break;
+
+ case MIXER_TYPE_HARDWARE:
//nothing to do
- } else {
+ break;
+
+ case MIXER_TYPE_UNKNOWN:
g_error("unknown mixer type %s at line %i\n",
param->value, param->line);
}
}
- if (volume_mixer_type == VOLUME_MIXER_TYPE_HARDWARE)
+ if (volume_mixer_type == MIXER_TYPE_HARDWARE)
hardware_volume_timer = g_timer_new();
}
@@ -103,11 +103,12 @@ static int software_volume_get(void)
int volume_level_get(void)
{
switch (volume_mixer_type) {
- case VOLUME_MIXER_TYPE_SOFTWARE:
+ case MIXER_TYPE_SOFTWARE:
return software_volume_get();
- case VOLUME_MIXER_TYPE_HARDWARE:
+ case MIXER_TYPE_HARDWARE:
return hardware_volume_get();
- case VOLUME_MIXER_TYPE_DISABLED:
+ case MIXER_TYPE_NONE:
+ case MIXER_TYPE_UNKNOWN:
return -1;
}
@@ -157,9 +158,9 @@ bool volume_level_change(int change, bool rel)
idle_add(IDLE_MIXER);
switch (volume_mixer_type) {
- case VOLUME_MIXER_TYPE_HARDWARE:
+ case MIXER_TYPE_HARDWARE:
return hardware_volume_change(change, rel);
- case VOLUME_MIXER_TYPE_SOFTWARE:
+ case MIXER_TYPE_SOFTWARE:
return software_volume_change(change, rel);
default:
return true;
@@ -172,7 +173,7 @@ void read_sw_volume_state(FILE *fp)
char *end = NULL;
long int sv;
- if (volume_mixer_type != VOLUME_MIXER_TYPE_SOFTWARE)
+ if (volume_mixer_type != MIXER_TYPE_SOFTWARE)
return;
while (fgets(buf, sizeof(buf), fp)) {
if (!g_str_has_prefix(buf, SW_VOLUME_STATE))
@@ -190,6 +191,6 @@ void read_sw_volume_state(FILE *fp)
void save_sw_volume_state(FILE *fp)
{
- if (volume_mixer_type == VOLUME_MIXER_TYPE_SOFTWARE)
+ if (volume_mixer_type == MIXER_TYPE_SOFTWARE)
fprintf(fp, SW_VOLUME_STATE "%d\n", volume_software_set);
}
diff --git a/src/volume.h b/src/volume.h
index 8ab38ce60..d5b9fec19 100644
--- a/src/volume.h
+++ b/src/volume.h
@@ -23,10 +23,6 @@
#include <stdbool.h>
#include <stdio.h>
-#define VOLUME_MIXER_SOFTWARE "software"
-#define VOLUME_MIXER_HARDWARE "hardware"
-#define VOLUME_MIXER_DISABLED "disabled"
-
void volume_init(void);
void volume_finish(void);