jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

986 lines
32KB

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