Skip to content

Commit

Permalink
Apply command line arguments _after_ sewttings from configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebrady committed May 20, 2015
1 parent 6bd14a6 commit 744214d
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions audio_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ static int init(int argc, char **argv, config_t *cfgp) {
int value;

int hardware_mixer = 0;

// get settings from settings file first, allow them to be over-ridden by command line options

if (cfgp!=NULL) {
/* Get the Output Device Name. */
if(config_lookup_string(cfgp, "alsa.output_device", &str)) {
alsa_out_dev = (char*)str;
}

/* Get the Mixer Type setting. */
if(config_lookup_string(cfgp, "alsa.mixer_type", &str)) {
if (strcasecmp(str,"software")==0)
hardware_mixer=0;
else if (strcasecmp(str,"hardware")==0)
hardware_mixer=1;
else
die("Invalid alsa mixer option choice \"%s\". It should be \"software\" or \"hardware\"");
}

/* Get the Mixer Device Name. */
if(config_lookup_string(cfgp, "alsa.mixer_device", &str)) {
alsa_mix_dev = (char*)str;
}

/* Get the Mixer Control Name. */
if(config_lookup_string(cfgp, "alsa.mixer_control_name", &str)) {
alsa_mix_ctrl = (char*)str;
}

}

optind = 1; // optind=0 is equivalent to optind=1 plus special behaviour
argv--; // so we shift the arguments to satisfy getopt()
Expand Down Expand Up @@ -131,34 +161,6 @@ static int init(int argc, char **argv, config_t *cfgp) {
if (optind < argc)
die("Invalid audio argument: %s", argv[optind]);

if (cfgp!=NULL) {
/* Get the Output Device Name. */
if(config_lookup_string(cfgp, "alsa.output_device", &str)) {
alsa_out_dev = (char*)str;
}

/* Get the Mixer Type setting. */
if(config_lookup_string(cfgp, "alsa.mixer_type", &str)) {
if (strcasecmp(str,"software")==0)
hardware_mixer=0;
else if (strcasecmp(str,"hardware")==0)
hardware_mixer=1;
else
die("Invalid alsa mixer option choice \"%s\". It should be \"software\" or \"hardware\"");
}

/* Get the Mixer Device Name. */
if(config_lookup_string(cfgp, "alsa.mixer_device", &str)) {
alsa_mix_dev = (char*)str;
}

/* Get the Mixer Control Name. */
if(config_lookup_string(cfgp, "alsa.mixer_control_name", &str)) {
alsa_mix_ctrl = (char*)str;
}

}

if (!hardware_mixer)
return 0;

Expand Down

0 comments on commit 744214d

Please sign in to comment.