Remove compiler warning
[jack2.git] / example-clients / connect.c
blobc97131246635da4204e128a5da35ff9b21dc7c19
1 /*
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.
18 $Id: connect.c,v 1.1.2.1 2006/06/05 16:54:55 letz Exp $
21 #include <stdio.h>
22 #include <errno.h>
23 #ifndef WIN32
24 #include <unistd.h>
25 #endif
26 #include <string.h>
27 #include <stdlib.h>
28 #include <math.h>
31 #include "jack.h"
33 jack_port_t *input_port;
34 jack_port_t *output_port;
35 int connecting, disconnecting;
36 #define TRUE 1
37 #define FALSE 0
39 int
40 main (int argc, char *argv[])
43 jack_client_t* client = NULL;
44 char *my_name = strrchr(argv[0], '/');
45 connecting = disconnecting = FALSE;
46 if (my_name == 0) {
47 my_name = argv[0];
48 } else {
49 my_name ++;
52 printf("name %s\n", my_name);
54 if (strstr(my_name, "jack_disconnect")) {
55 disconnecting = TRUE;
56 } else
57 if (strstr(my_name, "jack_connect")) {
58 connecting = TRUE;
59 } else {
60 fprintf(stderr, "ERROR! client should be called jack_connect or jack_disconnect. client is called %s\n", my_name);
61 //return 1;
62 goto error;
65 printf("connecting %ld\n",connecting);
67 if (argc != 3) {
68 fprintf (stderr, "usage: %s <src_port> <dst_port>\n", my_name);
69 fprintf(stderr, "The source port must be an output port of the source client.\n");
70 fprintf (stderr, "The destination port must be an input port of the destination client.\n");
71 //return 1;
72 goto error;
75 /* try to become a client of the JACK server */
77 if ((client = jack_client_new (my_name)) == 0) {
78 fprintf (stderr, "jack server not running?\n");
79 //return 1;
80 goto error;
83 /* display the current sample rate. once the client is activated
84 (see below), you should rely on your own sample rate
85 callback (see above) for this value.
88 // printf ("engine sample rate: %" PRIu32 "\n",jack_get_sample_rate (client));
90 /* find the two ports */
92 if ((input_port = jack_port_by_name(client, argv[1])) == 0) {
93 fprintf (stderr, "ERROR %s not a valid port\n", argv[1]);
94 goto error;
96 if ((output_port = jack_port_by_name(client, argv[2])) == 0) {
97 fprintf (stderr, "ERROR %s not a valid port\n", argv[2]);
98 goto error;
101 /* tell the JACK server that we are ready to roll */
103 if (jack_activate (client)) {
104 fprintf (stderr, "cannot activate client");
105 goto error;
108 /* connect the ports. Note: you can't do this before
109 the client is activated (this may change in the future).
112 /* jack_port_connect not yet implemented
113 if (jack_port_connect(client, input_port, output_port)) {
114 fprintf (stderr, "cannot connect ports\n");
117 if (connecting) {
118 printf("connecting %s %s\n",jack_port_name(input_port), jack_port_name(output_port));
120 if (jack_connect(client, jack_port_name(input_port), jack_port_name(output_port))) {
121 fprintf (stderr, "cannot connect ports\n");
122 goto error;
125 if (disconnecting) {
126 printf("disconnecting %s %s\n",jack_port_name(input_port), jack_port_name(output_port));
128 if (jack_disconnect(client, jack_port_name(input_port), jack_port_name(output_port))) {
129 fprintf (stderr, "cannot disconnect ports\n");
130 goto error;
133 //jack_deactivate (client);
134 jack_client_close (client);
135 return 0;
137 error:
138 if (client) jack_client_close (client);
139 return 1;