Skip to content

Commit 6ab8896

Browse files
committed
Add position2dict()
1 parent 6c4ae51 commit 6ab8896

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

jack.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -730,22 +730,7 @@ def transport_query(self):
730730
731731
"""
732732
state, pos = self.transport_query_struct()
733-
assert pos.unique_1 == pos.unique_2
734-
735-
keys = ['usecs', 'frame_rate', 'frame']
736-
if pos.valid & _lib.JackPositionBBT:
737-
keys += ['bar', 'beat', 'tick', 'bar_start_tick', 'beats_per_bar',
738-
'beat_type', 'ticks_per_beat', 'beats_per_minute']
739-
if pos.valid & _lib.JackPositionTimecode:
740-
keys += ['frame_time', 'next_time']
741-
if pos.valid & _lib.JackBBTFrameOffset:
742-
keys += ['bbt_offset']
743-
if pos.valid & _lib.JackAudioVideoRatio:
744-
keys += ['audio_frames_per_video_frame']
745-
if pos.valid & _lib.JackVideoFrameOffset:
746-
keys += ['video_offset']
747-
748-
return TransportState(state), dict((k, getattr(pos, k)) for k in keys)
733+
return TransportState(state), position2dict(pos)
749734

750735
def transport_query_struct(self):
751736
"""Query the current transport state and position.
@@ -2453,6 +2438,26 @@ class JackError(Exception):
24532438
pass
24542439

24552440

2441+
def position2dict(pos):
2442+
"""Convert CFFI position struct to a dict."""
2443+
assert pos.unique_1 == pos.unique_2
2444+
2445+
keys = ['usecs', 'frame_rate', 'frame']
2446+
if pos.valid & _lib.JackPositionBBT:
2447+
keys += ['bar', 'beat', 'tick', 'bar_start_tick', 'beats_per_bar',
2448+
'beat_type', 'ticks_per_beat', 'beats_per_minute']
2449+
if pos.valid & _lib.JackPositionTimecode:
2450+
keys += ['frame_time', 'next_time']
2451+
if pos.valid & _lib.JackBBTFrameOffset:
2452+
keys += ['bbt_offset']
2453+
if pos.valid & _lib.JackAudioVideoRatio:
2454+
keys += ['audio_frames_per_video_frame']
2455+
if pos.valid & _lib.JackVideoFrameOffset:
2456+
keys += ['video_offset']
2457+
2458+
return dict((k, getattr(pos, k)) for k in keys)
2459+
2460+
24562461
def version():
24572462
"""Get tuple of major/minor/micro/protocol version."""
24582463
major_ptr = _ffi.new("int*")

0 commit comments

Comments
 (0)