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.

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