Allow sound api to be specified in the config file

This commit is contained in:
Johannes Holmberg 2015-09-16 21:19:47 -04:00 committed by Carlos R. Mafra
parent 7678102e3b
commit 5ca72823d7
2 changed files with 19 additions and 5 deletions

View file

@ -66,7 +66,7 @@ const char default_osd_color[] = "green";
void config_init(void) void config_init(void)
{ {
memset(&config, 0, sizeof(config)); memset(&config, 0, sizeof(config));
config.api = 0; config.api = -1;
config.mixer_device = NULL; config.mixer_device = NULL;
config.mousewheel = 1; config.mousewheel = 1;
config.scrolltext = 1; config.scrolltext = 1;
@ -163,8 +163,10 @@ void parse_cli_options(int argc, char **argv)
case 'a': case 'a':
if(!strcmp("oss", optarg)) if(!strcmp("oss", optarg))
config.api = 1; config.api = 1;
else if (strcmp("alsa", optarg)) else if (!strcmp("alsa", optarg))
fprintf(stderr, "Warning: Incorrect sound api specified, defaulting to alsa\n"); config.api = 0;
else
fprintf(stderr, "wmix:warning: incorrect sound api specified on command line, ignoring\n");
break; break;
case 'd': case 'd':
if (config.display_name) if (config.display_name)
@ -325,7 +327,16 @@ void config_read(void)
*ptr = '\0'; *ptr = '\0';
/* Check what keyword we have */ /* Check what keyword we have */
if (strcmp(keyword, "device") == 0) { if (strcmp(keyword, "api") == 0) {
if (config.api == -1) {
if(!strcmp("oss", value))
config.api = 1;
else if (!strcmp("alsa", value))
config.api = 0;
else
fprintf(stderr, "wmix:warning: incorrect sound api in config, ignoring\n");
}
} else if (strcmp(keyword, "device") == 0) {
if (config.mixer_device == default_mixer_device) if (config.mixer_device == default_mixer_device)
config.mixer_device = strdup(value); config.mixer_device = strdup(value);
/* If not the default, keep the previous value because it was provided in the command-line */ /* If not the default, keep the previous value because it was provided in the command-line */
@ -393,6 +404,9 @@ void config_read(void)
void config_set_defaults() void config_set_defaults()
{ {
if (config.api == -1)
config.api = 0;
if (!config.mixer_device) { if (!config.mixer_device) {
if (config.api == 0) if (config.api == 0)
config.mixer_device = (char *)default_card_name; config.mixer_device = (char *)default_card_name;

View file

@ -28,7 +28,7 @@ extern struct _Config {
char *display_name; /* X Display to connect to */ char *display_name; /* X Display to connect to */
char *mixer_device; /* device file to use for controlling Mixer volumes */ char *mixer_device; /* device file to use for controlling Mixer volumes */
unsigned int api; /* Sound API (0 = ALSA, 1 = OSS) */ int api; /* Sound API (0 = ALSA, 1 = OSS) */
unsigned int verbose : 1; /* be Verbose when starting */ unsigned int verbose : 1; /* be Verbose when starting */
unsigned int osd : 1; /* show OSD? */ unsigned int osd : 1; /* show OSD? */
unsigned int mousewheel : 1; /* mousewheel enabled? */ unsigned int mousewheel : 1; /* mousewheel enabled? */