cleanup...
[jack.git] / example-clients / showtime.c
blobe97da09accef161f56cfe7d97fc5ec6f0c20a753
1 #include <stdio.h>
2 #include <errno.h>
3 #include <unistd.h>
4 #include <signal.h>
5 #include <stdlib.h>
7 #include <jack/jack.h>
8 #include <jack/transport.h>
10 jack_client_t *client;
13 void
14 showtime ()
16 jack_position_t current;
17 jack_transport_state_t transport_state;
18 jack_nframes_t frame_time;
20 transport_state = jack_transport_query (client, &current);
21 frame_time = jack_frame_time (client);
23 printf ("frame: %7" PRIu32 " @ %" PRIu32 "\t", current.frame, frame_time);
25 switch (transport_state) {
26 case JackTransportStopped:
27 printf ("state: Stopped");
28 break;
29 case JackTransportRolling:
30 printf ("state: Rolling");
31 break;
32 case JackTransportStarting:
33 printf ("state: Starting");
34 break;
35 default:
36 printf ("state: [unknown]");
39 if (current.valid & JackPositionBBT)
40 printf ("\tBBT: %3" PRIi32 "|%" PRIi32 "|%04"
41 PRIi32, current.bar, current.beat, current.tick);
43 if (current.valid & JackPositionTimecode)
44 printf ("\tTC: (%.6f, %.6f)",
45 current.frame_time, current.next_time);
47 if (current.valid & JackBBTFrameOffset)
48 printf ("\tBBT offset: (%" PRIi32 ")",
49 current.bbt_offset);
51 if (current.valid & JackAudioVideoRatio)
52 printf ("\taudio/video: (%f)",
53 current.audio_frames_per_video_frame);
55 if (current.valid & JackVideoFrameOffset) {
56 if (current.video_offset) {
57 printf ("\t video@: (%" PRIi32 ")", current.video_offset);
58 } else {
59 printf ("\t no video");
63 printf ("\n");
66 void
67 jack_shutdown (void *arg)
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[])
84 /* try to become a client of the JACK server */
86 if ((client = jack_client_new ("showtime")) == 0) {
87 fprintf (stderr, "jack server not running?\n");
88 return 1;
91 signal (SIGQUIT, signal_handler);
92 signal (SIGTERM, signal_handler);
93 signal (SIGHUP, signal_handler);
94 signal (SIGINT, signal_handler);
96 /* tell the JACK server to call `jack_shutdown()' if
97 it ever shuts down, either entirely, or if it
98 just decides to stop calling us.
101 jack_on_shutdown (client, jack_shutdown, 0);
103 /* tell the JACK server that we are ready to roll */
105 if (jack_activate (client)) {
106 fprintf (stderr, "cannot activate client");
107 return 1;
110 while (1) {
111 usleep (20);
112 showtime ();
115 jack_client_close (client);
116 exit (0);