jack2 codebase
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.

640 lines
20KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004 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_types_h__
  17. #define __jack_types_h__
  18. #include <jack/systemdeps.h>
  19. typedef int32_t jack_shmsize_t;
  20. /**
  21. * Type used to represent sample frame counts.
  22. */
  23. typedef uint32_t jack_nframes_t;
  24. /**
  25. * Maximum value that can be stored in jack_nframes_t
  26. */
  27. #define JACK_MAX_FRAMES (4294967295U) /* This should be UINT32_MAX, but C++ has a problem with that. */
  28. /**
  29. * Type used to represent the value of free running
  30. * monotonic clock with units of microseconds.
  31. */
  32. typedef _jack_time_t jack_time_t;
  33. /**
  34. * Maximum size of @a load_init string passed to an internal client
  35. * jack_initialize() function via jack_internal_client_load().
  36. */
  37. #define JACK_LOAD_INIT_LIMIT 1024
  38. /**
  39. * jack_intclient_t is an opaque type representing a loaded internal
  40. * client. You may only access it using the API provided in @ref
  41. * intclient.h "<jack/intclient.h>".
  42. */
  43. typedef uint64_t jack_intclient_t;
  44. /**
  45. * jack_port_t is an opaque type. You may only access it using the
  46. * API provided.
  47. */
  48. typedef struct _jack_port jack_port_t;
  49. /**
  50. * jack_client_t is an opaque type. You may only access it using the
  51. * API provided.
  52. */
  53. typedef struct _jack_client jack_client_t;
  54. /**
  55. * Ports have unique ids. A port registration callback is the only
  56. * place you ever need to know their value.
  57. */
  58. #if defined(__x86_64__) || defined(__ppc64__)
  59. typedef uint64_t jack_port_id_t;
  60. #else
  61. typedef uint32_t jack_port_id_t;
  62. #endif
  63. typedef uint32_t jack_port_type_id_t;
  64. /**
  65. * Prototype for the client supplied function that is called
  66. * by the engine anytime there is work to be done.
  67. *
  68. * @pre nframes == jack_get_buffer_size()
  69. * @pre nframes == pow(2,x)
  70. *
  71. * @param nframes number of frames to process
  72. * @param arg pointer to a client supplied structure
  73. *
  74. * @return zero on success, non-zero on error
  75. */
  76. typedef int (*JackProcessCallback)(jack_nframes_t nframes, void *arg);
  77. /**
  78. * Prototype for the client thread routine called
  79. * by the engine when the client is inserted in the graph.
  80. *
  81. * @param arg pointer to a client supplied structure
  82. *
  83. */
  84. typedef void *(*JackThreadCallback)(void* arg);
  85. /**
  86. * Prototype for the client supplied function that is called
  87. * once after the creation of the thread in which other
  88. * callbacks will be made. Special thread characteristics
  89. * can be set from this callback, for example. This is a
  90. * highly specialized callback and most clients will not
  91. * and should not use it.
  92. *
  93. * @param arg pointer to a client supplied structure
  94. *
  95. * @return void
  96. */
  97. typedef void (*JackThreadInitCallback)(void *arg);
  98. /**
  99. * Prototype for the client supplied function that is called
  100. * whenever the processing graph is reordered.
  101. *
  102. * @param arg pointer to a client supplied structure
  103. *
  104. * @return zero on success, non-zero on error
  105. */
  106. typedef int (*JackGraphOrderCallback)(void *arg);
  107. /**
  108. * Prototype for the client-supplied function that is called whenever
  109. * an xrun has occured.
  110. *
  111. * @see jack_get_xrun_delayed_usecs()
  112. *
  113. * @param arg pointer to a client supplied structure
  114. *
  115. * @return zero on success, non-zero on error
  116. */
  117. typedef int (*JackXRunCallback)(void *arg);
  118. /**
  119. * Prototype for the @a bufsize_callback that is invoked whenever the
  120. * JACK engine buffer size changes. Although this function is called
  121. * in the JACK process thread, the normal process cycle is suspended
  122. * during its operation, causing a gap in the audio flow. So, the @a
  123. * bufsize_callback can allocate storage, touch memory not previously
  124. * referenced, and perform other operations that are not realtime
  125. * safe.
  126. *
  127. * @param nframes buffer size
  128. * @param arg pointer supplied by jack_set_buffer_size_callback().
  129. *
  130. * @return zero on success, non-zero on error
  131. */
  132. typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void *arg);
  133. /**
  134. * Prototype for the client supplied function that is called
  135. * when the engine sample rate changes.
  136. *
  137. * @param nframes new engine sample rate
  138. * @param arg pointer to a client supplied structure
  139. *
  140. * @return zero on success, non-zero on error
  141. */
  142. typedef int (*JackSampleRateCallback)(jack_nframes_t nframes, void *arg);
  143. /**
  144. * Prototype for the client supplied function that is called
  145. * whenever a port is registered or unregistered.
  146. *
  147. * @param arg pointer to a client supplied structure
  148. */
  149. typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int, void *arg);
  150. /**
  151. * Prototype for the client supplied function that is called
  152. * whenever a client is registered or unregistered.
  153. *
  154. * @param name a null-terminated string containing the client name
  155. * @param register non-zero if the client is being registered,
  156. * zero if the client is being unregistered
  157. * @param arg pointer to a client supplied structure
  158. */
  159. typedef void (*JackClientRegistrationCallback)(const char* name, int val, void *arg);
  160. /**
  161. * Prototype for the client supplied function that is called
  162. * whenever a client is registered or unregistered.
  163. *
  164. * @param a one of two ports connected or disconnected
  165. * @param b one of two ports connected or disconnected
  166. * @param connect non-zero if ports were connected
  167. * zero if ports were disconnected
  168. * @param arg pointer to a client supplied data
  169. */
  170. typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
  171. /**
  172. * Prototype for the client supplied function that is called
  173. * whenever the port name has been changed.
  174. *
  175. * @param port the port that has been renamed
  176. * @param new_name the new name
  177. * @param arg pointer to a client supplied structure
  178. *
  179. * @return zero on success, non-zero on error
  180. */
  181. typedef int (*JackPortRenameCallback)(jack_port_id_t port, const char* new_name, void *arg);
  182. /**
  183. * Prototype for the client supplied function that is called
  184. * whenever jackd starts or stops freewheeling.
  185. *
  186. * @param starting non-zero if we start starting to freewheel, zero otherwise
  187. * @param arg pointer to a client supplied structure
  188. */
  189. typedef void (*JackFreewheelCallback)(int starting, void *arg);
  190. /**
  191. * Used for the type argument of jack_port_register() for default
  192. * audio ports and midi ports.
  193. */
  194. #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
  195. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  196. /**
  197. * For convenience, use this typedef if you want to be able to change
  198. * between float and double. You may want to typedef sample_t to
  199. * jack_default_audio_sample_t in your application.
  200. */
  201. typedef float jack_default_audio_sample_t;
  202. /**
  203. * A port has a set of flags that are formed by AND-ing together the
  204. * desired values from the list below. The flags "JackPortIsInput" and
  205. * "JackPortIsOutput" are mutually exclusive and it is an error to use
  206. * them both.
  207. */
  208. enum JackPortFlags {
  209. /**
  210. * if JackPortIsInput is set, then the port can receive
  211. * data.
  212. */
  213. JackPortIsInput = 0x1,
  214. /**
  215. * if JackPortIsOutput is set, then data can be read from
  216. * the port.
  217. */
  218. JackPortIsOutput = 0x2,
  219. /**
  220. * if JackPortIsPhysical is set, then the port corresponds
  221. * to some kind of physical I/O connector.
  222. */
  223. JackPortIsPhysical = 0x4,
  224. /**
  225. * if JackPortCanMonitor is set, then a call to
  226. * jack_port_request_monitor() makes sense.
  227. *
  228. * Precisely what this means is dependent on the client. A typical
  229. * result of it being called with TRUE as the second argument is
  230. * that data that would be available from an output port (with
  231. * JackPortIsPhysical set) is sent to a physical output connector
  232. * as well, so that it can be heard/seen/whatever.
  233. *
  234. * Clients that do not control physical interfaces
  235. * should never create ports with this bit set.
  236. */
  237. JackPortCanMonitor = 0x8,
  238. /**
  239. * JackPortIsTerminal means:
  240. *
  241. * for an input port: the data received by the port
  242. * will not be passed on or made
  243. * available at any other port
  244. *
  245. * for an output port: the data available at the port
  246. * does not originate from any other port
  247. *
  248. * Audio synthesizers, I/O hardware interface clients, HDR
  249. * systems are examples of clients that would set this flag for
  250. * their ports.
  251. */
  252. JackPortIsTerminal = 0x10
  253. };
  254. /**
  255. * @ref jack_options_t bits
  256. */
  257. enum JackOptions {
  258. /**
  259. * Null value to use when no option bits are needed.
  260. */
  261. JackNullOption = 0x00,
  262. /**
  263. * Do not automatically start the JACK server when it is not
  264. * already running. This option is always selected if
  265. * \$JACK_NO_START_SERVER is defined in the calling process
  266. * environment.
  267. */
  268. JackNoStartServer = 0x01,
  269. /**
  270. * Use the exact client name requested. Otherwise, JACK
  271. * automatically generates a unique one, if needed.
  272. */
  273. JackUseExactName = 0x02,
  274. /**
  275. * Open with optional <em>(char *) server_name</em> parameter.
  276. */
  277. JackServerName = 0x04,
  278. /**
  279. * Load internal client from optional <em>(char *)
  280. * load_name</em>. Otherwise use the @a client_name.
  281. */
  282. JackLoadName = 0x08,
  283. /**
  284. * Pass optional <em>(char *) load_init</em> string to the
  285. * jack_initialize() entry point of an internal client.
  286. */
  287. JackLoadInit = 0x10
  288. };
  289. /** Valid options for opening an external client. */
  290. #define JackOpenOptions (JackServerName|JackNoStartServer|JackUseExactName)
  291. /** Valid options for loading an internal client. */
  292. #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
  293. /**
  294. * Options for several JACK operations, formed by OR-ing together the
  295. * relevant @ref JackOptions bits.
  296. */
  297. typedef enum JackOptions jack_options_t;
  298. /**
  299. * @ref jack_status_t bits
  300. */
  301. enum JackStatus {
  302. /**
  303. * Overall operation failed.
  304. */
  305. JackFailure = 0x01,
  306. /**
  307. * The operation contained an invalid or unsupported option.
  308. */
  309. JackInvalidOption = 0x02,
  310. /**
  311. * The desired client name was not unique. With the @ref
  312. * JackUseExactName option this situation is fatal. Otherwise,
  313. * the name was modified by appending a dash and a two-digit
  314. * number in the range "-01" to "-99". The
  315. * jack_get_client_name() function will return the exact string
  316. * that was used. If the specified @a client_name plus these
  317. * extra characters would be too long, the open fails instead.
  318. */
  319. JackNameNotUnique = 0x04,
  320. /**
  321. * The JACK server was started as a result of this operation.
  322. * Otherwise, it was running already. In either case the caller
  323. * is now connected to jackd, so there is no race condition.
  324. * When the server shuts down, the client will find out.
  325. */
  326. JackServerStarted = 0x08,
  327. /**
  328. * Unable to connect to the JACK server.
  329. */
  330. JackServerFailed = 0x10,
  331. /**
  332. * Communication error with the JACK server.
  333. */
  334. JackServerError = 0x20,
  335. /**
  336. * Requested client does not exist.
  337. */
  338. JackNoSuchClient = 0x40,
  339. /**
  340. * Unable to load internal client
  341. */
  342. JackLoadFailure = 0x80,
  343. /**
  344. * Unable to initialize client
  345. */
  346. JackInitFailure = 0x100,
  347. /**
  348. * Unable to access shared memory
  349. */
  350. JackShmFailure = 0x200,
  351. /**
  352. * Client's protocol version does not match
  353. */
  354. JackVersionError = 0x400
  355. };
  356. /**
  357. * Status word returned from several JACK operations, formed by
  358. * OR-ing together the relevant @ref JackStatus bits.
  359. */
  360. typedef enum JackStatus jack_status_t;
  361. /**
  362. * Transport states.
  363. */
  364. typedef enum {
  365. /* the order matters for binary compatibility */
  366. JackTransportStopped = 0, /**< Transport halted */
  367. JackTransportRolling = 1, /**< Transport playing */
  368. JackTransportLooping = 2, /**< For OLD_TRANSPORT, now ignored */
  369. JackTransportStarting = 3, /**< Waiting for sync ready */
  370. JackTransportNetStarting = 4, /**< Waiting for sync ready on the network*/
  371. } jack_transport_state_t;
  372. typedef uint64_t jack_unique_t; /**< Unique ID (opaque) */
  373. /**
  374. * Optional struct jack_position_t fields.
  375. */
  376. typedef enum {
  377. JackPositionBBT = 0x10, /**< Bar, Beat, Tick */
  378. JackPositionTimecode = 0x20, /**< External timecode */
  379. JackBBTFrameOffset = 0x40, /**< Frame offset of BBT information */
  380. JackAudioVideoRatio = 0x80, /**< audio frames per video frame */
  381. JackVideoFrameOffset = 0x100 /**< frame offset of first video frame */
  382. } jack_position_bits_t;
  383. /** all valid position bits */
  384. #define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode)
  385. #define EXTENDED_TIME_INFO
  386. typedef struct {
  387. /* these four cannot be set from clients: the server sets them */
  388. jack_unique_t unique_1; /**< unique ID */
  389. jack_time_t usecs; /**< monotonic, free-rolling */
  390. jack_nframes_t frame_rate; /**< current frame rate (per second) */
  391. jack_nframes_t frame; /**< frame number, always present */
  392. jack_position_bits_t valid; /**< which other fields are valid */
  393. /* JackPositionBBT fields: */
  394. int32_t bar; /**< current bar */
  395. int32_t beat; /**< current beat-within-bar */
  396. int32_t tick; /**< current tick-within-beat */
  397. double bar_start_tick;
  398. float beats_per_bar; /**< time signature "numerator" */
  399. float beat_type; /**< time signature "denominator" */
  400. double ticks_per_beat;
  401. double beats_per_minute;
  402. /* JackPositionTimecode fields: (EXPERIMENTAL: could change) */
  403. double frame_time; /**< current time in seconds */
  404. double next_time; /**< next sequential frame_time
  405. (unless repositioned) */
  406. /* JackBBTFrameOffset fields: */
  407. jack_nframes_t bbt_offset; /**< frame offset for the BBT fields
  408. (the given bar, beat, and tick
  409. values actually refer to a time
  410. frame_offset frames before the
  411. start of the cycle), should
  412. be assumed to be 0 if
  413. JackBBTFrameOffset is not
  414. set. If JackBBTFrameOffset is
  415. set and this value is zero, the BBT
  416. time refers to the first frame of this
  417. cycle. If the value is positive,
  418. the BBT time refers to a frame that
  419. many frames before the start of the
  420. cycle. */
  421. /* JACK video positional data (experimental) */
  422. float audio_frames_per_video_frame; /**< number of audio frames
  423. per video frame. Should be assumed
  424. zero if JackAudioVideoRatio is not
  425. set. If JackAudioVideoRatio is set
  426. and the value is zero, no video
  427. data exists within the JACK graph */
  428. jack_nframes_t video_offset; /**< audio frame at which the first video
  429. frame in this cycle occurs. Should
  430. be assumed to be 0 if JackVideoFrameOffset
  431. is not set. If JackVideoFrameOffset is
  432. set, but the value is zero, there is
  433. no video frame within this cycle. */
  434. /* For binary compatibility, new fields should be allocated from
  435. * this padding area with new valid bits controlling access, so
  436. * the existing structure size and offsets are preserved. */
  437. int32_t padding[7];
  438. /* When (unique_1 == unique_2) the contents are consistent. */
  439. jack_unique_t unique_2; /**< unique ID */
  440. } jack_position_t;
  441. /**
  442. * Prototype for the @a sync_callback defined by slow-sync clients.
  443. * When the client is active, this callback is invoked just before
  444. * process() in the same thread. This occurs once after registration,
  445. * then subsequently whenever some client requests a new position, or
  446. * the transport enters the ::JackTransportStarting state. This
  447. * realtime function must not wait.
  448. *
  449. * The transport @a state will be:
  450. *
  451. * - ::JackTransportStopped when a new position is requested;
  452. * - ::JackTransportStarting when the transport is waiting to start;
  453. * - ::JackTransportRolling when the timeout has expired, and the
  454. * position is now a moving target.
  455. *
  456. * @param state current transport state.
  457. * @param pos new transport position.
  458. * @param arg the argument supplied by jack_set_sync_callback().
  459. *
  460. * @return TRUE (non-zero) when ready to roll.
  461. */
  462. typedef int (*JackSyncCallback)(jack_transport_state_t state,
  463. jack_position_t *pos,
  464. void *arg);
  465. /**
  466. * Prototype for the @a timebase_callback used to provide extended
  467. * position information. Its output affects all of the following
  468. * process cycle. This realtime function must not wait.
  469. *
  470. * This function is called immediately after process() in the same
  471. * thread whenever the transport is rolling, or when any client has
  472. * requested a new position in the previous cycle. The first cycle
  473. * after jack_set_timebase_callback() is also treated as a new
  474. * position, or the first cycle after jack_activate() if the client
  475. * had been inactive.
  476. *
  477. * The timebase master may not use its @a pos argument to set @a
  478. * pos->frame. To change position, use jack_transport_reposition() or
  479. * jack_transport_locate(). These functions are realtime-safe, the @a
  480. * timebase_callback can call them directly.
  481. *
  482. * @param state current transport state.
  483. * @param nframes number of frames in current period.
  484. * @param pos address of the position structure for the next cycle; @a
  485. * pos->frame will be its frame number. If @a new_pos is FALSE, this
  486. * structure contains extended position information from the current
  487. * cycle. If TRUE, it contains whatever was set by the requester.
  488. * The @a timebase_callback's task is to update the extended
  489. * information here.
  490. * @param new_pos TRUE (non-zero) for a newly requested @a pos, or for
  491. * the first cycle after the @a timebase_callback is defined.
  492. * @param arg the argument supplied by jack_set_timebase_callback().
  493. */
  494. typedef void (*JackTimebaseCallback)(jack_transport_state_t state,
  495. jack_nframes_t nframes,
  496. jack_position_t *pos,
  497. int new_pos,
  498. void *arg);
  499. /*********************************************************************
  500. * The following interfaces are DEPRECATED. They are only provided
  501. * for compatibility with the earlier JACK transport implementation.
  502. *********************************************************************/
  503. /**
  504. * Optional struct jack_transport_info_t fields.
  505. *
  506. * @see jack_position_bits_t.
  507. */
  508. typedef enum {
  509. JackTransportState = 0x1, /**< Transport state */
  510. JackTransportPosition = 0x2, /**< Frame number */
  511. JackTransportLoop = 0x4, /**< Loop boundaries (ignored) */
  512. JackTransportSMPTE = 0x8, /**< SMPTE (ignored) */
  513. JackTransportBBT = 0x10 /**< Bar, Beat, Tick */
  514. } jack_transport_bits_t;
  515. /**
  516. * Deprecated struct for transport position information.
  517. *
  518. * @deprecated This is for compatibility with the earlier transport
  519. * interface. Use the jack_position_t struct, instead.
  520. */
  521. typedef struct {
  522. /* these two cannot be set from clients: the server sets them */
  523. jack_nframes_t frame_rate; /**< current frame rate (per second) */
  524. jack_time_t usecs; /**< monotonic, free-rolling */
  525. jack_transport_bits_t valid; /**< which fields are legal to read */
  526. jack_transport_state_t transport_state;
  527. jack_nframes_t frame;
  528. jack_nframes_t loop_start;
  529. jack_nframes_t loop_end;
  530. long smpte_offset; /**< SMPTE offset (from frame 0) */
  531. float smpte_frame_rate; /**< 29.97, 30, 24 etc. */
  532. int bar;
  533. int beat;
  534. int tick;
  535. double bar_start_tick;
  536. float beats_per_bar;
  537. float beat_type;
  538. double ticks_per_beat;
  539. double beats_per_minute;
  540. }
  541. jack_transport_info_t;
  542. #endif /* __jack_types_h__ */