feat: add frontend selection flags to main.c

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-01 14:36:27 +00:00
parent 95a143282f
commit b66b37c767

32
main.c
View File

@@ -2,8 +2,11 @@
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include "engine.h"
#include "tui.h"
#include "cli.h"
#include "gui.h"
static Engine engine;
static volatile int keep_running = 1;
@@ -18,15 +21,19 @@ void print_usage(const char *program) {
printf("Options:\n");
printf(" -n <name> JACK client name (default: jack-looper)\n");
printf(" -c <channel> MIDI control channel (default: 0)\n");
printf(" -t Use TUI frontend (default)\n");
printf(" -i Use CLI frontend (interactive)\n");
printf(" -g Use GUI frontend\n");
printf(" -h Show this help\n");
}
int main(int argc, char *argv[]) {
const char *client_name = "jack-looper";
int control_channel = 0;
enum { FRONTEND_TUI, FRONTEND_CLI, FRONTEND_GUI } frontend = FRONTEND_TUI;
int opt;
while ((opt = getopt(argc, argv, "n:c:h")) != -1) {
while ((opt = getopt(argc, argv, "n:c:tigh")) != -1) {
switch (opt) {
case 'n':
client_name = optarg;
@@ -38,6 +45,15 @@ int main(int argc, char *argv[]) {
return 1;
}
break;
case 't':
frontend = FRONTEND_TUI;
break;
case 'i':
frontend = FRONTEND_CLI;
break;
case 'g':
frontend = FRONTEND_GUI;
break;
case 'h':
print_usage(argv[0]);
return 0;
@@ -72,13 +88,23 @@ int main(int argc, char *argv[]) {
printf("Sample rate: %u Hz\n", engine.sample_rate);
printf("Press Ctrl+C to stop\n\n");
// Initialize and run TUI
// Run selected frontend
switch (frontend) {
case FRONTEND_TUI:
tui_init(&engine);
tui_run(&engine);
tui_cleanup();
break;
case FRONTEND_CLI:
cli_run(&engine);
break;
case FRONTEND_GUI:
gui_main(&engine);
break;
}
// Cleanup
printf("\nShutting down...\n"); // This line may not be reached if tui_run returns
printf("\nShutting down...\n");
engine_stop(&engine);
engine_cleanup(&engine);