Skip to content

Commit f8a21a8

Browse files
Vampouillemgeier
authored andcommitted
Add Client.transport_query()
See spatialaudio#10.
1 parent 63a9cba commit f8a21a8

1 file changed

Lines changed: 87 additions & 4 deletions

File tree

‎jack.py‎

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
3535
typedef uint64_t jack_uuid_t;
3636
typedef uint32_t jack_nframes_t;
37-
/* TODO: jack_time_t */
37+
typedef uint64_t jack_time_t;
3838
typedef struct _jack_port jack_port_t;
3939
typedef struct _jack_client jack_client_t;
4040
typedef uint32_t jack_port_id_t;
@@ -92,7 +92,14 @@
9292
JackTransportStarting = 3,
9393
JackTransportNetStarting = 4,
9494
} jack_transport_state_t;
95-
typedef struct _jack_position jack_position_t;
95+
typedef uint64_t jack_unique_t;
96+
typedef enum {
97+
JackPositionBBT = 0x10,
98+
JackPositionTimecode = 0x20,
99+
JackBBTFrameOffset = 0x40,
100+
JackAudioVideoRatio = 0x80,
101+
JackVideoFrameOffset = 0x100,
102+
} jack_position_bits_t;
96103
97104
/* jack.h */
98105
@@ -190,9 +197,7 @@
190197
/* transport.h */
191198
192199
int jack_transport_locate(jack_client_t* client, jack_nframes_t frame);
193-
jack_transport_state_t jack_transport_query(const jack_client_t* client, jack_position_t* pos);
194200
jack_nframes_t jack_get_current_transport_frame(const jack_client_t* client);
195-
int jack_transport_reposition(jack_client_t* client, const jack_position_t* pos);
196201
void jack_transport_start(jack_client_t* client);
197202
void jack_transport_stop(jack_client_t* client);
198203
@@ -223,6 +228,35 @@
223228
#define EEXIST 17
224229
""")
225230

231+
# Packed structure
232+
_ffi.cdef("""
233+
struct _jack_position {
234+
jack_unique_t unique_1;
235+
jack_time_t usecs;
236+
jack_nframes_t frame_rate;
237+
jack_nframes_t frame;
238+
jack_position_bits_t valid;
239+
int32_t bar;
240+
int32_t beat;
241+
int32_t tick;
242+
double bar_start_tick;
243+
float beats_per_bar;
244+
float beat_type;
245+
double ticks_per_beat;
246+
double beats_per_minute;
247+
double frame_time;
248+
double next_time;
249+
jack_nframes_t bbt_offset;
250+
float audio_frames_per_video_frame;
251+
jack_nframes_t video_offset;
252+
int32_t padding[7];
253+
jack_unique_t unique_2;
254+
};
255+
typedef struct _jack_position jack_position_t;
256+
jack_transport_state_t jack_transport_query(const jack_client_t* client, jack_position_t* pos);
257+
int jack_transport_reposition(jack_client_t* client, const jack_position_t* pos);
258+
""", packed=True)
259+
226260
_lib = _ffi.dlopen("jack")
227261

228262
_AUDIO = b"32 bit float mono audio"
@@ -297,6 +331,7 @@ def __init__(self, name, use_exact_name=False, no_start_server=False,
297331
self._midi_inports = Ports(self, _MIDI, _lib.JackPortIsInput)
298332
self._midi_outports = Ports(self, _MIDI, _lib.JackPortIsOutput)
299333
self._keepalive = []
334+
self._position = _ffi.new("jack_position_t*")
300335

301336
# Avoid confusion if something goes wrong before opening the client:
302337
_ptr = _ffi.NULL
@@ -600,6 +635,54 @@ def transport_locate(self, frame):
600635
_check(_lib.jack_transport_locate(self._ptr, frame),
601636
"Error locating JACK transport")
602637

638+
def transport_query(self):
639+
"""return current transport state and position.
640+
641+
Return a tuple with current transport state and position informations
642+
643+
Transport state
644+
---------------
645+
Transport state can take following value :
646+
* 0 : Stopped
647+
* 1 : Rolling (playing)
648+
* 2 : Looping
649+
* 3 : Starting (preparing playback)
650+
* 4 : Net Starting
651+
652+
Position informations
653+
---------------------
654+
Position information are stored in CFFI object. This object have
655+
following attribute :
656+
* usecs : monotonic, free-rolling
657+
* frame_rate : current frame rate (per second)
658+
* frame : frame number (frame count since transport start)
659+
* valid : indicate which fields are present and valid (see below)
660+
* bar: current bar
661+
* beat: current beat-within-bar
662+
* tick: current tick-within-beat
663+
* bar_start_tick
664+
* bbt_offset : frame offset for the BBT fields (see below)
665+
* beats_per_bar : time signature "numerator"
666+
* beat_type : time signature "denominator"
667+
* ticks_per_beat : ticks per beat
668+
* beats_per_minute : current tempo (BPM)
669+
* frame_time : current time in seconds
670+
* next_time : next sequential frame_time (unless repositioned)
671+
* audio_frames_per_video_frame
672+
* video_offset
673+
674+
valid field is can take following values (bit flag) :
675+
* 0x10 : bar, beat, tick, bar_start_tick, beats_per_bar,
676+
beat_type, ticks_per_beat, beats_per_minute
677+
* 0x20 : frame_time, next_time
678+
* 0x40 : bbt_offset
679+
* 0x80 : audio_frames_per_video_frame
680+
* 0x100 : video_offset
681+
682+
"""
683+
transport_state = _lib.jack_transport_query(self._ptr, self._position)
684+
return transport_state, self._position
685+
603686
def set_freewheel(self, onoff):
604687
"""Start/Stop JACK's "freewheel" mode.
605688

0 commit comments

Comments
 (0)