aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Wilson <simonwilson@google.com>2011-05-26 18:22:00 -0700
committerSimon Wilson <simonwilson@google.com>2011-05-26 18:22:00 -0700
commita1bb1e0a27aeb853697106bc311c5ca77ab782c1 (patch)
tree2155db040db4ae56b71fa38f5ae7ad1e4cbd64b2
parent542a629f75a0b0ce190b95a2c26842c6b9dfe615 (diff)
mixer: implement mixer_ctl_set/get_int functions
-rw-r--r--mixer.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/mixer.c b/mixer.c
index 9c7e3b5..dc01e99 100644
--- a/mixer.c
+++ b/mixer.c
@@ -236,6 +236,26 @@ static int int_to_percent(struct snd_ctl_elem_info *ei, int value)
int mixer_ctl_get_percent(struct mixer_ctl *ctl)
{
+ if (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return int_to_percent(ctl->info, mixer_ctl_get_int(ctl));
+}
+
+int mixer_ctl_set_percent(struct mixer_ctl *ctl, int percent)
+{
+ if (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return mixer_ctl_set_int(ctl, percent_to_int(ctl->info, percent));
+}
+
+int mixer_ctl_get_int(struct mixer_ctl *ctl)
+{
struct snd_ctl_elem_value ev;
memset(&ev, 0, sizeof(ev));
@@ -247,10 +267,11 @@ int mixer_ctl_get_percent(struct mixer_ctl *ctl)
case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
return !!ev.value.integer.value[0]; /* TODO: handle multiple return values */
break;
- case SNDRV_CTL_ELEM_TYPE_INTEGER: {
- return int_to_percent(ctl->info, ev.value.integer.value[0]);
+
+ case SNDRV_CTL_ELEM_TYPE_INTEGER:
+ return ev.value.integer.value[0]; /* TODO: handle multiple return values */
break;
- }
+
default:
errno = EINVAL;
return -1;
@@ -259,31 +280,30 @@ int mixer_ctl_get_percent(struct mixer_ctl *ctl)
return 0;
}
-int mixer_ctl_set_percent(struct mixer_ctl *ctl, int percent)
+int mixer_ctl_set_int(struct mixer_ctl *ctl, int value)
{
struct snd_ctl_elem_value ev;
unsigned int n;
memset(&ev, 0, sizeof(ev));
ev.id.numid = ctl->info->id.numid;
+
switch (ctl->info->type) {
case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
for (n = 0; n < ctl->info->count; n++)
- ev.value.integer.value[n] = !!percent; /* TODO: handle multiple set values */
+ ev.value.integer.value[n] = !!value;
break;
- case SNDRV_CTL_ELEM_TYPE_INTEGER: {
- int value = percent_to_int(ctl->info, percent);
+ case SNDRV_CTL_ELEM_TYPE_INTEGER:
for (n = 0; n < ctl->info->count; n++)
ev.value.integer.value[n] = value;
break;
- }
default:
errno = EINVAL;
return -1;
}
-
+
return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
}