feat: add rack mode, colon commands, and client command parser

This commit is contained in:
Loic Coenen
2026-05-16 23:15:07 +00:00
committed by Loic Coenen (aider)
parent c7df02d37c
commit 9fda1b2669
10 changed files with 560 additions and 43 deletions

View File

@@ -11,6 +11,17 @@ static jack_client_t *jack_client = NULL; // private JACK client for port conn
static int carla_pids[MAX_PLUGINS];
static int plugin_count = 0;
#define MAX_CONNECTIONS 1024
typedef struct {
int plugin_id;
char plugin_port[256];
char looper_port[256];
} connection_t;
static connection_t connections[MAX_CONNECTIONS];
static int conn_count = 0;
int carla_init_jack(void) {
if (handle != NULL) return 0;
@@ -95,7 +106,20 @@ int carla_connect(int id, const char *port_name, const char *looper_port) {
// Real JACK port connection
int ret = jack_connect(jack_client, looper_port, port_name);
return (ret == 0) ? 0 : -1;
if (ret != 0) return -1;
// Store the connection so we can disconnect it later
if (conn_count < MAX_CONNECTIONS) {
connections[conn_count].plugin_id = id;
strncpy(connections[conn_count].plugin_port, port_name,
sizeof(connections[conn_count].plugin_port) - 1);
connections[conn_count].plugin_port[sizeof(connections[conn_count].plugin_port) - 1] = '\0';
strncpy(connections[conn_count].looper_port, looper_port,
sizeof(connections[conn_count].looper_port) - 1);
connections[conn_count].looper_port[sizeof(connections[conn_count].looper_port) - 1] = '\0';
conn_count++;
}
return 0;
}
int carla_disconnect(const char *from, const char *to) {
@@ -105,7 +129,20 @@ int carla_disconnect(const char *from, const char *to) {
// Real JACK port disconnection
int ret = jack_disconnect(jack_client, from, to);
return (ret == 0) ? 0 : -1;
if (ret != 0) return -1;
// Remove the connection from our internal list (matching both port names)
for (int i = 0; i < conn_count; i++) {
if (strcmp(connections[i].looper_port, from) == 0 &&
strcmp(connections[i].plugin_port, to) == 0) {
// Shift remaining entries down
for (int j = i; j < conn_count - 1; j++)
connections[j] = connections[j + 1];
conn_count--;
break;
}
}
return 0;
}
void carla_set_bypass(int id, bool bypass) {
@@ -114,3 +151,28 @@ void carla_set_bypass(int id, bool bypass) {
int pid = carla_pids[id];
carla_set_active(handle, (uint)pid, !bypass);
}
int carla_disconnect_plugin(int id) {
if (!jack_client) return 0;
// Disconnect all stored connections for this plugin id
int any = 0;
for (int i = 0; i < conn_count; ) {
if (connections[i].plugin_id == id) {
jack_disconnect(jack_client,
connections[i].looper_port,
connections[i].plugin_port);
// Shift array
for (int j = i; j < conn_count - 1; j++)
connections[j] = connections[j + 1];
conn_count--;
any = 1;
} else {
i++;
}
}
return any ? 0 : -1; // return -1 if no connections were found (harmless)
}
CarlaHostHandle carla_get_handle(void) {
return handle;
}