Windows JackRouter sources and project added.
[jack2.git] / common / jack / jack.h
blob74c8b3cbe939397ad1fd5cc958970f38cd1990c2
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"
27 #endif
29 #include <jack/systemdeps.h>
30 #include <jack/types.h>
31 #include <jack/transport.h>
33 /**
34 * Note: More documentation can be found in jack/types.h.
37 /*************************************************************
38 * NOTE: JACK_WEAK_EXPORT ***MUST*** be used on every function
39 * added to the JACK API after the 0.116.2 release.
40 *************************************************************/
42 #ifndef JACK_WEAK_EXPORT
43 #ifdef __GNUC__
44 /* JACK_WEAK_EXPORT needs to be a macro which
45 expands into a compiler directive. If non-null, the directive
46 must tell the compiler to arrange for weak linkage of
47 the symbol it used with. For this to work full may
48 require linker arguments in the client as well.
50 #define JACK_WEAK_EXPORT __attribute__((weak))
51 #else
52 #define JACK_WEAK_EXPORT
53 /* Add other things here for non-gcc platforms */
54 #endif
55 #endif
57 /**
58 * @defgroup ClientFunctions Creating & manipulating clients
59 * @{
62 /**
63 * Call this function to get version of the JACK, in form of several numbers
65 * @param major_ptr pointer to variable receiving major version of JACK.
67 * @param minor_ptr pointer to variable receiving minor version of JACK.
69 * @param major_ptr pointer to variable receiving micro version of JACK.
71 * @param major_ptr pointer to variable receiving protocol version of JACK.
74 void
75 jack_get_version(
76 int *major_ptr,
77 int *minor_ptr,
78 int *micro_ptr,
79 int *proto_ptr);
81 /**
82 * Call this function to get version of the JACK, in form of a string
84 * @return Human readable string describing JACK version being used.
87 const char *
88 jack_get_version_string();
90 /**
91 * Open an external client session with a JACK server. This interface
92 * is more complex but more powerful than jack_client_new(). With it,
93 * clients may choose which of several servers to connect, and control
94 * whether and how to start the server automatically, if it was not
95 * already running. There is also an option for JACK to generate a
96 * unique client name, when necessary.
98 * @param client_name of at most jack_client_name_size() characters.
99 * The name scope is local to each server. Unless forbidden by the
100 * @ref JackUseExactName option, the server will modify this name to
101 * create a unique variant, if needed.
103 * @param options formed by OR-ing together @ref JackOptions bits.
104 * Only the @ref JackOpenOptions bits are allowed.
106 * @param status (if non-NULL) an address for JACK to return
107 * information from the open operation. This status word is formed by
108 * OR-ing together the relevant @ref JackStatus bits.
111 * <b>Optional parameters:</b> depending on corresponding [@a options
112 * bits] additional parameters may follow @a status (in this order).
114 * @arg [@ref JackServerName] <em>(char *) server_name</em> selects
115 * from among several possible concurrent server instances. Server
116 * names are unique to each user. If unspecified, use "default"
117 * unless \$JACK_DEFAULT_SERVER is defined in the process environment.
119 * @return Opaque client handle if successful. If this is NULL, the
120 * open operation failed, @a *status includes @ref JackFailure and the
121 * caller is not a JACK client.
123 jack_client_t * jack_client_open (const char *client_name,
124 jack_options_t options,
125 jack_status_t *status, ...);
128 * \bold THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED IN
129 * NEW JACK CLIENTS
131 * @deprecated Please use jack_client_open().
133 jack_client_t * jack_client_new (const char *client_name);
136 * Disconnects an external client from a JACK server.
138 * @return 0 on success, otherwise a non-zero error code
140 int jack_client_close (jack_client_t *client);
143 * @return the maximum number of characters in a JACK client name
144 * including the final NULL character. This value is a constant.
146 int jack_client_name_size (void);
149 * @return pointer to actual client name. This is useful when @ref
150 * JackUseExactName is not specified on open and @ref
151 * JackNameNotUnique status was returned. In that case, the actual
152 * name will differ from the @a client_name requested.
154 char * jack_get_client_name (jack_client_t *client);
157 * Load an internal client into the Jack server.
159 * Internal clients run inside the JACK server process. They can use
160 * most of the same functions as external clients. Each internal
161 * client must declare jack_initialize() and jack_finish() entry
162 * points, called at load and unload times. See inprocess.c for an
163 * example of how to write an internal client.
165 * @deprecated Please use jack_internal_client_load().
167 * @param client_name of at most jack_client_name_size() characters.
169 * @param load_name of a shared object file containing the code for
170 * the new client.
172 * @param load_init an arbitary string passed to the jack_initialize()
173 * routine of the new client (may be NULL).
175 * @return 0 if successful.
177 int jack_internal_client_new (const char *client_name,
178 const char *load_name,
179 const char *load_init);
182 * Remove an internal client from a JACK server.
184 * @deprecated Please use jack_internal_client_load().
186 void jack_internal_client_close (const char *client_name);
189 * Tell the Jack server that the program is ready to start processing
190 * audio.
192 * @return 0 on success, otherwise a non-zero error code
194 int jack_activate (jack_client_t *client);
197 * Tell the Jack server to remove this @a client from the process
198 * graph. Also, disconnect all ports belonging to it, since inactive
199 * clients have no port connections.
201 * @return 0 on success, otherwise a non-zero error code
203 int jack_deactivate (jack_client_t *client);
206 * @return pid of client. If not available, 0 will be returned.
208 int jack_get_client_pid (const char *name);
211 * @return the pthread ID of the thread running the JACK client side
212 * code.
214 pthread_t jack_client_thread_id (jack_client_t *);
216 /*@}*/
219 * @param client pointer to JACK client structure.
221 * Check if the JACK subsystem is running with -R (--realtime).
223 * @return 1 if JACK is running realtime, 0 otherwise
225 int jack_is_realtime (jack_client_t *client);
228 * @defgroup NonCallbackAPI The non-callback API
229 * @{
233 * \bold THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED IN
234 * NEW JACK CLIENTS.
236 * @deprecated Please use jack_cycle_wait() and jack_cycle_signal() functions.
238 jack_nframes_t jack_thread_wait (jack_client_t*, int status);
241 * Wait until this JACK client should process data.
243 * @param client - pointer to a JACK client structure
245 * @return the number of frames of data to process
247 jack_nframes_t jack_cycle_wait (jack_client_t* client);
250 * Signal next clients in the graph.
252 * @param client - pointer to a JACK client structure
253 * @param status - if non-zero, calling thread should exit
255 void jack_cycle_signal (jack_client_t* client, int status);
258 * Tell the Jack server to call @a thread_callback in the RT thread.
259 * Typical use are in conjunction with @a jack_cycle_wait and @a jack_cycle_signal functions.
260 * The code in the supplied function must be suitable for real-time
261 * execution. That means that it cannot call functions that might
262 * block for a long time. This includes malloc, free, printf,
263 * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
264 * pthread_cond_wait, etc, etc. See
265 * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
266 * for more information.
268 * NOTE: this function cannot be called while the client is activated
269 * (after jack_activate has been called.)
271 * @return 0 on success, otherwise a non-zero error code.
273 int jack_set_process_thread(jack_client_t* client, JackThreadCallback thread_callback, void *arg);
275 /*@}*/
278 * @defgroup ClientCallbacks Setting Client Callbacks
279 * @{
283 * Tell JACK to call @a thread_init_callback once just after
284 * the creation of the thread in which all other callbacks
285 * will be handled.
287 * The code in the supplied function does not need to be
288 * suitable for real-time execution.
290 * NOTE: this function cannot be called while the client is activated
291 * (after jack_activate has been called.)
293 * @return 0 on success, otherwise a non-zero error code, causing JACK
294 * to remove that client from the process() graph.
296 int jack_set_thread_init_callback (jack_client_t *client,
297 JackThreadInitCallback thread_init_callback,
298 void *arg);
301 * @param client pointer to JACK client structure.
302 * @param function The jack_shutdown function pointer.
303 * @param arg The arguments for the jack_shutdown function.
305 * Register a function (and argument) to be called if and when the
306 * JACK server shuts down the client thread. The function must
307 * be written as if it were an asynchonrous POSIX signal
308 * handler --- use only async-safe functions, and remember that it
309 * is executed from another thread. A typical function might
310 * set a flag or write to a pipe so that the rest of the
311 * application knows that the JACK client thread has shut
312 * down.
314 * NOTE: clients do not need to call this. It exists only
315 * to help more complex clients understand what is going
316 * on. It should be called before jack_client_activate().
318 * NOTE: if a client calls this AND jack_on_info_shutdown(), then
319 * the event of a client thread shutdown, the callback
320 * passed to this function will not be called, and the one passed to
321 * jack_on_info_shutdown() will.
323 void jack_on_shutdown (jack_client_t *client,
324 JackShutdownCallback shutdown_callback, void *arg) JACK_WEAK_EXPORT;
327 * @param client pointer to JACK client structure.
328 * @param function The jack_info_shutdown function pointer.
329 * @param arg The arguments for the jack_info_shutdown function.
331 * Register a function (and argument) to be called if and when the
332 * JACK server shuts down the client thread. The function must
333 * be written as if it were an asynchonrous POSIX signal
334 * handler --- use only async-safe functions, and remember that it
335 * is executed from another thread. A typical function might
336 * set a flag or write to a pipe so that the rest of the
337 * application knows that the JACK client thread has shut
338 * down.
340 * NOTE: clients do not need to call this. It exists only
341 * to help more complex clients understand what is going
342 * on. It should be called before jack_client_activate().
344 * NOTE: if a client calls this AND jack_on_info_shutdown(), then
345 * the event of a client thread shutdown, the callback
346 * passed to this function will not be called, and the one passed to
347 * jack_on_info_shutdown() will.
349 void jack_on_info_shutdown (jack_client_t *client,
350 JackInfoShutdownCallback shutdown_callback, void *arg);
353 * Tell the Jack server to call @a process_callback whenever there is
354 * work be done, passing @a arg as the second argument.
356 * The code in the supplied function must be suitable for real-time
357 * execution. That means that it cannot call functions that might
358 * block for a long time. This includes malloc, free, printf,
359 * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
360 * pthread_cond_wait, etc, etc. See
361 * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
362 * for more information.
364 * NOTE: this function cannot be called while the client is activated
365 * (after jack_activate has been called.)
367 * @return 0 on success, otherwise a non-zero error code.
369 int jack_set_process_callback (jack_client_t *client,
370 JackProcessCallback process_callback,
371 void *arg);
374 * Tell the Jack server to call @a freewheel_callback
375 * whenever we enter or leave "freewheel" mode, passing @a
376 * arg as the second argument. The first argument to the
377 * callback will be non-zero if JACK is entering freewheel
378 * mode, and zero otherwise.
380 * All "notification events" are received in a seperated non RT thread,
381 * the code in the supplied function does not need to be
382 * suitable for real-time execution.
384 * NOTE: this function cannot be called while the client is activated
385 * (after jack_activate has been called.)
387 * @return 0 on success, otherwise a non-zero error code.
389 int jack_set_freewheel_callback (jack_client_t *client,
390 JackFreewheelCallback freewheel_callback,
391 void *arg);
394 * Tell JACK to call @a bufsize_callback whenever the size of the the
395 * buffer that will be passed to the @a process_callback is about to
396 * change. Clients that depend on knowing the buffer size must supply
397 * a @a bufsize_callback before activating themselves.
399 * All "notification events" are received in a seperated non RT thread,
400 * the code in the supplied function does not need to be
401 * suitable for real-time execution.
403 * NOTE: this function cannot be called while the client is activated
404 * (after jack_activate has been called.)
406 * @param client pointer to JACK client structure.
407 * @param bufsize_callback function to call when the buffer size changes.
408 * @param arg argument for @a bufsize_callback.
410 * @return 0 on success, otherwise a non-zero error code
412 int jack_set_buffer_size_callback (jack_client_t *client,
413 JackBufferSizeCallback bufsize_callback,
414 void *arg);
417 * Tell the Jack server to call @a srate_callback whenever the system
418 * sample rate changes.
420 * All "notification events" are received in a seperated non RT thread,
421 * the code in the supplied function does not need to be
422 * suitable for real-time execution.
424 * NOTE: this function cannot be called while the client is activated
425 * (after jack_activate has been called.)
427 * @return 0 on success, otherwise a non-zero error code
429 int jack_set_sample_rate_callback (jack_client_t *client,
430 JackSampleRateCallback srate_callback,
431 void *arg);
434 * Tell the JACK server to call @a client_registration_callback whenever a
435 * client is registered or unregistered, passing @a arg as a parameter.
437 * All "notification events" are received in a seperated non RT thread,
438 * the code in the supplied function does not need to be
439 * suitable for real-time execution.
441 * NOTE: this function cannot be called while the client is activated
442 * (after jack_activate has been called.)
444 * @return 0 on success, otherwise a non-zero error code
446 int jack_set_client_registration_callback (jack_client_t *,
447 JackClientRegistrationCallback
448 registration_callback, void *arg);
451 * Tell the JACK server to call @a registration_callback whenever a
452 * port is registered or unregistered, passing @a arg as a parameter.
454 * All "notification events" are received in a seperated non RT thread,
455 * the code in the supplied function does not need to be
456 * suitable for real-time execution.
458 * NOTE: this function cannot be called while the client is activated
459 * (after jack_activate has been called.)
461 * @return 0 on success, otherwise a non-zero error code
463 int jack_set_port_registration_callback (jack_client_t *,
464 JackPortRegistrationCallback
465 registration_callback, void *arg);
468 * Tell the JACK server to call @a connect_callback whenever a
469 * port is connected or disconnected, passing @a arg as a parameter.
471 * All "notification events" are received in a seperated non RT thread,
472 * the code in the supplied function does not need to be
473 * suitable for real-time execution.
475 * NOTE: this function cannot be called while the client is activated
476 * (after jack_activate has been called.)
478 * @return 0 on success, otherwise a non-zero error code
480 int jack_set_port_connect_callback (jack_client_t *,
481 JackPortConnectCallback
482 connect_callback, void *arg);
485 * Tell the JACK server to call @a rename_callback whenever a
486 * port is renamed, passing @a arg as a parameter.
488 * All "notification events" are received in a seperated non RT thread,
489 * the code in the supplied function does not need to be
490 * suitable for real-time execution.
492 * NOTE: this function cannot be called while the client is activated
493 * (after jack_activate has been called.)
495 * @return 0 on success, otherwise a non-zero error code
497 int jack_set_port_rename_callback (jack_client_t *,
498 JackPortRenameCallback
499 rename_callback, void *arg);
502 * Tell the JACK server to call @a graph_callback whenever the
503 * processing graph is reordered, passing @a arg as a parameter.
505 * All "notification events" are received in a seperated non RT thread,
506 * the code in the supplied function does not need to be
507 * suitable for real-time execution.
509 * NOTE: this function cannot be called while the client is activated
510 * (after jack_activate has been called.)
512 * @return 0 on success, otherwise a non-zero error code
514 int jack_set_graph_order_callback (jack_client_t *,
515 JackGraphOrderCallback graph_callback,
516 void *);
519 * Tell the JACK server to call @a xrun_callback whenever there is a
520 * xrun, passing @a arg as a parameter.
522 * All "notification events" are received in a seperated non RT thread,
523 * the code in the supplied function does not need to be
524 * suitable for real-time execution.
526 * NOTE: this function cannot be called while the client is activated
527 * (after jack_activate has been called.)
529 * @return 0 on success, otherwise a non-zero error code
531 int jack_set_xrun_callback (jack_client_t *,
532 JackXRunCallback xrun_callback, void *arg);
534 /*@}*/
537 * @defgroup ServerClientControl Controlling & querying JACK server operation
538 * @{
542 * Start/Stop JACK's "freewheel" mode.
544 * When in "freewheel" mode, JACK no longer waits for
545 * any external event to begin the start of the next process
546 * cycle.
548 * As a result, freewheel mode causes "faster than realtime"
549 * execution of a JACK graph. If possessed, real-time
550 * scheduling is dropped when entering freewheel mode, and
551 * if appropriate it is reacquired when stopping.
553 * IMPORTANT: on systems using capabilities to provide real-time
554 * scheduling (i.e. Linux kernel 2.4), if onoff is zero, this function
555 * must be called from the thread that originally called jack_activate().
556 * This restriction does not apply to other systems (e.g. Linux kernel 2.6
557 * or OS X).
559 * @param client pointer to JACK client structure
560 * @param onoff if non-zero, freewheel mode starts. Otherwise
561 * freewheel mode ends.
563 * @return 0 on success, otherwise a non-zero error code.
565 int jack_set_freewheel(jack_client_t* client, int onoff);
568 * Change the buffer size passed to the @a process_callback.
570 * This operation stops the JACK engine process cycle, then calls all
571 * registered @a bufsize_callback functions before restarting the
572 * process cycle. This will cause a gap in the audio flow, so it
573 * should only be done at appropriate stopping points.
575 * @see jack_set_buffer_size_callback()
577 * @param client pointer to JACK client structure.
578 * @param nframes new buffer size. Must be a power of two.
580 * @return 0 on success, otherwise a non-zero error code
582 int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
585 * @return the sample rate of the jack system, as set by the user when
586 * jackd was started.
588 jack_nframes_t jack_get_sample_rate (jack_client_t *);
591 * @return the current maximum size that will ever be passed to the @a
592 * process_callback. It should only be used *before* the client has
593 * been activated. This size may change, clients that depend on it
594 * must register a @a bufsize_callback so they will be notified if it
595 * does.
597 * @see jack_set_buffer_size_callback()
599 jack_nframes_t jack_get_buffer_size (jack_client_t *);
602 * Old-style interface to become the timebase for the entire JACK
603 * subsystem.
605 * @deprecated This function still exists for compatibility with the
606 * earlier transport interface, but it does nothing. Instead, see
607 * transport.h and use jack_set_timebase_callback().
609 * @return ENOSYS, function not implemented.
611 int jack_engine_takeover_timebase (jack_client_t *);
614 * @return the current CPU load estimated by JACK. This is a running
615 * average of the time it takes to execute a full process cycle for
616 * all clients as a percentage of the real time available per cycle
617 * determined by the buffer size and sample rate.
619 float jack_cpu_load (jack_client_t *client);
621 /*@}*/
624 * @defgroup PortFunctions Creating & manipulating ports
625 * @{
629 * Create a new port for the client. This is an object used for moving
630 * data of any type in or out of the client. Ports may be connected
631 * in various ways.
633 * Each port has a short name. The port's full name contains the name
634 * of the client concatenated with a colon (:) followed by its short
635 * name. The jack_port_name_size() is the maximum length of this full
636 * name. Exceeding that will cause the port registration to fail and
637 * return NULL.
639 * All ports have a type, which may be any non-NULL and non-zero
640 * length string, passed as an argument. Some port types are built
641 * into the JACK API, currently only JACK_DEFAULT_AUDIO_TYPE.
643 * @param client pointer to JACK client structure.
644 * @param port_name non-empty short name for the new port (not
645 * including the leading @a "client_name:").
646 * @param port_type port type name. If longer than
647 * jack_port_type_size(), only that many characters are significant.
648 * @param flags @ref JackPortFlags bit mask.
649 * @param buffer_size must be non-zero if this is not a built-in @a
650 * port_type. Otherwise, it is ignored.
652 * @return jack_port_t pointer on success, otherwise NULL.
654 jack_port_t * jack_port_register (jack_client_t *client,
655 const char *port_name,
656 const char *port_type,
657 unsigned long flags,
658 unsigned long buffer_size);
661 * Remove the port from the client, disconnecting any existing
662 * connections.
664 * @return 0 on success, otherwise a non-zero error code
666 int jack_port_unregister (jack_client_t *, jack_port_t *);
669 * This returns a pointer to the memory area associated with the
670 * specified port. For an output port, it will be a memory area
671 * that can be written to; for an input port, it will be an area
672 * containing the data from the port's connection(s), or
673 * zero-filled. if there are multiple inbound connections, the data
674 * will be mixed appropriately.
676 * FOR OUTPUT PORTS ONLY : DEPRECATED in Jack 2.0 !!
677 * ---------------------------------------------------
678 * You may cache the value returned, but only between calls to
679 * your "blocksize" callback. For this reason alone, you should
680 * either never cache the return value or ensure you have
681 * a "blocksize" callback and be sure to invalidate the cached
682 * address from there.
684 * Caching output ports is DEPRECATED in Jack 2.0, due to some new optimization (like "pipelining").
685 * Port buffers have to be retrieved in each callback for proper functionning.
687 void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
690 * @return the full name of the jack_port_t (including the @a
691 * "client_name:" prefix).
693 * @see jack_port_name_size().
695 const char * jack_port_name (const jack_port_t *port);
698 * @return the short name of the jack_port_t (not including the @a
699 * "client_name:" prefix).
701 * @see jack_port_name_size().
703 const char * jack_port_short_name (const jack_port_t *port);
706 * @return the @ref JackPortFlags of the jack_port_t.
708 int jack_port_flags (const jack_port_t *port);
711 * @return the @a port type, at most jack_port_type_size() characters
712 * including a final NULL.
714 const char * jack_port_type (const jack_port_t *port);
717 * @return the @a port type id.
719 jack_port_type_id_t jack_port_type_id (const jack_port_t *port);
722 * @return TRUE if the jack_port_t belongs to the jack_client_t.
724 int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
727 * @return number of connections to or from @a port.
729 * @pre The calling client must own @a port.
731 int jack_port_connected (const jack_port_t *port);
734 * @return TRUE if the locally-owned @a port is @b directly connected
735 * to the @a port_name.
737 * @see jack_port_name_size()
739 int jack_port_connected_to (const jack_port_t *port,
740 const char *port_name);
743 * @return a null-terminated array of full port names to which the @a
744 * port is connected. If none, returns NULL.
746 * The caller is responsible for calling free(3) on any non-NULL
747 * returned value.
749 * @param port locally owned jack_port_t pointer.
751 * @see jack_port_name_size(), jack_port_get_all_connections()
753 const char ** jack_port_get_connections (const jack_port_t *port);
756 * @return a null-terminated array of full port names to which the @a
757 * port is connected. If none, returns NULL.
759 * The caller is responsible for calling free(3) on any non-NULL
760 * returned value.
762 * This differs from jack_port_get_connections() in two important
763 * respects:
765 * 1) You may not call this function from code that is
766 * executed in response to a JACK event. For example,
767 * you cannot use it in a GraphReordered handler.
769 * 2) You need not be the owner of the port to get information
770 * about its connections.
772 * @see jack_port_name_size()
774 const char ** jack_port_get_all_connections (const jack_client_t *client,
775 const jack_port_t *port);
779 * @deprecated This function will be removed from a future version
780 * of JACK. Do not use it. There is no replacement. It has
781 * turned out to serve essentially no purpose in real-life
782 * JACK clients.
784 int jack_port_tie (jack_port_t *src, jack_port_t *dst);
788 * @deprecated This function will be removed from a future version
789 * of JACK. Do not use it. There is no replacement. It has
790 * turned out to serve essentially no purpose in real-life
791 * JACK clients.
793 int jack_port_untie (jack_port_t *port);
796 * @return the time (in frames) between data being available or
797 * delivered at/to a port, and the time at which it arrived at or is
798 * delivered to the "other side" of the port. E.g. for a physical
799 * audio output port, this is the time between writing to the port and
800 * when the signal will leave the connector. For a physical audio
801 * input port, this is the time between the sound arriving at the
802 * connector and the corresponding frames being readable from the
803 * port.
805 jack_nframes_t jack_port_get_latency (jack_port_t *port);
808 * The maximum of the sum of the latencies in every
809 * connection path that can be drawn between the port and other
810 * ports with the @ref JackPortIsTerminal flag set.
812 jack_nframes_t jack_port_get_total_latency (jack_client_t *,
813 jack_port_t *port);
816 * The port latency is zero by default. Clients that control
817 * physical hardware with non-zero latency should call this
818 * to set the latency to its correct value. Note that the value
819 * should include any systemic latency present "outside" the
820 * physical hardware controlled by the client. For example,
821 * for a client controlling a digital audio interface connected
822 * to an external digital converter, the latency setting should
823 * include both buffering by the audio interface *and* the converter.
825 void jack_port_set_latency (jack_port_t *, jack_nframes_t);
828 * Request a complete recomputation of a port's total latency. This
829 * can be called by a client that has just changed the internal
830 * latency of its port using @function jack_port_set_latency
831 * and wants to ensure that all signal pathways in the graph
832 * are updated with respect to the values that will be returned
833 * by @function jack_port_get_total_latency.
835 * @return zero for successful execution of the request. non-zero
836 * otherwise.
838 int jack_recompute_total_latency (jack_client_t*, jack_port_t* port);
841 * Request a complete recomputation of all port latencies. This
842 * can be called by a client that has just changed the internal
843 * latency of its port using @function jack_port_set_latency
844 * and wants to ensure that all signal pathways in the graph
845 * are updated with respect to the values that will be returned
846 * by @function jack_port_get_total_latency. It allows a client
847 * to change multiple port latencies without triggering a
848 * recompute for each change.
850 * @return zero for successful execution of the request. non-zero
851 * otherwise.
853 int jack_recompute_total_latencies (jack_client_t*);
856 * Modify a port's short name. May be called at any time. If the
857 * resulting full name (including the @a "client_name:" prefix) is
858 * longer than jack_port_name_size(), it will be truncated.
860 * @return 0 on success, otherwise a non-zero error code.
862 int jack_port_set_name (jack_port_t *port, const char *port_name);
865 * Set @a alias as an alias for @a port. May be called at any time.
866 * If the alias is longer than jack_port_name_size(), it will be truncated.
868 * After a successful call, and until JACK exits or
869 * @function jack_port_unset_alias() is called, @alias may be
870 * used as a alternate name for the port.
872 * Ports can have up to two aliases - if both are already
873 * set, this function will return an error.
875 * @return 0 on success, otherwise a non-zero error code.
877 int jack_port_set_alias (jack_port_t *port, const char *alias);
880 * Remove @a alias as an alias for @a port. May be called at any time.
882 * After a successful call, @a alias can no longer be
883 * used as a alternate name for the port.
885 * @return 0 on success, otherwise a non-zero error code.
887 int jack_port_unset_alias (jack_port_t *port, const char *alias);
890 * Get any aliases known for @port.
892 * @return the number of aliases discovered for the port
894 int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
897 * If @ref JackPortCanMonitor is set for this @a port, turn input
898 * monitoring on or off. Otherwise, do nothing.
900 int jack_port_request_monitor (jack_port_t *port, int onoff);
903 * If @ref JackPortCanMonitor is set for this @a port_name, turn input
904 * monitoring on or off. Otherwise, do nothing.
906 * @return 0 on success, otherwise a non-zero error code.
908 * @see jack_port_name_size()
910 int jack_port_request_monitor_by_name (jack_client_t *client,
911 const char *port_name, int onoff);
914 * If @ref JackPortCanMonitor is set for a port, this function turns
915 * on input monitoring if it was off, and turns it off if only one
916 * request has been made to turn it on. Otherwise it does nothing.
918 * @return 0 on success, otherwise a non-zero error code
920 int jack_port_ensure_monitor (jack_port_t *port, int onoff);
923 * @return TRUE if input monitoring has been requested for @a port.
925 int jack_port_monitoring_input (jack_port_t *port);
928 * Establish a connection between two ports.
930 * When a connection exists, data written to the source port will
931 * be available to be read at the destination port.
933 * @pre The port types must be identical.
935 * @pre The @ref JackPortFlags of the @a source_port must include @ref
936 * JackPortIsOutput.
938 * @pre The @ref JackPortFlags of the @a destination_port must include
939 * @ref JackPortIsInput.
941 * @return 0 on success, EEXIST if the connection is already made,
942 * otherwise a non-zero error code
944 int jack_connect (jack_client_t *,
945 const char *source_port,
946 const char *destination_port);
949 * Remove a connection between two ports.
951 * @pre The port types must be identical.
953 * @pre The @ref JackPortFlags of the @a source_port must include @ref
954 * JackPortIsOutput.
956 * @pre The @ref JackPortFlags of the @a destination_port must include
957 * @ref JackPortIsInput.
959 * @return 0 on success, otherwise a non-zero error code
961 int jack_disconnect (jack_client_t *,
962 const char *source_port,
963 const char *destination_port);
966 * Perform the same function as jack_disconnect() using port handles
967 * rather than names. This avoids the name lookup inherent in the
968 * name-based version.
970 * Clients connecting their own ports are likely to use this function,
971 * while generic connection clients (e.g. patchbays) would use
972 * jack_disconnect().
974 int jack_port_disconnect (jack_client_t *, jack_port_t *);
977 * @return the maximum number of characters in a full JACK port name
978 * including the final NULL character. This value is a constant.
980 * A port's full name contains the owning client name concatenated
981 * with a colon (:) followed by its short name and a NULL
982 * character.
984 int jack_port_name_size(void);
987 * @return the maximum number of characters in a JACK port type name
988 * including the final NULL character. This value is a constant.
990 int jack_port_type_size(void);
992 /*@}*/
995 * @defgroup PortSearching Looking up ports
996 * @{
1000 * @param port_name_pattern A regular expression used to select
1001 * ports by name. If NULL or of zero length, no selection based
1002 * on name will be carried out.
1003 * @param type_name_pattern A regular expression used to select
1004 * ports by type. If NULL or of zero length, no selection based
1005 * on type will be carried out.
1006 * @param flags A value used to select ports by their flags.
1007 * If zero, no selection based on flags will be carried out.
1009 * @return a NULL-terminated array of ports that match the specified
1010 * arguments. The caller is responsible for calling free(3) any
1011 * non-NULL returned value.
1013 * @see jack_port_name_size(), jack_port_type_size()
1015 const char ** jack_get_ports (jack_client_t *,
1016 const char *port_name_pattern,
1017 const char *type_name_pattern,
1018 unsigned long flags);
1021 * @return address of the jack_port_t named @a port_name.
1023 * @see jack_port_name_size()
1025 jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
1028 * @return address of the jack_port_t of a @a port_id.
1030 jack_port_t * jack_port_by_id (jack_client_t *client,
1031 jack_port_id_t port_id);
1033 /*@}*/
1036 * @defgroup TimeFunctions Handling time
1037 * @{
1039 * JACK time is in units of 'frames', according to the current sample rate.
1040 * The absolute value of frame times is meaningless, frame times have meaning
1041 * only relative to each other.
1045 * @return the estimated time in frames that has passed since the JACK
1046 * server began the current process cycle.
1048 jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
1051 * @return the estimated current time in frames.
1052 * This function is intended for use in other threads (not the process
1053 * callback). The return value can be compared with the value of
1054 * jack_last_frame_time to relate time in other threads to JACK time.
1056 jack_nframes_t jack_frame_time (const jack_client_t *);
1059 * @return the precise time at the start of the current process cycle.
1060 * This function may only be used from the process callback, and can
1061 * be used to interpret timestamps generated by jack_frame_time() in
1062 * other threads with respect to the current process cycle.
1064 * This is the only jack time function that returns exact time:
1065 * when used during the process callback it always returns the same
1066 * value (until the next process callback, where it will return
1067 * that value + nframes, etc). The return value is guaranteed to be
1068 * monotonic and linear in this fashion unless an xrun occurs.
1069 * If an xrun occurs, clients must check this value again, as time
1070 * may have advanced in a non-linear way (e.g. cycles may have been skipped).
1072 jack_nframes_t jack_last_frame_time (const jack_client_t *client);
1075 * @return the estimated time in microseconds of the specified frame time
1077 jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t);
1080 * @return the estimated time in frames for the specified system time.
1082 jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t);
1085 * @return return JACK's current system time in microseconds,
1086 * using the JACK clock source.
1088 * The value returned is guaranteed to be monotonic, but not linear.
1090 jack_time_t jack_get_time();
1092 /*@}*/
1095 * @defgroup ErrorOutput Controlling error/information output
1097 /*@{*/
1100 * Display JACK error message.
1102 * Set via jack_set_error_function(), otherwise a JACK-provided
1103 * default will print @a msg (plus a newline) to stderr.
1105 * @param msg error message text (no newline at end).
1107 extern void (*jack_error_callback)(const char *msg);
1110 * Set the @ref jack_error_callback for error message display.
1111 * Set it to NULL to restore default_jack_error_callback function.
1113 * The JACK library provides two built-in callbacks for this purpose:
1114 * default_jack_error_callback() and silent_jack_error_callback().
1116 void jack_set_error_function (void (*func)(const char *));
1119 * Display JACK info message.
1121 * Set via jack_set_info_function(), otherwise a JACK-provided
1122 * default will print @a msg (plus a newline) to stdout.
1124 * @param msg info message text (no newline at end).
1126 extern void (*jack_info_callback)(const char *msg);
1129 * Set the @ref jack_info_callback for info message display.
1130 * Set it to NULL to restore default_jack_info_callback function.
1132 * The JACK library provides two built-in callbacks for this purpose:
1133 * default_jack_info_callback() and silent_jack_info_callback().
1135 void jack_set_info_function (void (*func)(const char *));
1137 /*@}*/
1140 * The free function to be used on memory returned by jack_port_get_connections,
1141 * jack_port_get_all_connections and jack_get_ports functions.
1142 * This is MANDATORY on Windows when otherwise all nasty runtime version related crashes can occur.
1143 * Developers are strongly encouraged to use this function instead of the standard "free" function in new code.
1146 void jack_free(void* ptr);
1149 #ifdef __cplusplus
1151 #endif
1153 #endif /* __jack_h__ */