diff options
author | Takashi Iwai <tiwai@suse.de> | 2013-01-16 12:29:43 +0100 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2013-01-16 12:30:33 +0100 |
commit | 45e66120b51a92ddf99ea43432108e94e9828482 (patch) | |
tree | 45b2dd0b078ae733711143e3a461fe910bb729d0 | |
parent | f9b70e7ea4835f06807c57f5a42954ac9b4643e7 (diff) | |
download | hda-emu-45e66120b51a92ddf99ea43432108e94e9828482.tar.gz |
Allow passing name string to get/set argument
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | README | 22 | ||||
-rw-r--r-- | hda-ctlsh.c | 72 |
2 files changed, 89 insertions, 5 deletions
@@ -122,12 +122,32 @@ BASIC COMMANDS integer value between 0 and 31, and its current values are 0 and 0 (usually for left and right channels). + Instead of the numid, you can pass the name string of the control + element. Use single- or double quotes around the name. + + > get "Master Playback Volume" + 1 Master Playback Volume:0 + MIN/MAX: 0/31, VAL: [0] [0] + + If there are multiple control elements with the same name and + different indices, pass the index number with ":" suffix. + + > get "Headphone Playback Switch:1" + 20 Headphone Playback Switch:1 + MIN/MAX: 0/1, VAL: [1] [1] + + * set - Set the control element value. Pass the numid and the value(s). + Set the control element value. Pass the numid or the name string in + the first argument, and pass and the value(s) in the rest. > set 1 10 4 + or + + > set "Master Playback Volume" 10 4 + When the log level is more than 1, you'll see the codec verbs such as diff --git a/hda-ctlsh.c b/hda-ctlsh.c index 04fc318..2b53530 100644 --- a/hda-ctlsh.c +++ b/hda-ctlsh.c @@ -47,14 +47,23 @@ static char *gettoken(char **bufp) { char *p; char *token = *bufp; + char quote = 0; while (*token && isspace(*token)) token++; if (!*token || *token == '\n') return NULL; + if (*token == '\'' || *token == '"') { + quote = *token; + token++; + } p = token; - while (*p && !(isspace(*p) || *p == '\n')) - p++; + for (; *p && *p != '\n'; p++) { + if (*p == quote) + break; + if (!quote && isspace(*p)) + break; + } if (*p) *p++ = 0; *bufp = p; @@ -159,6 +168,35 @@ static void show_db_info(struct snd_kcontrol *kctl, } } +/* name string may be modified */ +static int get_ctl_numid(char *name) +{ + struct snd_kcontrol *kctl = NULL; + struct snd_ctl_elem_id id; + char *p; + + memset(&id, 0, sizeof(id)); + id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + + p = strchr(name, ':'); + if (p) { + id.index = atoi(p + 1); + if (id.index < 0) + goto error; + *p = 0; + } + + strncpy(id.name, name, sizeof(id.name) - 1); + kctl = snd_ctl_find_id(NULL, &id); + + error: + if (p) + *p = ':'; + if (kctl) + return kctl->id.numid; + return 0; +} + static void get_element(char *line) { struct snd_kcontrol *kctl; @@ -166,11 +204,24 @@ static void get_element(char *line) struct snd_ctl_elem_value uval; int numid; int i, err; + char *token; - if (getint(&line, &numid)) { + token = gettoken(&line); + if (!token) { usage("get"); return; } + + if (isdigit(*token)) + numid = strtoul(token, NULL, 0); + else { + numid = get_ctl_numid(token); + if (!numid) { + hda_log(HDA_LOG_INFO, "No element '%s'\n", token); + return; + } + } + kctl = snd_ctl_find_numid(NULL, numid); if (!kctl) { hda_log(HDA_LOG_INFO, "No element %d\n", numid); @@ -238,11 +289,24 @@ static void set_element(char *line) struct snd_ctl_elem_value uval; unsigned int numid; int i, err; + char *token; - if (getint(&line, &numid)) { + token = gettoken(&line); + if (!token) { usage("set"); return; } + + if (isdigit(*token)) + numid = strtoul(token, NULL, 0); + else { + numid = get_ctl_numid(token); + if (!numid) { + hda_log(HDA_LOG_INFO, "No element '%s'\n", token); + return; + } + } + kctl = snd_ctl_find_numid(NULL, numid); if (!kctl) { hda_log(HDA_LOG_INFO, "No element %d\n", numid); |