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.

532 lines
16KB

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