summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2025-05-30 21:20:25 -0400
committervin <git@vineetk.net>2025-05-30 21:20:25 -0400
commitd59bcc1c67be40e9176e08f05d64ce71dabe4c4a (patch)
tree0b2691f8b744b7f491187b9e28959dbfc673f377 /main.c
parent120c63bcaa15bcee927f22157f799b8795851c8f (diff)
able to know when clients are un/registered
Diffstat (limited to 'main.c')
-rw-r--r--main.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..a821ef3
--- /dev/null
+++ b/main.c
@@ -0,0 +1,43 @@
1#include <jack/jack.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5static void
6registration_cb(jack_port_id_t port_id, int is_registered, void *arg)
7{
8 jack_client_t *client = (jack_client_t *)arg;
9 jack_port_t *port = jack_port_by_id(client, port_id);
10 const char *port_name = jack_port_name(port);
11
12 if (is_registered) {
13 printf("%s registered\n", port_name);
14 } else {
15 printf("%s unregistered\n", port_name);
16 }
17}
18
19int
20main(void)
21{
22 jack_client_t *client;
23
24 client = jack_client_open("jack_connectd", JackNullOption, NULL);
25 if (client == NULL) {
26 fprintf(stderr, "Failed to connect to JACK server.\n");
27 return 1;
28 }
29
30 /* client is passed as arg so it can be used within cb */
31 jack_set_port_registration_callback(client, registration_cb, client);
32
33 /* start processing callbacks */
34 if (jack_activate(client) != 0) {
35 fprintf(stderr, "Failed to activate JACK client.\n");
36 return 1;
37 }
38
39 /* do nothing else while waiting */
40 for (;;);
41
42 return 0;
43}