| 1 |
// SPDX-FileCopyrightText: 2022-2025 Geoffrey D. Bennett <[email protected]> |
| 2 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 3 |
|
| 4 |
#include "alsa.h" |
| 5 |
#include "alsa-sim.h" |
| 6 |
#include "welcome.h" |
| 7 |
#include "debug.h" |
| 8 |
#include "main.h" |
| 9 |
#include "menu.h" |
| 10 |
#include "scarlett2-firmware.h" |
| 11 |
#include "scarlett4-firmware.h" |
| 12 |
#include "window-hardware.h" |
| 13 |
#include "window-iface.h" |
| 14 |
|
| 15 |
GtkApplication *app; |
| 16 |
|
| 17 |
// CSS |
| 18 |
|
| 19 |
static void load_css(void) { |
| 20 |
GtkCssProvider *css = gtk_css_provider_new(); |
| 21 |
GdkDisplay *display = gdk_display_get_default(); |
| 22 |
|
| 23 |
gtk_style_context_add_provider_for_display( |
| 24 |
display, GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION |
| 25 |
); |
| 26 |
gtk_css_provider_load_from_resource( |
| 27 |
css, |
| 28 |
"/vu/b4/alsa-scarlett-gui/alsa-scarlett-gui.css" |
| 29 |
); |
| 30 |
|
| 31 |
g_object_unref(css); |
| 32 |
} |
| 33 |
|
| 34 |
// gtk init |
| 35 |
|
| 36 |
static void startup(GtkApplication *app, gpointer user_data) { |
| 37 |
debug_init(); |
| 38 |
|
| 39 |
gtk_application_set_menubar(app, G_MENU_MODEL(create_app_menu(app))); |
| 40 |
|
| 41 |
load_css(); |
| 42 |
|
| 43 |
scarlett2_enum_firmware(); |
| 44 |
scarlett4_enum_firmware(); |
| 45 |
alsa_init(); |
| 46 |
|
| 47 |
create_no_card_window(); |
| 48 |
create_hardware_window(app); |
| 49 |
|
| 50 |
show_welcome(app); |
| 51 |
} |
| 52 |
|
| 53 |
// not called when any files are opened from the command-line so we do |
| 54 |
// everything in startup(), but GTK wants this signal handled |
| 55 |
// regardless |
| 56 |
static void activate(GtkApplication *app, gpointer user_data) { |
| 57 |
} |
| 58 |
|
| 59 |
static void open_cb( |
| 60 |
GtkApplication *app, |
| 61 |
GFile **files, |
| 62 |
gint n_files, |
| 63 |
const gchar *hint |
| 64 |
) { |
| 65 |
for (int i = 0; i < n_files; i++) { |
| 66 |
char *fn = g_file_get_path(files[i]); |
| 67 |
create_sim_from_file(NULL, fn); |
| 68 |
g_free(fn); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
int main(int argc, char **argv) { |
| 73 |
app = gtk_application_new( |
| 74 |
"vu.b4.alsa-scarlett-gui", G_APPLICATION_HANDLES_OPEN |
| 75 |
); |
| 76 |
g_signal_connect(app, "startup", G_CALLBACK(startup), NULL); |
| 77 |
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); |
| 78 |
g_signal_connect(app, "open", G_CALLBACK(open_cb), NULL); |
| 79 |
int status = g_application_run(G_APPLICATION(app), argc, argv); |
| 80 |
g_object_unref(app); |
| 81 |
|
| 82 |
return status; |
| 83 |
} |