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.

685 lines
23KB

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