Debian Codegraph @

src/config-autogain.c

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2022-2025 Geoffrey D. Bennett <[email protected]>
2 // SPDX-License-Identifier: GPL-3.0-or-later
3
4 #include <gtk/gtk.h>
5
6 #include "alsa.h"
7 #include "config-helpers.h"
8 #include "widget-gain.h"
9 #include "window-configuration.h"
10
11 #define AUTOGAIN_TARGET_COUNT 3
12
13 void add_autogain_tab(GtkWidget *notebook, struct alsa_card *card) {
14 static const char *names[] = {
15 "Autogain Hot Target",
16 "Autogain Mean Target",
17 "Autogain Peak Target"
18 };
19 static const char *labels[] = { "Hot", "Mean", "Peak" };
20
21 int count = 0;
22 for (int i = 0; i < AUTOGAIN_TARGET_COUNT; i++)
23 if (get_elem_by_name(card->elems, names[i]))
24 count++;
25
26 if (!count)
27 return;
28
29 GtkWidget *content = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
30 gtk_widget_set_margin_start(content, 20);
31 gtk_widget_set_margin_end(content, 20);
32 gtk_widget_set_margin_top(content, 20);
33 gtk_widget_set_margin_bottom(content, 20);
34
35 const char *help_text = count == 1
36 ? "Configure the target level for the Autogain feature.\n"
37 "This setting controls what signal level Autogain aims for."
38 : "Configure the target levels for the Autogain feature.\n"
39 "These settings control what signal levels Autogain aims for.";
40 gtk_box_append(GTK_BOX(content), config_help_label(help_text));
41
42 GtkWidget *grid = gtk_grid_new();
43 gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
44 gtk_grid_set_column_spacing(GTK_GRID(grid), 20);
45 gtk_widget_set_margin_top(grid, 10);
46 gtk_widget_set_halign(grid, GTK_ALIGN_START);
47
48 int col = 0;
49 for (int i = 0; i < AUTOGAIN_TARGET_COUNT; i++) {
50 struct alsa_elem *elem = get_elem_by_name(card->elems, names[i]);
51 if (!elem)
52 continue;
53
54 GtkWidget *label = gtk_label_new(labels[i]);
55 gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
56 gtk_grid_attach(GTK_GRID(grid), label, col, 0, 1, 1);
57
58 GtkWidget *gain = make_gain_alsa_elem(
59 elem,
60 0, // zero_is_off
61 WIDGET_GAIN_TAPER_LINEAR,
62 1, // can_control
63 FALSE // show_level
64 );
65 gtk_grid_attach(GTK_GRID(grid), gain, col, 1, 1, 1);
66 col++;
67 }
68
69 gtk_box_append(GTK_BOX(content), grid);
70
71 g_object_set_data(G_OBJECT(content), PAGE_ID_KEY, (gpointer)"autogain");
72 gtk_notebook_append_page(
73 GTK_NOTEBOOK(notebook), content, gtk_label_new("Autogain")
74 );
75 }