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.

1154 lines
39KB

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