added an option to aseqnet to optionally set the midi process name

This option allows to run multiple instances of aseqnet without having
to double check the assigned port number, since each one can get spawned
with a unique name.

Fixes: https://github.com/alsa-project/alsa-utils/pull/95
Signed-off-by: Andrea Piras <andrea.piras.85@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Andrea Piras 2019-11-29 03:13:21 +01:00 committed by Jaroslav Kysela
parent 6a0d13ddb2
commit 0e21f4d864
3 changed files with 23 additions and 8 deletions

View file

@ -50,4 +50,6 @@ The available options are:
-s addr : explicit read-subscription to the given address
(client:addr).
-d addr : explicit write-subscription to the given address.
-n name : specify the midi name of the process.
Default value is either 'Net Client' or 'Net Server'.
-v : verbose mode.

View file

@ -70,6 +70,9 @@ Subscribe to the given address for read automatically.
.B \-d addr
Subscribe to the given address for write automatically.
.TP
.B \-n name
Specify the midi name of the process.
.TP
.B \-v
Verbose mode.

View file

@ -37,7 +37,7 @@ static void usage(void);
static void init_buf(void);
static void init_pollfds(void);
static void close_files(void);
static void init_seq(char *source, char *dest);
static void init_seq(char *source, char *dest, char *name);
static int get_port(char *service);
static void sigterm_exit(int sig);
static void init_server(int port);
@ -87,6 +87,7 @@ static const struct option long_option[] = {
{"port", 1, NULL, 'p'},
{"source", 1, NULL, 's'},
{"dest", 1, NULL, 'd'},
{"name", 1, NULL, 'n'},
{"help", 0, NULL, 'h'},
{"verbose", 0, NULL, 'v'},
{"info", 0, NULL, 'i'},
@ -98,13 +99,14 @@ int main(int argc, char **argv)
int c;
int port = DEFAULT_PORT;
char *source = NULL, *dest = NULL;
char *name = NULL;
#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
textdomain(PACKAGE);
#endif
while ((c = getopt_long(argc, argv, "p:s:d:vi", long_option, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "p:s:d:n:,vi", long_option, NULL)) != -1) {
switch (c) {
case 'p':
if (isdigit(*optarg))
@ -118,6 +120,9 @@ int main(int argc, char **argv)
case 'd':
dest = optarg;
break;
case 'n':
name = optarg;
break;
case 'v':
verbose++;
break;
@ -134,7 +139,7 @@ int main(int argc, char **argv)
signal(SIGTERM, sigterm_exit);
init_buf();
init_seq(source, dest);
init_seq(source, dest, name);
if (optind >= argc) {
server_mode = 1;
@ -170,6 +175,7 @@ static void usage(void)
printf(_(" -p,--port # : specify TCP port (digit or service name)\n"));
printf(_(" -s,--source addr : read from given addr (client:port)\n"));
printf(_(" -d,--dest addr : write to given addr (client:port)\n"));
printf(_(" -n,--name value : use a specific midi process name\n"));
printf(_(" -v, --verbose : print verbose messages\n"));
printf(_(" -i, --info : print certain received events\n"));
}
@ -223,7 +229,7 @@ static void close_files(void)
/*
* initialize sequencer
*/
static void init_seq(char *source, char *dest)
static void init_seq(char *source, char *dest, char* name)
{
snd_seq_addr_t addr;
int err, counti, counto;
@ -252,10 +258,14 @@ static void init_seq(char *source, char *dest)
snd_seq_nonblock(handle, 1);
/* set client info */
if (name)
snd_seq_set_client_name(handle, name);
else {
if (server_mode)
snd_seq_set_client_name(handle, "Net Server");
else
snd_seq_set_client_name(handle, "Net Client");
}
/* create a port */
seq_port = snd_seq_create_simple_port(handle, "Network",