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.

473 lines
14KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004 Jack O'Quin
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __jack_types_h__
  17. #define __jack_types_h__
  18. #include <inttypes.h>
  19. typedef int32_t jack_shmsize_t;
  20. /**
  21. * Type used to represent sample frame counts.
  22. */
  23. typedef uint32_t jack_nframes_t;
  24. /**
  25. * Maximum value that can be stored in jack_nframes_t
  26. */
  27. #define JACK_MAX_FRAMES (4294967295U) /* This should be UINT32_MAX, but
  28. C++ has a problem with that. */
  29. /**
  30. * Type used to represent the value of free running
  31. * monotonic clock with units of microseconds.
  32. */
  33. typedef uint64_t jack_time_t;
  34. /**
  35. * Maximum size of @a load_init string passed to an internal client
  36. * jack_initialize() function via jack_internal_client_load().
  37. */
  38. #define JACK_LOAD_INIT_LIMIT 1024
  39. /**
  40. * jack_intclient_t is an opaque type representing a loaded internal
  41. * client. You may only access it using the API provided in @ref
  42. * intclient.h "<jack/intclient.h>".
  43. */
  44. typedef uint64_t jack_intclient_t;
  45. /**
  46. * jack_port_t is an opaque type. You may only access it using the
  47. * API provided.
  48. */
  49. typedef struct _jack_port jack_port_t;
  50. /**
  51. * jack_client_t is an opaque type. You may only access it using the
  52. * API provided.
  53. */
  54. typedef struct _jack_client jack_client_t;
  55. /**
  56. * Ports have unique ids. A port registration callback is the only
  57. * place you ever need to know their value.
  58. */
  59. typedef uint32_t jack_port_id_t;
  60. /**
  61. * @ref jack_options_t bits
  62. */
  63. enum JackOptions {
  64. /**
  65. * Null value to use when no option bits are needed.
  66. */
  67. JackNullOption = 0x00,
  68. /**
  69. * Do not automatically start the JACK server when it is not
  70. * already running. This option is always selected if
  71. * \$JACK_NO_START_SERVER is defined in the calling process
  72. * environment.
  73. */
  74. JackNoStartServer = 0x01,
  75. /**
  76. * Use the exact client name requested. Otherwise, JACK
  77. * automatically generates a unique one, if needed.
  78. */
  79. JackUseExactName = 0x02,
  80. /**
  81. * Open with optional <em>(char *) server_name</em> parameter.
  82. */
  83. JackServerName = 0x04,
  84. /**
  85. * Load internal client from optional <em>(char *)
  86. * load_name</em>. Otherwise use the @a client_name.
  87. */
  88. JackLoadName = 0x08,
  89. /**
  90. * Pass optional <em>(char *) load_init</em> string to the
  91. * jack_initialize() entry point of an internal client.
  92. */
  93. JackLoadInit = 0x10,
  94. JackSessionUUID = 0x20
  95. };
  96. /** Valid options for opening an external client. */
  97. #define JackOpenOptions (JackSessionUUID|JackServerName|JackNoStartServer|JackUseExactName)
  98. /** Valid options for loading an internal client. */
  99. #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
  100. /**
  101. * Options for several JACK operations, formed by OR-ing together the
  102. * relevant @ref JackOptions bits.
  103. */
  104. typedef enum JackOptions jack_options_t;
  105. /**
  106. * @ref jack_status_t bits
  107. */
  108. enum JackStatus {
  109. /**
  110. * Overall operation failed.
  111. */
  112. JackFailure = 0x01,
  113. /**
  114. * The operation contained an invalid or unsupported option.
  115. */
  116. JackInvalidOption = 0x02,
  117. /**
  118. * The desired client name was not unique. With the @ref
  119. * JackUseExactName option this situation is fatal. Otherwise,
  120. * the name was modified by appending a dash and a two-digit
  121. * number in the range "-01" to "-99". The
  122. * jack_get_client_name() function will return the exact string
  123. * that was used. If the specified @a client_name plus these
  124. * extra characters would be too long, the open fails instead.
  125. */
  126. JackNameNotUnique = 0x04,
  127. /**
  128. * The JACK server was started as a result of this operation.
  129. * Otherwise, it was running already. In either case the caller
  130. * is now connected to jackd, so there is no race condition.
  131. * When the server shuts down, the client will find out.
  132. */
  133. JackServerStarted = 0x08,
  134. /**
  135. * Unable to connect to the JACK server.
  136. */
  137. JackServerFailed = 0x10,
  138. /**
  139. * Communication error with the JACK server.
  140. */
  141. JackServerError = 0x20,
  142. /**
  143. * Requested client does not exist.
  144. */
  145. JackNoSuchClient = 0x40,
  146. /**
  147. * Unable to load internal client
  148. */
  149. JackLoadFailure = 0x80,
  150. /**
  151. * Unable to initialize client
  152. */
  153. JackInitFailure = 0x100,
  154. /**
  155. * Unable to access shared memory
  156. */
  157. JackShmFailure = 0x200,
  158. /**
  159. * Client's protocol version does not match
  160. */
  161. JackVersionError = 0x400,
  162. /*
  163. * BackendError
  164. */
  165. JackBackendError = 0x800,
  166. /*
  167. * Client is being shutdown against its will
  168. */
  169. JackClientZombie = 0x1000
  170. };
  171. /**
  172. * Status word returned from several JACK operations, formed by
  173. * OR-ing together the relevant @ref JackStatus bits.
  174. */
  175. typedef enum JackStatus jack_status_t;
  176. enum JackSessionEvent {
  177. JackSessionSave = 1,
  178. JackSessionQuit = 2
  179. };
  180. typedef enum JackSessionEvent jack_session_event_t;
  181. /**
  182. * Prototype for the client supplied function that is called
  183. * by the engine anytime there is work to be done.
  184. *
  185. * @pre nframes == jack_get_buffer_size()
  186. * @pre nframes == pow(2,x)
  187. *
  188. * @param nframes number of frames to process
  189. * @param arg pointer to a client supplied data
  190. *
  191. * @return zero on success, non-zero on error
  192. */
  193. typedef int (*JackProcessCallback)(jack_nframes_t nframes, void *arg);
  194. /**
  195. * Prototype for the client supplied function that is called
  196. * once after the creation of the thread in which other
  197. * callbacks will be made. Special thread characteristics
  198. * can be set from this callback, for example. This is a
  199. * highly specialized callback and most clients will not
  200. * and should not use it.
  201. *
  202. * @param arg pointer to a client supplied structure
  203. *
  204. * @return void
  205. */
  206. typedef void (*JackThreadInitCallback)(void *arg);
  207. /**
  208. * Prototype for the client supplied function that is called
  209. * whenever the processing graph is reordered.
  210. *
  211. * @param arg pointer to a client supplied data
  212. *
  213. * @return zero on success, non-zero on error
  214. */
  215. typedef int (*JackGraphOrderCallback)(void *arg);
  216. /**
  217. * Prototype for the client-supplied function that is called whenever
  218. * an xrun has occured.
  219. *
  220. * @see jack_get_xrun_delayed_usecs()
  221. *
  222. * @param arg pointer to a client supplied data
  223. *
  224. * @return zero on success, non-zero on error
  225. */
  226. typedef int (*JackXRunCallback)(void *arg);
  227. /**
  228. * Prototype for the @a bufsize_callback that is invoked whenever the
  229. * JACK engine buffer size changes. Although this function is called
  230. * in the JACK process thread, the normal process cycle is suspended
  231. * during its operation, causing a gap in the audio flow. So, the @a
  232. * bufsize_callback can allocate storage, touch memory not previously
  233. * referenced, and perform other operations that are not realtime
  234. * safe.
  235. *
  236. * @param nframes buffer size
  237. * @param arg pointer supplied by jack_set_buffer_size_callback().
  238. *
  239. * @return zero on success, non-zero on error
  240. */
  241. typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void *arg);
  242. /**
  243. * Prototype for the client supplied function that is called
  244. * when the engine sample rate changes.
  245. *
  246. * @param nframes new engine sample rate
  247. * @param arg pointer to a client supplied data
  248. *
  249. * @return zero on success, non-zero on error
  250. */
  251. typedef int (*JackSampleRateCallback)(jack_nframes_t nframes, void *arg);
  252. /**
  253. * Prototype for the client supplied function that is called
  254. * whenever a port is registered or unregistered.
  255. *
  256. * @param port the ID of the port
  257. * @param arg pointer to a client supplied data
  258. * @param register non-zero if the port is being registered,
  259. * zero if the port is being unregistered
  260. */
  261. typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int register, void *arg);
  262. /**
  263. * Prototype for the client supplied function that is called
  264. * whenever a client is registered or unregistered.
  265. *
  266. * @param name a null-terminated string containing the client name
  267. * @param register non-zero if the client is being registered,
  268. * zero if the client is being unregistered
  269. * @param arg pointer to a client supplied data
  270. */
  271. typedef void (*JackClientRegistrationCallback)(const char* name, int register, void *arg);
  272. /**
  273. * Prototype for the client supplied function that is called
  274. * whenever a client is registered or unregistered.
  275. *
  276. * @param a one of two ports connected or disconnected
  277. * @param b one of two ports connected or disconnected
  278. * @param connect non-zero if ports were connected
  279. * zero if ports were disconnected
  280. * @param arg pointer to a client supplied data
  281. */
  282. typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
  283. /**
  284. * Prototype for the client supplied function that is called
  285. * whenever jackd starts or stops freewheeling.
  286. *
  287. * @param starting non-zero if we start starting to freewheel, zero otherwise
  288. * @param arg pointer to a client supplied structure
  289. */
  290. typedef void (*JackFreewheelCallback)(int starting, void *arg);
  291. typedef void *(*JackThreadCallback)(void* arg);
  292. /**
  293. * Prototype for the client supplied function that is called
  294. * whenever jackd is shutdown. Note that after server shutdown,
  295. * the client pointer is *not* deallocated by libjack,
  296. * the application is responsible to properly use jack_client_close()
  297. * to release client ressources. Warning: jack_client_close() cannot be
  298. * safely used inside the shutdown callback and has to be called outside of
  299. * the callback context.
  300. *
  301. * @param arg pointer to a client supplied structure
  302. */
  303. typedef void (*JackShutdownCallback)(void *arg);
  304. /**
  305. * Prototype for the client supplied function that is called
  306. * whenever jackd is shutdown. Note that after server shutdown,
  307. * the client pointer is *not* deallocated by libjack,
  308. * the application is responsible to properly use jack_client_close()
  309. * to release client ressources. Warning: jack_client_close() cannot be
  310. * safely used inside the shutdown callback and has to be called outside of
  311. * the callback context.
  312. *
  313. * @param code a shuntdown code
  314. * @param reason a string discribing the shuntdown reason (backend failure, server crash... etc...)
  315. * @param arg pointer to a client supplied structure
  316. */
  317. typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, void *arg);
  318. /**
  319. * Prototype for the client supplied function that is called
  320. * whenever a session notification is sent via jack_session_notify().
  321. * for a save event the client is required to save its state.
  322. * it must save it into session_dir, and at least use prefix for the first
  323. * part of the filename. (it is free to create a directory or create more
  324. * files, as long as these start with prefix.)
  325. * the prefix also acts as uuid, which the client needs to specify
  326. * to jack_client_open() upon session reload.
  327. *
  328. * The return value is a commandline, which will restore the state.
  329. *
  330. * @param code the type of the Event (Save or Quit)
  331. * @param session_dir with trailing separator.
  332. * @param prefix for saved files.
  333. * @param arg pointer to a client supplied structure
  334. */
  335. typedef char *(*JackSessionCallback)(jack_session_event_t code, const char* session_dir, const char* uuid, void *arg);
  336. /**
  337. * Used for the type argument of jack_port_register() for default
  338. * audio and midi ports.
  339. */
  340. #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
  341. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  342. /**
  343. * For convenience, use this typedef if you want to be able to change
  344. * between float and double. You may want to typedef sample_t to
  345. * jack_default_audio_sample_t in your application.
  346. */
  347. typedef float jack_default_audio_sample_t;
  348. /**
  349. * A port has a set of flags that are formed by AND-ing together the
  350. * desired values from the list below. The flags "JackPortIsInput" and
  351. * "JackPortIsOutput" are mutually exclusive and it is an error to use
  352. * them both.
  353. */
  354. enum JackPortFlags {
  355. /**
  356. * if JackPortIsInput is set, then the port can receive
  357. * data.
  358. */
  359. JackPortIsInput = 0x1,
  360. /**
  361. * if JackPortIsOutput is set, then data can be read from
  362. * the port.
  363. */
  364. JackPortIsOutput = 0x2,
  365. /**
  366. * if JackPortIsPhysical is set, then the port corresponds
  367. * to some kind of physical I/O connector.
  368. */
  369. JackPortIsPhysical = 0x4,
  370. /**
  371. * if JackPortCanMonitor is set, then a call to
  372. * jack_port_request_monitor() makes sense.
  373. *
  374. * Precisely what this means is dependent on the client. A typical
  375. * result of it being called with TRUE as the second argument is
  376. * that data that would be available from an output port (with
  377. * JackPortIsPhysical set) is sent to a physical output connector
  378. * as well, so that it can be heard/seen/whatever.
  379. *
  380. * Clients that do not control physical interfaces
  381. * should never create ports with this bit set.
  382. */
  383. JackPortCanMonitor = 0x8,
  384. /**
  385. * JackPortIsTerminal means:
  386. *
  387. * for an input port: the data received by the port
  388. * will not be passed on or made
  389. * available at any other port
  390. *
  391. * for an output port: the data available at the port
  392. * does not originate from any other port
  393. *
  394. * Audio synthesizers, I/O hardware interface clients, HDR
  395. * systems are examples of clients that would set this flag for
  396. * their ports.
  397. */
  398. JackPortIsTerminal = 0x10
  399. };
  400. typedef struct {
  401. char uuid[16];
  402. char client_name[33];
  403. char command[256];
  404. } jack_session_command_t;
  405. #endif /* __jack_types_h__ */