Skip to content

Commit 5b745f2

Browse files
committed
Rename transport_query() -> transport_query_struct() ...
... create a new transport_query() and a TransportState class. See spatialaudio#12.
1 parent 0563d10 commit 5b745f2

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

‎jack.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,42 @@ def transport_locate(self, frame):
691691
def transport_query(self):
692692
"""Query the current transport state and position.
693693
694+
This is a convenience function that does the same as
695+
:meth:`transport_query_struct` but it only returns the valid
696+
fields in an easy-to-use ``dict``.
697+
698+
Returns
699+
-------
700+
state : TransportState
701+
The transport state can take following values:
702+
:attr:`STOPPED`, :attr:`ROLLING`, :attr:`STARTING` and
703+
:attr:`NETSTARTING`.
704+
position : dict
705+
A dictionary containing only the valid fields of the
706+
structure returned by :meth:`transport_query_struct`.
707+
708+
"""
709+
state, pos = self.transport_query_struct()
710+
assert pos.unique_1 == pos.unique_2
711+
712+
keys = ['usecs', 'frame_rate', 'frame']
713+
if pos.valid & _lib.JackPositionBBT:
714+
keys += ['bar', 'beat', 'tick', 'bar_start_tick', 'beats_per_bar',
715+
'beat_type', 'ticks_per_beat', 'beats_per_minute']
716+
if pos.valid & _lib.JackPositionTimecode:
717+
keys += ['frame_time', 'next_time']
718+
if pos.valid & _lib.JackBBTFrameOffset:
719+
keys += ['bbt_offset']
720+
if pos.valid & _lib.JackAudioVideoRatio:
721+
keys += ['audio_frames_per_video_frame']
722+
if pos.valid & _lib.JackVideoFrameOffset:
723+
keys += ['video_offset']
724+
725+
return TransportState(state), dict((k, getattr(pos, k)) for k in keys)
726+
727+
def transport_query_struct(self):
728+
"""Query the current transport state and position.
729+
694730
This function is realtime-safe, and can be called from any
695731
thread. If called from the process thread, the returned
696732
position corresponds to the first frame of the current cycle and
@@ -708,6 +744,10 @@ def transport_query(self):
708744
709745
__ http://jackaudio.org/files/docs/html/structjack__position__t.html
710746
747+
See Also
748+
--------
749+
transport_query
750+
711751
"""
712752
state = _lib.jack_transport_query(self._ptr, self._position)
713753
return state, self._position
@@ -2269,6 +2309,27 @@ def _hasflag(self, flag):
22692309
return bool(self & flag)
22702310

22712311

2312+
class TransportState(_StatusBase):
2313+
2314+
"""Representation of the JACK transport state.
2315+
2316+
See Also
2317+
--------
2318+
:attr:`Client.transport_state`, :meth:`Client.transport_query`
2319+
2320+
"""
2321+
2322+
__slots__ = ()
2323+
2324+
def __repr__(self):
2325+
return "jack." + {
2326+
_lib.JackTransportStopped: 'STOPPED',
2327+
_lib.JackTransportRolling: 'ROLLING',
2328+
_lib.JackTransportStarting: 'STARTING',
2329+
_lib.JackTransportNetStarting: 'NETSTARTING',
2330+
}[int(self)]
2331+
2332+
22722333
class JackError(Exception):
22732334

22742335
"""Exception for all kinds of JACK-related errors."""

0 commit comments

Comments
 (0)