aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tinyalsa/asoundlib.h4
-rw-r--r--mixer.c34
-rw-r--r--tinymix.c12
3 files changed, 47 insertions, 3 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 4ee04a3..bd0cdee 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -131,4 +131,8 @@ int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id);
int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value);
int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string);
+/* Determe range of integer mixer controls */
+int mixer_ctl_get_range_min(struct mixer_ctl *ctl);
+int mixer_ctl_get_range_max(struct mixer_ctl *ctl);
+
#endif
diff --git a/mixer.c b/mixer.c
index eedcbb7..2bb37a1 100644
--- a/mixer.c
+++ b/mixer.c
@@ -372,6 +372,40 @@ int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value)
return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
}
+int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
+{
+ struct snd_ctl_elem_value ev;
+
+ if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ 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;
+
+ return ctl->info->value.integer.min;
+}
+
+int mixer_ctl_get_range_max(struct mixer_ctl *ctl)
+{
+ struct snd_ctl_elem_value ev;
+
+ if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ 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;
+
+ return ctl->info->value.integer.max;
+}
+
unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl)
{
if (!ctl) {
diff --git a/tinymix.c b/tinymix.c
index 0b834cb..7f593b3 100644
--- a/tinymix.c
+++ b/tinymix.c
@@ -102,6 +102,7 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id)
unsigned int num_values;
char buffer[256];
unsigned int i;
+ int min, max;
if (id >= mixer_get_num_ctls(mixer)) {
fprintf(stderr, "Invalid mixer control\n");
@@ -119,19 +120,24 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id)
switch (type)
{
case MIXER_CTL_TYPE_INT:
- printf("\t%d", mixer_ctl_get_value(ctl, i));
+ printf(" %d", mixer_ctl_get_value(ctl, i));
break;
case MIXER_CTL_TYPE_BOOL:
- printf("\t%s", mixer_ctl_get_value(ctl, i) ? "On" : "Off");
+ printf(" %s", mixer_ctl_get_value(ctl, i) ? "On" : "Off");
break;
case MIXER_CTL_TYPE_ENUM:
tinymix_print_enum(ctl);
break;
default:
- printf("\tunknown");
+ printf(" unknown");
break;
};
}
+ if (type == MIXER_CTL_TYPE_INT) {
+ min = mixer_ctl_get_range_min(ctl);
+ max = mixer_ctl_get_range_max(ctl);
+ printf(" (range %d->%d)", min, max);
+ }
printf("\n");
}