alsactl init - allow enum specification by name strings

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2008-08-14 11:21:59 +02:00
parent 24fe765fa6
commit 11684b3c8b
2 changed files with 36 additions and 7 deletions

View file

@ -16,7 +16,7 @@ CTL{name}="Front Playback Volume", CTL{value}="35,35"
CTL{name}="Front Playback Switch", CTL{value}="on,on" CTL{name}="Front Playback Switch", CTL{value}="on,on"
CTL{name}="PCM Playback Volume", CTL{value}="150,150" CTL{name}="PCM Playback Volume", CTL{value}="150,150"
# capture # capture
CTL{name}="Input Source", CTL{value}="0" CTL{name}="Input Source", CTL{value}="Mic"
CTL{name}="Capture Volume", CTL{value}="65,65" CTL{name}="Capture Volume", CTL{value}="65,65"
CTL{name}="Capture Switch", CTL{value}="on,on" CTL{name}="Capture Switch", CTL{value}="on,on"
RESULT="true", EXIT="return" RESULT="true", EXIT="return"
@ -26,8 +26,8 @@ LABEL="Lenovo T61"
CTL{reset}="mixer" CTL{reset}="mixer"
CTL{name}="Headphone Playback Switch", CTL{value}="on,on" CTL{name}="Headphone Playback Switch", CTL{value}="on,on"
CTL{name}="PCM Playback Volume", CTL{value}="30,30" CTL{name}="PCM Playback Volume", CTL{value}="30,30"
# capture (Internal Mic) # capture
CTL{name}="Input Source", CTL{value}="1" CTL{name}="Input Source", CTL{value}="Internal Mic"
CTL{name}="Internal Mic Boost", CTL{value}="1" CTL{name}="Internal Mic Boost", CTL{value}="1"
CTL{name}="Capture Volume", CTL{value}="45,45" CTL{name}="Capture Volume", CTL{value}="45,45"
CTL{name}="Capture Switch", CTL{value}="on,on" CTL{name}="Capture Switch", CTL{value}="on,on"

View file

@ -333,8 +333,9 @@ static const char *get_ctl_value(struct space *space)
static int set_ctl_value(struct space *space, const char *value) static int set_ctl_value(struct space *space, const char *value)
{ {
snd_ctl_elem_type_t type; snd_ctl_elem_type_t type;
unsigned int idx, count; unsigned int idx, idx2, count, items;
const char *pos; const char *pos;
snd_hctl_elem_t *elem;
int val; int val;
type = snd_ctl_elem_info_get_type(space->ctl_info); type = snd_ctl_elem_info_get_type(space->ctl_info);
@ -377,8 +378,32 @@ static int set_ctl_value(struct space *space, const char *value)
for (idx = 0; idx < count; idx++) { for (idx = 0; idx < count; idx++) {
while (*value == ' ') while (*value == ' ')
value++; value++;
snd_ctl_elem_value_set_enumerated(space->ctl_value, idx, strtol(value, NULL, 0));
pos = strchr(value, ','); pos = strchr(value, ',');
if (isdigit(value[0]) || value[0] == '-') {
snd_ctl_elem_value_set_enumerated(space->ctl_value, idx, strtol(value, NULL, 0));
} else {
if (pos)
*(char *)pos = '\0';
remove_trailing_chars((char *)value, ' ');
items = snd_ctl_elem_info_get_items(space->ctl_info);
for (idx2 = 0; idx2 < items; idx2++) {
snd_ctl_elem_info_set_item(space->ctl_info, idx);
elem = snd_hctl_find_elem(space->ctl_handle, space->ctl_id);
if (elem == NULL)
return -ENOENT;
val = snd_hctl_elem_info(elem, space->ctl_info);
if (val < 0)
return val;
if (strcasecmp(snd_ctl_elem_info_get_item_name(space->ctl_info), value) == 0) {
snd_ctl_elem_value_set_enumerated(space->ctl_value, idx, idx2);
break;
}
}
if (idx2 >= items) {
Perror(space, "wrong enum identifier '%s'", value);
return -EINVAL;
}
}
value = pos ? pos + 1 : value + strlen(value) - 1; value = pos ? pos + 1 : value + strlen(value) - 1;
} }
break; break;
@ -389,14 +414,14 @@ static int set_ctl_value(struct space *space, const char *value)
while (*value == ' ') while (*value == ' ')
value++; value++;
if (strlen(value) != count * 2) { if (strlen(value) != count * 2) {
Perror(space, "bad ctl value hexa length (should be %u bytes, line %i)", count, space->linenum); Perror(space, "bad ctl value hexa length (should be %u bytes)", count);
return -EINVAL; return -EINVAL;
} }
for (idx = 0; idx < count; idx += 2) { for (idx = 0; idx < count; idx += 2) {
val = hextodigit(*(value++)) << 4; val = hextodigit(*(value++)) << 4;
val |= hextodigit(*(value++)); val |= hextodigit(*(value++));
if (val > 255) { if (val > 255) {
Perror(space, "bad ctl hexa value (line %i)", space->linenum); Perror(space, "bad ctl hexa value");
return -EINVAL; return -EINVAL;
} }
snd_ctl_elem_value_set_byte(space->ctl_value, idx, val); snd_ctl_elem_value_set_byte(space->ctl_value, idx, val);
@ -1371,6 +1396,8 @@ static int parse_line(struct space *space, char *line, size_t linesize)
Perror(space, "unterminated GOTO '%s'", space->go_to); Perror(space, "unterminated GOTO '%s'", space->go_to);
free(space->go_to); free(space->go_to);
} }
if (err)
break;
} }
closedir(dir); closedir(dir);
} else { } else {
@ -1392,6 +1419,8 @@ static int parse_line(struct space *space, char *line, size_t linesize)
space->linenum = linenum; space->linenum = linenum;
if (space->quit) if (space->quit)
break; break;
if (err)
break;
continue; continue;
} }
if (strncasecmp(key, "ACCESS", 6) == 0) { if (strncasecmp(key, "ACCESS", 6) == 0) {