Merge pull request #23 from jackaudio/device_reservation_fixes
[jack2.git] / example-clients / showtime.c
blob0b421e7cd66193919d2341e0e9d824e94ebd0d84
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 fprintf(stderr, "JACK shut down, exiting ...\n");
68 exit (1);
71 void
72 signal_handler (int sig)
74 jack_client_close (client);
75 fprintf (stderr, "signal received, exiting ...\n");
76 exit (0);
79 int
80 main (int argc, char *argv[])
82 /* try to become a client of the JACK server */
84 if ((client = jack_client_open ("showtime", JackNullOption, NULL)) == 0) {
85 fprintf (stderr, "JACK server not running?\n");
86 return 1;
89 signal (SIGQUIT, signal_handler);
90 signal (SIGTERM, signal_handler);
91 signal (SIGHUP, signal_handler);
92 signal (SIGINT, signal_handler);
94 /* tell the JACK server to call `jack_shutdown()' if
95 it ever shuts down, either entirely, or if it
96 just decides to stop calling us.
99 jack_on_shutdown (client, jack_shutdown, 0);
101 /* tell the JACK server that we are ready to roll */
103 if (jack_activate (client)) {
104 fprintf (stderr, "cannot activate client");
105 return 1;
108 while (1) {
109 usleep (20);
110 showtime ();
113 jack_client_close (client);
114 exit (0);