2000-01-04 13:39:00 +01:00
|
|
|
/*
|
|
|
|
* connect / disconnect two subscriber ports
|
|
|
|
* ver.0.1.3
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Takashi Iwai
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <getopt.h>
|
2000-11-25 17:38:04 +01:00
|
|
|
#include <stdarg.h>
|
2005-10-31 15:44:03 +01:00
|
|
|
#include <locale.h>
|
2000-01-04 13:39:00 +01:00
|
|
|
#include <sys/ioctl.h>
|
2001-09-11 11:34:14 +02:00
|
|
|
#include <alsa/asoundlib.h>
|
2005-06-23 12:38:06 +02:00
|
|
|
#include "aconfig.h"
|
|
|
|
#include "gettext.h"
|
2000-01-04 13:39:00 +01:00
|
|
|
|
2000-11-25 17:38:04 +01:00
|
|
|
static void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list arg;
|
|
|
|
|
|
|
|
if (err == ENOENT) /* Ignore those misleading "warnings" */
|
|
|
|
return;
|
|
|
|
va_start(arg, fmt);
|
|
|
|
fprintf(stderr, "ALSA lib %s:%i:(%s) ", file, line, function);
|
|
|
|
vfprintf(stderr, fmt, arg);
|
|
|
|
if (err)
|
|
|
|
fprintf(stderr, ": %s", snd_strerror(err));
|
|
|
|
putc('\n', stderr);
|
|
|
|
va_end(arg);
|
|
|
|
}
|
|
|
|
|
2000-01-04 13:39:00 +01:00
|
|
|
static void usage(void)
|
|
|
|
{
|
2005-06-23 12:39:16 +02:00
|
|
|
printf(_("aconnect - ALSA sequencer connection manager\n"));
|
|
|
|
printf(_("Copyright (C) 1999-2000 Takashi Iwai\n"));
|
|
|
|
printf(_("Usage:\n"));
|
|
|
|
printf(_(" * Connection/disconnection between two ports\n"));
|
|
|
|
printf(_(" aconnect [-options] sender receiver\n"));
|
|
|
|
printf(_(" sender, receiver = client:port pair\n"));
|
|
|
|
printf(_(" -d,--disconnect disconnect\n"));
|
|
|
|
printf(_(" -e,--exclusive exclusive connection\n"));
|
|
|
|
printf(_(" -r,--real # convert real-time-stamp on queue\n"));
|
|
|
|
printf(_(" -t,--tick # convert tick-time-stamp on queue\n"));
|
|
|
|
printf(_(" * List connected ports (no subscription action)\n"));
|
|
|
|
printf(_(" aconnect -i|-o [-options]\n"));
|
|
|
|
printf(_(" -i,--input list input (readable) ports\n"));
|
|
|
|
printf(_(" -o,--output list output (writable) ports\n"));
|
|
|
|
printf(_(" -l,--list list current connections of each port\n"));
|
|
|
|
printf(_(" * Remove all exported connections\n"));
|
|
|
|
printf(_(" -x, --removeall\n"));
|
2000-01-04 13:39:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-07-04 15:55:13 +02:00
|
|
|
* check permission (capability) of specified port
|
2000-01-04 13:39:00 +01:00
|
|
|
*/
|
2001-07-04 15:55:13 +02:00
|
|
|
|
|
|
|
#define LIST_INPUT 1
|
|
|
|
#define LIST_OUTPUT 2
|
|
|
|
|
|
|
|
#define perm_ok(pinfo,bits) ((snd_seq_port_info_get_capability(pinfo) & (bits)) == (bits))
|
|
|
|
|
|
|
|
static int check_permission(snd_seq_port_info_t *pinfo, int perm)
|
2000-01-04 13:39:00 +01:00
|
|
|
{
|
2001-07-04 15:55:13 +02:00
|
|
|
if (perm) {
|
|
|
|
if (perm & LIST_INPUT) {
|
|
|
|
if (perm_ok(pinfo, SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ))
|
|
|
|
goto __ok;
|
|
|
|
}
|
|
|
|
if (perm & LIST_OUTPUT) {
|
|
|
|
if (perm_ok(pinfo, SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE))
|
|
|
|
goto __ok;
|
2000-09-14 12:19:45 +02:00
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
return 0;
|
2000-09-14 12:19:45 +02:00
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
__ok:
|
|
|
|
if (snd_seq_port_info_get_capability(pinfo) & SND_SEQ_PORT_CAP_NO_EXPORT)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
2000-01-04 13:39:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* list subscribers of specified type
|
|
|
|
*/
|
2001-07-04 15:55:13 +02:00
|
|
|
static void list_each_subs(snd_seq_t *seq, snd_seq_query_subscribe_t *subs, int type, const char *msg)
|
2000-01-04 13:39:00 +01:00
|
|
|
{
|
2001-07-04 15:55:13 +02:00
|
|
|
int count = 0;
|
|
|
|
snd_seq_query_subscribe_set_type(subs, type);
|
|
|
|
snd_seq_query_subscribe_set_index(subs, 0);
|
2000-01-04 13:39:00 +01:00
|
|
|
while (snd_seq_query_port_subscribers(seq, subs) >= 0) {
|
2001-07-04 15:55:13 +02:00
|
|
|
const snd_seq_addr_t *addr;
|
|
|
|
if (count++ == 0)
|
2000-01-04 13:39:00 +01:00
|
|
|
printf("\t%s: ", msg);
|
|
|
|
else
|
|
|
|
printf(", ");
|
2001-07-04 15:55:13 +02:00
|
|
|
addr = snd_seq_query_subscribe_get_addr(subs);
|
|
|
|
printf("%d:%d", addr->client, addr->port);
|
|
|
|
if (snd_seq_query_subscribe_get_exclusive(subs))
|
2000-01-04 13:39:00 +01:00
|
|
|
printf("[ex]");
|
2001-07-04 15:55:13 +02:00
|
|
|
if (snd_seq_query_subscribe_get_time_update(subs))
|
2000-01-04 13:39:00 +01:00
|
|
|
printf("[%s:%d]",
|
2001-07-04 15:55:13 +02:00
|
|
|
(snd_seq_query_subscribe_get_time_real(subs) ? "real" : "tick"),
|
|
|
|
snd_seq_query_subscribe_get_queue(subs));
|
|
|
|
snd_seq_query_subscribe_set_index(subs, snd_seq_query_subscribe_get_index(subs) + 1);
|
2000-01-04 13:39:00 +01:00
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
if (count > 0)
|
2000-01-04 13:39:00 +01:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* list subscribers
|
|
|
|
*/
|
2001-07-04 15:55:13 +02:00
|
|
|
static void list_subscribers(snd_seq_t *seq, const snd_seq_addr_t *addr)
|
2000-01-04 13:39:00 +01:00
|
|
|
{
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_query_subscribe_t *subs;
|
|
|
|
snd_seq_query_subscribe_alloca(&subs);
|
|
|
|
snd_seq_query_subscribe_set_root(subs, addr);
|
2005-06-23 12:38:06 +02:00
|
|
|
list_each_subs(seq, subs, SND_SEQ_QUERY_SUBS_READ, _("Connecting To"));
|
|
|
|
list_each_subs(seq, subs, SND_SEQ_QUERY_SUBS_WRITE, _("Connected From"));
|
2000-01-04 13:39:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-08-31 13:20:34 +02:00
|
|
|
* search all ports
|
2000-01-04 13:39:00 +01:00
|
|
|
*/
|
2000-08-31 13:20:34 +02:00
|
|
|
typedef void (*action_func_t)(snd_seq_t *seq, snd_seq_client_info_t *cinfo, snd_seq_port_info_t *pinfo, int count);
|
|
|
|
|
2001-07-04 15:55:13 +02:00
|
|
|
static void do_search_port(snd_seq_t *seq, int perm, action_func_t do_action)
|
2000-01-04 13:39:00 +01:00
|
|
|
{
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_client_info_t *cinfo;
|
|
|
|
snd_seq_port_info_t *pinfo;
|
2000-08-31 13:20:34 +02:00
|
|
|
int count;
|
2000-01-04 13:39:00 +01:00
|
|
|
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_client_info_alloca(&cinfo);
|
|
|
|
snd_seq_port_info_alloca(&pinfo);
|
|
|
|
snd_seq_client_info_set_client(cinfo, -1);
|
|
|
|
while (snd_seq_query_next_client(seq, cinfo) >= 0) {
|
2000-01-04 13:39:00 +01:00
|
|
|
/* reset query info */
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
|
|
|
|
snd_seq_port_info_set_port(pinfo, -1);
|
2000-08-31 13:20:34 +02:00
|
|
|
count = 0;
|
2001-07-04 15:55:13 +02:00
|
|
|
while (snd_seq_query_next_port(seq, pinfo) >= 0) {
|
|
|
|
if (check_permission(pinfo, perm)) {
|
|
|
|
do_action(seq, cinfo, pinfo, count);
|
2000-08-31 13:20:34 +02:00
|
|
|
count++;
|
2000-01-04 13:39:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-31 13:20:34 +02:00
|
|
|
static void print_port(snd_seq_t *seq, snd_seq_client_info_t *cinfo,
|
|
|
|
snd_seq_port_info_t *pinfo, int count)
|
|
|
|
{
|
|
|
|
if (! count) {
|
2005-06-23 12:38:06 +02:00
|
|
|
printf(_("client %d: '%s' [type=%s]\n"),
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_client_info_get_client(cinfo),
|
|
|
|
snd_seq_client_info_get_name(cinfo),
|
2005-06-23 12:38:06 +02:00
|
|
|
(snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT ?
|
|
|
|
_("user") : _("kernel")));
|
2000-08-31 13:20:34 +02:00
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
printf(" %3d '%-16s'\n",
|
|
|
|
snd_seq_port_info_get_port(pinfo),
|
|
|
|
snd_seq_port_info_get_name(pinfo));
|
2000-08-31 13:20:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_port_and_subs(snd_seq_t *seq, snd_seq_client_info_t *cinfo,
|
|
|
|
snd_seq_port_info_t *pinfo, int count)
|
|
|
|
{
|
|
|
|
print_port(seq, cinfo, pinfo, count);
|
2001-07-04 15:55:13 +02:00
|
|
|
list_subscribers(seq, snd_seq_port_info_get_addr(pinfo));
|
2000-08-31 13:20:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* remove all (exported) connections
|
|
|
|
*/
|
|
|
|
static void remove_connection(snd_seq_t *seq, snd_seq_client_info_t *cinfo,
|
|
|
|
snd_seq_port_info_t *pinfo, int count)
|
|
|
|
{
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_query_subscribe_t *query;
|
2010-05-26 10:37:58 +02:00
|
|
|
snd_seq_port_info_t *port;
|
|
|
|
snd_seq_port_subscribe_t *subs;
|
2001-07-04 15:55:13 +02:00
|
|
|
|
|
|
|
snd_seq_query_subscribe_alloca(&query);
|
|
|
|
snd_seq_query_subscribe_set_root(query, snd_seq_port_info_get_addr(pinfo));
|
|
|
|
snd_seq_query_subscribe_set_type(query, SND_SEQ_QUERY_SUBS_READ);
|
|
|
|
snd_seq_query_subscribe_set_index(query, 0);
|
2010-05-26 10:37:58 +02:00
|
|
|
|
|
|
|
snd_seq_port_info_alloca(&port);
|
|
|
|
snd_seq_port_subscribe_alloca(&subs);
|
|
|
|
|
|
|
|
while (snd_seq_query_port_subscribers(seq, query) >= 0) {
|
2001-07-04 15:55:13 +02:00
|
|
|
const snd_seq_addr_t *sender = snd_seq_query_subscribe_get_root(query);
|
|
|
|
const snd_seq_addr_t *dest = snd_seq_query_subscribe_get_addr(query);
|
2000-08-31 13:20:34 +02:00
|
|
|
|
2010-05-26 10:37:58 +02:00
|
|
|
if (snd_seq_get_any_port_info(seq, dest->client, dest->port, port) < 0 ||
|
|
|
|
!(snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_SUBS_WRITE) ||
|
|
|
|
(snd_seq_port_info_get_capability(port) & SND_SEQ_PORT_CAP_NO_EXPORT)) {
|
|
|
|
snd_seq_query_subscribe_set_index(query, snd_seq_query_subscribe_get_index(query) + 1);
|
2010-05-26 10:07:47 +02:00
|
|
|
continue;
|
2010-05-26 10:37:58 +02:00
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_port_subscribe_set_queue(subs, snd_seq_query_subscribe_get_queue(query));
|
|
|
|
snd_seq_port_subscribe_set_sender(subs, sender);
|
|
|
|
snd_seq_port_subscribe_set_dest(subs, dest);
|
2010-05-26 10:37:58 +02:00
|
|
|
if (snd_seq_unsubscribe_port(seq, subs) < 0) {
|
|
|
|
snd_seq_query_subscribe_set_index(query, snd_seq_query_subscribe_get_index(query) + 1);
|
|
|
|
}
|
2000-08-31 13:20:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_all_connections(snd_seq_t *seq)
|
|
|
|
{
|
2001-07-04 15:55:13 +02:00
|
|
|
do_search_port(seq, 0, remove_connection);
|
2000-08-31 13:20:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* main..
|
|
|
|
*/
|
|
|
|
|
2000-01-04 13:39:00 +01:00
|
|
|
enum {
|
2001-07-04 15:55:13 +02:00
|
|
|
SUBSCRIBE, UNSUBSCRIBE, LIST, REMOVE_ALL
|
2000-01-04 13:39:00 +01:00
|
|
|
};
|
|
|
|
|
2008-11-21 13:10:02 +01:00
|
|
|
static const struct option long_option[] = {
|
2000-01-04 13:39:00 +01:00
|
|
|
{"disconnect", 0, NULL, 'd'},
|
|
|
|
{"input", 0, NULL, 'i'},
|
|
|
|
{"output", 0, NULL, 'o'},
|
|
|
|
{"real", 1, NULL, 'r'},
|
|
|
|
{"tick", 1, NULL, 't'},
|
|
|
|
{"exclusive", 0, NULL, 'e'},
|
|
|
|
{"list", 0, NULL, 'l'},
|
2000-08-31 13:20:34 +02:00
|
|
|
{"removeall", 0, NULL, 'x'},
|
2000-01-04 13:39:00 +01:00
|
|
|
{NULL, 0, NULL, 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
snd_seq_t *seq;
|
|
|
|
int queue = 0, convert_time = 0, convert_real = 0, exclusive = 0;
|
|
|
|
int command = SUBSCRIBE;
|
2001-07-04 15:55:13 +02:00
|
|
|
int list_perm = 0;
|
2000-01-04 13:39:00 +01:00
|
|
|
int client;
|
|
|
|
int list_subs = 0;
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_port_subscribe_t *subs;
|
|
|
|
snd_seq_addr_t sender, dest;
|
2000-01-04 13:39:00 +01:00
|
|
|
|
2005-11-08 17:43:36 +01:00
|
|
|
#ifdef ENABLE_NLS
|
2005-06-23 12:38:06 +02:00
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
textdomain(PACKAGE);
|
2005-11-08 17:43:36 +01:00
|
|
|
#endif
|
2005-06-23 12:38:06 +02:00
|
|
|
|
2002-07-17 14:05:15 +02:00
|
|
|
while ((c = getopt_long(argc, argv, "dior:t:elx", long_option, NULL)) != -1) {
|
2000-01-04 13:39:00 +01:00
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
command = UNSUBSCRIBE;
|
|
|
|
break;
|
|
|
|
case 'i':
|
2001-07-04 15:55:13 +02:00
|
|
|
command = LIST;
|
|
|
|
list_perm |= LIST_INPUT;
|
2000-01-04 13:39:00 +01:00
|
|
|
break;
|
|
|
|
case 'o':
|
2001-07-04 15:55:13 +02:00
|
|
|
command = LIST;
|
|
|
|
list_perm |= LIST_OUTPUT;
|
2000-01-04 13:39:00 +01:00
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
exclusive = 1;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
queue = atoi(optarg);
|
|
|
|
convert_time = 1;
|
|
|
|
convert_real = 1;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
queue = atoi(optarg);
|
|
|
|
convert_time = 1;
|
|
|
|
convert_real = 0;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
list_subs = 1;
|
|
|
|
break;
|
2000-08-31 13:20:34 +02:00
|
|
|
case 'x':
|
|
|
|
command = REMOVE_ALL;
|
|
|
|
break;
|
2000-01-04 13:39:00 +01:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-15 10:55:17 +02:00
|
|
|
if (snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("can't open sequencer\n"));
|
2000-01-04 13:39:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-11-25 17:38:04 +01:00
|
|
|
snd_lib_error_set_handler(error_handler);
|
|
|
|
|
2000-08-31 13:20:34 +02:00
|
|
|
switch (command) {
|
2001-07-04 15:55:13 +02:00
|
|
|
case LIST:
|
|
|
|
do_search_port(seq, list_perm,
|
|
|
|
list_subs ? print_port_and_subs : print_port);
|
2000-01-04 13:39:00 +01:00
|
|
|
snd_seq_close(seq);
|
|
|
|
return 0;
|
2000-08-31 13:20:34 +02:00
|
|
|
case REMOVE_ALL:
|
|
|
|
remove_all_connections(seq);
|
|
|
|
snd_seq_close(seq);
|
|
|
|
return 0;
|
2000-01-04 13:39:00 +01:00
|
|
|
}
|
|
|
|
|
2000-08-31 13:20:34 +02:00
|
|
|
/* connection or disconnection */
|
|
|
|
|
2000-01-04 13:39:00 +01:00
|
|
|
if (optind + 2 > argc) {
|
|
|
|
snd_seq_close(seq);
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((client = snd_seq_client_id(seq)) < 0) {
|
|
|
|
snd_seq_close(seq);
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("can't get client id\n"));
|
2000-01-04 13:39:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set client info */
|
2001-07-04 15:55:13 +02:00
|
|
|
if (snd_seq_set_client_name(seq, "ALSA Connector") < 0) {
|
2000-01-04 13:39:00 +01:00
|
|
|
snd_seq_close(seq);
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("can't set client info\n"));
|
2002-07-17 14:05:15 +02:00
|
|
|
return 1;
|
2000-01-04 13:39:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set subscription */
|
2001-07-04 15:55:13 +02:00
|
|
|
if (snd_seq_parse_address(seq, &sender, argv[optind]) < 0) {
|
2002-07-17 14:05:15 +02:00
|
|
|
snd_seq_close(seq);
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("invalid sender address %s\n"), argv[optind]);
|
2000-01-04 13:39:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
if (snd_seq_parse_address(seq, &dest, argv[optind + 1]) < 0) {
|
2002-07-17 14:05:15 +02:00
|
|
|
snd_seq_close(seq);
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("invalid destination address %s\n"), argv[optind + 1]);
|
2000-01-04 13:39:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
snd_seq_port_subscribe_alloca(&subs);
|
|
|
|
snd_seq_port_subscribe_set_sender(subs, &sender);
|
|
|
|
snd_seq_port_subscribe_set_dest(subs, &dest);
|
|
|
|
snd_seq_port_subscribe_set_queue(subs, queue);
|
|
|
|
snd_seq_port_subscribe_set_exclusive(subs, exclusive);
|
|
|
|
snd_seq_port_subscribe_set_time_update(subs, convert_time);
|
|
|
|
snd_seq_port_subscribe_set_time_real(subs, convert_real);
|
2000-01-04 13:39:00 +01:00
|
|
|
|
|
|
|
if (command == UNSUBSCRIBE) {
|
2001-07-04 15:55:13 +02:00
|
|
|
if (snd_seq_get_port_subscription(seq, subs) < 0) {
|
2000-01-04 13:39:00 +01:00
|
|
|
snd_seq_close(seq);
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("No subscription is found\n"));
|
2000-01-04 13:39:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
if (snd_seq_unsubscribe_port(seq, subs) < 0) {
|
2000-01-04 13:39:00 +01:00
|
|
|
snd_seq_close(seq);
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("Disconnection failed (%s)\n"), snd_strerror(errno));
|
2000-01-04 13:39:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
2001-07-04 15:55:13 +02:00
|
|
|
if (snd_seq_get_port_subscription(seq, subs) == 0) {
|
2000-01-04 13:39:00 +01:00
|
|
|
snd_seq_close(seq);
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("Connection is already subscribed\n"));
|
2000-01-04 13:39:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2001-07-04 15:55:13 +02:00
|
|
|
if (snd_seq_subscribe_port(seq, subs) < 0) {
|
2000-01-04 13:39:00 +01:00
|
|
|
snd_seq_close(seq);
|
2005-06-23 12:38:06 +02:00
|
|
|
fprintf(stderr, _("Connection failed (%s)\n"), snd_strerror(errno));
|
2000-01-04 13:39:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_seq_close(seq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|