jack.h 41.8 KB
Newer Older
sletz's avatar
sletz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
  Copyright (C) 2001 Paul Davis
  Copyright (C) 2004 Jack O'Quin
  
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as published by
  the Free Software Foundation; either version 2.1 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public License
  along with this program; if not, write to the Free Software 
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

#ifndef __jack_h__
#define __jack_h__

#ifdef __cplusplus
extern "C"
{
#endif

29
#include <jack/systemdeps.h>
sletz's avatar
sletz committed
30
31
#include <jack/types.h>
#include <jack/transport.h>
sletz's avatar
sletz committed
32

33
34
35
36
/**
 * Note: More documentation can be found in jack/types.h.
 */
 
37
38
39
40
41
42
43
44
45
46
47
48
    /*************************************************************
     * NOTE: JACK_WEAK_EXPORT ***MUST*** be used on every function
     * added to the JACK API after the 0.116.2 release.
     * 
     * Functions that predate this release are marked with 
     * JACK_WEAK_OPTIONAL_EXPORT which can be defined at compile
     * time in a variety of ways. The default definition is empty,
     * so that these symbols get normal linkage. If you wish to
     * use all JACK symbols with weak linkage, include 
     * <jack/weakjack.h> before jack.h.
     *************************************************************/
    
49
50
#ifndef JACK_WEAK_EXPORT
#ifdef __GNUC__
51
52
53
54
55
56
    /* JACK_WEAK_EXPORT needs to be a macro which
     expands into a compiler directive. If non-null, the directive 
     must tell the compiler to arrange for weak linkage of 
     the symbol it used with. For this to work full may
     require linker arguments in the client as well.
     */
57
#define JACK_WEAK_EXPORT __attribute__((weak))
58
59
#else
    /* Add other things here for non-gcc platforms */
60
61
#endif
#endif
62
63
64
65
66
67
68
69
70
71
72
73
74
    
#ifndef JACK_OPTIONAL_WEAK_EXPORT
#define JACK_OPTIONAL_WEAK_EXPORT
#endif
    
#ifndef JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT
#ifdef __GNUC__
#define JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT __attribute__((__deprecated__))
#else
    /* Add other things here for non-gcc platforms */
#endif /* __GNUC__ */
#endif
    
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
 * Call this function to get version of the JACK, in form of several numbers
 *
 * @param major_ptr pointer to variable receiving major version of JACK.
 *
 * @param minor_ptr pointer to variable receiving minor version of JACK.
 *
 * @param major_ptr pointer to variable receiving micro version of JACK.
 *
 * @param major_ptr pointer to variable receiving protocol version of JACK.
 *
 */
void
jack_get_version(
    int *major_ptr,
    int *minor_ptr,
    int *micro_ptr,
92
    int *proto_ptr) JACK_OPTIONAL_WEAK_EXPORT;
93
94
95
96
97
98
99
100

/**
 * Call this function to get version of the JACK, in form of a string
 *
 * @return Human readable string describing JACK version being used.
 *
 */
const char *
101
jack_get_version_string() JACK_OPTIONAL_WEAK_EXPORT;
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

/**
 * Open an external client session with a JACK server.  This interface
 * is more complex but more powerful than jack_client_new().  With it,
 * clients may choose which of several servers to connect, and control
 * whether and how to start the server automatically, if it was not
 * already running.  There is also an option for JACK to generate a
 * unique client name, when necessary.
 *
 * @param client_name of at most jack_client_name_size() characters.
 * The name scope is local to each server.  Unless forbidden by the
 * @ref JackUseExactName option, the server will modify this name to
 * create a unique variant, if needed.
 *
 * @param options formed by OR-ing together @ref JackOptions bits.
 * Only the @ref JackOpenOptions bits are allowed.
 *
 * @param status (if non-NULL) an address for JACK to return
 * information from the open operation.  This status word is formed by
 * OR-ing together the relevant @ref JackStatus bits.
 *
 *
 * <b>Optional parameters:</b> depending on corresponding [@a options
 * bits] additional parameters may follow @a status (in this order).
 *
 * @arg [@ref JackServerName] <em>(char *) server_name</em> selects
 * from among several possible concurrent server instances.  Server
 * names are unique to each user.  If unspecified, use "default"
 * unless \$JACK_DEFAULT_SERVER is defined in the process environment.
 *
 * @return Opaque client handle if successful.  If this is NULL, the
 * open operation failed, @a *status includes @ref JackFailure and the
 * caller is not a JACK client.
 */
jack_client_t * jack_client_open (const char *client_name,
                                  jack_options_t options,
138
                                  jack_status_t *status, ...) JACK_OPTIONAL_WEAK_EXPORT;
139
140
141
142
143

/**
* \bold THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED IN
*  NEW JACK CLIENTS
*
144
* @deprecated Please use jack_client_open().
145
*/
146
jack_client_t * jack_client_new (const char *client_name) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
147
148
149
150
151
152

/**
 * Disconnects an external client from a JACK server.
 *
 * @return 0 on success, otherwise a non-zero error code
 */
153
int jack_client_close (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
154
155
156
157
158

/**
 * @return the maximum number of characters in a JACK client name
 * including the final NULL character.  This value is a constant.
 */
159
int jack_client_name_size (void) JACK_OPTIONAL_WEAK_EXPORT;
160
161
162
163
164
165
166

/**
 * @return pointer to actual client name.  This is useful when @ref
 * JackUseExactName is not specified on open and @ref
 * JackNameNotUnique status was returned.  In that case, the actual
 * name will differ from the @a client_name requested.
 */
167
char * jack_get_client_name (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

/**
 * Load an internal client into the Jack server.
 *
 * Internal clients run inside the JACK server process.  They can use
 * most of the same functions as external clients.  Each internal
 * client must declare jack_initialize() and jack_finish() entry
 * points, called at load and unload times.  See inprocess.c for an
 * example of how to write an internal client.
 *
 * @deprecated Please use jack_internal_client_load().
 *
 * @param client_name of at most jack_client_name_size() characters.
 *
 * @param load_name of a shared object file containing the code for
 * the new client.
 *
 * @param load_init an arbitary string passed to the jack_initialize()
 * routine of the new client (may be NULL).
 *
 * @return 0 if successful.
 */
int jack_internal_client_new (const char *client_name,
                              const char *load_name,
192
                              const char *load_init) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
193
194
195
196
197
198

/**
 * Remove an internal client from a JACK server.
 *
 * @deprecated Please use jack_internal_client_load().
 */
199
void jack_internal_client_close (const char *client_name) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
200
201
202
203
204
205
206

/**
 * Tell the Jack server that the program is ready to start processing
 * audio.
 *
 * @return 0 on success, otherwise a non-zero error code
 */
207
int jack_activate (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
208
209
210
211
212
213
214
215

/**
 * Tell the Jack server to remove this @a client from the process
 * graph.  Also, disconnect all ports belonging to it, since inactive
 * clients have no port connections.
 *
 * @return 0 on success, otherwise a non-zero error code
 */
216
int jack_deactivate (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
217
218
219
220

/**
 * @return pid of client. If not available, 0 will be returned.
 */
221
int jack_get_client_pid (const char *name) JACK_OPTIONAL_WEAK_EXPORT;
222
223
224
225
226

/**
 * @return the pthread ID of the thread running the JACK client side
 * code.
 */
227
pthread_t jack_client_thread_id (jack_client_t *) JACK_OPTIONAL_WEAK_EXPORT;
228
229
230
231
232
233
234
235
236
237

/*@}*/

/**
 * @param client pointer to JACK client structure.
 *
 * Check if the JACK subsystem is running with -R (--realtime).
 *
 * @return 1 if JACK is running realtime, 0 otherwise
 */
238
int jack_is_realtime (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
239
240
241
242
243
244
245
246
247
248

/**
 * @defgroup NonCallbackAPI The non-callback API
 * @{
 */

/**
 * \bold THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED IN
 *  NEW JACK CLIENTS.
 *
249
 * @deprecated Please use jack_cycle_wait() and jack_cycle_signal() functions.
250
 */
251
jack_nframes_t jack_thread_wait (jack_client_t*, int status) JACK_OPTIONAL_WEAK_EXPORT;
252
253
254
255
256
257
258
259

/**
 * Wait until this JACK client should process data.
 * 
 * @param client - pointer to a JACK client structure
 *
 * @return the number of frames of data to process
 */
260
    jack_nframes_t jack_cycle_wait (jack_client_t* client) JACK_OPTIONAL_WEAK_EXPORT;
261
262
263
264
265
266
267

/**
 * Signal next clients in the graph.
 * 
 * @param client - pointer to a JACK client structure
 * @param status - if non-zero, calling thread should exit
 */
268
void jack_cycle_signal (jack_client_t* client, int status) JACK_OPTIONAL_WEAK_EXPORT;
269
270
271

/**
 * Tell the Jack server to call @a thread_callback in the RT thread.
272
 * Typical use are in conjunction with @a jack_cycle_wait and @a jack_cycle_signal functions.
273
274
275
276
277
278
279
280
281
282
283
284
285
 * The code in the supplied function must be suitable for real-time
 * execution.  That means that it cannot call functions that might
 * block for a long time. This includes malloc, free, printf,
 * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
 * pthread_cond_wait, etc, etc. See
 * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
 * for more information.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code.
*/
286
int jack_set_process_thread(jack_client_t* client, JackThreadCallback thread_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

/*@}*/

/**
 * @defgroup ClientCallbacks Setting Client Callbacks
 * @{
 */

/**
 * Tell JACK to call @a thread_init_callback once just after
 * the creation of the thread in which all other callbacks 
 * will be handled.
 *
 * The code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code, causing JACK
 * to remove that client from the process() graph.
 */
int jack_set_thread_init_callback (jack_client_t *client,
                                   JackThreadInitCallback thread_init_callback,
311
                                   void *arg) JACK_OPTIONAL_WEAK_EXPORT;
312
313
314
315
316
317

/**
 * @param client pointer to JACK client structure.
 * @param function The jack_shutdown function pointer.
 * @param arg The arguments for the jack_shutdown function.
 *
318
 * Register a function (and argument) to be called if and when the
319
320
321
322
323
324
325
326
327
328
329
 * JACK server shuts down the client thread.  The function must
 * be written as if it were an asynchonrous POSIX signal
 * handler --- use only async-safe functions, and remember that it
 * is executed from another thread.  A typical function might
 * set a flag or write to a pipe so that the rest of the
 * application knows that the JACK client thread has shut
 * down.
 *
 * NOTE: clients do not need to call this.  It exists only
 * to help more complex clients understand what is going
 * on.  It should be called before jack_client_activate().
sletz's avatar
sletz committed
330
331
332
333
334
 *
 * NOTE: if a client calls this AND jack_on_info_shutdown(), then
 * the event of a client thread shutdown, the callback
 * passed to this function will not be called, and the one passed to
 * jack_on_info_shutdown() will.
335
336
 */
void jack_on_shutdown (jack_client_t *client,
337
                       JackShutdownCallback shutdown_callback, void *arg) JACK_WEAK_EXPORT;
338

339
340
/**
 * @param client pointer to JACK client structure.
341
342
 * @param function The jack_info_shutdown function pointer.
 * @param arg The arguments for the jack_info_shutdown function.
343
344
345
346
347
348
349
350
351
352
353
354
355
 *
 * Register a function (and argument) to be called if and when the
 * JACK server shuts down the client thread.  The function must
 * be written as if it were an asynchonrous POSIX signal
 * handler --- use only async-safe functions, and remember that it
 * is executed from another thread.  A typical function might
 * set a flag or write to a pipe so that the rest of the
 * application knows that the JACK client thread has shut
 * down.
 *
 * NOTE: clients do not need to call this.  It exists only
 * to help more complex clients understand what is going
 * on.  It should be called before jack_client_activate().
sletz's avatar
sletz committed
356
357
358
359
360
 *
 * NOTE: if a client calls this AND jack_on_info_shutdown(), then
 * the event of a client thread shutdown, the callback
 * passed to this function will not be called, and the one passed to
 * jack_on_info_shutdown() will.
361
362
 */
void jack_on_info_shutdown (jack_client_t *client,
363
                            JackInfoShutdownCallback shutdown_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
364
    
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/**
 * Tell the Jack server to call @a process_callback whenever there is
 * work be done, passing @a arg as the second argument.
 *
 * The code in the supplied function must be suitable for real-time
 * execution.  That means that it cannot call functions that might
 * block for a long time. This includes malloc, free, printf,
 * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
 * pthread_cond_wait, etc, etc. See
 * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
 * for more information.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code.
 */
int jack_set_process_callback (jack_client_t *client,
                               JackProcessCallback process_callback,
384
                               void *arg) JACK_OPTIONAL_WEAK_EXPORT;
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

/**
 * Tell the Jack server to call @a freewheel_callback
 * whenever we enter or leave "freewheel" mode, passing @a
 * arg as the second argument. The first argument to the
 * callback will be non-zero if JACK is entering freewheel
 * mode, and zero otherwise.
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code.
 */
int jack_set_freewheel_callback (jack_client_t *client,
                                 JackFreewheelCallback freewheel_callback,
404
                                 void *arg) JACK_OPTIONAL_WEAK_EXPORT;
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

/**
 * Tell JACK to call @a bufsize_callback whenever the size of the the
 * buffer that will be passed to the @a process_callback is about to
 * change.  Clients that depend on knowing the buffer size must supply
 * a @a bufsize_callback before activating themselves.
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @param client pointer to JACK client structure.
 * @param bufsize_callback function to call when the buffer size changes.
 * @param arg argument for @a bufsize_callback.
 *
 * @return 0 on success, otherwise a non-zero error code
 */
int jack_set_buffer_size_callback (jack_client_t *client,
                                   JackBufferSizeCallback bufsize_callback,
427
                                   void *arg) JACK_OPTIONAL_WEAK_EXPORT;
sletz's avatar
Test    
sletz committed
428

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
/**
 * Tell the Jack server to call @a srate_callback whenever the system
 * sample rate changes.
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code
 */
int jack_set_sample_rate_callback (jack_client_t *client,
                                   JackSampleRateCallback srate_callback,
444
                                   void *arg) JACK_OPTIONAL_WEAK_EXPORT;
445
446

/**
sletz's avatar
sletz committed
447
448
 * Tell the JACK server to call @a client_registration_callback whenever a
 * client is registered or unregistered, passing @a arg as a parameter.
449
450
451
452
453
454
455
456
457
458
459
460
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code
 */
int jack_set_client_registration_callback (jack_client_t *,
                       JackClientRegistrationCallback
461
                                           registration_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

/**
 * Tell the JACK server to call @a registration_callback whenever a
 * port is registered or unregistered, passing @a arg as a parameter.
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code
 */
 int jack_set_port_registration_callback (jack_client_t *,
477
478
                                          JackPortRegistrationCallback
                                          registration_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
        
 /**
 * Tell the JACK server to call @a connect_callback whenever a
 * port is connected or disconnected, passing @a arg as a parameter.
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code
 */
int jack_set_port_connect_callback (jack_client_t *,
494
495
                                    JackPortConnectCallback
                                    connect_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510

 /**
 * Tell the JACK server to call @a rename_callback whenever a
 * port is renamed, passing @a arg as a parameter.
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code
 */
int jack_set_port_rename_callback (jack_client_t *,
511
512
                                   JackPortRenameCallback
                                   rename_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528

/**
 * Tell the JACK server to call @a graph_callback whenever the
 * processing graph is reordered, passing @a arg as a parameter.
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code
 */
int jack_set_graph_order_callback (jack_client_t *,
                                   JackGraphOrderCallback graph_callback,
529
                                   void *) JACK_OPTIONAL_WEAK_EXPORT;
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

/**
 * Tell the JACK server to call @a xrun_callback whenever there is a
 * xrun, passing @a arg as a parameter.
 *
 * All "notification events" are received in a seperated non RT thread,
 * the code in the supplied function does not need to be
 * suitable for real-time execution.
 *
 * NOTE: this function cannot be called while the client is activated 
 * (after jack_activate has been called.)
 *
 * @return 0 on success, otherwise a non-zero error code
 */
int jack_set_xrun_callback (jack_client_t *,
545
                            JackXRunCallback xrun_callback, void *arg) JACK_OPTIONAL_WEAK_EXPORT;
546
547
548
549
                            
/*@}*/

/**
550
 * @defgroup ServerClientControl Controlling & querying JACK server operation
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
 * @{
 */
                         
/**
 * Start/Stop JACK's "freewheel" mode.
 *
 * When in "freewheel" mode, JACK no longer waits for
 * any external event to begin the start of the next process
 * cycle. 
 *
 * As a result, freewheel mode causes "faster than realtime"
 * execution of a JACK graph. If possessed, real-time
 * scheduling is dropped when entering freewheel mode, and
 * if appropriate it is reacquired when stopping.
 * 
 * IMPORTANT: on systems using capabilities to provide real-time
 * scheduling (i.e. Linux kernel 2.4), if onoff is zero, this function
 * must be called from the thread that originally called jack_activate(). 
 * This restriction does not apply to other systems (e.g. Linux kernel 2.6 
 * or OS X).
 * 
 * @param client pointer to JACK client structure
 * @param onoff  if non-zero, freewheel mode starts. Otherwise
 *                  freewheel mode ends.
 *
 * @return 0 on success, otherwise a non-zero error code.
 */
578
int jack_set_freewheel(jack_client_t* client, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594

/**
 * Change the buffer size passed to the @a process_callback.
 *
 * This operation stops the JACK engine process cycle, then calls all
 * registered @a bufsize_callback functions before restarting the
 * process cycle.  This will cause a gap in the audio flow, so it
 * should only be done at appropriate stopping points.
 *
 * @see jack_set_buffer_size_callback()
 *
 * @param client pointer to JACK client structure.
 * @param nframes new buffer size.  Must be a power of two.
 *
 * @return 0 on success, otherwise a non-zero error code
 */
595
int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes) JACK_OPTIONAL_WEAK_EXPORT;
596
597
598
599
600
                       
/**
 * @return the sample rate of the jack system, as set by the user when
 * jackd was started.
 */
601
jack_nframes_t jack_get_sample_rate (jack_client_t *) JACK_OPTIONAL_WEAK_EXPORT;
602
603
604
605
606
607
608
609
610
611

/**
 * @return the current maximum size that will ever be passed to the @a
 * process_callback.  It should only be used *before* the client has
 * been activated.  This size may change, clients that depend on it
 * must register a @a bufsize_callback so they will be notified if it
 * does.
 *
 * @see jack_set_buffer_size_callback()
 */
612
jack_nframes_t jack_get_buffer_size (jack_client_t *) JACK_OPTIONAL_WEAK_EXPORT;
613
614
615
616
617
618
619
620
621
622
623

/**
 * Old-style interface to become the timebase for the entire JACK
 * subsystem.
 *
 * @deprecated This function still exists for compatibility with the
 * earlier transport interface, but it does nothing.  Instead, see
 * transport.h and use jack_set_timebase_callback().
 *
 * @return ENOSYS, function not implemented.
 */
624
int jack_engine_takeover_timebase (jack_client_t *) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
625
626
627
628
629
630
631

/**
 * @return the current CPU load estimated by JACK.  This is a running
 * average of the time it takes to execute a full process cycle for
 * all clients as a percentage of the real time available per cycle
 * determined by the buffer size and sample rate.
 */
632
float jack_cpu_load (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670

/*@}*/

/**
 * @defgroup PortFunctions Creating & manipulating ports
 * @{
 */
 
/**
 * Create a new port for the client. This is an object used for moving
 * data of any type in or out of the client.  Ports may be connected
 * in various ways.
 *
 * Each port has a short name.  The port's full name contains the name
 * of the client concatenated with a colon (:) followed by its short
 * name.  The jack_port_name_size() is the maximum length of this full
 * name.  Exceeding that will cause the port registration to fail and
 * return NULL.
 *
 * All ports have a type, which may be any non-NULL and non-zero
 * length string, passed as an argument.  Some port types are built
 * into the JACK API, currently only JACK_DEFAULT_AUDIO_TYPE.
 *
 * @param client pointer to JACK client structure.
 * @param port_name non-empty short name for the new port (not
 * including the leading @a "client_name:").
 * @param port_type port type name.  If longer than
 * jack_port_type_size(), only that many characters are significant.
 * @param flags @ref JackPortFlags bit mask.
 * @param buffer_size must be non-zero if this is not a built-in @a
 * port_type.  Otherwise, it is ignored.
 *
 * @return jack_port_t pointer on success, otherwise NULL.
 */
jack_port_t * jack_port_register (jack_client_t *client,
                                  const char *port_name,
                                  const char *port_type,
                                  unsigned long flags,
671
                                  unsigned long buffer_size) JACK_OPTIONAL_WEAK_EXPORT;
672
673
674
675
676
677
678

/**
 * Remove the port from the client, disconnecting any existing
 * connections.
 *
 * @return 0 on success, otherwise a non-zero error code
 */
679
int jack_port_unregister (jack_client_t *, jack_port_t *) JACK_OPTIONAL_WEAK_EXPORT;
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699

/**
 * This returns a pointer to the memory area associated with the
 * specified port. For an output port, it will be a memory area
 * that can be written to; for an input port, it will be an area
 * containing the data from the port's connection(s), or
 * zero-filled. if there are multiple inbound connections, the data
 * will be mixed appropriately.  
 *
 * FOR OUTPUT PORTS ONLY : DEPRECATED in Jack 2.0 !!
 * ---------------------------------------------------
 * You may cache the value returned, but only between calls to
 * your "blocksize" callback. For this reason alone, you should
 * either never cache the return value or ensure you have
 * a "blocksize" callback and be sure to invalidate the cached
 * address from there.
 * 
 * Caching output ports is DEPRECATED in Jack 2.0, due to some new optimization (like "pipelining").
 * Port buffers have to be retrieved in each callback for proper functionning. 
 */
700
void * jack_port_get_buffer (jack_port_t *, jack_nframes_t) JACK_OPTIONAL_WEAK_EXPORT;
701
702
703
704
705
706
707

/**
 * @return the full name of the jack_port_t (including the @a
 * "client_name:" prefix).
 *
 * @see jack_port_name_size().
 */
708
const char * jack_port_name (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
709
710
711
712
713
714
715

/**
 * @return the short name of the jack_port_t (not including the @a
 * "client_name:" prefix).
 *
 * @see jack_port_name_size().
 */
716
const char * jack_port_short_name (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
717
718
719
720

/**
 * @return the @ref JackPortFlags of the jack_port_t.
 */
721
int jack_port_flags (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
722
723
724
725
726

/**
 * @return the @a port type, at most jack_port_type_size() characters
 * including a final NULL.
 */
727
const char * jack_port_type (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
728
729
730
731

 /**
 * @return the @a port type id.
 */
732
jack_port_type_id_t jack_port_type_id (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
733
734
735
736

/**
 * @return TRUE if the jack_port_t belongs to the jack_client_t.
 */
737
int jack_port_is_mine (const jack_client_t *, const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
738
739
740
741
742
743

/**
 * @return number of connections to or from @a port.
 *
 * @pre The calling client must own @a port.
 */
744
int jack_port_connected (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
745
746
747
748
749
750
751
752

/**
 * @return TRUE if the locally-owned @a port is @b directly connected
 * to the @a port_name.
 *
 * @see jack_port_name_size()
 */
int jack_port_connected_to (const jack_port_t *port,
753
                            const char *port_name) JACK_OPTIONAL_WEAK_EXPORT;
754
755
756
757
758
759
760
761
762
763
764
765

/**
 * @return a null-terminated array of full port names to which the @a
 * port is connected.  If none, returns NULL.
 *
 * The caller is responsible for calling free(3) on any non-NULL
 * returned value.
 *
 * @param port locally owned jack_port_t pointer.
 *
 * @see jack_port_name_size(), jack_port_get_all_connections()
 */
766
const char ** jack_port_get_connections (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787

/**
 * @return a null-terminated array of full port names to which the @a
 * port is connected.  If none, returns NULL.
 *
 * The caller is responsible for calling free(3) on any non-NULL
 * returned value.
 *
 * This differs from jack_port_get_connections() in two important
 * respects:
 *
 *     1) You may not call this function from code that is
 *          executed in response to a JACK event. For example,
 *          you cannot use it in a GraphReordered handler.
 *
 *     2) You need not be the owner of the port to get information
 *          about its connections. 
 *
 * @see jack_port_name_size()
 */
const char ** jack_port_get_all_connections (const jack_client_t *client,
788
                                             const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
789
790
791
792
793
794
795
796

/**
 *
 * @deprecated This function will be removed from a future version 
 * of JACK. Do not use it. There is no replacement. It has 
 * turned out to serve essentially no purpose in real-life
 * JACK clients.
 */
797
int jack_port_tie (jack_port_t *src, jack_port_t *dst) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
798
799
800
801
802
803
804
805

/**
 *
 * @deprecated This function will be removed from a future version 
 * of JACK. Do not use it. There is no replacement. It has 
 * turned out to serve essentially no purpose in real-life
 * JACK clients.
 */
806
int jack_port_untie (jack_port_t *port) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
807
808
809
810
811
812
813
814
815
816
817

 /**
 * @return the time (in frames) between data being available or
 * delivered at/to a port, and the time at which it arrived at or is
 * delivered to the "other side" of the port.  E.g. for a physical
 * audio output port, this is the time between writing to the port and
 * when the signal will leave the connector.  For a physical audio
 * input port, this is the time between the sound arriving at the
 * connector and the corresponding frames being readable from the
 * port.
 */
818
jack_nframes_t jack_port_get_latency (jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
819
820
821
822
823
824
825

/**
 * The maximum of the sum of the latencies in every
 * connection path that can be drawn between the port and other
 * ports with the @ref JackPortIsTerminal flag set.
 */
jack_nframes_t jack_port_get_total_latency (jack_client_t *,
826
                                            jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
827
828
829
830
831
832
833
834
835
836
837

/**
 * The port latency is zero by default. Clients that control
 * physical hardware with non-zero latency should call this
 * to set the latency to its correct value. Note that the value
 * should include any systemic latency present "outside" the
 * physical hardware controlled by the client. For example,
 * for a client controlling a digital audio interface connected
 * to an external digital converter, the latency setting should
 * include both buffering by the audio interface *and* the converter. 
 */
838
void jack_port_set_latency (jack_port_t *, jack_nframes_t) JACK_OPTIONAL_WEAK_EXPORT;
839
840
841
842
843
844
845
846
847
848
849
850

/**
* Request a complete recomputation of a port's total latency. This
* can be called by a client that has just changed the internal
* latency of its port using @function jack_port_set_latency
* and wants to ensure that all signal pathways in the graph
* are updated with respect to the values that will be returned
* by @function jack_port_get_total_latency. 
* 
* @return zero for successful execution of the request. non-zero
*         otherwise.
*/
851
int jack_recompute_total_latency (jack_client_t*, jack_port_t* port) JACK_OPTIONAL_WEAK_EXPORT;
852
853
854
855
856
857
858
859
860
861
862
863
864
865

/**
* Request a complete recomputation of all port latencies. This
* can be called by a client that has just changed the internal
* latency of its port using @function jack_port_set_latency
* and wants to ensure that all signal pathways in the graph
* are updated with respect to the values that will be returned
* by @function jack_port_get_total_latency. It allows a client 
* to change multiple port latencies without triggering a 
* recompute for each change.
* 
* @return zero for successful execution of the request. non-zero
*         otherwise.
*/
866
    int jack_recompute_total_latencies (jack_client_t*) JACK_OPTIONAL_WEAK_EXPORT;
867
868
869
870
871
872
873
874

/**
 * Modify a port's short name.  May be called at any time.  If the
 * resulting full name (including the @a "client_name:" prefix) is
 * longer than jack_port_name_size(), it will be truncated.
 *
 * @return 0 on success, otherwise a non-zero error code.
 */
875
int jack_port_set_name (jack_port_t *port, const char *port_name) JACK_OPTIONAL_WEAK_EXPORT;
876
877
878
879
880
881
882
883
884
885
886
887
888
889

/**
 * Set @a alias as an alias for @a port.  May be called at any time.
 * If the alias is longer than jack_port_name_size(), it will be truncated.
 * 
 * After a successful call, and until JACK exits or
 * @function jack_port_unset_alias() is called, @alias may be
 * used as a alternate name for the port.
 *
 * Ports can have up to two aliases - if both are already 
 * set, this function will return an error.
 *
 * @return 0 on success, otherwise a non-zero error code.
 */
890
int jack_port_set_alias (jack_port_t *port, const char *alias) JACK_OPTIONAL_WEAK_EXPORT;
891
892
893
894
895
896
897
898
899

/**
 * Remove @a alias as an alias for @a port.  May be called at any time.
 * 
 * After a successful call, @a alias can no longer be 
 * used as a alternate name for the port.
 *
 * @return 0 on success, otherwise a non-zero error code.
 */
900
int jack_port_unset_alias (jack_port_t *port, const char *alias) JACK_OPTIONAL_WEAK_EXPORT;
901

902
/**
903
904
905
906
 * Get any aliases known for @port.
 *
 * @return the number of aliases discovered for the port
 */
907
int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]) JACK_OPTIONAL_WEAK_EXPORT;
908
909
910
911
912

/**
 * If @ref JackPortCanMonitor is set for this @a port, turn input
 * monitoring on or off.  Otherwise, do nothing.
 */
913
int jack_port_request_monitor (jack_port_t *port, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
914
915
916
917
918
919
920
921
922
923

/**
 * If @ref JackPortCanMonitor is set for this @a port_name, turn input
 * monitoring on or off.  Otherwise, do nothing.
 *
 * @return 0 on success, otherwise a non-zero error code.
 *
 * @see jack_port_name_size()
 */
int jack_port_request_monitor_by_name (jack_client_t *client,
924
                                       const char *port_name, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
925
926
927
928
929
930
931
932

/**
 * If @ref JackPortCanMonitor is set for a port, this function turns
 * on input monitoring if it was off, and turns it off if only one
 * request has been made to turn it on.  Otherwise it does nothing.
 *
 * @return 0 on success, otherwise a non-zero error code
 */
933
int jack_port_ensure_monitor (jack_port_t *port, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
934
935
936
937

/**
 * @return TRUE if input monitoring has been requested for @a port.
 */
938
int jack_port_monitoring_input (jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958

/**
 * Establish a connection between two ports.
 *
 * When a connection exists, data written to the source port will
 * be available to be read at the destination port.
 *
 * @pre The port types must be identical.
 *
 * @pre The @ref JackPortFlags of the @a source_port must include @ref
 * JackPortIsOutput.
 *
 * @pre The @ref JackPortFlags of the @a destination_port must include
 * @ref JackPortIsInput.
 *
 * @return 0 on success, EEXIST if the connection is already made,
 * otherwise a non-zero error code
 */
int jack_connect (jack_client_t *,
                  const char *source_port,
959
                  const char *destination_port) JACK_OPTIONAL_WEAK_EXPORT;
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975

/**
 * Remove a connection between two ports.
 *
 * @pre The port types must be identical.
 *
 * @pre The @ref JackPortFlags of the @a source_port must include @ref
 * JackPortIsOutput.
 *
 * @pre The @ref JackPortFlags of the @a destination_port must include
 * @ref JackPortIsInput.
 *
 * @return 0 on success, otherwise a non-zero error code
 */
int jack_disconnect (jack_client_t *,
                     const char *source_port,
976
                     const char *destination_port) JACK_OPTIONAL_WEAK_EXPORT;
977
978
979
980
981
982
983
984
985
986

/**
 * Perform the same function as jack_disconnect() using port handles
 * rather than names.  This avoids the name lookup inherent in the
 * name-based version.
 *
 * Clients connecting their own ports are likely to use this function,
 * while generic connection clients (e.g. patchbays) would use
 * jack_disconnect().
 */
987
int jack_port_disconnect (jack_client_t *, jack_port_t *) JACK_OPTIONAL_WEAK_EXPORT;
988
989
990
991
992
993
994
995
996

/**
 * @return the maximum number of characters in a full JACK port name
 * including the final NULL character.  This value is a constant.
 *
 * A port's full name contains the owning client name concatenated
 * with a colon (:) followed by its short name and a NULL
 * character.
 */
997
int jack_port_name_size(void) JACK_OPTIONAL_WEAK_EXPORT;
998
999
1000

/**
 * @return the maximum number of characters in a JACK port type name
For faster browsing, not all history is shown. View entire blame