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.

582 lines
19KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. $Id$
  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/error.h>
  24. #include <jack/transport.h>
  25. /**
  26. * Note: More documentation can be found in jack/types.h.
  27. */
  28. /**
  29. * Attemps to become an external client of the Jack server.
  30. */
  31. jack_client_t *jack_client_new (const char *client_name);
  32. /**
  33. * Disconnects an external client from a JACK server.
  34. *
  35. * @return 0 on success, otherwise a non-zero error code
  36. */
  37. int jack_client_close (jack_client_t *client);
  38. /**
  39. * @param client_name The name for the new client
  40. * @param so_name A path to a shared object file containing the code for the new client
  41. * @param so_data An arbitary string containing information to be passed to the init() routine of the new client
  42. *
  43. * Attemps to load an internal client into the Jack server.
  44. */
  45. int jack_internal_client_new (const char *client_name, const char *so_name, const char *so_data);
  46. /**
  47. * Removes an internal client from a JACK server.
  48. *
  49. * @return 0 on success, otherwise a non-zero error code
  50. */
  51. void jack_internal_client_close (const char *client_name);
  52. /**
  53. * @param client The Jack client structure.
  54. * @param function The jack_shutdown function pointer.
  55. * @param arg The arguments for the jack_shutdown function.
  56. *
  57. * Register a function (and argument) to be called if and when the
  58. * JACK server shuts down the client thread. The function must
  59. * be written as if it were an asynchonrous POSIX signal
  60. * handler --- use only async-safe functions, and remember that it
  61. * is executed from another thread. A typical function might
  62. * set a flag or write to a pipe so that the rest of the
  63. * application knows that the JACK client thread has shut
  64. * down.
  65. *
  66. * NOTE: clients do not need to call this. It exists only
  67. * to help more complex clients understand what is going
  68. * on. If called, it should be called before jack_client_activate().
  69. */
  70. void jack_on_shutdown (jack_client_t *client, void (*function)(void *arg), void *arg);
  71. /**
  72. * Tell the Jack server to call 'process_callback' whenever there is work
  73. * be done, passing 'arg' as the second argument.
  74. *
  75. * The code in the supplied function must be suitable for real-time
  76. * execution. That means that it cannot call functions that might block for
  77. * a long time.  This includes malloc, free, printf, pthread_mutex_lock,
  78. * sleep, wait, poll, select, pthread_join, pthread_cond_wait, etc, etc. 
  79. * See
  80. * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
  81. * for more information.
  82. *
  83. *
  84. * @return 0 on success, otherwise a non-zero error code
  85. */
  86. int jack_set_process_callback (jack_client_t *, JackProcessCallback process_callback, void *arg);
  87. /**
  88. * Tell the Jack server to call 'bufsize_callback' whenever the size of the
  89. * the buffer that will be passed to the process callback changes,
  90. * passing 'arg' as the second argument.
  91. *
  92. * @return 0 on success, otherwise a non-zero error code
  93. */
  94. int jack_set_buffer_size_callback (jack_client_t *, JackBufferSizeCallback bufsize_callback, void *arg);
  95. /**
  96. * Tell the Jack server to call 'srate_callback' whenever the sample rate of
  97. * the system changes.
  98. *
  99. * @return 0 on success, otherwise a non-zero error code
  100. */
  101. int jack_set_sample_rate_callback (jack_client_t *, JackSampleRateCallback srate_callback, void *arg);
  102. /**
  103. * Tell the Jack server to call 'registration_callback' whenever a port is registered
  104. * or unregistered, passing 'arg' as a second argument.
  105. *
  106. * @return 0 on success, otherwise a non-zero error code
  107. */
  108. int jack_set_port_registration_callback (jack_client_t *, JackPortRegistrationCallback registration_callback, void *arg);
  109. /**
  110. * Tell the Jack server to call 'registration_callback' whenever the processing
  111. * graph is reordered, passing 'arg' as an argument.
  112. *
  113. * @return 0 on success, otherwise a non-zero error code
  114. */
  115. int jack_set_graph_order_callback (jack_client_t *, JackGraphOrderCallback graph_callback, void *);
  116. /**
  117. * Tell the Jack server to call 'xrun_callback' whenever there is a xrun, passing
  118. * 'arg' as an argument.
  119. *
  120. * @return 0 on success, otherwise a non-zero error code
  121. */
  122. int jack_set_xrun_callback (jack_client_t *, JackXRunCallback xrun_callback, void *arg);
  123. /**
  124. * Tell the Jack server that the program is ready to start processing
  125. * audio.
  126. *
  127. * @return 0 on success, otherwise a non-zero error code
  128. */
  129. int jack_activate (jack_client_t *client);
  130. /**
  131. * Tells the Jack server that the program should be removed from the
  132. * processing graph. As a side effect, this will disconnect any
  133. * and all ports belonging to the client, since inactive clients
  134. * are not allowed to be connected to any other ports.
  135. *
  136. * @return 0 on success, otherwise a non-zero error code
  137. */
  138. int jack_deactivate (jack_client_t *client);
  139. /**
  140. * This creates a new port for the client.
  141. *
  142. * A port is an object used for moving data in or out of the client.
  143. * the data may be of any type. Ports may be connected to each other
  144. * in various ways.
  145. *
  146. * A port has a short name, which may be any non-NULL and non-zero
  147. * length string, and is passed as the first argument. A port's full
  148. * name is the name of the client concatenated with a colon (:) and
  149. * then its short name.
  150. *
  151. * A port has a type, which may be any non-NULL and non-zero length
  152. * string, and is passed as the second argument. For types that are
  153. * not built into the jack API (currently just
  154. * JACK_DEFAULT_AUDIO_TYPE) the client MUST supply a non-zero size
  155. * for the buffer as for 'buffer_size' . For builtin types,
  156. * 'buffer_size' is ignored.
  157. *
  158. * The 'flags' argument is formed from a bitmask of JackPortFlags values.
  159. */
  160. jack_port_t *jack_port_register (jack_client_t *,
  161. const char *port_name,
  162. const char *port_type,
  163. unsigned long flags,
  164. unsigned long buffer_size);
  165. /**
  166. * This removes the port from the client, disconnecting
  167. * any existing connections at the same time.
  168. *
  169. * @return 0 on success, otherwise a non-zero error code
  170. */
  171. int jack_port_unregister (jack_client_t *, jack_port_t *);
  172. /**
  173. * This returns a pointer to the memory area associated with the
  174. * specified port. For an output port, it will be a memory area
  175. * that can be written to; for an input port, it will be an area
  176. * containing the data from the port's connection(s), or
  177. * zero-filled. if there are multiple inbound connections, the data
  178. * will be mixed appropriately.
  179. *
  180. * You may cache the value returned, but only between calls to
  181. * your "blocksize" callback. For this reason alone, you should
  182. * either never cache the return value or ensure you have
  183. * a "blocksize" callback and be sure to invalidate the cached
  184. * address from there.
  185. */
  186. void *jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  187. /**
  188. * Returns the name of the jack_port_t.
  189. */
  190. const char * jack_port_name (const jack_port_t *port);
  191. /**
  192. * Returns the short name of the jack_port_t.
  193. */
  194. const char * jack_port_short_name (const jack_port_t *port);
  195. /**
  196. * Returns the flags of the jack_port_t.
  197. */
  198. int jack_port_flags (const jack_port_t *port);
  199. /**
  200. * Returns the type of the jack_port_t.
  201. */
  202. const char * jack_port_type (const jack_port_t *port);
  203. /**
  204. * Returns 1 if the jack_port_t belongs to the jack_client_t.
  205. */
  206. int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  207. /**
  208. * This returns a positive integer indicating the number
  209. * of connections to or from 'port'.
  210. *
  211. * ®pre The calling client must own 'port'.
  212. */
  213. int jack_port_connected (const jack_port_t *port);
  214. /**
  215. * This returns TRUE or FALSE if the port argument is
  216. * DIRECTLY connected to the port with the name given in 'portname'
  217. *
  218. * @pre The calling client must own 'port'.
  219. */
  220. int jack_port_connected_to (const jack_port_t *port, const char *portname);
  221. /**
  222. * This returns a null-terminated array of port names to which
  223. * the argument port is connected. if there are no connections, it
  224. * returns NULL.
  225. *
  226. * The caller is responsible for calling free(3) on any
  227. * non-NULL returned value.
  228. *
  229. * @pre The calling client must own 'port'.
  230. *
  231. * See jack_port_get_all_connections() for an alternative.
  232. */
  233. const char ** jack_port_get_connections (const jack_port_t *port);
  234. /**
  235. * This returns a null-terminated array of port names to which
  236. * the argument port is connected. if there are no connections, it
  237. * returns NULL.
  238. *
  239. * The caller is responsible for calling free(3) on any
  240. * non-NULL returned value.
  241. *
  242. * It differs from jack_port_get_connections() in two important
  243. * respects:
  244. *
  245. * 1) You may not call this function from code that is
  246. * executed in response to a JACK event. For example,
  247. * you cannot use it in a GraphReordered handler.
  248. *
  249. * 2) You need not be the owner of the port to get information
  250. * about its connections.
  251. */
  252. const char ** jack_port_get_all_connections (const jack_client_t *client, const jack_port_t *port);
  253. /**
  254. * A client may call this on a pair of its own ports to
  255. * semi-permanently wire them together. This means that
  256. * a client that wants to direct-wire an input port to
  257. * an output port can call this and then no longer
  258. * have to worry about moving data between them. Any data
  259. * arriving at the input port will appear automatically
  260. * at the output port.
  261. *
  262. * The 'destination' port must be an output port. The 'source'
  263. * port must be an input port. Both ports must belong to
  264. * the same client. You cannot use this to tie ports between
  265. * clients. That is what a connection is for.
  266. *
  267. * @return 0 on success, otherwise a non-zero error code
  268. */
  269. int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  270. /**
  271. * This undoes the effect of jack_port_tie(). The port
  272. * should be same as the 'destination' port passed to
  273. * jack_port_tie().
  274. *
  275. * @return 0 on success, otherwise a non-zero error code
  276. */
  277. int jack_port_untie (jack_port_t *port);
  278. /**
  279. * A client may call this function to prevent other objects
  280. * from changing the connection status of a port. The port
  281. * must be owned by the calling client.
  282. *
  283. * @return 0 on success, otherwise a non-zero error code
  284. */
  285. int jack_port_lock (jack_client_t *, jack_port_t *);
  286. /**
  287. * This allows other objects to change the connection status of a port.
  288. *
  289. * @return 0 on success, otherwise a non-zero error code
  290. */
  291. int jack_port_unlock (jack_client_t *, jack_port_t *);
  292. /**
  293. * Returns the time (in frames) between data being available
  294. * or delivered at/to a port, and the time at which it
  295. * arrived at or is delivered to the "other side" of the port.
  296. * E.g. for a physical audio output port, this is the time between
  297. * writing to the port and when the audio will be audible.
  298. * For a physical audio input port, this is the time between the sound
  299. * being audible and the corresponding frames being readable from the
  300. * port.
  301. */
  302. jack_nframes_t jack_port_get_latency (jack_port_t *port);
  303. /**
  304. * The maximum of the sum of the latencies in every
  305. * connection path that can be drawn between the port and other
  306. * ports with the JackPortIsTerminal flag set.
  307. */
  308. jack_nframes_t jack_port_get_total_latency (jack_client_t *, jack_port_t *port);
  309. /**
  310. * The port latency is zero by default. Clients that control
  311. * physical hardware with non-zero latency should call this
  312. * to set the latency to its correct value. Note that the value
  313. * should include any systemic latency present "outside" the
  314. * physical hardware controlled by the client. For example,
  315. * for a client controlling a digital audio interface connected
  316. * to an external digital converter, the latency setting should
  317. * include both buffering by the audio interface *and* the converter.
  318. */
  319. void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  320. /**
  321. * This modifies a port's name, and may be called at any time.
  322. *
  323. * @return 0 on success, otherwise a non-zero error code
  324. */
  325. int jack_port_set_name (jack_port_t *port, const char *name);
  326. /**
  327. */
  328. double jack_port_get_peak (jack_port_t*, jack_nframes_t);
  329. /**
  330. */
  331. double jack_port_get_power (jack_port_t*, jack_nframes_t);
  332. /**
  333. */
  334. void jack_port_set_peak_function (jack_port_t *, double (*func)(jack_port_t*, jack_nframes_t));
  335. /**
  336. */
  337. void jack_port_set_power_function (jack_port_t *, double (*func)(jack_port_t*, jack_nframes_t));
  338. /**
  339. * If JackPortCanMonitor is set for a port, then these 2 functions will
  340. * turn on/off input monitoring for the port. If JackPortCanMonitor
  341. * is not set, then these functions will have no effect.
  342. */
  343. int jack_port_request_monitor (jack_port_t *port, int onoff);
  344. /**
  345. * If JackPortCanMonitor is set for a port, then these 2 functions will
  346. * turn on/off input monitoring for the port. If JackPortCanMonitor
  347. * is not set, then these functions will have no effect.
  348. *
  349. * @return 0 on success, otherwise a non-zero error code
  350. */
  351. int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff);
  352. /**
  353. * If JackPortCanMonitor is set for a port, then this function will
  354. * turn on input monitoring if it was off, and will turn it off it
  355. * only one request has been made to turn it on. If JackPortCanMonitor
  356. * is not set, then this function will do nothing.
  357. *
  358. * @return 0 on success, otherwise a non-zero error code
  359. */
  360. int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  361. /**
  362. * Returns a true or false value depending on whether or not
  363. * input monitoring has been requested for 'port'.
  364. */
  365. int jack_port_monitoring_input (jack_port_t *port);
  366. /**
  367. * Establishes a connection between two ports.
  368. *
  369. * When a connection exists, data written to the source port will
  370. * be available to be read at the destination port.
  371. *
  372. * @pre The types of both ports must be identical to establish a connection.
  373. * @pre The flags of the source port must include PortIsOutput.
  374. * @pre The flags of the destination port must include PortIsInput.
  375. *
  376. * @return 0 on success, otherwise a non-zero error code
  377. */
  378. int jack_connect (jack_client_t *,
  379. const char *source_port,
  380. const char *destination_port);
  381. /**
  382. * Removes a connection between two ports.
  383. *
  384. * @pre The types of both ports must be identical to establish a connection.
  385. * @pre The flags of the source port must include PortIsOutput.
  386. * @pre The flags of the destination port must include PortIsInput.
  387. *
  388. * @return 0 on success, otherwise a non-zero error code
  389. */
  390. int jack_disconnect (jack_client_t *,
  391. const char *source_port,
  392. const char *destination_port);
  393. /**
  394. * Performs the exact same function as jack_connect(), but it uses
  395. * port handles rather than names, which avoids the name lookup inherent
  396. * in the name-based version.
  397. *
  398. * It is envisaged that clients connecting their own ports will use these
  399. * two, whereas generic connection clients (e.g. patchbays) will use the
  400. * name-based versions.
  401. *
  402. * @return 0 on success, otherwise a non-zero error code
  403. */
  404. int jack_port_connect (jack_client_t *, jack_port_t *src, jack_port_t *dst);
  405. /**
  406. * Performs the exact same function as jack_disconnect(), but it uses
  407. * port handles rather than names, which avoids the name lookup inherent
  408. * in the name-based version.
  409. *
  410. * It is envisaged that clients disconnecting their own ports will use these
  411. * two, whereas generic connection clients (e.g. patchbays) will use the
  412. * name-based versions.
  413. */
  414. int jack_port_disconnect (jack_client_t *, jack_port_t *);
  415. /**
  416. * This returns the sample rate of the jack system, as set by the user when
  417. * jackd was started.
  418. */
  419. unsigned long jack_get_sample_rate (jack_client_t *);
  420. /**
  421. * This returns the current maximum size that will
  422. * ever be passed to the "process" callback. It should only
  423. * be used *before* the client has been activated. After activation,
  424. * the client will be notified of buffer size changes if it
  425. * registers a buffer_size callback.
  426. */
  427. jack_nframes_t jack_get_buffer_size (jack_client_t *);
  428. /**
  429. * @param port_name_pattern A regular expression used to select
  430. * ports by name. If NULL or of zero length, no selection based
  431. * on name will be carried out.
  432. * @param type_name_pattern A regular expression used to select
  433. * ports by type. If NULL or of zero length, no selection based
  434. * on type will be carried out.
  435. * @param flags A value used to select ports by their flags.
  436. * If zero, no selection based on flags will be carried out.
  437. *
  438. * This function returns a NULL-terminated array of ports that match
  439. * the specified arguments.
  440. * The caller is responsible for calling free(3) any non-NULL returned value.
  441. */
  442. const char ** jack_get_ports (jack_client_t *,
  443. const char *port_name_pattern,
  444. const char *type_name_pattern,
  445. unsigned long flags);
  446. /**
  447. * Searchs for and returns the jack_port_t with the name value
  448. * from portname.
  449. */
  450. jack_port_t *jack_port_by_name (jack_client_t *, const char *portname);
  451. /**
  452. * Searchs for and returns the jack_port_t of id 'id'.
  453. */
  454. jack_port_t *jack_port_by_id (const jack_client_t *client, jack_port_id_t id);
  455. /**
  456. * If a client is told (by the user) to become the timebase
  457. * for the entire system, it calls this function. If it
  458. * returns zero, then the client has the responsibility to
  459. * call jack_set_transport_info()) at the end of its process()
  460. * callback.
  461. *
  462. * @return 0 on success, otherwise a non-zero error code
  463. */
  464. int jack_engine_takeover_timebase (jack_client_t *);
  465. /**
  466. * undocumented
  467. */
  468. void jack_update_time (jack_client_t *, jack_nframes_t);
  469. /**
  470. * This estimates the time that has passed since the
  471. * start jack server started calling the process()
  472. * callbacks of all its clients.
  473. */
  474. jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  475. /**
  476. * Return an estimate of the current time in frames. It is a running
  477. * counter - no significance should be attached to the return
  478. * value. it should be used to compute the difference between
  479. * a previously returned value.
  480. */
  481. jack_nframes_t jack_frame_time (const jack_client_t *);
  482. /**
  483. * This returns the current CPU load estimated by JACK
  484. * as a percentage. The load is computed by measuring
  485. * the amount of time it took to execute all clients
  486. * as a fraction of the total amount of time
  487. * represented by the data that was processed.
  488. */
  489. float jack_cpu_load (jack_client_t *client);
  490. /**
  491. * Set the directory in which the server is expected
  492. * to have put its communication FIFOs. A client
  493. * will need to call this before calling
  494. * jack_client_new() if the server was started
  495. * with arguments telling it to use a non-standard
  496. * directory.
  497. */
  498. void jack_set_server_dir (const char *path);
  499. /**
  500. * Return the pthread ID of the thread running the JACK client
  501. * side code.
  502. */
  503. pthread_t jack_client_thread_id (jack_client_t *);
  504. #ifdef __cplusplus
  505. }
  506. #endif
  507. #endif /* __jack_h__ */