diff options
| author | vin <git@vineetk.net> | 2025-05-30 21:20:25 -0400 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2025-05-30 21:20:25 -0400 |
| commit | d59bcc1c67be40e9176e08f05d64ce71dabe4c4a (patch) | |
| tree | 0b2691f8b744b7f491187b9e28959dbfc673f377 /main.c | |
| parent | 120c63bcaa15bcee927f22157f799b8795851c8f (diff) | |
able to know when clients are un/registered
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 43 |
1 files changed, 43 insertions, 0 deletions
| @@ -0,0 +1,43 @@ | |||
| 1 | #include <jack/jack.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | |||
| 5 | static void | ||
| 6 | registration_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 | |||
| 19 | int | ||
| 20 | main(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 | } | ||
