jack1 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.

1035 lines
36KB

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