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>
31 jack_port_t
*input_port
;
32 jack_port_t
*output_port
;
33 int connecting
, disconnecting
;
38 show_version (char *my_name
)
40 fprintf (stderr
, "%s: JACK Audio Connection Kit version " VERSION
"\n", my_name
);
44 show_usage (char *my_name
)
46 show_version (my_name
);
47 fprintf (stderr
, "\nusage: %s [options] <src_port> <dst_port>\n", my_name
);
48 fprintf (stderr
, "Connects two JACK ports together.\n\n");
49 fprintf (stderr
, " The source port must be an output port of the source client.\n");
50 fprintf (stderr
, " The destination port must be an input port of the destination client.\n");
51 fprintf (stderr
, " -s, --server <name> Connect to the jack server named <name>\n");
52 fprintf (stderr
, " -v, --version Output version information and exit\n");
53 fprintf (stderr
, " -h, --help Display this help message\n\n");
54 fprintf (stderr
, "For more information see http://jackaudio.org/\n");
58 main (int argc
, char *argv
[])
60 jack_client_t
*client
;
62 char *server_name
= NULL
;
65 jack_options_t options
= JackNoStartServer
;
66 char *my_name
= strrchr(argv
[0], '/');
68 struct option long_options
[] = {
69 { "server", 1, 0, 's' },
70 { "help", 0, 0, 'h' },
71 { "version", 0, 0, 'v' },
75 while ((c
= getopt_long (argc
, argv
, "s:AclLphvt", long_options
, &option_index
)) >= 0) {
78 server_name
= (char *) malloc (sizeof (char) * strlen(optarg
));
79 strcpy (server_name
, optarg
);
80 options
|= JackServerName
;
87 show_version (my_name
);
97 connecting
= disconnecting
= FALSE
;
104 if (strstr(my_name
, "disconnect")) {
105 disconnecting
= TRUE
;
107 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 /* display the current sample rate. once the client is activated
124 (see below), you should rely on your own sample rate
125 callback (see above) for this value.
128 printf ("engine sample rate: %" PRIu32
"\n",
129 jack_get_sample_rate (client
));
131 /* find the two ports */
133 if ((input_port
= jack_port_by_name(client
, argv
[argc
-1])) == 0) {
134 fprintf (stderr
, "ERROR %s not a valid port\n", argv
[argc
-1]);
137 if ((output_port
= jack_port_by_name(client
, argv
[argc
-2])) == 0) {
138 fprintf (stderr
, "ERROR %s not a valid port\n", argv
[argc
-2]);
142 /* tell the JACK server that we are ready to roll */
144 if (jack_activate (client
)) {
145 fprintf (stderr
, "cannot activate client");
149 /* connect the ports. Note: you can't do this before
150 the client is activated (this may change in the future).
153 /* jack_port_connect not implemented
154 if (jack_port_connect(client, input_port, output_port)) {
155 fprintf (stderr, "cannot connect ports\n");
159 if (jack_connect(client
, jack_port_name(input_port
), jack_port_name(output_port
))) {
160 fprintf (stderr
, "cannot connect ports\n");
165 if (jack_disconnect(client
, jack_port_name(input_port
), jack_port_name(output_port
))) {
166 fprintf (stderr
, "cannot disconnect ports\n");
171 jack_client_close (client
);