~ubuntu-branches/ubuntu/saucy/jack-audio-connection-kit/saucy

« back to all changes in this revision

Viewing changes to example-clients/showtime.c

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-12-06 11:05:15 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081206110515-xa9v9pajr9jqvfvg
Tags: 0.115.6-1ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  - Redirect stderr in bash completion (Debian #504488).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <errno.h>
 
3
#include <unistd.h>
 
4
#include <signal.h>
 
5
#include <stdlib.h>
 
6
 
 
7
#include <jack/jack.h>
 
8
#include <jack/transport.h>
 
9
 
 
10
jack_client_t *client;
 
11
 
 
12
 
 
13
void
 
14
showtime ()
 
15
{
 
16
        jack_position_t current;
 
17
        jack_transport_state_t transport_state;
 
18
        jack_nframes_t frame_time;
 
19
 
 
20
        transport_state = jack_transport_query (client, &current);
 
21
        frame_time = jack_frame_time (client);
 
22
        
 
23
        printf ("frame: %7" PRIu32 " @ %" PRIu32 "\t", current.frame, frame_time);
 
24
 
 
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]");
 
37
        }
 
38
 
 
39
        if (current.valid & JackPositionBBT)
 
40
                printf ("\tBBT: %3" PRIi32 "|%" PRIi32 "|%04"
 
41
                        PRIi32, current.bar, current.beat, current.tick);
 
42
 
 
43
        if (current.valid & JackPositionTimecode)
 
44
                printf ("\tTC: (%.6f, %.6f)",
 
45
                        current.frame_time, current.next_time);
 
46
 
 
47
        if (current.valid & JackBBTFrameOffset)
 
48
                printf ("\tBBT offset: (%" PRIi32 ")",
 
49
                        current.bbt_offset);
 
50
 
 
51
        if (current.valid & JackAudioVideoRatio)
 
52
                printf ("\taudio/video: (%f)",
 
53
                        current.audio_frames_per_video_frame);
 
54
 
 
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");
 
60
                }
 
61
        }
 
62
        
 
63
        printf ("\n");
 
64
}
 
65
 
 
66
void
 
67
jack_shutdown (void *arg)
 
68
{
 
69
        exit (1);
 
70
}
 
71
 
 
72
void
 
73
signal_handler (int sig)
 
74
{
 
75
        jack_client_close (client);
 
76
        fprintf (stderr, "signal received, exiting ...\n");
 
77
        exit (0);
 
78
}
 
79
 
 
80
int
 
81
main (int argc, char *argv[])
 
82
 
 
83
{
 
84
        /* try to become a client of the JACK server */
 
85
 
 
86
        if ((client = jack_client_new ("showtime")) == 0) {
 
87
                fprintf (stderr, "jack server not running?\n");
 
88
                return 1;
 
89
        }
 
90
 
 
91
        signal (SIGQUIT, signal_handler);
 
92
        signal (SIGTERM, signal_handler);
 
93
        signal (SIGHUP, signal_handler);
 
94
        signal (SIGINT, signal_handler);
 
95
 
 
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.
 
99
        */
 
100
 
 
101
        jack_on_shutdown (client, jack_shutdown, 0);
 
102
 
 
103
        /* tell the JACK server that we are ready to roll */
 
104
 
 
105
        if (jack_activate (client)) {
 
106
                fprintf (stderr, "cannot activate client");
 
107
                return 1;
 
108
        }
 
109
        
 
110
        while (1) {
 
111
                usleep (20);
 
112
                showtime ();
 
113
        }
 
114
 
 
115
        jack_client_close (client);
 
116
        exit (0);
 
117
}