Remove hard-coded values from widget-gain.c and widget-volume.c

Update alsa-sim.c and alsa.c to read the TLV info, and update the gain
and volume widgets to use that info rather than hard-coding the
min/max values.
This commit is contained in:
Geoffrey D. Bennett
2023-11-30 23:57:47 +10:30
parent 197f469bd8
commit be458afcc4
5 changed files with 116 additions and 16 deletions

View File

@@ -151,6 +151,42 @@ static void alsa_parse_comment_node(
elem->type = SND_CTL_ELEM_TYPE_INTEGER;
} else if (strcmp(key, "item") == 0) {
alsa_parse_enum_items(node, elem);
} else if (strcmp(key, "range") == 0) {
if (type != SND_CONFIG_TYPE_STRING) {
printf("range type not string\n");
return;
}
const char *range;
err = snd_config_get_string(node, &range);
if (err < 0)
fatal_alsa_error("snd_config_get_string error", err);
// Parse the range string and update elem->min_val and elem->max_val
int min_val, max_val;
if (sscanf(range, "%d - %d", &min_val, &max_val) == 2) {
elem->min_val = min_val;
elem->max_val = max_val;
}
} else if (strcmp(key, "dbmin") == 0) {
if (type != SND_CONFIG_TYPE_INTEGER) {
printf("dbmin type not integer\n");
return;
}
long dbmin;
err = snd_config_get_integer(node, &dbmin);
if (err < 0)
fatal_alsa_error("snd_config_get_integer error", err);
elem->min_dB = dbmin / 100;
} else if (strcmp(key, "dbmax") == 0) {
if (type != SND_CONFIG_TYPE_INTEGER) {
printf("dbmax type not integer\n");
return;
}
long dbmax;
err = snd_config_get_integer(node, &dbmax);
if (err < 0)
fatal_alsa_error("snd_config_get_integer error", err);
elem->max_dB = dbmax / 100;
}
}
}