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.

585 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. * FOR OUTPUT PORTS ONLY
  181. * ---------------------
  182. * You may cache the value returned, but only between calls to
  183. * your "blocksize" callback. For this reason alone, you should
  184. * either never cache the return value or ensure you have
  185. * a "blocksize" callback and be sure to invalidate the cached
  186. * address from there.
  187. */
  188. void *jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  189. /**
  190. * Returns the name of the jack_port_t.
  191. */
  192. const char * jack_port_name (const jack_port_t *port);
  193. /**
  194. * Returns the short name of the jack_port_t.
  195. */
  196. const char * jack_port_short_name (const jack_port_t *port);
  197. /**
  198. * Returns the flags of the jack_port_t.
  199. */
  200. int jack_port_flags (const jack_port_t *port);
  201. /**
  202. * Returns the type of the jack_port_t.
  203. */
  204. const char * jack_port_type (const jack_port_t *port);
  205. /**
  206. * Returns 1 if the jack_port_t belongs to the jack_client_t.
  207. */
  208. int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  209. /**
  210. * This returns a positive integer indicating the number
  211. * of connections to or from 'port'.
  212. *
  213. * ®pre The calling client must own 'port'.
  214. */
  215. int jack_port_connected (const jack_port_t *port);
  216. /**
  217. * This returns TRUE or FALSE if the port argument is
  218. * DIRECTLY connected to the port with the name given in 'portname'
  219. *
  220. * @pre The calling client must own 'port'.
  221. */
  222. int jack_port_connected_to (const jack_port_t *port, const char *portname);
  223. /**
  224. * This returns a null-terminated array of port names to which
  225. * the argument port is connected. if there are no connections, it
  226. * returns NULL.
  227. *
  228. * The caller is responsible for calling free(3) on any
  229. * non-NULL returned value.
  230. *
  231. * @pre The calling client must own 'port'.
  232. *
  233. * See jack_port_get_all_connections() for an alternative.
  234. */
  235. const char ** jack_port_get_connections (const jack_port_t *port);
  236. /**
  237. * This returns a null-terminated array of port names to which
  238. * the argument port is connected. if there are no connections, it
  239. * returns NULL.
  240. *
  241. * The caller is responsible for calling free(3) on any
  242. * non-NULL returned value.
  243. *
  244. * It differs from jack_port_get_connections() in two important
  245. * respects:
  246. *
  247. * 1) You may not call this function from code that is
  248. * executed in response to a JACK event. For example,
  249. * you cannot use it in a GraphReordered handler.
  250. *
  251. * 2) You need not be the owner of the port to get information
  252. * about its connections.
  253. */
  254. const char ** jack_port_get_all_connections (const jack_client_t *client, const jack_port_t *port);
  255. /**
  256. * A client may call this on a pair of its own ports to
  257. * semi-permanently wire them together. This means that
  258. * a client that wants to direct-wire an input port to
  259. * an output port can call this and then no longer
  260. * have to worry about moving data between them. Any data
  261. * arriving at the input port will appear automatically
  262. * at the output port.
  263. *
  264. * The 'destination' port must be an output port. The 'source'
  265. * port must be an input port. Both ports must belong to
  266. * the same client. You cannot use this to tie ports between
  267. * clients. That is what a connection is for.
  268. *
  269. * @return 0 on success, otherwise a non-zero error code
  270. */
  271. int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  272. /**
  273. * This undoes the effect of jack_port_tie(). The port
  274. * should be same as the 'destination' port passed to
  275. * jack_port_tie().
  276. *
  277. * @return 0 on success, otherwise a non-zero error code
  278. */
  279. int jack_port_untie (jack_port_t *port);
  280. /**
  281. * A client may call this function to prevent other objects
  282. * from changing the connection status of a port. The port
  283. * must be owned by the calling client.
  284. *
  285. * @return 0 on success, otherwise a non-zero error code
  286. */
  287. int jack_port_lock (jack_client_t *, jack_port_t *);
  288. /**
  289. * This allows other objects to change the connection status of a port.
  290. *
  291. * @return 0 on success, otherwise a non-zero error code
  292. */
  293. int jack_port_unlock (jack_client_t *, jack_port_t *);
  294. /**
  295. * Returns the time (in frames) between data being
  296. * available or delivered at/to a port, and the time at
  297. * which it arrived at or is delivered to the "other side"
  298. * of the port. E.g. for a physical audio output port, this
  299. * is the time between writing to the port and when the
  300. * signal will leave the connector. For a physical audio
  301. * input port, this is the time between the sound arriving
  302. * at the connector and the corresponding frames being
  303. * readable from the port.
  304. */
  305. jack_nframes_t jack_port_get_latency (jack_port_t *port);
  306. /**
  307. * The maximum of the sum of the latencies in every
  308. * connection path that can be drawn between the port and other
  309. * ports with the JackPortIsTerminal flag set.
  310. */
  311. jack_nframes_t jack_port_get_total_latency (jack_client_t *, jack_port_t *port);
  312. /**
  313. * The port latency is zero by default. Clients that control
  314. * physical hardware with non-zero latency should call this
  315. * to set the latency to its correct value. Note that the value
  316. * should include any systemic latency present "outside" the
  317. * physical hardware controlled by the client. For example,
  318. * for a client controlling a digital audio interface connected
  319. * to an external digital converter, the latency setting should
  320. * include both buffering by the audio interface *and* the converter.
  321. */
  322. void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  323. /**
  324. * This modifies a port's name, and may be called at any time.
  325. *
  326. * @return 0 on success, otherwise a non-zero error code
  327. */
  328. int jack_port_set_name (jack_port_t *port, const char *name);
  329. /**
  330. */
  331. double jack_port_get_peak (jack_port_t*, jack_nframes_t);
  332. /**
  333. */
  334. double jack_port_get_power (jack_port_t*, jack_nframes_t);
  335. /**
  336. */
  337. void jack_port_set_peak_function (jack_port_t *, double (*func)(jack_port_t*, jack_nframes_t));
  338. /**
  339. */
  340. void jack_port_set_power_function (jack_port_t *, double (*func)(jack_port_t*, jack_nframes_t));
  341. /**
  342. * If JackPortCanMonitor is set for a port, then these 2 functions will
  343. * turn on/off input monitoring for the port. If JackPortCanMonitor
  344. * is not set, then these functions will have no effect.
  345. */
  346. int jack_port_request_monitor (jack_port_t *port, int onoff);
  347. /**
  348. * If JackPortCanMonitor is set for a port, then these 2 functions will
  349. * turn on/off input monitoring for the port. If JackPortCanMonitor
  350. * is not set, then these functions will have no effect.
  351. *
  352. * @return 0 on success, otherwise a non-zero error code
  353. */
  354. int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff);
  355. /**
  356. * If JackPortCanMonitor is set for a port, then this function will
  357. * turn on input monitoring if it was off, and will turn it off it
  358. * only one request has been made to turn it on. If JackPortCanMonitor
  359. * is not set, then this function will do nothing.
  360. *
  361. * @return 0 on success, otherwise a non-zero error code
  362. */
  363. int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  364. /**
  365. * Returns a true or false value depending on whether or not
  366. * input monitoring has been requested for 'port'.
  367. */
  368. int jack_port_monitoring_input (jack_port_t *port);
  369. /**
  370. * Establishes a connection between two ports.
  371. *
  372. * When a connection exists, data written to the source port will
  373. * be available to be read at the destination port.
  374. *
  375. * @pre The types of both ports must be identical to establish a connection.
  376. * @pre The flags of the source port must include PortIsOutput.
  377. * @pre The flags of the destination port must include PortIsInput.
  378. *
  379. * @return 0 on success, otherwise a non-zero error code
  380. */
  381. int jack_connect (jack_client_t *,
  382. const char *source_port,
  383. const char *destination_port);
  384. /**
  385. * Removes a connection between two ports.
  386. *
  387. * @pre The types of both ports must be identical to establish a connection.
  388. * @pre The flags of the source port must include PortIsOutput.
  389. * @pre The flags of the destination port must include PortIsInput.
  390. *
  391. * @return 0 on success, otherwise a non-zero error code
  392. */
  393. int jack_disconnect (jack_client_t *,
  394. const char *source_port,
  395. const char *destination_port);
  396. /**
  397. * Performs the exact same function as jack_connect(), but it uses
  398. * port handles rather than names, which avoids the name lookup inherent
  399. * in the name-based version.
  400. *
  401. * It is envisaged that clients connecting their own ports will use these
  402. * two, whereas generic connection clients (e.g. patchbays) will use the
  403. * name-based versions.
  404. *
  405. * @return 0 on success, otherwise a non-zero error code
  406. */
  407. int jack_port_connect (jack_client_t *, jack_port_t *src, jack_port_t *dst);
  408. /**
  409. * Performs the exact same function as jack_disconnect(), but it uses
  410. * port handles rather than names, which avoids the name lookup inherent
  411. * in the name-based version.
  412. *
  413. * It is envisaged that clients disconnecting their own ports will use these
  414. * two, whereas generic connection clients (e.g. patchbays) will use the
  415. * name-based versions.
  416. */
  417. int jack_port_disconnect (jack_client_t *, jack_port_t *);
  418. /**
  419. * This returns the sample rate of the jack system, as set by the user when
  420. * jackd was started.
  421. */
  422. unsigned long jack_get_sample_rate (jack_client_t *);
  423. /**
  424. * This returns the current maximum size that will
  425. * ever be passed to the "process" callback. It should only
  426. * be used *before* the client has been activated. After activation,
  427. * the client will be notified of buffer size changes if it
  428. * registers a buffer_size callback.
  429. */
  430. jack_nframes_t jack_get_buffer_size (jack_client_t *);
  431. /**
  432. * @param port_name_pattern A regular expression used to select
  433. * ports by name. If NULL or of zero length, no selection based
  434. * on name will be carried out.
  435. * @param type_name_pattern A regular expression used to select
  436. * ports by type. If NULL or of zero length, no selection based
  437. * on type will be carried out.
  438. * @param flags A value used to select ports by their flags.
  439. * If zero, no selection based on flags will be carried out.
  440. *
  441. * This function returns a NULL-terminated array of ports that match
  442. * the specified arguments.
  443. * The caller is responsible for calling free(3) any non-NULL returned value.
  444. */
  445. const char ** jack_get_ports (jack_client_t *,
  446. const char *port_name_pattern,
  447. const char *type_name_pattern,
  448. unsigned long flags);
  449. /**
  450. * Searchs for and returns the jack_port_t with the name value
  451. * from portname.
  452. */
  453. jack_port_t *jack_port_by_name (jack_client_t *, const char *portname);
  454. /**
  455. * Searchs for and returns the jack_port_t of id 'id'.
  456. */
  457. jack_port_t *jack_port_by_id (const jack_client_t *client, jack_port_id_t id);
  458. /**
  459. * If a client is told (by the user) to become the timebase
  460. * for the entire system, it calls this function. If it
  461. * returns zero, then the client has the responsibility to
  462. * call jack_set_transport_info()) at the end of its process()
  463. * callback.
  464. *
  465. * @return 0 on success, otherwise a non-zero error code
  466. */
  467. int jack_engine_takeover_timebase (jack_client_t *);
  468. /**
  469. * undocumented
  470. */
  471. void jack_update_time (jack_client_t *, jack_nframes_t);
  472. /**
  473. * This estimates the time that has passed since the
  474. * start jack server started calling the process()
  475. * callbacks of all its clients.
  476. */
  477. jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  478. /**
  479. * Return an estimate of the current time in frames. It is a running
  480. * counter - no significance should be attached to the return
  481. * value. it should be used to compute the difference between
  482. * a previously returned value.
  483. */
  484. jack_nframes_t jack_frame_time (const jack_client_t *);
  485. /**
  486. * This returns the current CPU load estimated by JACK
  487. * as a percentage. The load is computed by measuring
  488. * the amount of time it took to execute all clients
  489. * as a fraction of the total amount of time
  490. * represented by the data that was processed.
  491. */
  492. float jack_cpu_load (jack_client_t *client);
  493. /**
  494. * Set the directory in which the server is expected
  495. * to have put its communication FIFOs. A client
  496. * will need to call this before calling
  497. * jack_client_new() if the server was started
  498. * with arguments telling it to use a non-standard
  499. * directory.
  500. */
  501. void jack_set_server_dir (const char *path);
  502. /**
  503. * Return the pthread ID of the thread running the JACK client
  504. * side code.
  505. */
  506. pthread_t jack_client_thread_id (jack_client_t *);
  507. #ifdef __cplusplus
  508. }
  509. #endif
  510. #endif /* __jack_h__ */