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.

958 lines
31KB

  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. See
  185. * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
  186. * for more information.
  187. *
  188. * @return 0 on success, otherwise a non-zero error code.
  189. */
  190. int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg);
  191. /*@}*/
  192. /**
  193. * @defgroup ClientCallbacks Setting Client Callbacks
  194. * @{
  195. */
  196. /**
  197. * Tell JACK to call @a thread_init_callback once just after
  198. * the creation of the thread in which all other callbacks
  199. * will be handled.
  200. *
  201. * The code in the supplied function does not need to be
  202. * suitable for real-time execution.
  203. *
  204. * @return 0 on success, otherwise a non-zero error code, causing JACK
  205. * to remove that client from the process() graph.
  206. */
  207. int jack_set_thread_init_callback (jack_client_t *client,
  208. JackThreadInitCallback thread_init_callback,
  209. void *arg);
  210. /**
  211. * @param client pointer to JACK client structure.
  212. * @param function The jack_shutdown function pointer.
  213. * @param arg The arguments for the jack_shutdown function.
  214. *
  215. * Register a function (and argument) to be called if and when the
  216. * JACK server shuts down the client thread. The function must
  217. * be written as if it were an asynchonrous POSIX signal
  218. * handler --- use only async-safe functions, and remember that it
  219. * is executed from another thread. A typical function might
  220. * set a flag or write to a pipe so that the rest of the
  221. * application knows that the JACK client thread has shut
  222. * down.
  223. *
  224. * NOTE: clients do not need to call this. It exists only
  225. * to help more complex clients understand what is going
  226. * on. It should be called before jack_client_activate().
  227. */
  228. void jack_on_shutdown (jack_client_t *client,
  229. void (*function)(void *arg), void *arg);
  230. /**
  231. * Tell the Jack server to call @a process_callback whenever there is
  232. * work be done, passing @a arg as the second argument.
  233. *
  234. * The code in the supplied function must be suitable for real-time
  235. * execution. That means that it cannot call functions that might
  236. * block for a long time. This includes malloc, free, printf,
  237. * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
  238. * pthread_cond_wait, etc, etc. See
  239. * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
  240. * for more information.
  241. *
  242. * @return 0 on success, otherwise a non-zero error code, causing JACK
  243. * to remove that client from the process() graph.
  244. */
  245. int jack_set_process_callback (jack_client_t *client,
  246. JackProcessCallback process_callback,
  247. void *arg);
  248. /**
  249. * Tell the Jack server to call @a freewheel_callback
  250. * whenever we enter or leave "freewheel" mode, passing @a
  251. * arg as the second argument. The first argument to the
  252. * callback will be non-zero if JACK is entering freewheel
  253. * mode, and zero otherwise.
  254. *
  255. * @return 0 on success, otherwise a non-zero error code.
  256. */
  257. int jack_set_freewheel_callback (jack_client_t *client,
  258. JackFreewheelCallback freewheel_callback,
  259. void *arg);
  260. /**
  261. * Tell JACK to call @a bufsize_callback whenever the size of the the
  262. * buffer that will be passed to the @a process_callback is about to
  263. * change. Clients that depend on knowing the buffer size must supply
  264. * a @a bufsize_callback before activating themselves.
  265. *
  266. * @param client pointer to JACK client structure.
  267. * @param bufsize_callback function to call when the buffer size changes.
  268. * @param arg argument for @a bufsize_callback.
  269. *
  270. * @return 0 on success, otherwise a non-zero error code
  271. */
  272. int jack_set_buffer_size_callback (jack_client_t *client,
  273. JackBufferSizeCallback bufsize_callback,
  274. void *arg);
  275. /**
  276. * Tell the Jack server to call @a srate_callback whenever the system
  277. * sample rate changes.
  278. *
  279. * @return 0 on success, otherwise a non-zero error code
  280. */
  281. int jack_set_sample_rate_callback (jack_client_t *client,
  282. JackSampleRateCallback srate_callback,
  283. void *arg);
  284. /**
  285. * Tell the JACK server to call @a registration_callback whenever a
  286. * port is registered or unregistered, passing @a arg as a parameter.
  287. *
  288. * @return 0 on success, otherwise a non-zero error code
  289. */
  290. int jack_set_client_registration_callback (jack_client_t *,
  291. JackClientRegistrationCallback
  292. registration_callback, void *arg);
  293. /**
  294. * Tell the JACK server to call @a registration_callback whenever a
  295. * port is registered or unregistered, passing @a arg as a parameter.
  296. *
  297. * @return 0 on success, otherwise a non-zero error code
  298. */
  299. int jack_set_port_registration_callback (jack_client_t *,
  300. JackPortRegistrationCallback
  301. registration_callback, void *arg);
  302. /**
  303. * Tell the JACK server to call @a connect_callback whenever a
  304. * port is connected or disconnected, passing @a arg as a parameter.
  305. *
  306. * @return 0 on success, otherwise a non-zero error code
  307. */
  308. int jack_set_port_connect_callback (jack_client_t *,
  309. JackPortConnectCallback
  310. connect_callback, void *arg);
  311. /**
  312. * Tell the JACK server to call @a graph_callback whenever the
  313. * processing graph is reordered, passing @a arg as a parameter.
  314. *
  315. * @return 0 on success, otherwise a non-zero error code
  316. */
  317. int jack_set_graph_order_callback (jack_client_t *,
  318. JackGraphOrderCallback graph_callback,
  319. void *);
  320. /**
  321. * Tell the JACK server to call @a xrun_callback whenever there is a
  322. * xrun, passing @a arg as a parameter.
  323. *
  324. * @return 0 on success, otherwise a non-zero error code
  325. */
  326. int jack_set_xrun_callback (jack_client_t *,
  327. JackXRunCallback xrun_callback, void *arg);
  328. /*@}*/
  329. /**
  330. * @defgroup ServerControl Controlling & querying JACK server operation
  331. * @{
  332. */
  333. /**
  334. * Start/Stop JACK's "freewheel" mode.
  335. *
  336. * When in "freewheel" mode, JACK no longer waits for
  337. * any external event to begin the start of the next process
  338. * cycle.
  339. *
  340. * As a result, freewheel mode causes "faster than realtime"
  341. * execution of a JACK graph. If possessed, real-time
  342. * scheduling is dropped when entering freewheel mode, and
  343. * if appropriate it is reacquired when stopping.
  344. *
  345. * IMPORTANT: on systems using capabilities to provide real-time
  346. * scheduling (i.e. Linux kernel 2.4), if onoff is zero, this function
  347. * must be called from the thread that originally called jack_activate().
  348. * This restriction does not apply to other systems (e.g. Linux kernel 2.6
  349. * or OS X).
  350. *
  351. * @param client pointer to JACK client structure
  352. * @param onoff if non-zero, freewheel mode starts. Otherwise
  353. * freewheel mode ends.
  354. *
  355. * @return 0 on success, otherwise a non-zero error code.
  356. */
  357. int jack_set_freewheel(jack_client_t* client, int onoff);
  358. /**
  359. * Change the buffer size passed to the @a process_callback.
  360. *
  361. * This operation stops the JACK engine process cycle, then calls all
  362. * registered @a bufsize_callback functions before restarting the
  363. * process cycle. This will cause a gap in the audio flow, so it
  364. * should only be done at appropriate stopping points.
  365. *
  366. * @see jack_set_buffer_size_callback()
  367. *
  368. * @param client pointer to JACK client structure.
  369. * @param nframes new buffer size. Must be a power of two.
  370. *
  371. * @return 0 on success, otherwise a non-zero error code
  372. */
  373. int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
  374. /**
  375. * @return the sample rate of the jack system, as set by the user when
  376. * jackd was started.
  377. */
  378. jack_nframes_t jack_get_sample_rate (jack_client_t *);
  379. /**
  380. * @return the current maximum size that will ever be passed to the @a
  381. * process_callback. It should only be used *before* the client has
  382. * been activated. This size may change, clients that depend on it
  383. * must register a @a bufsize_callback so they will be notified if it
  384. * does.
  385. *
  386. * @see jack_set_buffer_size_callback()
  387. */
  388. jack_nframes_t jack_get_buffer_size (jack_client_t *);
  389. /**
  390. * Old-style interface to become the timebase for the entire JACK
  391. * subsystem.
  392. *
  393. * @deprecated This function still exists for compatibility with the
  394. * earlier transport interface, but it does nothing. Instead, see
  395. * transport.h and use jack_set_timebase_callback().
  396. *
  397. * @return ENOSYS, function not implemented.
  398. */
  399. int jack_engine_takeover_timebase (jack_client_t *);
  400. /**
  401. * @return the current CPU load estimated by JACK. This is a running
  402. * average of the time it takes to execute a full process cycle for
  403. * all clients as a percentage of the real time available per cycle
  404. * determined by the buffer size and sample rate.
  405. */
  406. float jack_cpu_load (jack_client_t *client);
  407. /*@}*/
  408. /**
  409. * @defgroup PortFunctions Creating & manipulating ports
  410. * @{
  411. */
  412. /**
  413. * Create a new port for the client. This is an object used for moving
  414. * data of any type in or out of the client. Ports may be connected
  415. * in various ways.
  416. *
  417. * Each port has a short name. The port's full name contains the name
  418. * of the client concatenated with a colon (:) followed by its short
  419. * name. The jack_port_name_size() is the maximum length of this full
  420. * name. Exceeding that will cause the port registration to fail and
  421. * return NULL.
  422. *
  423. * All ports have a type, which may be any non-NULL and non-zero
  424. * length string, passed as an argument. Some port types are built
  425. * into the JACK API, like JACK_DEFAULT_AUDIO_TYPE or JACK_DEFAULT_MIDI_TYPE
  426. *
  427. * @param client pointer to JACK client structure.
  428. * @param port_name non-empty short name for the new port (not
  429. * including the leading @a "client_name:").
  430. * @param port_type port type name. If longer than
  431. * jack_port_type_size(), only that many characters are significant.
  432. * @param flags @ref JackPortFlags bit mask.
  433. * @param buffer_size must be non-zero if this is not a built-in @a
  434. * port_type. Otherwise, it is ignored.
  435. *
  436. * @return jack_port_t pointer on success, otherwise NULL.
  437. */
  438. jack_port_t *jack_port_register (jack_client_t *client,
  439. const char *port_name,
  440. const char *port_type,
  441. unsigned long flags,
  442. unsigned long buffer_size);
  443. /**
  444. * Remove the port from the client, disconnecting any existing
  445. * connections.
  446. *
  447. * @return 0 on success, otherwise a non-zero error code
  448. */
  449. int jack_port_unregister (jack_client_t *, jack_port_t *);
  450. /**
  451. * This returns a pointer to the memory area associated with the
  452. * specified port. For an output port, it will be a memory area
  453. * that can be written to; for an input port, it will be an area
  454. * containing the data from the port's connection(s), or
  455. * zero-filled. if there are multiple inbound connections, the data
  456. * will be mixed appropriately.
  457. *
  458. * FOR OUTPUT PORTS ONLY : WILL BE DEPRECATED in Jack 2.0 !!
  459. * ---------------------------------------------------------
  460. * You may cache the value returned, but only between calls to
  461. * your "blocksize" callback. For this reason alone, you should
  462. * either never cache the return value or ensure you have
  463. * a "blocksize" callback and be sure to invalidate the cached
  464. * address from there.
  465. *
  466. * Caching output ports is DEPRECATED in Jack 2.0, due to some new optimization (like "pipelining").
  467. * Port buffers have to be retrieved in each callback for proper functionning.
  468. */
  469. void *jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  470. /**
  471. * @return the full name of the jack_port_t (including the @a
  472. * "client_name:" prefix).
  473. *
  474. * @see jack_port_name_size().
  475. */
  476. const char *jack_port_name (const jack_port_t *port);
  477. /**
  478. * @return the short name of the jack_port_t (not including the @a
  479. * "client_name:" prefix).
  480. *
  481. * @see jack_port_name_size().
  482. */
  483. const char *jack_port_short_name (const jack_port_t *port);
  484. /**
  485. * @return the @ref JackPortFlags of the jack_port_t.
  486. */
  487. int jack_port_flags (const jack_port_t *port);
  488. /**
  489. * @return the @a port type, at most jack_port_type_size() characters
  490. * including a final NULL.
  491. */
  492. const char *jack_port_type (const jack_port_t *port);
  493. /**
  494. * @return TRUE if the jack_port_t belongs to the jack_client_t.
  495. */
  496. int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  497. /**
  498. * @return number of connections to or from @a port.
  499. *
  500. * @pre The calling client must own @a port.
  501. */
  502. int jack_port_connected (const jack_port_t *port);
  503. /**
  504. * @return TRUE if the locally-owned @a port is @b directly connected
  505. * to the @a port_name.
  506. *
  507. * @see jack_port_name_size()
  508. */
  509. int jack_port_connected_to (const jack_port_t *port,
  510. const char *port_name);
  511. /**
  512. * @return a null-terminated array of full port names to which the @a
  513. * port is connected. If none, returns NULL.
  514. *
  515. * The caller is responsible for calling free(3) on any non-NULL
  516. * returned value.
  517. *
  518. * @param port locally owned jack_port_t pointer.
  519. *
  520. * @see jack_port_name_size(), jack_port_get_all_connections()
  521. */
  522. const char **jack_port_get_connections (const jack_port_t *port);
  523. /**
  524. * @return a null-terminated array of full port names to which the @a
  525. * port is connected. If none, returns NULL.
  526. *
  527. * The caller is responsible for calling free(3) on any non-NULL
  528. * returned value.
  529. *
  530. * This differs from jack_port_get_connections() in two important
  531. * respects:
  532. *
  533. * 1) You may not call this function from code that is
  534. * executed in response to a JACK event. For example,
  535. * you cannot use it in a GraphReordered handler.
  536. *
  537. * 2) You need not be the owner of the port to get information
  538. * about its connections.
  539. *
  540. * @see jack_port_name_size()
  541. */
  542. const char **jack_port_get_all_connections (const jack_client_t *client,
  543. const jack_port_t *port);
  544. /**
  545. *
  546. * @deprecated This function will be removed from a future version
  547. * of JACK. Do not use it. There is no replacement. It has
  548. * turned out to serve essentially no purpose in real-life
  549. * JACK clients.
  550. */
  551. int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  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_untie (jack_port_t *port);
  560. /**
  561. * @return the time (in frames) between data being available or
  562. * delivered at/to a port, and the time at which it arrived at or is
  563. * delivered to the "other side" of the port. E.g. for a physical
  564. * audio output port, this is the time between writing to the port and
  565. * when the signal will leave the connector. For a physical audio
  566. * input port, this is the time between the sound arriving at the
  567. * connector and the corresponding frames being readable from the
  568. * port.
  569. */
  570. jack_nframes_t jack_port_get_latency (jack_port_t *port);
  571. /**
  572. * The maximum of the sum of the latencies in every
  573. * connection path that can be drawn between the port and other
  574. * ports with the @ref JackPortIsTerminal flag set.
  575. */
  576. jack_nframes_t jack_port_get_total_latency (jack_client_t *,
  577. jack_port_t *port);
  578. /**
  579. * The port latency is zero by default. Clients that control
  580. * physical hardware with non-zero latency should call this
  581. * to set the latency to its correct value. Note that the value
  582. * should include any systemic latency present "outside" the
  583. * physical hardware controlled by the client. For example,
  584. * for a client controlling a digital audio interface connected
  585. * to an external digital converter, the latency setting should
  586. * include both buffering by the audio interface *and* the converter.
  587. */
  588. void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  589. /**
  590. * Request a complete recomputation of a port's total latency. This
  591. * can be called by a client that has just changed the internal
  592. * latency of its port using jack_port_set_latency
  593. * and wants to ensure that all signal pathways in the graph
  594. * are updated with respect to the values that will be returned
  595. * by jack_port_get_total_latency.
  596. *
  597. * @return zero for successful execution of the request. non-zero
  598. * otherwise.
  599. */
  600. int jack_recompute_total_latency (jack_client_t*, jack_port_t* port);
  601. /**
  602. * Request a complete recomputation of all port latencies. This
  603. * can be called by a client that has just changed the internal
  604. * latency of its port using jack_port_set_latency
  605. * and wants to ensure that all signal pathways in the graph
  606. * are updated with respect to the values that will be returned
  607. * by jack_port_get_total_latency. It allows a client
  608. * to change multiple port latencies without triggering a
  609. * recompute for each change.
  610. *
  611. * @return zero for successful execution of the request. non-zero
  612. * otherwise.
  613. */
  614. int jack_recompute_total_latencies (jack_client_t*);
  615. /**
  616. * Modify a port's short name. May be called at any time. If the
  617. * resulting full name (including the @a "client_name:" prefix) is
  618. * longer than jack_port_name_size(), it will be truncated.
  619. *
  620. * @return 0 on success, otherwise a non-zero error code.
  621. */
  622. int jack_port_set_name (jack_port_t *port, const char *port_name);
  623. /**
  624. * Set @a alias as an alias for @a port. May be called at any time.
  625. * If the alias is longer than jack_port_name_size(), it will be truncated.
  626. *
  627. * After a successful call, and until JACK exits or
  628. * jack_port_unset_alias() is called, may be
  629. * used as a alternate name for the port.
  630. *
  631. * Ports can have up to two aliases - if both are already
  632. * set, this function will return an error.
  633. *
  634. * @return 0 on success, otherwise a non-zero error code.
  635. */
  636. int jack_port_set_alias (jack_port_t *port, const char *alias);
  637. /**
  638. * Remove @a alias as an alias for @a port. May be called at any time.
  639. *
  640. * After a successful call, @a alias can no longer be
  641. * used as a alternate name for the port.
  642. *
  643. * @return 0 on success, otherwise a non-zero error code.
  644. */
  645. int jack_port_unset_alias (jack_port_t *port, const char *alias);
  646. /*
  647. * Get any aliases known for @port.
  648. *
  649. * @return the number of aliases discovered for the port
  650. */
  651. int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
  652. /**
  653. * If @ref JackPortCanMonitor is set for this @a port, turn input
  654. * monitoring on or off. Otherwise, do nothing.
  655. */
  656. int jack_port_request_monitor (jack_port_t *port, int onoff);
  657. /**
  658. * If @ref JackPortCanMonitor is set for this @a port_name, turn input
  659. * monitoring on or off. Otherwise, do nothing.
  660. *
  661. * @return 0 on success, otherwise a non-zero error code.
  662. *
  663. * @see jack_port_name_size()
  664. */
  665. int jack_port_request_monitor_by_name (jack_client_t *client,
  666. const char *port_name, int onoff);
  667. /**
  668. * If @ref JackPortCanMonitor is set for a port, this function turns
  669. * on input monitoring if it was off, and turns it off if only one
  670. * request has been made to turn it on. Otherwise it does nothing.
  671. *
  672. * @return 0 on success, otherwise a non-zero error code
  673. */
  674. int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  675. /**
  676. * @return TRUE if input monitoring has been requested for @a port.
  677. */
  678. int jack_port_monitoring_input (jack_port_t *port);
  679. /**
  680. * Establish a connection between two ports.
  681. *
  682. * When a connection exists, data written to the source port will
  683. * be available to be read at the destination port.
  684. *
  685. * @pre The port types must be identical.
  686. *
  687. * @pre The @ref JackPortFlags of the @a source_port must include @ref
  688. * JackPortIsOutput.
  689. *
  690. * @pre The @ref JackPortFlags of the @a destination_port must include
  691. * @ref JackPortIsInput.
  692. *
  693. * @return 0 on success, EEXIST if the connection is already made,
  694. * otherwise a non-zero error code
  695. */
  696. int jack_connect (jack_client_t *,
  697. const char *source_port,
  698. const char *destination_port);
  699. /**
  700. * Remove a connection between two ports.
  701. *
  702. * @pre The port types must be identical.
  703. *
  704. * @pre The @ref JackPortFlags of the @a source_port must include @ref
  705. * JackPortIsOutput.
  706. *
  707. * @pre The @ref JackPortFlags of the @a destination_port must include
  708. * @ref JackPortIsInput.
  709. *
  710. * @return 0 on success, otherwise a non-zero error code
  711. */
  712. int jack_disconnect (jack_client_t *,
  713. const char *source_port,
  714. const char *destination_port);
  715. /**
  716. * Perform the same function as jack_disconnect() using port handles
  717. * rather than names. This avoids the name lookup inherent in the
  718. * name-based version.
  719. *
  720. * Clients connecting their own ports are likely to use this function,
  721. * while generic connection clients (e.g. patchbays) would use
  722. * jack_disconnect().
  723. */
  724. int jack_port_disconnect (jack_client_t *, jack_port_t *);
  725. /**
  726. * @return the maximum number of characters in a full JACK port name
  727. * including the final NULL character. This value is a constant.
  728. *
  729. * A port's full name contains the owning client name concatenated
  730. * with a colon (:) followed by its short name and a NULL
  731. * character.
  732. */
  733. int jack_port_name_size(void);
  734. /**
  735. * @return the maximum number of characters in a JACK port type name
  736. * including the final NULL character. This value is a constant.
  737. */
  738. int jack_port_type_size(void);
  739. /*@}*/
  740. /**
  741. * @defgroup PortSearching Looking up ports
  742. * @{
  743. */
  744. /**
  745. * @param port_name_pattern A regular expression used to select
  746. * ports by name. If NULL or of zero length, no selection based
  747. * on name will be carried out.
  748. * @param type_name_pattern A regular expression used to select
  749. * ports by type. If NULL or of zero length, no selection based
  750. * on type will be carried out.
  751. * @param flags A value used to select ports by their flags.
  752. * If zero, no selection based on flags will be carried out.
  753. *
  754. * @return a NULL-terminated array of ports that match the specified
  755. * arguments. The caller is responsible for calling free(3) any
  756. * non-NULL returned value.
  757. *
  758. * @see jack_port_name_size(), jack_port_type_size()
  759. */
  760. const char **jack_get_ports (jack_client_t *,
  761. const char *port_name_pattern,
  762. const char *type_name_pattern,
  763. unsigned long flags);
  764. /**
  765. * @return address of the jack_port_t named @a port_name.
  766. *
  767. * @see jack_port_name_size()
  768. */
  769. jack_port_t *jack_port_by_name (jack_client_t *, const char *port_name);
  770. /**
  771. * @return address of the jack_port_t of a @a port_id.
  772. */
  773. jack_port_t *jack_port_by_id (jack_client_t *client,
  774. jack_port_id_t port_id);
  775. /*@}*/
  776. /**
  777. * @defgroup TimeFunctions Handling time
  778. * @{
  779. */
  780. /**
  781. * @return the time in frames that has passed since the JACK server
  782. * began the current process cycle.
  783. */
  784. jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  785. /**
  786. * @return an estimate of the current time in frames. This is a
  787. * running counter, no significance should be attached to its value,
  788. * but it can be compared to a previously returned value.
  789. */
  790. jack_nframes_t jack_frame_time (const jack_client_t *);
  791. /**
  792. * @return the frame_time after the last processing of the graph
  793. * this is only to be used from the process callback.
  794. *
  795. * This function can be used to put timestamps generated by
  796. * jack_frame_time() in correlation to the current process cycle.
  797. */
  798. jack_nframes_t jack_last_frame_time (const jack_client_t *client);
  799. /**
  800. * @return estimated time in microseconds of the specified frame time
  801. */
  802. jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t);
  803. /**
  804. * @return estimated time in frames for the specified system time.
  805. */
  806. jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t);
  807. /**
  808. * @return return JACK's current system time in microseconds,
  809. * using JACK clock source.
  810. *
  811. * The value returned is guaranteed to be monotonic, but not linear.
  812. *
  813. * This function is a client version of jack_get_microseconds().
  814. */
  815. jack_time_t jack_get_time();
  816. /*@}*/
  817. /**
  818. * @defgroup ErrorOutput Controlling error/information output
  819. */
  820. /*@{*/
  821. /**
  822. * Display JACK error message.
  823. *
  824. * Set via jack_set_error_function(), otherwise a JACK-provided
  825. * default will print @a msg (plus a newline) to stderr.
  826. *
  827. * @param msg error message text (no newline at end).
  828. */
  829. extern void (*jack_error_callback)(const char *msg);
  830. /**
  831. * Set the @ref jack_error_callback for error message display.
  832. *
  833. * The JACK library provides two built-in callbacks for this purpose:
  834. * default_jack_error_callback() and silent_jack_error_callback().
  835. */
  836. void jack_set_error_function (void (*func)(const char *));
  837. /**
  838. * Display JACK info message.
  839. *
  840. * Set via jack_set_info_function(), otherwise a JACK-provided
  841. * default will print @a msg (plus a newline) to stdout.
  842. *
  843. * @param msg info message text (no newline at end).
  844. */
  845. extern void (*jack_info_callback)(const char *msg);
  846. /**
  847. * Set the @ref jack_info_callback for info message display.
  848. */
  849. void jack_set_info_function (void (*func)(const char *));
  850. /*@}*/
  851. #ifdef __cplusplus
  852. }
  853. #endif
  854. #endif /* __jack_h__ */