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.

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