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.

1078 lines
35KB

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