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.

1146 lines
41KB

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