FreeBSD: Add missing OSS option --excl to man page.
[jack2.git] / example-clients / showtime.c
blob5c352f87f00292ed945d65d52f7bad2a5c914e36
1 /*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 #include <stdio.h>
18 #include <errno.h>
19 #include <unistd.h>
20 #include <signal.h>
21 #include <stdlib.h>
22 #include <inttypes.h>
24 #include <jack/jack.h>
25 #include <jack/transport.h>
27 jack_client_t *client;
29 static void
30 showtime ()
32 jack_position_t current;
33 jack_transport_state_t transport_state;
34 jack_nframes_t frame_time;
36 transport_state = jack_transport_query (client, &current);
37 frame_time = jack_frame_time (client);
39 printf ("frame = %u frame_time = %u usecs = %" PRIu64 "\t", current.frame, frame_time, current.usecs);
41 switch (transport_state) {
42 case JackTransportStopped:
43 printf ("state: Stopped");
44 break;
45 case JackTransportRolling:
46 printf ("state: Rolling");
47 break;
48 case JackTransportStarting:
49 printf ("state: Starting");
50 break;
51 default:
52 printf ("state: [unknown]");
55 if (current.valid & JackPositionBBT)
56 printf ("\tBBT: %3" PRIi32 "|%" PRIi32 "|%04"
57 PRIi32, current.bar, current.beat, current.tick);
59 if (current.valid & JackPositionTimecode)
60 printf ("\tTC: (%.6f, %.6f)",
61 current.frame_time, current.next_time);
62 printf ("\n");
65 static void
66 jack_shutdown (void *arg)
68 fprintf(stderr, "JACK shut down, exiting ...\n");
69 exit (1);
72 void
73 signal_handler (int sig)
75 jack_client_close (client);
76 fprintf (stderr, "signal received, exiting ...\n");
77 exit (0);
80 int
81 main (int argc, char *argv[])
83 /* try to become a client of the JACK server */
85 if ((client = jack_client_open ("showtime", JackNullOption, NULL)) == 0) {
86 fprintf (stderr, "JACK server not running?\n");
87 return 1;
90 #ifndef WIN32
91 signal (SIGQUIT, signal_handler);
92 signal (SIGHUP, signal_handler);
93 #endif
95 signal (SIGTERM, signal_handler);
96 signal (SIGINT, signal_handler);
98 /* tell the JACK server to call `jack_shutdown()' if
99 it ever shuts down, either entirely, or if it
100 just decides to stop calling us.
103 jack_on_shutdown (client, jack_shutdown, 0);
105 /* tell the JACK server that we are ready to roll */
107 if (jack_activate (client)) {
108 fprintf (stderr, "cannot activate client");
109 return 1;
112 while (1) {
113 usleep (20);
114 showtime ();
117 jack_client_close (client);
118 exit (0);