From 9e2c240f20f82159b59c37ed3c722c1279f7863e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Boisnard?= Date: Tue, 17 Sep 2013 22:43:18 +0200 Subject: Add a function to disambiguate duplicate control names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Control names are not unique and can be shared by multiple mixers controls. When this happens, there is no way of accessing the mixer using its control name, because mixer_get_ctl_by_name() always returns the first match. The only way of accessing the mixer is through its control number, i.e. using mixer_get_ctl(). This patch adds the function mixer_get_ctl_by_name_and_index() to offer the possibility to retrieve a control through its name and index. This index corresponds to the nth occurence of the control name in the global supported controls names list. Change-Id: Ie29bf2a949ecf69f106bbe359155cdbfbe98928c Signed-off-by: Frédéric Boisnard Signed-off-by: David Wagner Signed-off-by: Bruce Beare Signed-off-by: Jack Ren Author-Tracking-BZ: 139255 --- include/tinyalsa/asoundlib.h | 3 +++ mixer.c | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h index 3d20b94..873b9c9 100644 --- a/include/tinyalsa/asoundlib.h +++ b/include/tinyalsa/asoundlib.h @@ -215,6 +215,9 @@ const char *mixer_get_name(struct mixer *mixer); unsigned int mixer_get_num_ctls(struct mixer *mixer); struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id); struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name); +struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer, + const char *name, + unsigned int index); /* Get info about mixer controls */ const char *mixer_ctl_get_name(struct mixer_ctl *ctl); diff --git a/mixer.c b/mixer.c index 4568cca..afe9d7f 100644 --- a/mixer.c +++ b/mixer.c @@ -191,6 +191,13 @@ struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id) } struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name) +{ + return mixer_get_ctl_by_name_and_index(mixer, name, 0); +} + +struct mixer_ctl *mixer_get_ctl_by_name_and_index(struct mixer *mixer, + const char *name, + unsigned int index) { unsigned int n; @@ -199,7 +206,8 @@ struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name) for (n = 0; n < mixer->count; n++) if (!strcmp(name, (char*) mixer->elem_info[n].id.name)) - return mixer->ctl + n; + if (index-- == 0) + return mixer->ctl + n; return NULL; } -- cgit v1.2.3