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.

1227 lines
44KB

  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_h__
  17. #define __jack_h__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include <jack/types.h>
  22. #include <jack/transport.h>
  23. /**
  24. * Note: More documentation can be found in jack/types.h.
  25. */
  26. /*************************************************************
  27. * NOTE: JACK_WEAK_EXPORT ***MUST*** be used on every function
  28. * added to the JACK API after the 0.116.2 release.
  29. *
  30. * Functions that predate this release are marked with
  31. * JACK_WEAK_OPTIONAL_EXPORT which can be defined at compile
  32. * time in a variety of ways. The default definition is empty,
  33. * so that these symbols get normal linkage. If you wish to
  34. * use all JACK symbols with weak linkage, include
  35. * <jack/weakjack.h> before jack.h.
  36. *************************************************************/
  37. #include <jack/weakmacros.h>
  38. /**
  39. * @defgroup ClientFunctions Creating & manipulating clients
  40. * @{
  41. */
  42. /**
  43. * Open an external client session with a JACK server. This interface
  44. * is more complex but more powerful than jack_client_new(). With it,
  45. * clients may choose which of several servers to connect, and control
  46. * whether and how to start the server automatically, if it was not
  47. * already running. There is also an option for JACK to generate a
  48. * unique client name, when necessary.
  49. *
  50. * @param client_name of at most jack_client_name_size() characters.
  51. * The name scope is local to each server. Unless forbidden by the
  52. * @ref JackUseExactName option, the server will modify this name to
  53. * create a unique variant, if needed.
  54. *
  55. * @param options formed by OR-ing together @ref JackOptions bits.
  56. * Only the @ref JackOpenOptions bits are allowed.
  57. *
  58. * @param status (if non-NULL) an address for JACK to return
  59. * information from the open operation. This status word is formed by
  60. * OR-ing together the relevant @ref JackStatus bits.
  61. *
  62. *
  63. * <b>Optional parameters:</b> depending on corresponding [@a options
  64. * bits] additional parameters may follow @a status (in this order).
  65. *
  66. * @arg [@ref JackServerName] <em>(char *) server_name</em> selects
  67. * from among several possible concurrent server instances. Server
  68. * names are unique to each user. If unspecified, use "default"
  69. * unless \$JACK_DEFAULT_SERVER is defined in the process environment.
  70. *
  71. * @return Opaque client handle if successful. If this is NULL, the
  72. * open operation failed, @a *status includes @ref JackFailure and the
  73. * caller is not a JACK client.
  74. */
  75. jack_client_t *jack_client_open (const char *client_name,
  76. jack_options_t options,
  77. jack_status_t *status, ...) JACK_OPTIONAL_WEAK_EXPORT;
  78. /**
  79. * <b>THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED IN
  80. * NEW JACK CLIENTS</b>
  81. *
  82. */
  83. jack_client_t *jack_client_new (const char *client_name) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  84. /**
  85. * Disconnects an external client from a JACK server.
  86. *
  87. * @return 0 on success, otherwise a non-zero error code
  88. */
  89. int jack_client_close (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  90. /**
  91. * @return the maximum number of characters in a JACK client name
  92. * including the final NULL character. This value is a constant.
  93. */
  94. int jack_client_name_size (void) JACK_OPTIONAL_WEAK_EXPORT;
  95. /**
  96. * @return pointer to actual client name. This is useful when @ref
  97. * JackUseExactName is not specified on open and @ref
  98. * JackNameNotUnique status was returned. In that case, the actual
  99. * name will differ from the @a client_name requested.
  100. */
  101. char *jack_get_client_name (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  102. /**
  103. * Load an internal client into the Jack server.
  104. *
  105. * Internal clients run inside the JACK server process. They can use
  106. * most of the same functions as external clients. Each internal
  107. * client must declare jack_initialize() and jack_finish() entry
  108. * points, called at load and unload times. See inprocess.c for an
  109. * example of how to write an internal client.
  110. *
  111. * @deprecated Please use jack_internal_client_load().
  112. *
  113. * @param client_name of at most jack_client_name_size() characters.
  114. *
  115. * @param load_name of a shared object file containing the code for
  116. * the new client.
  117. *
  118. * @param load_init an arbitary string passed to the jack_initialize()
  119. * routine of the new client (may be NULL).
  120. *
  121. * @return 0 if successful.
  122. */
  123. int jack_internal_client_new (const char *client_name,
  124. const char *load_name,
  125. const char *load_init) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  126. /**
  127. * Remove an internal client from a JACK server.
  128. *
  129. * @deprecated Please use jack_internal_client_load().
  130. */
  131. void jack_internal_client_close (const char *client_name) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  132. /**
  133. * Tell the Jack server that the program is ready to start processing
  134. * audio.
  135. *
  136. * @return 0 on success, otherwise a non-zero error code
  137. */
  138. int jack_activate (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  139. /**
  140. * Tell the Jack server to remove this @a client from the process
  141. * graph. Also, disconnect all ports belonging to it, since inactive
  142. * clients have no port connections.
  143. *
  144. * @return 0 on success, otherwise a non-zero error code
  145. */
  146. int jack_deactivate (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  147. /**
  148. * @return the pthread ID of the thread running the JACK client side
  149. * code.
  150. */
  151. jack_native_thread_t jack_client_thread_id (jack_client_t *) JACK_OPTIONAL_WEAK_EXPORT;
  152. /*@}*/
  153. /**
  154. * @param client pointer to JACK client structure.
  155. *
  156. * Check if the JACK subsystem is running with -R (--realtime).
  157. *
  158. * @return 1 if JACK is running realtime, 0 otherwise
  159. */
  160. int jack_is_realtime (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  161. /**
  162. * @defgroup NonCallbackAPI The non-callback API
  163. * @{
  164. */
  165. /**
  166. * <b>THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED IN
  167. * NEW JACK CLIENTS</b>
  168. *
  169. * It should be replace by use of @ jack_cycle_wait and @ jack_cycle_signal functions.
  170. *
  171. */
  172. jack_nframes_t jack_thread_wait (jack_client_t*, int status) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  173. /**
  174. * Wait until this JACK client should process data.
  175. *
  176. * @param client - pointer to a JACK client structure
  177. *
  178. * @return the number of frames of data to process
  179. */
  180. jack_nframes_t jack_cycle_wait (jack_client_t* client) JACK_OPTIONAL_WEAK_EXPORT;
  181. /**
  182. * Signal next clients in the graph.
  183. *
  184. * @param client - pointer to a JACK client structure
  185. * @param status - if non-zero, calling thread should exit
  186. */
  187. void jack_cycle_signal (jack_client_t* client, int status) JACK_OPTIONAL_WEAK_EXPORT;
  188. /**
  189. * Tell the Jack server to call @a thread_callback in the RT thread.
  190. * Typical use are in conjunction with @a jack_cycle_wait and @ jack_cycle_signal functions.
  191. * The code in the supplied function must be suitable for real-time
  192. * execution. That means that it cannot call functions that might
  193. * block for a long time. This includes all I/O functions (disk, TTY, network),
  194. * malloc, free, printf, pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
  195. * pthread_cond_wait, etc, etc.
  196. *
  197. * @return 0 on success, otherwise a non-zero error code.
  198. */
  199. int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  200. /*@}*/
  201. /**
  202. * @defgroup ClientCallbacks Setting Client Callbacks
  203. * @{
  204. */
  205. /**
  206. * Tell JACK to call @a thread_init_callback once just after
  207. * the creation of the thread in which all other callbacks
  208. * will be handled.
  209. *
  210. * The code in the supplied function does not need to be
  211. * suitable for real-time execution.
  212. *
  213. * @return 0 on success, otherwise a non-zero error code, causing JACK
  214. * to remove that client from the process() graph.
  215. */
  216. int jack_set_thread_init_callback (jack_client_t *client,
  217. JackThreadInitCallback thread_init_callback,
  218. void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  219. /**
  220. * @param client pointer to JACK client structure.
  221. * @param function The jack_shutdown function pointer.
  222. * @param arg The arguments for the jack_shutdown function.
  223. *
  224. * Register a function (and argument) to be called if and when the
  225. * JACK server shuts down the client thread. The function must
  226. * be written as if it were an asynchonrous POSIX signal
  227. * handler --- use only async-safe functions, and remember that it
  228. * is executed from another thread. A typical function might
  229. * set a flag or write to a pipe so that the rest of the
  230. * application knows that the JACK client thread has shut
  231. * down.
  232. *
  233. * NOTE: clients do not need to call this. It exists only
  234. * to help more complex clients understand what is going
  235. * on. It should be called before jack_client_activate().
  236. *
  237. * NOTE: if a client calls this AND jack_on_info_shutdown(), then
  238. * the event of a client thread shutdown, the callback
  239. * passed to this function will not be called, and the one passed to
  240. * jack_on_info_shutdown() will.
  241. */
  242. void jack_on_shutdown (jack_client_t *client,
  243. JackShutdownCallback function, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  244. /**
  245. * @param client pointer to JACK client structure.
  246. * @param function The jack_shutdown function pointer.
  247. * @param arg The arguments for the jack_shutdown function.
  248. *
  249. * Register a function (and argument) to be called if and when the
  250. * JACK server shuts down the client thread. The function must
  251. * be written as if it were an asynchonrous POSIX signal
  252. * handler --- use only async-safe functions, and remember that it
  253. * is executed from another thread. A typical function might
  254. * set a flag or write to a pipe so that the rest of the
  255. * application knows that the JACK client thread has shut
  256. * down.
  257. *
  258. * NOTE: clients do not need to call this. It exists only
  259. * to help more complex clients understand what is going
  260. * on. It should be called before jack_client_activate().
  261. *
  262. * NOTE: if a client calls this AND jack_on_shutdown(), then in the
  263. * event of a client thread shutdown, the callback passed to
  264. * this function will be called, and the one passed to
  265. * jack_on_shutdown() will not.
  266. */
  267. void jack_on_info_shutdown (jack_client_t *client,
  268. JackInfoShutdownCallback function, void *arg) JACK_WEAK_EXPORT;
  269. /**
  270. * Tell the Jack server to call @a process_callback whenever there is
  271. * work be done, passing @a arg as the second argument.
  272. *
  273. * The code in the supplied function must be suitable for real-time
  274. * execution. That means that it cannot call functions that might
  275. * block for a long time. This includes all I/O functions (disk, TTY, network),
  276. * malloc, free, printf, pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
  277. * pthread_cond_wait, etc, etc.
  278. *
  279. * @return 0 on success, otherwise a non-zero error code, causing JACK
  280. * to remove that client from the process() graph.
  281. */
  282. int jack_set_process_callback (jack_client_t *client,
  283. JackProcessCallback process_callback,
  284. void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  285. /**
  286. * Tell the Jack server to call @a freewheel_callback
  287. * whenever we enter or leave "freewheel" mode, passing @a
  288. * arg as the second argument. The first argument to the
  289. * callback will be non-zero if JACK is entering freewheel
  290. * mode, and zero otherwise.
  291. *
  292. * @return 0 on success, otherwise a non-zero error code.
  293. */
  294. int jack_set_freewheel_callback (jack_client_t *client,
  295. JackFreewheelCallback freewheel_callback,
  296. void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  297. /**
  298. * Tell JACK to call @a bufsize_callback whenever the size of the the
  299. * buffer that will be passed to the @a process_callback is about to
  300. * change. Clients that depend on knowing the buffer size must supply
  301. * a @a bufsize_callback before activating themselves.
  302. *
  303. * @param client pointer to JACK client structure.
  304. * @param bufsize_callback function to call when the buffer size changes.
  305. * @param arg argument for @a bufsize_callback.
  306. *
  307. * @return 0 on success, otherwise a non-zero error code
  308. */
  309. int jack_set_buffer_size_callback (jack_client_t *client,
  310. JackBufferSizeCallback bufsize_callback,
  311. void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  312. /**
  313. * Tell the Jack server to call @a srate_callback whenever the system
  314. * sample rate changes.
  315. *
  316. * @return 0 on success, otherwise a non-zero error code
  317. */
  318. int jack_set_sample_rate_callback (jack_client_t *client,
  319. JackSampleRateCallback srate_callback,
  320. void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  321. /**
  322. * Tell the JACK server to call @a registration_callback whenever a
  323. * port is registered or unregistered, passing @a arg as a parameter.
  324. *
  325. * @return 0 on success, otherwise a non-zero error code
  326. */
  327. int jack_set_client_registration_callback (jack_client_t *,
  328. JackClientRegistrationCallback
  329. registration_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  330. /**
  331. * Tell the JACK server to call @a registration_callback whenever a
  332. * port is registered or unregistered, passing @a arg as a parameter.
  333. *
  334. * @return 0 on success, otherwise a non-zero error code
  335. */
  336. int jack_set_port_registration_callback (jack_client_t *,
  337. JackPortRegistrationCallback
  338. registration_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  339. /**
  340. * Tell the JACK server to call @a connect_callback whenever a
  341. * port is connected or disconnected, passing @a arg as a parameter.
  342. *
  343. * @return 0 on success, otherwise a non-zero error code
  344. */
  345. int jack_set_port_connect_callback (jack_client_t *,
  346. JackPortConnectCallback
  347. connect_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  348. /**
  349. * Tell the JACK server to call @a graph_callback whenever the
  350. * processing graph is reordered, passing @a arg as a parameter.
  351. *
  352. * @return 0 on success, otherwise a non-zero error code
  353. */
  354. int jack_set_graph_order_callback (jack_client_t *,
  355. JackGraphOrderCallback graph_callback,
  356. void *) JACK_OPTIONAL_WEAK_EXPORT;
  357. /**
  358. * Tell the JACK server to call @a xrun_callback whenever there is a
  359. * xrun, passing @a arg as a parameter.
  360. *
  361. * @return 0 on success, otherwise a non-zero error code
  362. */
  363. int jack_set_xrun_callback (jack_client_t *,
  364. JackXRunCallback xrun_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
  365. /**
  366. * Tell the Jack server to call @a latency_callback whenever it
  367. * is necessary to recompute the latencies for some or all
  368. * Jack ports.
  369. *
  370. * @a latency_callback will be called twice each time it is
  371. * needed, once being passed JackCaptureLatency and once
  372. * JackPlaybackLatency. See @ref LatencyFunctions for
  373. * the definition of each type of latency and related functions.
  374. *
  375. * <b>IMPORTANT: Most JACK clients do NOT need to register a latency
  376. * callback.</b>
  377. *
  378. * Clients that meet any of the following conditions do NOT
  379. * need to register a latency callback:
  380. *
  381. * - have only input ports
  382. * - have only output ports
  383. * - their output is totally unrelated to their input
  384. * - their output is not delayed relative to their input
  385. * (i.e. data that arrives in a given process()
  386. * callback is processed and output again in the
  387. * same callback)
  388. *
  389. * Clients NOT registering a latency callback MUST also
  390. * satisfy this condition:
  391. *
  392. * - have no multiple distinct internal signal pathways
  393. *
  394. * This means that if your client has more than 1 input and
  395. * output port, and considers them always "correlated"
  396. * (e.g. as a stereo pair), then there is only 1 (e.g. stereo)
  397. * signal pathway through the client. This would be true,
  398. * for example, of a stereo FX rack client that has a
  399. * left/right input pair and a left/right output pair.
  400. *
  401. * However, this is somewhat a matter of perspective. The
  402. * same FX rack client could be connected so that its
  403. * two input ports were connected to entirely separate
  404. * sources. Under these conditions, the fact that the client
  405. * does not register a latency callback MAY result
  406. * in port latency values being incorrect.
  407. *
  408. * Clients that do not meet any of those conditions SHOULD
  409. * register a latency callback.
  410. *
  411. * See the documentation for @ref jack_port_set_latency_range()
  412. * on how the callback should operate. Remember that the @a mode
  413. * argument given to the latency callback will need to be
  414. * passed into @ref jack_port_set_latency_range()
  415. *
  416. * @return 0 on success, otherwise a non-zero error code
  417. */
  418. int jack_set_latency_callback (jack_client_t *,
  419. JackLatencyCallback latency_callback,
  420. void *) JACK_WEAK_EXPORT;
  421. /*@}*/
  422. /**
  423. * @defgroup ServerControl Controlling & querying JACK server operation
  424. * @{
  425. */
  426. /**
  427. * Start/Stop JACK's "freewheel" mode.
  428. *
  429. * When in "freewheel" mode, JACK no longer waits for
  430. * any external event to begin the start of the next process
  431. * cycle.
  432. *
  433. * As a result, freewheel mode causes "faster than realtime"
  434. * execution of a JACK graph. If possessed, real-time
  435. * scheduling is dropped when entering freewheel mode, and
  436. * if appropriate it is reacquired when stopping.
  437. *
  438. * IMPORTANT: on systems using capabilities to provide real-time
  439. * scheduling (i.e. Linux kernel 2.4), if onoff is zero, this function
  440. * must be called from the thread that originally called jack_activate().
  441. * This restriction does not apply to other systems (e.g. Linux kernel 2.6
  442. * or OS X).
  443. *
  444. * @param client pointer to JACK client structure
  445. * @param onoff if non-zero, freewheel mode starts. Otherwise
  446. * freewheel mode ends.
  447. *
  448. * @return 0 on success, otherwise a non-zero error code.
  449. */
  450. int jack_set_freewheel(jack_client_t* client, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  451. /**
  452. * Change the buffer size passed to the @a process_callback.
  453. *
  454. * This operation stops the JACK engine process cycle, then calls all
  455. * registered @a bufsize_callback functions before restarting the
  456. * process cycle. This will cause a gap in the audio flow, so it
  457. * should only be done at appropriate stopping points.
  458. *
  459. * @see jack_set_buffer_size_callback()
  460. *
  461. * @param client pointer to JACK client structure.
  462. * @param nframes new buffer size. Must be a power of two.
  463. *
  464. * @return 0 on success, otherwise a non-zero error code
  465. */
  466. int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes) JACK_OPTIONAL_WEAK_EXPORT;
  467. /**
  468. * @return the sample rate of the jack system, as set by the user when
  469. * jackd was started.
  470. */
  471. jack_nframes_t jack_get_sample_rate (jack_client_t *) JACK_OPTIONAL_WEAK_EXPORT;
  472. /**
  473. * @return the current maximum size that will ever be passed to the @a
  474. * process_callback. It should only be used *before* the client has
  475. * been activated. This size may change, clients that depend on it
  476. * must register a @a bufsize_callback so they will be notified if it
  477. * does.
  478. *
  479. * @see jack_set_buffer_size_callback()
  480. */
  481. jack_nframes_t jack_get_buffer_size (jack_client_t *) JACK_OPTIONAL_WEAK_EXPORT;
  482. /**
  483. * Old-style interface to become the timebase for the entire JACK
  484. * subsystem.
  485. *
  486. * @deprecated This function still exists for compatibility with the
  487. * earlier transport interface, but it does nothing. Instead, see
  488. * transport.h and use jack_set_timebase_callback().
  489. *
  490. * @return ENOSYS, function not implemented.
  491. */
  492. int jack_engine_takeover_timebase (jack_client_t *) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  493. /**
  494. * @return the current CPU load estimated by JACK. This is a running
  495. * average of the time it takes to execute a full process cycle for
  496. * all clients as a percentage of the real time available per cycle
  497. * determined by the buffer size and sample rate.
  498. */
  499. float jack_cpu_load (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  500. /*@}*/
  501. /**
  502. * @defgroup PortFunctions Creating & manipulating ports
  503. * @{
  504. */
  505. /**
  506. * Create a new port for the client. This is an object used for moving
  507. * data of any type in or out of the client. Ports may be connected
  508. * in various ways.
  509. *
  510. * Each port has a short name. The port's full name contains the name
  511. * of the client concatenated with a colon (:) followed by its short
  512. * name. The jack_port_name_size() is the maximum length of this full
  513. * name. Exceeding that will cause the port registration to fail and
  514. * return NULL.
  515. *
  516. * The @a port_name must be unique among all ports owned by this client.
  517. * If the name is not unique, the registration will fail.
  518. *
  519. * All ports have a type, which may be any non-NULL and non-zero
  520. * length string, passed as an argument. Some port types are built
  521. * into the JACK API, like JACK_DEFAULT_AUDIO_TYPE or JACK_DEFAULT_MIDI_TYPE
  522. *
  523. * @param client pointer to JACK client structure.
  524. * @param port_name non-empty short name for the new port (not
  525. * including the leading @a "client_name:"). Must be unique.
  526. * @param port_type port type name. If longer than
  527. * jack_port_type_size(), only that many characters are significant.
  528. * @param flags @ref JackPortFlags bit mask.
  529. * @param buffer_size must be non-zero if this is not a built-in @a
  530. * port_type. Otherwise, it is ignored.
  531. *
  532. * @return jack_port_t pointer on success, otherwise NULL.
  533. */
  534. jack_port_t *jack_port_register (jack_client_t *client,
  535. const char *port_name,
  536. const char *port_type,
  537. unsigned long flags,
  538. unsigned long buffer_size) JACK_OPTIONAL_WEAK_EXPORT;
  539. /**
  540. * Remove the port from the client, disconnecting any existing
  541. * connections.
  542. *
  543. * @return 0 on success, otherwise a non-zero error code
  544. */
  545. int jack_port_unregister (jack_client_t *, jack_port_t *) JACK_OPTIONAL_WEAK_EXPORT;
  546. /**
  547. * This returns a pointer to the memory area associated with the
  548. * specified port. For an output port, it will be a memory area
  549. * that can be written to; for an input port, it will be an area
  550. * containing the data from the port's connection(s), or
  551. * zero-filled. if there are multiple inbound connections, the data
  552. * will be mixed appropriately.
  553. *
  554. * Do not cache the returned address across process() callbacks.
  555. * Port buffers have to be retrieved in each callback for proper functionning.
  556. */
  557. void *jack_port_get_buffer (jack_port_t *, jack_nframes_t) JACK_OPTIONAL_WEAK_EXPORT;
  558. /**
  559. * @return the full name of the jack_port_t (including the @a
  560. * "client_name:" prefix).
  561. *
  562. * @see jack_port_name_size().
  563. */
  564. const char *jack_port_name (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  565. /**
  566. * @return the short name of the jack_port_t (not including the @a
  567. * "client_name:" prefix).
  568. *
  569. * @see jack_port_name_size().
  570. */
  571. const char *jack_port_short_name (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  572. /**
  573. * @return the @ref JackPortFlags of the jack_port_t.
  574. */
  575. int jack_port_flags (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  576. /**
  577. * @return the @a port type, at most jack_port_type_size() characters
  578. * including a final NULL.
  579. */
  580. const char *jack_port_type (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  581. /**
  582. * @return TRUE if the jack_port_t belongs to the jack_client_t.
  583. */
  584. int jack_port_is_mine (const jack_client_t *, const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  585. /**
  586. * @return number of connections to or from @a port.
  587. *
  588. * @pre The calling client must own @a port.
  589. */
  590. int jack_port_connected (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  591. /**
  592. * @return TRUE if the locally-owned @a port is @b directly connected
  593. * to the @a port_name.
  594. *
  595. * @see jack_port_name_size()
  596. */
  597. int jack_port_connected_to (const jack_port_t *port,
  598. const char *port_name) JACK_OPTIONAL_WEAK_EXPORT;
  599. /**
  600. * @return a null-terminated array of full port names to which the @a
  601. * port is connected. If none, returns NULL.
  602. *
  603. * The caller is responsible for calling jack_free(3) on any non-NULL
  604. * returned value.
  605. *
  606. * @param port locally owned jack_port_t pointer.
  607. *
  608. * @see jack_port_name_size(), jack_port_get_all_connections()
  609. */
  610. const char **jack_port_get_connections (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  611. /**
  612. * @return a null-terminated array of full port names to which the @a
  613. * port is connected. If none, returns NULL.
  614. *
  615. * The caller is responsible for calling jack_free(3) on any non-NULL
  616. * returned value.
  617. *
  618. * This differs from jack_port_get_connections() in two important
  619. * respects:
  620. *
  621. * 1) You may not call this function from code that is
  622. * executed in response to a JACK event. For example,
  623. * you cannot use it in a GraphReordered handler.
  624. *
  625. * 2) You need not be the owner of the port to get information
  626. * about its connections.
  627. *
  628. * @see jack_port_name_size()
  629. */
  630. const char **jack_port_get_all_connections (const jack_client_t *client,
  631. const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  632. /**
  633. *
  634. * @deprecated This function will be removed from a future version
  635. * of JACK. Do not use it. There is no replacement. It has
  636. * turned out to serve essentially no purpose in real-life
  637. * JACK clients.
  638. */
  639. int jack_port_tie (jack_port_t *src, jack_port_t *dst) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  640. /**
  641. *
  642. * @deprecated This function will be removed from a future version
  643. * of JACK. Do not use it. There is no replacement. It has
  644. * turned out to serve essentially no purpose in real-life
  645. * JACK clients.
  646. */
  647. int jack_port_untie (jack_port_t *port) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  648. /**
  649. * Modify a port's short name. May be called at any time. If the
  650. * resulting full name (including the @a "client_name:" prefix) is
  651. * longer than jack_port_name_size(), it will be truncated.
  652. *
  653. * @return 0 on success, otherwise a non-zero error code.
  654. */
  655. int jack_port_set_name (jack_port_t *port, const char *port_name) JACK_OPTIONAL_WEAK_EXPORT;
  656. /**
  657. * Set @a alias as an alias for @a port. May be called at any time.
  658. * If the alias is longer than jack_port_name_size(), it will be truncated.
  659. *
  660. * After a successful call, and until JACK exits or
  661. * jack_port_unset_alias() is called, may be
  662. * used as a alternate name for the port.
  663. *
  664. * Ports can have up to two aliases - if both are already
  665. * set, this function will return an error.
  666. *
  667. * @return 0 on success, otherwise a non-zero error code.
  668. */
  669. int jack_port_set_alias (jack_port_t *port, const char *alias) JACK_OPTIONAL_WEAK_EXPORT;
  670. /**
  671. * Remove @a alias as an alias for @a port. May be called at any time.
  672. *
  673. * After a successful call, @a alias can no longer be
  674. * used as a alternate name for the port.
  675. *
  676. * @return 0 on success, otherwise a non-zero error code.
  677. */
  678. int jack_port_unset_alias (jack_port_t *port, const char *alias) JACK_OPTIONAL_WEAK_EXPORT;
  679. /*
  680. * Get any aliases known for @port.
  681. *
  682. * @return the number of aliases discovered for the port
  683. */
  684. int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]) JACK_OPTIONAL_WEAK_EXPORT;
  685. /**
  686. * If @ref JackPortCanMonitor is set for this @a port, turn input
  687. * monitoring on or off. Otherwise, do nothing.
  688. */
  689. int jack_port_request_monitor (jack_port_t *port, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  690. /**
  691. * If @ref JackPortCanMonitor is set for this @a port_name, turn input
  692. * monitoring on or off. Otherwise, do nothing.
  693. *
  694. * @return 0 on success, otherwise a non-zero error code.
  695. *
  696. * @see jack_port_name_size()
  697. */
  698. int jack_port_request_monitor_by_name (jack_client_t *client,
  699. const char *port_name, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  700. /**
  701. * If @ref JackPortCanMonitor is set for a port, this function turns
  702. * on input monitoring if it was off, and turns it off if only one
  703. * request has been made to turn it on. Otherwise it does nothing.
  704. *
  705. * @return 0 on success, otherwise a non-zero error code
  706. */
  707. int jack_port_ensure_monitor (jack_port_t *port, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  708. /**
  709. * @return TRUE if input monitoring has been requested for @a port.
  710. */
  711. int jack_port_monitoring_input (jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  712. /**
  713. * Establish a connection between two ports.
  714. *
  715. * When a connection exists, data written to the source port will
  716. * be available to be read at the destination port.
  717. *
  718. * @pre The port types must be identical.
  719. *
  720. * @pre The @ref JackPortFlags of the @a source_port must include @ref
  721. * JackPortIsOutput.
  722. *
  723. * @pre The @ref JackPortFlags of the @a destination_port must include
  724. * @ref JackPortIsInput.
  725. *
  726. * @return 0 on success, EEXIST if the connection is already made,
  727. * otherwise a non-zero error code
  728. */
  729. int jack_connect (jack_client_t *,
  730. const char *source_port,
  731. const char *destination_port) JACK_OPTIONAL_WEAK_EXPORT;
  732. /**
  733. * Remove a connection between two ports.
  734. *
  735. * @pre The port types must be identical.
  736. *
  737. * @pre The @ref JackPortFlags of the @a source_port must include @ref
  738. * JackPortIsOutput.
  739. *
  740. * @pre The @ref JackPortFlags of the @a destination_port must include
  741. * @ref JackPortIsInput.
  742. *
  743. * @return 0 on success, otherwise a non-zero error code
  744. */
  745. int jack_disconnect (jack_client_t *,
  746. const char *source_port,
  747. const char *destination_port) JACK_OPTIONAL_WEAK_EXPORT;
  748. /**
  749. * Perform the same function as jack_disconnect() using port handles
  750. * rather than names. This avoids the name lookup inherent in the
  751. * name-based version.
  752. *
  753. * Clients connecting their own ports are likely to use this function,
  754. * while generic connection clients (e.g. patchbays) would use
  755. * jack_disconnect().
  756. */
  757. int jack_port_disconnect (jack_client_t *, jack_port_t *) JACK_OPTIONAL_WEAK_EXPORT;
  758. /**
  759. * @return the maximum number of characters in a full JACK port name
  760. * including the final NULL character. This value is a constant.
  761. *
  762. * A port's full name contains the owning client name concatenated
  763. * with a colon (:) followed by its short name and a NULL
  764. * character.
  765. */
  766. int jack_port_name_size(void) JACK_OPTIONAL_WEAK_EXPORT;
  767. /**
  768. * @return the maximum number of characters in a JACK port type name
  769. * including the final NULL character. This value is a constant.
  770. */
  771. int jack_port_type_size(void) JACK_OPTIONAL_WEAK_EXPORT;
  772. /**
  773. * @return the buffersize of a port of type @arg port_type.
  774. *
  775. * this function may only be called in a buffer_size callback.
  776. */
  777. size_t jack_port_type_get_buffer_size (jack_client_t *client, const char *port_type) JACK_WEAK_EXPORT;
  778. /*@}*/
  779. /**
  780. * @defgroup LatencyFunctions Managing and determining latency
  781. *
  782. * The purpose of JACK's latency API is to allow clients to
  783. * easily answer two questions:
  784. *
  785. * - How long has it been since the data read from a port arrived
  786. * at the edge of the JACK graph (either via a physical port
  787. * or being synthesized from scratch)?
  788. *
  789. * - How long will it be before the data written to a port arrives
  790. * at the edge of a JACK graph?
  791. * To help answering these two questions, all JACK ports have two
  792. * latency values associated with them, both measured in frames:
  793. *
  794. * <b>capture latency</b>: how long since the data read from
  795. * the buffer of a port arrived at at
  796. * a port marked with JackPortIsTerminal.
  797. * The data will have come from the "outside
  798. * world" if the terminal port is also
  799. * marked with JackPortIsPhysical, or
  800. * will have been synthesized by the client
  801. * that owns the terminal port.
  802. *
  803. * <b>playback latency</b>: how long until the data
  804. * written to the buffer of port will reach a port
  805. * marked with JackPortIsTerminal.
  806. *
  807. * Both latencies might potentially have more than one value
  808. * because there may be multiple pathways to/from a given port
  809. * and a terminal port. Latency is therefore generally
  810. * expressed a min/max pair.
  811. *
  812. * In most common setups, the minimum and maximum latency
  813. * are the same, but this design accomodates more complex
  814. * routing, and allows applications (and thus users) to
  815. * detect cases where routing is creating an anomalous
  816. * situation that may either need fixing or more
  817. * sophisticated handling by clients that care about
  818. * latency.
  819. *
  820. * See also @ref jack_set_latency_callback for details on how
  821. * clients that add latency to the signal path should interact
  822. * with JACK to ensure that the correct latency figures are
  823. * used.
  824. * @{
  825. */
  826. /**
  827. * The port latency is zero by default. Clients that control
  828. * physical hardware with non-zero latency should call this
  829. * to set the latency to its correct value. Note that the value
  830. * should include any systemic latency present "outside" the
  831. * physical hardware controlled by the client. For example,
  832. * for a client controlling a digital audio interface connected
  833. * to an external digital converter, the latency setting should
  834. * include both buffering by the audio interface *and* the converter.
  835. *
  836. * @deprecated This method will be removed in the next major
  837. * release of JACK. It should not be used in new code, and should
  838. * be replaced by a latency callback that calls @ref
  839. * jack_port_set_latency_range().
  840. */
  841. void jack_port_set_latency (jack_port_t *, jack_nframes_t) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  842. /**
  843. * return the latency range defined by @a mode for
  844. * @a port, in frames.
  845. *
  846. * See @ref LatencyFunctions for the definition of each latency value.
  847. *
  848. * This is normally used in the LatencyCallback.
  849. * and therefor safe to execute from callbacks.
  850. */
  851. void jack_port_get_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range) JACK_WEAK_EXPORT;
  852. /**
  853. * set the minimum and maximum latencies defined by
  854. * @a mode for @a port, in frames.
  855. *
  856. * See @ref LatencyFunctions for the definition of each latency value.
  857. *
  858. * This function should ONLY be used inside a latency
  859. * callback. The client should determine the current
  860. * value of the latency using @ref jack_port_get_latency_range()
  861. * (called using the same mode as @a mode)
  862. * and then add some number of frames to that reflects
  863. * latency added by the client.
  864. *
  865. * How much latency a client adds will vary
  866. * dramatically. For most clients, the answer is zero
  867. * and there is no reason for them to register a latency
  868. * callback and thus they should never call this
  869. * function.
  870. *
  871. * More complex clients that take an input signal,
  872. * transform it in some way and output the result but
  873. * not during the same process() callback will
  874. * generally know a single constant value to add
  875. * to the value returned by @ref jack_port_get_latency_range().
  876. *
  877. * Such clients would register a latency callback (see
  878. * @ref jack_set_latency_callback) and must know what input
  879. * ports feed which output ports as part of their
  880. * internal state. Their latency callback will update
  881. * the ports' latency values appropriately.
  882. *
  883. * A pseudo-code example will help. The @a mode argument to the latency
  884. * callback will determine whether playback or capture
  885. * latency is being set. The callback will use
  886. * @ref jack_port_set_latency_range() as follows:
  887. *
  888. * \code
  889. * jack_latency_range_t range;
  890. * if (mode == JackPlaybackLatency) {
  891. * foreach input_port in (all self-registered port) {
  892. * jack_port_get_latency_range (port_feeding_input_port, JackPlaybackLatency, &range);
  893. * range.min += min_delay_added_as_signal_flows_from port_feeding to input_port;
  894. * range.max += max_delay_added_as_signal_flows_from port_feeding to input_port;
  895. * jack_port_set_latency_range (input_port, JackPlaybackLatency, &range);
  896. * }
  897. * } else if (mode == JackCaptureLatency) {
  898. * foreach output_port in (all self-registered port) {
  899. * jack_port_get_latency_range (port_fed_by_output_port, JackCaptureLatency, &range);
  900. * range.min += min_delay_added_as_signal_flows_from_output_port_to_fed_by_port;
  901. * range.max += max_delay_added_as_signal_flows_from_output_port_to_fed_by_port;
  902. * jack_port_set_latency_range (output_port, JackCaptureLatency, &range);
  903. * }
  904. * }
  905. * \endcode
  906. *
  907. * In this relatively simple pseudo-code example, it is assumed that
  908. * each input port or output is connected to only 1 output or input
  909. * port respectively.
  910. *
  911. * If a port is connected to more than 1 other port, then the
  912. * range.min and range.max values passed to @ref
  913. * jack_port_set_latency_range() should reflect the minimum and
  914. * maximum values across all connected ports.
  915. *
  916. * See the description of @ref jack_set_latency_callback for more
  917. * information.
  918. */
  919. void jack_port_set_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range) JACK_WEAK_EXPORT;
  920. /**
  921. * Request a complete recomputation of all port latencies. This
  922. * can be called by a client that has just changed the internal
  923. * latency of its port using jack_port_set_latency
  924. * and wants to ensure that all signal pathways in the graph
  925. * are updated with respect to the values that will be returned
  926. * by jack_port_get_total_latency. It allows a client
  927. * to change multiple port latencies without triggering a
  928. * recompute for each change.
  929. *
  930. * @return zero for successful execution of the request. non-zero
  931. * otherwise.
  932. */
  933. int jack_recompute_total_latencies (jack_client_t*) JACK_OPTIONAL_WEAK_EXPORT;
  934. /**
  935. * @return the time (in frames) between data being available or
  936. * delivered at/to a port, and the time at which it arrived at or is
  937. * delivered to the "other side" of the port. E.g. for a physical
  938. * audio output port, this is the time between writing to the port and
  939. * when the signal will leave the connector. For a physical audio
  940. * input port, this is the time between the sound arriving at the
  941. * connector and the corresponding frames being readable from the
  942. * port.
  943. *
  944. * @deprecated This method will be removed in the next major
  945. * release of JACK. It should not be used in new code, and should
  946. * be replaced by jack_port_get_latency_range() in any existing
  947. * use cases.
  948. */
  949. jack_nframes_t jack_port_get_latency (jack_port_t *port) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  950. /**
  951. * The maximum of the sum of the latencies in every
  952. * connection path that can be drawn between the port and other
  953. * ports with the @ref JackPortIsTerminal flag set.
  954. *
  955. * @deprecated This method will be removed in the next major
  956. * release of JACK. It should not be used in new code, and should
  957. * be replaced by jack_port_get_latency_range() in any existing
  958. * use cases.
  959. */
  960. jack_nframes_t jack_port_get_total_latency (jack_client_t *,
  961. jack_port_t *port) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  962. /**
  963. * Request a complete recomputation of a port's total latency. This
  964. * can be called by a client that has just changed the internal
  965. * latency of its port using jack_port_set_latency
  966. * and wants to ensure that all signal pathways in the graph
  967. * are updated with respect to the values that will be returned
  968. * by jack_port_get_total_latency.
  969. *
  970. * @return zero for successful execution of the request. non-zero
  971. * otherwise.
  972. *
  973. * @deprecated This method will be removed in the next major
  974. * release of JACK. It should not be used in new code, and should
  975. * be replaced by jack_recompute_total_latencies() in any existing
  976. * use cases.
  977. */
  978. int jack_recompute_total_latency (jack_client_t*, jack_port_t* port) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  979. /*@}*/
  980. /**
  981. * @defgroup PortSearching Looking up ports
  982. * @{
  983. */
  984. /**
  985. * @param port_name_pattern A regular expression used to select
  986. * ports by name. If NULL or of zero length, no selection based
  987. * on name will be carried out.
  988. * @param type_name_pattern A regular expression used to select
  989. * ports by type. If NULL or of zero length, no selection based
  990. * on type will be carried out.
  991. * @param flags A value used to select ports by their flags.
  992. * If zero, no selection based on flags will be carried out.
  993. *
  994. * @return a NULL-terminated array of ports that match the specified
  995. * arguments. The caller is responsible for calling jack_free(3) any
  996. * non-NULL returned value.
  997. *
  998. * @see jack_port_name_size(), jack_port_type_size()
  999. */
  1000. const char **jack_get_ports (jack_client_t *,
  1001. const char *port_name_pattern,
  1002. const char *type_name_pattern,
  1003. unsigned long flags) JACK_OPTIONAL_WEAK_EXPORT;
  1004. /**
  1005. * @return address of the jack_port_t named @a port_name.
  1006. *
  1007. * @see jack_port_name_size()
  1008. */
  1009. jack_port_t *jack_port_by_name (jack_client_t *, const char *port_name) JACK_OPTIONAL_WEAK_EXPORT;
  1010. /**
  1011. * @return address of the jack_port_t of a @a port_id.
  1012. */
  1013. jack_port_t *jack_port_by_id (jack_client_t *client,
  1014. jack_port_id_t port_id) JACK_OPTIONAL_WEAK_EXPORT;
  1015. /*@}*/
  1016. /**
  1017. * @defgroup TimeFunctions Handling time
  1018. * @{
  1019. *
  1020. * JACK time is in units of 'frames', according to the current sample rate.
  1021. * The absolute value of frame times is meaningless, frame times have meaning
  1022. * only relative to each other.
  1023. */
  1024. /**
  1025. * @return the estimated time in frames that has passed since the JACK
  1026. * server began the current process cycle.
  1027. */
  1028. jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *) JACK_OPTIONAL_WEAK_EXPORT;
  1029. /**
  1030. * @return the estimated current time in frames.
  1031. * This function is intended for use in other threads (not the process
  1032. * callback). The return value can be compared with the value of
  1033. * jack_last_frame_time to relate time in other threads to JACK time.
  1034. */
  1035. jack_nframes_t jack_frame_time (const jack_client_t *) JACK_OPTIONAL_WEAK_EXPORT;
  1036. /**
  1037. * @return the precise time at the start of the current process cycle.
  1038. * This function may only be used from the process callback, and can
  1039. * be used to interpret timestamps generated by jack_frame_time() in
  1040. * other threads with respect to the current process cycle.
  1041. *
  1042. * This is the only jack time function that returns exact time:
  1043. * when used during the process callback it always returns the same
  1044. * value (until the next process callback, where it will return
  1045. * that value + nframes, etc). The return value is guaranteed to be
  1046. * monotonic and linear in this fashion unless an xrun occurs.
  1047. * If an xrun occurs, clients must check this value again, as time
  1048. * may have advanced in a non-linear way (e.g. cycles may have been skipped).
  1049. */
  1050. jack_nframes_t jack_last_frame_time (const jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
  1051. /**
  1052. * @return the estimated time in microseconds of the specified frame time
  1053. */
  1054. jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t) JACK_OPTIONAL_WEAK_EXPORT;
  1055. /**
  1056. * @return the estimated time in frames for the specified system time.
  1057. */
  1058. jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t) JACK_OPTIONAL_WEAK_EXPORT;
  1059. /**
  1060. * @return return JACK's current system time in microseconds,
  1061. * using the JACK clock source.
  1062. *
  1063. * The value returned is guaranteed to be monotonic, but not linear.
  1064. */
  1065. jack_time_t jack_get_time() JACK_OPTIONAL_WEAK_EXPORT;
  1066. /*@}*/
  1067. /**
  1068. * @defgroup ErrorOutput Controlling error/information output
  1069. */
  1070. /*@{*/
  1071. /**
  1072. * Display JACK error message.
  1073. *
  1074. * Set via jack_set_error_function(), otherwise a JACK-provided
  1075. * default will print @a msg (plus a newline) to stderr.
  1076. *
  1077. * @param msg error message text (no newline at end).
  1078. */
  1079. extern void (*jack_error_callback)(const char *msg) JACK_OPTIONAL_WEAK_EXPORT;
  1080. /**
  1081. * Set the @ref jack_error_callback for error message display.
  1082. *
  1083. * The JACK library provides two built-in callbacks for this purpose:
  1084. * default_jack_error_callback() and silent_jack_error_callback().
  1085. */
  1086. void jack_set_error_function (void (*func)(const char *)) JACK_OPTIONAL_WEAK_EXPORT;
  1087. /**
  1088. * Display JACK info message.
  1089. *
  1090. * Set via jack_set_info_function(), otherwise a JACK-provided
  1091. * default will print @a msg (plus a newline) to stdout.
  1092. *
  1093. * @param msg info message text (no newline at end).
  1094. */
  1095. extern void (*jack_info_callback)(const char *msg) JACK_OPTIONAL_WEAK_EXPORT;
  1096. /**
  1097. * Set the @ref jack_info_callback for info message display.
  1098. */
  1099. void jack_set_info_function (void (*func)(const char *)) JACK_OPTIONAL_WEAK_EXPORT;
  1100. /*@}*/
  1101. /**
  1102. * The free function to be used on memory returned by jack_port_get_connections,
  1103. * jack_port_get_all_connections and jack_get_ports functions.
  1104. * This is MANDATORY on Windows when otherwise all nasty runtime version related crashes can occur.
  1105. * Developers are strongly encouraged to use this function instead of the standard "free" function in new code.
  1106. *
  1107. */
  1108. void jack_free(void* ptr) JACK_OPTIONAL_WEAK_EXPORT;
  1109. #ifdef __cplusplus
  1110. }
  1111. #endif
  1112. #endif /* __jack_h__ */