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.

1027 lines
33KB

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