Add a string parameter to server ==> client notification, add a new InfoShutdown...
[jack2.git] / common / jack / types.h
blob6623aa4d11dc65946f48b5b2f3ac43a92cd94f0d
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_types_h__
22 #define __jack_types_h__
24 #include <jack/systemdeps.h>
27 typedef int32_t jack_shmsize_t;
29 /**
30 * Type used to represent sample frame counts.
32 typedef uint32_t jack_nframes_t;
34 /**
35 * Maximum value that can be stored in jack_nframes_t
37 #define JACK_MAX_FRAMES (4294967295U) /* This should be UINT32_MAX, but C++ has a problem with that. */
39 /**
40 * Type used to represent the value of free running
41 * monotonic clock with units of microseconds.
43 typedef uint64_t jack_time_t;
45 /**
46 * Maximum size of @a load_init string passed to an internal client
47 * jack_initialize() function via jack_internal_client_load().
49 #define JACK_LOAD_INIT_LIMIT 1024
51 /**
52 * jack_intclient_t is an opaque type representing a loaded internal
53 * client. You may only access it using the API provided in @ref
54 * intclient.h "<jack/intclient.h>".
56 typedef uint64_t jack_intclient_t;
58 /**
59 * jack_port_t is an opaque type. You may only access it using the
60 * API provided.
62 typedef struct _jack_port jack_port_t;
64 /**
65 * jack_client_t is an opaque type. You may only access it using the
66 * API provided.
68 typedef struct _jack_client jack_client_t;
70 /**
71 * Ports have unique ids. A port registration callback is the only
72 * place you ever need to know their value.
74 typedef uint32_t jack_port_id_t;
76 typedef uint32_t jack_port_type_id_t;
78 /**
79 * Prototype for the client supplied function that is called
80 * by the engine anytime there is work to be done.
82 * @pre nframes == jack_get_buffer_size()
83 * @pre nframes == pow(2,x)
85 * @param nframes number of frames to process
86 * @param arg pointer to a client supplied structure
88 * @return zero on success, non-zero on error
90 typedef int (*JackProcessCallback)(jack_nframes_t nframes, void *arg);
92 /**
93 * Prototype for the client thread routine called
94 * by the engine when the client is inserted in the graph.
96 * @param arg pointer to a client supplied structure
99 typedef void *(*JackThreadCallback)(void* arg);
102 * Prototype for the client supplied function that is called
103 * once after the creation of the thread in which other
104 * callbacks will be made. Special thread characteristics
105 * can be set from this callback, for example. This is a
106 * highly specialized callback and most clients will not
107 * and should not use it.
109 * @param arg pointer to a client supplied structure
111 * @return void
113 typedef void (*JackThreadInitCallback)(void *arg);
116 * Prototype for the client supplied function that is called
117 * whenever the processing graph is reordered.
119 * @param arg pointer to a client supplied structure
121 * @return zero on success, non-zero on error
123 typedef int (*JackGraphOrderCallback)(void *arg);
126 * Prototype for the client-supplied function that is called whenever
127 * an xrun has occured.
129 * @see jack_get_xrun_delayed_usecs()
131 * @param arg pointer to a client supplied structure
133 * @return zero on success, non-zero on error
135 typedef int (*JackXRunCallback)(void *arg);
138 * Prototype for the @a bufsize_callback that is invoked whenever the
139 * JACK engine buffer size changes. Although this function is called
140 * in the JACK process thread, the normal process cycle is suspended
141 * during its operation, causing a gap in the audio flow. So, the @a
142 * bufsize_callback can allocate storage, touch memory not previously
143 * referenced, and perform other operations that are not realtime
144 * safe.
146 * @param nframes buffer size
147 * @param arg pointer supplied by jack_set_buffer_size_callback().
149 * @return zero on success, non-zero on error
151 typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void *arg);
154 * Prototype for the client supplied function that is called
155 * when the engine sample rate changes.
157 * @param nframes new engine sample rate
158 * @param arg pointer to a client supplied structure
160 * @return zero on success, non-zero on error
162 typedef int (*JackSampleRateCallback)(jack_nframes_t nframes, void *arg);
165 * Prototype for the client supplied function that is called
166 * whenever a port is registered or unregistered.
168 * @param arg pointer to a client supplied structure
170 typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int, void *arg);
173 * Prototype for the client supplied function that is called
174 * whenever a client is registered or unregistered.
176 * @param name a null-terminated string containing the client name
177 * @param register non-zero if the client is being registered,
178 * zero if the client is being unregistered
179 * @param arg pointer to a client supplied structure
181 typedef void (*JackClientRegistrationCallback)(const char* name, int val, void *arg);
184 * Prototype for the client supplied function that is called
185 * whenever a port is connected or disconnected.
187 * @param a one of two ports connected or disconnected
188 * @param b one of two ports connected or disconnected
189 * @param connect non-zero if ports were connected
190 * zero if ports were disconnected
191 * @param arg pointer to a client supplied data
193 typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
196 * Prototype for the client supplied function that is called
197 * whenever the port name has been changed.
199 * @param port the port that has been renamed
200 * @param new_name the new name
201 * @param arg pointer to a client supplied structure
203 * @return zero on success, non-zero on error
205 typedef int (*JackPortRenameCallback)(jack_port_id_t port, const char* new_name, void *arg);
208 * Prototype for the client supplied function that is called
209 * whenever jackd starts or stops freewheeling.
211 * @param starting non-zero if we start starting to freewheel, zero otherwise
212 * @param arg pointer to a client supplied structure
214 typedef void (*JackFreewheelCallback)(int starting, void *arg);
217 * @deprecated Prototype for the client supplied function that is called
218 * whenever jackd is shutdown. Note that after server shutdown,
219 * the client pointer is *not* deallocated by libjack,
220 * the application is responsible to properly use jack_client_close()
221 * to release client ressources. Warning: jack_client_close() cannot be
222 * safely used inside the shutdown callback and has to be called outside of
223 * the callback context.
225 * @param arg pointer to a client supplied structure
227 typedef void (*JackShutdownCallback)(void *arg);
230 * Prototype for the client supplied function that is called
231 * whenever jackd is shutdown. Note that after server shutdown,
232 * the client pointer is *not* deallocated by libjack,
233 * the application is responsible to properly use jack_client_close()
234 * to release client ressources. Warning: jack_client_close() cannot be
235 * safely used inside the shutdown callback and has to be called outside of
236 * the callback context.
238 * @param reason a string discribinh the shuntdown reason (backend failure, server crash... etc...)
239 * @param arg pointer to a client supplied structure
241 typedef void (*JackInfoShutdownCallback)(const char* reason, void *arg);
245 * Used for the type argument of jack_port_register() for default
246 * audio ports and midi ports.
248 #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
249 #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
252 * For convenience, use this typedef if you want to be able to change
253 * between float and double. You may want to typedef sample_t to
254 * jack_default_audio_sample_t in your application.
256 typedef float jack_default_audio_sample_t;
259 * A port has a set of flags that are formed by AND-ing together the
260 * desired values from the list below. The flags "JackPortIsInput" and
261 * "JackPortIsOutput" are mutually exclusive and it is an error to use
262 * them both.
264 enum JackPortFlags {
267 * if JackPortIsInput is set, then the port can receive
268 * data.
270 JackPortIsInput = 0x1,
273 * if JackPortIsOutput is set, then data can be read from
274 * the port.
276 JackPortIsOutput = 0x2,
279 * if JackPortIsPhysical is set, then the port corresponds
280 * to some kind of physical I/O connector.
282 JackPortIsPhysical = 0x4,
285 * if JackPortCanMonitor is set, then a call to
286 * jack_port_request_monitor() makes sense.
288 * Precisely what this means is dependent on the client. A typical
289 * result of it being called with TRUE as the second argument is
290 * that data that would be available from an output port (with
291 * JackPortIsPhysical set) is sent to a physical output connector
292 * as well, so that it can be heard/seen/whatever.
294 * Clients that do not control physical interfaces
295 * should never create ports with this bit set.
297 JackPortCanMonitor = 0x8,
300 * JackPortIsTerminal means:
302 * for an input port: the data received by the port
303 * will not be passed on or made
304 * available at any other port
306 * for an output port: the data available at the port
307 * does not originate from any other port
309 * Audio synthesizers, I/O hardware interface clients, HDR
310 * systems are examples of clients that would set this flag for
311 * their ports.
313 JackPortIsTerminal = 0x10
317 * @ref jack_options_t bits
319 enum JackOptions {
322 * Null value to use when no option bits are needed.
324 JackNullOption = 0x00,
327 * Do not automatically start the JACK server when it is not
328 * already running. This option is always selected if
329 * \$JACK_NO_START_SERVER is defined in the calling process
330 * environment.
332 JackNoStartServer = 0x01,
335 * Use the exact client name requested. Otherwise, JACK
336 * automatically generates a unique one, if needed.
338 JackUseExactName = 0x02,
341 * Open with optional <em>(char *) server_name</em> parameter.
343 JackServerName = 0x04,
346 * Load internal client from optional <em>(char *)
347 * load_name</em>. Otherwise use the @a client_name.
349 JackLoadName = 0x08,
352 * Pass optional <em>(char *) load_init</em> string to the
353 * jack_initialize() entry point of an internal client.
355 JackLoadInit = 0x10
358 /** Valid options for opening an external client. */
359 #define JackOpenOptions (JackServerName|JackNoStartServer|JackUseExactName)
361 /** Valid options for loading an internal client. */
362 #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
365 * Options for several JACK operations, formed by OR-ing together the
366 * relevant @ref JackOptions bits.
368 typedef enum JackOptions jack_options_t;
371 * @ref jack_status_t bits
373 enum JackStatus {
376 * Overall operation failed.
378 JackFailure = 0x01,
381 * The operation contained an invalid or unsupported option.
383 JackInvalidOption = 0x02,
386 * The desired client name was not unique. With the @ref
387 * JackUseExactName option this situation is fatal. Otherwise,
388 * the name was modified by appending a dash and a two-digit
389 * number in the range "-01" to "-99". The
390 * jack_get_client_name() function will return the exact string
391 * that was used. If the specified @a client_name plus these
392 * extra characters would be too long, the open fails instead.
394 JackNameNotUnique = 0x04,
397 * The JACK server was started as a result of this operation.
398 * Otherwise, it was running already. In either case the caller
399 * is now connected to jackd, so there is no race condition.
400 * When the server shuts down, the client will find out.
402 JackServerStarted = 0x08,
405 * Unable to connect to the JACK server.
407 JackServerFailed = 0x10,
410 * Communication error with the JACK server.
412 JackServerError = 0x20,
415 * Requested client does not exist.
417 JackNoSuchClient = 0x40,
420 * Unable to load internal client
422 JackLoadFailure = 0x80,
425 * Unable to initialize client
427 JackInitFailure = 0x100,
430 * Unable to access shared memory
432 JackShmFailure = 0x200,
435 * Client's protocol version does not match
437 JackVersionError = 0x400
441 * Status word returned from several JACK operations, formed by
442 * OR-ing together the relevant @ref JackStatus bits.
444 typedef enum JackStatus jack_status_t;
447 * Transport states.
449 typedef enum {
451 /* the order matters for binary compatibility */
452 JackTransportStopped = 0, /**< Transport halted */
453 JackTransportRolling = 1, /**< Transport playing */
454 JackTransportLooping = 2, /**< For OLD_TRANSPORT, now ignored */
455 JackTransportStarting = 3, /**< Waiting for sync ready */
456 JackTransportNetStarting = 4, /**< Waiting for sync ready on the network*/
458 } jack_transport_state_t;
460 typedef uint64_t jack_unique_t; /**< Unique ID (opaque) */
463 * Optional struct jack_position_t fields.
465 typedef enum {
467 JackPositionBBT = 0x10, /**< Bar, Beat, Tick */
468 JackPositionTimecode = 0x20, /**< External timecode */
469 JackBBTFrameOffset = 0x40, /**< Frame offset of BBT information */
470 JackAudioVideoRatio = 0x80, /**< audio frames per video frame */
471 JackVideoFrameOffset = 0x100 /**< frame offset of first video frame */
473 } jack_position_bits_t;
475 /** all valid position bits */
476 #define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode)
477 #define EXTENDED_TIME_INFO
479 typedef struct {
481 /* these four cannot be set from clients: the server sets them */
482 jack_unique_t unique_1; /**< unique ID */
483 jack_time_t usecs; /**< monotonic, free-rolling */
484 jack_nframes_t frame_rate; /**< current frame rate (per second) */
485 jack_nframes_t frame; /**< frame number, always present */
487 jack_position_bits_t valid; /**< which other fields are valid */
489 /* JackPositionBBT fields: */
490 int32_t bar; /**< current bar */
491 int32_t beat; /**< current beat-within-bar */
492 int32_t tick; /**< current tick-within-beat */
493 double bar_start_tick;
495 float beats_per_bar; /**< time signature "numerator" */
496 float beat_type; /**< time signature "denominator" */
497 double ticks_per_beat;
498 double beats_per_minute;
500 /* JackPositionTimecode fields: (EXPERIMENTAL: could change) */
501 double frame_time; /**< current time in seconds */
502 double next_time; /**< next sequential frame_time
503 (unless repositioned) */
505 /* JackBBTFrameOffset fields: */
506 jack_nframes_t bbt_offset; /**< frame offset for the BBT fields
507 (the given bar, beat, and tick
508 values actually refer to a time
509 frame_offset frames before the
510 start of the cycle), should
511 be assumed to be 0 if
512 JackBBTFrameOffset is not
513 set. If JackBBTFrameOffset is
514 set and this value is zero, the BBT
515 time refers to the first frame of this
516 cycle. If the value is positive,
517 the BBT time refers to a frame that
518 many frames before the start of the
519 cycle. */
521 /* JACK video positional data (experimental) */
523 float audio_frames_per_video_frame; /**< number of audio frames
524 per video frame. Should be assumed
525 zero if JackAudioVideoRatio is not
526 set. If JackAudioVideoRatio is set
527 and the value is zero, no video
528 data exists within the JACK graph */
530 jack_nframes_t video_offset; /**< audio frame at which the first video
531 frame in this cycle occurs. Should
532 be assumed to be 0 if JackVideoFrameOffset
533 is not set. If JackVideoFrameOffset is
534 set, but the value is zero, there is
535 no video frame within this cycle. */
537 /* For binary compatibility, new fields should be allocated from
538 * this padding area with new valid bits controlling access, so
539 * the existing structure size and offsets are preserved. */
540 int32_t padding[7];
542 /* When (unique_1 == unique_2) the contents are consistent. */
543 jack_unique_t unique_2; /**< unique ID */
545 } jack_position_t;
548 * Prototype for the @a sync_callback defined by slow-sync clients.
549 * When the client is active, this callback is invoked just before
550 * process() in the same thread. This occurs once after registration,
551 * then subsequently whenever some client requests a new position, or
552 * the transport enters the ::JackTransportStarting state. This
553 * realtime function must not wait.
555 * The transport @a state will be:
557 * - ::JackTransportStopped when a new position is requested;
558 * - ::JackTransportStarting when the transport is waiting to start;
559 * - ::JackTransportRolling when the timeout has expired, and the
560 * position is now a moving target.
562 * @param state current transport state.
563 * @param pos new transport position.
564 * @param arg the argument supplied by jack_set_sync_callback().
566 * @return TRUE (non-zero) when ready to roll.
568 typedef int (*JackSyncCallback)(jack_transport_state_t state,
569 jack_position_t *pos,
570 void *arg);
574 * Prototype for the @a timebase_callback used to provide extended
575 * position information. Its output affects all of the following
576 * process cycle. This realtime function must not wait.
578 * This function is called immediately after process() in the same
579 * thread whenever the transport is rolling, or when any client has
580 * requested a new position in the previous cycle. The first cycle
581 * after jack_set_timebase_callback() is also treated as a new
582 * position, or the first cycle after jack_activate() if the client
583 * had been inactive.
585 * The timebase master may not use its @a pos argument to set @a
586 * pos->frame. To change position, use jack_transport_reposition() or
587 * jack_transport_locate(). These functions are realtime-safe, the @a
588 * timebase_callback can call them directly.
590 * @param state current transport state.
591 * @param nframes number of frames in current period.
592 * @param pos address of the position structure for the next cycle; @a
593 * pos->frame will be its frame number. If @a new_pos is FALSE, this
594 * structure contains extended position information from the current
595 * cycle. If TRUE, it contains whatever was set by the requester.
596 * The @a timebase_callback's task is to update the extended
597 * information here.
598 * @param new_pos TRUE (non-zero) for a newly requested @a pos, or for
599 * the first cycle after the @a timebase_callback is defined.
600 * @param arg the argument supplied by jack_set_timebase_callback().
602 typedef void (*JackTimebaseCallback)(jack_transport_state_t state,
603 jack_nframes_t nframes,
604 jack_position_t *pos,
605 int new_pos,
606 void *arg);
608 /*********************************************************************
609 * The following interfaces are DEPRECATED. They are only provided
610 * for compatibility with the earlier JACK transport implementation.
611 *********************************************************************/
614 * Optional struct jack_transport_info_t fields.
616 * @see jack_position_bits_t.
618 typedef enum {
620 JackTransportState = 0x1, /**< Transport state */
621 JackTransportPosition = 0x2, /**< Frame number */
622 JackTransportLoop = 0x4, /**< Loop boundaries (ignored) */
623 JackTransportSMPTE = 0x8, /**< SMPTE (ignored) */
624 JackTransportBBT = 0x10 /**< Bar, Beat, Tick */
626 } jack_transport_bits_t;
629 * Deprecated struct for transport position information.
631 * @deprecated This is for compatibility with the earlier transport
632 * interface. Use the jack_position_t struct, instead.
634 typedef struct {
636 /* these two cannot be set from clients: the server sets them */
638 jack_nframes_t frame_rate; /**< current frame rate (per second) */
639 jack_time_t usecs; /**< monotonic, free-rolling */
641 jack_transport_bits_t valid; /**< which fields are legal to read */
642 jack_transport_state_t transport_state;
643 jack_nframes_t frame;
644 jack_nframes_t loop_start;
645 jack_nframes_t loop_end;
647 long smpte_offset; /**< SMPTE offset (from frame 0) */
648 float smpte_frame_rate; /**< 29.97, 30, 24 etc. */
650 int bar;
651 int beat;
652 int tick;
653 double bar_start_tick;
655 float beats_per_bar;
656 float beat_type;
657 double ticks_per_beat;
658 double beats_per_minute;
660 } jack_transport_info_t;
662 #endif /* __jack_types_h__ */