Add input select widget for 4th Gen 2i2 and 4i4

This commit is contained in:
Geoffrey D. Bennett
2023-12-04 00:49:44 +10:30
parent 47034d7901
commit b35fa3cf50
3 changed files with 103 additions and 3 deletions

View File

@@ -9,6 +9,7 @@
#include "widget-combo.h" #include "widget-combo.h"
#include "widget-dual.h" #include "widget-dual.h"
#include "widget-gain.h" #include "widget-gain.h"
#include "widget-input-select.h"
#include "widget-label.h" #include "widget-label.h"
#include "window-helper.h" #include "window-helper.h"
#include "window-levels.h" #include "window-levels.h"
@@ -339,6 +340,9 @@ static void create_input_controls(
if (!input_count) if (!input_count)
return; return;
struct alsa_elem *input_select_elem =
get_elem_by_name(elems, "Input Select Capture Enum");
GtkWidget *sep = gtk_separator_new(GTK_ORIENTATION_VERTICAL); GtkWidget *sep = gtk_separator_new(GTK_ORIENTATION_VERTICAL);
gtk_widget_set_halign(sep, GTK_ALIGN_CENTER); gtk_widget_set_halign(sep, GTK_ALIGN_CENTER);
gtk_grid_attach(GTK_GRID(top), sep, (*x)++, 0, 1, 3); gtk_grid_attach(GTK_GRID(top), sep, (*x)++, 0, 1, 3);
@@ -354,9 +358,15 @@ static void create_input_controls(
gtk_grid_attach(GTK_GRID(top), input_grid, *x, 2, 1, 1); gtk_grid_attach(GTK_GRID(top), input_grid, *x, 2, 1, 1);
for (int i = 1; i <= input_count; i++) { for (int i = 1; i <= input_count; i++) {
GtkWidget *label;
if (input_select_elem) {
label = make_input_select_alsa_elem(input_select_elem, i);
} else {
char s[20]; char s[20];
snprintf(s, 20, "%d", i); snprintf(s, 20, "%d", i);
GtkWidget *label = gtk_label_new(s); label = gtk_label_new(s);
}
gtk_grid_attach(GTK_GRID(input_grid), label, i, 0, 1, 1); gtk_grid_attach(GTK_GRID(input_grid), label, i, 0, 1, 1);
} }

77
src/widget-input-select.c Normal file
View File

@@ -0,0 +1,77 @@
// SPDX-FileCopyrightText: 2023-2024 Geoffrey D. Bennett <g@b4.vu>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "stringhelper.h"
#include "widget-input-select.h"
struct input_select {
struct alsa_elem *elem;
GtkWidget *button;
int line_num;
};
static void input_select_clicked(
GtkWidget *widget,
struct input_select *data
) {
int count = alsa_get_item_count(data->elem);
// select the item that matches the line number that was clicked on
for (int i = 0; i < count; i++) {
const char *text = alsa_get_item_name(data->elem, i);
int a, b;
get_two_num_from_string(text, &a, &b);
if ((b == -1 && a == data->line_num) ||
(a <= data->line_num && b >= data->line_num)) {
alsa_set_elem_value(data->elem, i);
break;
}
}
}
static void input_select_updated(
struct alsa_elem *elem,
void *private
) {
struct input_select *data = private;
int line_num = data->line_num;
int is_writable = alsa_get_elem_writable(elem);
int value = alsa_get_elem_value(elem);
const char *text = alsa_get_item_name(elem, value);
int a, b;
get_two_num_from_string(text, &a, &b);
// set the button active if it's the selected line number
// (or in the range)
int active = b == -1
? a == line_num
: a <= line_num && b >= line_num;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->button), active);
gtk_widget_set_sensitive(data->button, !active && is_writable);
}
GtkWidget *make_input_select_alsa_elem(
struct alsa_elem *elem,
int line_num
) {
struct input_select *data = malloc(sizeof(struct input_select));
data->elem = elem;
data->button = gtk_toggle_button_new();
data->line_num = line_num;
char s[20];
snprintf(s, 20, "%d", line_num);
gtk_button_set_label(GTK_BUTTON(data->button), s);
g_signal_connect(
data->button, "clicked", G_CALLBACK(input_select_clicked), data
);
alsa_elem_add_callback(elem, input_select_updated, data);
input_select_updated(elem, data);
return data->button;
}

13
src/widget-input-select.h Normal file
View File

@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2023-2024 Geoffrey D. Bennett <g@b4.vu>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <gtk/gtk.h>
#include "alsa.h"
GtkWidget *make_input_select_alsa_elem(
struct alsa_elem *alsa_elem,
int line_num
);