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.

1031 lines
38KB

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