1 /*
2   Copyright (C) 2001 Paul Davis
3   Copyright (C) 2004 Jack O'Quin
4 
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.
9 
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.
14 
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.
18 
19 */
20 
21 module jack.c.types;
22 public import jack.c.systemdeps;
23 import core.stdc.config: c_long;
24 
25 extern(C)
26 {
27 
28 alias jack_shmsize_t = int32_t;
29 
30 /**
31  * Type used to represent sample frame counts.
32  */
33 alias jack_nframes_t = uint32_t;
34 
35 /**
36  * Maximum value that can be stored in jack_nframes_t
37  */
38 enum JACK_MAX_FRAMES = 4294967295U;   /* This should be UINT32_MAX, but C++ has a problem with that. */
39 
40 /**
41  * Type used to represent the value of free running
42  * monotonic clock with units of microseconds.
43  */
44 alias jack_time_t = uint64_t;
45 
46 /**
47  *  Maximum size of @a load_init string passed to an internal client
48  *  jack_initialize() function via jack_internal_client_load().
49  */
50 enum JACK_LOAD_INIT_LIMIT = 1024;
51 
52 /**
53  *  jack_intclient_t is an opaque type representing a loaded internal
54  *  client.  You may only access it using the API provided in @ref
55  *  intclient.h "<jack/intclient.h>".
56  */
57 alias jack_intclient_t = uint64_t;
58 
59 /**
60  *  jack_port_t is an opaque type.  You may only access it using the
61  *  API provided.
62  */
63 struct jack_port_t;
64 
65 /**
66  *  jack_client_t is an opaque type.  You may only access it using the
67  *  API provided.
68  */
69 struct jack_client_t;
70 
71 /**
72  *  Ports have unique ids. A port registration callback is the only
73  *  place you ever need to know their value.
74  */
75 alias jack_port_id_t = uint32_t;
76 
77 alias jack_port_type_id_t = uint32_t;
78 
79 /**
80  *  @ref jack_options_t bits
81  */
82 enum JackOptions {
83     /**
84      * Null value to use when no option bits are needed.
85      */
86     JackNullOption = 0x00,
87 
88     /**
89      * Do not automatically start the JACK server when it is not
90      * already running.  This option is always selected if
91      * \$JACK_NO_START_SERVER is defined in the calling process
92      * environment.
93      */
94     JackNoStartServer = 0x01,
95 
96     /**
97      * Use the exact client name requested.  Otherwise, JACK
98      * automatically generates a unique one, if needed.
99      */
100     JackUseExactName = 0x02,
101 
102     /**
103      * Open with optional <em>(char *) server_name</em> parameter.
104      */
105     JackServerName = 0x04,
106 
107     /**
108      * Load internal client from optional <em>(char *)
109      * load_name</em>.  Otherwise use the @a client_name.
110      */
111     JackLoadName = 0x08,
112 
113     /**
114      * Pass optional <em>(char *) load_init</em> string to the
115      * jack_initialize() entry point of an internal client.
116      */
117     JackLoadInit = 0x10,
118 
119      /**
120       * pass a SessionID Token this allows the sessionmanager to identify the client again.
121       */
122     JackSessionID = 0x20
123 };
124 
125 /** Valid options for opening an external client. */
126 enum JackOpenOptions = JackOptions.JackSessionID|JackOptions.JackServerName|JackOptions.JackNoStartServer|JackOptions.JackUseExactName;
127 
128 /** Valid options for loading an internal client. */
129 enum JackLoadOptions = JackOptions.JackLoadInit|JackOptions.JackLoadName|JackOptions.JackUseExactName;
130 
131 /**
132  *  Options for several JACK operations, formed by OR-ing together the
133  *  relevant @ref JackOptions bits.
134  */
135 alias jack_options_t = JackOptions;
136 
137 /**
138  *  @ref jack_status_t bits
139  */
140 enum JackStatus {
141     /**
142      * Overall operation failed.
143      */
144     JackFailure = 0x01,
145 
146     /**
147      * The operation contained an invalid or unsupported option.
148      */
149     JackInvalidOption = 0x02,
150 
151     /**
152      * The desired client name was not unique.  With the @ref
153      * JackUseExactName option this situation is fatal.  Otherwise,
154      * the name was modified by appending a dash and a two-digit
155      * number in the range "-01" to "-99".  The
156      * jack_get_client_name() function will return the exact string
157      * that was used.  If the specified @a client_name plus these
158      * extra characters would be too long, the open fails instead.
159      */
160     JackNameNotUnique = 0x04,
161 
162     /**
163      * The JACK server was started as a result of this operation.
164      * Otherwise, it was running already.  In either case the caller
165      * is now connected to jackd, so there is no race condition.
166      * When the server shuts down, the client will find out.
167      */
168     JackServerStarted = 0x08,
169 
170     /**
171      * Unable to connect to the JACK server.
172      */
173     JackServerFailed = 0x10,
174 
175     /**
176      * Communication error with the JACK server.
177      */
178     JackServerError = 0x20,
179 
180     /**
181      * Requested client does not exist.
182      */
183     JackNoSuchClient = 0x40,
184 
185     /**
186      * Unable to load internal client
187      */
188     JackLoadFailure = 0x80,
189 
190     /**
191      * Unable to initialize client
192      */
193     JackInitFailure = 0x100,
194 
195     /**
196      * Unable to access shared memory
197      */
198     JackShmFailure = 0x200,
199 
200     /**
201      * Client's protocol version does not match
202      */
203     JackVersionError = 0x400,
204 
205     /**
206      * Backend error
207      */
208     JackBackendError = 0x800,
209 
210     /**
211      * Client zombified failure
212      */
213     JackClientZombie = 0x1000
214 };
215 
216 /**
217  *  Status word returned from several JACK operations, formed by
218  *  OR-ing together the relevant @ref JackStatus bits.
219  */
220 alias jack_status_t = JackStatus;
221 
222 /**
223  *  @ref jack_latency_callback_mode_t
224  */
225 enum JackLatencyCallbackMode {
226      /**
227       * Latency Callback for Capture Latency.
228       * Input Ports have their latency value setup.
229       * In the Callback the client needs to set the latency of the output ports
230       */
231      JackCaptureLatency,
232 
233      /**
234       * Latency Callback for Playback Latency.
235       * Output Ports have their latency value setup.
236       * In the Callback the client needs to set the latency of the input ports
237       */
238      JackPlaybackLatency
239 };
240 
241 /**
242  *  Type of Latency Callback (Capture or Playback)
243  */
244 alias jack_latency_callback_mode_t = JackLatencyCallbackMode;
245 
246 /**
247  * Prototype for the client supplied function that is called
248  * by the engine when port latencies need to be recalculated
249  *
250  * @param mode playback or capture latency
251  * @param arg pointer to a client supplied data
252  *
253  * @return zero on success, non-zero on error
254  */
255 alias JackLatencyCallback = void function(jack_latency_callback_mode_t mode, void *arg);
256 
257 /**
258  * the new latency API operates on Ranges.
259  */
260 align(1)
261 struct jack_latency_range_t
262 {
263     /**
264      * minimum latency
265      */
266     jack_nframes_t min;
267     /**
268      * maximum latency
269      */
270     jack_nframes_t max;
271 };
272 
273 /**
274  * Prototype for the client supplied function that is called
275  * by the engine anytime there is work to be done.
276  *
277  * @pre nframes == jack_get_buffer_size()
278  * @pre nframes == pow(2,x)
279  *
280  * @param nframes number of frames to process
281  * @param arg pointer to a client supplied structure
282  *
283  * @return zero on success, non-zero on error
284  */
285 alias JackProcessCallback = int function(jack_nframes_t nframes, void *arg);
286 
287 /**
288  * Prototype for the client thread routine called
289  * by the engine when the client is inserted in the graph.
290  *
291  * @param arg pointer to a client supplied structure
292  *
293  */
294 alias JackThreadCallback = void *function(void* arg);
295 
296 /**
297  * Prototype for the client supplied function that is called
298  * once after the creation of the thread in which other
299  * callbacks will be made. Special thread characteristics
300  * can be set from this callback, for example. This is a
301  * highly specialized callback and most clients will not
302  * and should not use it.
303  *
304  * @param arg pointer to a client supplied structure
305  *
306  * @return void
307  */
308 alias JackThreadInitCallback = void function(void *arg);
309 
310 /**
311  * Prototype for the client supplied function that is called
312  * whenever the processing graph is reordered.
313  *
314  * @param arg pointer to a client supplied structure
315  *
316  * @return zero on success, non-zero on error
317  */
318 alias JackGraphOrderCallback = int function(void *arg);
319 
320 /**
321  * Prototype for the client-supplied function that is called whenever
322  * an xrun has occured.
323  *
324  * @see jack_get_xrun_delayed_usecs()
325  *
326  * @param arg pointer to a client supplied structure
327  *
328  * @return zero on success, non-zero on error
329  */
330 alias JackXRunCallback = int function(void *arg);
331 
332 /**
333  * Prototype for the @a bufsize_callback that is invoked whenever the
334  * JACK engine buffer size changes.  Although this function is called
335  * in the JACK process thread, the normal process cycle is suspended
336  * during its operation, causing a gap in the audio flow.  So, the @a
337  * bufsize_callback can allocate storage, touch memory not previously
338  * referenced, and perform other operations that are not realtime
339  * safe.
340  *
341  * @param nframes buffer size
342  * @param arg pointer supplied by jack_set_buffer_size_callback().
343  *
344  * @return zero on success, non-zero on error
345  */
346 alias JackBufferSizeCallback = int function(jack_nframes_t nframes, void *arg);
347 
348 /**
349  * Prototype for the client supplied function that is called
350  * when the engine sample rate changes.
351  *
352  * @param nframes new engine sample rate
353  * @param arg pointer to a client supplied structure
354  *
355  * @return zero on success, non-zero on error
356  */
357 alias JackSampleRateCallback = int function(jack_nframes_t nframes, void *arg);
358 
359 /**
360  * Prototype for the client supplied function that is called
361  * whenever a port is registered or unregistered.
362  *
363  * @param port the ID of the port
364  * @param arg pointer to a client supplied data
365  * @param register non-zero if the port is being registered,
366  *                     zero if the port is being unregistered
367  */
368 alias JackPortRegistrationCallback = void function(jack_port_id_t port, int register, void *arg);
369 
370 /**
371  * Prototype for the client supplied function that is called
372  * whenever a client is registered or unregistered.
373  *
374  * @param name a null-terminated string containing the client name
375  * @param register non-zero if the client is being registered,
376  *                     zero if the client is being unregistered
377  * @param arg pointer to a client supplied structure
378  */
379 alias JackClientRegistrationCallback = void function(const(char)* name, int register, void *arg);
380 
381 /**
382  * Prototype for the client supplied function that is called
383  * whenever a port is connected or disconnected.
384  *
385  * @param a one of two ports connected or disconnected
386  * @param b one of two ports connected or disconnected
387  * @param connect non-zero if ports were connected
388  *                    zero if ports were disconnected
389  * @param arg pointer to a client supplied data
390  */
391 alias JackPortConnectCallback = void function(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
392 
393 /**
394  * Prototype for the client supplied function that is called
395  * whenever the port name has been changed.
396  *
397  * @param port the port that has been renamed
398  * @param new_name the new name
399  * @param arg pointer to a client supplied structure
400  *
401  * @return zero on success, non-zero on error
402  */
403 alias JackPortRenameCallback = int function(jack_port_id_t port, const(char)* old_name, const(char)* new_name, void *arg);
404 
405 /**
406  * Prototype for the client supplied function that is called
407  * whenever jackd starts or stops freewheeling.
408  *
409  * @param starting non-zero if we start starting to freewheel, zero otherwise
410  * @param arg pointer to a client supplied structure
411  */
412 alias JackFreewheelCallback = void function(int starting, void *arg);
413 
414 /**
415  * Prototype for the client supplied function that is called
416  * whenever jackd is shutdown. Note that after server shutdown,
417  * the client pointer is *not* deallocated by libjack,
418  * the application is responsible to properly use jack_client_close()
419  * to release client ressources. Warning: jack_client_close() cannot be
420  * safely used inside the shutdown callback and has to be called outside of
421  * the callback context.
422  *
423  * @param arg pointer to a client supplied structure
424  */
425 alias JackShutdownCallback = void function(void *arg);
426 
427 /**
428  * Prototype for the client supplied function that is called
429  * whenever jackd is shutdown. Note that after server shutdown,
430  * the client pointer is *not* deallocated by libjack,
431  * the application is responsible to properly use jack_client_close()
432  * to release client ressources. Warning: jack_client_close() cannot be
433  * safely used inside the shutdown callback and has to be called outside of
434  * the callback context.
435 
436  * @param code a status word, formed by OR-ing together the relevant @ref JackStatus bits.
437  * @param reason a string describing the shutdown reason (backend failure, server crash... etc...)
438  * @param arg pointer to a client supplied structure
439  */
440 alias JackInfoShutdownCallback = void function(jack_status_t code, const(char)* reason, void *arg);
441 
442 /**
443  * Used for the type argument of jack_port_register() for default
444  * audio ports and midi ports.
445  */
446 enum JACK_DEFAULT_AUDIO_TYPE = "32 bit float mono audio";
447 enum JACK_DEFAULT_MIDI_TYPE = "8 bit raw midi";
448 
449 /**
450  * For convenience, use this typedef if you want to be able to change
451  * between float and double. You may want to typedef sample_t to
452  * jack_default_audio_sample_t in your application.
453  */
454 alias jack_default_audio_sample_t = float;
455 
456 /**
457  *  A port has a set of flags that are formed by AND-ing together the
458  *  desired values from the list below. The flags "JackPortIsInput" and
459  *  "JackPortIsOutput" are mutually exclusive and it is an error to use
460  *  them both.
461  */
462 enum JackPortFlags {
463     /**
464      * if JackPortIsInput is set, then the port can receive
465      * data.
466      */
467     JackPortIsInput = 0x1,
468 
469     /**
470      * if JackPortIsOutput is set, then data can be read from
471      * the port.
472      */
473     JackPortIsOutput = 0x2,
474 
475     /**
476      * if JackPortIsPhysical is set, then the port corresponds
477      * to some kind of physical I/O connector.
478      */
479     JackPortIsPhysical = 0x4,
480 
481     /**
482      * if JackPortCanMonitor is set, then a call to
483      * jack_port_request_monitor() makes sense.
484      *
485      * Precisely what this means is dependent on the client. A typical
486      * result of it being called with TRUE as the second argument is
487      * that data that would be available from an output port (with
488      * JackPortIsPhysical set) is sent to a physical output connector
489      * as well, so that it can be heard/seen/whatever.
490      *
491      * Clients that do not control physical interfaces
492      * should never create ports with this bit set.
493      */
494     JackPortCanMonitor = 0x8,
495 
496     /**
497      * JackPortIsTerminal means:
498      *
499      *  for an input port: the data received by the port
500      *                    will not be passed on or made
501      *                     available at any other port
502      *
503      * for an output port: the data available at the port
504      *                    does not originate from any other port
505      *
506      * Audio synthesizers, I/O hardware interface clients, HDR
507      * systems are examples of clients that would set this flag for
508      * their ports.
509      */
510     JackPortIsTerminal = 0x10,
511 };
512 
513 /**
514  * Transport states.
515  */
516 enum jack_transport_state_t {
517     /* the order matters for binary compatibility */
518     JackTransportStopped = 0,       /**< Transport halted */
519     JackTransportRolling = 1,       /**< Transport playing */
520     JackTransportLooping = 2,       /**< For OLD_TRANSPORT, now ignored */
521     JackTransportStarting = 3,      /**< Waiting for sync ready */
522     JackTransportNetStarting = 4,       /**< Waiting for sync ready on the network*/
523 };
524 
525 alias jack_unique_t = uint64_t;         /**< Unique ID (opaque) */
526 
527 /**
528  * Optional struct jack_position_t fields.
529  */
530 enum jack_position_bits_t {
531     JackPositionBBT = 0x10,     /**< Bar, Beat, Tick */
532     JackPositionTimecode = 0x20,        /**< External timecode */
533     JackBBTFrameOffset =      0x40,     /**< Frame offset of BBT information */
534     JackAudioVideoRatio =     0x80, /**< audio frames per video frame */
535     JackVideoFrameOffset =   0x100  /**< frame offset of first video frame */
536 };
537 
538 /** all valid position bits */
539 enum JACK_POSITION_MASK = jack_position_bits_t.JackPositionBBT|jack_position_bits_t.JackPositionTimecode;
540 
541 align(1)
542 struct jack_position_t {
543     /* these four cannot be set from clients: the server sets them */
544     jack_unique_t       unique_1;       /**< unique ID */
545     jack_time_t         usecs;          /**< monotonic, free-rolling */
546     jack_nframes_t      frame_rate;     /**< current frame rate (per second) */
547     jack_nframes_t      frame;          /**< frame number, always present */
548 
549     jack_position_bits_t valid;         /**< which other fields are valid */
550 
551     /* JackPositionBBT fields: */
552     int32_t             bar;            /**< current bar */
553     int32_t             beat;           /**< current beat-within-bar */
554     int32_t             tick;           /**< current tick-within-beat */
555     double              bar_start_tick;
556 
557     float               beats_per_bar;  /**< time signature "numerator" */
558     float               beat_type;      /**< time signature "denominator" */
559     double              ticks_per_beat;
560     double              beats_per_minute;
561 
562     /* JackPositionTimecode fields:     (EXPERIMENTAL: could change) */
563     double              frame_time;     /**< current time in seconds */
564     double              next_time;      /**< next sequential frame_time
565                          (unless repositioned) */
566 
567     /* JackBBTFrameOffset fields: */
568     jack_nframes_t      bbt_offset;     /**< frame offset for the BBT fields
569                          (the given bar, beat, and tick
570                          values actually refer to a time
571                          frame_offset frames before the
572                          start of the cycle), should
573                          be assumed to be 0 if
574                          JackBBTFrameOffset is not
575                          set. If JackBBTFrameOffset is
576                          set and this value is zero, the BBT
577                          time refers to the first frame of this
578                          cycle. If the value is positive,
579                          the BBT time refers to a frame that
580                          many frames before the start of the
581                          cycle. */
582 
583     /* JACK video positional data (experimental) */
584 
585     float               audio_frames_per_video_frame; /**< number of audio frames
586                          per video frame. Should be assumed
587                          zero if JackAudioVideoRatio is not
588                          set. If JackAudioVideoRatio is set
589                          and the value is zero, no video
590                          data exists within the JACK graph */
591 
592     jack_nframes_t      video_offset;   /**< audio frame at which the first video
593                          frame in this cycle occurs. Should
594                          be assumed to be 0 if JackVideoFrameOffset
595                          is not set. If JackVideoFrameOffset is
596                          set, but the value is zero, there is
597                          no video frame within this cycle. */
598 
599     /* For binary compatibility, new fields should be allocated from
600      * this padding area with new valid bits controlling access, so
601      * the existing structure size and offsets are preserved. */
602     int32_t[7]             padding;
603 
604     /* When (unique_1 == unique_2) the contents are consistent. */
605     jack_unique_t       unique_2;       /**< unique ID */
606 };
607 
608 /**
609     * Prototype for the @a sync_callback defined by slow-sync clients.
610     * When the client is active, this callback is invoked just before
611     * process() in the same thread.  This occurs once after registration,
612     * then subsequently whenever some client requests a new position, or
613     * the transport enters the ::JackTransportStarting state.  This
614     * realtime function must not wait.
615     *
616     * The transport @a state will be:
617     *
618     *   - ::JackTransportStopped when a new position is requested;
619     *   - ::JackTransportStarting when the transport is waiting to start;
620     *   - ::JackTransportRolling when the timeout has expired, and the
621     *   position is now a moving target.
622     *
623     * @param state current transport state.
624     * @param pos new transport position.
625     * @param arg the argument supplied by jack_set_sync_callback().
626     *
627     * @return TRUE (non-zero) when ready to roll.
628     */
629 alias JackSyncCallback = int function(jack_transport_state_t state,
630                                       jack_position_t *pos,
631                                       void *arg);
632 
633 
634 /**
635   * Prototype for the @a timebase_callback used to provide extended
636   * position information.  Its output affects all of the following
637   * process cycle.  This realtime function must not wait.
638   *
639   * This function is called immediately after process() in the same
640   * thread whenever the transport is rolling, or when any client has
641   * requested a new position in the previous cycle.  The first cycle
642   * after jack_set_timebase_callback() is also treated as a new
643   * position, or the first cycle after jack_activate() if the client
644   * had been inactive.
645   *
646   * The timebase master may not use its @a pos argument to set @a
647   * pos->frame.  To change position, use jack_transport_reposition() or
648   * jack_transport_locate().  These functions are realtime-safe, the @a
649   * timebase_callback can call them directly.
650   *
651   * @param state current transport state.
652   * @param nframes number of frames in current period.
653   * @param pos address of the position structure for the next cycle; @a
654   * pos->frame will be its frame number.  If @a new_pos is FALSE, this
655   * structure contains extended position information from the current
656   * cycle.  If TRUE, it contains whatever was set by the requester.
657   * The @a timebase_callback's task is to update the extended
658   * information here.
659   * @param new_pos TRUE (non-zero) for a newly requested @a pos, or for
660   * the first cycle after the @a timebase_callback is defined.
661   * @param arg the argument supplied by jack_set_timebase_callback().
662   */
663 alias JackTimebaseCallback = void function(jack_transport_state_t state,
664                                            jack_nframes_t nframes,
665                                            jack_position_t *pos,
666                                            int new_pos,
667                                            void *arg);
668 
669 /*********************************************************************
670     * The following interfaces are DEPRECATED.  They are only provided
671     * for compatibility with the earlier JACK transport implementation.
672     *********************************************************************/
673 
674 /**
675  * Optional struct jack_transport_info_t fields.
676  *
677  * @see jack_position_bits_t.
678  */
679 enum jack_transport_bits_t {
680     JackTransportState = 0x1,   /**< Transport state */
681     JackTransportPosition = 0x2,        /**< Frame number */
682     JackTransportLoop = 0x4,    /**< Loop boundaries (ignored) */
683     JackTransportSMPTE = 0x8,   /**< SMPTE (ignored) */
684     JackTransportBBT = 0x10     /**< Bar, Beat, Tick */
685 };
686 
687 /**
688  * Deprecated struct for transport position information.
689  *
690  * @deprecated This is for compatibility with the earlier transport
691  * interface.  Use the jack_position_t struct, instead.
692  */
693 struct jack_transport_info_t {
694     /* these two cannot be set from clients: the server sets them */
695 
696     jack_nframes_t frame_rate;          /**< current frame rate (per second) */
697     jack_time_t usecs;          /**< monotonic, free-rolling */
698 
699     jack_transport_bits_t valid;        /**< which fields are legal to read */
700     jack_transport_state_t transport_state;
701     jack_nframes_t frame;
702     jack_nframes_t loop_start;
703     jack_nframes_t loop_end;
704 
705     c_long smpte_offset;  /**< SMPTE offset (from frame 0) */
706     float smpte_frame_rate;     /**< 29.97, 30, 24 etc. */
707 
708     int bar;
709     int beat;
710     int tick;
711     double bar_start_tick;
712 
713     float beats_per_bar;
714     float beat_type;
715     double ticks_per_beat;
716     double beats_per_minute;
717 };
718 
719 }