feat: add status FIFO and parse status line in client

This commit is contained in:
Loic Coenen
2026-05-14 14:56:11 +00:00
committed by Loic Coenen (aider)
parent 791744beeb
commit 5341cb676a
3 changed files with 65 additions and 1 deletions

View File

@@ -5,6 +5,9 @@
#include "midi.h"
#include "queue.h"
#include <jack/jack.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <jack/midiport.h>
#include <math.h>
#include <stdatomic.h>
@@ -12,6 +15,39 @@
#include <stdlib.h>
#include <string.h>
#define STATUS_FIFO "/tmp/looper_status"
static void looper_write_status(void) {
int fd = open(STATUS_FIFO, O_WRONLY | O_NONBLOCK);
if (fd < 0)
return;
struct channel_t *cur = get_channels_array();
int cap = atomic_load(&channel_capacity);
char buf[256];
for (int ch = 0; ch < cap; ch++) {
if (!atomic_load(&cur[ch].active))
continue;
int sc_idx = atomic_load(&cur[ch].current_scene);
int state = atomic_load(&cur[ch].scenes[sc_idx].state);
const char *state_str;
switch (state) {
case STATE_IDLE: state_str = "IDLE"; break;
case STATE_RECORD: state_str = "RECORD"; break;
case STATE_LOOPING: state_str = "LOOPING"; break;
case STATE_PAUSED: state_str = "PAUSED"; break;
default: state_str = "UNKNOWN";
}
int n = snprintf(buf, sizeof(buf),
"CH=%d SC=%d STATE=%s\n",
ch, sc_idx, state_str);
if (n > 0) {
int ret = write(fd, buf, n);
(void)ret;
}
}
close(fd);
}
/* Global state (shared across files) */
struct channel_t *_Atomic channels = NULL;
atomic_int channel_capacity = 0;
@@ -393,6 +429,9 @@ void jack_shutdown_cb(void *arg) {
* looper initialisation
* ---------------------------------------------------------------- */
int looper_init(jack_client_t *client) {
/* create status FIFO (ignore if already exists) */
mkfifo(STATUS_FIFO, 0666);
queue_init(&cmd_queue);
queue_init(&cmd_queue_main_midi);
queue_init(&cmd_queue_main_fifo);
@@ -631,4 +670,7 @@ void looper_process_commands(jack_client_t *client) {
pending_old = NULL;
}
}
/* write current state to status FIFO */
looper_write_status();
}