|
34 | 34 |
|
35 | 35 | typedef uint64_t jack_uuid_t; |
36 | 36 | typedef uint32_t jack_nframes_t; |
37 | | -/* TODO: jack_time_t */ |
| 37 | +typedef uint64_t jack_time_t; |
38 | 38 | typedef struct _jack_port jack_port_t; |
39 | 39 | typedef struct _jack_client jack_client_t; |
40 | 40 | typedef uint32_t jack_port_id_t; |
|
92 | 92 | JackTransportStarting = 3, |
93 | 93 | JackTransportNetStarting = 4, |
94 | 94 | } 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; |
96 | 103 |
|
97 | 104 | /* jack.h */ |
98 | 105 |
|
|
190 | 197 | /* transport.h */ |
191 | 198 |
|
192 | 199 | 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); |
194 | 200 | 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); |
196 | 201 | void jack_transport_start(jack_client_t* client); |
197 | 202 | void jack_transport_stop(jack_client_t* client); |
198 | 203 |
|
|
223 | 228 | #define EEXIST 17 |
224 | 229 | """) |
225 | 230 |
|
| 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 | + |
226 | 260 | _lib = _ffi.dlopen("jack") |
227 | 261 |
|
228 | 262 | _AUDIO = b"32 bit float mono audio" |
@@ -297,6 +331,7 @@ def __init__(self, name, use_exact_name=False, no_start_server=False, |
297 | 331 | self._midi_inports = Ports(self, _MIDI, _lib.JackPortIsInput) |
298 | 332 | self._midi_outports = Ports(self, _MIDI, _lib.JackPortIsOutput) |
299 | 333 | self._keepalive = [] |
| 334 | + self._position = _ffi.new("jack_position_t*") |
300 | 335 |
|
301 | 336 | # Avoid confusion if something goes wrong before opening the client: |
302 | 337 | _ptr = _ffi.NULL |
@@ -600,6 +635,54 @@ def transport_locate(self, frame): |
600 | 635 | _check(_lib.jack_transport_locate(self._ptr, frame), |
601 | 636 | "Error locating JACK transport") |
602 | 637 |
|
| 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 | + |
603 | 686 | def set_freewheel(self, onoff): |
604 | 687 | """Start/Stop JACK's "freewheel" mode. |
605 | 688 |
|
|
0 commit comments