Skip to content

Commit 1e48dae

Browse files
committed
Add "showtime" example client
Closes #20.
1 parent 4cdd149 commit 1e48dae

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

doc/examples.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ Pass-Through Client
1717

1818
.. literalinclude:: ../examples/thru_client.py
1919

20+
"Showtime" Client
21+
-----------------
22+
23+
:download:`showtime.py <../examples/showtime.py>`
24+
25+
.. literalinclude:: ../examples/showtime.py
26+
2027
MIDI Monitor
2128
------------
2229

examples/showtime.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python3
2+
3+
"""Display information about time, transport state et cetera.
4+
5+
This is somewhat modeled after the "showtime.c" example of JACK.
6+
https://github.com/jackaudio/example-clients/blob/master/showtime.c
7+
https://github.com/jackaudio/jack2/blob/master/example-clients/showtime.c
8+
9+
"""
10+
from contextlib import suppress
11+
import time
12+
import sys
13+
14+
import jack
15+
16+
17+
try:
18+
client = jack.Client('showtime')
19+
except jack.JackError:
20+
sys.exit('JACK server not running?')
21+
22+
23+
def showtime():
24+
state, pos = client.transport_query()
25+
items = []
26+
items.append('frame = {} frame_time = {} usecs = {} '.format(
27+
pos['frame'], client.frame_time, pos['usecs']))
28+
items.append('state: {}'.format(state))
29+
with suppress(KeyError):
30+
items.append('BBT: {bar:3}|{beat}|{tick:04}'.format(**pos))
31+
with suppress(KeyError):
32+
items.append('TC: ({frame_time:.6f}, {next_time:.6f})'.format(**pos))
33+
with suppress(KeyError):
34+
items.append('BBT offset: ({bbt_offset})'.format(**pos))
35+
with suppress(KeyError):
36+
items.append(
37+
'audio/video: ({audio_frames_per_video_frame})'.format(**pos))
38+
with suppress(KeyError):
39+
video_offset = pos['video_offset']
40+
if video_offset:
41+
items.append(' video@: ({})'.format(video_offset))
42+
else:
43+
items.append(' no video');
44+
print(*items, sep='\t')
45+
46+
47+
@client.set_shutdown_callback
48+
def shutdown(status, reason):
49+
sys.exit('JACK shut down, exiting ...')
50+
51+
52+
with client:
53+
try:
54+
while True:
55+
time.sleep(0.00002)
56+
showtime()
57+
except KeyboardInterrupt:
58+
print('signal received, exiting ...', file=sys.stderr)
59+
sys.exit(0)

0 commit comments

Comments
 (0)