Add get_elem_by_substr() to alsa.[ch]

This commit is contained in:
Geoffrey D. Bennett
2024-03-31 03:27:49 +10:30
parent 6a04e1d1fa
commit 97ca9ae754
2 changed files with 16 additions and 0 deletions

View File

@@ -76,6 +76,21 @@ struct alsa_elem *get_elem_by_prefix(GArray *elems, const char *prefix) {
return NULL;
}
// return the first element with a name containing the given substring
struct alsa_elem *get_elem_by_substr(GArray *elems, const char *substr) {
for (int i = 0; i < elems->len; i++) {
struct alsa_elem *elem = &g_array_index(elems, struct alsa_elem, i);
if (!elem->card)
continue;
if (strstr(elem->name, substr))
return elem;
}
return NULL;
}
// find the maximum number in the matching elements
// search by element name prefix and substring
// e.g. get_max_elem_by_name(elems, "Line", "Pad Capture Switch")

View File

@@ -200,6 +200,7 @@ void fatal_alsa_error(const char *msg, int err);
// locate elements or get information about them
struct alsa_elem *get_elem_by_name(GArray *elems, const char *name);
struct alsa_elem *get_elem_by_prefix(GArray *elems, const char *prefix);
struct alsa_elem *get_elem_by_substr(GArray *elems, const char *substr);
int get_max_elem_by_name(
GArray *elems,
const char *prefix,