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.

368 lines
13KB

  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: jack.h,v 1.1 2002-07-28 23:18:15 nebogeo Exp $
  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. jack_client_t *jack_client_new (const char *client_name);
  24. int jack_client_close (jack_client_t *client);
  25. /* register a function (and argument) to be called if and when the
  26. JACK server shuts down the client thread. the function must
  27. be written as if it were an asynchonrous POSIX signal
  28. handler - use only async-safe functions, and remember that it
  29. is executed from another thread. a typical function might
  30. set a flag or write to a pipe so that the rest of the
  31. application knows that the JACK client thread has shut
  32. down.
  33. NOTE: clients do not need to call this. it exists only
  34. to help more complex clients understand what is going
  35. on. if called, it must be called before jack_client_activate().
  36. */
  37. void jack_on_shutdown (jack_client_t *, void (*function)(void *arg), void *arg);
  38. /* see simple_client.c to understand what these do.
  39. */
  40. int jack_set_process_callback (jack_client_t *, JackProcessCallback, void *arg);
  41. int jack_set_buffer_size_callback (jack_client_t *, JackBufferSizeCallback, void *arg);
  42. int jack_set_sample_rate_callback (jack_client_t *, JackSampleRateCallback, void *arg);
  43. int jack_set_port_registration_callback (jack_client_t *, JackPortRegistrationCallback, void *);
  44. int jack_activate (jack_client_t *client);
  45. int jack_deactivate (jack_client_t *client);
  46. /* this creates a new port for the client.
  47. a port is an object used for moving data in or out of the client.
  48. the data may be of any type. ports may be connected to each other
  49. in various ways.
  50. a port has a short name, which may be any non-NULL and non-zero
  51. length string, and is passed as the first argument. a port's full
  52. name is the name of the client concatenated with a colon (:) and
  53. then its short name.
  54. a port has a type, which may be any non-NULL and non-zero length
  55. string, and is passed as the second argument. for types that are
  56. not built into the jack API (currently just
  57. JACK_DEFAULT_AUDIO_TYPE) the client MUST supply a non-zero size
  58. for the buffer as the fourth argument. for builtin types, the
  59. fourth argument is ignored.
  60. a port has a set of flags, enumerated below and passed as the third
  61. argument in the form of a bitmask created by AND-ing together the
  62. desired flags. the flags "IsInput" and "IsOutput" are mutually
  63. exclusive and it is an error to use them both.
  64. */
  65. enum JackPortFlags {
  66. JackPortIsInput = 0x1,
  67. JackPortIsOutput = 0x2,
  68. JackPortIsPhysical = 0x4, /* refers to a physical connection */
  69. /* if JackPortCanMonitor is set, then a call to
  70. jack_port_request_monitor() makes sense.
  71. Precisely what this means is dependent on the client. A typical
  72. result of it being called with TRUE as the second argument is
  73. that data that would be available from an output port (with
  74. JackPortIsPhysical set) is sent to a physical output connector
  75. as well, so that it can be heard/seen/whatever.
  76. Clients that do not control physical interfaces
  77. should never create ports with this bit set.
  78. */
  79. JackPortCanMonitor = 0x8,
  80. /* JackPortIsTerminal means:
  81. for an input port: the data received by the port
  82. will not be passed on or made
  83. available at any other port
  84. for an output port: the data available at the port
  85. does not originate from any
  86. other port
  87. Audio synthesizers, i/o h/w interface clients, HDR
  88. systems are examples of things that would set this
  89. flag for their ports.
  90. */
  91. JackPortIsTerminal = 0x10
  92. };
  93. #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
  94. jack_port_t *
  95. jack_port_register (jack_client_t *,
  96. const char *port_name,
  97. const char *port_type,
  98. unsigned long flags,
  99. unsigned long buffer_size);
  100. /* this removes the port from the client, disconnecting
  101. any existing connections at the same time.
  102. */
  103. int jack_port_unregister (jack_client_t *, jack_port_t *);
  104. /* a port is an opaque type. these help with a few things */
  105. const char * jack_port_name (const jack_port_t *port);
  106. const char * jack_port_short_name (const jack_port_t *port);
  107. int jack_port_flags (const jack_port_t *port);
  108. const char * jack_port_type (const jack_port_t *port);
  109. /* this returns TRUE or FALSE to indicate if there are
  110. any connections to/from the port argument.
  111. */
  112. int jack_port_connected (const jack_port_t *port);
  113. /* this returns TRUE or FALSE if the port argument is
  114. DIRECTLY connected to the port with the name given in
  115. `portname'
  116. */
  117. int jack_port_connected_to (const jack_port_t *port, const char *portname);
  118. int jack_port_connected_to_port (const jack_port_t *port, const jack_port_t *other_port);
  119. /* this returns a null-terminated array of port names to
  120. which the argument port is connected. if there are no
  121. connections, it returns NULL.
  122. the caller is responsible for calling free(3) on any
  123. non-NULL returned value.
  124. */
  125. const char ** jack_port_get_connections (const jack_port_t *port);
  126. /* this modifies a port's name, and may be called at any
  127. time.
  128. */
  129. int jack_port_set_name (jack_port_t *port, const char *name);
  130. /* This returns a pointer to the memory area associated with the
  131. specified port. It can only be called from within the client's
  132. "process" callback. For an output port, it will be a memory area
  133. that can be written to; for an input port, it will be an area
  134. containing the data from the port's connection(s), or
  135. zero-filled. if there are multiple inbound connections, the data
  136. will be mixed appropriately.
  137. You may not cache the values returned across process() callbacks.
  138. There is no guarantee that the values will not change from
  139. process() callback to process() callback.
  140. */
  141. void *jack_port_get_buffer (jack_port_t *, nframes_t);
  142. /* these two functions establish and disestablish a connection
  143. between two ports. when a connection exists, data written
  144. to the source port will be available to be read at the destination
  145. port.
  146. the types of both ports must be identical to establish a connection.
  147. the flags of the source port must include PortIsOutput.
  148. the flags of the destination port must include PortIsInput.
  149. */
  150. int jack_connect (jack_client_t *,
  151. const char *source_port,
  152. const char *destination_port);
  153. int jack_disconnect (jack_client_t *,
  154. const char *source_port,
  155. const char *destination_port);
  156. /* these two functions perform the exact same function
  157. as the jack_connect() and jack_disconnect(), but they
  158. use port handles rather than names, which avoids
  159. the name lookup inherent in the name-based versions.
  160. it is envisaged that clients (dis)connecting their own
  161. ports will use these two, wherease generic connection
  162. clients (e.g. patchbays) will use the name-based
  163. versions
  164. */
  165. int jack_port_connect (jack_client_t *, jack_port_t *src, jack_port_t *dst);
  166. int jack_port_disconnect (jack_client_t *, jack_port_t *);
  167. /* A client may call this on a pair of its own ports to
  168. semi-permanently wire them together. This means that
  169. a client that wants to direct-wire an input port to
  170. an output port can call this and then no longer
  171. have to worry about moving data between them. Any data
  172. arriving at the input port will appear automatically
  173. at the output port.
  174. The `destination' port must be an output port. The `source'
  175. port must be an input port. Both ports must belong to
  176. the same client. You cannot use this to tie ports between
  177. clients. Thats what a connection is for.
  178. */
  179. int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  180. /* This undoes the effect of jack_port_tie(). The port
  181. should be same as the `destination' port passed to
  182. jack_port_tie().
  183. */
  184. int jack_port_untie (jack_port_t *port);
  185. /* a client may call this function to prevent other objects
  186. from changing the connection status of a port. the port
  187. must be owned by the calling client.
  188. */
  189. int jack_port_lock (jack_client_t *, jack_port_t *);
  190. int jack_port_unlock (jack_client_t *, jack_port_t *);
  191. /* returns the time (in frames) between data being available
  192. or delivered at/to a port, and the time at which it
  193. arrived at or is delivered to the "other side" of the port.
  194. e.g. for a physical audio output port, this is the time between
  195. writing to the port and when the audio will be audible.
  196. for a physical audio input port, this is the time between the sound
  197. being audible and the corresponding frames being readable from the
  198. port.
  199. */
  200. nframes_t jack_port_get_latency (jack_port_t *port);
  201. /* the port latency is zero by default. clients that control
  202. physical hardware with non-zero latency should call this
  203. to set the latency to its correct value. note that the value
  204. should include any systemic latency present "outside" the
  205. physical hardware controlled by the client. for example,
  206. for a client controlling a digital audio interface connected
  207. to an external digital converter, the latency setting should
  208. include both buffering by the audio interface *and* the converter.
  209. */
  210. void jack_port_set_latency (jack_port_t *, nframes_t);
  211. /* if JackPortCanMonitor is set for a port, then these 2 functions will
  212. turn on/off input monitoring for the port. if JackPortCanMonitor
  213. is not set, then these functions will have no effect.
  214. */
  215. int jack_port_request_monitor (jack_port_t *port, int onoff);
  216. int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff);
  217. /* if JackPortCanMonitor is set for a port, then this function will
  218. turn on input monitoring if it was off, and will turn it off it
  219. only one request has been made to turn it on. if JackPortCanMonitor
  220. is not set, then this function will do nothing.
  221. */
  222. int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  223. /* returns a true or false value depending on whether or not
  224. input monitoring has been requested for `port'.
  225. */
  226. int jack_port_monitoring_input (jack_port_t *port);
  227. /* this returns the sample rate of the jack system */
  228. unsigned long jack_get_sample_rate (jack_client_t *);
  229. /* this returns the current maximum size that will
  230. ever be passed to the "process" callback. it should only
  231. be used *before* the client has been activated. after activation,
  232. the client will be notified of buffer size changes if it
  233. registers a buffer_size callback.
  234. */
  235. nframes_t jack_get_buffer_size (jack_client_t *);
  236. /* This function returns a NULL-terminated array of ports that match the
  237. specified arguments.
  238. port_name_pattern: a regular expression used to select ports by name.
  239. if NULL or of zero length, no selection based on
  240. name will be carried out.
  241. type_name_pattern: a regular expression used to select ports by type.
  242. if NULL or of zero length, no selection based on
  243. type will be carried out.
  244. flags: a value used to select ports by their flags. if
  245. zero, no selection based on flags will be carried out.
  246. The caller is responsible for calling free(3) any non-NULL returned
  247. value.
  248. */
  249. const char ** jack_get_ports (jack_client_t *,
  250. const char *port_name_pattern,
  251. const char *type_name_pattern,
  252. unsigned long flags);
  253. jack_port_t *jack_port_by_name (jack_client_t *, const char *portname);
  254. /* If a client is told (by the user) to become the timebase
  255. for the entire system, it calls this function. If it
  256. returns zero, then the client has the responsibility to
  257. call jack_update_time() at the end of its process()
  258. callback. Whatever time it provides (in frames since its
  259. reference zero time) becomes the current timebase for the
  260. entire system.
  261. */
  262. int jack_engine_takeover_timebase (jack_client_t *);
  263. void jack_update_time (jack_client_t *, nframes_t);
  264. /* this estimates the time that has passed since the
  265. start jack server started calling the process()
  266. callbacks of all its clients.
  267. */
  268. nframes_t jack_frames_since_cycle_start (jack_client_t *);
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272. #endif /* __jack_h__ */