ensure that client-side message buffer thread calls thread_init callback if/when...
[jack.git] / jack / jack.h
blobb76cdc18afadd4f37edc098513532f3288722ffe
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.
21 #ifndef __jack_h__
22 #define __jack_h__
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 #include <pthread.h>
30 #include <jack/types.h>
31 #include <jack/transport.h>
33 /**
34 * Note: More documentation can be found in jack/types.h.
38 /*************************************************************
39 * NOTE: JACK_WEAK_EXPORT ***MUST*** be used on every function
40 * added to the JACK API after the 0.116.2 release.
41 *************************************************************/
43 #ifndef JACK_WEAK_EXPORT
44 #ifdef __GNUC__
45 /* JACK_WEAK_EXPORT needs to be a macro which
46 expands into a compiler directive. If non-null, the directive
47 must tell the compiler to arrange for weak linkage of
48 the symbol it used with. For this to work full may
49 require linker arguments in the client as well.
51 #define JACK_WEAK_EXPORT __attribute__((weak))
52 #else
53 /* Add other things here for non-gcc platforms */
54 #endif
55 #endif
58 /**
59 * @defgroup ClientFunctions Creating & manipulating clients
60 * @{
63 /**
64 * Open an external client session with a JACK server. This interface
65 * is more complex but more powerful than jack_client_new(). With it,
66 * clients may choose which of several servers to connect, and control
67 * whether and how to start the server automatically, if it was not
68 * already running. There is also an option for JACK to generate a
69 * unique client name, when necessary.
71 * @param client_name of at most jack_client_name_size() characters.
72 * The name scope is local to each server. Unless forbidden by the
73 * @ref JackUseExactName option, the server will modify this name to
74 * create a unique variant, if needed.
76 * @param options formed by OR-ing together @ref JackOptions bits.
77 * Only the @ref JackOpenOptions bits are allowed.
79 * @param status (if non-NULL) an address for JACK to return
80 * information from the open operation. This status word is formed by
81 * OR-ing together the relevant @ref JackStatus bits.
84 * <b>Optional parameters:</b> depending on corresponding [@a options
85 * bits] additional parameters may follow @a status (in this order).
87 * @arg [@ref JackServerName] <em>(char *) server_name</em> selects
88 * from among several possible concurrent server instances. Server
89 * names are unique to each user. If unspecified, use "default"
90 * unless \$JACK_DEFAULT_SERVER is defined in the process environment.
92 * @return Opaque client handle if successful. If this is NULL, the
93 * open operation failed, @a *status includes @ref JackFailure and the
94 * caller is not a JACK client.
96 jack_client_t *jack_client_open (const char *client_name,
97 jack_options_t options,
98 jack_status_t *status, ...);
101 * <b>THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED IN
102 * NEW JACK CLIENTS</b>
105 jack_client_t *jack_client_new (const char *client_name);
108 * Disconnects an external client from a JACK server.
110 * @return 0 on success, otherwise a non-zero error code
112 int jack_client_close (jack_client_t *client);
115 * @return the maximum number of characters in a JACK client name
116 * including the final NULL character. This value is a constant.
118 int jack_client_name_size (void);
121 * @return pointer to actual client name. This is useful when @ref
122 * JackUseExactName is not specified on open and @ref
123 * JackNameNotUnique status was returned. In that case, the actual
124 * name will differ from the @a client_name requested.
126 char *jack_get_client_name (jack_client_t *client);
129 * Load an internal client into the Jack server.
131 * Internal clients run inside the JACK server process. They can use
132 * most of the same functions as external clients. Each internal
133 * client must declare jack_initialize() and jack_finish() entry
134 * points, called at load and unload times. See inprocess.c for an
135 * example of how to write an internal client.
137 * @deprecated Please use jack_internal_client_load().
139 * @param client_name of at most jack_client_name_size() characters.
141 * @param load_name of a shared object file containing the code for
142 * the new client.
144 * @param load_init an arbitary string passed to the jack_initialize()
145 * routine of the new client (may be NULL).
147 * @return 0 if successful.
149 int jack_internal_client_new (const char *client_name,
150 const char *load_name,
151 const char *load_init);
154 * Remove an internal client from a JACK server.
156 * @deprecated Please use jack_internal_client_load().
158 void jack_internal_client_close (const char *client_name);
161 * Tell the Jack server that the program is ready to start processing
162 * audio.
164 * @return 0 on success, otherwise a non-zero error code
166 int jack_activate (jack_client_t *client);
169 * Tell the Jack server to remove this @a client from the process
170 * graph. Also, disconnect all ports belonging to it, since inactive
171 * clients have no port connections.
173 * @return 0 on success, otherwise a non-zero error code
175 int jack_deactivate (jack_client_t *client);
178 * @return the pthread ID of the thread running the JACK client side
179 * code.
181 pthread_t jack_client_thread_id (jack_client_t *);
183 /*@}*/
186 * @param client pointer to JACK client structure.
188 * Check if the JACK subsystem is running with -R (--realtime).
190 * @return 1 if JACK is running realtime, 0 otherwise
192 int jack_is_realtime (jack_client_t *client);
195 * @defgroup NonCallbackAPI The non-callback API
196 * @{
200 * <b>THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED IN
201 * NEW JACK CLIENTS</b>
203 * It should be replace by use of @ jack_cycle_wait and @ jack_cycle_signal functions.
206 jack_nframes_t jack_thread_wait (jack_client_t*, int status);
209 * Wait until this JACK client should process data.
211 * @param client - pointer to a JACK client structure
213 * @return the number of frames of data to process
215 jack_nframes_t jack_cycle_wait (jack_client_t* client);
218 * Signal next clients in the graph.
220 * @param client - pointer to a JACK client structure
221 * @param status - if non-zero, calling thread should exit
223 void jack_cycle_signal (jack_client_t* client, int status);
226 * Tell the Jack server to call @a thread_callback in the RT thread.
227 * Typical use are in conjunction with @a jack_cycle_wait and @ jack_cycle_signal functions.
228 * The code in the supplied function must be suitable for real-time
229 * execution. That means that it cannot call functions that might
230 * block for a long time. This includes malloc, free, printf,
231 * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
232 * pthread_cond_wait, etc, etc.
234 * @return 0 on success, otherwise a non-zero error code.
236 int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg);
238 /*@}*/
241 * @defgroup ClientCallbacks Setting Client Callbacks
242 * @{
246 * Tell JACK to call @a thread_init_callback once just after
247 * the creation of the thread in which all other callbacks
248 * will be handled.
250 * The code in the supplied function does not need to be
251 * suitable for real-time execution.
253 * @return 0 on success, otherwise a non-zero error code, causing JACK
254 * to remove that client from the process() graph.
256 int jack_set_thread_init_callback (jack_client_t *client,
257 JackThreadInitCallback thread_init_callback,
258 void *arg);
260 /**
261 * @param client pointer to JACK client structure.
262 * @param function The jack_shutdown function pointer.
263 * @param arg The arguments for the jack_shutdown function.
265 * Register a function (and argument) to be called if and when the
266 * JACK server shuts down the client thread. The function must
267 * be written as if it were an asynchonrous POSIX signal
268 * handler --- use only async-safe functions, and remember that it
269 * is executed from another thread. A typical function might
270 * set a flag or write to a pipe so that the rest of the
271 * application knows that the JACK client thread has shut
272 * down.
274 * NOTE: clients do not need to call this. It exists only
275 * to help more complex clients understand what is going
276 * on. It should be called before jack_client_activate().
278 * NOTE: if a client calls this AND jack_on_info_shutdown(), then
279 * the event of a client thread shutdown, the callback
280 * passed to this function will not be called, and the one passed to
281 * jack_on_info_shutdown() will.
283 void jack_on_shutdown (jack_client_t *client,
284 JackShutdownCallback function, void *arg);
287 * @param client pointer to JACK client structure.
288 * @param function The jack_shutdown function pointer.
289 * @param arg The arguments for the jack_shutdown function.
291 * Register a function (and argument) to be called if and when the
292 * JACK server shuts down the client thread. The function must
293 * be written as if it were an asynchonrous POSIX signal
294 * handler --- use only async-safe functions, and remember that it
295 * is executed from another thread. A typical function might
296 * set a flag or write to a pipe so that the rest of the
297 * application knows that the JACK client thread has shut
298 * down.
300 * NOTE: clients do not need to call this. It exists only
301 * to help more complex clients understand what is going
302 * on. It should be called before jack_client_activate().
304 * NOTE: if a client calls this AND jack_on_shutdown(), then in the
305 * event of a client thread shutdown, the callback passed to
306 * this function will be called, and the one passed to
307 * jack_on_shutdown() will not.
309 void jack_on_info_shutdown (jack_client_t *client,
310 JackInfoShutdownCallback function, void *arg) JACK_WEAK_EXPORT;
313 * Tell the Jack server to call @a process_callback whenever there is
314 * work be done, passing @a arg as the second argument.
316 * The code in the supplied function must be suitable for real-time
317 * execution. That means that it cannot call functions that might
318 * block for a long time. This includes malloc, free, printf,
319 * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
320 * pthread_cond_wait, etc, etc.
322 * @return 0 on success, otherwise a non-zero error code, causing JACK
323 * to remove that client from the process() graph.
325 int jack_set_process_callback (jack_client_t *client,
326 JackProcessCallback process_callback,
327 void *arg);
330 * Tell the Jack server to call @a freewheel_callback
331 * whenever we enter or leave "freewheel" mode, passing @a
332 * arg as the second argument. The first argument to the
333 * callback will be non-zero if JACK is entering freewheel
334 * mode, and zero otherwise.
336 * @return 0 on success, otherwise a non-zero error code.
338 int jack_set_freewheel_callback (jack_client_t *client,
339 JackFreewheelCallback freewheel_callback,
340 void *arg);
343 * Tell JACK to call @a bufsize_callback whenever the size of the the
344 * buffer that will be passed to the @a process_callback is about to
345 * change. Clients that depend on knowing the buffer size must supply
346 * a @a bufsize_callback before activating themselves.
348 * @param client pointer to JACK client structure.
349 * @param bufsize_callback function to call when the buffer size changes.
350 * @param arg argument for @a bufsize_callback.
352 * @return 0 on success, otherwise a non-zero error code
354 int jack_set_buffer_size_callback (jack_client_t *client,
355 JackBufferSizeCallback bufsize_callback,
356 void *arg);
359 * Tell the Jack server to call @a srate_callback whenever the system
360 * sample rate changes.
362 * @return 0 on success, otherwise a non-zero error code
364 int jack_set_sample_rate_callback (jack_client_t *client,
365 JackSampleRateCallback srate_callback,
366 void *arg);
369 * Tell the JACK server to call @a registration_callback whenever a
370 * port is registered or unregistered, passing @a arg as a parameter.
372 * @return 0 on success, otherwise a non-zero error code
374 int jack_set_client_registration_callback (jack_client_t *,
375 JackClientRegistrationCallback
376 registration_callback, void *arg);
379 * Tell the JACK server to call @a registration_callback whenever a
380 * port is registered or unregistered, passing @a arg as a parameter.
382 * @return 0 on success, otherwise a non-zero error code
384 int jack_set_port_registration_callback (jack_client_t *,
385 JackPortRegistrationCallback
386 registration_callback, void *arg);
389 * Tell the JACK server to call @a connect_callback whenever a
390 * port is connected or disconnected, passing @a arg as a parameter.
392 * @return 0 on success, otherwise a non-zero error code
394 int jack_set_port_connect_callback (jack_client_t *,
395 JackPortConnectCallback
396 connect_callback, void *arg);
398 * Tell the JACK server to call @a graph_callback whenever the
399 * processing graph is reordered, passing @a arg as a parameter.
401 * @return 0 on success, otherwise a non-zero error code
403 int jack_set_graph_order_callback (jack_client_t *,
404 JackGraphOrderCallback graph_callback,
405 void *);
408 * Tell the JACK server to call @a xrun_callback whenever there is a
409 * xrun, passing @a arg as a parameter.
411 * @return 0 on success, otherwise a non-zero error code
413 int jack_set_xrun_callback (jack_client_t *,
414 JackXRunCallback xrun_callback, void *arg);
416 /*@}*/
419 * @defgroup ServerControl Controlling & querying JACK server operation
420 * @{
424 * Start/Stop JACK's "freewheel" mode.
426 * When in "freewheel" mode, JACK no longer waits for
427 * any external event to begin the start of the next process
428 * cycle.
430 * As a result, freewheel mode causes "faster than realtime"
431 * execution of a JACK graph. If possessed, real-time
432 * scheduling is dropped when entering freewheel mode, and
433 * if appropriate it is reacquired when stopping.
435 * IMPORTANT: on systems using capabilities to provide real-time
436 * scheduling (i.e. Linux kernel 2.4), if onoff is zero, this function
437 * must be called from the thread that originally called jack_activate().
438 * This restriction does not apply to other systems (e.g. Linux kernel 2.6
439 * or OS X).
441 * @param client pointer to JACK client structure
442 * @param onoff if non-zero, freewheel mode starts. Otherwise
443 * freewheel mode ends.
445 * @return 0 on success, otherwise a non-zero error code.
447 int jack_set_freewheel(jack_client_t* client, int onoff);
450 * Change the buffer size passed to the @a process_callback.
452 * This operation stops the JACK engine process cycle, then calls all
453 * registered @a bufsize_callback functions before restarting the
454 * process cycle. This will cause a gap in the audio flow, so it
455 * should only be done at appropriate stopping points.
457 * @see jack_set_buffer_size_callback()
459 * @param client pointer to JACK client structure.
460 * @param nframes new buffer size. Must be a power of two.
462 * @return 0 on success, otherwise a non-zero error code
464 int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
467 * @return the sample rate of the jack system, as set by the user when
468 * jackd was started.
470 jack_nframes_t jack_get_sample_rate (jack_client_t *);
473 * @return the current maximum size that will ever be passed to the @a
474 * process_callback. It should only be used *before* the client has
475 * been activated. This size may change, clients that depend on it
476 * must register a @a bufsize_callback so they will be notified if it
477 * does.
479 * @see jack_set_buffer_size_callback()
481 jack_nframes_t jack_get_buffer_size (jack_client_t *);
484 * Old-style interface to become the timebase for the entire JACK
485 * subsystem.
487 * @deprecated This function still exists for compatibility with the
488 * earlier transport interface, but it does nothing. Instead, see
489 * transport.h and use jack_set_timebase_callback().
491 * @return ENOSYS, function not implemented.
493 int jack_engine_takeover_timebase (jack_client_t *);
496 * @return the current CPU load estimated by JACK. This is a running
497 * average of the time it takes to execute a full process cycle for
498 * all clients as a percentage of the real time available per cycle
499 * determined by the buffer size and sample rate.
501 float jack_cpu_load (jack_client_t *client);
504 /*@}*/
507 * @defgroup PortFunctions Creating & manipulating ports
508 * @{
512 * Create a new port for the client. This is an object used for moving
513 * data of any type in or out of the client. Ports may be connected
514 * in various ways.
516 * Each port has a short name. The port's full name contains the name
517 * of the client concatenated with a colon (:) followed by its short
518 * name. The jack_port_name_size() is the maximum length of this full
519 * name. Exceeding that will cause the port registration to fail and
520 * return NULL.
522 * All ports have a type, which may be any non-NULL and non-zero
523 * length string, passed as an argument. Some port types are built
524 * into the JACK API, like JACK_DEFAULT_AUDIO_TYPE or JACK_DEFAULT_MIDI_TYPE
526 * @param client pointer to JACK client structure.
527 * @param port_name non-empty short name for the new port (not
528 * including the leading @a "client_name:").
529 * @param port_type port type name. If longer than
530 * jack_port_type_size(), only that many characters are significant.
531 * @param flags @ref JackPortFlags bit mask.
532 * @param buffer_size must be non-zero if this is not a built-in @a
533 * port_type. Otherwise, it is ignored.
535 * @return jack_port_t pointer on success, otherwise NULL.
537 jack_port_t *jack_port_register (jack_client_t *client,
538 const char *port_name,
539 const char *port_type,
540 unsigned long flags,
541 unsigned long buffer_size);
543 /**
544 * Remove the port from the client, disconnecting any existing
545 * connections.
547 * @return 0 on success, otherwise a non-zero error code
549 int jack_port_unregister (jack_client_t *, jack_port_t *);
552 * This returns a pointer to the memory area associated with the
553 * specified port. For an output port, it will be a memory area
554 * that can be written to; for an input port, it will be an area
555 * containing the data from the port's connection(s), or
556 * zero-filled. if there are multiple inbound connections, the data
557 * will be mixed appropriately.
559 * Do not cache the returned address across process() callbacks.
560 * Port buffers have to be retrieved in each callback for proper functionning.
562 void *jack_port_get_buffer (jack_port_t *, jack_nframes_t);
565 * @return the full name of the jack_port_t (including the @a
566 * "client_name:" prefix).
568 * @see jack_port_name_size().
570 const char *jack_port_name (const jack_port_t *port);
573 * @return the short name of the jack_port_t (not including the @a
574 * "client_name:" prefix).
576 * @see jack_port_name_size().
578 const char *jack_port_short_name (const jack_port_t *port);
581 * @return the @ref JackPortFlags of the jack_port_t.
583 int jack_port_flags (const jack_port_t *port);
586 * @return the @a port type, at most jack_port_type_size() characters
587 * including a final NULL.
589 const char *jack_port_type (const jack_port_t *port);
591 /**
592 * @return TRUE if the jack_port_t belongs to the jack_client_t.
594 int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
596 /**
597 * @return number of connections to or from @a port.
599 * @pre The calling client must own @a port.
601 int jack_port_connected (const jack_port_t *port);
604 * @return TRUE if the locally-owned @a port is @b directly connected
605 * to the @a port_name.
607 * @see jack_port_name_size()
609 int jack_port_connected_to (const jack_port_t *port,
610 const char *port_name);
613 * @return a null-terminated array of full port names to which the @a
614 * port is connected. If none, returns NULL.
616 * The caller is responsible for calling free(3) on any non-NULL
617 * returned value.
619 * @param port locally owned jack_port_t pointer.
621 * @see jack_port_name_size(), jack_port_get_all_connections()
623 const char **jack_port_get_connections (const jack_port_t *port);
626 * @return a null-terminated array of full port names to which the @a
627 * port is connected. If none, returns NULL.
629 * The caller is responsible for calling free(3) on any non-NULL
630 * returned value.
632 * This differs from jack_port_get_connections() in two important
633 * respects:
635 * 1) You may not call this function from code that is
636 * executed in response to a JACK event. For example,
637 * you cannot use it in a GraphReordered handler.
639 * 2) You need not be the owner of the port to get information
640 * about its connections.
642 * @see jack_port_name_size()
644 const char **jack_port_get_all_connections (const jack_client_t *client,
645 const jack_port_t *port);
649 * @deprecated This function will be removed from a future version
650 * of JACK. Do not use it. There is no replacement. It has
651 * turned out to serve essentially no purpose in real-life
652 * JACK clients.
654 int jack_port_tie (jack_port_t *src, jack_port_t *dst);
658 * @deprecated This function will be removed from a future version
659 * of JACK. Do not use it. There is no replacement. It has
660 * turned out to serve essentially no purpose in real-life
661 * JACK clients.
663 int jack_port_untie (jack_port_t *port);
665 /**
666 * @return the time (in frames) between data being available or
667 * delivered at/to a port, and the time at which it arrived at or is
668 * delivered to the "other side" of the port. E.g. for a physical
669 * audio output port, this is the time between writing to the port and
670 * when the signal will leave the connector. For a physical audio
671 * input port, this is the time between the sound arriving at the
672 * connector and the corresponding frames being readable from the
673 * port.
675 jack_nframes_t jack_port_get_latency (jack_port_t *port);
678 * The maximum of the sum of the latencies in every
679 * connection path that can be drawn between the port and other
680 * ports with the @ref JackPortIsTerminal flag set.
682 jack_nframes_t jack_port_get_total_latency (jack_client_t *,
683 jack_port_t *port);
686 * The port latency is zero by default. Clients that control
687 * physical hardware with non-zero latency should call this
688 * to set the latency to its correct value. Note that the value
689 * should include any systemic latency present "outside" the
690 * physical hardware controlled by the client. For example,
691 * for a client controlling a digital audio interface connected
692 * to an external digital converter, the latency setting should
693 * include both buffering by the audio interface *and* the converter.
695 void jack_port_set_latency (jack_port_t *, jack_nframes_t);
698 * Request a complete recomputation of a port's total latency. This
699 * can be called by a client that has just changed the internal
700 * latency of its port using jack_port_set_latency
701 * and wants to ensure that all signal pathways in the graph
702 * are updated with respect to the values that will be returned
703 * by jack_port_get_total_latency.
705 * @return zero for successful execution of the request. non-zero
706 * otherwise.
708 int jack_recompute_total_latency (jack_client_t*, jack_port_t* port);
711 * Request a complete recomputation of all port latencies. This
712 * can be called by a client that has just changed the internal
713 * latency of its port using jack_port_set_latency
714 * and wants to ensure that all signal pathways in the graph
715 * are updated with respect to the values that will be returned
716 * by jack_port_get_total_latency. It allows a client
717 * to change multiple port latencies without triggering a
718 * recompute for each change.
720 * @return zero for successful execution of the request. non-zero
721 * otherwise.
723 int jack_recompute_total_latencies (jack_client_t*);
726 * Modify a port's short name. May be called at any time. If the
727 * resulting full name (including the @a "client_name:" prefix) is
728 * longer than jack_port_name_size(), it will be truncated.
730 * @return 0 on success, otherwise a non-zero error code.
732 int jack_port_set_name (jack_port_t *port, const char *port_name);
735 * Set @a alias as an alias for @a port. May be called at any time.
736 * If the alias is longer than jack_port_name_size(), it will be truncated.
738 * After a successful call, and until JACK exits or
739 * jack_port_unset_alias() is called, may be
740 * used as a alternate name for the port.
742 * Ports can have up to two aliases - if both are already
743 * set, this function will return an error.
745 * @return 0 on success, otherwise a non-zero error code.
747 int jack_port_set_alias (jack_port_t *port, const char *alias);
750 * Remove @a alias as an alias for @a port. May be called at any time.
752 * After a successful call, @a alias can no longer be
753 * used as a alternate name for the port.
755 * @return 0 on success, otherwise a non-zero error code.
757 int jack_port_unset_alias (jack_port_t *port, const char *alias);
760 * Get any aliases known for @port.
762 * @return the number of aliases discovered for the port
764 int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
767 * If @ref JackPortCanMonitor is set for this @a port, turn input
768 * monitoring on or off. Otherwise, do nothing.
770 int jack_port_request_monitor (jack_port_t *port, int onoff);
773 * If @ref JackPortCanMonitor is set for this @a port_name, turn input
774 * monitoring on or off. Otherwise, do nothing.
776 * @return 0 on success, otherwise a non-zero error code.
778 * @see jack_port_name_size()
780 int jack_port_request_monitor_by_name (jack_client_t *client,
781 const char *port_name, int onoff);
784 * If @ref JackPortCanMonitor is set for a port, this function turns
785 * on input monitoring if it was off, and turns it off if only one
786 * request has been made to turn it on. Otherwise it does nothing.
788 * @return 0 on success, otherwise a non-zero error code
790 int jack_port_ensure_monitor (jack_port_t *port, int onoff);
793 * @return TRUE if input monitoring has been requested for @a port.
795 int jack_port_monitoring_input (jack_port_t *port);
798 * Establish a connection between two ports.
800 * When a connection exists, data written to the source port will
801 * be available to be read at the destination port.
803 * @pre The port types must be identical.
805 * @pre The @ref JackPortFlags of the @a source_port must include @ref
806 * JackPortIsOutput.
808 * @pre The @ref JackPortFlags of the @a destination_port must include
809 * @ref JackPortIsInput.
811 * @return 0 on success, EEXIST if the connection is already made,
812 * otherwise a non-zero error code
814 int jack_connect (jack_client_t *,
815 const char *source_port,
816 const char *destination_port);
819 * Remove a connection between two ports.
821 * @pre The port types must be identical.
823 * @pre The @ref JackPortFlags of the @a source_port must include @ref
824 * JackPortIsOutput.
826 * @pre The @ref JackPortFlags of the @a destination_port must include
827 * @ref JackPortIsInput.
829 * @return 0 on success, otherwise a non-zero error code
831 int jack_disconnect (jack_client_t *,
832 const char *source_port,
833 const char *destination_port);
836 * Perform the same function as jack_disconnect() using port handles
837 * rather than names. This avoids the name lookup inherent in the
838 * name-based version.
840 * Clients connecting their own ports are likely to use this function,
841 * while generic connection clients (e.g. patchbays) would use
842 * jack_disconnect().
844 int jack_port_disconnect (jack_client_t *, jack_port_t *);
847 * @return the maximum number of characters in a full JACK port name
848 * including the final NULL character. This value is a constant.
850 * A port's full name contains the owning client name concatenated
851 * with a colon (:) followed by its short name and a NULL
852 * character.
854 int jack_port_name_size(void);
857 * @return the maximum number of characters in a JACK port type name
858 * including the final NULL character. This value is a constant.
860 int jack_port_type_size(void);
861 /*@}*/
864 * @defgroup PortSearching Looking up ports
865 * @{
869 * @param port_name_pattern A regular expression used to select
870 * ports by name. If NULL or of zero length, no selection based
871 * on name will be carried out.
872 * @param type_name_pattern A regular expression used to select
873 * ports by type. If NULL or of zero length, no selection based
874 * on type will be carried out.
875 * @param flags A value used to select ports by their flags.
876 * If zero, no selection based on flags will be carried out.
878 * @return a NULL-terminated array of ports that match the specified
879 * arguments. The caller is responsible for calling free(3) any
880 * non-NULL returned value.
882 * @see jack_port_name_size(), jack_port_type_size()
884 const char **jack_get_ports (jack_client_t *,
885 const char *port_name_pattern,
886 const char *type_name_pattern,
887 unsigned long flags);
890 * @return address of the jack_port_t named @a port_name.
892 * @see jack_port_name_size()
894 jack_port_t *jack_port_by_name (jack_client_t *, const char *port_name);
897 * @return address of the jack_port_t of a @a port_id.
899 jack_port_t *jack_port_by_id (jack_client_t *client,
900 jack_port_id_t port_id);
902 /*@}*/
906 * @defgroup TimeFunctions Handling time
907 * @{
909 * JACK time is in units of 'frames', according to the current sample rate.
910 * The absolute value of frame times is meaningless, frame times have meaning
911 * only relative to each other.
915 * @return the estimated time in frames that has passed since the JACK
916 * server began the current process cycle.
918 jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
921 * @return the estimated current time in frames.
922 * This function is intended for use in other threads (not the process
923 * callback). The return value can be compared with the value of
924 * jack_last_frame_time to relate time in other threads to JACK time.
926 jack_nframes_t jack_frame_time (const jack_client_t *);
929 * @return the precise time at the start of the current process cycle.
930 * This function may only be used from the process callback, and can
931 * be used to interpret timestamps generated by jack_frame_time() in
932 * other threads with respect to the current process cycle.
934 * This is the only jack time function that returns exact time:
935 * when used during the process callback it always returns the same
936 * value (until the next process callback, where it will return
937 * that value + nframes, etc). The return value is guaranteed to be
938 * monotonic and linear in this fashion unless an xrun occurs.
939 * If an xrun occurs, clients must check this value again, as time
940 * may have advanced in a non-linear way (e.g. cycles may have been skipped).
942 jack_nframes_t jack_last_frame_time (const jack_client_t *client);
945 * @return the estimated time in microseconds of the specified frame time
947 jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t);
950 * @return the estimated time in frames for the specified system time.
952 jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t);
955 * @return return JACK's current system time in microseconds,
956 * using the JACK clock source.
958 * The value returned is guaranteed to be monotonic, but not linear.
960 jack_time_t jack_get_time();
962 /*@}*/
965 * @defgroup ErrorOutput Controlling error/information output
967 /*@{*/
970 * Display JACK error message.
972 * Set via jack_set_error_function(), otherwise a JACK-provided
973 * default will print @a msg (plus a newline) to stderr.
975 * @param msg error message text (no newline at end).
977 extern void (*jack_error_callback)(const char *msg);
980 * Set the @ref jack_error_callback for error message display.
982 * The JACK library provides two built-in callbacks for this purpose:
983 * default_jack_error_callback() and silent_jack_error_callback().
985 void jack_set_error_function (void (*func)(const char *));
988 * Display JACK info message.
990 * Set via jack_set_info_function(), otherwise a JACK-provided
991 * default will print @a msg (plus a newline) to stdout.
993 * @param msg info message text (no newline at end).
995 extern void (*jack_info_callback)(const char *msg);
998 * Set the @ref jack_info_callback for info message display.
1000 void jack_set_info_function (void (*func)(const char *));
1001 /*@}*/
1004 * The free function to be used on memory returned by jack_port_get_connections,
1005 * jack_port_get_all_connections and jack_get_ports functions.
1006 * This is MANDATORY on Windows when otherwise all nasty runtime version related crashes can occur.
1007 * Developers are strongly encouraged to use this function instead of the standard "free" function in new code.
1010 void jack_free(void* ptr);
1012 #ifdef __cplusplus
1014 #endif
1016 #endif /* __jack_h__ */