Gen 1: Move alsa-sim elem creation into alsa_config_to_new_elem()

This commit is contained in:
Geoffrey D. Bennett
2025-02-10 00:07:17 +10:30
parent c38bbba793
commit 1cdac65c00

View File

@@ -200,8 +200,8 @@ static void alsa_parse_comment_node(
} }
static int alsa_config_to_new_elem( static int alsa_config_to_new_elem(
snd_config_t *config, struct alsa_card *card,
struct alsa_elem *elem snd_config_t *config
) { ) {
const char *s; const char *s;
int id; int id;
@@ -212,6 +212,8 @@ static int alsa_config_to_new_elem(
long int_value; long int_value;
int err; int err;
struct alsa_elem elem = {};
err = snd_config_get_id(config, &s); err = snd_config_get_id(config, &s);
if (err < 0) if (err < 0)
fatal_alsa_error("snd_config_get_id error", err); fatal_alsa_error("snd_config_get_id error", err);
@@ -268,7 +270,8 @@ static int alsa_config_to_new_elem(
fatal_alsa_error("snd_config_get_string error", err); fatal_alsa_error("snd_config_get_string error", err);
string_value = strdup(s); string_value = strdup(s);
} else if (type == SND_CONFIG_TYPE_COMPOUND) { } else if (type == SND_CONFIG_TYPE_COMPOUND) {
elem->count = snd_config_is_array(node); elem.count = snd_config_is_array(node);
if (strcmp(name, "Level Meter") == 0) { if (strcmp(name, "Level Meter") == 0) {
seen_value = 1; seen_value = 1;
value_type = SND_CONFIG_TYPE_INTEGER; value_type = SND_CONFIG_TYPE_INTEGER;
@@ -286,7 +289,7 @@ static int alsa_config_to_new_elem(
// comment node? // comment node?
} else if (strcmp(key, "comment") == 0) { } else if (strcmp(key, "comment") == 0) {
alsa_parse_comment_node(node, elem); alsa_parse_comment_node(node, &elem);
// this isn't needed // this isn't needed
} else if (strcmp(key, "index") == 0) { } else if (strcmp(key, "index") == 0) {
@@ -321,21 +324,21 @@ static int alsa_config_to_new_elem(
// integer in config // integer in config
if (value_type == SND_CONFIG_TYPE_INTEGER) { if (value_type == SND_CONFIG_TYPE_INTEGER) {
elem->value = int_value; elem.value = int_value;
// string in config // string in config
} else if (value_type == SND_CONFIG_TYPE_STRING) { } else if (value_type == SND_CONFIG_TYPE_STRING) {
// translate boolean true/false // translate boolean true/false
if (elem->type == SND_CTL_ELEM_TYPE_BOOLEAN) { if (elem.type == SND_CTL_ELEM_TYPE_BOOLEAN) {
if (strcmp(string_value, "true") == 0) if (strcmp(string_value, "true") == 0)
elem->value = 1; elem.value = 1;
// translate enum string value to integer // translate enum string value to integer
} else if (elem->type == SND_CTL_ELEM_TYPE_ENUMERATED) { } else if (elem.type == SND_CTL_ELEM_TYPE_ENUMERATED) {
for (int i = 0; i < elem->item_count; i++) { for (int i = 0; i < elem.item_count; i++) {
if (strcmp(string_value, elem->item_names[i]) == 0) { if (strcmp(string_value, elem.item_names[i]) == 0) {
elem->value = i; elem.value = i;
break; break;
} }
} }
@@ -346,8 +349,9 @@ static int alsa_config_to_new_elem(
} }
} }
elem->numid = id; elem.card = card;
elem->name = name; elem.numid = id;
elem.name = name;
free(iface); free(iface);
free(string_value); free(string_value);
@@ -382,18 +386,8 @@ static void alsa_config_to_new_card(
if (snd_config_get_type(config) != SND_CONFIG_TYPE_COMPOUND) if (snd_config_get_type(config) != SND_CONFIG_TYPE_COMPOUND)
continue; continue;
struct alsa_elem elem = {};
elem.card = card;
// create the element // create the element
int err = alsa_config_to_new_elem(node, &elem); alsa_config_to_new_elem(card, node);
if (err)
continue;
if (card->elems->len <= elem.numid)
g_array_set_size(card->elems, elem.numid + 1);
g_array_index(card->elems, struct alsa_elem, elem.numid) = elem;
} }
} }