diff --git a/src/iface-mixer.c b/src/iface-mixer.c index f276288..037439e 100644 --- a/src/iface-mixer.c +++ b/src/iface-mixer.c @@ -174,7 +174,7 @@ static void create_input_gain_control( int current_row, 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); } @@ -466,7 +466,7 @@ static void create_output_controls( // output controls if (strncmp(elem->name, "Line", 4) == 0) { if (strstr(elem->name, "Playback Volume")) { - w = make_gain_alsa_elem(elem); + w = make_gain_alsa_elem(elem, 1); gtk_grid_attach( 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 1–2" : "HW"); 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( w, gen4 @@ -522,7 +522,7 @@ static void create_output_controls( "This control shows the setting of the headphone volume knob." ); 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); } else if (strcmp(elem->name, "Mute Playback Switch") == 0) { w = make_boolean_alsa_elem( diff --git a/src/widget-gain.c b/src/widget-gain.c index afcab48..53c4633 100644 --- a/src/widget-gain.c +++ b/src/widget-gain.c @@ -9,6 +9,7 @@ struct gain { GtkWidget *vbox; GtkWidget *dial; GtkWidget *label; + int zero_is_off; }; 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); char s[20]; + char *p = s; float scale = (float)(elem->max_dB - elem->min_dB) / (elem->max_val - elem->min_val); float value = (float)alsa_value * scale + elem->min_dB; - if (scale < 1) - snprintf(s, 20, "%.1f", value); - else - snprintf(s, 20, "%.0fdB", value); + 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) + p += sprintf(p, "%.1f", fabs(value)); + else + p += sprintf(p, "%.0f", fabs(value)); + } + if (scale >= 1) + p += sprintf(p, "dB"); gtk_label_set_text(GTK_LABEL(data->label), s); } //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)); data->elem = elem; 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); gtk_widget_set_vexpand(data->dial, TRUE); + data->zero_is_off = zero_is_off; + g_signal_connect( data->dial, "value-changed", G_CALLBACK(gain_changed), data ); diff --git a/src/widget-gain.h b/src/widget-gain.h index 353aa69..26f8fa0 100644 --- a/src/widget-gain.h +++ b/src/widget-gain.h @@ -7,4 +7,4 @@ #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); diff --git a/src/window-mixer.c b/src/window-mixer.c index 76c45dc..714768e 100644 --- a/src/window-mixer.c +++ b/src/window-mixer.c @@ -76,7 +76,7 @@ GtkWidget *create_mixer_controls(struct alsa_card *card) { } // 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); // look up the r_snk entry for the mixer input number