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.

610 lines
20KB

  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 <pthread.h>
  22. #include <jack/types.h>
  23. #include <jack/transport.h>
  24. /**
  25. * Note: More documentation can be found in jack/types.h.
  26. */
  27. /**
  28. * Attemps to become an external client of the Jack server.
  29. */
  30. jack_client_t *jack_client_new (const char *client_name);
  31. /**
  32. * Disconnects an external client from a JACK server.
  33. *
  34. * @return 0 on success, otherwise a non-zero error code
  35. */
  36. int jack_client_close (jack_client_t *client);
  37. /**
  38. * @param client_name The name for the new client
  39. * @param so_name A path to a shared object file containing the code for the new client
  40. * @param so_data An arbitary string containing information to be passed to the init() routine of the new client
  41. *
  42. * Attemps to load an internal client into the Jack server.
  43. */
  44. int jack_internal_client_new (const char *client_name, const char *so_name, const char *so_data);
  45. /**
  46. * Removes an internal client from a JACK server.
  47. *
  48. * @return 0 on success, otherwise a non-zero error code
  49. */
  50. void jack_internal_client_close (const char *client_name);
  51. /**
  52. * @param client The Jack client structure.
  53. *
  54. * Check if the JACK subsystem is running with -R (--realtime).
  55. *
  56. * @return 1 if JACK is running realtime, 0 otherwise
  57. */
  58. int jack_is_realtime (jack_client_t *client);
  59. /**
  60. * @param client The Jack client structure.
  61. * @param function The jack_shutdown function pointer.
  62. * @param arg The arguments for the jack_shutdown function.
  63. *
  64. * Register a function (and argument) to be called if and when the
  65. * JACK server shuts down the client thread. The function must
  66. * be written as if it were an asynchonrous POSIX signal
  67. * handler --- use only async-safe functions, and remember that it
  68. * is executed from another thread. A typical function might
  69. * set a flag or write to a pipe so that the rest of the
  70. * application knows that the JACK client thread has shut
  71. * down.
  72. *
  73. * NOTE: clients do not need to call this. It exists only
  74. * to help more complex clients understand what is going
  75. * on. If called, it should be called before jack_client_activate().
  76. */
  77. void jack_on_shutdown (jack_client_t *client, void (*function)(void *arg), void *arg);
  78. /**
  79. * Tell the Jack server to call 'process_callback' whenever there is work
  80. * be done, passing 'arg' as the second argument.
  81. *
  82. * The code in the supplied function must be suitable for real-time
  83. * execution. That means that it cannot call functions that might block for
  84. * a long time.  This includes malloc, free, printf, pthread_mutex_lock,
  85. * sleep, wait, poll, select, pthread_join, pthread_cond_wait, etc, etc. 
  86. * See
  87. * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
  88. * for more information.
  89. *
  90. *
  91. * @return 0 on success, otherwise a non-zero error code, causing JACK
  92. * to remove that client from the process() graph.
  93. */
  94. int jack_set_process_callback (jack_client_t *, JackProcessCallback process_callback, void *arg);
  95. /**
  96. * Tell the Jack server to call 'bufsize_callback' whenever the size of the
  97. * the buffer that will be passed to the process callback changes,
  98. * passing 'arg' as the second argument.
  99. *
  100. * @return 0 on success, otherwise a non-zero error code
  101. */
  102. int jack_set_buffer_size_callback (jack_client_t *, JackBufferSizeCallback bufsize_callback, void *arg);
  103. /**
  104. * Tell the Jack server to call 'srate_callback' whenever the sample rate of
  105. * the system changes.
  106. *
  107. * @return 0 on success, otherwise a non-zero error code
  108. */
  109. int jack_set_sample_rate_callback (jack_client_t *, JackSampleRateCallback srate_callback, void *arg);
  110. /**
  111. * Tell the Jack server to call 'registration_callback' whenever a port is registered
  112. * or unregistered, passing 'arg' as a second argument.
  113. *
  114. * @return 0 on success, otherwise a non-zero error code
  115. */
  116. int jack_set_port_registration_callback (jack_client_t *, JackPortRegistrationCallback registration_callback, void *arg);
  117. /**
  118. * Tell the Jack server to call 'registration_callback' whenever the processing
  119. * graph is reordered, passing 'arg' as an argument.
  120. *
  121. * @return 0 on success, otherwise a non-zero error code
  122. */
  123. int jack_set_graph_order_callback (jack_client_t *, JackGraphOrderCallback graph_callback, void *);
  124. /**
  125. * Tell the Jack server to call 'xrun_callback' whenever there is a xrun, passing
  126. * 'arg' as an argument.
  127. *
  128. * @return 0 on success, otherwise a non-zero error code
  129. */
  130. int jack_set_xrun_callback (jack_client_t *, JackXRunCallback xrun_callback, void *arg);
  131. /**
  132. * Tell the Jack server that the program is ready to start processing
  133. * audio.
  134. *
  135. * @return 0 on success, otherwise a non-zero error code
  136. */
  137. int jack_activate (jack_client_t *client);
  138. /**
  139. * Tells the Jack server that the program should be removed from the
  140. * processing graph. As a side effect, this will disconnect any
  141. * and all ports belonging to the client, since inactive clients
  142. * are not allowed to be connected to any other ports.
  143. *
  144. * @return 0 on success, otherwise a non-zero error code
  145. */
  146. int jack_deactivate (jack_client_t *client);
  147. /**
  148. * This creates a new port for the client.
  149. *
  150. * A port is an object used for moving data in or out of the client.
  151. * the data may be of any type. Ports may be connected to each other
  152. * in various ways.
  153. *
  154. * A port has a short name, a non-NULL and non-zero length string, and
  155. * is passed as the first argument. A port's full name is the name of
  156. * the client concatenated with a colon (:) and then its short
  157. * name. There are limits to the length of the name, and exceeding
  158. * them will cause registration of the port to fail and the function
  159. * to return NULL. The limit is derived from the size of a full port
  160. * name, which also has to include the client name and a separator
  161. * character.
  162. *
  163. * A port has a type, which may be any non-NULL and non-zero length
  164. * string, and is passed as the second argument. For types that are
  165. * not built into the jack API (currently just
  166. * JACK_DEFAULT_AUDIO_TYPE) the client MUST supply a non-zero size
  167. * for the buffer as for 'buffer_size' . For builtin types,
  168. * 'buffer_size' is ignored.
  169. *
  170. * The 'flags' argument is formed from a bitmask of JackPortFlags values.
  171. *
  172. * @return a valid jack_port_t* on success, NULL otherwise.
  173. * returns NULL.
  174. */
  175. jack_port_t *jack_port_register (jack_client_t *,
  176. const char *port_name,
  177. const char *port_type,
  178. unsigned long flags,
  179. unsigned long buffer_size);
  180. /**
  181. * This removes the port from the client, disconnecting
  182. * any existing connections at the same time.
  183. *
  184. * @return 0 on success, otherwise a non-zero error code
  185. */
  186. int jack_port_unregister (jack_client_t *, jack_port_t *);
  187. /**
  188. * This returns a pointer to the memory area associated with the
  189. * specified port. For an output port, it will be a memory area
  190. * that can be written to; for an input port, it will be an area
  191. * containing the data from the port's connection(s), or
  192. * zero-filled. if there are multiple inbound connections, the data
  193. * will be mixed appropriately.
  194. *
  195. * FOR OUTPUT PORTS ONLY
  196. * ---------------------
  197. * You may cache the value returned, but only between calls to
  198. * your "blocksize" callback. For this reason alone, you should
  199. * either never cache the return value or ensure you have
  200. * a "blocksize" callback and be sure to invalidate the cached
  201. * address from there.
  202. */
  203. void *jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  204. /**
  205. * Returns the name of the jack_port_t.
  206. */
  207. const char * jack_port_name (const jack_port_t *port);
  208. /**
  209. * Returns the short name of the jack_port_t.
  210. */
  211. const char * jack_port_short_name (const jack_port_t *port);
  212. /**
  213. * Returns the flags of the jack_port_t.
  214. */
  215. int jack_port_flags (const jack_port_t *port);
  216. /**
  217. * Returns the type of the jack_port_t.
  218. */
  219. const char * jack_port_type (const jack_port_t *port);
  220. /**
  221. * Returns 1 if the jack_port_t belongs to the jack_client_t.
  222. */
  223. int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  224. /**
  225. * This returns a positive integer indicating the number
  226. * of connections to or from 'port'.
  227. *
  228. * ®pre The calling client must own 'port'.
  229. */
  230. int jack_port_connected (const jack_port_t *port);
  231. /**
  232. * This returns TRUE or FALSE if the port argument is
  233. * DIRECTLY connected to the port with the name given in 'portname'
  234. *
  235. * @pre The calling client must own 'port'.
  236. */
  237. int jack_port_connected_to (const jack_port_t *port, const char *portname);
  238. /**
  239. * This returns a null-terminated array of port names to which
  240. * the argument port is connected. if there are no connections, it
  241. * returns NULL.
  242. *
  243. * The caller is responsible for calling free(3) on any
  244. * non-NULL returned value.
  245. *
  246. * @pre The calling client must own 'port'.
  247. *
  248. * See jack_port_get_all_connections() for an alternative.
  249. */
  250. const char ** jack_port_get_connections (const jack_port_t *port);
  251. /**
  252. * This returns a null-terminated array of port names to which
  253. * the argument port is connected. if there are no connections, it
  254. * returns NULL.
  255. *
  256. * The caller is responsible for calling free(3) on any
  257. * non-NULL returned value.
  258. *
  259. * It differs from jack_port_get_connections() in two important
  260. * respects:
  261. *
  262. * 1) You may not call this function from code that is
  263. * executed in response to a JACK event. For example,
  264. * you cannot use it in a GraphReordered handler.
  265. *
  266. * 2) You need not be the owner of the port to get information
  267. * about its connections.
  268. */
  269. const char ** jack_port_get_all_connections (const jack_client_t *client, const jack_port_t *port);
  270. /**
  271. * A client may call this on a pair of its own ports to
  272. * semi-permanently wire them together. This means that
  273. * a client that wants to direct-wire an input port to
  274. * an output port can call this and then no longer
  275. * have to worry about moving data between them. Any data
  276. * arriving at the input port will appear automatically
  277. * at the output port.
  278. *
  279. * The 'destination' port must be an output port. The 'source'
  280. * port must be an input port. Both ports must belong to
  281. * the same client. You cannot use this to tie ports between
  282. * clients. That is what a connection is for.
  283. *
  284. * @return 0 on success, otherwise a non-zero error code
  285. */
  286. int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  287. /**
  288. * This undoes the effect of jack_port_tie(). The port
  289. * should be same as the 'destination' port passed to
  290. * jack_port_tie().
  291. *
  292. * @return 0 on success, otherwise a non-zero error code
  293. */
  294. int jack_port_untie (jack_port_t *port);
  295. /**
  296. * A client may call this function to prevent other objects
  297. * from changing the connection status of a port. The port
  298. * must be owned by the calling client.
  299. *
  300. * @return 0 on success, otherwise a non-zero error code
  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. * @return 0 on success, otherwise a non-zero error code
  307. */
  308. int jack_port_unlock (jack_client_t *, jack_port_t *);
  309. /**
  310. * Returns the time (in frames) between data being
  311. * available or delivered at/to a port, and the time at
  312. * which it arrived at or is delivered to the "other side"
  313. * of the port. E.g. for a physical audio output port, this
  314. * is the time between writing to the port and when the
  315. * signal will leave the connector. For a physical audio
  316. * input port, this is the time between the sound arriving
  317. * at the connector and the corresponding frames being
  318. * readable from the port.
  319. */
  320. jack_nframes_t jack_port_get_latency (jack_port_t *port);
  321. /**
  322. * The maximum of the sum of the latencies in every
  323. * connection path that can be drawn between the port and other
  324. * ports with the JackPortIsTerminal flag set.
  325. */
  326. jack_nframes_t jack_port_get_total_latency (jack_client_t *, jack_port_t *port);
  327. /**
  328. * The port latency is zero by default. Clients that control
  329. * physical hardware with non-zero latency should call this
  330. * to set the latency to its correct value. Note that the value
  331. * should include any systemic latency present "outside" the
  332. * physical hardware controlled by the client. For example,
  333. * for a client controlling a digital audio interface connected
  334. * to an external digital converter, the latency setting should
  335. * include both buffering by the audio interface *and* the converter.
  336. */
  337. void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  338. /**
  339. * This modifies a port's name, and may be called at any time.
  340. *
  341. * @return 0 on success, otherwise a non-zero error code
  342. */
  343. int jack_port_set_name (jack_port_t *port, const char *name);
  344. /**
  345. */
  346. double jack_port_get_peak (jack_port_t*, jack_nframes_t);
  347. /**
  348. */
  349. double jack_port_get_power (jack_port_t*, jack_nframes_t);
  350. /**
  351. */
  352. void jack_port_set_peak_function (jack_port_t *, double (*func)(jack_port_t*, jack_nframes_t));
  353. /**
  354. */
  355. void jack_port_set_power_function (jack_port_t *, double (*func)(jack_port_t*, jack_nframes_t));
  356. /**
  357. * If JackPortCanMonitor is set for a port, then these 2 functions will
  358. * turn on/off input monitoring for the port. If JackPortCanMonitor
  359. * is not set, then these functions will have no effect.
  360. */
  361. int jack_port_request_monitor (jack_port_t *port, int onoff);
  362. /**
  363. * If JackPortCanMonitor is set for a port, then these 2 functions will
  364. * turn on/off input monitoring for the port. If JackPortCanMonitor
  365. * is not set, then these functions will have no effect.
  366. *
  367. * @return 0 on success, otherwise a non-zero error code
  368. */
  369. int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff);
  370. /**
  371. * If JackPortCanMonitor is set for a port, then this function will
  372. * turn on input monitoring if it was off, and will turn it off it
  373. * only one request has been made to turn it on. If JackPortCanMonitor
  374. * is not set, then this function will do nothing.
  375. *
  376. * @return 0 on success, otherwise a non-zero error code
  377. */
  378. int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  379. /**
  380. * Returns a true or false value depending on whether or not
  381. * input monitoring has been requested for 'port'.
  382. */
  383. int jack_port_monitoring_input (jack_port_t *port);
  384. /**
  385. * Establishes a connection between two ports.
  386. *
  387. * When a connection exists, data written to the source port will
  388. * be available to be read at the destination port.
  389. *
  390. * @pre The types of both ports must be identical to establish a connection.
  391. * @pre The flags of the source port must include PortIsOutput.
  392. * @pre The flags of the destination port must include PortIsInput.
  393. *
  394. * @return 0 on success, otherwise a non-zero error code
  395. */
  396. int jack_connect (jack_client_t *,
  397. const char *source_port,
  398. const char *destination_port);
  399. /**
  400. * Removes a connection between two ports.
  401. *
  402. * @pre The types of both ports must be identical to establish a connection.
  403. * @pre The flags of the source port must include PortIsOutput.
  404. * @pre The flags of the destination port must include PortIsInput.
  405. *
  406. * @return 0 on success, otherwise a non-zero error code
  407. */
  408. int jack_disconnect (jack_client_t *,
  409. const char *source_port,
  410. const char *destination_port);
  411. /**
  412. * Performs the exact same function as jack_connect(), but it uses
  413. * port handles rather than names, which avoids the name lookup inherent
  414. * in the name-based version.
  415. *
  416. * It is envisaged that clients connecting their own ports will use these
  417. * two, whereas generic connection clients (e.g. patchbays) will use the
  418. * name-based versions.
  419. *
  420. * @return 0 on success, otherwise a non-zero error code
  421. */
  422. int jack_port_connect (jack_client_t *, jack_port_t *src, jack_port_t *dst);
  423. /**
  424. * Performs the exact same function as jack_disconnect(), but it uses
  425. * port handles rather than names, which avoids the name lookup inherent
  426. * in the name-based version.
  427. *
  428. * It is envisaged that clients disconnecting their own ports will use these
  429. * two, whereas generic connection clients (e.g. patchbays) will use the
  430. * name-based versions.
  431. */
  432. int jack_port_disconnect (jack_client_t *, jack_port_t *);
  433. /**
  434. * This returns the sample rate of the jack system, as set by the user when
  435. * jackd was started.
  436. */
  437. unsigned long jack_get_sample_rate (jack_client_t *);
  438. /**
  439. * This returns the current maximum size that will
  440. * ever be passed to the "process" callback. It should only
  441. * be used *before* the client has been activated. After activation,
  442. * the client will be notified of buffer size changes if it
  443. * registers a buffer_size callback.
  444. */
  445. jack_nframes_t jack_get_buffer_size (jack_client_t *);
  446. /**
  447. * @param port_name_pattern A regular expression used to select
  448. * ports by name. If NULL or of zero length, no selection based
  449. * on name will be carried out.
  450. * @param type_name_pattern A regular expression used to select
  451. * ports by type. If NULL or of zero length, no selection based
  452. * on type will be carried out.
  453. * @param flags A value used to select ports by their flags.
  454. * If zero, no selection based on flags will be carried out.
  455. *
  456. * This function returns a NULL-terminated array of ports that match
  457. * the specified arguments.
  458. * The caller is responsible for calling free(3) any non-NULL returned value.
  459. */
  460. const char ** jack_get_ports (jack_client_t *,
  461. const char *port_name_pattern,
  462. const char *type_name_pattern,
  463. unsigned long flags);
  464. /**
  465. * Searchs for and returns the jack_port_t with the name value
  466. * from portname.
  467. */
  468. jack_port_t *jack_port_by_name (jack_client_t *, const char *portname);
  469. /**
  470. * Searchs for and returns the jack_port_t of id 'id'.
  471. */
  472. jack_port_t *jack_port_by_id (const jack_client_t *client, jack_port_id_t id);
  473. /**
  474. * If a client is told (by the user) to become the timebase for the
  475. * entire system, it calls this function. If it returns zero, then the
  476. * client has the responsibility to call jack_set_transport_info() at
  477. * the end of its process callback.
  478. *
  479. * @deprecated This function is only for compatibility with earlier
  480. * transport implementations. Instead, see <jack/transport.h> and use
  481. * jack_set_timebase_callback().
  482. *
  483. * @return 0 on success, otherwise a non-zero error code
  484. */
  485. int jack_engine_takeover_timebase (jack_client_t *);
  486. /**
  487. * undocumented
  488. */
  489. void jack_update_time (jack_client_t *, jack_nframes_t);
  490. /**
  491. * This estimates the time that has passed since the JACK server
  492. * started calling the process callbacks of all its clients.
  493. */
  494. jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  495. /**
  496. * Return an estimate of the current time in frames. It is a running
  497. * counter - no significance should be attached to the return
  498. * value. it should be used to compute the difference between
  499. * a previously returned value.
  500. */
  501. jack_nframes_t jack_frame_time (const jack_client_t *);
  502. /**
  503. * This returns the current CPU load estimated by JACK
  504. * as a percentage. The load is computed by measuring
  505. * the amount of time it took to execute all clients
  506. * as a fraction of the total amount of time
  507. * represented by the data that was processed.
  508. */
  509. float jack_cpu_load (jack_client_t *client);
  510. /**
  511. * Set the directory in which the server is expected
  512. * to have put its communication FIFOs. A client
  513. * will need to call this before calling
  514. * jack_client_new() if the server was started
  515. * with arguments telling it to use a non-standard
  516. * directory.
  517. */
  518. void jack_set_server_dir (const char *path);
  519. /**
  520. * Return the pthread ID of the thread running the JACK client
  521. * side code.
  522. */
  523. pthread_t jack_client_thread_id (jack_client_t *);
  524. extern void (*jack_error_callback)(const char *desc);
  525. /**
  526. * Sets callback to be called to print error messages.
  527. */
  528. void jack_set_error_function (void (*func)(const char *));
  529. #ifdef __cplusplus
  530. }
  531. #endif
  532. #endif /* __jack_h__ */