diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 40 |
1 files changed, 37 insertions, 3 deletions
| @@ -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 | ||
| 5 | static void | 11 | static void |
| 6 | registration_cb(jack_port_id_t port_id, int is_registered, void *arg) | 12 | registration_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); |
