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.

876 lines
32KB

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