jack_connectd

Simple daemon for connecting and disconnecting ports upon registration for the JACK audio system
Log | Files | Refs | README | LICENSE

commit 0ec8963a62d95322a0848ce75965b7481d05bda2
parent d59bcc1c67be40e9176e08f05d64ce71dabe4c4a
Author: vin <git@vineetk.net>
Date:   Fri, 30 May 2025 23:24:50 -0400

write the callback

Diffstat:
Aconfig.h | 8++++++++
Mmain.c | 40+++++++++++++++++++++++++++++++++++++---
2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/config.h b/config.h @@ -0,0 +1,8 @@ +struct jack_connection_t { + const char *in; + const char *out; +}; + +struct jack_connection_t auto_connects[] = { + {"system:capture_1", "system:playback_1"}, +}; diff --git a/main.c b/main.c @@ -1,15 +1,49 @@ +#include <arpa/tftp.h> #include <jack/jack.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> + +#include "config.h" + +#define LEN(arr) (sizeof(arr) / sizeof(arr[0])) static void registration_cb(jack_port_id_t port_id, int is_registered, void *arg) { - jack_client_t *client = (jack_client_t *)arg; - jack_port_t *port = jack_port_by_id(client, port_id); - const char *port_name = jack_port_name(port); + struct jack_connection_t conn; + jack_client_t *client; + jack_port_t *port; + const char *port_name; + int ret; + + client = (jack_client_t *)arg; + port = jack_port_by_id(client, port_id); + port_name = jack_port_name(port); if (is_registered) { + for (unsigned long i = 0; i < LEN(auto_connects); i++) { + conn = auto_connects[i]; + + if (strcmp(port_name, conn.in)) { + if (jack_port_flags(port) & JackPortIsInput) { + ret = jack_connect(client, port_name, conn.out); + if (ret != 0 && ret != EEXISTS) { + fprintf(stderr, "Failed to connect %s to %s.\n", + port_name, conn.out); + } + } + } else if (strcmp(port_name, conn.out)) { + if (jack_port_flags(port) & JackPortIsOutput) { + ret = jack_connect(client, conn.in, port_name); + if (ret != 0 && ret != EEXISTS) { + fprintf(stderr, "Failed to connect %s to %s.\n", + conn.in, port_name); + } + } + } + } + printf("%s registered\n", port_name); } else { printf("%s unregistered\n", port_name);