Accept the client name as address argument of aconnect and aseqnet.

You may use aconnect like this:
	% aconnect External:0 Emu8000:1
This commit is contained in:
Takashi Iwai 2000-09-14 10:19:45 +00:00
parent d57f1ef166
commit e0847b4af8
3 changed files with 72 additions and 17 deletions

View file

@ -36,6 +36,13 @@ option.
.IP "" 4 .IP "" 4
% aconnect -d 64:0 65:0 % aconnect -d 64:0 65:0
.PP .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 Another function of
.B aconnect .B aconnect
is to list the present ports is to list the present ports
@ -54,9 +61,9 @@ client 0: 'System' [group=system] [type=kernel]
.br .br
1 'Announce ' [group=system] 1 'Announce ' [group=system]
.in -4 .in -4
client 64: '0: MIDI Synth' [group=] [type=kernel] client 64: 'External MIDI-0' [group=] [type=kernel]
.in +4 .in +4
0 'card 0: synth-midi: 0' [group=device] 0 'MIDI 0-0 ' [group=device]
.in -4 .in -4
.PP .PP
Similary, to see the output ports, use Similary, to see the output ports, use

View file

@ -50,17 +50,41 @@ static void usage(void)
/* /*
* parse command line to client:port * 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; char *p;
int client, port;
if (! isdigit(*arg))
return -1;
if ((p = strpbrk(arg, ":.")) == NULL) if ((p = strpbrk(arg, ":.")) == NULL)
return -1; return -1;
addr->client = atoi(arg); if ((port = atoi(p + 1)) < 0)
addr->port = atoi(p + 1); 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; return 0;
} }
@ -354,11 +378,11 @@ int main(int argc, char **argv)
/* set subscription */ /* set subscription */
memset(&subs, 0, sizeof(subs)); 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]); fprintf(stderr, "invalid sender address %s\n", argv[optind]);
return 1; 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]); fprintf(stderr, "invalid destination address %s\n", argv[optind + 1]);
return 1; return 1;
} }

View file

@ -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; char *p;
int client, port;
if (! isdigit(*arg))
return -1;
if ((p = strpbrk(arg, ":.")) == NULL) if ((p = strpbrk(arg, ":.")) == NULL)
return -1; return -1;
addr->client = atoi(arg); if ((port = atoi(p + 1)) < 0)
addr->port = atoi(p + 1); 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; return 0;
} }
@ -240,7 +264,7 @@ static void init_seq(char *source, char *dest)
/* explicit subscriptions */ /* explicit subscriptions */
if (source) { if (source) {
/* read subscription */ /* read subscription */
if (parse_addr(&addr, source) < 0) { if (parse_address(handle, &addr, source) < 0) {
fprintf(stderr, "invalid source address %s\n", source); fprintf(stderr, "invalid source address %s\n", source);
exit(1); exit(1);
} }
@ -251,7 +275,7 @@ static void init_seq(char *source, char *dest)
} }
if (dest) { if (dest) {
/* write subscription */ /* write subscription */
if (parse_addr(&addr, dest) < 0) { if (parse_address(handle, &addr, dest) < 0) {
fprintf(stderr, "invalid destination address %s\n", dest); fprintf(stderr, "invalid destination address %s\n", dest);
exit(1); exit(1);
} }