feat: add logging system, orchestrator, and documentation

This commit is contained in:
Loic Coenen
2026-06-06 12:48:58 +00:00
committed by Loic Coenen (aider)
16 changed files with 739 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -Wall -Wextra -Wpedantic -std=c11 -Isrc
CFLAGS = -Wall -Wextra -Wpedantic -std=c11 -Isrc -I../engine/src
CARLA_INC = -I/usr/include/carla -I/usr/include/carla/includes
CARLA_LIB = -L/usr/lib/carla -Wl,-rpath,/usr/lib/carla -lcarla_standalone2
@@ -8,6 +8,7 @@ CARLA_OBJ = src/carla_host.o
PLUGINS_OBJ = src/plugins.o
CLIENT_CMD_OBJ = src/client_cmd.o
SCRIPT_OBJ = src/script.o
LOG_OBJ = src/log.o
# Test binaries
TEST_PLUGINS_BIN = test_plugins
@@ -18,7 +19,7 @@ TEST_INTEGRATION_BIN = test_integration
all: looper-client test_status_parse
looper-client: src/main.c src/tui.c $(PLUGINS_OBJ) $(CARLA_OBJ) $(CLIENT_CMD_OBJ) $(SCRIPT_OBJ)
looper-client: src/main.c src/tui.c $(PLUGINS_OBJ) $(CARLA_OBJ) $(CLIENT_CMD_OBJ) $(SCRIPT_OBJ) $(LOG_OBJ)
$(CC) $(CFLAGS) $(CARLA_INC) -o $@ $^ $(CARLA_LIB) -ljack -lncurses
test_status_parse: tests/test_status_parse.c $(PLUGINS_OBJ) $(CARLA_OBJ) $(CLIENT_CMD_OBJ) $(SCRIPT_OBJ)
@@ -53,6 +54,9 @@ $(TEST_SCRIPT_OBJ): tests/test_script.c src/script.h
$(TEST_SCRIPT_BIN): $(TEST_SCRIPT_OBJ) $(SCRIPT_OBJ)
$(CC) $(CFLAGS) -o $@ $^
$(LOG_OBJ): src/log.c
$(CC) $(CFLAGS) -c -o $@ $<
# --- Plugin tests ---
TEST_PLUGINS_OBJ = tests/test_plugins.o

1
client/src/log.c Normal file
View File

@@ -0,0 +1 @@
#include "../../engine/src/log.c"

View File

@@ -1,10 +1,13 @@
#include "tui.h"
#include "log.h"
#include "script.h"
#include <string.h>
#include <stdlib.h>
#include "tui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
log_init();
const char *script_path = NULL;
if (argc > 2 && strcmp(argv[1], "-s") == 0) {
@@ -20,11 +23,12 @@ int main(int argc, char *argv[]) {
}
if (script_path && script_load(script_path) != 0) {
fprintf(stderr, "Warning: could not load script '%s'\n", script_path);
log_msg("Warning: could not load script '%s'", script_path);
}
tui_init();
tui_run();
tui_cleanup();
log_close();
return 0;
}

View File

@@ -45,6 +45,13 @@ int script_load(const char *path) {
return 0;
}
void script_cleanup(void) {
for (int i = 0; i < MAX_NOTES; i++) {
free(note_actions[i]);
note_actions[i] = NULL;
}
}
void script_handle_note(int note) {
if (note < 0 || note >= MAX_NOTES) return;
char *macro = note_actions[note];

View File

@@ -3,5 +3,6 @@
int script_load(const char *path);
void script_handle_note(int note);
void script_cleanup(void);
#endif

View File

@@ -1,22 +1,29 @@
#include "tui.h"
#include <ncurses.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <dirent.h>
#include <sys/stat.h>
#include <math.h>
#include "carla_host.h"
#include "client_cmd.h"
#include "plugins.h"
#include "script.h"
#include "tui.h"
#include <CarlaHost.h>
#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <math.h>
#include <ncurses.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
/* ---------- engine alive indicator ---------- */
static bool engine_running = false;
static bool debug_mode = false;
/* ---------- FIFO command helper ---------- */
int send_command(const char *cmd) {
if (debug_mode) {
fprintf(stderr, "DEBUG: send_command(%s)\n", cmd);
}
const char *fifo_path = getenv("LOOPER_CMD_FIFO");
if (!fifo_path) fifo_path = "/tmp/looper_cmd";
int fd = open(fifo_path, O_WRONLY | O_NONBLOCK);
@@ -162,7 +169,7 @@ static void draw_grid(void) {
}
clear();
attron(A_BOLD);
mvprintw(0,0,"JACK Looper - Client (FIFO only)");
mvprintw(0,0,"JACK Looper - Client (FIFO only) %s", engine_running ? "[online]" : "[offline]");
attroff(A_BOLD);
for (int r=0; r<GRID_ROWS; r++)
for (int c=0; c<GRID_COLS; c++)
@@ -181,6 +188,7 @@ static void draw_grid(void) {
void tui_init(void) {
initscr();
cbreak(); noecho(); keypad(stdscr, TRUE); curs_set(0);
debug_mode = (getenv("LOOPER_DEBUG") != NULL);
if (!has_colors()) { endwin(); fprintf(stderr,"No colors\n"); exit(1); }
start_color();
init_pair(COLOR_EMPTY, COLOR_WHITE, COLOR_BLACK);
@@ -234,6 +242,9 @@ void tui_run(void) {
close(fd);
}
/* Check if engine is alive by testing existence of status FIFO */
engine_running = (access(STATUS_FIFO, F_OK) == 0);
/* read any available note events (for script macros) */
int nfd = open(NOTES_FIFO, O_RDONLY | O_NONBLOCK);
if (nfd >= 0) {
@@ -398,6 +409,8 @@ void tui_run(void) {
void tui_cleanup(void) {
if (yank_buffer.clip_indices) free(yank_buffer.clip_indices);
/* free script note allocations */
script_cleanup();
/* delete FIFOs */
unlink(STATUS_FIFO);
unlink(CMD_FIFO);