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.

1134 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. * NOTE: if a client calls this AND jack_on_info_shutdown(), then
  266. * the event of a client thread shutdown, the callback
  267. * passed to this function will not be called, and the one passed to
  268. * jack_on_info_shutdown() will.
  269. */
  270. void jack_on_shutdown (jack_client_t *client,
  271. JackShutdownCallback shutdown_callback, void *arg);
  272. /**
  273. * @param client pointer to JACK client structure.
  274. * @param function The jack_info_shutdown function pointer.
  275. * @param arg The arguments for the jack_info_shutdown function.
  276. *
  277. * Register a function (and argument) to be called if and when the
  278. * JACK server shuts down the client thread. The function must
  279. * be written as if it were an asynchonrous POSIX signal
  280. * handler --- use only async-safe functions, and remember that it
  281. * is executed from another thread. A typical function might
  282. * set a flag or write to a pipe so that the rest of the
  283. * application knows that the JACK client thread has shut
  284. * down.
  285. *
  286. * NOTE: clients do not need to call this. It exists only
  287. * to help more complex clients understand what is going
  288. * on. It should be called before jack_client_activate().
  289. *
  290. * NOTE: if a client calls this AND jack_on_info_shutdown(), then
  291. * the event of a client thread shutdown, the callback
  292. * passed to this function will not be called, and the one passed to
  293. * jack_on_info_shutdown() will.
  294. */
  295. void jack_on_info_shutdown (jack_client_t *client,
  296. JackInfoShutdownCallback shutdown_callback, void *arg);
  297. /**
  298. * Tell the Jack server to call @a process_callback whenever there is
  299. * work be done, passing @a arg as the second argument.
  300. *
  301. * The code in the supplied function must be suitable for real-time
  302. * execution. That means that it cannot call functions that might
  303. * block for a long time. This includes malloc, free, printf,
  304. * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
  305. * pthread_cond_wait, etc, etc. See
  306. * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
  307. * for more information.
  308. *
  309. * NOTE: this function cannot be called while the client is activated
  310. * (after jack_activate has been called.)
  311. *
  312. * @return 0 on success, otherwise a non-zero error code.
  313. */
  314. int jack_set_process_callback (jack_client_t *client,
  315. JackProcessCallback process_callback,
  316. void *arg);
  317. /**
  318. * Tell the Jack server to call @a freewheel_callback
  319. * whenever we enter or leave "freewheel" mode, passing @a
  320. * arg as the second argument. The first argument to the
  321. * callback will be non-zero if JACK is entering freewheel
  322. * mode, and zero otherwise.
  323. *
  324. * All "notification events" are received in a seperated non RT thread,
  325. * the code in the supplied function does not need to be
  326. * suitable for real-time execution.
  327. *
  328. * NOTE: this function cannot be called while the client is activated
  329. * (after jack_activate has been called.)
  330. *
  331. * @return 0 on success, otherwise a non-zero error code.
  332. */
  333. int jack_set_freewheel_callback (jack_client_t *client,
  334. JackFreewheelCallback freewheel_callback,
  335. void *arg);
  336. /**
  337. * Tell JACK to call @a bufsize_callback whenever the size of the the
  338. * buffer that will be passed to the @a process_callback is about to
  339. * change. Clients that depend on knowing the buffer size must supply
  340. * a @a bufsize_callback before activating themselves.
  341. *
  342. * All "notification events" are received in a seperated non RT thread,
  343. * the code in the supplied function does not need to be
  344. * suitable for real-time execution.
  345. *
  346. * NOTE: this function cannot be called while the client is activated
  347. * (after jack_activate has been called.)
  348. *
  349. * @param client pointer to JACK client structure.
  350. * @param bufsize_callback function to call when the buffer size changes.
  351. * @param arg argument for @a bufsize_callback.
  352. *
  353. * @return 0 on success, otherwise a non-zero error code
  354. */
  355. int jack_set_buffer_size_callback (jack_client_t *client,
  356. JackBufferSizeCallback bufsize_callback,
  357. void *arg);
  358. /**
  359. * Tell the Jack server to call @a srate_callback whenever the system
  360. * sample rate changes.
  361. *
  362. * All "notification events" are received in a seperated non RT thread,
  363. * the code in the supplied function does not need to be
  364. * suitable for real-time execution.
  365. *
  366. * NOTE: this function cannot be called while the client is activated
  367. * (after jack_activate has been called.)
  368. *
  369. * @return 0 on success, otherwise a non-zero error code
  370. */
  371. int jack_set_sample_rate_callback (jack_client_t *client,
  372. JackSampleRateCallback srate_callback,
  373. void *arg);
  374. /**
  375. * Tell the JACK server to call @a registration_callback whenever a
  376. * port is registered or unregistered, passing @a arg as a parameter.
  377. *
  378. * All "notification events" are received in a seperated non RT thread,
  379. * the code in the supplied function does not need to be
  380. * suitable for real-time execution.
  381. *
  382. * NOTE: this function cannot be called while the client is activated
  383. * (after jack_activate has been called.)
  384. *
  385. * @return 0 on success, otherwise a non-zero error code
  386. */
  387. int jack_set_client_registration_callback (jack_client_t *,
  388. JackClientRegistrationCallback
  389. registration_callback, void *arg);
  390. /**
  391. * Tell the JACK server to call @a registration_callback whenever a
  392. * port is registered or unregistered, passing @a arg as a parameter.
  393. *
  394. * All "notification events" are received in a seperated non RT thread,
  395. * the code in the supplied function does not need to be
  396. * suitable for real-time execution.
  397. *
  398. * NOTE: this function cannot be called while the client is activated
  399. * (after jack_activate has been called.)
  400. *
  401. * @return 0 on success, otherwise a non-zero error code
  402. */
  403. int jack_set_port_registration_callback (jack_client_t *,
  404. JackPortRegistrationCallback
  405. registration_callback, void *arg);
  406. /**
  407. * Tell the JACK server to call @a connect_callback whenever a
  408. * port is connected or disconnected, passing @a arg as a parameter.
  409. *
  410. * All "notification events" are received in a seperated non RT thread,
  411. * the code in the supplied function does not need to be
  412. * suitable for real-time execution.
  413. *
  414. * NOTE: this function cannot be called while the client is activated
  415. * (after jack_activate has been called.)
  416. *
  417. * @return 0 on success, otherwise a non-zero error code
  418. */
  419. int jack_set_port_connect_callback (jack_client_t *,
  420. JackPortConnectCallback
  421. connect_callback, void *arg);
  422. /**
  423. * Tell the JACK server to call @a rename_callback whenever a
  424. * port is renamed, passing @a arg as a parameter.
  425. *
  426. * All "notification events" are received in a seperated non RT thread,
  427. * the code in the supplied function does not need to be
  428. * suitable for real-time execution.
  429. *
  430. * NOTE: this function cannot be called while the client is activated
  431. * (after jack_activate has been called.)
  432. *
  433. * @return 0 on success, otherwise a non-zero error code
  434. */
  435. int jack_set_port_rename_callback (jack_client_t *,
  436. JackPortRenameCallback
  437. rename_callback, void *arg);
  438. /**
  439. * Tell the JACK server to call @a graph_callback whenever the
  440. * processing graph is reordered, passing @a arg as a parameter.
  441. *
  442. * All "notification events" are received in a seperated non RT thread,
  443. * the code in the supplied function does not need to be
  444. * suitable for real-time execution.
  445. *
  446. * NOTE: this function cannot be called while the client is activated
  447. * (after jack_activate has been called.)
  448. *
  449. * @return 0 on success, otherwise a non-zero error code
  450. */
  451. int jack_set_graph_order_callback (jack_client_t *,
  452. JackGraphOrderCallback graph_callback,
  453. void *);
  454. /**
  455. * Tell the JACK server to call @a xrun_callback whenever there is a
  456. * xrun, passing @a arg as a parameter.
  457. *
  458. * All "notification events" are received in a seperated non RT thread,
  459. * the code in the supplied function does not need to be
  460. * suitable for real-time execution.
  461. *
  462. * NOTE: this function cannot be called while the client is activated
  463. * (after jack_activate has been called.)
  464. *
  465. * @return 0 on success, otherwise a non-zero error code
  466. */
  467. int jack_set_xrun_callback (jack_client_t *,
  468. JackXRunCallback xrun_callback, void *arg);
  469. /*@}*/
  470. /**
  471. * @defgroup ServerClientControl Controlling & querying JACK server operation
  472. * @{
  473. */
  474. /**
  475. * Start/Stop JACK's "freewheel" mode.
  476. *
  477. * When in "freewheel" mode, JACK no longer waits for
  478. * any external event to begin the start of the next process
  479. * cycle.
  480. *
  481. * As a result, freewheel mode causes "faster than realtime"
  482. * execution of a JACK graph. If possessed, real-time
  483. * scheduling is dropped when entering freewheel mode, and
  484. * if appropriate it is reacquired when stopping.
  485. *
  486. * IMPORTANT: on systems using capabilities to provide real-time
  487. * scheduling (i.e. Linux kernel 2.4), if onoff is zero, this function
  488. * must be called from the thread that originally called jack_activate().
  489. * This restriction does not apply to other systems (e.g. Linux kernel 2.6
  490. * or OS X).
  491. *
  492. * @param client pointer to JACK client structure
  493. * @param onoff if non-zero, freewheel mode starts. Otherwise
  494. * freewheel mode ends.
  495. *
  496. * @return 0 on success, otherwise a non-zero error code.
  497. */
  498. int jack_set_freewheel(jack_client_t* client, int onoff);
  499. /**
  500. * Change the buffer size passed to the @a process_callback.
  501. *
  502. * This operation stops the JACK engine process cycle, then calls all
  503. * registered @a bufsize_callback functions before restarting the
  504. * process cycle. This will cause a gap in the audio flow, so it
  505. * should only be done at appropriate stopping points.
  506. *
  507. * @see jack_set_buffer_size_callback()
  508. *
  509. * @param client pointer to JACK client structure.
  510. * @param nframes new buffer size. Must be a power of two.
  511. *
  512. * @return 0 on success, otherwise a non-zero error code
  513. */
  514. int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
  515. /**
  516. * @return the sample rate of the jack system, as set by the user when
  517. * jackd was started.
  518. */
  519. jack_nframes_t jack_get_sample_rate (jack_client_t *);
  520. /**
  521. * @return the current maximum size that will ever be passed to the @a
  522. * process_callback. It should only be used *before* the client has
  523. * been activated. This size may change, clients that depend on it
  524. * must register a @a bufsize_callback so they will be notified if it
  525. * does.
  526. *
  527. * @see jack_set_buffer_size_callback()
  528. */
  529. jack_nframes_t jack_get_buffer_size (jack_client_t *);
  530. /**
  531. * Old-style interface to become the timebase for the entire JACK
  532. * subsystem.
  533. *
  534. * @deprecated This function still exists for compatibility with the
  535. * earlier transport interface, but it does nothing. Instead, see
  536. * transport.h and use jack_set_timebase_callback().
  537. *
  538. * @return ENOSYS, function not implemented.
  539. */
  540. int jack_engine_takeover_timebase (jack_client_t *);
  541. /**
  542. * @return the current CPU load estimated by JACK. This is a running
  543. * average of the time it takes to execute a full process cycle for
  544. * all clients as a percentage of the real time available per cycle
  545. * determined by the buffer size and sample rate.
  546. */
  547. float jack_cpu_load (jack_client_t *client);
  548. /*@}*/
  549. /**
  550. * @defgroup PortFunctions Creating & manipulating ports
  551. * @{
  552. */
  553. /**
  554. * Create a new port for the client. This is an object used for moving
  555. * data of any type in or out of the client. Ports may be connected
  556. * in various ways.
  557. *
  558. * Each port has a short name. The port's full name contains the name
  559. * of the client concatenated with a colon (:) followed by its short
  560. * name. The jack_port_name_size() is the maximum length of this full
  561. * name. Exceeding that will cause the port registration to fail and
  562. * return NULL.
  563. *
  564. * All ports have a type, which may be any non-NULL and non-zero
  565. * length string, passed as an argument. Some port types are built
  566. * into the JACK API, currently only JACK_DEFAULT_AUDIO_TYPE.
  567. *
  568. * @param client pointer to JACK client structure.
  569. * @param port_name non-empty short name for the new port (not
  570. * including the leading @a "client_name:").
  571. * @param port_type port type name. If longer than
  572. * jack_port_type_size(), only that many characters are significant.
  573. * @param flags @ref JackPortFlags bit mask.
  574. * @param buffer_size must be non-zero if this is not a built-in @a
  575. * port_type. Otherwise, it is ignored.
  576. *
  577. * @return jack_port_t pointer on success, otherwise NULL.
  578. */
  579. jack_port_t * jack_port_register (jack_client_t *client,
  580. const char *port_name,
  581. const char *port_type,
  582. unsigned long flags,
  583. unsigned long buffer_size);
  584. /**
  585. * Remove the port from the client, disconnecting any existing
  586. * connections.
  587. *
  588. * @return 0 on success, otherwise a non-zero error code
  589. */
  590. int jack_port_unregister (jack_client_t *, jack_port_t *);
  591. /**
  592. * This returns a pointer to the memory area associated with the
  593. * specified port. For an output port, it will be a memory area
  594. * that can be written to; for an input port, it will be an area
  595. * containing the data from the port's connection(s), or
  596. * zero-filled. if there are multiple inbound connections, the data
  597. * will be mixed appropriately.
  598. *
  599. * FOR OUTPUT PORTS ONLY : DEPRECATED in Jack 2.0 !!
  600. * ---------------------------------------------------
  601. * You may cache the value returned, but only between calls to
  602. * your "blocksize" callback. For this reason alone, you should
  603. * either never cache the return value or ensure you have
  604. * a "blocksize" callback and be sure to invalidate the cached
  605. * address from there.
  606. *
  607. * Caching output ports is DEPRECATED in Jack 2.0, due to some new optimization (like "pipelining").
  608. * Port buffers have to be retrieved in each callback for proper functionning.
  609. */
  610. void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  611. /**
  612. * @return the full name of the jack_port_t (including the @a
  613. * "client_name:" prefix).
  614. *
  615. * @see jack_port_name_size().
  616. */
  617. const char * jack_port_name (const jack_port_t *port);
  618. /**
  619. * @return the short name of the jack_port_t (not including the @a
  620. * "client_name:" prefix).
  621. *
  622. * @see jack_port_name_size().
  623. */
  624. const char * jack_port_short_name (const jack_port_t *port);
  625. /**
  626. * @return the @ref JackPortFlags of the jack_port_t.
  627. */
  628. int jack_port_flags (const jack_port_t *port);
  629. /**
  630. * @return the @a port type, at most jack_port_type_size() characters
  631. * including a final NULL.
  632. */
  633. const char * jack_port_type (const jack_port_t *port);
  634. /**
  635. * @return the @a port type id.
  636. */
  637. jack_port_type_id_t jack_port_type_id (const jack_port_t *port);
  638. /**
  639. * @return TRUE if the jack_port_t belongs to the jack_client_t.
  640. */
  641. int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  642. /**
  643. * @return number of connections to or from @a port.
  644. *
  645. * @pre The calling client must own @a port.
  646. */
  647. int jack_port_connected (const jack_port_t *port);
  648. /**
  649. * @return TRUE if the locally-owned @a port is @b directly connected
  650. * to the @a port_name.
  651. *
  652. * @see jack_port_name_size()
  653. */
  654. int jack_port_connected_to (const jack_port_t *port,
  655. const char *port_name);
  656. /**
  657. * @return a null-terminated array of full port names to which the @a
  658. * port is connected. If none, returns NULL.
  659. *
  660. * The caller is responsible for calling free(3) on any non-NULL
  661. * returned value.
  662. *
  663. * @param port locally owned jack_port_t pointer.
  664. *
  665. * @see jack_port_name_size(), jack_port_get_all_connections()
  666. */
  667. const char ** jack_port_get_connections (const jack_port_t *port);
  668. /**
  669. * @return a null-terminated array of full port names to which the @a
  670. * port is connected. If none, returns NULL.
  671. *
  672. * The caller is responsible for calling free(3) on any non-NULL
  673. * returned value.
  674. *
  675. * This differs from jack_port_get_connections() in two important
  676. * respects:
  677. *
  678. * 1) You may not call this function from code that is
  679. * executed in response to a JACK event. For example,
  680. * you cannot use it in a GraphReordered handler.
  681. *
  682. * 2) You need not be the owner of the port to get information
  683. * about its connections.
  684. *
  685. * @see jack_port_name_size()
  686. */
  687. const char ** jack_port_get_all_connections (const jack_client_t *client,
  688. const jack_port_t *port);
  689. /**
  690. *
  691. * @deprecated This function will be removed from a future version
  692. * of JACK. Do not use it. There is no replacement. It has
  693. * turned out to serve essentially no purpose in real-life
  694. * JACK clients.
  695. */
  696. int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  697. /**
  698. *
  699. * @deprecated This function will be removed from a future version
  700. * of JACK. Do not use it. There is no replacement. It has
  701. * turned out to serve essentially no purpose in real-life
  702. * JACK clients.
  703. */
  704. int jack_port_untie (jack_port_t *port);
  705. /**
  706. * @return the time (in frames) between data being available or
  707. * delivered at/to a port, and the time at which it arrived at or is
  708. * delivered to the "other side" of the port. E.g. for a physical
  709. * audio output port, this is the time between writing to the port and
  710. * when the signal will leave the connector. For a physical audio
  711. * input port, this is the time between the sound arriving at the
  712. * connector and the corresponding frames being readable from the
  713. * port.
  714. */
  715. jack_nframes_t jack_port_get_latency (jack_port_t *port);
  716. /**
  717. * The maximum of the sum of the latencies in every
  718. * connection path that can be drawn between the port and other
  719. * ports with the @ref JackPortIsTerminal flag set.
  720. */
  721. jack_nframes_t jack_port_get_total_latency (jack_client_t *,
  722. jack_port_t *port);
  723. /**
  724. * The port latency is zero by default. Clients that control
  725. * physical hardware with non-zero latency should call this
  726. * to set the latency to its correct value. Note that the value
  727. * should include any systemic latency present "outside" the
  728. * physical hardware controlled by the client. For example,
  729. * for a client controlling a digital audio interface connected
  730. * to an external digital converter, the latency setting should
  731. * include both buffering by the audio interface *and* the converter.
  732. */
  733. void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  734. /**
  735. * Request a complete recomputation of a port's total latency. This
  736. * can be called by a client that has just changed the internal
  737. * latency of its port using @function jack_port_set_latency
  738. * and wants to ensure that all signal pathways in the graph
  739. * are updated with respect to the values that will be returned
  740. * by @function jack_port_get_total_latency.
  741. *
  742. * @return zero for successful execution of the request. non-zero
  743. * otherwise.
  744. */
  745. int jack_recompute_total_latency (jack_client_t*, jack_port_t* port);
  746. /**
  747. * Request a complete recomputation of all port latencies. This
  748. * can be called by a client that has just changed the internal
  749. * latency of its port using @function jack_port_set_latency
  750. * and wants to ensure that all signal pathways in the graph
  751. * are updated with respect to the values that will be returned
  752. * by @function jack_port_get_total_latency. It allows a client
  753. * to change multiple port latencies without triggering a
  754. * recompute for each change.
  755. *
  756. * @return zero for successful execution of the request. non-zero
  757. * otherwise.
  758. */
  759. int jack_recompute_total_latencies (jack_client_t*);
  760. /**
  761. * Modify a port's short name. May be called at any time. If the
  762. * resulting full name (including the @a "client_name:" prefix) is
  763. * longer than jack_port_name_size(), it will be truncated.
  764. *
  765. * @return 0 on success, otherwise a non-zero error code.
  766. */
  767. int jack_port_set_name (jack_port_t *port, const char *port_name);
  768. /**
  769. * Set @a alias as an alias for @a port. May be called at any time.
  770. * If the alias is longer than jack_port_name_size(), it will be truncated.
  771. *
  772. * After a successful call, and until JACK exits or
  773. * @function jack_port_unset_alias() is called, @alias may be
  774. * used as a alternate name for the port.
  775. *
  776. * Ports can have up to two aliases - if both are already
  777. * set, this function will return an error.
  778. *
  779. * @return 0 on success, otherwise a non-zero error code.
  780. */
  781. int jack_port_set_alias (jack_port_t *port, const char *alias);
  782. /**
  783. * Remove @a alias as an alias for @a port. May be called at any time.
  784. *
  785. * After a successful call, @a alias can no longer be
  786. * used as a alternate name for the port.
  787. *
  788. * @return 0 on success, otherwise a non-zero error code.
  789. */
  790. int jack_port_unset_alias (jack_port_t *port, const char *alias);
  791. /**
  792. * Get any aliases known for @port.
  793. *
  794. * @return the number of aliases discovered for the port
  795. */
  796. int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
  797. /**
  798. * If @ref JackPortCanMonitor is set for this @a port, turn input
  799. * monitoring on or off. Otherwise, do nothing.
  800. */
  801. int jack_port_request_monitor (jack_port_t *port, int onoff);
  802. /**
  803. * If @ref JackPortCanMonitor is set for this @a port_name, turn input
  804. * monitoring on or off. Otherwise, do nothing.
  805. *
  806. * @return 0 on success, otherwise a non-zero error code.
  807. *
  808. * @see jack_port_name_size()
  809. */
  810. int jack_port_request_monitor_by_name (jack_client_t *client,
  811. const char *port_name, int onoff);
  812. /**
  813. * If @ref JackPortCanMonitor is set for a port, this function turns
  814. * on input monitoring if it was off, and turns it off if only one
  815. * request has been made to turn it on. Otherwise it does nothing.
  816. *
  817. * @return 0 on success, otherwise a non-zero error code
  818. */
  819. int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  820. /**
  821. * @return TRUE if input monitoring has been requested for @a port.
  822. */
  823. int jack_port_monitoring_input (jack_port_t *port);
  824. /**
  825. * Establish a connection between two ports.
  826. *
  827. * When a connection exists, data written to the source port will
  828. * be available to be read at the destination port.
  829. *
  830. * @pre The port types must be identical.
  831. *
  832. * @pre The @ref JackPortFlags of the @a source_port must include @ref
  833. * JackPortIsOutput.
  834. *
  835. * @pre The @ref JackPortFlags of the @a destination_port must include
  836. * @ref JackPortIsInput.
  837. *
  838. * @return 0 on success, EEXIST if the connection is already made,
  839. * otherwise a non-zero error code
  840. */
  841. int jack_connect (jack_client_t *,
  842. const char *source_port,
  843. const char *destination_port);
  844. /**
  845. * Remove a connection between two ports.
  846. *
  847. * @pre The port types must be identical.
  848. *
  849. * @pre The @ref JackPortFlags of the @a source_port must include @ref
  850. * JackPortIsOutput.
  851. *
  852. * @pre The @ref JackPortFlags of the @a destination_port must include
  853. * @ref JackPortIsInput.
  854. *
  855. * @return 0 on success, otherwise a non-zero error code
  856. */
  857. int jack_disconnect (jack_client_t *,
  858. const char *source_port,
  859. const char *destination_port);
  860. /**
  861. * Perform the same function as jack_disconnect() using port handles
  862. * rather than names. This avoids the name lookup inherent in the
  863. * name-based version.
  864. *
  865. * Clients connecting their own ports are likely to use this function,
  866. * while generic connection clients (e.g. patchbays) would use
  867. * jack_disconnect().
  868. */
  869. int jack_port_disconnect (jack_client_t *, jack_port_t *);
  870. /**
  871. * @return the maximum number of characters in a full JACK port name
  872. * including the final NULL character. This value is a constant.
  873. *
  874. * A port's full name contains the owning client name concatenated
  875. * with a colon (:) followed by its short name and a NULL
  876. * character.
  877. */
  878. int jack_port_name_size(void);
  879. /**
  880. * @return the maximum number of characters in a JACK port type name
  881. * including the final NULL character. This value is a constant.
  882. */
  883. int jack_port_type_size(void);
  884. /*@}*/
  885. /**
  886. * @defgroup PortSearching Looking up ports
  887. * @{
  888. */
  889. /**
  890. * @param port_name_pattern A regular expression used to select
  891. * ports by name. If NULL or of zero length, no selection based
  892. * on name will be carried out.
  893. * @param type_name_pattern A regular expression used to select
  894. * ports by type. If NULL or of zero length, no selection based
  895. * on type will be carried out.
  896. * @param flags A value used to select ports by their flags.
  897. * If zero, no selection based on flags will be carried out.
  898. *
  899. * @return a NULL-terminated array of ports that match the specified
  900. * arguments. The caller is responsible for calling free(3) any
  901. * non-NULL returned value.
  902. *
  903. * @see jack_port_name_size(), jack_port_type_size()
  904. */
  905. const char ** jack_get_ports (jack_client_t *,
  906. const char *port_name_pattern,
  907. const char *type_name_pattern,
  908. unsigned long flags);
  909. /**
  910. * @return address of the jack_port_t named @a port_name.
  911. *
  912. * @see jack_port_name_size()
  913. */
  914. jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
  915. /**
  916. * @return address of the jack_port_t of a @a port_id.
  917. */
  918. jack_port_t * jack_port_by_id (jack_client_t *client,
  919. jack_port_id_t port_id);
  920. /*@}*/
  921. /**
  922. * @defgroup TimeFunctions Handling time
  923. * @{
  924. *
  925. * JACK time is in units of 'frames', according to the current sample rate.
  926. * The absolute value of frame times is meaningless, frame times have meaning
  927. * only relative to each other.
  928. */
  929. /**
  930. * @return the estimated time in frames that has passed since the JACK
  931. * server began the current process cycle.
  932. */
  933. jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  934. /**
  935. * @return the estimated current time in frames.
  936. * This function is intended for use in other threads (not the process
  937. * callback). The return value can be compared with the value of
  938. * jack_last_frame_time to relate time in other threads to JACK time.
  939. */
  940. jack_nframes_t jack_frame_time (const jack_client_t *);
  941. /**
  942. * @return the precise time at the start of the current process cycle.
  943. * This function may only be used from the process callback, and can
  944. * be used to interpret timestamps generated by jack_frame_time() in
  945. * other threads with respect to the current process cycle.
  946. *
  947. * This is the only jack time function that returns exact time:
  948. * when used during the process callback it always returns the same
  949. * value (until the next process callback, where it will return
  950. * that value + nframes, etc). The return value is guaranteed to be
  951. * monotonic and linear in this fashion unless an xrun occurs.
  952. * If an xrun occurs, clients must check this value again, as time
  953. * may have advanced in a non-linear way (e.g. cycles may have been skipped).
  954. */
  955. jack_nframes_t jack_last_frame_time (const jack_client_t *client);
  956. /**
  957. * @return the estimated time in microseconds of the specified frame time
  958. */
  959. jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t);
  960. /**
  961. * @return the estimated time in frames for the specified system time.
  962. */
  963. jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t);
  964. /**
  965. * @return return JACK's current system time in microseconds,
  966. * using the JACK clock source.
  967. *
  968. * The value returned is guaranteed to be monotonic, but not linear.
  969. */
  970. jack_time_t jack_get_time();
  971. /*@}*/
  972. /**
  973. * @defgroup ErrorOutput Controlling error/information output
  974. */
  975. /*@{*/
  976. /**
  977. * Display JACK error message.
  978. *
  979. * Set via jack_set_error_function(), otherwise a JACK-provided
  980. * default will print @a msg (plus a newline) to stderr.
  981. *
  982. * @param msg error message text (no newline at end).
  983. */
  984. extern void (*jack_error_callback)(const char *msg);
  985. /**
  986. * Set the @ref jack_error_callback for error message display.
  987. * Set it to NULL to restore default_jack_error_callback function.
  988. *
  989. * The JACK library provides two built-in callbacks for this purpose:
  990. * default_jack_error_callback() and silent_jack_error_callback().
  991. */
  992. void jack_set_error_function (void (*func)(const char *));
  993. /**
  994. * Display JACK info message.
  995. *
  996. * Set via jack_set_info_function(), otherwise a JACK-provided
  997. * default will print @a msg (plus a newline) to stdout.
  998. *
  999. * @param msg info message text (no newline at end).
  1000. */
  1001. extern void (*jack_info_callback)(const char *msg);
  1002. /**
  1003. * Set the @ref jack_info_callback for info message display.
  1004. * Set it to NULL to restore default_jack_info_callback function.
  1005. *
  1006. * The JACK library provides two built-in callbacks for this purpose:
  1007. * default_jack_info_callback() and silent_jack_info_callback().
  1008. */
  1009. void jack_set_info_function (void (*func)(const char *));
  1010. /*@}*/
  1011. /**
  1012. * The free function to be used on memory returned by jack_port_get_connections,
  1013. * jack_port_get_all_connections and jack_get_ports functions.
  1014. * This is MANDATORY on Windows when otherwise all nasty runtime version related crashes can occur.
  1015. * Developers are strongly encouraged to use this function instead of the standard "free" function in new code.
  1016. *
  1017. */
  1018. void jack_free(void* ptr);
  1019. #ifdef __cplusplus
  1020. }
  1021. #endif
  1022. #endif /* __jack_h__ */