Merge branch 'master' into develop
[jack2.git] / tools / samplerate.c
blob88b5c31a05e5803fb615939d7b96b64a98326c68
1 /*
2 * smaplerate.c -- get current samplerate
4 * Copyright (C) 2003 Jack O'Quin.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <stdio.h>
22 #include <errno.h>
23 #include <unistd.h>
24 #include <signal.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <jack/jack.h>
28 #include <jack/transport.h>
30 char *package; /* program name */
31 jack_client_t *client;
33 void jack_shutdown(void *arg)
35 fprintf(stderr, "JACK shut down, exiting ...\n");
36 exit(1);
39 void signal_handler(int sig)
41 jack_client_close(client);
42 fprintf(stderr, "signal received, exiting ...\n");
43 exit(0);
46 void parse_arguments(int argc, char *argv[])
49 /* basename $0 */
50 package = strrchr(argv[0], '/');
51 if (package == 0)
52 package = argv[0];
53 else
54 package++;
56 if (argc==1) {
57 return;
59 fprintf(stderr, "usage: %s\n", package);
60 exit(9);
63 int main(int argc, char *argv[])
65 parse_arguments(argc, argv);
67 /* become a JACK client */
68 if ((client = jack_client_open(package, JackNullOption, NULL)) == 0) {
69 fprintf(stderr, "JACK server not running?\n");
70 exit(1);
73 #ifndef WIN32
74 signal(SIGQUIT, signal_handler);
75 signal(SIGHUP, signal_handler);
76 #endif
77 signal(SIGTERM, signal_handler);
78 signal(SIGINT, signal_handler);
80 jack_on_shutdown(client, jack_shutdown, 0);
82 fprintf(stdout, "%d\n", jack_get_sample_rate( client ) );
84 jack_client_close(client);
86 return 0;