| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "window-hardware.h" |
| 5 |
|
| 6 |
GtkWidget *window_hardware; |
| 7 |
|
| 8 |
struct hw_info { |
| 9 |
char *name; |
| 10 |
}; |
| 11 |
|
| 12 |
struct hw_cat { |
| 13 |
char *name; |
| 14 |
struct hw_info *info; |
| 15 |
}; |
| 16 |
|
| 17 |
struct hw_info gen_1_info[] = { |
| 18 |
{ "Scarlett 6i6 1st Gen" }, |
| 19 |
{ "Scarlett 8i6 1st Gen" }, |
| 20 |
{ "Scarlett 18i6 1st Gen" }, |
| 21 |
{ "Scarlett 18i8 1st Gen" }, |
| 22 |
{ "Scarlett 18i20 1st Gen" }, |
| 23 |
{ } |
| 24 |
}; |
| 25 |
|
| 26 |
struct hw_info gen_2_info[] = { |
| 27 |
{ "Scarlett 6i6 2nd Gen" }, |
| 28 |
{ "Scarlett 18i8 2nd Gen" }, |
| 29 |
{ "Scarlett 18i20 2nd Gen" }, |
| 30 |
{ } |
| 31 |
}; |
| 32 |
|
| 33 |
struct hw_info gen_3_info[] = { |
| 34 |
{ "Scarlett Solo 3rd Gen" }, |
| 35 |
{ "Scarlett 2i2 3rd Gen" }, |
| 36 |
{ "Scarlett 4i4 3rd Gen" }, |
| 37 |
{ "Scarlett 8i6 3rd Gen" }, |
| 38 |
{ "Scarlett 18i8 3rd Gen" }, |
| 39 |
{ "Scarlett 18i20 3rd Gen" }, |
| 40 |
{ } |
| 41 |
}; |
| 42 |
|
| 43 |
struct hw_info gen_4_info[] = { |
| 44 |
{ "Scarlett Solo 4th Gen" }, |
| 45 |
{ "Scarlett 2i2 4th Gen" }, |
| 46 |
{ "Scarlett 4i4 4th Gen" }, |
| 47 |
{ "Scarlett 16i16 4th Gen" }, |
| 48 |
{ "Scarlett 18i16 4th Gen" }, |
| 49 |
{ "Scarlett 18i20 4th Gen" }, |
| 50 |
{ } |
| 51 |
}; |
| 52 |
|
| 53 |
struct hw_info clarett_usb_info[] = { |
| 54 |
{ "Clarett 2Pre USB" }, |
| 55 |
{ "Clarett 4Pre USB" }, |
| 56 |
{ "Clarett 8Pre USB" }, |
| 57 |
{ } |
| 58 |
}; |
| 59 |
|
| 60 |
struct hw_info clarett_plus_info[] = { |
| 61 |
{ "Clarett+ 2Pre" }, |
| 62 |
{ "Clarett+ 4Pre" }, |
| 63 |
{ "Clarett+ 8Pre" }, |
| 64 |
{ } |
| 65 |
}; |
| 66 |
|
| 67 |
struct hw_info vocaster_info[] = { |
| 68 |
{ "Vocaster One" }, |
| 69 |
{ "Vocaster Two" }, |
| 70 |
{ } |
| 71 |
}; |
| 72 |
|
| 73 |
struct hw_cat hw_cat[] = { |
| 74 |
{ "1st Gen", |
| 75 |
gen_1_info |
| 76 |
}, |
| 77 |
{ "2nd Gen", |
| 78 |
gen_2_info |
| 79 |
}, |
| 80 |
{ "3rd Gen", |
| 81 |
gen_3_info |
| 82 |
}, |
| 83 |
{ "4th Gen", |
| 84 |
gen_4_info |
| 85 |
}, |
| 86 |
{ "Clarett USB", |
| 87 |
clarett_usb_info |
| 88 |
}, |
| 89 |
{ "Clarett+", |
| 90 |
clarett_plus_info |
| 91 |
}, |
| 92 |
{ "Vocaster", |
| 93 |
vocaster_info |
| 94 |
}, |
| 95 |
{ } |
| 96 |
}; |
| 97 |
|
| 98 |
gboolean window_hardware_close_request( |
| 99 |
GtkWindow *w, |
| 100 |
gpointer data |
| 101 |
) { |
| 102 |
GtkApplication *app = data; |
| 103 |
|
| 104 |
g_action_group_activate_action( |
| 105 |
G_ACTION_GROUP(app), "hardware", NULL |
| 106 |
); |
| 107 |
return true; |
| 108 |
} |
| 109 |
|
| 110 |
static gboolean on_key_press( |
| 111 |
GtkEventControllerKey *controller, |
| 112 |
guint keyval, |
| 113 |
guint keycode, |
| 114 |
GdkModifierType state, |
| 115 |
gpointer user_data |
| 116 |
) { |
| 117 |
GtkApplication *app = user_data; |
| 118 |
|
| 119 |
if (keyval == GDK_KEY_Escape) { |
| 120 |
g_action_group_activate_action(G_ACTION_GROUP(app), "hardware", NULL); |
| 121 |
return 1; |
| 122 |
} |
| 123 |
|
| 124 |
if (state & GDK_CONTROL_MASK) { |
| 125 |
const char *action = NULL; |
| 126 |
|
| 127 |
switch (keyval) { |
| 128 |
case GDK_KEY_q: action = "quit"; break; |
| 129 |
case GDK_KEY_w: |
| 130 |
case GDK_KEY_h: action = "hardware"; break; |
| 131 |
} |
| 132 |
|
| 133 |
if (action) { |
| 134 |
g_action_group_activate_action(G_ACTION_GROUP(app), action, NULL); |
| 135 |
return 1; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
return 0; |
| 140 |
} |
| 141 |
|
| 142 |
GtkWidget *make_notebook_page(struct hw_cat *cat) { |
| 143 |
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); |
| 144 |
for (struct hw_info *info = cat->info; info->name; info++) { |
| 145 |
GtkWidget *label = gtk_label_new(info->name); |
| 146 |
gtk_box_append(GTK_BOX(box), label); |
| 147 |
} |
| 148 |
return box; |
| 149 |
} |
| 150 |
|
| 151 |
void add_notebook_pages(GtkWidget *notebook) { |
| 152 |
for (struct hw_cat *cat = hw_cat; cat->name; cat++) { |
| 153 |
GtkWidget *page = make_notebook_page(cat); |
| 154 |
GtkWidget *label = gtk_label_new(cat->name); |
| 155 |
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, label); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
void create_hardware_window(GtkApplication *app) { |
| 160 |
window_hardware = gtk_window_new(); |
| 161 |
g_signal_connect( |
| 162 |
window_hardware, |
| 163 |
"close_request", |
| 164 |
G_CALLBACK(window_hardware_close_request), |
| 165 |
app |
| 166 |
); |
| 167 |
|
| 168 |
GtkEventController *key_controller = gtk_event_controller_key_new(); |
| 169 |
gtk_widget_add_controller(window_hardware, key_controller); |
| 170 |
g_signal_connect( |
| 171 |
key_controller, "key-pressed", G_CALLBACK(on_key_press), app |
| 172 |
); |
| 173 |
|
| 174 |
gtk_window_set_title( |
| 175 |
GTK_WINDOW(window_hardware), |
| 176 |
"ALSA Scarlett Supported Hardware" |
| 177 |
); |
| 178 |
|
| 179 |
GtkWidget *top = gtk_frame_new(NULL); |
| 180 |
gtk_widget_add_css_class(top, "window-frame"); |
| 181 |
gtk_window_set_child(GTK_WINDOW(window_hardware), top); |
| 182 |
|
| 183 |
GtkWidget *notebook = gtk_notebook_new(); |
| 184 |
gtk_widget_add_css_class(notebook, "window-content"); |
| 185 |
gtk_frame_set_child(GTK_FRAME(top), notebook); |
| 186 |
|
| 187 |
add_notebook_pages(notebook); |
| 188 |
} |