From d56a1d34ff2b78be3165000d28657ed5d520f8eb Mon Sep 17 00:00:00 2001 From: "Geoffrey D. Bennett" Date: Sun, 3 Dec 2023 00:28:20 +1030 Subject: [PATCH] Add 4th Gen input controls --- src/iface-mixer.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++ src/widget-label.c | 23 ++++++++++++ src/widget-label.h | 10 +++++ 3 files changed, 126 insertions(+) create mode 100644 src/widget-label.c create mode 100644 src/widget-label.h diff --git a/src/iface-mixer.c b/src/iface-mixer.c index ab42a2a..2dada67 100644 --- a/src/iface-mixer.c +++ b/src/iface-mixer.c @@ -9,6 +9,7 @@ #include "widget-combo.h" #include "widget-dual.h" #include "widget-gain.h" +#include "widget-label.h" #include "window-helper.h" #include "window-levels.h" #include "window-mixer.h" @@ -148,6 +149,77 @@ static GtkWidget *create_global_box(GtkWidget *grid, int *x, int orient) { return controls; } +static void create_input_link_control( + struct alsa_elem *elem, + GtkWidget *grid, + int current_row, + int line_num +) { + GtkWidget *w = make_boolean_alsa_elem(elem, "Off", "On"); + + int from, to; + get_two_num_from_string(elem->name, &from, &to); + if (to == -1) + to = from; + + gtk_grid_attach(GTK_GRID(grid), w, from, current_row, to - from + 1, 1); +} + +static void create_input_gain_control( + struct alsa_elem *elem, + GtkWidget *grid, + int current_row, + int line_num +) { + GtkWidget *w = make_gain_alsa_elem(elem); + + gtk_grid_attach(GTK_GRID(grid), w, line_num, current_row, 1, 1); +} + +static void create_input_autogain_control( + struct alsa_elem *elem, + GtkWidget *grid, + int current_row, + int line_num +) { + GtkWidget *w = make_boolean_alsa_elem(elem, "Off", "On"); + gtk_widget_set_tooltip_text( + w, + "Autogain will listen to the input signal for 10 seconds and " + "automatically set the gain of the input channel to get the " + "best signal level." + ); + + gtk_grid_attach(GTK_GRID(grid), w, line_num, current_row, 1, 1); +} + +static void create_input_autogain_status_control( + struct alsa_elem *elem, + GtkWidget *grid, + int current_row, + int line_num +) { + GtkWidget *w = make_label_alsa_elem(elem); + + gtk_grid_attach(GTK_GRID(grid), w, line_num, current_row, 1, 1); +} + +static void create_input_safe_control( + struct alsa_elem *elem, + GtkWidget *grid, + int current_row, + int line_num +) { + GtkWidget *w = make_boolean_alsa_elem(elem, "Off", "On"); + gtk_widget_set_tooltip_text( + w, + "Enabling Safe Mode prevents the input from clipping by " + "automatically reducing the gain if the signal is too hot." + ); + + gtk_grid_attach(GTK_GRID(grid), w, line_num, current_row, 1, 1); +} + static void create_input_level_control( struct alsa_elem *elem, GtkWidget *grid, @@ -287,6 +359,27 @@ static void create_input_controls( } int current_row = 1; + create_input_controls_by_type( + elems, input_grid, ¤t_row, + "Link", "Link Capture Switch", create_input_link_control + ); + create_input_controls_by_type( + elems, input_grid, ¤t_row, + "Gain", "Gain Capture Volume", create_input_gain_control + ); + create_input_controls_by_type( + elems, input_grid, ¤t_row, + "Autogain", "Autogain Capture Switch", create_input_autogain_control + ); + create_input_controls_by_type( + elems, input_grid, ¤t_row, + "Autogain Status", "Autogain Status Capture Enum", + create_input_autogain_status_control + ); + create_input_controls_by_type( + elems, input_grid, ¤t_row, + "Safe", "Safe Capture Switch", create_input_safe_control + ); create_input_controls_by_type( elems, input_grid, ¤t_row, "Level", "Level Capture Enum", create_input_level_control diff --git a/src/widget-label.c b/src/widget-label.c new file mode 100644 index 0000000..9af9fb2 --- /dev/null +++ b/src/widget-label.c @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2022 Geoffrey D. Bennett +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "widget-label.h" + +static void label_updated(struct alsa_elem *elem) { + const char *text = alsa_get_item_name(elem, alsa_get_elem_value(elem)); + + gtk_label_set_text(GTK_LABEL(elem->widget), text); +} + +GtkWidget *make_label_alsa_elem(struct alsa_elem *elem) { + GtkWidget *label = gtk_label_new(NULL); + gtk_widget_set_halign(label, GTK_ALIGN_CENTER); + gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + + elem->widget = label; + elem->widget_callback = label_updated; + + label_updated(elem); + + return label; +} diff --git a/src/widget-label.h b/src/widget-label.h new file mode 100644 index 0000000..b1c33bf --- /dev/null +++ b/src/widget-label.h @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: 2022 Geoffrey D. Bennett +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include + +#include "alsa.h" + +GtkWidget *make_label_alsa_elem(struct alsa_elem *elem);