Files
jack-looper/main.c
Loic Coenen 05c6f34b8f feat: add microui-based GUI with transport controls and progress bar
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
2026-05-01 13:02:39 +00:00

131 lines
3.3 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include "engine.h"
#include "tui.h"
static Engine engine;
static volatile int keep_running = 1;
void signal_handler(int sig) {
(void)sig;
keep_running = 0;
}
void print_usage(const char *program) {
printf("Usage: %s [options]\n", program);
printf("Options:\n");
printf(" -n <name> JACK client name (default: jack-looper)\n");
printf(" -c <channel> MIDI control channel (default: 0)\n");
printf(" -h Show this help\n");
}
int main(int argc, char *argv[]) {
const char *client_name = "jack-looper";
int control_channel = 0;
int opt;
while ((opt = getopt(argc, argv, "n:c:h")) != -1) {
switch (opt) {
case 'n':
client_name = optarg;
break;
case 'c':
control_channel = atoi(optarg);
if (control_channel < 0 || control_channel > 15) {
fprintf(stderr, "Control channel must be 0-15\n");
return 1;
}
break;
case 'h':
print_usage(argv[0]);
return 0;
default:
print_usage(argv[0]);
return 1;
}
}
// Initialize engine
if (engine_init(&engine, client_name) != 0) {
fprintf(stderr, "Failed to initialize engine\n");
return 1;
}
engine.control_channel = control_channel;
// Set up signal handler
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
// Start engine
if (engine_start(&engine) != 0) {
fprintf(stderr, "Failed to start engine\n");
engine_cleanup(&engine);
return 1;
}
printf("JACK Looper started\n");
printf("Client name: %s\n", client_name);
printf("Control channel: %d\n", control_channel);
printf("Sample rate: %u Hz\n", engine.sample_rate);
printf("Press Ctrl+C to stop\n\n");
// Initialize and run TUI
tui_init(&engine);
tui_run(&engine);
tui_cleanup();
// Cleanup
printf("\nShutting down...\n"); // This line may not be reached if tui_run returns
engine_stop(&engine);
engine_cleanup(&engine);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <jack/jack.h>
#include "engine.h"
#include "tui.h"
int main(void)
{
jack_client_t *client;
const char *client_name = "jack_looper";
jack_options_t options = JackNullOption;
jack_status_t status;
client = jack_client_open(client_name, options, &status);
if (client == NULL) {
fprintf(stderr, "jack_client_open() failed, status = 0x%2.0x\n", status);
if (status & JackServerFailed) {
fprintf(stderr, "Unable to connect to JACK server\n");
}
return 1;
}
float *buffer = calloc(4096, sizeof(float));
if (!buffer) {
fprintf(stderr, "Failed to allocate audio buffer\n");
jack_client_close(client);
return 1;
}
if (engine_init(client, buffer, 4096) != 0) {
fprintf(stderr, "Failed to initialize engine\n");
free(buffer);
jack_client_close(client);
return 1;
}
int ret = tui_main(client, buffer, 4096);
engine_cleanup(client);
free(buffer);
jack_client_close(client);
return ret;
}