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.

456 lines
15KB

  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 <jack/types.h>
  22. #include <jack/error.h>
  23. #include <jack/transport.h>
  24. /**
  25. * Note: More documentation can be found in jack/types.h.
  26. */
  27. /**
  28. * Attemps to become a client of the Jack server.
  29. */
  30. jack_client_t *jack_client_new (const char *client_name);
  31. /**
  32. * Disconnects from Jack server.
  33. */
  34. int jack_client_close (jack_client_t *client);
  35. /**
  36. * @param client The Jack client structure.
  37. * @param function The jack_shutdown function pointer.
  38. * @param arg The arguments for the jack_shutdown function.
  39. *
  40. * Register a function (and argument) to be called if and when the
  41. * JACK server shuts down the client thread. The function must
  42. * be written as if it were an asynchonrous POSIX signal
  43. * handler --- use only async-safe functions, and remember that it
  44. * is executed from another thread. A typical function might
  45. * set a flag or write to a pipe so that the rest of the
  46. * application knows that the JACK client thread has shut
  47. * down.
  48. *
  49. * NOTE: clients do not need to call this. It exists only
  50. * to help more complex clients understand what is going
  51. * on. If called, it must be called before jack_client_activate().
  52. */
  53. void jack_on_shutdown (jack_client_t *client, void (*function)(void *arg), void *arg);
  54. /**
  55. * Tell the Jack server to call 'process_callback' whenever there is work
  56. * be done, passing 'arg' as the second argument.
  57. */
  58. int jack_set_process_callback (jack_client_t *, JackProcessCallback process_callback, void *arg);
  59. /**
  60. * Tell the Jack server to call 'bufsize_callback' whenever the
  61. * maximum number of frames that could be passed to 'process()'
  62. * changes. 'arg' will be supplied as a second argument.
  63. */
  64. int jack_set_buffer_size_callback (jack_client_t *, JackBufferSizeCallback bufsize_callback, void *arg);
  65. /**
  66. * Tell the Jack server to call 'srate_callback' whenever the sample rate of
  67. * the system changes.
  68. */
  69. int jack_set_sample_rate_callback (jack_client_t *, JackSampleRateCallback srate_callback, void *arg);
  70. /**
  71. * Tell the Jack server to call 'registration_callback' whenever a port is registered
  72. * or unregistered, passing 'arg' as a second argument.
  73. */
  74. int jack_set_port_registration_callback (jack_client_t *, JackPortRegistrationCallback registration_callback, void *arg);
  75. /**
  76. * Tell the Jack server to call 'registration_callback' whenever the processing
  77. * graph is reordered, passing 'arg' as an argument.
  78. */
  79. int jack_set_graph_order_callback (jack_client_t *, JackGraphOrderCallback graph_callback, void *);
  80. /**
  81. * Tell the Jack server to call 'xrun_callback' whenever there is a xrun, passing
  82. * 'arg' as an argument.
  83. */
  84. int jack_set_xrun_callback (jack_client_t *, JackXRunCallback xrun_callback, void *arg);
  85. /**
  86. * Tell the Jack server that the program is ready to start processing
  87. * audio.
  88. */
  89. int jack_activate (jack_client_t *client);
  90. /**
  91. * Tells the Jack server that the program should be removed from the
  92. * processing graph. As a side effect, this will disconnect any
  93. * and all ports belonging to the client, since inactive clients
  94. * are not allowed to be connected to any other ports.
  95. */
  96. int jack_deactivate (jack_client_t *client);
  97. /**
  98. * This creates a new port for the client.
  99. *
  100. * A port is an object used for moving data in or out of the client.
  101. * the data may be of any type. Ports may be connected to each other
  102. * in various ways.
  103. *
  104. * A port has a short name, which may be any non-NULL and non-zero
  105. * length string, and is passed as the first argument. A port's full
  106. * name is the name of the client concatenated with a colon (:) and
  107. * then its short name.
  108. *
  109. * A port has a type, which may be any non-NULL and non-zero length
  110. * string, and is passed as the second argument. For types that are
  111. * not built into the jack API (currently just
  112. * JACK_DEFAULT_AUDIO_TYPE) the client MUST supply a non-zero size
  113. * for the buffer as for @buffer_size. For builtin types,
  114. * @buffer_size is ignored.
  115. *
  116. * The @flags argument is formed from a bitmask of JackPortFlags values.
  117. */
  118. jack_port_t *jack_port_register (jack_client_t *,
  119. const char *port_name,
  120. const char *port_type,
  121. unsigned long flags,
  122. unsigned long buffer_size);
  123. /**
  124. * This removes the port from the client, disconnecting
  125. * any existing connections at the same time.
  126. */
  127. int jack_port_unregister (jack_client_t *, jack_port_t *);
  128. /**
  129. * Returns the name of the jack_port_t.
  130. */
  131. const char * jack_port_name (const jack_port_t *port);
  132. /**
  133. * Returns the short name of the jack_port_t.
  134. */
  135. const char * jack_port_short_name (const jack_port_t *port);
  136. /**
  137. * Returns the flags of the jack_port_t.
  138. */
  139. int jack_port_flags (const jack_port_t *port);
  140. /**
  141. * Returns the type of the jack_port_t.
  142. */
  143. const char * jack_port_type (const jack_port_t *port);
  144. /**
  145. * Returns 1 if the jack_port_t belongs to the jack_client_t.
  146. */
  147. int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  148. /**
  149. * This returns TRUE or FALSE to indicate if there are
  150. * any connections to/from the port argument.
  151. */
  152. int jack_port_connected (const jack_port_t *port);
  153. /**
  154. * This returns TRUE or FALSE if the port argument is
  155. * DIRECTLY connected to the port with the name given in 'portname'
  156. */
  157. int jack_port_connected_to (const jack_port_t *port, const char *portname);
  158. /**
  159. * This returns TRUE or FALSE if the two ports are
  160. * directly connected to each other.
  161. */
  162. int jack_port_connected_to_port (const jack_port_t *port, const jack_port_t *other_port);
  163. /**
  164. * This returns a null-terminated array of port names to which
  165. * the argument port is connected. if there are no connections, it
  166. * returns NULL.
  167. *
  168. * The caller is responsible for calling free(3) on any
  169. * non-NULL returned value.
  170. */
  171. const char ** jack_port_get_connections (const jack_port_t *port);
  172. /**
  173. * This modifies a port's name, and may be called at any time.
  174. */
  175. int jack_port_set_name (jack_port_t *port, const char *name);
  176. /**
  177. * This returns a pointer to the memory area associated with the
  178. * specified port. For an output port, it will be a memory area
  179. * that can be written to; for an input port, it will be an area
  180. * containing the data from the port's connection(s), or
  181. * zero-filled. if there are multiple inbound connections, the data
  182. * will be mixed appropriately.
  183. *
  184. * You may cache the value returned, but only between calls to
  185. * your "blocksize" callback. For this reason alone, you should
  186. * either never cache the return value or ensure you have
  187. * a "blocksize" callback and be sure to invalidate the cached
  188. * address from there.
  189. */
  190. void *jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  191. /**
  192. * Establishes a connection between two ports.
  193. *
  194. * When a connection exists, data written to the source port will
  195. * be available to be read at the destination port.
  196. *
  197. * The types of both ports must be identical to establish a connection.
  198. * The flags of the source port must include PortIsOutput.
  199. * The flags of the destination port must include PortIsInput.
  200. */
  201. int jack_connect (jack_client_t *,
  202. const char *source_port,
  203. const char *destination_port);
  204. /**
  205. * Removes a connection between two ports.
  206. *
  207. * The types of both ports must be identical to establish a connection.
  208. * The flags of the source port must include PortIsOutput.
  209. * The flags of the destination port must include PortIsInput.
  210. */
  211. int jack_disconnect (jack_client_t *,
  212. const char *source_port,
  213. const char *destination_port);
  214. /**
  215. * Performs the exact same function as jack_connect(), but it uses
  216. * port handles rather than names, which avoids the name lookup inherent
  217. * in the name-based version.
  218. *
  219. * It is envisaged that clients connecting their own ports will use these
  220. * two, whereas generic connection clients (e.g. patchbays) will use the
  221. * name-based versions.
  222. */
  223. int jack_port_connect (jack_client_t *, jack_port_t *src, jack_port_t *dst);
  224. /**
  225. * Performs the exact same function as jack_disconnect(), but it uses
  226. * port handles rather than names, which avoids the name lookup inherent
  227. * in the name-based version.
  228. *
  229. * It is envisaged that clients disconnecting their own ports will use these
  230. * two, whereas generic connection clients (e.g. patchbays) will use the
  231. * name-based versions.
  232. */
  233. int jack_port_disconnect (jack_client_t *, jack_port_t *);
  234. /**
  235. * A client may call this on a pair of its own ports to
  236. * semi-permanently wire them together. This means that
  237. * a client that wants to direct-wire an input port to
  238. * an output port can call this and then no longer
  239. * have to worry about moving data between them. Any data
  240. * arriving at the input port will appear automatically
  241. * at the output port.
  242. *
  243. * The 'destination' port must be an output port. The 'source'
  244. * port must be an input port. Both ports must belong to
  245. * the same client. You cannot use this to tie ports between
  246. * clients. That is what a connection is for.
  247. */
  248. int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  249. /**
  250. * This undoes the effect of jack_port_tie(). The port
  251. * should be same as the 'destination' port passed to
  252. * jack_port_tie().
  253. */
  254. int jack_port_untie (jack_port_t *port);
  255. /**
  256. * A client may call this function to prevent other objects
  257. * from changing the connection status of a port. The port
  258. * must be owned by the calling client.
  259. */
  260. int jack_port_lock (jack_client_t *, jack_port_t *);
  261. /**
  262. * This allows other objects to change the connection status of a port.
  263. */
  264. int jack_port_unlock (jack_client_t *, jack_port_t *);
  265. /**
  266. * Returns the time (in frames) between data being available
  267. * or delivered at/to a port, and the time at which it
  268. * arrived at or is delivered to the "other side" of the port.
  269. * E.g. for a physical audio output port, this is the time between
  270. * writing to the port and when the audio will be audible.
  271. * For a physical audio input port, this is the time between the sound
  272. * being audible and the corresponding frames being readable from the
  273. * port.
  274. */
  275. jack_nframes_t jack_port_get_latency (jack_port_t *port);
  276. /**
  277. * The maximum of the sum of the latencies in every
  278. * connection path that can be drawn between the port and other
  279. * ports with the JackPortIsTerminal flag set.
  280. */
  281. jack_nframes_t jack_port_get_total_latency (jack_client_t *, jack_port_t *port);
  282. /**
  283. * The port latency is zero by default. Clients that control
  284. * physical hardware with non-zero latency should call this
  285. * to set the latency to its correct value. Note that the value
  286. * should include any systemic latency present "outside" the
  287. * physical hardware controlled by the client. For example,
  288. * for a client controlling a digital audio interface connected
  289. * to an external digital converter, the latency setting should
  290. * include both buffering by the audio interface *and* the converter.
  291. */
  292. void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  293. /**
  294. * If JackPortCanMonitor is set for a port, then these 2 functions will
  295. * turn on/off input monitoring for the port. If JackPortCanMonitor
  296. * is not set, then these functions will have no effect.
  297. */
  298. int jack_port_request_monitor (jack_port_t *port, int onoff);
  299. /**
  300. * If JackPortCanMonitor is set for a port, then these 2 functions will
  301. * turn on/off input monitoring for the port. If JackPortCanMonitor
  302. * is not set, then these functions will have no effect.
  303. */
  304. int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff);
  305. /**
  306. * If JackPortCanMonitor is set for a port, then this function will
  307. * turn on input monitoring if it was off, and will turn it off it
  308. * only one request has been made to turn it on. If JackPortCanMonitor
  309. * is not set, then this function will do nothing.
  310. */
  311. int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  312. /**
  313. * Returns a true or false value depending on whether or not
  314. * input monitoring has been requested for 'port'.
  315. */
  316. int jack_port_monitoring_input (jack_port_t *port);
  317. /**
  318. * This returns the sample rate of the jack system, as set by the user when
  319. * jackd was started.
  320. */
  321. unsigned long jack_get_sample_rate (jack_client_t *);
  322. /**
  323. * This returns the current maximum size that will
  324. * ever be passed to the "process" callback. It should only
  325. * be used *before* the client has been activated. After activation,
  326. * the client will be notified of buffer size changes if it
  327. * registers a buffer_size callback.
  328. */
  329. jack_nframes_t jack_get_buffer_size (jack_client_t *);
  330. /**
  331. * @param port_name_pattern A regular expression used to select
  332. * ports by name. If NULL or of zero length, no selection based
  333. * on name will be carried out.
  334. * @param type_name_pattern A regular expression used to select
  335. * ports by type. If NULL or of zero length, no selection based
  336. * on type will be carried out.
  337. * @param flags A value used to select ports by their flags.
  338. * If zero, no selection based on flags will be carried out.
  339. *
  340. * This function returns a NULL-terminated array of ports that match
  341. * the specified arguments.
  342. * The caller is responsible for calling free(3) any non-NULL returned value.
  343. */
  344. const char ** jack_get_ports (jack_client_t *,
  345. const char *port_name_pattern,
  346. const char *type_name_pattern,
  347. unsigned long flags);
  348. /**
  349. * Searchs for and returns the jack_port_t with the name value
  350. * from portname.
  351. */
  352. jack_port_t *jack_port_by_name (jack_client_t *, const char *portname);
  353. /**
  354. * Searchs for and returns the jack_port_t of id @id.
  355. */
  356. jack_port_t *jack_port_by_id (jack_client_t *client, jack_port_id_t id);
  357. /**
  358. * If a client is told (by the user) to become the timebase
  359. * for the entire system, it calls this function. If it
  360. * returns zero, then the client has the responsibility to
  361. * call jack_set_transport_info()) at the end of its process()
  362. * callback.
  363. */
  364. int jack_engine_takeover_timebase (jack_client_t *);
  365. /**
  366. * undocumented
  367. */
  368. void jack_update_time (jack_client_t *, jack_nframes_t);
  369. /**
  370. * This estimates the time that has passed since the
  371. * start jack server started calling the process()
  372. * callbacks of all its clients.
  373. */
  374. jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  375. /**
  376. * Return an estimate of the current time in frames. It is a running
  377. * counter - no significance should be attached to the return
  378. * value. it should be used to compute the difference between
  379. * a previously returned value.
  380. */
  381. jack_nframes_t jack_frame_time (const jack_client_t *);
  382. /**
  383. * This returns the current CPU load estimated by JACK
  384. * as a percentage. The load is computed by measuring
  385. * the number of cycles it took to execute all clients
  386. * as a fraction of the total number of cycles
  387. * represented by the data that was processed.
  388. */
  389. float jack_cpu_load (jack_client_t *client);
  390. #ifdef __cplusplus
  391. }
  392. #endif
  393. #endif /* __jack_h__ */