This repository has been archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
showtime.c
117 lines (92 loc) · 2.35 KB
/
showtime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <jack/jack.h>
#include <jack/transport.h>
jack_client_t *client;
void
showtime ()
{
jack_position_t current;
jack_transport_state_t transport_state;
jack_nframes_t frame_time;
transport_state = jack_transport_query (client, ¤t);
frame_time = jack_frame_time (client);
printf ("frame: %7" PRIu32 " @ %" PRIu32 "\t", current.frame, frame_time);
switch (transport_state) {
case JackTransportStopped:
printf ("state: Stopped");
break;
case JackTransportRolling:
printf ("state: Rolling");
break;
case JackTransportStarting:
printf ("state: Starting");
break;
default:
printf ("state: [unknown]");
}
if (current.valid & JackPositionBBT)
printf ("\tBBT: %3" PRIi32 "|%" PRIi32 "|%04"
PRIi32, current.bar, current.beat, current.tick);
if (current.valid & JackPositionTimecode)
printf ("\tTC: (%.6f, %.6f)",
current.frame_time, current.next_time);
if (current.valid & JackBBTFrameOffset)
printf ("\tBBT offset: (%" PRIi32 ")",
current.bbt_offset);
if (current.valid & JackAudioVideoRatio)
printf ("\taudio/video: (%f)",
current.audio_frames_per_video_frame);
if (current.valid & JackVideoFrameOffset) {
if (current.video_offset) {
printf ("\t video@: (%" PRIi32 ")", current.video_offset);
} else {
printf ("\t no video");
}
}
printf ("\n");
}
void
jack_shutdown (void *arg)
{
exit (1);
}
void
signal_handler (int sig)
{
jack_client_close (client);
fprintf (stderr, "signal received, exiting ...\n");
exit (0);
}
int
main (int argc, char *argv[])
{
/* try to become a client of the JACK server */
if ((client = jack_client_open ("showtime", JackNullOption, NULL)) == 0) {
fprintf (stderr, "jack server not running?\n");
return 1;
}
signal (SIGQUIT, signal_handler);
signal (SIGTERM, signal_handler);
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
/* tell the JACK server to call `jack_shutdown()' if
it ever shuts down, either entirely, or if it
just decides to stop calling us.
*/
jack_on_shutdown (client, jack_shutdown, 0);
/* tell the JACK server that we are ready to roll */
if (jack_activate (client)) {
fprintf (stderr, "cannot activate client");
return 1;
}
while (1) {
usleep (20);
showtime ();
}
jack_client_close (client);
exit (0);
}