2 Copyright (C) 2002 Jeremy Hall
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <jack/jack.h>
35 show_version (char *my_name
)
37 fprintf (stderr
, "%s: JACK Audio Connection Kit version " VERSION
"\n", my_name
);
41 show_usage (char *my_name
)
43 show_version (my_name
);
44 fprintf (stderr
, "\nusage: %s [options] port1 port2\n", my_name
);
45 fprintf (stderr
, "Connects two JACK ports together.\n\n");
46 fprintf (stderr
, " -s, --server <name> Connect to the jack server named <name>\n");
47 fprintf (stderr
, " -v, --version Output version information and exit\n");
48 fprintf (stderr
, " -h, --help Display this help message\n\n");
49 fprintf (stderr
, "For more information see http://jackaudio.org/\n");
53 main (int argc
, char *argv
[])
55 jack_client_t
*client
;
57 char *server_name
= NULL
;
60 jack_options_t options
= JackNoStartServer
;
61 char *my_name
= strrchr(argv
[0], '/');
62 jack_port_t
*src_port
= 0;
63 jack_port_t
*dst_port
= 0;
64 jack_port_t
*port1
= 0;
65 jack_port_t
*port2
= 0;
66 int connecting
, disconnecting
;
67 int port1_flags
, port2_flags
;
69 struct option long_options
[] = {
70 { "server", 1, 0, 's' },
71 { "help", 0, 0, 'h' },
72 { "version", 0, 0, 'v' },
76 while ((c
= getopt_long (argc
, argv
, "s:hv", long_options
, &option_index
)) >= 0) {
79 server_name
= (char *) malloc (sizeof (char) * strlen(optarg
));
80 strcpy (server_name
, optarg
);
81 options
|= JackServerName
;
88 show_version (my_name
);
98 connecting
= disconnecting
= FALSE
;
105 if (strstr(my_name
, "disconnect")) {
107 } else if (strstr(my_name
, "connect")) {
110 fprintf(stderr
, "ERROR! client should be called jack_connect or jack_disconnect. client is called %s\n", my_name
);
114 if (argc
< 3) show_usage(my_name
);
116 /* try to become a client of the JACK server */
118 if ((client
= jack_client_open (my_name
, options
, &status
, server_name
)) == 0) {
119 fprintf (stderr
, "jack server not running?\n");
123 /* find the two ports */
125 if ((port1
= jack_port_by_name(client
, argv
[argc
-1])) == 0) {
126 fprintf (stderr
, "ERROR %s not a valid port\n", argv
[argc
-1]);
129 if ((port2
= jack_port_by_name(client
, argv
[argc
-2])) == 0) {
130 fprintf (stderr
, "ERROR %s not a valid port\n", argv
[argc
-2]);
134 port1_flags
= jack_port_flags (port1
);
135 port2_flags
= jack_port_flags (port2
);
137 if (port1_flags
& JackPortIsInput
) {
138 if (port2_flags
& JackPortIsOutput
) {
143 if (port2_flags
& JackPortIsInput
) {
149 if (!src_port
|| !dst_port
) {
150 fprintf (stderr
, "arguments must include 1 input port and 1 output port\n");
154 /* connect the ports. Note: you can't do this before
155 the client is activated (this may change in the future).
159 if (jack_connect(client
, jack_port_name(src_port
), jack_port_name(dst_port
))) {
164 if (jack_disconnect(client
, jack_port_name(src_port
), jack_port_name(dst_port
))) {
169 jack_client_close (client
);