|
| 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