Add a generic exception mechanism for mixer-control-names which don't use the standard suffixes from the suffixes table. And move the existing exceptions which consist of a simple !strcmp() check over to this new mechanism. This also fixes the "Capture Volume" and "Capture Switch" exceptions no longer working after commit 86b9c67774bc ("mixer: simple - Unify simple_none: base_len() exception handling") because they were moved to after the suffix checking, so they would be treated as CTL_GLOBAL_VOLUME resp. CTL_GLOBAL_SWITCH based on their suffix before the exception check has a chance to check for a match. Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx> --- src/mixer/simple_none.c | 48 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c index 71d88486..30d5aa8b 100644 --- a/src/mixer/simple_none.c +++ b/src/mixer/simple_none.c @@ -905,14 +905,41 @@ static const struct suf { {" Volume", CTL_GLOBAL_VOLUME}, {NULL, 0} }; + +static const struct excep { + const char *name; + int base_len; + selem_ctl_type_t type; +} exceptions[] = { + /* Special case - handle "Input Source" as a capture route. + * Note that it's *NO* capture source. A capture source is split over + * sub-elements, and multiple capture-sources will result in an error. + * That's why some drivers use "Input Source" as a workaround. + * Hence, this is a workaround for a workaround to get the things + * straight back again. Sigh. + */ + {"Input Source", 12, CTL_CAPTURE_ROUTE}, + /* Avoid these Capture Volume/Switch controls getting seen as GLOBAL VOL/SW */ + {"Capture Volume", 7, CTL_CAPTURE_VOLUME}, + {"Capture Switch", 7, CTL_CAPTURE_SWITCH}, + {NULL,} +}; #endif /* Return base length */ static int base_len(const char *name, selem_ctl_type_t *type) { + const struct excep *e; const struct suf *p; size_t nlen = strlen(name); + for (e = exceptions; e->name; e++) { + if (!strcmp(name, e->name)) { + *type = e->type; + return e->base_len; + } + } + for (p = suffixes; p->suffix; p++) { size_t slen = strlen(p->suffix); size_t l; @@ -926,27 +953,6 @@ static int base_len(const char *name, selem_ctl_type_t *type) } } - /* exception: "Capture Volume" and "Capture Switch" */ - if (!strcmp(name, "Capture Volume")) { - *type = CTL_CAPTURE_VOLUME; - return strlen("Capture"); - } - if (!strcmp(name, "Capture Switch")) { - *type = CTL_CAPTURE_SWITCH; - return strlen("Capture"); - } - - /* Special case - handle "Input Source" as a capture route. - * Note that it's *NO* capture source. A capture source is split over - * sub-elements, and multiple capture-sources will result in an error. - * That's why some drivers use "Input Source" as a workaround. - * Hence, this is a workaround for a workaround to get the things - * straight back again. Sigh. - */ - if (!strcmp(name, "Input Source")) { - *type = CTL_CAPTURE_ROUTE; - return strlen(name); - } if (strstr(name, "3D Control")) { if (strstr(name, "Depth")) { *type = CTL_PLAYBACK_VOLUME; -- 2.31.1