From e0847b4af87f144b67e62e98f8d3a4879151946f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 14 Sep 2000 10:19:45 +0000 Subject: [PATCH] Accept the client name as address argument of aconnect and aseqnet. You may use aconnect like this: % aconnect External:0 Emu8000:1 --- seq/aconnect/aconnect.1 | 11 +++++++++-- seq/aconnect/aconnect.c | 38 +++++++++++++++++++++++++++++++------- seq/aseqnet/aseqnet.c | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/seq/aconnect/aconnect.1 b/seq/aconnect/aconnect.1 index 4d75924..ed34ea7 100644 --- a/seq/aconnect/aconnect.1 +++ b/seq/aconnect/aconnect.1 @@ -36,6 +36,13 @@ option. .IP "" 4 % aconnect -d 64:0 65:0 .PP +The address can be given using the client's name. +.IP "" 4 +% aconnect External:0 Emu8000:1 +.PP +Then the port 0 of the client matching with the string "External" is +connected to the port 1 of the client matching with the "Emu8000". +.PP Another function of .B aconnect is to list the present ports @@ -54,9 +61,9 @@ client 0: 'System' [group=system] [type=kernel] .br 1 'Announce ' [group=system] .in -4 -client 64: '0: MIDI Synth' [group=] [type=kernel] +client 64: 'External MIDI-0' [group=] [type=kernel] .in +4 -0 'card 0: synth-midi: 0' [group=device] +0 'MIDI 0-0 ' [group=device] .in -4 .PP Similary, to see the output ports, use diff --git a/seq/aconnect/aconnect.c b/seq/aconnect/aconnect.c index aa552a4..c0ccc9a 100644 --- a/seq/aconnect/aconnect.c +++ b/seq/aconnect/aconnect.c @@ -50,17 +50,41 @@ static void usage(void) /* * parse command line to client:port + * NB: the given string will be broken. */ -static int parse_address(snd_seq_addr_t *addr, char *arg) +static int parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, char *arg) { char *p; + int client, port; - if (! isdigit(*arg)) - return -1; if ((p = strpbrk(arg, ":.")) == NULL) return -1; - addr->client = atoi(arg); - addr->port = atoi(p + 1); + if ((port = atoi(p + 1)) < 0) + return -1; + addr->port = port; + if (isdigit(*arg)) { + client = atoi(arg); + if (client < 0) + return -1; + addr->client = client; + } else { + /* convert from the name */ + snd_seq_client_info_t cinfo; + int len; + + *p = 0; + len = strlen(arg); + if (len <= 0) + return -1; + cinfo.client = -1; + while (snd_seq_query_next_client(seq, &cinfo) >= 0) { + if (! strncmp(cinfo.name, arg, len)) { + addr->client = cinfo.client; + return 0; + } + } + return -1; /* not found */ + } return 0; } @@ -354,11 +378,11 @@ int main(int argc, char **argv) /* set subscription */ memset(&subs, 0, sizeof(subs)); - if (parse_address(&subs.sender, argv[optind]) < 0) { + if (parse_address(seq, &subs.sender, argv[optind]) < 0) { fprintf(stderr, "invalid sender address %s\n", argv[optind]); return 1; } - if (parse_address(&subs.dest, argv[optind + 1]) < 0) { + if (parse_address(seq, &subs.dest, argv[optind + 1]) < 0) { fprintf(stderr, "invalid destination address %s\n", argv[optind + 1]); return 1; } diff --git a/seq/aseqnet/aseqnet.c b/seq/aseqnet/aseqnet.c index 8eab330..9640195 100644 --- a/seq/aseqnet/aseqnet.c +++ b/seq/aseqnet/aseqnet.c @@ -169,18 +169,42 @@ static void init_buf(void) } /* - * parse client:port argument + * parse command line to client:port + * NB: the given string will be broken. */ -static int parse_addr(snd_seq_addr_t *addr, char *arg) +static int parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, char *arg) { char *p; + int client, port; - if (! isdigit(*arg)) - return -1; if ((p = strpbrk(arg, ":.")) == NULL) return -1; - addr->client = atoi(arg); - addr->port = atoi(p + 1); + if ((port = atoi(p + 1)) < 0) + return -1; + addr->port = port; + if (isdigit(*arg)) { + client = atoi(arg); + if (client < 0) + return -1; + addr->client = client; + } else { + /* convert from the name */ + snd_seq_client_info_t cinfo; + int len; + + *p = 0; + len = strlen(arg); + if (len <= 0) + return -1; + cinfo.client = -1; + while (snd_seq_query_next_client(seq, &cinfo) >= 0) { + if (! strncmp(cinfo.name, arg, len)) { + addr->client = cinfo.client; + return 0; + } + } + return -1; /* not found */ + } return 0; } @@ -240,7 +264,7 @@ static void init_seq(char *source, char *dest) /* explicit subscriptions */ if (source) { /* read subscription */ - if (parse_addr(&addr, source) < 0) { + if (parse_address(handle, &addr, source) < 0) { fprintf(stderr, "invalid source address %s\n", source); exit(1); } @@ -251,7 +275,7 @@ static void init_seq(char *source, char *dest) } if (dest) { /* write subscription */ - if (parse_addr(&addr, dest) < 0) { + if (parse_address(handle, &addr, dest) < 0) { fprintf(stderr, "invalid destination address %s\n", dest); exit(1); }