Merge branch 'master' into server_no_deadlock
[jack2.git] / example-clients / showtime.c
blobaf413e89455f7dd9212b7b0b9d483cb4d6663be0
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>
23 #include <jack/jack.h>
24 #include <jack/transport.h>
26 jack_client_t *client;
28 static void
29 showtime ()
31 jack_position_t current;
32 jack_transport_state_t transport_state;
33 jack_nframes_t frame_time;
35 transport_state = jack_transport_query (client, &current);
36 frame_time = jack_frame_time (client);
38 printf ("frame = %u frame_time = %u usecs = %lld \t", current.frame, frame_time, current.usecs);
40 switch (transport_state) {
41 case JackTransportStopped:
42 printf ("state: Stopped");
43 break;
44 case JackTransportRolling:
45 printf ("state: Rolling");
46 break;
47 case JackTransportStarting:
48 printf ("state: Starting");
49 break;
50 default:
51 printf ("state: [unknown]");
54 if (current.valid & JackPositionBBT)
55 printf ("\tBBT: %3" PRIi32 "|%" PRIi32 "|%04"
56 PRIi32, current.bar, current.beat, current.tick);
58 if (current.valid & JackPositionTimecode)
59 printf ("\tTC: (%.6f, %.6f)",
60 current.frame_time, current.next_time);
61 printf ("\n");
64 static void
65 jack_shutdown (void *arg)
67 exit (1);
70 void
71 signal_handler (int sig)
73 jack_client_close (client);
74 fprintf (stderr, "signal received, exiting ...\n");
75 exit (0);
78 int
79 main (int argc, char *argv[])
81 /* try to become a client of the JACK server */
83 if ((client = jack_client_open ("showtime", JackNullOption, NULL)) == 0) {
84 fprintf (stderr, "jack server not running?\n");
85 return 1;
88 signal (SIGQUIT, signal_handler);
89 signal (SIGTERM, signal_handler);
90 signal (SIGHUP, signal_handler);
91 signal (SIGINT, signal_handler);
93 /* tell the JACK server to call `jack_shutdown()' if
94 it ever shuts down, either entirely, or if it
95 just decides to stop calling us.
98 jack_on_shutdown (client, jack_shutdown, 0);
100 /* tell the JACK server that we are ready to roll */
102 if (jack_activate (client)) {
103 fprintf (stderr, "cannot activate client");
104 return 1;
107 while (1) {
108 usleep (20);
109 showtime ();
112 jack_client_close (client);
113 exit (0);