JACK API headers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

529 lines
20KB

  1. /*
  2. Copyright (C) 2002 Paul Davis
  3. Copyright (C) 2003 Jack O'Quin
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __jack_transport_h__
  17. #define __jack_transport_h__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include <jack/types.h>
  22. #include <jack/weakmacros.h>
  23. /**
  24. * Transport states.
  25. */
  26. typedef enum {
  27. /* the order matters for binary compatibility */
  28. JackTransportStopped = 0, /**< Transport halted */
  29. JackTransportRolling = 1, /**< Transport playing */
  30. JackTransportLooping = 2, /**< For OLD_TRANSPORT, now ignored */
  31. JackTransportStarting = 3 /**< Waiting for sync ready */
  32. } jack_transport_state_t;
  33. typedef uint64_t jack_unique_t; /**< Unique ID (opaque) */
  34. /**
  35. * Optional struct jack_position_t fields.
  36. */
  37. typedef enum {
  38. JackPositionBBT = 0x10, /**< Bar, Beat, Tick */
  39. JackPositionTimecode = 0x20, /**< External timecode */
  40. JackBBTFrameOffset = 0x40, /**< Frame offset of BBT information */
  41. JackAudioVideoRatio = 0x80, /**< audio frames per video frame */
  42. JackVideoFrameOffset = 0x100 /**< frame offset of first video frame */
  43. } jack_position_bits_t;
  44. /** all valid position bits */
  45. #define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode|JackBBTFrameOffset|JackAudioVideoRatio|JackVideoFrameOffset)
  46. #define EXTENDED_TIME_INFO
  47. /**
  48. * Struct for transport position information.
  49. */
  50. typedef struct {
  51. /*@{*/
  52. /** @name Server-set fields
  53. * these cannot be set from clients; the server sets them */
  54. jack_unique_t unique_1; /**< unique ID */
  55. jack_time_t usecs; /**< microsecond timestamp that is guaranteed to be
  56. monotonic, but not neccessarily
  57. linear.
  58. The absolute value is
  59. implementation-dependent (i.e. it
  60. could be wall-clock, time since
  61. jack started, uptime, etc). */
  62. jack_nframes_t frame_rate; /**< current frame rate, in frames per second */
  63. /*}@*/
  64. /*@{*/
  65. /** @name Mandatory fields
  66. */
  67. jack_nframes_t frame; /**< frame number, always present/required.
  68. This is the frame number on the
  69. transport timeline, which is not
  70. the same as what @ref
  71. jack_frame_time returns. */
  72. jack_position_bits_t valid; /**< which other fields are valid, as a
  73. bitmask constructed from values in
  74. \ref jack_position_bits_t */
  75. /*}@*/
  76. /*@{*/
  77. /** @name JackPositionBBT fields
  78. * Bar:Beat.Tick-related information.
  79. *
  80. * Applications that support
  81. * JackPositionBBT are encouraged to also fill the JackBBTFrameOffset
  82. */
  83. int32_t bar; /**< current bar
  84. Should be >0: the first bar is
  85. bar '1'. */
  86. int32_t beat; /**< current beat-within-bar
  87. Should be >0 and <=beats_per_bar:
  88. the first beat is beat '1'.
  89. */
  90. int32_t tick; /**< current tick-within-beat
  91. Should be >0 and <=ticks_per_beat:
  92. the first tick is tick '0'. */
  93. double bar_start_tick; /**< number of ticks that have elapsed
  94. between frame 0 and the first beat
  95. of the current measure. */
  96. float beats_per_bar; /**< time signature "numerator" */
  97. float beat_type; /**< time signature "denominator" */
  98. double ticks_per_beat; /**< number of ticks within a bar.
  99. Usually a moderately large integer
  100. with many denominators, such as
  101. 1920.0 */
  102. double beats_per_minute; /**< BPM, quantized to block size. This
  103. means when the tempo is not constant
  104. within this block, the BPM value should
  105. adapted to compensate for this. This
  106. is different from most fields in this
  107. struct, which specify the value at
  108. the beginning of the block rather
  109. than an average.*/
  110. /*}@*/
  111. /*@{*/
  112. /** @name JackPositionTimecode fields
  113. * EXPERIMENTAL: could change */
  114. double frame_time; /**< current time in seconds */
  115. double next_time; /**< next sequential frame_time
  116. (unless repositioned) */
  117. /*}@*/
  118. /*@{*/
  119. /* JackBBTFrameOffset fields */
  120. jack_nframes_t bbt_offset; /**< frame offset for the BBT fields
  121. (the given bar, beat, and tick
  122. values actually refer to a time
  123. frame_offset frames before the
  124. start of the cycle), should
  125. be assumed to be 0 if
  126. JackBBTFrameOffset is not
  127. set. If JackBBTFrameOffset is
  128. set and this value is zero, the BBT
  129. time refers to the first frame of this
  130. cycle. If the value is positive,
  131. the BBT time refers to a frame that
  132. many frames before the start of the
  133. cycle. */
  134. /*}@*/
  135. /*@{*/
  136. /* JACK video positional data
  137. * EXPERIMENTAL: could change */
  138. float audio_frames_per_video_frame; /**< number of audio frames
  139. per video frame. Should be assumed
  140. zero if JackAudioVideoRatio is not
  141. set. If JackAudioVideoRatio is set
  142. and the value is zero, no video
  143. data exists within the JACK graph */
  144. jack_nframes_t video_offset; /**< audio frame at which the first video
  145. frame in this cycle occurs. Should
  146. be assumed to be 0 if JackVideoFrameOffset
  147. is not set. If JackVideoFrameOffset is
  148. set, but the value is zero, there is
  149. no video frame within this cycle. */
  150. /*}@*/
  151. /*@{*/
  152. /** @name Other fields */
  153. /* For binary compatibility, new fields should be allocated from
  154. * this padding area with new valid bits controlling access, so
  155. * the existing structure size and offsets are preserved. */
  156. int32_t padding[7];
  157. /*}@*/
  158. /* When (unique_1 == unique_2) the contents are consistent. */
  159. jack_unique_t unique_2; /**< unique ID */
  160. } POST_PACKED_STRUCTURE jack_position_t;
  161. /**
  162. * @defgroup TransportControl Transport and Timebase control
  163. * @{
  164. */
  165. /**
  166. * Called by the timebase master to release itself from that
  167. * responsibility.
  168. *
  169. * If the timebase master releases the timebase or leaves the JACK
  170. * graph for any reason, the JACK engine takes over at the start of
  171. * the next process cycle. The transport state does not change. If
  172. * rolling, it continues to play, with frame numbers as the only
  173. * available position information.
  174. *
  175. * @see jack_set_timebase_callback
  176. *
  177. * @param client the JACK client structure.
  178. *
  179. * @return 0 on success, otherwise a non-zero error code.
  180. */
  181. int jack_release_timebase (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  182. /**
  183. * Prototype for the @a sync_callback defined by @ref slowsyncclients
  184. * "slow-sync clients". When the client is active, this callback is
  185. * invoked just before process() in the same thread. This occurs once
  186. * after registration, then subsequently whenever some client requests
  187. * a new position, or the transport enters the ::JackTransportStarting
  188. * state. This realtime function must not wait.
  189. *
  190. * The transport @a state will be:
  191. *
  192. * - ::JackTransportStopped when a new position is requested;
  193. * - ::JackTransportStarting when the transport is waiting to start;
  194. * - ::JackTransportRolling when the timeout has expired, and the
  195. * position is now a moving target.
  196. *
  197. * @param state current transport state.
  198. * @param pos new transport position.
  199. * @param arg the argument supplied by jack_set_sync_callback().
  200. *
  201. * @return TRUE (non-zero) when ready to roll.
  202. */
  203. typedef int (*JackSyncCallback)(jack_transport_state_t state,
  204. jack_position_t *pos,
  205. void *arg);
  206. /**
  207. * Register (or unregister) as a @ref slowsyncclients "slow-sync client", that cannot
  208. * respond immediately to transport position changes.
  209. *
  210. * The @a sync_callback will be invoked at the first available
  211. * opportunity after its registration is complete. If the client is
  212. * currently active this will be the following process cycle,
  213. * otherwise it will be the first cycle after calling jack_activate().
  214. * After that, it runs according to the ::JackSyncCallback rules.
  215. * Clients that don't set a @a sync_callback are assumed to be ready
  216. * immediately any time the transport wants to start.
  217. *
  218. * @param client the JACK client structure.
  219. * @param sync_callback is a realtime function that returns TRUE when
  220. * the client is ready. Setting @a sync_callback to NULL declares that
  221. * this client no longer requires slow-sync processing.
  222. * @param arg an argument for the @a sync_callback function.
  223. *
  224. * @return 0 on success, otherwise a non-zero error code.
  225. */
  226. int jack_set_sync_callback (jack_client_t *client,
  227. JackSyncCallback sync_callback,
  228. void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  229. /**
  230. * Set the timeout value for @ref slowsyncclients "slow-sync clients".
  231. *
  232. * This timeout prevents unresponsive slow-sync clients from
  233. * completely halting the transport mechanism. The default is two
  234. * seconds. When the timeout expires, the transport starts rolling,
  235. * even if some slow-sync clients are still unready. The @a
  236. * sync_callbacks of these clients continue being invoked, giving them
  237. * a chance to catch up.
  238. *
  239. * @see jack_set_sync_callback
  240. *
  241. * @param client the JACK client structure.
  242. * @param timeout is delay (in microseconds) before the timeout expires.
  243. *
  244. * @return 0 on success, otherwise a non-zero error code.
  245. */
  246. int jack_set_sync_timeout (jack_client_t *client,
  247. jack_time_t timeout) JACK_OPTIONAL_WEAK_EXPORT;
  248. /**
  249. * Prototype for the @a timebase_callback used to provide extended
  250. * position information. Its output affects all of the following
  251. * process cycle. This realtime function must not wait.
  252. *
  253. * This function is called immediately after process() in the same
  254. * thread whenever the transport is rolling, or when any client has
  255. * requested a new position in the previous cycle. The first cycle
  256. * after jack_set_timebase_callback() is also treated as a new
  257. * position, or the first cycle after jack_activate() if the client
  258. * had been inactive.
  259. *
  260. * The timebase master may not use its @a pos argument to set @a
  261. * pos->frame. To change position, use jack_transport_reposition() or
  262. * jack_transport_locate(). These functions are realtime-safe, the @a
  263. * timebase_callback can call them directly.
  264. *
  265. * @param state current transport state.
  266. * @param nframes number of frames in current period.
  267. * @param pos address of the position structure for the next cycle; @a
  268. * pos->frame will be its frame number. If @a new_pos is FALSE, this
  269. * structure contains extended position information from the current
  270. * cycle. If TRUE, it contains whatever was set by the requester.
  271. * The @a timebase_callback's task is to update the extended
  272. * information here.
  273. * @param new_pos TRUE (non-zero) for a newly requested @a pos, or for
  274. * the first cycle after the @a timebase_callback is defined.
  275. * @param arg the argument supplied by jack_set_timebase_callback().
  276. */
  277. typedef void (*JackTimebaseCallback)(jack_transport_state_t state,
  278. jack_nframes_t nframes,
  279. jack_position_t *pos,
  280. int new_pos,
  281. void *arg);
  282. /**
  283. * Register as timebase master for the JACK subsystem.
  284. *
  285. * The timebase master registers a callback that updates extended
  286. * position information such as beats or timecode whenever necessary.
  287. * Without this extended information, there is no need for this
  288. * function.
  289. *
  290. * There is never more than one master at a time. When a new client
  291. * takes over, the former @a timebase_callback is no longer called.
  292. * Taking over the timebase may be done conditionally, so it fails if
  293. * there was a master already.
  294. *
  295. * The method may be called whether the client has been activated or not.
  296. *
  297. * @param client the JACK client structure.
  298. * @param conditional non-zero for a conditional request.
  299. * @param timebase_callback is a realtime function that returns
  300. * position information.
  301. * @param arg an argument for the @a timebase_callback function.
  302. *
  303. * @return
  304. * - 0 on success;
  305. * - EBUSY if a conditional request fails because there was already a
  306. * timebase master;
  307. * - other non-zero error code.
  308. */
  309. int jack_set_timebase_callback (jack_client_t *client,
  310. int conditional,
  311. JackTimebaseCallback timebase_callback,
  312. void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  313. /**
  314. * Reposition the transport to a new frame number.
  315. *
  316. * May be called at any time by any client. The new position takes
  317. * effect in two process cycles. If there are @ref slowsyncclients
  318. * "slow-sync clients" and the transport is already rolling, it will
  319. * enter the ::JackTransportStarting state and begin invoking their @a
  320. * sync_callbacks until ready. This function is realtime-safe.
  321. *
  322. * @see jack_transport_reposition, jack_set_sync_callback
  323. *
  324. * @param client the JACK client structure.
  325. * @param frame frame number of new transport position.
  326. *
  327. * @return 0 if valid request, non-zero otherwise.
  328. */
  329. int jack_transport_locate (jack_client_t *client,
  330. jack_nframes_t frame) JACK_OPTIONAL_WEAK_EXPORT;
  331. /**
  332. * Query the current transport state and position.
  333. *
  334. * This function is realtime-safe, and can be called from any thread.
  335. * If called from the process thread, @a pos corresponds to the first
  336. * frame of the current cycle and the state returned is valid for the
  337. * entire cycle.
  338. *
  339. * @param client the JACK client structure.
  340. * @param pos pointer to structure for returning current transport
  341. * position; @a pos->valid will show which fields contain valid data.
  342. * If @a pos is NULL, do not return position information.
  343. *
  344. * @return Current transport state.
  345. */
  346. jack_transport_state_t jack_transport_query (const jack_client_t *client,
  347. jack_position_t *pos) JACK_OPTIONAL_WEAK_EXPORT;
  348. /**
  349. * Return an estimate of the current transport frame,
  350. * including any time elapsed since the last transport
  351. * positional update.
  352. *
  353. * @param client the JACK client structure
  354. */
  355. jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  356. /**
  357. * Request a new transport position.
  358. *
  359. * May be called at any time by any client. The new position takes
  360. * effect in two process cycles. If there are @ref slowsyncclients
  361. * "slow-sync clients" and the transport is already rolling, it will
  362. * enter the ::JackTransportStarting state and begin invoking their @a
  363. * sync_callbacks until ready. This function is realtime-safe.
  364. *
  365. * @see jack_transport_locate, jack_set_sync_callback
  366. *
  367. * @param client the JACK client structure.
  368. * @param pos requested new transport position. Fill pos->valid to specify
  369. * which fields should be taken into account. If you mark a set of fields
  370. * as valid, you are expected to fill them all.
  371. *
  372. * @return 0 if valid request, EINVAL if position structure rejected.
  373. */
  374. int jack_transport_reposition (jack_client_t *client,
  375. const jack_position_t *pos) JACK_OPTIONAL_WEAK_EXPORT;
  376. /**
  377. * Start the JACK transport rolling.
  378. *
  379. * Any client can make this request at any time. It takes effect no
  380. * sooner than the next process cycle, perhaps later if there are
  381. * @ref slowsyncclients "slow-sync clients". This function is realtime-safe.
  382. *
  383. * @see jack_set_sync_callback
  384. *
  385. * @param client the JACK client structure.
  386. */
  387. void jack_transport_start (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  388. /**
  389. * Stop the JACK transport.
  390. *
  391. * Any client can make this request at any time. It takes effect on
  392. * the next process cycle. This function is realtime-safe.
  393. *
  394. * @param client the JACK client structure.
  395. */
  396. void jack_transport_stop (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  397. /*@}*/
  398. /*********************************************************************
  399. * The following interfaces are DEPRECATED. They are only provided
  400. * for compatibility with the earlier JACK transport implementation.
  401. *********************************************************************/
  402. /**
  403. * Optional struct jack_transport_info_t fields.
  404. *
  405. * @see jack_position_bits_t.
  406. */
  407. typedef enum {
  408. JackTransportState = 0x1, /**< Transport state */
  409. JackTransportPosition = 0x2, /**< Frame number */
  410. JackTransportLoop = 0x4, /**< Loop boundaries (ignored) */
  411. JackTransportSMPTE = 0x8, /**< SMPTE (ignored) */
  412. JackTransportBBT = 0x10 /**< Bar, Beat, Tick */
  413. } jack_transport_bits_t;
  414. /**
  415. * Deprecated struct for transport position information.
  416. *
  417. * @deprecated This is for compatibility with the earlier transport
  418. * interface. Use the jack_position_t struct, instead.
  419. */
  420. typedef struct {
  421. /* these two cannot be set from clients: the server sets them */
  422. jack_nframes_t frame_rate; /**< current frame rate (per second) */
  423. jack_time_t usecs; /**< monotonic, free-rolling */
  424. jack_transport_bits_t valid; /**< which fields are legal to read */
  425. jack_transport_state_t transport_state;
  426. jack_nframes_t frame;
  427. jack_nframes_t loop_start;
  428. jack_nframes_t loop_end;
  429. long smpte_offset; /**< SMPTE offset (from frame 0) */
  430. float smpte_frame_rate; /**< 29.97, 30, 24 etc. */
  431. int bar;
  432. int beat;
  433. int tick;
  434. double bar_start_tick;
  435. float beats_per_bar;
  436. float beat_type;
  437. double ticks_per_beat;
  438. double beats_per_minute;
  439. } jack_transport_info_t;
  440. /**
  441. * Gets the current transport info structure (deprecated).
  442. *
  443. * @param client the JACK client structure.
  444. * @param tinfo current transport info structure. The "valid" field
  445. * describes which fields contain valid data.
  446. *
  447. * @deprecated This is for compatibility with the earlier transport
  448. * interface. Use jack_transport_query(), instead.
  449. *
  450. * @pre Must be called from the process thread.
  451. */
  452. void jack_get_transport_info (jack_client_t *client,
  453. jack_transport_info_t *tinfo) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  454. /**
  455. * Set the transport info structure (deprecated).
  456. *
  457. * @deprecated This function still exists for compatibility with the
  458. * earlier transport interface, but it does nothing. Instead, define
  459. * a ::JackTimebaseCallback.
  460. */
  461. void jack_set_transport_info (jack_client_t *client,
  462. jack_transport_info_t *tinfo) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  463. #ifdef __cplusplus
  464. }
  465. #endif
  466. #endif /* __jack_transport_h__ */