From f0a20ee4ccbba5504bd87397fcf9d9a89467208d Mon Sep 17 00:00:00 2001 From: Simon Wilson Date: Sun, 5 Jun 2011 21:18:52 -0700 Subject: 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 --- tinymix.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'tinymix.c') diff --git a/tinymix.c b/tinymix.c index 68c23d1..bf24a7c 100644 --- a/tinymix.c +++ b/tinymix.c @@ -32,6 +32,8 @@ static void tinymix_list_controls(struct mixer *mixer); static void tinymix_detail_control(struct mixer *mixer, unsigned int id); +static void tinymix_set_value(struct mixer *mixer, unsigned int id, + char *value); int main(int argc, char **argv) { @@ -43,8 +45,10 @@ int main(int argc, char **argv) tinymix_list_controls(mixer); else if (argc == 2) tinymix_detail_control(mixer, atoi(argv[1])); + else if (argc == 3) + tinymix_set_value(mixer, atoi(argv[1]), argv[2]); else - printf("Usage: tinymix [control id]\n"); + printf("Usage: tinymix [control id] [value to set]\n"); mixer_close(mixer); @@ -129,3 +133,34 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id) printf("\n"); } +static void tinymix_set_value(struct mixer *mixer, unsigned int id, + char *string) +{ + struct mixer_ctl *ctl; + enum mixer_ctl_type type; + unsigned int num_values; + unsigned int i; + + ctl = mixer_get_ctl(mixer, id); + type = mixer_ctl_get_type(ctl); + num_values = mixer_ctl_get_num_values(ctl); + + if (isdigit(string[0])) { + int value = atoi(string); + + for (i = 0; i < num_values; i++) { + if (mixer_ctl_set_value(ctl, i, value)) { + fprintf(stderr, "Error: invalid value\n"); + return; + } + } + } else { + if (type == MIXER_CTL_TYPE_ENUM) { + if (mixer_ctl_set_enum_by_string(ctl, string)) + fprintf(stderr, "Error: invalid enum value\n"); + } else { + fprintf(stderr, "Error: only enum types can be set with strings\n"); + } + } +} + -- cgit v1.2.3