Add Pieter Palmers FreeBob driver.
[jack2.git] / common / jack.h
blob0789da6c2cc73a678769d5b921f436c18dbfc326
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004 Jack O'Quin
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 $Id: jack.h,v 1.5.2.6 2006/06/20 14:44:00 letz Exp $
22 #ifndef __jack_h__
23 #define __jack_h__
25 #ifdef __cplusplus
26 extern "C"
28 #endif
30 #ifdef WIN32
31 #include <windows.h>
32 typedef HANDLE pthread_t;
33 #else
34 #include <pthread.h>
35 #endif
38 #include <jack/types.h>
39 #include <jack/transport.h>
42 #include "types.h"
43 #include "transport.h"
45 /**
46 * Note: More documentation can be found in jack/types.h.
49 /**
50 * Open an external client session with a JACK server. This interface
51 * is more complex but more powerful than jack_client_new(). With it,
52 * clients may choose which of several servers to connect, and control
53 * whether and how to start the server automatically, if it was not
54 * already running. There is also an option for JACK to generate a
55 * unique client name, when necessary.
57 * @param client_name of at most jack_client_name_size() characters.
58 * The name scope is local to each server. Unless forbidden by the
59 * @ref JackUseExactName option, the server will modify this name to
60 * create a unique variant, if needed.
62 * @param options formed by OR-ing together @ref JackOptions bits.
63 * Only the @ref JackOpenOptions bits are allowed.
65 * @param status (if non-NULL) an address for JACK to return
66 * information from the open operation. This status word is formed by
67 * OR-ing together the relevant @ref JackStatus bits.
70 * <b>Optional parameters:</b> depending on corresponding [@a options
71 * bits] additional parameters may follow @a status (in this order).
73 * @arg [@ref JackServerName] <em>(char *) server_name</em> selects
74 * from among several possible concurrent server instances. Server
75 * names are unique to each user. If unspecified, use "default"
76 * unless \$JACK_DEFAULT_SERVER is defined in the process environment.
78 * @return Opaque client handle if successful. If this is NULL, the
79 * open operation failed, @a *status includes @ref JackFailure and the
80 * caller is not a JACK client.
82 jack_client_t * jack_client_open (const char *client_name,
83 jack_options_t options,
84 jack_status_t *status, ...);
86 /**
87 * Attempt to become an external client of the Jack server.
89 * JACK is evolving a mechanism for automatically starting the server
90 * when needed. As a transition, jack_client_new() only does this
91 * when \$JACK_START_SERVER is defined in the environment of the
92 * calling process. In the future this will become normal behavior.
93 * For full control of this feature, use jack_client_open(), instead.
94 * In either case, defining \$JACK_NO_START_SERVER disables this
95 * feature.
97 * @param client_name of at most jack_client_name_size() characters.
98 * If this name is already in use, the request fails.
100 * @return Opaque client handle if successful, otherwise NULL.
102 * @note Failure generally means that the JACK server is not running.
103 * If there was some other problem, it will be reported via the @ref
104 * jack_error_callback mechanism. Use jack_client_open() and check
105 * the @a status parameter for more detailed information.
107 jack_client_t * jack_client_new (const char *client_name);
110 * Disconnects an external client from a JACK server.
112 * @return 0 on success, otherwise a non-zero error code
114 int jack_client_close (jack_client_t *client);
117 * @return the maximum number of characters in a JACK client name
118 * including the final NULL character. This value is a constant.
120 int jack_client_name_size (void);
123 * @return pointer to actual client name. This is useful when @ref
124 * JackUseExactName is not specified on open and @ref
125 * JackNameNotUnique status was returned. In that case, the actual
126 * name will differ from the @a client_name requested.
128 char * jack_get_client_name (jack_client_t *client);
131 * Load an internal client into the Jack server.
133 * Internal clients run inside the JACK server process. They can use
134 * most of the same functions as external clients. Each internal
135 * client must declare jack_initialize() and jack_finish() entry
136 * points, called at load and unload times. See inprocess.c for an
137 * example of how to write an internal client.
139 * @deprecated Please use jack_internal_client_load().
141 * @param client_name of at most jack_client_name_size() characters.
143 * @param load_name of a shared object file containing the code for
144 * the new client.
146 * @param load_init an arbitary string passed to the jack_initialize()
147 * routine of the new client (may be NULL).
149 * @return 0 if successful.
151 int jack_internal_client_new (const char *client_name,
152 const char *load_name,
153 const char *load_init);
155 jack_client_t* my_jack_internal_client_new(const char* client_name);
158 * Remove an internal client from a JACK server.
160 * @deprecated Please use jack_internal_client_load().
162 void jack_internal_client_close (const char *client_name);
164 void my_jack_internal_client_close (jack_client_t* client);
167 * @param client pointer to JACK client structure.
169 * Check if the JACK subsystem is running with -R (--realtime).
171 * @return 1 if JACK is running realtime, 0 otherwise
173 int jack_is_realtime (jack_client_t *client);
176 * @param client pointer to JACK client structure.
177 * @param function The jack_shutdown function pointer.
178 * @param arg The arguments for the jack_shutdown function.
180 * Register a function (and argument) to be called if and when the
181 * JACK server shuts down the client thread. The function must
182 * be written as if it were an asynchonrous POSIX signal
183 * handler --- use only async-safe functions, and remember that it
184 * is executed from another thread. A typical function might
185 * set a flag or write to a pipe so that the rest of the
186 * application knows that the JACK client thread has shut
187 * down.
189 * NOTE: clients do not need to call this. It exists only
190 * to help more complex clients understand what is going
191 * on. It should be called before jack_client_activate().
193 void jack_on_shutdown (jack_client_t *client,
194 void (*function)(void *arg), void *arg);
197 * Tell the Jack server to call @a process_callback whenever there is
198 * work be done, passing @a arg as the second argument.
200 * The code in the supplied function must be suitable for real-time
201 * execution. That means that it cannot call functions that might
202 * block for a long time.  This includes malloc, free, printf,
203 * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
204 * pthread_cond_wait, etc, etc.  See
205 * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
206 * for more information.
208 * @return 0 on success, otherwise a non-zero error code, causing JACK
209 * to remove that client from the process() graph.
211 int jack_set_process_callback (jack_client_t *client,
212 JackProcessCallback process_callback,
213 void *arg);
216 * Tell JACK to call @a thread_init_callback once just after
217 * the creation of the thread in which all other callbacks
218 * will be handled.
220 * The code in the supplied function does not need to be
221 * suitable for real-time execution.
223 * @return 0 on success, otherwise a non-zero error code, causing JACK
224 * to remove that client from the process() graph.
226 int jack_set_thread_init_callback (jack_client_t *client,
227 JackThreadInitCallback thread_init_callback,
228 void *arg);
231 * Tell the Jack server to call @a freewheel_callback
232 * whenever we enter or leave "freewheel" mode, passing @a
233 * arg as the second argument. The first argument to the
234 * callback will be non-zero if JACK is entering freewheel
235 * mode, and zero otherwise.
237 * @return 0 on success, otherwise a non-zero error code.
239 int jack_set_freewheel_callback (jack_client_t *client,
240 JackFreewheelCallback freewheel_callback,
241 void *arg);
244 * Start/Stop JACK's "freewheel" mode.
246 * When in "freewheel" mode, JACK no longer waits for
247 * any external event to begin the start of the next process
248 * cycle.
250 * As a result, freewheel mode causes "faster than realtime"
251 * execution of a JACK graph. If possessed, real-time
252 * scheduling is dropped when entering freewheel mode, and
253 * if appropriate it is reacquired when stopping.
255 * IMPORTANT: on systems using capabilities to provide real-time
256 * scheduling (i.e. Linux kernel 2.4), if onoff is zero, this function
257 * must be called from the thread that originally called jack_activate().
258 * This restriction does not apply to other systems (e.g. Linux kernel 2.6
259 * or OS X).
261 * @param client pointer to JACK client structure
262 * @param onoff if non-zero, freewheel mode starts. Otherwise
263 * freewheel mode ends.
265 * @return 0 on success, otherwise a non-zero error code.
267 int jack_set_freewheel(jack_client_t* client, int onoff);
270 * Change the buffer size passed to the @a process_callback.
272 * This operation stops the JACK engine process cycle, then calls all
273 * registered @a bufsize_callback functions before restarting the
274 * process cycle. This will cause a gap in the audio flow, so it
275 * should only be done at appropriate stopping points.
277 * @see jack_set_buffer_size_callback()
279 * @param client pointer to JACK client structure.
280 * @param nframes new buffer size. Must be a power of two.
282 * @return 0 on success, otherwise a non-zero error code
284 int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
287 * Tell JACK to call @a bufsize_callback whenever the size of the the
288 * buffer that will be passed to the @a process_callback is about to
289 * change. Clients that depend on knowing the buffer size must supply
290 * a @a bufsize_callback before activating themselves.
292 * @param client pointer to JACK client structure.
293 * @param bufsize_callback function to call when the buffer size changes.
294 * @param arg argument for @a bufsize_callback.
296 * @return 0 on success, otherwise a non-zero error code
298 int jack_set_buffer_size_callback (jack_client_t *client,
299 JackBufferSizeCallback bufsize_callback,
300 void *arg);
303 * Tell the Jack server to call @a srate_callback whenever the system
304 * sample rate changes.
306 * @return 0 on success, otherwise a non-zero error code
308 int jack_set_sample_rate_callback (jack_client_t *client,
309 JackSampleRateCallback srate_callback,
310 void *arg);
313 * Tell the JACK server to call @a registration_callback whenever a
314 * port is registered or unregistered, passing @a arg as a parameter.
316 * @return 0 on success, otherwise a non-zero error code
318 int jack_set_port_registration_callback (jack_client_t *,
319 JackPortRegistrationCallback
320 registration_callback, void *arg);
323 * Tell the JACK server to call @a graph_callback whenever the
324 * processing graph is reordered, passing @a arg as a parameter.
326 * @return 0 on success, otherwise a non-zero error code
328 int jack_set_graph_order_callback (jack_client_t *,
329 JackGraphOrderCallback graph_callback,
330 void *);
333 * Tell the JACK server to call @a xrun_callback whenever there is a
334 * xrun, passing @a arg as a parameter.
336 * @return 0 on success, otherwise a non-zero error code
338 int jack_set_xrun_callback (jack_client_t *,
339 JackXRunCallback xrun_callback, void *arg);
342 * Tell the Jack server that the program is ready to start processing
343 * audio.
345 * @return 0 on success, otherwise a non-zero error code
347 int jack_activate (jack_client_t *client);
350 * Tell the Jack server to remove this @a client from the process
351 * graph. Also, disconnect all ports belonging to it, since inactive
352 * clients have no port connections.
354 * @return 0 on success, otherwise a non-zero error code
356 int jack_deactivate (jack_client_t *client);
359 * Create a new port for the client. This is an object used for moving
360 * data of any type in or out of the client. Ports may be connected
361 * in various ways.
363 * Each port has a short name. The port's full name contains the name
364 * of the client concatenated with a colon (:) followed by its short
365 * name. The jack_port_name_size() is the maximum length of this full
366 * name. Exceeding that will cause the port registration to fail and
367 * return NULL.
369 * All ports have a type, which may be any non-NULL and non-zero
370 * length string, passed as an argument. Some port types are built
371 * into the JACK API, currently only JACK_DEFAULT_AUDIO_TYPE.
373 * @param client pointer to JACK client structure.
374 * @param port_name non-empty short name for the new port (not
375 * including the leading @a "client_name:").
376 * @param port_type port type name. If longer than
377 * jack_port_type_size(), only that many characters are significant.
378 * @param flags @ref JackPortFlags bit mask.
379 * @param buffer_size must be non-zero if this is not a built-in @a
380 * port_type. Otherwise, it is ignored.
382 * @return jack_port_t pointer on success, otherwise NULL.
384 jack_port_t * jack_port_register (jack_client_t *client,
385 const char *port_name,
386 const char *port_type,
387 unsigned long flags,
388 unsigned long buffer_size);
391 * Remove the port from the client, disconnecting any existing
392 * connections.
394 * @return 0 on success, otherwise a non-zero error code
396 int jack_port_unregister (jack_client_t *, jack_port_t *);
399 * This returns a pointer to the memory area associated with the
400 * specified port. For an output port, it will be a memory area
401 * that can be written to; for an input port, it will be an area
402 * containing the data from the port's connection(s), or
403 * zero-filled. if there are multiple inbound connections, the data
404 * will be mixed appropriately.
406 * FOR OUTPUT PORTS ONLY
407 * ---------------------
408 * You may cache the value returned, but only between calls to
409 * your "blocksize" callback. For this reason alone, you should
410 * either never cache the return value or ensure you have
411 * a "blocksize" callback and be sure to invalidate the cached
412 * address from there.
414 void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
417 * @return the full name of the jack_port_t (including the @a
418 * "client_name:" prefix).
420 * @see jack_port_name_size().
422 const char * jack_port_name (const jack_port_t *port);
425 * @return the short name of the jack_port_t (not including the @a
426 * "client_name:" prefix).
428 * @see jack_port_name_size().
430 const char * jack_port_short_name (const jack_port_t *port);
433 * @return the @ref JackPortFlags of the jack_port_t.
435 int jack_port_flags (const jack_port_t *port);
438 * @return the @a port type, at most jack_port_type_size() characters
439 * including a final NULL.
441 const char * jack_port_type (const jack_port_t *port);
444 * @return TRUE if the jack_port_t belongs to the jack_client_t.
446 int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
449 * @return number of connections to or from @a port.
451 * @pre The calling client must own @a port.
453 int jack_port_connected (const jack_port_t *port);
456 * @return TRUE if the locally-owned @a port is @b directly connected
457 * to the @a port_name.
459 * @see jack_port_name_size()
461 int jack_port_connected_to (const jack_port_t *port,
462 const char *port_name);
465 * @return a null-terminated array of full port names to which the @a
466 * port is connected. If none, returns NULL.
468 * The caller is responsible for calling free(3) on any non-NULL
469 * returned value.
471 * @param port locally owned jack_port_t pointer.
473 * @see jack_port_name_size(), jack_port_get_all_connections()
475 const char ** jack_port_get_connections (const jack_port_t *port);
478 * @return a null-terminated array of full port names to which the @a
479 * port is connected. If none, returns NULL.
481 * The caller is responsible for calling free(3) on any non-NULL
482 * returned value.
484 * This differs from jack_port_get_connections() in two important
485 * respects:
487 * 1) You may not call this function from code that is
488 * executed in response to a JACK event. For example,
489 * you cannot use it in a GraphReordered handler.
491 * 2) You need not be the owner of the port to get information
492 * about its connections.
494 * @see jack_port_name_size()
496 const char ** jack_port_get_all_connections (const jack_client_t *client,
497 const jack_port_t *port);
500 * A client may call this on a pair of its own ports to
501 * semi-permanently wire them together. This means that
502 * a client that wants to direct-wire an input port to
503 * an output port can call this and then no longer
504 * have to worry about moving data between them. Any data
505 * arriving at the input port will appear automatically
506 * at the output port.
508 * The 'destination' port must be an output port. The 'source'
509 * port must be an input port. Both ports must belong to
510 * the same client. You cannot use this to tie ports between
511 * clients. That is what a connection is for.
513 * @return 0 on success, otherwise a non-zero error code
515 int jack_port_tie (jack_port_t *src, jack_port_t *dst);
518 * This undoes the effect of jack_port_tie(). The port
519 * should be same as the 'destination' port passed to
520 * jack_port_tie().
522 * @return 0 on success, otherwise a non-zero error code
524 int jack_port_untie (jack_port_t *port);
527 * A client may call this function to prevent other objects
528 * from changing the connection status of a port. The port
529 * must be owned by the calling client.
531 * @return 0 on success, otherwise a non-zero error code
533 int jack_port_lock (jack_client_t *, jack_port_t *);
536 * This allows other objects to change the connection status of a port.
538 * @return 0 on success, otherwise a non-zero error code
540 int jack_port_unlock (jack_client_t *, jack_port_t *);
543 * @return the time (in frames) between data being available or
544 * delivered at/to a port, and the time at which it arrived at or is
545 * delivered to the "other side" of the port. E.g. for a physical
546 * audio output port, this is the time between writing to the port and
547 * when the signal will leave the connector. For a physical audio
548 * input port, this is the time between the sound arriving at the
549 * connector and the corresponding frames being readable from the
550 * port.
552 jack_nframes_t jack_port_get_latency (jack_port_t *port);
555 * The maximum of the sum of the latencies in every
556 * connection path that can be drawn between the port and other
557 * ports with the @ref JackPortIsTerminal flag set.
559 jack_nframes_t jack_port_get_total_latency (jack_client_t *,
560 jack_port_t *port);
563 * The port latency is zero by default. Clients that control
564 * physical hardware with non-zero latency should call this
565 * to set the latency to its correct value. Note that the value
566 * should include any systemic latency present "outside" the
567 * physical hardware controlled by the client. For example,
568 * for a client controlling a digital audio interface connected
569 * to an external digital converter, the latency setting should
570 * include both buffering by the audio interface *and* the converter.
572 void jack_port_set_latency (jack_port_t *, jack_nframes_t);
577 int jack_recompute_total_latencies (jack_client_t*);
580 * Modify a port's short name. May be called at any time. If the
581 * resulting full name (including the @a "client_name:" prefix) is
582 * longer than jack_port_name_size(), it will be truncated.
584 * @return 0 on success, otherwise a non-zero error code.
586 int jack_port_set_name (jack_port_t *port, const char *port_name);
589 * If @ref JackPortCanMonitor is set for this @a port, turn input
590 * monitoring on or off. Otherwise, do nothing.
592 int jack_port_request_monitor (jack_port_t *port, int onoff);
595 * If @ref JackPortCanMonitor is set for this @a port_name, turn input
596 * monitoring on or off. Otherwise, do nothing.
598 * @return 0 on success, otherwise a non-zero error code.
600 * @see jack_port_name_size()
602 int jack_port_request_monitor_by_name (jack_client_t *client,
603 const char *port_name, int onoff);
606 * If @ref JackPortCanMonitor is set for a port, this function turns
607 * on input monitoring if it was off, and turns it off if only one
608 * request has been made to turn it on. Otherwise it does nothing.
610 * @return 0 on success, otherwise a non-zero error code
612 int jack_port_ensure_monitor (jack_port_t *port, int onoff);
615 * @return TRUE if input monitoring has been requested for @a port.
617 int jack_port_monitoring_input (jack_port_t *port);
620 * Establish a connection between two ports.
622 * When a connection exists, data written to the source port will
623 * be available to be read at the destination port.
625 * @pre The port types must be identical.
627 * @pre The @ref JackPortFlags of the @a source_port must include @ref
628 * JackPortIsOutput.
630 * @pre The @ref JackPortFlags of the @a destination_port must include
631 * @ref JackPortIsInput.
633 * @return 0 on success, EEXIST if the connection is already made,
634 * otherwise a non-zero error code
636 int jack_connect (jack_client_t *,
637 const char *source_port,
638 const char *destination_port);
641 * Remove a connection between two ports.
643 * @pre The port types must be identical.
645 * @pre The @ref JackPortFlags of the @a source_port must include @ref
646 * JackPortIsOutput.
648 * @pre The @ref JackPortFlags of the @a destination_port must include
649 * @ref JackPortIsInput.
651 * @return 0 on success, otherwise a non-zero error code
653 int jack_disconnect (jack_client_t *,
654 const char *source_port,
655 const char *destination_port);
658 * Perform the same function as jack_disconnect() using port handles
659 * rather than names. This avoids the name lookup inherent in the
660 * name-based version.
662 * Clients connecting their own ports are likely to use this function,
663 * while generic connection clients (e.g. patchbays) would use
664 * jack_disconnect().
666 int jack_port_disconnect (jack_client_t *, jack_port_t *);
669 * @return the maximum number of characters in a full JACK port name
670 * including the final NULL character. This value is a constant.
672 * A port's full name contains the owning client name concatenated
673 * with a colon (:) followed by its short name and a NULL
674 * character.
676 int jack_port_name_size(void);
679 * @return the maximum number of characters in a JACK port type name
680 * including the final NULL character. This value is a constant.
682 int jack_port_type_size(void);
685 * @return the sample rate of the jack system, as set by the user when
686 * jackd was started.
688 jack_nframes_t jack_get_sample_rate (jack_client_t *);
691 * @return the current maximum size that will ever be passed to the @a
692 * process_callback. It should only be used *before* the client has
693 * been activated. This size may change, clients that depend on it
694 * must register a @a bufsize_callback so they will be notified if it
695 * does.
697 * @see jack_set_buffer_size_callback()
699 jack_nframes_t jack_get_buffer_size (jack_client_t *);
702 * @param port_name_pattern A regular expression used to select
703 * ports by name. If NULL or of zero length, no selection based
704 * on name will be carried out.
705 * @param type_name_pattern A regular expression used to select
706 * ports by type. If NULL or of zero length, no selection based
707 * on type will be carried out.
708 * @param flags A value used to select ports by their flags.
709 * If zero, no selection based on flags will be carried out.
711 * @return a NULL-terminated array of ports that match the specified
712 * arguments. The caller is responsible for calling free(3) any
713 * non-NULL returned value.
715 * @see jack_port_name_size(), jack_port_type_size()
717 const char ** jack_get_ports (jack_client_t *,
718 const char *port_name_pattern,
719 const char *type_name_pattern,
720 unsigned long flags);
723 * @return address of the jack_port_t named @a port_name.
725 * @see jack_port_name_size()
727 jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
730 * @return address of the jack_port_t of a @a port_id.
732 jack_port_t * jack_port_by_id (jack_client_t *client,
733 jack_port_id_t port_id);
736 * Old-style interface to become the timebase for the entire JACK
737 * subsystem.
739 * @deprecated This function still exists for compatibility with the
740 * earlier transport interface, but it does nothing. Instead, see
741 * transport.h and use jack_set_timebase_callback().
743 * @return ENOSYS, function not implemented.
745 int jack_engine_takeover_timebase (jack_client_t *);
748 * @return the time in frames that has passed since the JACK server
749 * began the current process cycle.
751 jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
754 * @return an estimate of the current time in frames. This is a
755 * running counter, no significance should be attached to its value,
756 * but it can be compared to a previously returned value.
758 jack_nframes_t jack_frame_time (const jack_client_t *);
761 * @return the frame_time after the last processing of the graph
762 * this is only to be used from the process callback.
764 * This function can be used to put timestamps generated by
765 * jack_frame_time() in correlation to the current process cycle.
767 jack_nframes_t jack_last_frame_time (const jack_client_t *client);
770 * @return the current CPU load estimated by JACK. This is a running
771 * average of the time it takes to execute a full process cycle for
772 * all clients as a percentage of the real time available per cycle
773 * determined by the buffer size and sample rate.
775 float jack_cpu_load (jack_client_t *client);
778 * @return the pthread ID of the thread running the JACK client side
779 * code.
781 pthread_t jack_client_thread_id (jack_client_t *);
784 * Display JACK error message.
786 * Set via jack_set_error_function(), otherwise a JACK-provided
787 * default will print @a msg (plus a newline) to stderr.
789 * @param msg error message text (no newline at end).
791 extern void (*jack_error_callback)(const char *msg);
794 * Set the @ref jack_error_callback for error message display.
796 * The JACK library provides two built-in callbacks for this purpose:
797 * default_jack_error_callback() and silent_jack_error_callback().
799 void jack_set_error_function (void (*func)(const char *));
801 #ifdef __cplusplus
803 #endif
805 #endif /* __jack_h__ */