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.

477 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. /**
  95. * pass a UUID Token, this will unlock and assign an assigned name
  96. * to the client.
  97. */
  98. JackSessionUUID = 0x20
  99. };
  100. /** Valid options for opening an external client. */
  101. #define JackOpenOptions (JackSessionUUID|JackServerName|JackNoStartServer|JackUseExactName)
  102. /** Valid options for loading an internal client. */
  103. #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
  104. /**
  105. * Options for several JACK operations, formed by OR-ing together the
  106. * relevant @ref JackOptions bits.
  107. */
  108. typedef enum JackOptions jack_options_t;
  109. /**
  110. * @ref jack_status_t bits
  111. */
  112. enum JackStatus {
  113. /**
  114. * Overall operation failed.
  115. */
  116. JackFailure = 0x01,
  117. /**
  118. * The operation contained an invalid or unsupported option.
  119. */
  120. JackInvalidOption = 0x02,
  121. /**
  122. * The desired client name was not unique. With the @ref
  123. * JackUseExactName option this situation is fatal. Otherwise,
  124. * the name was modified by appending a dash and a two-digit
  125. * number in the range "-01" to "-99". The
  126. * jack_get_client_name() function will return the exact string
  127. * that was used. If the specified @a client_name plus these
  128. * extra characters would be too long, the open fails instead.
  129. */
  130. JackNameNotUnique = 0x04,
  131. /**
  132. * The JACK server was started as a result of this operation.
  133. * Otherwise, it was running already. In either case the caller
  134. * is now connected to jackd, so there is no race condition.
  135. * When the server shuts down, the client will find out.
  136. */
  137. JackServerStarted = 0x08,
  138. /**
  139. * Unable to connect to the JACK server.
  140. */
  141. JackServerFailed = 0x10,
  142. /**
  143. * Communication error with the JACK server.
  144. */
  145. JackServerError = 0x20,
  146. /**
  147. * Requested client does not exist.
  148. */
  149. JackNoSuchClient = 0x40,
  150. /**
  151. * Unable to load internal client
  152. */
  153. JackLoadFailure = 0x80,
  154. /**
  155. * Unable to initialize client
  156. */
  157. JackInitFailure = 0x100,
  158. /**
  159. * Unable to access shared memory
  160. */
  161. JackShmFailure = 0x200,
  162. /**
  163. * Client's protocol version does not match
  164. */
  165. JackVersionError = 0x400,
  166. /*
  167. * BackendError
  168. */
  169. JackBackendError = 0x800,
  170. /*
  171. * Client is being shutdown against its will
  172. */
  173. JackClientZombie = 0x1000
  174. };
  175. /**
  176. * Status word returned from several JACK operations, formed by
  177. * OR-ing together the relevant @ref JackStatus bits.
  178. */
  179. typedef enum JackStatus jack_status_t;
  180. enum JackSessionEvent {
  181. JackSessionSave = 1,
  182. JackSessionQuit = 2
  183. };
  184. typedef enum JackSessionEvent jack_session_event_t;
  185. /**
  186. * Prototype for the client supplied function that is called
  187. * by the engine anytime there is work to be done.
  188. *
  189. * @pre nframes == jack_get_buffer_size()
  190. * @pre nframes == pow(2,x)
  191. *
  192. * @param nframes number of frames to process
  193. * @param arg pointer to a client supplied data
  194. *
  195. * @return zero on success, non-zero on error
  196. */
  197. typedef int (*JackProcessCallback)(jack_nframes_t nframes, void *arg);
  198. /**
  199. * Prototype for the client supplied function that is called
  200. * once after the creation of the thread in which other
  201. * callbacks will be made. Special thread characteristics
  202. * can be set from this callback, for example. This is a
  203. * highly specialized callback and most clients will not
  204. * and should not use it.
  205. *
  206. * @param arg pointer to a client supplied structure
  207. *
  208. * @return void
  209. */
  210. typedef void (*JackThreadInitCallback)(void *arg);
  211. /**
  212. * Prototype for the client supplied function that is called
  213. * whenever the processing graph is reordered.
  214. *
  215. * @param arg pointer to a client supplied data
  216. *
  217. * @return zero on success, non-zero on error
  218. */
  219. typedef int (*JackGraphOrderCallback)(void *arg);
  220. /**
  221. * Prototype for the client-supplied function that is called whenever
  222. * an xrun has occured.
  223. *
  224. * @see jack_get_xrun_delayed_usecs()
  225. *
  226. * @param arg pointer to a client supplied data
  227. *
  228. * @return zero on success, non-zero on error
  229. */
  230. typedef int (*JackXRunCallback)(void *arg);
  231. /**
  232. * Prototype for the @a bufsize_callback that is invoked whenever the
  233. * JACK engine buffer size changes. Although this function is called
  234. * in the JACK process thread, the normal process cycle is suspended
  235. * during its operation, causing a gap in the audio flow. So, the @a
  236. * bufsize_callback can allocate storage, touch memory not previously
  237. * referenced, and perform other operations that are not realtime
  238. * safe.
  239. *
  240. * @param nframes buffer size
  241. * @param arg pointer supplied by jack_set_buffer_size_callback().
  242. *
  243. * @return zero on success, non-zero on error
  244. */
  245. typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void *arg);
  246. /**
  247. * Prototype for the client supplied function that is called
  248. * when the engine sample rate changes.
  249. *
  250. * @param nframes new engine sample rate
  251. * @param arg pointer to a client supplied data
  252. *
  253. * @return zero on success, non-zero on error
  254. */
  255. typedef int (*JackSampleRateCallback)(jack_nframes_t nframes, void *arg);
  256. /**
  257. * Prototype for the client supplied function that is called
  258. * whenever a port is registered or unregistered.
  259. *
  260. * @param port the ID of the port
  261. * @param arg pointer to a client supplied data
  262. * @param register non-zero if the port is being registered,
  263. * zero if the port is being unregistered
  264. */
  265. typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int register, void *arg);
  266. /**
  267. * Prototype for the client supplied function that is called
  268. * whenever a client is registered or unregistered.
  269. *
  270. * @param name a null-terminated string containing the client name
  271. * @param register non-zero if the client is being registered,
  272. * zero if the client is being unregistered
  273. * @param arg pointer to a client supplied data
  274. */
  275. typedef void (*JackClientRegistrationCallback)(const char* name, int register, void *arg);
  276. /**
  277. * Prototype for the client supplied function that is called
  278. * whenever a client is registered or unregistered.
  279. *
  280. * @param a one of two ports connected or disconnected
  281. * @param b one of two ports connected or disconnected
  282. * @param connect non-zero if ports were connected
  283. * zero if ports were disconnected
  284. * @param arg pointer to a client supplied data
  285. */
  286. typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
  287. /**
  288. * Prototype for the client supplied function that is called
  289. * whenever jackd starts or stops freewheeling.
  290. *
  291. * @param starting non-zero if we start starting to freewheel, zero otherwise
  292. * @param arg pointer to a client supplied structure
  293. */
  294. typedef void (*JackFreewheelCallback)(int starting, void *arg);
  295. typedef void *(*JackThreadCallback)(void* arg);
  296. /**
  297. * Prototype for the client supplied function that is called
  298. * whenever jackd is shutdown. Note that after server shutdown,
  299. * the client pointer is *not* deallocated by libjack,
  300. * the application is responsible to properly use jack_client_close()
  301. * to release client ressources. Warning: jack_client_close() cannot be
  302. * safely used inside the shutdown callback and has to be called outside of
  303. * the callback context.
  304. *
  305. * @param arg pointer to a client supplied structure
  306. */
  307. typedef void (*JackShutdownCallback)(void *arg);
  308. /**
  309. * Prototype for the client supplied function that is called
  310. * whenever jackd is shutdown. Note that after server shutdown,
  311. * the client pointer is *not* deallocated by libjack,
  312. * the application is responsible to properly use jack_client_close()
  313. * to release client ressources. Warning: jack_client_close() cannot be
  314. * safely used inside the shutdown callback and has to be called outside of
  315. * the callback context.
  316. *
  317. * @param code a shuntdown code
  318. * @param reason a string discribing the shuntdown reason (backend failure, server crash... etc...)
  319. * @param arg pointer to a client supplied structure
  320. */
  321. typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, void *arg);
  322. /**
  323. * Prototype for the client supplied function that is called
  324. * whenever a session notification is sent via jack_session_notify().
  325. * for a save event the client is required to save its state.
  326. * it must save it into session_dir, and at least use prefix for the first
  327. * part of the filename. (it is free to create a directory or create more
  328. * files, as long as these start with prefix.)
  329. * the prefix also acts as uuid, which the client needs to specify
  330. * to jack_client_open() upon session reload.
  331. *
  332. * The return value is a commandline, which will restore the state.
  333. *
  334. * @param code the type of the Event (Save or Quit)
  335. * @param session_dir with trailing separator.
  336. * @param prefix for saved files.
  337. * @param arg pointer to a client supplied structure
  338. */
  339. typedef char *(*JackSessionCallback)(jack_session_event_t code, const char* session_dir, const char* uuid, void *arg);
  340. /**
  341. * Used for the type argument of jack_port_register() for default
  342. * audio and midi ports.
  343. */
  344. #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
  345. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  346. /**
  347. * For convenience, use this typedef if you want to be able to change
  348. * between float and double. You may want to typedef sample_t to
  349. * jack_default_audio_sample_t in your application.
  350. */
  351. typedef float jack_default_audio_sample_t;
  352. /**
  353. * A port has a set of flags that are formed by AND-ing together the
  354. * desired values from the list below. The flags "JackPortIsInput" and
  355. * "JackPortIsOutput" are mutually exclusive and it is an error to use
  356. * them both.
  357. */
  358. enum JackPortFlags {
  359. /**
  360. * if JackPortIsInput is set, then the port can receive
  361. * data.
  362. */
  363. JackPortIsInput = 0x1,
  364. /**
  365. * if JackPortIsOutput is set, then data can be read from
  366. * the port.
  367. */
  368. JackPortIsOutput = 0x2,
  369. /**
  370. * if JackPortIsPhysical is set, then the port corresponds
  371. * to some kind of physical I/O connector.
  372. */
  373. JackPortIsPhysical = 0x4,
  374. /**
  375. * if JackPortCanMonitor is set, then a call to
  376. * jack_port_request_monitor() makes sense.
  377. *
  378. * Precisely what this means is dependent on the client. A typical
  379. * result of it being called with TRUE as the second argument is
  380. * that data that would be available from an output port (with
  381. * JackPortIsPhysical set) is sent to a physical output connector
  382. * as well, so that it can be heard/seen/whatever.
  383. *
  384. * Clients that do not control physical interfaces
  385. * should never create ports with this bit set.
  386. */
  387. JackPortCanMonitor = 0x8,
  388. /**
  389. * JackPortIsTerminal means:
  390. *
  391. * for an input port: the data received by the port
  392. * will not be passed on or made
  393. * available at any other port
  394. *
  395. * for an output port: the data available at the port
  396. * does not originate from any other port
  397. *
  398. * Audio synthesizers, I/O hardware interface clients, HDR
  399. * systems are examples of clients that would set this flag for
  400. * their ports.
  401. */
  402. JackPortIsTerminal = 0x10
  403. };
  404. typedef struct {
  405. char uuid[16];
  406. char client_name[33];
  407. char command[256];
  408. } jack_session_command_t;
  409. #endif /* __jack_types_h__ */