diff options
author | Misael Lopez Cruz <misael.lopez@ti.com> | 2012-11-07 18:17:21 -0600 |
---|---|---|
committer | Simon Wilson <simonwilson@google.com> | 2012-11-09 13:41:10 -0800 |
commit | bad2b79b02708be69b65faae88f5be331bdf49b6 (patch) | |
tree | 3d1e8ca26ec5050a3be6b10888b4ceef71e9dc37 | |
parent | fcf66ab156a236ba2bb31df7d4d4611b8b7be431 (diff) |
tinymix: Add support for passing control name
Allow mixer controls to be accessed through the name, not only by id.
-rw-r--r-- | tinymix.c | 34 |
1 files changed, 23 insertions, 11 deletions
@@ -32,9 +32,9 @@ #include <ctype.h> static void tinymix_list_controls(struct mixer *mixer); -static void tinymix_detail_control(struct mixer *mixer, unsigned int id, +static void tinymix_detail_control(struct mixer *mixer, const char *control, int print_all); -static void tinymix_set_value(struct mixer *mixer, unsigned int id, +static void tinymix_set_value(struct mixer *mixer, const char *control, char **values, unsigned int num_values); static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all); @@ -63,9 +63,9 @@ int main(int argc, char **argv) if (argc == 1) tinymix_list_controls(mixer); else if (argc == 2) - tinymix_detail_control(mixer, atoi(argv[1]), 1); + tinymix_detail_control(mixer, argv[1], 1); else if (argc >= 3) - tinymix_set_value(mixer, atoi(argv[1]), &argv[2], argc - 2); + tinymix_set_value(mixer, argv[1], &argv[2], argc - 2); else printf("Usage: tinymix [-D card] [control id] [value to set]\n"); @@ -93,7 +93,7 @@ static void tinymix_list_controls(struct mixer *mixer) type = mixer_ctl_get_type_string(ctl); num_values = mixer_ctl_get_num_values(ctl); printf("%d\t%s\t%d\t%-40s", i, type, num_values, name); - tinymix_detail_control(mixer, i, 0); + tinymix_detail_control(mixer, name, 0); } } @@ -115,7 +115,7 @@ static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all) } } -static void tinymix_detail_control(struct mixer *mixer, unsigned int id, +static void tinymix_detail_control(struct mixer *mixer, const char *control, int print_all) { struct mixer_ctl *ctl; @@ -124,13 +124,16 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id, unsigned int i; int min, max; - if (id >= mixer_get_num_ctls(mixer)) { + if (isdigit(control[0])) + ctl = mixer_get_ctl(mixer, atoi(control)); + else + ctl = mixer_get_ctl_by_name(mixer, control); + + if (!ctl) { fprintf(stderr, "Invalid mixer control\n"); return; } - ctl = mixer_get_ctl(mixer, id); - type = mixer_ctl_get_type(ctl); num_values = mixer_ctl_get_num_values(ctl); @@ -168,7 +171,7 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id, printf("\n"); } -static void tinymix_set_value(struct mixer *mixer, unsigned int id, +static void tinymix_set_value(struct mixer *mixer, const char *control, char **values, unsigned int num_values) { struct mixer_ctl *ctl; @@ -176,7 +179,16 @@ static void tinymix_set_value(struct mixer *mixer, unsigned int id, unsigned int num_ctl_values; unsigned int i; - ctl = mixer_get_ctl(mixer, id); + if (isdigit(control[0])) + ctl = mixer_get_ctl(mixer, atoi(control)); + else + ctl = mixer_get_ctl_by_name(mixer, control); + + if (!ctl) { + fprintf(stderr, "Invalid mixer control\n"); + return; + } + type = mixer_ctl_get_type(ctl); num_ctl_values = mixer_ctl_get_num_values(ctl); |