mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-03 09:01:52 -05:00
mixer: simple - Unify simple_none: base_len() exception handling
Unify simple_none: base_len() exception handling: 1. In the "Input Source" and "3D Control" cases the base-name is the same as the full-name and base_len() simply returns strlen(name). Instead of returning 0 when the type is unknown, set the type to CTL_SINGLE and return strlen(name). This allows removing the special case for base_len() returning 0 in simple_event_add(). 2. Move the special handling for "Capture Volume" and "Capture Switch" from simple_event_add() to base_len(), so that we handle all exceptions inside base_len(). Instead of handling some special cases in base_len() and other special cases in simple_event_add(). [jk - moved the "Capture Volume" and "Capture Switch" to "Input Source" exceptions] Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
33ddf2e1c7
commit
86b9c67774
1 changed files with 25 additions and 18 deletions
|
|
@ -907,11 +907,12 @@ static const struct suf {
|
|||
};
|
||||
#endif
|
||||
|
||||
/* Return base length or 0 on failure */
|
||||
/* Return base length */
|
||||
static int base_len(const char *name, selem_ctl_type_t *type)
|
||||
{
|
||||
const struct suf *p;
|
||||
size_t nlen = strlen(name);
|
||||
|
||||
p = suffixes;
|
||||
while (p->suffix) {
|
||||
size_t slen = strlen(p->suffix);
|
||||
|
|
@ -927,6 +928,16 @@ static int base_len(const char *name, selem_ctl_type_t *type)
|
|||
p++;
|
||||
}
|
||||
|
||||
/* 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.
|
||||
|
|
@ -944,7 +955,9 @@ static int base_len(const char *name, selem_ctl_type_t *type)
|
|||
return strlen(name);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
*type = CTL_SINGLE;
|
||||
return strlen(name);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1605,8 +1618,10 @@ static int simple_add1(snd_mixer_class_t *class, const char *name,
|
|||
static int simple_event_add(snd_mixer_class_t *class, snd_hctl_elem_t *helem)
|
||||
{
|
||||
const char *name = snd_hctl_elem_get_name(helem);
|
||||
selem_ctl_type_t type;
|
||||
char ename[128];
|
||||
size_t len;
|
||||
selem_ctl_type_t type = CTL_SINGLE; /* to shut up warning */
|
||||
|
||||
if (snd_hctl_elem_get_interface(helem) != SND_CTL_ELEM_IFACE_MIXER)
|
||||
return 0;
|
||||
if (strcmp(name, "Capture Source") == 0) {
|
||||
|
|
@ -1633,23 +1648,15 @@ static int simple_event_add(snd_mixer_class_t *class, snd_hctl_elem_t *helem)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = base_len(name, &type);
|
||||
if (len == 0) {
|
||||
return simple_add1(class, name, helem, CTL_SINGLE, 0);
|
||||
} else {
|
||||
char ename[128];
|
||||
if (len >= sizeof(ename))
|
||||
len = sizeof(ename) - 1;
|
||||
memcpy(ename, name, len);
|
||||
ename[len] = 0;
|
||||
/* exception: Capture Volume and Capture Switch */
|
||||
if (type == CTL_GLOBAL_VOLUME && !strcmp(ename, "Capture"))
|
||||
type = CTL_CAPTURE_VOLUME;
|
||||
else if (type == CTL_GLOBAL_SWITCH && !strcmp(ename, "Capture"))
|
||||
type = CTL_CAPTURE_SWITCH;
|
||||
|
||||
return simple_add1(class, ename, helem, type, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int simple_event_remove(snd_hctl_elem_t *helem,
|
||||
snd_mixer_elem_t *melem)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue