2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2008 Grame
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 #include "JackClient.h"
22 #include "JackError.h"
23 #include "JackGraphManager.h"
24 #include "JackEngineControl.h"
25 #include "JackClientControl.h"
26 #include "JackGlobals.h"
28 #include "JackCompilerDeps.h"
29 #include "JackPortType.h"
30 #include "JackPlatformPlug.h"
33 #ifdef __CLIENTDEBUG__
34 #include "JackLibGlobals.h"
44 typedef void (*print_function
)(const char *);
45 typedef void *(*thread_routine
)(void*);
57 jack_get_version_string();
59 EXPORT jack_client_t
* jack_client_open_aux (const char *client_name
,
60 jack_options_t options
,
61 jack_status_t
*status
, va_list ap
);
62 EXPORT jack_client_t
* jack_client_open (const char *client_name
,
63 jack_options_t options
,
64 jack_status_t
*status
, ...);
65 EXPORT jack_client_t
* jack_client_new (const char *client_name
);
66 EXPORT
int jack_client_name_size (void);
67 EXPORT
char* jack_get_client_name (jack_client_t
*client
);
68 EXPORT
int jack_internal_client_new (const char *client_name
,
69 const char *load_name
,
70 const char *load_init
);
71 EXPORT
void jack_internal_client_close (const char *client_name
);
72 EXPORT
int jack_is_realtime (jack_client_t
*client
);
73 EXPORT
void jack_on_shutdown (jack_client_t
*client
,
74 JackShutdownCallback shutdown_callback
, void *arg
);
75 EXPORT
void jack_on_info_shutdown (jack_client_t
*client
,
76 JackInfoShutdownCallback shutdown_callback
, void *arg
);
77 EXPORT
int jack_set_process_callback (jack_client_t
*client
,
78 JackProcessCallback process_callback
,
80 EXPORT jack_nframes_t
jack_thread_wait(jack_client_t
*client
, int status
);
83 EXPORT jack_nframes_t
jack_cycle_wait (jack_client_t
*);
84 EXPORT
void jack_cycle_signal (jack_client_t
*, int status
);
85 EXPORT
int jack_set_process_thread(jack_client_t
* client
, JackThreadCallback fun
, void *arg
);
87 EXPORT
int jack_set_thread_init_callback (jack_client_t
*client
,
88 JackThreadInitCallback thread_init_callback
,
90 EXPORT
int jack_set_freewheel_callback (jack_client_t
*client
,
91 JackFreewheelCallback freewheel_callback
,
93 EXPORT
int jack_set_freewheel(jack_client_t
* client
, int onoff
);
94 EXPORT
int jack_set_buffer_size (jack_client_t
*client
, jack_nframes_t nframes
);
95 EXPORT
int jack_set_buffer_size_callback (jack_client_t
*client
,
96 JackBufferSizeCallback bufsize_callback
,
98 EXPORT
int jack_set_sample_rate_callback (jack_client_t
*client
,
99 JackSampleRateCallback srate_callback
,
101 EXPORT
int jack_set_client_registration_callback (jack_client_t
*,
102 JackClientRegistrationCallback
103 registration_callback
, void *arg
);
104 EXPORT
int jack_set_port_registration_callback (jack_client_t
*,
105 JackPortRegistrationCallback
106 registration_callback
, void *arg
);
107 EXPORT
int jack_set_port_connect_callback (jack_client_t
*,
108 JackPortConnectCallback
109 connect_callback
, void *arg
);
110 EXPORT
int jack_set_port_rename_callback (jack_client_t
*,
111 JackPortRenameCallback
112 rename_callback
, void *arg
);
113 EXPORT
int jack_set_graph_order_callback (jack_client_t
*,
114 JackGraphOrderCallback graph_callback
,
116 EXPORT
int jack_set_xrun_callback (jack_client_t
*,
117 JackXRunCallback xrun_callback
, void *arg
);
118 EXPORT
int jack_activate (jack_client_t
*client
);
119 EXPORT
int jack_deactivate (jack_client_t
*client
);
120 EXPORT jack_port_t
* jack_port_register (jack_client_t
*client
,
121 const char *port_name
,
122 const char *port_type
,
124 unsigned long buffer_size
);
125 EXPORT
int jack_port_unregister (jack_client_t
*, jack_port_t
*);
126 EXPORT
void * jack_port_get_buffer (jack_port_t
*, jack_nframes_t
);
127 EXPORT
const char * jack_port_name (const jack_port_t
*port
);
128 EXPORT
const char * jack_port_short_name (const jack_port_t
*port
);
129 EXPORT
int jack_port_flags (const jack_port_t
*port
);
130 EXPORT
const char * jack_port_type (const jack_port_t
*port
);
131 EXPORT jack_port_type_id_t
jack_port_type_id (const jack_port_t
*port
);
132 EXPORT
int jack_port_is_mine (const jack_client_t
*, const jack_port_t
*port
);
133 EXPORT
int jack_port_connected (const jack_port_t
*port
);
134 EXPORT
int jack_port_connected_to (const jack_port_t
*port
,
135 const char *port_name
);
136 EXPORT
const char ** jack_port_get_connections (const jack_port_t
*port
);
137 EXPORT
const char ** jack_port_get_all_connections (const jack_client_t
*client
,
138 const jack_port_t
*port
);
139 EXPORT
int jack_port_tie (jack_port_t
*src
, jack_port_t
*dst
);
140 EXPORT
int jack_port_untie (jack_port_t
*port
);
141 EXPORT jack_nframes_t
jack_port_get_latency (jack_port_t
*port
);
142 EXPORT jack_nframes_t
jack_port_get_total_latency (jack_client_t
*,
144 EXPORT
void jack_port_set_latency (jack_port_t
*, jack_nframes_t
);
145 EXPORT
int jack_recompute_total_latency (jack_client_t
*, jack_port_t
* port
);
146 EXPORT
int jack_recompute_total_latencies (jack_client_t
*);
147 EXPORT
int jack_port_set_name (jack_port_t
*port
, const char *port_name
);
148 EXPORT
int jack_port_set_alias (jack_port_t
*port
, const char *alias
);
149 EXPORT
int jack_port_unset_alias (jack_port_t
*port
, const char *alias
);
150 EXPORT
int jack_port_get_aliases (const jack_port_t
*port
, char* const aliases
[2]);
151 EXPORT
int jack_port_request_monitor (jack_port_t
*port
, int onoff
);
152 EXPORT
int jack_port_request_monitor_by_name (jack_client_t
*client
,
153 const char *port_name
, int onoff
);
154 EXPORT
int jack_port_ensure_monitor (jack_port_t
*port
, int onoff
);
155 EXPORT
int jack_port_monitoring_input (jack_port_t
*port
);
156 EXPORT
int jack_connect (jack_client_t
*,
157 const char *source_port
,
158 const char *destination_port
);
159 EXPORT
int jack_disconnect (jack_client_t
*,
160 const char *source_port
,
161 const char *destination_port
);
162 EXPORT
int jack_port_disconnect (jack_client_t
*, jack_port_t
*);
163 EXPORT
int jack_port_name_size(void);
164 EXPORT
int jack_port_type_size(void);
165 EXPORT jack_nframes_t
jack_get_sample_rate (jack_client_t
*);
166 EXPORT jack_nframes_t
jack_get_buffer_size (jack_client_t
*);
167 EXPORT
const char ** jack_get_ports (jack_client_t
*,
168 const char *port_name_pattern
,
169 const char *type_name_pattern
,
170 unsigned long flags
);
171 EXPORT jack_port_t
* jack_port_by_name (jack_client_t
*, const char *port_name
);
172 EXPORT jack_port_t
* jack_port_by_id (jack_client_t
*client
,
173 jack_port_id_t port_id
);
174 EXPORT
int jack_engine_takeover_timebase (jack_client_t
*);
175 EXPORT jack_nframes_t
jack_frames_since_cycle_start (const jack_client_t
*);
176 EXPORT jack_time_t
jack_get_time();
177 EXPORT jack_nframes_t
jack_time_to_frames(const jack_client_t
*client
, jack_time_t time
);
178 EXPORT jack_time_t
jack_frames_to_time(const jack_client_t
*client
, jack_nframes_t frames
);
179 EXPORT jack_nframes_t
jack_frame_time (const jack_client_t
*);
180 EXPORT jack_nframes_t
jack_last_frame_time (const jack_client_t
*client
);
181 EXPORT
float jack_cpu_load (jack_client_t
*client
);
182 EXPORT pthread_t
jack_client_thread_id (jack_client_t
*);
183 EXPORT
void jack_set_error_function (print_function
);
184 EXPORT
void jack_set_info_function (print_function
);
186 EXPORT
float jack_get_max_delayed_usecs (jack_client_t
*client
);
187 EXPORT
float jack_get_xrun_delayed_usecs (jack_client_t
*client
);
188 EXPORT
void jack_reset_max_delayed_usecs (jack_client_t
*client
);
190 EXPORT
int jack_release_timebase (jack_client_t
*client
);
191 EXPORT
int jack_set_sync_callback (jack_client_t
*client
,
192 JackSyncCallback sync_callback
,
194 EXPORT
int jack_set_sync_timeout (jack_client_t
*client
,
195 jack_time_t timeout
);
196 EXPORT
int jack_set_timebase_callback (jack_client_t
*client
,
198 JackTimebaseCallback timebase_callback
,
200 EXPORT
int jack_transport_locate (jack_client_t
*client
,
201 jack_nframes_t frame
);
202 EXPORT jack_transport_state_t
jack_transport_query (const jack_client_t
*client
,
203 jack_position_t
*pos
);
204 EXPORT jack_nframes_t
jack_get_current_transport_frame (const jack_client_t
*client
);
205 EXPORT
int jack_transport_reposition (jack_client_t
*client
,
206 jack_position_t
*pos
);
207 EXPORT
void jack_transport_start (jack_client_t
*client
);
208 EXPORT
void jack_transport_stop (jack_client_t
*client
);
209 EXPORT
void jack_get_transport_info (jack_client_t
*client
,
210 jack_transport_info_t
*tinfo
);
211 EXPORT
void jack_set_transport_info (jack_client_t
*client
,
212 jack_transport_info_t
*tinfo
);
214 EXPORT
int jack_client_real_time_priority (jack_client_t
*);
215 EXPORT
int jack_client_max_real_time_priority (jack_client_t
*);
216 EXPORT
int jack_acquire_real_time_scheduling (pthread_t thread
, int priority
);
217 EXPORT
int jack_client_create_thread (jack_client_t
* client
,
220 int realtime
, // boolean
221 thread_routine routine
,
223 EXPORT
int jack_drop_real_time_scheduling (pthread_t thread
);
225 EXPORT
int jack_client_stop_thread (jack_client_t
* client
, pthread_t thread
);
226 EXPORT
int jack_client_kill_thread (jack_client_t
* client
, pthread_t thread
);
228 EXPORT
void jack_set_thread_creator (jack_thread_creator_t jtc
);
230 EXPORT
char * jack_get_internal_client_name (jack_client_t
*client
,
231 jack_intclient_t intclient
);
232 EXPORT jack_intclient_t
jack_internal_client_handle (jack_client_t
*client
,
233 const char *client_name
,
234 jack_status_t
*status
);
235 EXPORT jack_intclient_t
jack_internal_client_load (jack_client_t
*client
,
236 const char *client_name
,
237 jack_options_t options
,
238 jack_status_t
*status
, ...);
239 EXPORT jack_intclient_t
jack_internal_client_load_aux (jack_client_t
*client
,
240 const char *client_name
,
241 jack_options_t options
,
242 jack_status_t
*status
, va_list ap
);
244 EXPORT jack_status_t
jack_internal_client_unload (jack_client_t
*client
,
245 jack_intclient_t intclient
);
246 EXPORT
void jack_free(void* ptr
);
252 static inline bool CheckPort(jack_port_id_t port_index
)
254 return (port_index
> 0 && port_index
< PORT_NUM_MAX
);
257 static inline bool CheckBufferSize(jack_nframes_t buffer_size
)
259 return (buffer_size
<= BUFFER_SIZE_MAX
);
262 static inline void WaitGraphChange()
265 TLS key that is set only in RT thread, so never waits for pending
266 graph change in RT context (just read the current graph state).
269 if (jack_tls_get(JackGlobals::fRealTime
) == NULL
) {
270 JackGraphManager
* manager
= GetGraphManager();
271 JackEngineControl
* control
= GetEngineControl();
274 if (manager
->IsPendingChange()) {
275 jack_log("WaitGraphChange...");
276 JackSleep(int(control
->fPeriodUsecs
* 1.1f
));
281 EXPORT
void jack_set_error_function (print_function func
)
283 jack_error_callback
= (func
== NULL
) ? &default_jack_error_callback
: func
;
286 EXPORT
void jack_set_info_function (print_function func
)
288 jack_info_callback
= (func
== NULL
) ? &default_jack_info_callback
: func
;
291 EXPORT jack_client_t
* jack_client_new(const char* client_name
)
293 #ifdef __CLIENTDEBUG__
294 JackGlobals::CheckContext("jack_client_new");
297 assert(JackGlobals::fOpenMutex
);
298 JackGlobals::fOpenMutex
->Lock();
299 jack_error("jack_client_new: deprecated");
300 int options
= JackUseExactName
;
301 if (getenv("JACK_START_SERVER") == NULL
)
302 options
|= JackNoStartServer
;
303 jack_client_t
* res
= jack_client_open_aux(client_name
, (jack_options_t
)options
, NULL
, NULL
);
304 JackGlobals::fOpenMutex
->Unlock();
306 } catch (std::bad_alloc
& e
) {
307 jack_error("Memory allocation error...");
310 jack_error("Unknown error...");
315 EXPORT
void* jack_port_get_buffer(jack_port_t
* port
, jack_nframes_t frames
)
317 #ifdef __CLIENTDEBUG__
318 JackGlobals::CheckContext("jack_port_get_buffer");
320 #if defined(__x86_64__) || defined(__ppc64__)
321 uint64_t port_aux
= (uint64_t)port
;
323 uint32_t port_aux
= (uint32_t)port
;
325 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
326 if (!CheckPort(myport
)) {
327 jack_error("jack_port_get_buffer called with an incorrect port %ld", myport
);
330 JackGraphManager
* manager
= GetGraphManager();
331 return (manager
? manager
->GetBuffer(myport
, frames
) : NULL
);
335 EXPORT
const char* jack_port_name(const jack_port_t
* port
)
337 #ifdef __CLIENTDEBUG__
338 JackGlobals::CheckContext("jack_port_name");
340 #if defined(__x86_64__) || defined(__ppc64__)
341 uint64_t port_aux
= (uint64_t)port
;
343 uint32_t port_aux
= (uint32_t)port
;
345 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
346 if (!CheckPort(myport
)) {
347 jack_error("jack_port_name called with an incorrect port %ld", myport
);
350 JackGraphManager
* manager
= GetGraphManager();
351 return (manager
? manager
->GetPort(myport
)->GetName() : NULL
);
355 EXPORT
const char* jack_port_short_name(const jack_port_t
* port
)
357 #ifdef __CLIENTDEBUG__
358 JackGlobals::CheckContext("jack_port_short_name");
360 #if defined(__x86_64__) || defined(__ppc64__)
361 uint64_t port_aux
= (uint64_t)port
;
363 uint32_t port_aux
= (uint32_t)port
;
365 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
366 if (!CheckPort(myport
)) {
367 jack_error("jack_port_short_name called with an incorrect port %ld", myport
);
370 JackGraphManager
* manager
= GetGraphManager();
371 return (manager
? manager
->GetPort(myport
)->GetShortName() : NULL
);
375 EXPORT
int jack_port_flags(const jack_port_t
* port
)
377 #ifdef __CLIENTDEBUG__
378 JackGlobals::CheckContext("jack_port_flags");
380 #if defined(__x86_64__) || defined(__ppc64__)
381 uint64_t port_aux
= (uint64_t)port
;
383 uint32_t port_aux
= (uint32_t)port
;
385 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
386 if (!CheckPort(myport
)) {
387 jack_error("jack_port_flags called with an incorrect port %ld", myport
);
390 JackGraphManager
* manager
= GetGraphManager();
391 return (manager
? manager
->GetPort(myport
)->GetFlags() : -1);
395 EXPORT
const char* jack_port_type(const jack_port_t
* port
)
397 #ifdef __CLIENTDEBUG__
398 JackGlobals::CheckContext("jack_port_type");
400 #if defined(__x86_64__) || defined(__ppc64__)
401 uint64_t port_aux
= (uint64_t)port
;
403 uint32_t port_aux
= (uint32_t)port
;
405 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
406 if (!CheckPort(myport
)) {
407 jack_error("jack_port_flags called an incorrect port %ld", myport
);
410 JackGraphManager
* manager
= GetGraphManager();
411 return (manager
? manager
->GetPort(myport
)->GetType() : NULL
);
415 EXPORT jack_port_type_id_t
jack_port_type_id(const jack_port_t
*port
)
417 #ifdef __CLIENTDEBUG__
418 JackGlobals::CheckContext("jack_port_type_id");
420 #if defined(__x86_64__) || defined(__ppc64__)
421 uint64_t port_aux
= (uint64_t)port
;
423 uint32_t port_aux
= (uint32_t)port
;
425 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
426 if (!CheckPort(myport
)) {
427 jack_error("jack_port_type_id called an incorrect port %ld", myport
);
430 JackGraphManager
* manager
= GetGraphManager();
431 return (manager
? GetPortTypeId(manager
->GetPort(myport
)->GetType()) : 0);
435 EXPORT
int jack_port_connected(const jack_port_t
* port
)
437 #ifdef __CLIENTDEBUG__
438 JackGlobals::CheckContext("jack_port_connected");
440 #if defined(__x86_64__) || defined(__ppc64__)
441 uint64_t port_aux
= (uint64_t)port
;
443 uint32_t port_aux
= (uint32_t)port
;
445 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
446 if (!CheckPort(myport
)) {
447 jack_error("jack_port_connected called with an incorrect port %ld", myport
);
451 JackGraphManager
* manager
= GetGraphManager();
452 return (manager
? manager
->GetConnectionsNum(myport
) : -1);
456 EXPORT
int jack_port_connected_to(const jack_port_t
* port
, const char* port_name
)
458 #ifdef __CLIENTDEBUG__
459 JackGlobals::CheckContext("jack_port_connected_to");
461 #if defined(__x86_64__) || defined(__ppc64__)
462 uint64_t port_aux
= (uint64_t)port
;
464 uint32_t port_aux
= (uint32_t)port
;
466 jack_port_id_t src
= (jack_port_id_t
)port_aux
;
467 if (!CheckPort(src
)) {
468 jack_error("jack_port_connected_to called with an incorrect port %ld", src
);
470 } else if (port_name
== NULL
) {
471 jack_error("jack_port_connected_to called with a NULL port name");
475 JackGraphManager
* manager
= GetGraphManager();
476 jack_port_id_t dst
= (manager
? manager
->GetPort(port_name
) : NO_PORT
);
477 if (dst
== NO_PORT
) {
478 jack_error("Unknown destination port port_name = %s", port_name
);
481 return manager
->IsConnected(src
, dst
);
486 EXPORT
int jack_port_tie(jack_port_t
* src
, jack_port_t
* dst
)
488 #ifdef __CLIENTDEBUG__
489 JackGlobals::CheckContext("jack_port_tie");
491 #if defined(__x86_64__) || defined(__ppc64__)
492 uint64_t src_aux
= (uint64_t)src
;
494 uint32_t src_aux
= (uint32_t)src
;
496 jack_port_id_t mysrc
= (jack_port_id_t
)src_aux
;
497 if (!CheckPort(mysrc
)) {
498 jack_error("jack_port_tie called with a NULL src port");
501 #if defined(__x86_64__) || defined(__ppc64__)
502 uint64_t dst_aux
= (uint64_t)dst
;
504 uint32_t dst_aux
= (uint32_t)dst
;
506 jack_port_id_t mydst
= (jack_port_id_t
)dst_aux
;
507 if (!CheckPort(mydst
)) {
508 jack_error("jack_port_tie called with a NULL dst port");
511 JackGraphManager
* manager
= GetGraphManager();
512 if (manager
&& manager
->GetPort(mysrc
)->GetRefNum() != manager
->GetPort(mydst
)->GetRefNum()) {
513 jack_error("jack_port_tie called with ports not belonging to the same client");
516 return manager
->GetPort(mydst
)->Tie(mysrc
);
520 EXPORT
int jack_port_untie(jack_port_t
* port
)
522 #ifdef __CLIENTDEBUG__
523 JackGlobals::CheckContext("jack_port_untie");
525 #if defined(__x86_64__) || defined(__ppc64__)
526 uint64_t port_aux
= (uint64_t)port
;
528 uint32_t port_aux
= (uint32_t)port
;
530 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
531 if (!CheckPort(myport
)) {
532 jack_error("jack_port_untie called with an incorrect port %ld", myport
);
535 JackGraphManager
* manager
= GetGraphManager();
536 return (manager
? manager
->GetPort(myport
)->UnTie() : -1);
540 EXPORT jack_nframes_t
jack_port_get_latency(jack_port_t
* port
)
542 #ifdef __CLIENTDEBUG__
543 JackGlobals::CheckContext("jack_port_get_latency");
545 #if defined(__x86_64__) || defined(__ppc64__)
546 uint64_t port_aux
= (uint64_t)port
;
548 uint32_t port_aux
= (uint32_t)port
;
550 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
551 if (!CheckPort(myport
)) {
552 jack_error("jack_port_get_latency called with an incorrect port %ld", myport
);
556 JackGraphManager
* manager
= GetGraphManager();
557 return (manager
? manager
->GetPort(myport
)->GetLatency() : 0);
561 EXPORT
void jack_port_set_latency(jack_port_t
* port
, jack_nframes_t frames
)
563 #ifdef __CLIENTDEBUG__
564 JackGlobals::CheckContext("jack_port_set_latency");
566 #if defined(__x86_64__) || defined(__ppc64__)
567 uint64_t port_aux
= (uint64_t)port
;
569 uint32_t port_aux
= (uint32_t)port
;
571 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
572 if (!CheckPort(myport
)) {
573 jack_error("jack_port_set_latency called with an incorrect port %ld", myport
);
575 JackGraphManager
* manager
= GetGraphManager();
577 manager
->GetPort(myport
)->SetLatency(frames
);
581 EXPORT
int jack_recompute_total_latency(jack_client_t
* ext_client
, jack_port_t
* port
)
583 #ifdef __CLIENTDEBUG__
584 JackGlobals::CheckContext("jack_recompute_total_latency");
587 JackClient
* client
= (JackClient
*)ext_client
;
588 #if defined(__x86_64__) || defined(__ppc64__)
589 uint64_t port_aux
= (uint64_t)port
;
591 uint32_t port_aux
= (uint32_t)port
;
593 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
594 if (client
== NULL
) {
595 jack_error("jack_recompute_total_latencies called with a NULL client");
597 } else if (!CheckPort(myport
)) {
598 jack_error("jack_recompute_total_latencies called with a NULL port");
602 JackGraphManager
* manager
= GetGraphManager();
603 return (manager
? manager
->ComputeTotalLatency(myport
) : -1);
607 EXPORT
int jack_recompute_total_latencies(jack_client_t
* ext_client
)
609 #ifdef __CLIENTDEBUG__
610 JackGlobals::CheckContext("jack_recompute_total_latencies");
613 JackClient
* client
= (JackClient
*)ext_client
;
614 if (client
== NULL
) {
615 jack_error("jack_recompute_total_latencies called with a NULL client");
619 JackGraphManager
* manager
= GetGraphManager();
620 return (manager
? manager
->ComputeTotalLatencies() : -1);
625 This is unsafe if case of concurrent access, and should be "serialized" doing a server call.
628 EXPORT
int jack_port_set_name(jack_port_t
* port
, const char* name
)
630 #ifdef __CLIENTDEBUG__
631 JackGlobals::CheckContext("jack_port_set_name");
633 #if defined(__x86_64__) || defined(__ppc64__)
634 uint64_t port_aux
= (uint64_t)port
;
636 uint32_t port_aux
= (uint32_t)port
;
638 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
639 if (!CheckPort(myport
)) {
640 jack_error("jack_port_set_name called with an incorrect port %ld", myport
);
642 } else if (name
== NULL
) {
643 jack_error("jack_port_set_name called with a NULL port name");
646 JackGraphManager
* manager
= GetGraphManager();
648 if (manager
&& ((refnum
= manager
->GetPort(myport
)->GetRefNum()) > 0)) {
649 JackClient
* client
= JackGlobals::fClientTable
[refnum
];
651 return client
->PortRename(myport
, name
);
658 EXPORT
int jack_port_set_alias(jack_port_t
* port
, const char* name
)
660 #ifdef __CLIENTDEBUG__
661 JackGlobals::CheckContext("jack_port_set_alias");
663 #if defined(__x86_64__) || defined(__ppc64__)
664 uint64_t port_aux
= (uint64_t)port
;
666 uint32_t port_aux
= (uint32_t)port
;
668 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
669 if (!CheckPort(myport
)) {
670 jack_error("jack_port_set_alias called with an incorrect port %ld", myport
);
672 } else if (name
== NULL
) {
673 jack_error("jack_port_set_alias called with a NULL port name");
676 JackGraphManager
* manager
= GetGraphManager();
677 return (manager
? manager
->GetPort(myport
)->SetAlias(name
) : -1);
681 EXPORT
int jack_port_unset_alias(jack_port_t
* port
, const char* name
)
683 #ifdef __CLIENTDEBUG__
684 JackGlobals::CheckContext("jack_port_unset_alias");
686 #if defined(__x86_64__) || defined(__ppc64__)
687 uint64_t port_aux
= (uint64_t)port
;
689 uint32_t port_aux
= (uint32_t)port
;
691 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
692 if (!CheckPort(myport
)) {
693 jack_error("jack_port_unset_alias called with an incorrect port %ld", myport
);
695 } else if (name
== NULL
) {
696 jack_error("jack_port_unset_alias called with a NULL port name");
699 JackGraphManager
* manager
= GetGraphManager();
700 return (manager
? manager
->GetPort(myport
)->UnsetAlias(name
) : -1);
704 EXPORT
int jack_port_get_aliases(const jack_port_t
* port
, char* const aliases
[2])
706 #ifdef __CLIENTDEBUG__
707 JackGlobals::CheckContext("jack_port_get_aliases");
709 #if defined(__x86_64__) || defined(__ppc64__)
710 uint64_t port_aux
= (uint64_t)port
;
712 uint32_t port_aux
= (uint32_t)port
;
714 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
715 if (!CheckPort(myport
)) {
716 jack_error("jack_port_get_aliases called with an incorrect port %ld", myport
);
719 JackGraphManager
* manager
= GetGraphManager();
720 return (manager
? manager
->GetPort(myport
)->GetAliases(aliases
) : -1);
724 EXPORT
int jack_port_request_monitor(jack_port_t
* port
, int onoff
)
726 #ifdef __CLIENTDEBUG__
727 JackGlobals::CheckContext("jack_port_request_monitor");
729 #if defined(__x86_64__) || defined(__ppc64__)
730 uint64_t port_aux
= (uint64_t)port
;
732 uint32_t port_aux
= (uint32_t)port
;
734 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
735 if (!CheckPort(myport
)) {
736 jack_error("jack_port_request_monitor called with an incorrect port %ld", myport
);
739 JackGraphManager
* manager
= GetGraphManager();
740 return (manager
? manager
->RequestMonitor(myport
, onoff
) : -1);
744 EXPORT
int jack_port_request_monitor_by_name(jack_client_t
* ext_client
, const char* port_name
, int onoff
)
746 #ifdef __CLIENTDEBUG__
747 JackGlobals::CheckContext("jack_port_request_monitor_by_name");
749 JackClient
* client
= (JackClient
*)ext_client
;
750 if (client
== NULL
) {
751 jack_error("jack_port_request_monitor_by_name called with a NULL client");
754 JackGraphManager
* manager
= GetGraphManager();
757 jack_port_id_t myport
= manager
->GetPort(port_name
);
758 if (!CheckPort(myport
)) {
759 jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name
);
762 return manager
->RequestMonitor(myport
, onoff
);
767 EXPORT
int jack_port_ensure_monitor(jack_port_t
* port
, int onoff
)
769 #ifdef __CLIENTDEBUG__
770 JackGlobals::CheckContext("jack_port_ensure_monitor");
772 #if defined(__x86_64__) || defined(__ppc64__)
773 uint64_t port_aux
= (uint64_t)port
;
775 uint32_t port_aux
= (uint32_t)port
;
777 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
778 if (!CheckPort(myport
)) {
779 jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport
);
782 JackGraphManager
* manager
= GetGraphManager();
783 return (manager
? manager
->GetPort(myport
)->EnsureMonitor(onoff
) : -1);
787 EXPORT
int jack_port_monitoring_input(jack_port_t
* port
)
789 #ifdef __CLIENTDEBUG__
790 JackGlobals::CheckContext("jack_port_monitoring_input");
792 #if defined(__x86_64__) || defined(__ppc64__)
793 uint64_t port_aux
= (uint64_t)port
;
795 uint32_t port_aux
= (uint32_t)port
;
797 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
798 if (!CheckPort(myport
)) {
799 jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport
);
802 JackGraphManager
* manager
= GetGraphManager();
803 return (manager
? manager
->GetPort(myport
)->MonitoringInput() : -1);
807 EXPORT
int jack_is_realtime(jack_client_t
* ext_client
)
809 #ifdef __CLIENTDEBUG__
810 JackGlobals::CheckContext("jack_is_realtime");
812 JackClient
* client
= (JackClient
*)ext_client
;
813 if (client
== NULL
) {
814 jack_error("jack_is_realtime called with a NULL client");
817 JackEngineControl
* control
= GetEngineControl();
818 return (control
? control
->fRealTime
: -1);
822 EXPORT
void jack_on_shutdown(jack_client_t
* ext_client
, JackShutdownCallback callback
, void* arg
)
824 #ifdef __CLIENTDEBUG__
825 JackGlobals::CheckContext("jack_on_shutdown");
827 JackClient
* client
= (JackClient
*)ext_client
;
828 if (client
== NULL
) {
829 jack_error("jack_on_shutdown called with a NULL client");
831 client
->OnShutdown(callback
, arg
);
835 EXPORT
void jack_on_info_shutdown(jack_client_t
* ext_client
, JackInfoShutdownCallback callback
, void* arg
)
837 #ifdef __CLIENTDEBUG__
838 JackGlobals::CheckContext("jack_on_info_shutdown");
840 JackClient
* client
= (JackClient
*)ext_client
;
841 if (client
== NULL
) {
842 jack_error("jack_on_info_shutdown called with a NULL client");
844 client
->OnInfoShutdown(callback
, arg
);
848 EXPORT
int jack_set_process_callback(jack_client_t
* ext_client
, JackProcessCallback callback
, void* arg
)
850 #ifdef __CLIENTDEBUG__
851 JackGlobals::CheckContext("jack_set_process_callback");
853 JackClient
* client
= (JackClient
*)ext_client
;
854 if (client
== NULL
) {
855 jack_error("jack_set_process_callback called with a NULL client");
858 return client
->SetProcessCallback(callback
, arg
);
862 EXPORT jack_nframes_t
jack_thread_wait(jack_client_t
* ext_client
, int status
)
864 #ifdef __CLIENTDEBUG__
865 JackGlobals::CheckContext("jack_thread_wait");
867 JackClient
* client
= (JackClient
*)ext_client
;
868 if (client
== NULL
) {
869 jack_error("jack_thread_wait called with a NULL client");
872 jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
877 EXPORT jack_nframes_t
jack_cycle_wait(jack_client_t
* ext_client
)
879 #ifdef __CLIENTDEBUG__
880 JackGlobals::CheckContext("jack_cycle_wait");
882 JackClient
* client
= (JackClient
*)ext_client
;
883 if (client
== NULL
) {
884 jack_error("jack_cycle_wait called with a NULL client");
887 return client
->CycleWait();
891 EXPORT
void jack_cycle_signal(jack_client_t
* ext_client
, int status
)
893 #ifdef __CLIENTDEBUG__
894 JackGlobals::CheckContext("jack_cycle_signal");
896 JackClient
* client
= (JackClient
*)ext_client
;
897 if (client
== NULL
) {
898 jack_error("jack_cycle_signal called with a NULL client");
900 client
->CycleSignal(status
);
904 EXPORT
int jack_set_process_thread(jack_client_t
* ext_client
, JackThreadCallback fun
, void *arg
)
906 #ifdef __CLIENTDEBUG__
907 JackGlobals::CheckContext("jack_set_process_thread");
909 JackClient
* client
= (JackClient
*)ext_client
;
910 if (client
== NULL
) {
911 jack_error("jack_set_process_thread called with a NULL client");
914 return client
->SetProcessThread(fun
, arg
);
918 EXPORT
int jack_set_freewheel_callback(jack_client_t
* ext_client
, JackFreewheelCallback freewheel_callback
, void* arg
)
920 #ifdef __CLIENTDEBUG__
921 JackGlobals::CheckContext("jack_set_freewheel_callback");
923 JackClient
* client
= (JackClient
*)ext_client
;
924 if (client
== NULL
) {
925 jack_error("jack_set_freewheel_callback called with a NULL client");
928 return client
->SetFreewheelCallback(freewheel_callback
, arg
);
932 EXPORT
int jack_set_freewheel(jack_client_t
* ext_client
, int onoff
)
934 #ifdef __CLIENTDEBUG__
935 JackGlobals::CheckContext("jack_set_freewheel");
937 JackClient
* client
= (JackClient
*)ext_client
;
938 if (client
== NULL
) {
939 jack_error("jack_set_freewheel called with a NULL client");
942 return client
->SetFreeWheel(onoff
);
946 EXPORT
int jack_set_buffer_size(jack_client_t
* ext_client
, jack_nframes_t buffer_size
)
948 #ifdef __CLIENTDEBUG__
949 JackGlobals::CheckContext("jack_set_buffer_size");
951 JackClient
* client
= (JackClient
*)ext_client
;
952 if (client
== NULL
) {
953 jack_error("jack_set_buffer_size called with a NULL client");
955 } else if (!CheckBufferSize(buffer_size
)) {
958 return client
->SetBufferSize(buffer_size
);
962 EXPORT
int jack_set_buffer_size_callback(jack_client_t
* ext_client
, JackBufferSizeCallback bufsize_callback
, void* arg
)
964 #ifdef __CLIENTDEBUG__
965 JackGlobals::CheckContext("jack_set_buffer_size_callback");
967 JackClient
* client
= (JackClient
*)ext_client
;
968 if (client
== NULL
) {
969 jack_error("jack_set_buffer_size_callback called with a NULL client");
972 return client
->SetBufferSizeCallback(bufsize_callback
, arg
);
976 EXPORT
int jack_set_sample_rate_callback(jack_client_t
* ext_client
, JackSampleRateCallback srate_callback
, void* arg
)
978 #ifdef __CLIENTDEBUG__
979 JackGlobals::CheckContext("jack_set_sample_rate_callback");
981 JackClient
* client
= (JackClient
*)ext_client
;
982 if (client
== NULL
) {
983 jack_error("jack_set_sample_rate_callback called with a NULL client");
986 return client
->SetSampleRateCallback(srate_callback
, arg
);
990 EXPORT
int jack_set_client_registration_callback(jack_client_t
* ext_client
, JackClientRegistrationCallback registration_callback
, void* arg
)
992 #ifdef __CLIENTDEBUG__
993 JackGlobals::CheckContext("jack_set_client_registration_callback");
995 JackClient
* client
= (JackClient
*)ext_client
;
996 if (client
== NULL
) {
997 jack_error("jack_set_client_registration_callback called with a NULL client");
1000 return client
->SetClientRegistrationCallback(registration_callback
, arg
);
1004 EXPORT
int jack_set_port_registration_callback(jack_client_t
* ext_client
, JackPortRegistrationCallback registration_callback
, void* arg
)
1006 #ifdef __CLIENTDEBUG__
1007 JackGlobals::CheckContext("jack_set_port_registration_callback");
1009 JackClient
* client
= (JackClient
*)ext_client
;
1010 if (client
== NULL
) {
1011 jack_error("jack_set_port_registration_callback called with a NULL client");
1014 return client
->SetPortRegistrationCallback(registration_callback
, arg
);
1018 EXPORT
int jack_set_port_connect_callback(jack_client_t
* ext_client
, JackPortConnectCallback portconnect_callback
, void* arg
)
1020 #ifdef __CLIENTDEBUG__
1021 JackGlobals::CheckContext("jack_set_port_connect_callback");
1023 JackClient
* client
= (JackClient
*)ext_client
;
1024 if (client
== NULL
) {
1025 jack_error("jack_set_port_connect_callback called with a NULL client");
1028 return client
->SetPortConnectCallback(portconnect_callback
, arg
);
1032 EXPORT
int jack_set_port_rename_callback(jack_client_t
* ext_client
, JackPortRenameCallback rename_callback
, void* arg
)
1034 #ifdef __CLIENTDEBUG__
1035 JackGlobals::CheckContext("jack_set_port_rename_callback");
1037 JackClient
* client
= (JackClient
*)ext_client
;
1038 if (client
== NULL
) {
1039 jack_error("jack_set_port_rename_callback called with a NULL client");
1042 return client
->SetPortRenameCallback(rename_callback
, arg
);
1046 EXPORT
int jack_set_graph_order_callback(jack_client_t
* ext_client
, JackGraphOrderCallback graph_callback
, void* arg
)
1048 #ifdef __CLIENTDEBUG__
1049 JackGlobals::CheckContext("jack_set_graph_order_callback");
1051 JackClient
* client
= (JackClient
*)ext_client
;
1052 jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client
, client
);
1053 if (client
== NULL
) {
1054 jack_error("jack_set_graph_order_callback called with a NULL client");
1057 return client
->SetGraphOrderCallback(graph_callback
, arg
);
1061 EXPORT
int jack_set_xrun_callback(jack_client_t
* ext_client
, JackXRunCallback xrun_callback
, void* arg
)
1063 #ifdef __CLIENTDEBUG__
1064 JackGlobals::CheckContext("jack_set_xrun_callback");
1066 JackClient
* client
= (JackClient
*)ext_client
;
1067 if (client
== NULL
) {
1068 jack_error("jack_set_xrun_callback called with a NULL client");
1071 return client
->SetXRunCallback(xrun_callback
, arg
);
1075 EXPORT
int jack_set_thread_init_callback(jack_client_t
* ext_client
, JackThreadInitCallback init_callback
, void *arg
)
1077 #ifdef __CLIENTDEBUG__
1078 JackGlobals::CheckContext("jack_set_thread_init_callback");
1080 JackClient
* client
= (JackClient
*)ext_client
;
1081 jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client
, client
);
1082 if (client
== NULL
) {
1083 jack_error("jack_set_thread_init_callback called with a NULL client");
1086 return client
->SetInitCallback(init_callback
, arg
);
1090 EXPORT
int jack_activate(jack_client_t
* ext_client
)
1092 #ifdef __CLIENTDEBUG__
1093 JackGlobals::CheckContext("jack_activate");
1095 JackClient
* client
= (JackClient
*)ext_client
;
1096 if (client
== NULL
) {
1097 jack_error("jack_activate called with a NULL client");
1100 return client
->Activate();
1104 EXPORT
int jack_deactivate(jack_client_t
* ext_client
)
1106 #ifdef __CLIENTDEBUG__
1107 JackGlobals::CheckContext("jack_deactivate");
1109 JackClient
* client
= (JackClient
*)ext_client
;
1110 if (client
== NULL
) {
1111 jack_error("jack_deactivate called with a NULL client");
1114 return client
->Deactivate();
1118 EXPORT jack_port_t
* jack_port_register(jack_client_t
* ext_client
, const char* port_name
, const char* port_type
, unsigned long flags
, unsigned long buffer_size
)
1120 #ifdef __CLIENTDEBUG__
1121 JackGlobals::CheckContext("jack_port_register");
1123 JackClient
* client
= (JackClient
*)ext_client
;
1124 if (client
== NULL
) {
1125 jack_error("jack_port_register called with a NULL client");
1127 } else if ((port_name
== NULL
) || (port_type
== NULL
)) {
1128 jack_error("jack_port_register called with a NULL port name or a NULL port_type");
1131 #if defined(__x86_64__) || defined(__ppc64__)
1132 return (jack_port_t
*)((uint64_t)client
->PortRegister(port_name
, port_type
, flags
, buffer_size
));
1134 return (jack_port_t
*)client
->PortRegister(port_name
, port_type
, flags
, buffer_size
);
1139 EXPORT
int jack_port_unregister(jack_client_t
* ext_client
, jack_port_t
* port
)
1141 #ifdef __CLIENTDEBUG__
1142 JackGlobals::CheckContext("jack_port_unregister");
1144 JackClient
* client
= (JackClient
*)ext_client
;
1145 if (client
== NULL
) {
1146 jack_error("jack_port_unregister called with a NULL client");
1149 #if defined(__x86_64__) || defined(__ppc64__)
1150 uint64_t port_aux
= (uint64_t)port
;
1152 uint32_t port_aux
= (uint32_t)port
;
1154 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1155 if (!CheckPort(myport
)) {
1156 jack_error("jack_port_unregister called with an incorrect port %ld", myport
);
1159 return client
->PortUnRegister(myport
);
1162 EXPORT
int jack_port_is_mine(const jack_client_t
* ext_client
, const jack_port_t
* port
)
1164 #ifdef __CLIENTDEBUG__
1165 JackGlobals::CheckContext("jack_port_is_mine");
1167 JackClient
* client
= (JackClient
*)ext_client
;
1168 if (client
== NULL
) {
1169 jack_error("jack_port_is_mine called with a NULL client");
1172 #if defined(__x86_64__) || defined(__ppc64__)
1173 uint64_t port_aux
= (uint64_t)port
;
1175 uint32_t port_aux
= (uint32_t)port
;
1177 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1178 if (!CheckPort(myport
)) {
1179 jack_error("jack_port_is_mine called with an incorrect port %ld", myport
);
1182 return client
->PortIsMine(myport
);
1185 EXPORT
const char** jack_port_get_connections(const jack_port_t
* port
)
1187 #ifdef __CLIENTDEBUG__
1188 JackGlobals::CheckContext("jack_port_get_connections");
1190 #if defined(__x86_64__) || defined(__ppc64__)
1191 uint64_t port_aux
= (uint64_t)port
;
1193 uint32_t port_aux
= (uint32_t)port
;
1195 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1196 if (!CheckPort(myport
)) {
1197 jack_error("jack_port_get_connections called with an incorrect port %ld", myport
);
1201 JackGraphManager
* manager
= GetGraphManager();
1202 return (manager
? manager
->GetConnections(myport
) : NULL
);
1206 // Calling client does not need to "own" the port
1207 EXPORT
const char** jack_port_get_all_connections(const jack_client_t
* ext_client
, const jack_port_t
* port
)
1209 #ifdef __CLIENTDEBUG__
1210 JackGlobals::CheckContext("jack_port_get_all_connections");
1212 JackClient
* client
= (JackClient
*)ext_client
;
1213 if (client
== NULL
) {
1214 jack_error("jack_port_get_all_connections called with a NULL client");
1218 #if defined(__x86_64__) || defined(__ppc64__)
1219 uint64_t port_aux
= (uint64_t)port
;
1221 uint32_t port_aux
= (uint32_t)port
;
1223 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1224 if (!CheckPort(myport
)) {
1225 jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport
);
1229 JackGraphManager
* manager
= GetGraphManager();
1230 return (manager
? manager
->GetConnections(myport
) : NULL
);
1234 EXPORT jack_nframes_t
jack_port_get_total_latency(jack_client_t
* ext_client
, jack_port_t
* port
)
1236 #ifdef __CLIENTDEBUG__
1237 JackGlobals::CheckContext("jack_port_get_total_latency");
1239 JackClient
* client
= (JackClient
*)ext_client
;
1240 if (client
== NULL
) {
1241 jack_error("jack_port_get_total_latency called with a NULL client");
1245 #if defined(__x86_64__) || defined(__ppc64__)
1246 uint64_t port_aux
= (uint64_t)port
;
1248 uint32_t port_aux
= (uint32_t)port
;
1250 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1251 if (!CheckPort(myport
)) {
1252 jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport
);
1256 JackGraphManager
* manager
= GetGraphManager();
1258 manager
->ComputeTotalLatency(myport
);
1259 return manager
->GetPort(myport
)->GetTotalLatency();
1266 EXPORT
int jack_connect(jack_client_t
* ext_client
, const char* src
, const char* dst
)
1268 #ifdef __CLIENTDEBUG__
1269 JackGlobals::CheckContext("jack_connect");
1271 JackClient
* client
= (JackClient
*)ext_client
;
1272 if (client
== NULL
) {
1273 jack_error("jack_connect called with a NULL client");
1275 } else if ((src
== NULL
) || (dst
== NULL
)) {
1276 jack_error("jack_connect called with a NULL port name");
1279 return client
->PortConnect(src
, dst
);
1283 EXPORT
int jack_disconnect(jack_client_t
* ext_client
, const char* src
, const char* dst
)
1285 #ifdef __CLIENTDEBUG__
1286 JackGlobals::CheckContext("jack_disconnect");
1288 JackClient
* client
= (JackClient
*)ext_client
;
1289 if (client
== NULL
) {
1290 jack_error("jack_disconnect called with a NULL client");
1292 } else if ((src
== NULL
) || (dst
== NULL
)) {
1293 jack_error("jack_connect called with a NULL port name");
1296 return client
->PortDisconnect(src
, dst
);
1300 EXPORT
int jack_port_disconnect(jack_client_t
* ext_client
, jack_port_t
* src
)
1302 #ifdef __CLIENTDEBUG__
1303 JackGlobals::CheckContext("jack_port_disconnect");
1305 JackClient
* client
= (JackClient
*)ext_client
;
1306 if (client
== NULL
) {
1307 jack_error("jack_port_disconnect called with a NULL client");
1310 #if defined(__x86_64__) || defined(__ppc64__)
1311 uint64_t port_aux
= (uint64_t)src
;
1313 uint32_t port_aux
= (uint32_t)src
;
1315 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1316 if (!CheckPort(myport
)) {
1317 jack_error("jack_port_disconnect called with an incorrect port %ld", myport
);
1320 return client
->PortDisconnect(myport
);
1323 EXPORT jack_nframes_t
jack_get_sample_rate(jack_client_t
* ext_client
)
1325 #ifdef __CLIENTDEBUG__
1326 JackGlobals::CheckContext("jack_get_sample_rate");
1328 JackClient
* client
= (JackClient
*)ext_client
;
1329 if (client
== NULL
) {
1330 jack_error("jack_get_sample_rate called with a NULL client");
1333 JackEngineControl
* control
= GetEngineControl();
1334 return (control
? control
->fSampleRate
: 0);
1338 EXPORT jack_nframes_t
jack_get_buffer_size(jack_client_t
* ext_client
)
1340 #ifdef __CLIENTDEBUG__
1341 JackGlobals::CheckContext("jack_get_buffer_size");
1343 JackClient
* client
= (JackClient
*)ext_client
;
1344 if (client
== NULL
) {
1345 jack_error("jack_get_buffer_size called with a NULL client");
1348 JackEngineControl
* control
= GetEngineControl();
1349 return (control
? control
->fBufferSize
: 0);
1353 EXPORT
const char** jack_get_ports(jack_client_t
* ext_client
, const char* port_name_pattern
, const char* type_name_pattern
, unsigned long flags
)
1355 #ifdef __CLIENTDEBUG__
1356 JackGlobals::CheckContext("jack_get_ports");
1358 JackClient
* client
= (JackClient
*)ext_client
;
1359 if (client
== NULL
) {
1360 jack_error("jack_get_ports called with a NULL client");
1363 JackGraphManager
* manager
= GetGraphManager();
1364 return (manager
? manager
->GetPorts(port_name_pattern
, type_name_pattern
, flags
) : NULL
);
1367 EXPORT jack_port_t
* jack_port_by_name(jack_client_t
* ext_client
, const char* portname
)
1369 #ifdef __CLIENTDEBUG__
1370 JackGlobals::CheckContext("jack_port_by_name");
1372 JackClient
* client
= (JackClient
*)ext_client
;
1373 if (client
== NULL
) {
1374 jack_error("jack_get_ports called with a NULL client");
1378 if (portname
== NULL
) {
1379 jack_error("jack_port_by_name called with a NULL port name");
1382 JackGraphManager
* manager
= GetGraphManager();
1385 int res
= manager
->GetPort(portname
); // returns a port index at least > 1
1386 #if defined(__x86_64__) || defined(__ppc64__)
1387 return (res
== NO_PORT
) ? NULL
: (jack_port_t
*)((uint64_t)res
);
1389 return (res
== NO_PORT
) ? NULL
: (jack_port_t
*)res
;
1394 EXPORT jack_port_t
* jack_port_by_id(jack_client_t
* ext_client
, jack_port_id_t id
)
1396 #ifdef __CLIENTDEBUG__
1397 JackGlobals::CheckContext("jack_port_by_id");
1399 /* jack_port_t* type is actually the port index */
1400 #if defined(__x86_64__) || defined(__ppc64__)
1401 return (jack_port_t
*)((uint64_t)id
);
1403 return (jack_port_t
*)id
;
1407 EXPORT
int jack_engine_takeover_timebase(jack_client_t
* ext_client
)
1409 #ifdef __CLIENTDEBUG__
1410 JackGlobals::CheckContext("jack_engine_takeover_timebase");
1412 JackClient
* client
= (JackClient
*)ext_client
;
1413 if (client
== NULL
) {
1414 jack_error("jack_engine_takeover_timebase called with a NULL client");
1417 jack_error("jack_engine_takeover_timebase: deprecated\n");
1422 EXPORT jack_nframes_t
jack_frames_since_cycle_start(const jack_client_t
* ext_client
)
1424 #ifdef __CLIENTDEBUG__
1425 JackGlobals::CheckContext("jack_frames_since_cycle_start");
1428 JackEngineControl
* control
= GetEngineControl();
1430 control
->ReadFrameTime(&timer
);
1431 return timer
.FramesSinceCycleStart(GetMicroSeconds(), control
->fSampleRate
);
1437 EXPORT jack_time_t
jack_get_time()
1439 #ifdef __CLIENTDEBUG__
1440 JackGlobals::CheckContext("jack_get_time");
1442 return GetMicroSeconds();
1445 EXPORT jack_time_t
jack_frames_to_time(const jack_client_t
* ext_client
, jack_nframes_t frames
)
1447 #ifdef __CLIENTDEBUG__
1448 JackGlobals::CheckContext("jack_frames_to_time");
1450 JackClient
* client
= (JackClient
*)ext_client
;
1451 if (client
== NULL
) {
1452 jack_error("jack_frames_to_time called with a NULL client");
1456 JackEngineControl
* control
= GetEngineControl();
1458 control
->ReadFrameTime(&timer
);
1459 return timer
.Frames2Time(frames
, control
->fBufferSize
);
1466 EXPORT jack_nframes_t
jack_time_to_frames(const jack_client_t
* ext_client
, jack_time_t time
)
1468 #ifdef __CLIENTDEBUG__
1469 JackGlobals::CheckContext("jack_time_to_frames");
1471 JackClient
* client
= (JackClient
*)ext_client
;
1472 if (client
== NULL
) {
1473 jack_error("jack_time_to_frames called with a NULL client");
1477 JackEngineControl
* control
= GetEngineControl();
1479 control
->ReadFrameTime(&timer
);
1480 return timer
.Time2Frames(time
, control
->fBufferSize
);
1487 EXPORT jack_nframes_t
jack_frame_time(const jack_client_t
* ext_client
)
1489 #ifdef __CLIENTDEBUG__
1490 JackGlobals::CheckContext("jack_frame_time");
1492 return jack_time_to_frames(ext_client
, GetMicroSeconds());
1495 EXPORT jack_nframes_t
jack_last_frame_time(const jack_client_t
* ext_client
)
1497 #ifdef __CLIENTDEBUG__
1498 JackGlobals::CheckContext("jack_last_frame_time");
1500 JackEngineControl
* control
= GetEngineControl();
1501 return (control
) ? control
->fFrameTimer
.ReadCurrentState()->CurFrame() : 0;
1504 EXPORT
float jack_cpu_load(jack_client_t
* ext_client
)
1506 #ifdef __CLIENTDEBUG__
1507 JackGlobals::CheckContext("jack_cpu_load");
1509 JackClient
* client
= (JackClient
*)ext_client
;
1510 if (client
== NULL
) {
1511 jack_error("jack_cpu_load called with a NULL client");
1514 JackEngineControl
* control
= GetEngineControl();
1515 return (control
? control
->fCPULoad
: 0.0f
);
1519 EXPORT pthread_t
jack_client_thread_id(jack_client_t
* ext_client
)
1521 #ifdef __CLIENTDEBUG__
1522 JackGlobals::CheckContext("jack_client_thread_id");
1524 JackClient
* client
= (JackClient
*)ext_client
;
1525 if (client
== NULL
) {
1526 jack_error("jack_client_thread_id called with a NULL client");
1527 return (pthread_t
)NULL
;
1529 return client
->GetThreadID();
1533 EXPORT
char* jack_get_client_name(jack_client_t
* ext_client
)
1535 #ifdef __CLIENTDEBUG__
1536 JackGlobals::CheckContext("jack_get_client_name");
1538 JackClient
* client
= (JackClient
*)ext_client
;
1539 if (client
== NULL
) {
1540 jack_error("jack_get_client_name called with a NULL client");
1543 return client
->GetClientControl()->fName
;
1547 EXPORT
int jack_client_name_size(void)
1549 return JACK_CLIENT_NAME_SIZE
;
1552 EXPORT
int jack_port_name_size(void)
1554 return JACK_PORT_NAME_SIZE
;
1557 EXPORT
int jack_port_type_size(void)
1559 return JACK_PORT_TYPE_SIZE
;
1563 EXPORT
int jack_release_timebase(jack_client_t
* ext_client
)
1565 #ifdef __CLIENTDEBUG__
1566 JackGlobals::CheckContext("jack_release_timebase");
1568 JackClient
* client
= (JackClient
*)ext_client
;
1569 if (client
== NULL
) {
1570 jack_error("jack_release_timebase called with a NULL client");
1573 return client
->ReleaseTimebase();
1577 EXPORT
int jack_set_sync_callback(jack_client_t
* ext_client
, JackSyncCallback sync_callback
, void *arg
)
1579 #ifdef __CLIENTDEBUG__
1580 JackGlobals::CheckContext("jack_set_sync_callback");
1582 JackClient
* client
= (JackClient
*)ext_client
;
1583 if (client
== NULL
) {
1584 jack_error("jack_set_sync_callback called with a NULL client");
1587 return client
->SetSyncCallback(sync_callback
, arg
);
1591 EXPORT
int jack_set_sync_timeout(jack_client_t
* ext_client
, jack_time_t timeout
)
1593 #ifdef __CLIENTDEBUG__
1594 JackGlobals::CheckContext("jack_set_sync_timeout");
1596 JackClient
* client
= (JackClient
*)ext_client
;
1597 if (client
== NULL
) {
1598 jack_error("jack_set_sync_timeout called with a NULL client");
1601 return client
->SetSyncTimeout(timeout
);
1605 EXPORT
int jack_set_timebase_callback(jack_client_t
* ext_client
, int conditional
, JackTimebaseCallback timebase_callback
, void* arg
)
1607 #ifdef __CLIENTDEBUG__
1608 JackGlobals::CheckContext("jack_set_timebase_callback");
1610 JackClient
* client
= (JackClient
*)ext_client
;
1611 if (client
== NULL
) {
1612 jack_error("jack_set_timebase_callback called with a NULL client");
1615 return client
->SetTimebaseCallback(conditional
, timebase_callback
, arg
);
1619 EXPORT
int jack_transport_locate(jack_client_t
* ext_client
, jack_nframes_t frame
)
1621 #ifdef __CLIENTDEBUG__
1622 JackGlobals::CheckContext("jack_transport_locate");
1624 JackClient
* client
= (JackClient
*)ext_client
;
1625 if (client
== NULL
) {
1626 jack_error("jack_transport_locate called with a NULL client");
1629 client
->TransportLocate(frame
);
1634 EXPORT jack_transport_state_t
jack_transport_query(const jack_client_t
* ext_client
, jack_position_t
* pos
)
1636 #ifdef __CLIENTDEBUG__
1637 JackGlobals::CheckContext("jack_transport_query");
1639 JackClient
* client
= (JackClient
*)ext_client
;
1640 if (client
== NULL
) {
1641 jack_error("jack_transport_query called with a NULL client");
1642 return JackTransportStopped
;
1644 return client
->TransportQuery(pos
);
1648 EXPORT jack_nframes_t
jack_get_current_transport_frame(const jack_client_t
* ext_client
)
1650 #ifdef __CLIENTDEBUG__
1651 JackGlobals::CheckContext("jack_get_current_transport_frame");
1653 JackClient
* client
= (JackClient
*)ext_client
;
1654 if (client
== NULL
) {
1655 jack_error("jack_get_current_transport_frame called with a NULL client");
1658 return client
->GetCurrentTransportFrame();
1662 EXPORT
int jack_transport_reposition(jack_client_t
* ext_client
, jack_position_t
* pos
)
1664 #ifdef __CLIENTDEBUG__
1665 JackGlobals::CheckContext("jack_transport_reposition");
1667 JackClient
* client
= (JackClient
*)ext_client
;
1668 if (client
== NULL
) {
1669 jack_error("jack_transport_reposition called with a NULL client");
1672 client
->TransportReposition(pos
);
1677 EXPORT
void jack_transport_start(jack_client_t
* ext_client
)
1679 #ifdef __CLIENTDEBUG__
1680 JackGlobals::CheckContext("jack_transport_start");
1682 JackClient
* client
= (JackClient
*)ext_client
;
1683 if (client
== NULL
) {
1684 jack_error("jack_transport_start called with a NULL client");
1686 client
->TransportStart();
1690 EXPORT
void jack_transport_stop(jack_client_t
* ext_client
)
1692 #ifdef __CLIENTDEBUG__
1693 JackGlobals::CheckContext("jack_transport_stop");
1695 JackClient
* client
= (JackClient
*)ext_client
;
1696 if (client
== NULL
) {
1697 jack_error("jack_transport_stop called with a NULL client");
1699 client
->TransportStop();
1704 EXPORT
void jack_get_transport_info(jack_client_t
* ext_client
, jack_transport_info_t
* tinfo
)
1706 #ifdef __CLIENTDEBUG__
1707 JackGlobals::CheckContext("jack_get_transport_info");
1709 jack_error("jack_get_transport_info: deprecated");
1711 memset(tinfo
, 0, sizeof(jack_transport_info_t
));
1714 EXPORT
void jack_set_transport_info(jack_client_t
* ext_client
, jack_transport_info_t
* tinfo
)
1716 #ifdef __CLIENTDEBUG__
1717 JackGlobals::CheckContext("jack_set_transport_info");
1719 jack_error("jack_set_transport_info: deprecated");
1721 memset(tinfo
, 0, sizeof(jack_transport_info_t
));
1725 EXPORT
float jack_get_max_delayed_usecs(jack_client_t
* ext_client
)
1727 #ifdef __CLIENTDEBUG__
1728 JackGlobals::CheckContext("jack_get_max_delayed_usecs");
1730 JackClient
* client
= (JackClient
*)ext_client
;
1731 if (client
== NULL
) {
1732 jack_error("jack_get_max_delayed_usecs called with a NULL client");
1735 JackEngineControl
* control
= GetEngineControl();
1736 return (control
? control
->fMaxDelayedUsecs
: 0.f
);
1740 EXPORT
float jack_get_xrun_delayed_usecs(jack_client_t
* ext_client
)
1742 #ifdef __CLIENTDEBUG__
1743 JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
1745 JackClient
* client
= (JackClient
*)ext_client
;
1746 if (client
== NULL
) {
1747 jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
1750 JackEngineControl
* control
= GetEngineControl();
1751 return (control
? control
->fXrunDelayedUsecs
: 0.f
);
1755 EXPORT
void jack_reset_max_delayed_usecs(jack_client_t
* ext_client
)
1757 #ifdef __CLIENTDEBUG__
1758 JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
1760 JackClient
* client
= (JackClient
*)ext_client
;
1761 if (client
== NULL
) {
1762 jack_error("jack_reset_max_delayed_usecs called with a NULL client");
1764 JackEngineControl
* control
= GetEngineControl();
1765 control
->ResetXRun();
1770 EXPORT
int jack_client_real_time_priority(jack_client_t
* ext_client
)
1772 #ifdef __CLIENTDEBUG__
1773 JackGlobals::CheckContext("jack_client_real_time_priority");
1775 JackClient
* client
= (JackClient
*)ext_client
;
1776 if (client
== NULL
) {
1777 jack_error("jack_client_real_time_priority called with a NULL client");
1780 JackEngineControl
* control
= GetEngineControl();
1781 return (control
->fRealTime
) ? control
->fClientPriority
: -1;
1785 EXPORT
int jack_client_max_real_time_priority(jack_client_t
* ext_client
)
1787 #ifdef __CLIENTDEBUG__
1788 JackGlobals::CheckContext("jack_client_max_real_time_priority");
1790 JackClient
* client
= (JackClient
*)ext_client
;
1791 if (client
== NULL
) {
1792 jack_error("jack_client_max_real_time_priority called with a NULL client");
1795 JackEngineControl
* control
= GetEngineControl();
1796 return (control
->fRealTime
) ? control
->fMaxClientPriority
: -1;
1800 EXPORT
int jack_acquire_real_time_scheduling(pthread_t thread
, int priority
)
1802 JackEngineControl
* control
= GetEngineControl();
1803 return (control
? JackThread::AcquireRealTimeImp(thread
, priority
, GetEngineControl()->fPeriod
, GetEngineControl()->fComputation
, GetEngineControl()->fConstraint
) : -1);
1806 EXPORT
int jack_client_create_thread(jack_client_t
* client
,
1809 int realtime
, /* boolean */
1810 thread_routine routine
,
1813 #ifdef __CLIENTDEBUG__
1814 JackGlobals::CheckContext("jack_client_create_thread");
1816 return JackThread::StartImp(thread
, priority
, realtime
, routine
, arg
);
1819 EXPORT
int jack_drop_real_time_scheduling(pthread_t thread
)
1821 return JackThread::DropRealTimeImp(thread
);
1824 EXPORT
int jack_client_stop_thread(jack_client_t
* client
, pthread_t thread
)
1826 #ifdef __CLIENTDEBUG__
1827 JackGlobals::CheckContext("jack_client_stop_thread");
1829 return JackThread::StopImp(thread
);
1832 EXPORT
int jack_client_kill_thread(jack_client_t
* client
, pthread_t thread
)
1834 #ifdef __CLIENTDEBUG__
1835 JackGlobals::CheckContext("jack_client_kill_thread");
1837 return JackThread::KillImp(thread
);
1841 EXPORT
void jack_set_thread_creator (jack_thread_creator_t jtc
)
1843 JackGlobals::fJackThreadCreator
= (jtc
== NULL
) ? pthread_create
: jtc
;
1848 EXPORT
int jack_internal_client_new (const char *client_name
,
1849 const char *load_name
,
1850 const char *load_init
)
1852 jack_error("jack_internal_client_new: deprecated");
1856 EXPORT
void jack_internal_client_close (const char *client_name
)
1858 jack_error("jack_internal_client_close: deprecated");
1861 EXPORT
char* jack_get_internal_client_name(jack_client_t
* ext_client
, jack_intclient_t intclient
)
1863 #ifdef __CLIENTDEBUG__
1864 JackGlobals::CheckContext("jack_get_internal_client_name");
1866 JackClient
* client
= (JackClient
*)ext_client
;
1867 if (client
== NULL
) {
1868 jack_error("jack_get_internal_client_name called with a NULL client");
1870 } else if (intclient
>= CLIENT_NUM
) {
1871 jack_error("jack_get_internal_client_name: incorrect client");
1874 return client
->GetInternalClientName(intclient
);
1878 EXPORT jack_intclient_t
jack_internal_client_handle(jack_client_t
* ext_client
, const char* client_name
, jack_status_t
* status
)
1880 #ifdef __CLIENTDEBUG__
1881 JackGlobals::CheckContext("jack_internal_client_handle");
1883 JackClient
* client
= (JackClient
*)ext_client
;
1884 if (client
== NULL
) {
1885 jack_error("jack_internal_client_handle called with a NULL client");
1888 jack_status_t my_status
;
1889 if (status
== NULL
) /* no status from caller? */
1890 status
= &my_status
; /* use local status word */
1891 *status
= (jack_status_t
)0;
1892 return client
->InternalClientHandle(client_name
, status
);
1896 EXPORT jack_intclient_t
jack_internal_client_load_aux(jack_client_t
* ext_client
, const char* client_name
, jack_options_t options
, jack_status_t
* status
, va_list ap
)
1898 #ifdef __CLIENTDEBUG__
1899 JackGlobals::CheckContext("jack_internal_client_load_aux");
1901 JackClient
* client
= (JackClient
*)ext_client
;
1902 if (client
== NULL
) {
1903 jack_error("jack_internal_client_load called with a NULL client");
1907 jack_status_t my_status
;
1909 if (status
== NULL
) /* no status from caller? */
1910 status
= &my_status
; /* use local status word */
1911 *status
= (jack_status_t
)0;
1913 /* validate parameters */
1914 if ((options
& ~JackLoadOptions
)) {
1915 int my_status1
= *status
| (JackFailure
| JackInvalidOption
);
1916 *status
= (jack_status_t
)my_status1
;
1920 /* parse variable arguments */
1921 jack_varargs_parse(options
, ap
, &va
);
1922 return client
->InternalClientLoad(client_name
, options
, status
, &va
);
1926 EXPORT jack_intclient_t
jack_internal_client_load(jack_client_t
*client
, const char *client_name
, jack_options_t options
, jack_status_t
*status
, ...)
1929 va_start(ap
, status
);
1930 jack_intclient_t res
= jack_internal_client_load_aux(client
, client_name
, options
, status
, ap
);
1935 EXPORT jack_status_t
jack_internal_client_unload(jack_client_t
* ext_client
, jack_intclient_t intclient
)
1937 #ifdef __CLIENTDEBUG__
1938 JackGlobals::CheckContext("jack_internal_client_load");
1940 JackClient
* client
= (JackClient
*)ext_client
;
1941 if (client
== NULL
) {
1942 jack_error("jack_internal_client_unload called with a NULL client");
1943 return (jack_status_t
)(JackNoSuchClient
| JackFailure
);
1944 } else if (intclient
>= CLIENT_NUM
) {
1945 jack_error("jack_internal_client_unload: incorrect client");
1946 return (jack_status_t
)(JackNoSuchClient
| JackFailure
);
1948 jack_status_t my_status
;
1949 client
->InternalClientUnload(intclient
, &my_status
);
1962 // FIXME: We need these comming from build system
1971 jack_get_version_string()
1976 EXPORT
void jack_free(void* ptr
)