Display -inf when volume/gain controls are at zero/off

This commit is contained in:
Geoffrey D. Bennett
2023-12-04 13:28:17 +10:30
parent 770ce1cc23
commit 20c4ff5559
4 changed files with 28 additions and 11 deletions

View File

@@ -174,7 +174,7 @@ static void create_input_gain_control(
int current_row, int current_row,
int line_num int line_num
) { ) {
GtkWidget *w = make_gain_alsa_elem(elem); GtkWidget *w = make_gain_alsa_elem(elem, 0);
gtk_grid_attach(GTK_GRID(grid), w, line_num, current_row, 1, 1); gtk_grid_attach(GTK_GRID(grid), w, line_num, current_row, 1, 1);
} }
@@ -466,7 +466,7 @@ static void create_output_controls(
// output controls // output controls
if (strncmp(elem->name, "Line", 4) == 0) { if (strncmp(elem->name, "Line", 4) == 0) {
if (strstr(elem->name, "Playback Volume")) { if (strstr(elem->name, "Playback Volume")) {
w = make_gain_alsa_elem(elem); w = make_gain_alsa_elem(elem, 1);
gtk_grid_attach( gtk_grid_attach(
GTK_GRID(output_grid), w, line_num - 1 + line_1_col, 1, 1, 1 GTK_GRID(output_grid), w, line_num - 1 + line_1_col, 1, 1, 1
); );
@@ -503,7 +503,7 @@ static void create_output_controls(
GtkWidget *l = gtk_label_new(gen4 ? "Line 12" : "HW"); GtkWidget *l = gtk_label_new(gen4 ? "Line 12" : "HW");
gtk_grid_attach(GTK_GRID(output_grid), l, 0, 0, 1, 1); gtk_grid_attach(GTK_GRID(output_grid), l, 0, 0, 1, 1);
w = make_gain_alsa_elem(elem); w = make_gain_alsa_elem(elem, 1);
gtk_widget_set_tooltip_text( gtk_widget_set_tooltip_text(
w, w,
gen4 gen4
@@ -522,7 +522,7 @@ static void create_output_controls(
"This control shows the setting of the headphone volume knob." "This control shows the setting of the headphone volume knob."
); );
gtk_grid_attach(GTK_GRID(output_grid), l, 1, 0, 1, 1); gtk_grid_attach(GTK_GRID(output_grid), l, 1, 0, 1, 1);
w = make_gain_alsa_elem(elem); w = make_gain_alsa_elem(elem, 1);
gtk_grid_attach(GTK_GRID(output_grid), w, 1, 1, 1, 1); gtk_grid_attach(GTK_GRID(output_grid), w, 1, 1, 1, 1);
} else if (strcmp(elem->name, "Mute Playback Switch") == 0) { } else if (strcmp(elem->name, "Mute Playback Switch") == 0) {
w = make_boolean_alsa_elem( w = make_boolean_alsa_elem(

View File

@@ -9,6 +9,7 @@ struct gain {
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *dial; GtkWidget *dial;
GtkWidget *label; GtkWidget *label;
int zero_is_off;
}; };
static void gain_changed(GtkWidget *widget, struct gain *data) { static void gain_changed(GtkWidget *widget, struct gain *data) {
@@ -30,21 +31,35 @@ static void gain_updated(
gtk_dial_set_value(GTK_DIAL(data->dial), alsa_value); gtk_dial_set_value(GTK_DIAL(data->dial), alsa_value);
char s[20]; char s[20];
char *p = s;
float scale = (float)(elem->max_dB - elem->min_dB) / float scale = (float)(elem->max_dB - elem->min_dB) /
(elem->max_val - elem->min_val); (elem->max_val - elem->min_val);
float value = (float)alsa_value * scale + elem->min_dB; float value = (float)alsa_value * scale + elem->min_dB;
if (value > elem->max_dB)
value = elem->max_dB;
else if (value < elem->min_dB)
value = elem->min_dB;
if (data->zero_is_off && alsa_value == 0) {
p += sprintf(p, "−∞");
} else {
if (value < 0)
p += sprintf(p, "");
if (scale < 1) if (scale < 1)
snprintf(s, 20, "%.1f", value); p += sprintf(p, "%.1f", fabs(value));
else else
snprintf(s, 20, "%.0fdB", value); p += sprintf(p, "%.0f", fabs(value));
}
if (scale >= 1)
p += sprintf(p, "dB");
gtk_label_set_text(GTK_LABEL(data->label), s); gtk_label_set_text(GTK_LABEL(data->label), s);
} }
//GList *make_gain_alsa_elem(struct alsa_elem *elem) { //GList *make_gain_alsa_elem(struct alsa_elem *elem) {
GtkWidget *make_gain_alsa_elem(struct alsa_elem *elem) { GtkWidget *make_gain_alsa_elem(struct alsa_elem *elem, int zero_is_off) {
struct gain *data = g_malloc(sizeof(struct gain)); struct gain *data = g_malloc(sizeof(struct gain));
data->elem = elem; data->elem = elem;
data->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); data->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
@@ -62,6 +77,8 @@ GtkWidget *make_gain_alsa_elem(struct alsa_elem *elem) {
data->label = gtk_label_new(NULL); data->label = gtk_label_new(NULL);
gtk_widget_set_vexpand(data->dial, TRUE); gtk_widget_set_vexpand(data->dial, TRUE);
data->zero_is_off = zero_is_off;
g_signal_connect( g_signal_connect(
data->dial, "value-changed", G_CALLBACK(gain_changed), data data->dial, "value-changed", G_CALLBACK(gain_changed), data
); );

View File

@@ -7,4 +7,4 @@
#include "alsa.h" #include "alsa.h"
GtkWidget *make_gain_alsa_elem(struct alsa_elem *alsa_elem); GtkWidget *make_gain_alsa_elem(struct alsa_elem *alsa_elem, int zero_is_off);

View File

@@ -76,7 +76,7 @@ GtkWidget *create_mixer_controls(struct alsa_card *card) {
} }
// create the gain control and attach to the grid // create the gain control and attach to the grid
GtkWidget *w = make_gain_alsa_elem(elem); GtkWidget *w = make_gain_alsa_elem(elem, 1);
gtk_grid_attach(GTK_GRID(mixer_top), w, input_num + 1, mix_num + 2, 1, 1); gtk_grid_attach(GTK_GRID(mixer_top), w, input_num + 1, mix_num + 2, 1, 1);
// look up the r_snk entry for the mixer input number // look up the r_snk entry for the mixer input number