diff options
author | Simon Wilson <ksattic@gmail.com> | 2011-06-05 21:18:52 -0700 |
---|---|---|
committer | Simon Wilson <ksattic@gmail.com> | 2011-06-05 21:18:52 -0700 |
commit | f0a20ee4ccbba5504bd87397fcf9d9a89467208d (patch) | |
tree | 0db49de15456ae4f240b5560f7c12ab14437fa1d /mixer.c | |
parent | 066c9f6753dff5e2b8556eeaec986651bf835e08 (diff) |
Implement mixer setting in tinymix
- re-add function to set enum type by string
- implement setting of mixer values in tinymix
- fix bug: read current mixer values before writing
Diffstat (limited to 'mixer.c')
-rw-r--r-- | mixer.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -348,6 +348,8 @@ int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value) memset(&ev, 0, sizeof(ev)); ev.id.numid = ctl->info->id.numid; + if (ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev)) + return -1; switch (ctl->info->type) { case SNDRV_CTL_ELEM_TYPE_BOOLEAN: @@ -400,3 +402,29 @@ int mixer_ctl_get_enum_string(struct mixer_ctl *ctl, unsigned int enum_id, return 0; } +int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string) +{ + unsigned int i, num_enums; + struct snd_ctl_elem_value ev; + + if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED)) { + errno = EINVAL; + return -1; + } + + num_enums = ctl->info->value.enumerated.items; + for (i = 0; i < num_enums; i++) { + if (!strcmp(string, ctl->ename[i])) { + memset(&ev, 0, sizeof(ev)); + ev.value.enumerated.item[0] = i; + ev.id.numid = ctl->info->id.numid; + if (ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev) < 0) + return -1; + return 0; + } + } + + errno = EINVAL; + return -1; +} + |