summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2025-05-30 23:24:50 -0400
committervin <git@vineetk.net>2025-05-30 23:24:58 -0400
commit0ec8963a62d95322a0848ce75965b7481d05bda2 (patch)
tree372fd72ba560b39c528496f31be81a7cbc1d1557 /main.c
parentd59bcc1c67be40e9176e08f05d64ce71dabe4c4a (diff)
write the callbackHEADmaster
Diffstat (limited to 'main.c')
-rw-r--r--main.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/main.c b/main.c
index a821ef3..a6066c2 100644
--- a/main.c
+++ b/main.c
@@ -1,15 +1,49 @@
1#include <arpa/tftp.h>
1#include <jack/jack.h> 2#include <jack/jack.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <stdlib.h> 4#include <stdlib.h>
5#include <string.h>
6
7#include "config.h"
8
9#define LEN(arr) (sizeof(arr) / sizeof(arr[0]))
4 10
5static void 11static void
6registration_cb(jack_port_id_t port_id, int is_registered, void *arg) 12registration_cb(jack_port_id_t port_id, int is_registered, void *arg)
7{ 13{
8 jack_client_t *client = (jack_client_t *)arg; 14 struct jack_connection_t conn;
9 jack_port_t *port = jack_port_by_id(client, port_id); 15 jack_client_t *client;
10 const char *port_name = jack_port_name(port); 16 jack_port_t *port;
17 const char *port_name;
18 int ret;
19
20 client = (jack_client_t *)arg;
21 port = jack_port_by_id(client, port_id);
22 port_name = jack_port_name(port);
11 23
12 if (is_registered) { 24 if (is_registered) {
25 for (unsigned long i = 0; i < LEN(auto_connects); i++) {
26 conn = auto_connects[i];
27
28 if (strcmp(port_name, conn.in)) {
29 if (jack_port_flags(port) & JackPortIsInput) {
30 ret = jack_connect(client, port_name, conn.out);
31 if (ret != 0 && ret != EEXISTS) {
32 fprintf(stderr, "Failed to connect %s to %s.\n",
33 port_name, conn.out);
34 }
35 }
36 } else if (strcmp(port_name, conn.out)) {
37 if (jack_port_flags(port) & JackPortIsOutput) {
38 ret = jack_connect(client, conn.in, port_name);
39 if (ret != 0 && ret != EEXISTS) {
40 fprintf(stderr, "Failed to connect %s to %s.\n",
41 conn.in, port_name);
42 }
43 }
44 }
45 }
46
13 printf("%s registered\n", port_name); 47 printf("%s registered\n", port_name);
14 } else { 48 } else {
15 printf("%s unregistered\n", port_name); 49 printf("%s unregistered\n", port_name);