Files
looper/src/main.c
Loic Coenen fe3fb7d873 fix: reduce main loop sleep to 1ms and add polling in tests
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-10 12:53:15 +00:00

62 lines
1.5 KiB
C

// cppcheck-suppress missingIncludeSystem
#include "looper.h"
#include "pipe.h"
#include <jack/jack.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
const char *client_name = "looper";
jack_options_t options = JackNullOption;
jack_status_t status;
jack_client_t *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;
}
if (status & JackNameNotUnique)
client_name = jack_get_client_name(client);
jack_set_process_callback(client, process_callback, NULL);
jack_on_shutdown(client, jack_shutdown_cb, NULL);
if (looper_init(client) != 0) {
fprintf(stderr, "looper initialisation failed\n");
jack_client_close(client);
return 1;
}
if (pipe_start_reader() != 0) {
fprintf(stderr, "pipe reader initialisation failed\n");
jack_client_close(client);
return 1;
}
if (jack_activate(client)) {
fprintf(stderr, "Cannot activate client\n");
jack_client_close(client);
return 1;
}
fprintf(stderr, "looper running (client name '%s')\n", client_name);
while (1) {
looper_process_commands(client);
{
struct timespec ts = {.tv_sec = 0, .tv_nsec = 1000000};
nanosleep(&ts, NULL);
} /* check commands every 1 ms */
}
jack_client_close(client);
return 0;
}