configure.ac: Move the encoders before the audio outputs.
[mpd-mk.git] / src / replay_gain_config.c
blob3eae9d960020185adc266d471111629f24389c80
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "config.h"
21 #include "replay_gain_config.h"
22 #include "conf.h"
23 #include "idle.h"
25 #include <glib.h>
27 #include <assert.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <math.h>
32 static const char *const replay_gain_mode_names[] = {
33 [REPLAY_GAIN_ALBUM] = "album",
34 [REPLAY_GAIN_TRACK] = "track",
37 enum replay_gain_mode replay_gain_mode = REPLAY_GAIN_OFF;
39 float replay_gain_preamp = 1.0;
40 float replay_gain_missing_preamp = 1.0;
42 const char *
43 replay_gain_get_mode_string(void)
45 switch (replay_gain_mode) {
46 case REPLAY_GAIN_AUTO:
47 return "auto";
49 case REPLAY_GAIN_OFF:
50 return "off";
52 case REPLAY_GAIN_TRACK:
53 return "track";
55 case REPLAY_GAIN_ALBUM:
56 return "album";
59 /* unreachable */
60 assert(false);
61 return "off";
64 bool
65 replay_gain_set_mode_string(const char *p)
67 assert(p != NULL);
69 if (strcmp(p, "off") == 0)
70 replay_gain_mode = REPLAY_GAIN_OFF;
71 else if (strcmp(p, "track") == 0)
72 replay_gain_mode = REPLAY_GAIN_TRACK;
73 else if (strcmp(p, "album") == 0)
74 replay_gain_mode = REPLAY_GAIN_ALBUM;
75 else if (strcmp(p, "auto") == 0)
76 replay_gain_mode = REPLAY_GAIN_AUTO;
77 else
78 return false;
80 idle_add(IDLE_OPTIONS);
82 return true;
85 void replay_gain_global_init(void)
87 const struct config_param *param = config_get_param(CONF_REPLAYGAIN);
89 if (param != NULL && !replay_gain_set_mode_string(param->value)) {
90 g_error("replaygain value \"%s\" at line %i is invalid\n",
91 param->value, param->line);
94 param = config_get_param(CONF_REPLAYGAIN_PREAMP);
96 if (param) {
97 char *test;
98 float f = strtod(param->value, &test);
100 if (*test != '\0') {
101 g_error("Replaygain preamp \"%s\" is not a number at "
102 "line %i\n", param->value, param->line);
105 if (f < -15 || f > 15) {
106 g_error("Replaygain preamp \"%s\" is not between -15 and"
107 "15 at line %i\n", param->value, param->line);
110 replay_gain_preamp = pow(10, f / 20.0);
113 param = config_get_param(CONF_REPLAYGAIN_MISSING_PREAMP);
115 if (param) {
116 char *test;
117 float f = strtod(param->value, &test);
119 if (*test != '\0') {
120 g_error("Replaygain missing preamp \"%s\" is not a number at "
121 "line %i\n", param->value, param->line);
124 if (f < -15 || f > 15) {
125 g_error("Replaygain missing preamp \"%s\" is not between -15 and"
126 "15 at line %i\n", param->value, param->line);
129 replay_gain_missing_preamp = pow(10, f / 20.0);