Debian Codegraph @

src/iface-mixer.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 "glow.h"
5 #include "gtkhelper.h"
6 #include "iface-mixer.h"
7 #include "presets.h"
8 #include "window-preferences.h"
9 #include "routing-lines.h"
10 #include "stringhelper.h"
11 #include "tooltips.h"
12 #include "widget-boolean.h"
13 #include "widget-drop-down.h"
14 #include "widget-dual.h"
15 #include "widget-gain.h"
16 #include "widget-input-select.h"
17 #include "widget-label.h"
18 #include "widget-sample-rate.h"
19 #include "window-configuration.h"
20 #include "window-dsp.h"
21 #include "window-helper.h"
22 #include "window-levels.h"
23 #include "window-mixer.h"
24 #include "window-routing.h"
25 #include "window-startup.h"
26
27 // find the routing sink for a hardware output by port number
28 static struct routing_snk *get_output_r_snk(
29 struct alsa_card *card,
30 int port_num
31 ) {
32 for (int i = 0; i < card->routing_snks->len; i++) {
33 struct routing_snk *r_snk = &g_array_index(
34 card->routing_snks, struct routing_snk, i
35 );
36 struct alsa_elem *elem = r_snk->elem;
37
38 if (elem->port_category != PC_HW)
39 continue;
40
41 if (elem->lr_num == port_num)
42 return r_snk;
43 }
44 return NULL;
45 }
46
47 static void add_clock_source_control(
48 struct alsa_card *card,
49 GtkWidget *global_controls
50 ) {
51 GPtrArray *elems = card->elems;
52
53 struct alsa_elem *clock_source = get_elem_by_prefix(elems, "Clock Source");
54
55 if (!clock_source) {
56 clock_source = get_elem_by_substr(elems, "Sync Clock Source");
57
58 if (!clock_source)
59 return;
60 }
61
62 GtkWidget *b = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
63 gtk_widget_set_tooltip_text(
64 b,
65 "Clock Source selects where the interface receives its digital "
66 "clock from. If you aren’t using S/PDIF or ADAT inputs, set this "
67 "to Internal."
68 );
69 gtk_box_append(GTK_BOX(global_controls), b);
70
71 GtkWidget *l = gtk_label_new("Clock Source");
72 GtkWidget *w = make_drop_down_alsa_elem(clock_source, NULL);
73 gtk_widget_add_css_class(w, "clock-source");
74 gtk_widget_add_css_class(w, "fixed");
75
76 gtk_box_append(GTK_BOX(b), l);
77 gtk_box_append(GTK_BOX(b), w);
78 }
79
80 static void add_sync_status_control(
81 struct alsa_card *card,
82 GtkWidget *global_controls
83 ) {
84 GPtrArray *elems = card->elems;
85
86 struct alsa_elem *sync_status = get_elem_by_name(elems, "Sync Status");
87
88 if (!sync_status) {
89 sync_status = get_elem_by_name(elems, "Sample Clock Sync Status");
90 if (!sync_status)
91 return;
92 }
93
94 GtkWidget *b = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
95 if (get_elem_by_prefix(elems, "Clock Source")) {
96 gtk_widget_set_tooltip_text(
97 b,
98 "Sync Status indicates if the interface is locked to a valid "
99 "digital clock. If you aren’t using S/PDIF or ADAT inputs and "
100 "the Sync Status is Unlocked, change the Clock Source to "
101 "Internal."
102 );
103 } else {
104 gtk_widget_set_tooltip_text(
105 b,
106 "Sync Status indicates if the interface is locked to a valid "
107 "digital clock. Since the Clock Source is fixed to internal on "
108 "this interface, this should stay locked."
109 );
110 }
111 gtk_box_append(GTK_BOX(global_controls), b);
112
113 GtkWidget *l = gtk_label_new("Sync Status");
114 gtk_box_append(GTK_BOX(b), l);
115 GtkWidget *w = make_boolean_alsa_elem(sync_status, "Unlocked", "Locked");
116 gtk_widget_add_css_class(w, "sync-status");
117 gtk_widget_add_css_class(w, "fixed");
118 gtk_box_append(GTK_BOX(b), w);
119 }
120
121 static void add_power_status_control(
122 struct alsa_card *card,
123 GtkWidget *global_controls
124 ) {
125 GPtrArray *elems = card->elems;
126
127 struct alsa_elem *power_status = get_elem_by_name(
128 elems, "Power Status Card Enum"
129 );
130
131 if (!power_status)
132 return;
133
134 GtkWidget *b = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
135 gtk_widget_set_tooltip_text(
136 b,
137 "Power indicates if the interface is being powered by the USB "
138 "bus, an external power supply, or if there is insufficient power "
139 "available and the interface has shut down."
140 );
141 gtk_box_append(GTK_BOX(global_controls), b);
142
143 GtkWidget *l = gtk_label_new("Power");
144 gtk_box_append(GTK_BOX(b), l);
145 GtkWidget *w = make_drop_down_alsa_elem(power_status, NULL);
146 gtk_widget_add_css_class(w, "power-status");
147 gtk_widget_add_css_class(w, "fixed");
148 gtk_box_append(GTK_BOX(b), w);
149 }
150
151 static void add_sample_rate_control(
152 struct alsa_card *card,
153 GtkWidget *global_controls
154 ) {
155 GtkWidget *b = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
156 gtk_widget_set_tooltip_text(
157 b,
158 "The Sample Rate cannot be changed here because it is set by the "
159 "application which is using the interface, usually a sound "
160 "server like PulseAudio, JACK, or PipeWire. If this shows N/A, "
161 "no application is currently using the interface.\n\n"
162 "Note that not all features are available on all interfaces at "
163 "sample rates above 48kHz. Please refer to the user guide for "
164 "your interface for more information."
165 );
166 gtk_box_append(GTK_BOX(global_controls), b);
167
168 GtkWidget *l = gtk_label_new("Sample Rate");
169 gtk_box_append(GTK_BOX(b), l);
170 GtkWidget *w = make_sample_rate_widget(card);
171 gtk_widget_add_css_class(w, "sample-rate");
172 gtk_box_append(GTK_BOX(b), w);
173 }
174
175 static void add_speaker_switching_controls_enum(
176 struct alsa_card *card,
177 GtkWidget *global_controls
178 ) {
179 GPtrArray *elems = card->elems;
180
181 struct alsa_elem *speaker_switching = get_elem_by_name(
182 elems, "Speaker Switching Playback Enum"
183 );
184
185 if (!speaker_switching)
186 return;
187
188 GtkWidget *w = make_dual_boolean_alsa_elems(
189 speaker_switching,
190 "Speaker Switching",
191 "Off", "On", "Main", "Alt"
192 );
193
194 gtk_widget_set_tooltip_text(
195 w,
196 "Speaker Switching lets you swap between two pairs of "
197 "monitoring speakers very easily."
198 );
199
200 gtk_box_append(GTK_BOX(global_controls), w);
201 }
202
203 static void add_speaker_switching_controls_switches(
204 struct alsa_card *card,
205 GtkWidget *global_controls
206 ) {
207 GPtrArray *elems = card->elems;
208
209 struct alsa_elem *enable = get_elem_by_name(
210 elems, "Speaker Switching Playback Switch"
211 );
212 struct alsa_elem *alt = get_elem_by_name(
213 elems, "Speaker Switching Alt Playback Switch"
214 );
215
216 if (!enable || !alt)
217 return;
218
219 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
220 gtk_widget_set_tooltip_text(
221 box,
222 "Speaker Switching lets you swap between two pairs of "
223 "monitoring speakers very easily."
224 );
225
226 GtkWidget *l = gtk_label_new("Speaker Switching");
227 GtkWidget *w1 = make_boolean_alsa_elem(enable, "Off", "On");
228 GtkWidget *w2 = make_boolean_alsa_elem(alt, "Main", "Alt");
229
230 gtk_widget_add_css_class(w1, "speaker-switching-enable");
231 gtk_widget_add_css_class(w2, "speaker-switching-alt");
232
233 gtk_box_append(GTK_BOX(box), l);
234 gtk_box_append(GTK_BOX(box), w1);
235 gtk_box_append(GTK_BOX(box), w2);
236 gtk_box_append(GTK_BOX(global_controls), box);
237 }
238
239 // Check if any Alt Group Output is enabled (Gen 4)
240 static int has_any_alt_group_enabled(struct alsa_card *card) {
241 for (int i = 1; i <= 8; i++) {
242 char name[64];
243 snprintf(name, sizeof(name), "Alt Group Output %d Playback Switch", i);
244 struct alsa_elem *elem = get_elem_by_name(card->elems, name);
245 if (elem && alsa_get_elem_value(elem))
246 return 1;
247 }
248 return 0;
249 }
250
251 // Callback to update speaker switching button sensitivity
252 static void update_speaker_switching_sensitivity(
253 struct alsa_elem *elem,
254 void *data
255 ) {
256 GtkWidget *button = data;
257 struct alsa_card *card = elem->card;
258
259 int enabled = has_any_alt_group_enabled(card);
260 gtk_widget_set_sensitive(button, enabled);
261 }
262
263 // Gen 4: Main/Alt selector only (speaker switching is implicit)
264 static void add_speaker_switching_controls_gen4(
265 struct alsa_card *card,
266 GtkWidget *global_controls
267 ) {
268 GPtrArray *elems = card->elems;
269
270 // Check if this is Gen 4 (has Main/Alt Group controls)
271 struct alsa_elem *main_group = get_elem_by_prefix(
272 elems, "Main Group Output"
273 );
274 if (!main_group)
275 return;
276
277 struct alsa_elem *alt = get_elem_by_name(
278 elems, "Speaker Switching Alt Playback Switch"
279 );
280 if (!alt)
281 return;
282
283 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
284 gtk_widget_set_tooltip_text(
285 box,
286 "Monitor Group lets you swap between Main and Alt monitor groups. "
287 "Configure which outputs belong to each group in the Configuration window."
288 );
289
290 GtkWidget *l = gtk_label_new("Monitor Group");
291 GtkWidget *w = make_boolean_alsa_elem(alt, "Main", "Alt");
292
293 gtk_widget_add_css_class(w, "speaker-switching-alt");
294
295 // Set initial sensitivity based on whether any Alt output is enabled
296 gtk_widget_set_sensitive(w, has_any_alt_group_enabled(card));
297
298 // Register callbacks on Alt Group Output switches to update sensitivity
299 for (int i = 1; i <= 8; i++) {
300 char name[64];
301 snprintf(name, sizeof(name), "Alt Group Output %d Playback Switch", i);
302 struct alsa_elem *alt_out = get_elem_by_name(elems, name);
303 if (alt_out)
304 alsa_elem_add_callback(alt_out, update_speaker_switching_sensitivity, w, NULL);
305 }
306
307 gtk_box_append(GTK_BOX(box), l);
308 gtk_box_append(GTK_BOX(box), w);
309 gtk_box_append(GTK_BOX(global_controls), box);
310 }
311
312 // Structure to track output volume widget and its monitor group elements
313 struct output_volume_group_data {
314 GtkWidget *widget;
315 struct alsa_elem *main_group_switch;
316 struct alsa_elem *alt_group_switch;
317 };
318
319 // Check if output is in a monitor group and update widget sensitivity
320 static void update_output_volume_sensitivity(
321 struct alsa_elem *elem,
322 void *data
323 ) {
324 struct output_volume_group_data *d = data;
325
326 int in_group = 0;
327
328 if (d->main_group_switch && alsa_get_elem_value(d->main_group_switch))
329 in_group = 1;
330 if (d->alt_group_switch && alsa_get_elem_value(d->alt_group_switch))
331 in_group = 1;
332
333 gtk_widget_set_sensitive(d->widget, !in_group);
334 }
335
336 // Free output volume group data
337 static void free_output_volume_group_data(void *data) {
338 g_free(data);
339 }
340
341 // Get the routing sink for an analogue output by lr_num
342 static struct routing_snk *get_analogue_output_snk(
343 struct alsa_card *card,
344 int lr_num
345 ) {
346 if (!card->routing_snks)
347 return NULL;
348
349 for (int i = 0; i < card->routing_snks->len; i++) {
350 struct routing_snk *snk = &g_array_index(
351 card->routing_snks, struct routing_snk, i
352 );
353 if (snk->elem->port_category == PC_HW &&
354 snk->elem->hw_type == HW_TYPE_ANALOGUE &&
355 snk->elem->lr_num == lr_num) {
356 return snk;
357 }
358 }
359 return NULL;
360 }
361
362 // Set up monitor group sensitivity tracking for an output volume widget
363 static void setup_output_volume_monitor_group(
364 struct alsa_card *card,
365 GtkWidget *widget,
366 int lr_num
367 ) {
368 struct routing_snk *snk = get_analogue_output_snk(card, lr_num);
369 if (!snk)
370 return;
371
372 // Check if this output has monitor group controls
373 if (!snk->main_group_switch && !snk->alt_group_switch)
374 return;
375
376 // Create tracking data
377 struct output_volume_group_data *data =
378 g_malloc(sizeof(struct output_volume_group_data));
379 data->widget = widget;
380 data->main_group_switch = snk->main_group_switch;
381 data->alt_group_switch = snk->alt_group_switch;
382
383 // Register callbacks on the group switches
384 if (snk->main_group_switch) {
385 alsa_elem_add_callback(
386 snk->main_group_switch,
387 update_output_volume_sensitivity,
388 data,
389 NULL
390 );
391 }
392 if (snk->alt_group_switch) {
393 alsa_elem_add_callback(
394 snk->alt_group_switch,
395 update_output_volume_sensitivity,
396 data,
397 NULL
398 );
399 }
400
401 // Attach cleanup to the widget
402 g_object_weak_ref(
403 G_OBJECT(widget),
404 (GWeakNotify)free_output_volume_group_data,
405 data
406 );
407
408 // Set initial sensitivity
409 int in_group = 0;
410 if (snk->main_group_switch && alsa_get_elem_value(snk->main_group_switch))
411 in_group = 1;
412 if (snk->alt_group_switch && alsa_get_elem_value(snk->alt_group_switch))
413 in_group = 1;
414 gtk_widget_set_sensitive(widget, !in_group);
415 }
416
417 // Structure to track monitor group label widget
418 struct monitor_group_label_data {
419 GtkWidget *label;
420 struct alsa_elem *main_group_switch;
421 struct alsa_elem *alt_group_switch;
422 struct alsa_elem *speaker_switch_alt;
423 };
424
425 // Update monitor group label based on current state
426 static void update_monitor_group_label(
427 struct alsa_elem *elem,
428 void *data
429 ) {
430 struct monitor_group_label_data *d = data;
431
432 int in_main = d->main_group_switch &&
433 alsa_get_elem_value(d->main_group_switch);
434 int in_alt = d->alt_group_switch &&
435 alsa_get_elem_value(d->alt_group_switch);
436
437 // If not in any group, hide the label
438 if (!in_main && !in_alt) {
439 gtk_label_set_text(GTK_LABEL(d->label), "");
440 return;
441 }
442
443 // Check which group is active (0 = Main, 1 = Alt)
444 int alt_active = d->speaker_switch_alt &&
445 alsa_get_elem_value(d->speaker_switch_alt);
446
447 if (in_main && !alt_active) {
448 // Active in Main group - green
449 gtk_label_set_markup(
450 GTK_LABEL(d->label),
451 "<span color=\"#4a4\" size=\"small\">Main</span>"
452 );
453 } else if (in_alt && alt_active) {
454 // Active in Alt group - red
455 gtk_label_set_markup(
456 GTK_LABEL(d->label),
457 "<span color=\"#f66\" size=\"small\">Alt</span>"
458 );
459 } else if (in_main && alt_active) {
460 // In Main but Alt is active - dimmed
461 gtk_label_set_markup(
462 GTK_LABEL(d->label),
463 "<span color=\"#666\" size=\"small\">Main</span>"
464 );
465 } else if (in_alt && !alt_active) {
466 // In Alt but Main is active - dimmed
467 gtk_label_set_markup(
468 GTK_LABEL(d->label),
469 "<span color=\"#666\" size=\"small\">Alt</span>"
470 );
471 }
472 }
473
474 // Free monitor group label data
475 static void free_monitor_group_label_data(void *data) {
476 g_free(data);
477 }
478
479 // Create monitor group indicator label for an output
480 static GtkWidget *create_monitor_group_label(
481 struct alsa_card *card,
482 int lr_num
483 ) {
484 struct routing_snk *snk = get_analogue_output_snk(card, lr_num);
485 if (!snk)
486 return NULL;
487
488 // Check if this output has monitor group controls
489 if (!snk->main_group_switch && !snk->alt_group_switch)
490 return NULL;
491
492 // Get the speaker switching alt control
493 struct alsa_elem *speaker_switch_alt = get_elem_by_name(
494 card->elems, "Speaker Switching Alt Playback Switch"
495 );
496
497 // Create label widget
498 GtkWidget *label = gtk_label_new("");
499 gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
500
501 // Create tracking data
502 struct monitor_group_label_data *data =
503 g_malloc(sizeof(struct monitor_group_label_data));
504 data->label = label;
505 data->main_group_switch = snk->main_group_switch;
506 data->alt_group_switch = snk->alt_group_switch;
507 data->speaker_switch_alt = speaker_switch_alt;
508
509 // Register callbacks on all relevant controls
510 if (snk->main_group_switch)
511 alsa_elem_add_callback(
512 snk->main_group_switch, update_monitor_group_label, data, NULL
513 );
514 if (snk->alt_group_switch)
515 alsa_elem_add_callback(
516 snk->alt_group_switch, update_monitor_group_label, data, NULL
517 );
518 if (speaker_switch_alt)
519 alsa_elem_add_callback(
520 speaker_switch_alt, update_monitor_group_label, data, NULL
521 );
522
523 // Attach cleanup to the widget
524 g_object_weak_ref(
525 G_OBJECT(label),
526 (GWeakNotify)free_monitor_group_label_data,
527 data
528 );
529
530 // Set initial state
531 update_monitor_group_label(NULL, data);
532
533 return label;
534 }
535
536 static void add_talkback_controls_enum(
537 struct alsa_card *card,
538 GtkWidget *global_controls
539 ) {
540 GPtrArray *elems = card->elems;
541
542 struct alsa_elem *talkback = get_elem_by_name(
543 elems, "Talkback Playback Enum"
544 );
545
546 if (!talkback)
547 return;
548
549 GtkWidget *w = make_dual_boolean_alsa_elems(
550 talkback,
551 "Talkback",
552 "Disabled", "Enabled", "Off", "On"
553 );
554
555 gtk_widget_set_tooltip_text(
556 w,
557 "Talkback lets you add another channel (usually the talkback "
558 "mic) to a mix with a button push, usually to talk to "
559 "musicians, and without using an additional mic channel."
560 );
561
562 gtk_box_append(GTK_BOX(global_controls), w);
563 }
564
565 static void add_talkback_controls_switches(
566 struct alsa_card *card,
567 GtkWidget *global_controls
568 ) {
569 GPtrArray *elems = card->elems;
570
571 struct alsa_elem *enable = get_elem_by_name(
572 elems, "Talkback Enable Playback Switch"
573 );
574 struct alsa_elem *talk = get_elem_by_name(
575 elems, "Talk Playback Switch"
576 );
577
578 if (!enable || !talk)
579 return;
580
581 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
582 gtk_widget_set_tooltip_text(
583 box,
584 "Talkback lets you add another channel (usually the talkback "
585 "mic) to a mix with a button push, usually to talk to "
586 "musicians, and without using an additional mic channel."
587 );
588
589 GtkWidget *l = gtk_label_new("Talkback");
590 GtkWidget *w1 = make_boolean_alsa_elem(enable, "Disabled", "Enabled");
591 GtkWidget *w2 = make_boolean_alsa_elem(talk, "Talk", "Talk");
592
593 gtk_widget_add_css_class(w1, "talkback-enable");
594 gtk_widget_add_css_class(w2, "talk");
595
596 gtk_box_append(GTK_BOX(box), l);
597 gtk_box_append(GTK_BOX(box), w1);
598 gtk_box_append(GTK_BOX(box), w2);
599 gtk_box_append(GTK_BOX(global_controls), box);
600 }
601
602 static GtkWidget *create_global_box(GtkWidget *grid, int *x, int orient) {
603 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
604 gtk_widget_set_vexpand(box, TRUE);
605
606 GtkWidget *label = gtk_label_new("Global");
607 gtk_widget_add_css_class(label, "controls-label");
608 gtk_widget_set_halign(label, GTK_ALIGN_START);
609 GtkWidget *controls = gtk_box_new(orient, 15);
610 gtk_widget_add_css_class(controls, "controls-content");
611 gtk_widget_set_vexpand(controls, TRUE);
612
613 gtk_box_append(GTK_BOX(box), label);
614 gtk_box_append(GTK_BOX(box), controls);
615
616 gtk_grid_attach(GTK_GRID(grid), box, *x, 0, 1, 1);
617
618 (*x)++;
619
620 return controls;
621 }
622
623 /* 4th Gen Solo Mix switch */
624 static void create_input_select_control(
625 GPtrArray *elems,
626 GtkWidget *input_grid,
627 int *current_row
628 ) {
629 struct alsa_elem *elem = get_elem_by_name(elems, "PCM Input Capture Switch");
630
631 if (!elem)
632 return;
633
634 GtkWidget *w = make_boolean_alsa_elem(elem, "Mix", "Mix");
635 gtk_widget_add_css_class(w, "pcm-input-mix");
636 gtk_widget_set_tooltip_text(
637 w,
638 "Enabling Input Mix selects Mix E/F as the input source for "
639 "the PCM 1/2 Inputs rather than the DSP 1/2 Inputs. This is "
640 "useful to get a mono mix of both input channels."
641 );
642 gtk_grid_attach(GTK_GRID(input_grid), w, 0, *current_row, 2, 1);
643
644 (*current_row)++;
645 }
646
647 static void create_input_link_control(
648 struct alsa_elem *elem,
649 GtkWidget *grid,
650 int current_row,
651 int column_num
652 ) {
653 GtkWidget *w = make_boolean_alsa_elem(elem, "Link", NULL);
654 gtk_widget_add_css_class(w, "input-link");
655 gtk_widget_set_hexpand(w, TRUE);
656
657 int from, to;
658 get_two_num_from_string(elem->name, &from, &to);
659
660 // skip even numbers
661 if (!(from % 2))
662 return;
663
664 if (to == -1)
665 to = from + 1;
666
667 gtk_grid_attach(GTK_GRID(grid), w, from - 1, current_row, to - from + 1, 1);
668 }
669
670 static void create_input_gain_control(
671 struct alsa_card *card,
672 struct alsa_elem *elem,
673 GtkWidget *grid,
674 int current_row,
675 int column_num
676 ) {
677 GtkWidget *w = make_gain_alsa_elem(elem, 0, WIDGET_GAIN_TAPER_LINEAR, 1, TRUE);
678
679 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
680
681 // find the routing source for this input's port number
682 // input gains correspond to hardware inputs (PC_HW)
683 struct routing_src *r_src = NULL;
684 for (int i = 0; i < card->routing_srcs->len; i++) {
685 struct routing_src *src = &g_array_index(
686 card->routing_srcs, struct routing_src, i
687 );
688 if (src->port_category == PC_HW && src->port_num == elem->lr_num - 1) {
689 r_src = src;
690 break;
691 }
692 }
693
694 // store widget in card's list
695 struct input_gain_widget *ig = g_malloc(sizeof(struct input_gain_widget));
696 ig->widget = w;
697 ig->port_num = elem->lr_num;
698 ig->r_src = r_src;
699 card->input_gain_widgets = g_list_append(card->input_gain_widgets, ig);
700 }
701
702 static void create_input_autogain_control(
703 struct alsa_elem *elem,
704 GtkWidget *grid,
705 int current_row,
706 int column_num
707 ) {
708 GtkWidget *w = make_boolean_alsa_elem(elem, "Autogain", NULL);
709 gtk_widget_add_css_class(w, "autogain");
710 gtk_widget_set_hexpand(w, TRUE);
711 gtk_widget_set_tooltip_text(
712 w,
713 "Autogain will listen to the input signal for 10 seconds and "
714 "automatically set the gain of the input channel to get the "
715 "best signal level."
716 );
717
718 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
719 }
720
721 static void create_input_autogain_status_control(
722 struct alsa_elem *elem,
723 GtkWidget *grid,
724 int current_row,
725 int column_num
726 ) {
727 GtkWidget *w = make_label_alsa_elem(elem);
728
729 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
730 }
731
732 static void create_input_safe_control(
733 struct alsa_elem *elem,
734 GtkWidget *grid,
735 int current_row,
736 int column_num
737 ) {
738 GtkWidget *w = make_boolean_alsa_elem(elem, "Safe", NULL);
739 gtk_widget_add_css_class(w, "safe");
740 gtk_widget_set_hexpand(w, TRUE);
741 gtk_widget_set_tooltip_text(
742 w,
743 "Enabling Safe Mode prevents the input from clipping by "
744 "automatically reducing the gain if the signal is too hot."
745 );
746
747 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
748 }
749
750 static void create_input_level_control(
751 struct alsa_elem *elem,
752 GtkWidget *grid,
753 int current_row,
754 int column_num
755 ) {
756 GtkWidget *w = make_boolean_alsa_elem(elem, "Inst", NULL);
757 gtk_widget_add_css_class(w, "inst");
758 gtk_widget_set_hexpand(w, TRUE);
759 gtk_widget_set_tooltip_text(w, level_descr);
760
761 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
762 }
763
764 static void create_input_air_switch_control(
765 struct alsa_elem *elem,
766 GtkWidget *grid,
767 int current_row,
768 int column_num
769 ) {
770 GtkWidget *w = make_boolean_alsa_elem(elem, "Air", NULL);
771 gtk_widget_add_css_class(w, "air");
772 gtk_widget_set_hexpand(w, TRUE);
773 gtk_widget_set_tooltip_text(w, air_descr);
774
775 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
776 }
777
778 static void create_input_air_enum_control(
779 struct alsa_elem *elem,
780 GtkWidget *grid,
781 int current_row,
782 int column_num
783 ) {
784 GtkWidget *w = make_drop_down_alsa_elem(elem, "Air");
785 gtk_widget_add_css_class(w, "air");
786 gtk_widget_set_hexpand(w, TRUE);
787 gtk_widget_set_tooltip_text(w, air_descr);
788
789 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
790 }
791
792 static void create_input_dsp_switch_control(
793 struct alsa_elem *elem,
794 GtkWidget *grid,
795 int current_row,
796 int column_num
797 ) {
798 GtkWidget *w = make_boolean_alsa_elem(elem, "Enhance", NULL);
799 gtk_widget_add_css_class(w, "dsp");
800 gtk_widget_set_hexpand(w, TRUE);
801 // gtk_widget_set_tooltip_text(w, dsp_descr);
802
803 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
804 }
805
806 static void create_input_dsp_preset_control(
807 struct alsa_elem *elem,
808 GtkWidget *grid,
809 int current_row,
810 int column_num
811 ) {
812 GtkWidget *w = make_drop_down_alsa_elem(elem, NULL);
813 gtk_widget_add_css_class(w, "dsp-preset");
814 gtk_widget_set_hexpand(w, TRUE);
815 // gtk_widget_set_tooltip_text(w, dsp_descr);
816
817 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
818 }
819
820 static void create_input_mute_switch_control(
821 struct alsa_elem *elem,
822 GtkWidget *grid,
823 int current_row,
824 int column_num
825 ) {
826 GtkWidget *w = make_boolean_alsa_elem(elem, "Mute", NULL);
827 gtk_widget_add_css_class(w, "input-mute");
828 gtk_widget_set_hexpand(w, TRUE);
829 // gtk_widget_set_tooltip_text(w, dsp_descr);
830
831 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
832 }
833
834 static void create_input_pad_control(
835 struct alsa_elem *elem,
836 GtkWidget *grid,
837 int current_row,
838 int column_num
839 ) {
840 GtkWidget *w = make_boolean_alsa_elem(elem, "Pad", NULL);
841 gtk_widget_add_css_class(w, "pad");
842 gtk_widget_set_hexpand(w, TRUE);
843 gtk_widget_set_tooltip_text(
844 w,
845 "Enabling Pad engages a 10dB attenuator in the channel, giving "
846 "you more headroom for very hot signals."
847 );
848
849 gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1);
850 }
851
852 static void create_input_gain_switch_control(
853 struct alsa_elem *elem,
854 GtkWidget *grid,
855 int current_row,
856 int column_num
857 ) {
858 GtkWidget *w = make_boolean_alsa_elem(elem, "Gain", NULL);
859 gtk_widget_add_css_class(w, "gain-switch");
860 gtk_widget_set_hexpand(w, TRUE);
861 gtk_widget_set_tooltip_text(
862 w,
863 "Enabling Gain switches from Low gain input (0dBFS = +16dBu)\n"
864 "to High gain input (0dBFS = −10dBV, approx −6dBu)."
865 );
866
867 // ignore current_row, always put it in the first row
868 gtk_grid_attach(GTK_GRID(grid), w, column_num, 1, 1, 1);
869 }
870
871 static void create_input_phantom_control(
872 struct alsa_elem *elem,
873 GtkWidget *grid,
874 int current_row,
875 int column_num
876 ) {
877 GtkWidget *w = make_boolean_alsa_elem(elem, "48V", NULL);
878 gtk_widget_add_css_class(w, "phantom");
879 gtk_widget_set_hexpand(w, TRUE);
880 gtk_widget_set_tooltip_text(w, phantom_descr);
881
882 int from, to;
883 get_two_num_from_string(elem->name, &from, &to);
884 if (to == -1)
885 to = from;
886
887 gtk_grid_attach(GTK_GRID(grid), w, from - 1, current_row, to - from + 1, 1);
888 }
889
890 static void create_input_controls_by_type(
891 GPtrArray *elems,
892 GtkWidget *grid,
893 int *current_row,
894 char *control,
895 void (*create_func)(struct alsa_elem *, GtkWidget *, int, int)
896 ) {
897 int count = 0;
898
899 for (int i = 0; i < elems->len; i++) {
900 struct alsa_elem *elem = g_ptr_array_index(elems, i);
901
902 // if no card entry, it's an empty slot
903 if (!elem->card)
904 continue;
905
906 if (!strstr(elem->name, control))
907 continue;
908
909 int column_num = get_num_from_string(elem->name) - 1;
910 create_func(elem, grid, *current_row, column_num);
911
912 count++;
913 }
914
915 // Don't increment row for 4th Gen Solo Inst control so Air control
916 // goes next to it
917 if (!strcmp(control, "Level Capture Enum") && count == 1)
918 return;
919
920 if (count)
921 (*current_row)++;
922 }
923
924 // variant that passes card to the callback
925 static void create_input_controls_by_type_with_card(
926 struct alsa_card *card,
927 GPtrArray *elems,
928 GtkWidget *grid,
929 int *current_row,
930 char *control,
931 void (*create_func)(struct alsa_card *, struct alsa_elem *, GtkWidget *, int, int)
932 ) {
933 int count = 0;
934
935 for (int i = 0; i < elems->len; i++) {
936 struct alsa_elem *elem = g_ptr_array_index(elems, i);
937
938 if (!elem->card)
939 continue;
940
941 if (!strstr(elem->name, control))
942 continue;
943
944 int column_num = get_num_from_string(elem->name) - 1;
945 create_func(card, elem, grid, *current_row, column_num);
946
947 count++;
948 }
949
950 if (count)
951 (*current_row)++;
952 }
953
954 static void create_input_controls(
955 struct alsa_card *card,
956 GtkWidget *top,
957 int *x,
958 int input_count
959 ) {
960 GPtrArray *elems = card->elems;
961
962 // Only the 18i20 Gen 2 has no input controls
963 if (!input_count)
964 return;
965
966 struct alsa_elem *input_select_elem =
967 get_elem_by_name(elems, "Input Select Capture Enum");
968
969 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
970
971 GtkWidget *label_ic = gtk_label_new("Analogue Inputs");
972 gtk_widget_add_css_class(label_ic, "controls-label");
973 gtk_widget_set_halign(label_ic, GTK_ALIGN_START);
974 gtk_box_append(GTK_BOX(box), label_ic);
975
976 GtkWidget *input_grid = gtk_grid_new();
977 gtk_widget_add_css_class(input_grid, "controls-content");
978 gtk_grid_set_spacing(GTK_GRID(input_grid), 10);
979 gtk_widget_set_hexpand(input_grid, TRUE);
980 gtk_widget_set_halign(input_grid, GTK_ALIGN_FILL);
981 gtk_widget_set_vexpand(input_grid, TRUE);
982 gtk_box_append(GTK_BOX(box), input_grid);
983
984 gtk_grid_attach(GTK_GRID(top), box, *x, 0, 1, 1);
985
986 for (int i = 1; i <= input_count; i++) {
987 GtkWidget *label;
988
989 if (input_select_elem) {
990 label = make_input_select_alsa_elem(input_select_elem, i);
991 } else {
992 char s[20];
993 snprintf(s, 20, "%d", i);
994 label = gtk_label_new(s);
995 }
996 gtk_grid_attach(GTK_GRID(input_grid), label, i - 1, 0, 1, 1);
997 }
998
999 int current_row = 1;
1000
1001 // 4th Gen Solo, put the Phantom Power control above the Air control
1002 if (get_elem_by_name(elems, "Direct Monitor Playback Switch")) {
1003 create_input_controls_by_type(
1004 elems, input_grid, &current_row,
1005 "Level Capture Enum", create_input_level_control
1006 );
1007 create_input_controls_by_type(
1008 elems, input_grid, &current_row,
1009 "Phantom Power Capture Switch", create_input_phantom_control
1010 );
1011 create_input_controls_by_type(
1012 elems, input_grid, &current_row,
1013 "Air Capture Enum", create_input_air_enum_control
1014 );
1015
1016 (*x)++;
1017 return;
1018 }
1019
1020 create_input_select_control(elems, input_grid, &current_row);
1021
1022 create_input_controls_by_type(
1023 elems, input_grid, &current_row,
1024 "Link Capture Switch", create_input_link_control
1025 );
1026 create_input_controls_by_type_with_card(
1027 card, elems, input_grid, &current_row,
1028 "Gain Capture Volume", create_input_gain_control
1029 );
1030 create_input_controls_by_type(
1031 elems, input_grid, &current_row,
1032 "Autogain Capture Switch", create_input_autogain_control
1033 );
1034 create_input_controls_by_type(
1035 elems, input_grid, &current_row,
1036 "Autogain Status Capture Enum", create_input_autogain_status_control
1037 );
1038 create_input_controls_by_type(
1039 elems, input_grid, &current_row,
1040 "Safe Capture Switch", create_input_safe_control
1041 );
1042 create_input_controls_by_type(
1043 elems, input_grid, &current_row,
1044 "Level Capture Enum", create_input_level_control
1045 );
1046 create_input_controls_by_type(
1047 elems, input_grid, &current_row,
1048 "Impedance Switch", create_input_level_control
1049 );
1050 create_input_controls_by_type(
1051 elems, input_grid, &current_row,
1052 "Air Capture Switch", create_input_air_switch_control
1053 );
1054 create_input_controls_by_type(
1055 elems, input_grid, &current_row,
1056 "Air Capture Enum", create_input_air_enum_control
1057 );
1058 create_input_controls_by_type(
1059 elems, input_grid, &current_row,
1060 "DSP Capture Switch", create_input_dsp_switch_control
1061 );
1062 create_input_controls_by_type(
1063 elems, input_grid, &current_row,
1064 "DSP Preset Capture Enum", create_input_dsp_preset_control
1065 );
1066 create_input_controls_by_type(
1067 elems, input_grid, &current_row,
1068 "Mute Capture Switch", create_input_mute_switch_control
1069 );
1070 create_input_controls_by_type(
1071 elems, input_grid, &current_row,
1072 "Pad Capture Switch", create_input_pad_control
1073 );
1074 create_input_controls_by_type(
1075 elems, input_grid, &current_row,
1076 "Pad Switch", create_input_pad_control
1077 );
1078 create_input_controls_by_type(
1079 elems, input_grid, &current_row,
1080 "Gain Switch", create_input_gain_switch_control
1081 );
1082 create_input_controls_by_type(
1083 elems, input_grid, &current_row,
1084 "Phantom Power Capture Switch", create_input_phantom_control
1085 );
1086
1087 (*x)++;
1088 }
1089
1090 static void create_output_controls(
1091 struct alsa_card *card,
1092 GtkWidget *top,
1093 int *x,
1094 int y,
1095 int x_span,
1096 int output_count
1097 ) {
1098 GPtrArray *elems = card->elems;
1099
1100 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
1101
1102 GtkWidget *label_oc = gtk_label_new("Analogue Outputs");
1103 gtk_widget_add_css_class(label_oc, "controls-label");
1104 gtk_widget_set_halign(label_oc, GTK_ALIGN_START);
1105 gtk_box_append(GTK_BOX(box), label_oc);
1106
1107 GtkWidget *output_grid = gtk_grid_new();
1108 gtk_widget_add_css_class(output_grid, "controls-content");
1109 gtk_grid_set_spacing(GTK_GRID(output_grid), 10);
1110 gtk_widget_set_hexpand(output_grid, TRUE);
1111 gtk_widget_set_vexpand(output_grid, TRUE);
1112 gtk_box_append(GTK_BOX(box), output_grid);
1113
1114 gtk_grid_attach(GTK_GRID(top), box, *x, y, x_span, 1);
1115
1116 /* 4th Gen Solo/2i2 */
1117 if (get_elem_by_prefix(elems, "Direct Monitor Playback")) {
1118 struct alsa_elem *elem;
1119
1120 for (int i = 0; i < 2; i++) {
1121 char s[20];
1122 snprintf(s, 20, "%d", i + 1);
1123 GtkWidget *label = gtk_label_new(s);
1124 gtk_grid_attach(GTK_GRID(output_grid), label, i, 0, 1, 1);
1125 }
1126
1127 /* Solo */
1128
1129 elem = get_elem_by_name(elems, "Direct Monitor Playback Switch");
1130
1131 if (elem) {
1132 GtkWidget *w = make_boolean_alsa_elem(elem, "Direct Monitor", NULL);
1133 gtk_widget_add_css_class(w, "direct-monitor");
1134 gtk_widget_set_tooltip_text(
1135 w,
1136 "Direct Monitor sends the analogue input signals to the "
1137 "analogue outputs for zero-latency monitoring."
1138 );
1139 gtk_grid_attach(GTK_GRID(output_grid), w, 0, 1, 2, 1);
1140 }
1141
1142 /* 2i2 */
1143
1144 elem = get_elem_by_name(elems, "Direct Monitor Playback Enum");
1145
1146 if (elem) {
1147 GtkWidget *w = make_drop_down_alsa_elem(elem, "Direct Monitor");
1148 gtk_widget_add_css_class(w, "direct-monitor");
1149 gtk_widget_set_tooltip_text(
1150 w,
1151 "Direct Monitor sends the analogue input signals to the "
1152 "analogue outputs for zero-latency monitoring."
1153 );
1154 gtk_grid_attach(GTK_GRID(output_grid), w, 0, 1, 2, 1);
1155 }
1156
1157 return;
1158 }
1159
1160 int has_sw_hw_ctrls =
1161 !!get_elem_by_substr(elems, "Volume Control Playback Enum");
1162 int line_1_col =
1163 has_sw_hw_ctrls ||
1164 get_elem_by_name(elems, "Mute Playback Switch") ||
1165 get_elem_by_name(elems, "Master Playback Switch");
1166
1167 for (int i = 0; i < output_count; i++) {
1168 char s[20];
1169 snprintf(s, 20, "%d", i + 1);
1170 GtkWidget *label = gtk_label_new(s);
1171 gtk_grid_attach(GTK_GRID(output_grid), label, i + line_1_col, 0, 1, 1);
1172 }
1173
1174 for (int i = 0; i < elems->len; i++) {
1175 struct alsa_elem *elem = g_ptr_array_index(elems, i);
1176 GtkWidget *w;
1177
1178 // if no card entry, it's an empty slot
1179 if (!elem->card)
1180 continue;
1181
1182 // output controls
1183
1184 // Gen 1 master output control
1185 if (strcmp(elem->name, "Master Playback Volume") == 0) {
1186 GtkWidget *l = gtk_label_new("Master");
1187 gtk_grid_attach(GTK_GRID(output_grid), l, 0, 0, 1, 1);
1188 w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG, 0, FALSE);
1189 gtk_widget_set_tooltip_text(w, "Master Volume Control");
1190 gtk_grid_attach(GTK_GRID(output_grid), w, 0, 2, 1, 1);
1191
1192 } else if (strncmp(elem->name, "Line", 4) == 0 ||
1193 (strncmp(elem->name, "Master", 6) == 0 && elem->lr_num) ||
1194 strncmp(elem->name, "Analogue", 8) == 0) {
1195
1196 if (strstr(elem->name, "Playback Volume")) {
1197 w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG, 1, TRUE);
1198 setup_output_volume_monitor_group(card, w, elem->lr_num);
1199 gtk_grid_attach(
1200 GTK_GRID(output_grid), w, elem->lr_num - 1 + line_1_col, 2, 1, 1
1201 );
1202
1203 // store widget in card's list for level updates
1204 struct routing_snk *r_snk = get_output_r_snk(card, elem->lr_num);
1205 struct output_gain_widget *og = g_malloc(sizeof(struct output_gain_widget));
1206 og->widget = w;
1207 og->port_num = elem->lr_num;
1208 og->r_snk = r_snk;
1209 card->output_gain_widgets = g_list_append(card->output_gain_widgets, og);
1210
1211 } else if (strstr(elem->name, "Playback Switch")) {
1212 w = make_boolean_alsa_elem(
1213 elem, "*audio-volume-high", "*audio-volume-muted"
1214 );
1215 gtk_widget_add_css_class(w, "mute");
1216 if (has_sw_hw_ctrls) {
1217 gtk_widget_set_tooltip_text(
1218 w,
1219 "Mute (only available when under software control)"
1220 );
1221 } else {
1222 gtk_widget_set_tooltip_text(w, "Mute");
1223 }
1224 gtk_grid_attach(
1225 GTK_GRID(output_grid), w, elem->lr_num - 1 + line_1_col, 3, 1, 1
1226 );
1227 } else if (strstr(elem->name, "Volume Control Playback Enum")) {
1228 w = make_boolean_alsa_elem(elem, "SW", "HW");
1229 gtk_widget_add_css_class(w, "sw-hw");
1230 gtk_widget_set_tooltip_text(
1231 w,
1232 "Set software-controlled (SW) or hardware-controlled (HW) "
1233 "volume for this analogue output."
1234 );
1235 gtk_grid_attach(
1236 GTK_GRID(output_grid), w, elem->lr_num - 1 + line_1_col, 4, 1, 1
1237 );
1238 }
1239
1240 // master output controls
1241 } else if (strcmp(elem->name, "Master HW Playback Volume") == 0) {
1242 int gen4 = !!strstr(card->name, "4th Gen");
1243
1244 GtkWidget *l = gtk_label_new(gen4 ? "Line 1–2" : "HW");
1245 gtk_grid_attach(GTK_GRID(output_grid), l, 0, 0, 1, 1);
1246 if (gen4) {
1247 w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_GEN4_VOLUME, 0, FALSE);
1248 } else {
1249 w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG, 0, FALSE);
1250 }
1251 gtk_widget_set_tooltip_text(
1252 w,
1253 gen4
1254 ? "This control shows the setting of the master volume "
1255 "knob, which controls the volume of the analogue line "
1256 "outputs 1 and 2."
1257 : "This control shows the setting of the physical "
1258 "(hardware) volume knob, which controls the volume of "
1259 "the analogue outputs which have been set to “HW”."
1260 );
1261 gtk_grid_attach(GTK_GRID(output_grid), w, 0, 2, 1, 1);
1262 } else if (strcmp(elem->name, "Headphone Playback Volume") == 0) {
1263 GtkWidget *l = gtk_label_new("Headphones");
1264 gtk_widget_set_tooltip_text(
1265 l,
1266 "This control shows the setting of the headphone volume knob."
1267 );
1268 gtk_grid_attach(GTK_GRID(output_grid), l, 1, 0, 1, 1);
1269 w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_GEN4_VOLUME, 0, FALSE);
1270 gtk_grid_attach(GTK_GRID(output_grid), w, 1, 2, 1, 1);
1271 } else if (strcmp(elem->name, "Mute Playback Switch") == 0) {
1272 w = make_boolean_alsa_elem(
1273 elem, "*audio-volume-high", "*audio-volume-muted"
1274 );
1275 gtk_widget_add_css_class(w, "mute");
1276 gtk_widget_set_tooltip_text(w, "Mute HW controlled outputs");
1277 gtk_grid_attach(GTK_GRID(output_grid), w, 0, 3, 1, 1);
1278 } else if (strcmp(elem->name, "Dim Playback Switch") == 0) {
1279 w = make_boolean_alsa_elem(
1280 elem, "*audio-volume-medium", "*audio-volume-low"
1281 );
1282 gtk_widget_add_css_class(w, "dim");
1283 gtk_widget_set_tooltip_text(
1284 w, "Dim (lower volume) of HW controlled outputs"
1285 );
1286 gtk_grid_attach(GTK_GRID(output_grid), w, 0, 4, 1, 1);
1287 } else if (strcmp(elem->name, "Speaker Mute Playback Switch") == 0) {
1288 w = make_boolean_alsa_elem(
1289 elem, "*audio-volume-high", "*audio-volume-muted"
1290 );
1291 gtk_widget_add_css_class(w, "mute");
1292 gtk_widget_set_tooltip_text(w, "Mute speaker output");
1293 gtk_grid_attach(GTK_GRID(output_grid), w, 0, 5, 1, 1);
1294 } else if (strstr(elem->name, "Headphones") &&
1295 strstr(elem->name, "Mute Playback Switch")) {
1296 int headphones_num = get_num_from_string(elem->name);
1297 int column = headphones_num > 0 ? headphones_num : 1;
1298
1299 w = make_boolean_alsa_elem(
1300 elem, "*audio-headphones-symbolic", "*audio-headphones-symbolic"
1301 );
1302 gtk_widget_add_css_class(w, "mute");
1303
1304 if (headphones_num > 0) {
1305 char tooltip[50];
1306 snprintf(tooltip, 50, "Mute headphones %d output", headphones_num);
1307 gtk_widget_set_tooltip_text(w, tooltip);
1308 } else {
1309 gtk_widget_set_tooltip_text(w, "Mute headphones output");
1310 }
1311
1312 gtk_grid_attach(GTK_GRID(output_grid), w, column, 5, 1, 1);
1313 }
1314 }
1315
1316 // Add monitor group indicator labels for each output
1317 for (int i = 0; i < output_count; i++) {
1318 GtkWidget *label = create_monitor_group_label(card, i + 1);
1319 if (label) {
1320 gtk_grid_attach(
1321 GTK_GRID(output_grid), label, i + line_1_col, 1, 1, 1
1322 );
1323 }
1324 }
1325
1326 (*x)++;
1327 }
1328
1329 static void create_global_controls(
1330 struct alsa_card *card,
1331 GtkWidget *top,
1332 int *x
1333 ) {
1334 int orient = card->has_speaker_switching
1335 ? GTK_ORIENTATION_HORIZONTAL
1336 : GTK_ORIENTATION_VERTICAL;
1337 GtkWidget *global_controls = create_global_box(top, x, orient);
1338 GtkWidget *column[3];
1339
1340 for (int i = 0; i < 3; i++)
1341 column[i] = global_controls;
1342
1343 if (card->has_speaker_switching) {
1344 for (int i = 0; i < 3; i++) {
1345 column[i] = gtk_box_new(GTK_ORIENTATION_VERTICAL, 15);
1346 gtk_box_append(GTK_BOX(global_controls), column[i]);
1347 }
1348 }
1349
1350 add_clock_source_control(card, column[0]);
1351 add_sync_status_control(card, column[1]);
1352 add_power_status_control(card, column[1]);
1353 add_sample_rate_control(card, column[2]);
1354 add_speaker_switching_controls_enum(card, column[0]);
1355 add_speaker_switching_controls_switches(card, column[0]);
1356 add_speaker_switching_controls_gen4(card, column[0]);
1357 add_talkback_controls_enum(card, column[1]);
1358 add_talkback_controls_switches(card, column[1]);
1359
1360 // Add Presets button if device has a serial number
1361 if (card->serial && *card->serial) {
1362 GtkWidget *presets_button = create_presets_button(card);
1363 gtk_widget_set_valign(presets_button, GTK_ALIGN_END);
1364 gtk_widget_set_vexpand(presets_button, TRUE);
1365 gtk_box_append(GTK_BOX(column[2]), presets_button);
1366 }
1367 }
1368
1369 static GtkWidget *create_main_window_controls(struct alsa_card *card) {
1370 int x = 0;
1371
1372 GtkWidget *top = gtk_grid_new();
1373 gtk_widget_add_css_class(top, "window-content");
1374 gtk_widget_add_css_class(top, "iface-mixer");
1375
1376 if (strstr(card->name, "4th Gen") ||
1377 strstr(card->name, "Gen 4")) {
1378 gtk_widget_add_css_class(top, "gen4");
1379 } else if (strstr(card->name, "Scarlett")) {
1380 gtk_widget_add_css_class(top, "scarlett");
1381 } else if (strstr(card->name, "Clarett")) {
1382 gtk_widget_add_css_class(top, "clarett");
1383 } else if (strstr(card->name, "Vocaster")) {
1384 gtk_widget_add_css_class(top, "vocaster");
1385 }
1386
1387 gtk_grid_set_spacing(GTK_GRID(top), 15);
1388
1389 int input_count = get_max_elem_by_name(
1390 card->elems, "Line", "Capture Switch"
1391 );
1392 if (!input_count)
1393 input_count =
1394 get_max_elem_by_name(card->elems, "Input", "Switch");
1395
1396 int output_count = get_max_elem_by_name(
1397 card->elems, "Line", "Playback Volume"
1398 );
1399 if (!output_count)
1400 output_count =
1401 get_max_elem_by_name(card->elems, "Master", "Playback Volume") * 2;
1402 if (!output_count)
1403 output_count =
1404 get_max_elem_by_name(card->elems, "Analogue", "Playback Volume");
1405
1406 create_global_controls(card, top, &x);
1407 create_input_controls(card, top, &x, input_count);
1408
1409 if (input_count + output_count >= 12) {
1410 x = 0;
1411 create_output_controls(card, top, &x, 1, 2, output_count);
1412 } else {
1413 create_output_controls(card, top, &x, 0, 1, output_count);
1414 }
1415
1416 return top;
1417 }
1418
1419 static gboolean window_routing_close_request(GtkWindow *w, gpointer data) {
1420 struct alsa_card *card = data;
1421
1422 gtk_widget_activate_action(
1423 GTK_WIDGET(card->window_main), "win.routing", NULL
1424 );
1425 return true;
1426 }
1427
1428 static gboolean window_mixer_close_request(GtkWindow *w, gpointer data) {
1429 struct alsa_card *card = data;
1430
1431 gtk_widget_activate_action(
1432 GTK_WIDGET(card->window_main), "win.mixer", NULL
1433 );
1434 return true;
1435 }
1436
1437 static gboolean window_configuration_close_request(GtkWindow *w, gpointer data) {
1438 struct alsa_card *card = data;
1439
1440 gtk_widget_activate_action(
1441 card->window_main,
1442 "win.configuration",
1443 NULL
1444 );
1445
1446 return true;
1447 }
1448
1449 static gboolean window_levels_close_request(GtkWindow *w, gpointer data) {
1450 struct alsa_card *card = data;
1451
1452 gtk_widget_activate_action(
1453 GTK_WIDGET(card->window_main), "win.levels", NULL
1454 );
1455 return true;
1456 }
1457
1458 static gboolean window_dsp_close_request(GtkWindow *w, gpointer data) {
1459 struct alsa_card *card = data;
1460
1461 gtk_widget_activate_action(
1462 GTK_WIDGET(card->window_main), "win.dsp", NULL
1463 );
1464 return true;
1465 }
1466
1467 static gboolean window_preferences_close_request(GtkWindow *w, gpointer data) {
1468 struct alsa_card *card = data;
1469
1470 gtk_widget_activate_action(
1471 GTK_WIDGET(card->window_main), "win.preferences", NULL
1472 );
1473 return true;
1474 }
1475
1476 // wrap a scrolled window around the controls
1477 static void create_scrollable_window(GtkWidget *window, GtkWidget *controls) {
1478 GtkWidget *scrolled_window = gtk_scrolled_window_new();
1479
1480 gtk_scrolled_window_set_policy(
1481 GTK_SCROLLED_WINDOW(scrolled_window),
1482 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC
1483 );
1484 gtk_scrolled_window_set_child(
1485 GTK_SCROLLED_WINDOW(scrolled_window), controls
1486 );
1487 gtk_scrolled_window_set_propagate_natural_height(
1488 GTK_SCROLLED_WINDOW(scrolled_window), TRUE
1489 );
1490 gtk_scrolled_window_set_propagate_natural_width(
1491 GTK_SCROLLED_WINDOW(scrolled_window), TRUE
1492 );
1493
1494 gtk_window_set_child(GTK_WINDOW(window), scrolled_window);
1495 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1496 }
1497
1498 GtkWidget *create_iface_mixer_main(struct alsa_card *card) {
1499
1500 // clear any existing input gain widgets from previous interface
1501 for (GList *l = card->input_gain_widgets; l != NULL; l = l->next)
1502 g_free(l->data);
1503 g_list_free(card->input_gain_widgets);
1504 card->input_gain_widgets = NULL;
1505
1506 // clear any existing output gain widgets from previous interface
1507 for (GList *l = card->output_gain_widgets; l != NULL; l = l->next)
1508 g_free(l->data);
1509 g_list_free(card->output_gain_widgets);
1510 card->output_gain_widgets = NULL;
1511
1512 card->has_speaker_switching =
1513 get_elem_by_name(card->elems, "Speaker Switching Playback Enum") ||
1514 get_elem_by_name(card->elems, "Speaker Switching Playback Switch");
1515
1516 card->has_talkback =
1517 get_elem_by_name(card->elems, "Talkback Playback Enum") ||
1518 get_elem_by_name(card->elems, "Talkback Enable Playback Switch");
1519
1520 GtkWidget *top = gtk_frame_new(NULL);
1521 gtk_widget_add_css_class(top, "window-frame");
1522 GtkWidget *contents = create_main_window_controls(card);
1523 gtk_frame_set_child(GTK_FRAME(top), contents);
1524
1525 GtkWidget *routing_top = create_routing_controls(card);
1526 if (!routing_top)
1527 return NULL;
1528
1529 // initialise level indication for routing lines
1530 routing_levels_init(card);
1531
1532 card->window_routing = create_subwindow(
1533 card, "Routing", G_CALLBACK(window_routing_close_request)
1534 );
1535
1536 create_scrollable_window(card->window_routing, routing_top);
1537
1538 GtkWidget *mixer_top = create_mixer_controls(card);
1539
1540 card->window_mixer = create_subwindow(
1541 card, "Mixer", G_CALLBACK(window_mixer_close_request)
1542 );
1543
1544 create_scrollable_window(card->window_mixer, mixer_top);
1545
1546 GtkWidget *levels_top = create_levels_controls(card);
1547
1548 card->window_levels = create_subwindow(
1549 card, "Levels", G_CALLBACK(window_levels_close_request)
1550 );
1551
1552 gtk_window_set_child(GTK_WINDOW(card->window_levels), levels_top);
1553
1554 card->window_startup = create_subwindow(
1555 card, "Startup Configuration", G_CALLBACK(window_startup_close_request)
1556 );
1557
1558 GtkWidget *startup = create_startup_controls(card);
1559 gtk_window_set_child(GTK_WINDOW(card->window_startup), startup);
1560
1561 card->window_configuration = create_subwindow(
1562 card, "Configuration", G_CALLBACK(window_configuration_close_request)
1563 );
1564 gtk_window_set_resizable(GTK_WINDOW(card->window_configuration), TRUE);
1565
1566 GtkWidget *configuration = create_configuration_controls(card);
1567 gtk_window_set_child(GTK_WINDOW(card->window_configuration), configuration);
1568
1569 // create DSP window if DSP controls are available
1570 if (get_elem_by_name(card->elems, "Line In 1 DSP Capture Switch")) {
1571 card->window_dsp = create_subwindow(
1572 card, "DSP", G_CALLBACK(window_dsp_close_request)
1573 );
1574
1575 GtkWidget *dsp = create_dsp_controls(card);
1576 gtk_window_set_child(GTK_WINDOW(card->window_dsp), dsp);
1577 }
1578
1579 card->window_preferences = create_subwindow(
1580 card, "Preferences",
1581 G_CALLBACK(window_preferences_close_request)
1582 );
1583
1584 GtkWidget *preferences = create_preferences_controls(card);
1585 gtk_window_set_child(
1586 GTK_WINDOW(card->window_preferences), preferences
1587 );
1588
1589 return top;
1590 }