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.

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