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 uintptr_t port_aux
= (uintptr_t)port
;
321 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
322 if (!CheckPort(myport
)) {
323 jack_error("jack_port_get_buffer called with an incorrect port %ld", myport
);
326 JackGraphManager
* manager
= GetGraphManager();
327 return (manager
? manager
->GetBuffer(myport
, frames
) : NULL
);
331 EXPORT
const char* jack_port_name(const jack_port_t
* port
)
333 #ifdef __CLIENTDEBUG__
334 JackGlobals::CheckContext("jack_port_name");
336 uintptr_t port_aux
= (uintptr_t)port
;
337 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
338 if (!CheckPort(myport
)) {
339 jack_error("jack_port_name called with an incorrect port %ld", myport
);
342 JackGraphManager
* manager
= GetGraphManager();
343 return (manager
? manager
->GetPort(myport
)->GetName() : NULL
);
347 EXPORT
const char* jack_port_short_name(const jack_port_t
* port
)
349 #ifdef __CLIENTDEBUG__
350 JackGlobals::CheckContext("jack_port_short_name");
352 uintptr_t port_aux
= (uintptr_t)port
;
353 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
354 if (!CheckPort(myport
)) {
355 jack_error("jack_port_short_name called with an incorrect port %ld", myport
);
358 JackGraphManager
* manager
= GetGraphManager();
359 return (manager
? manager
->GetPort(myport
)->GetShortName() : NULL
);
363 EXPORT
int jack_port_flags(const jack_port_t
* port
)
365 #ifdef __CLIENTDEBUG__
366 JackGlobals::CheckContext("jack_port_flags");
368 uintptr_t port_aux
= (uintptr_t)port
;
369 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
370 if (!CheckPort(myport
)) {
371 jack_error("jack_port_flags called with an incorrect port %ld", myport
);
374 JackGraphManager
* manager
= GetGraphManager();
375 return (manager
? manager
->GetPort(myport
)->GetFlags() : -1);
379 EXPORT
const char* jack_port_type(const jack_port_t
* port
)
381 #ifdef __CLIENTDEBUG__
382 JackGlobals::CheckContext("jack_port_type");
384 uintptr_t port_aux
= (uintptr_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 an incorrect port %ld", myport
);
390 JackGraphManager
* manager
= GetGraphManager();
391 return (manager
? manager
->GetPort(myport
)->GetType() : NULL
);
395 EXPORT jack_port_type_id_t
jack_port_type_id(const jack_port_t
*port
)
397 #ifdef __CLIENTDEBUG__
398 JackGlobals::CheckContext("jack_port_type_id");
400 uintptr_t port_aux
= (uintptr_t)port
;
401 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
402 if (!CheckPort(myport
)) {
403 jack_error("jack_port_type_id called an incorrect port %ld", myport
);
406 JackGraphManager
* manager
= GetGraphManager();
407 return (manager
? GetPortTypeId(manager
->GetPort(myport
)->GetType()) : 0);
411 EXPORT
int jack_port_connected(const jack_port_t
* port
)
413 #ifdef __CLIENTDEBUG__
414 JackGlobals::CheckContext("jack_port_connected");
416 uintptr_t port_aux
= (uintptr_t)port
;
417 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
418 if (!CheckPort(myport
)) {
419 jack_error("jack_port_connected called with an incorrect port %ld", myport
);
423 JackGraphManager
* manager
= GetGraphManager();
424 return (manager
? manager
->GetConnectionsNum(myport
) : -1);
428 EXPORT
int jack_port_connected_to(const jack_port_t
* port
, const char* port_name
)
430 #ifdef __CLIENTDEBUG__
431 JackGlobals::CheckContext("jack_port_connected_to");
433 uintptr_t port_aux
= (uintptr_t)port
;
434 jack_port_id_t src
= (jack_port_id_t
)port_aux
;
435 if (!CheckPort(src
)) {
436 jack_error("jack_port_connected_to called with an incorrect port %ld", src
);
438 } else if (port_name
== NULL
) {
439 jack_error("jack_port_connected_to called with a NULL port name");
443 JackGraphManager
* manager
= GetGraphManager();
444 jack_port_id_t dst
= (manager
? manager
->GetPort(port_name
) : NO_PORT
);
445 if (dst
== NO_PORT
) {
446 jack_error("Unknown destination port port_name = %s", port_name
);
449 return manager
->IsConnected(src
, dst
);
454 EXPORT
int jack_port_tie(jack_port_t
* src
, jack_port_t
* dst
)
456 #ifdef __CLIENTDEBUG__
457 JackGlobals::CheckContext("jack_port_tie");
459 uintptr_t src_aux
= (uintptr_t)src
;
460 jack_port_id_t mysrc
= (jack_port_id_t
)src_aux
;
461 if (!CheckPort(mysrc
)) {
462 jack_error("jack_port_tie called with a NULL src port");
465 uintptr_t dst_aux
= (uintptr_t)dst
;
466 jack_port_id_t mydst
= (jack_port_id_t
)dst_aux
;
467 if (!CheckPort(mydst
)) {
468 jack_error("jack_port_tie called with a NULL dst port");
471 JackGraphManager
* manager
= GetGraphManager();
472 if (manager
&& manager
->GetPort(mysrc
)->GetRefNum() != manager
->GetPort(mydst
)->GetRefNum()) {
473 jack_error("jack_port_tie called with ports not belonging to the same client");
476 return manager
->GetPort(mydst
)->Tie(mysrc
);
480 EXPORT
int jack_port_untie(jack_port_t
* port
)
482 #ifdef __CLIENTDEBUG__
483 JackGlobals::CheckContext("jack_port_untie");
485 uintptr_t port_aux
= (uintptr_t)port
;
486 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
487 if (!CheckPort(myport
)) {
488 jack_error("jack_port_untie called with an incorrect port %ld", myport
);
491 JackGraphManager
* manager
= GetGraphManager();
492 return (manager
? manager
->GetPort(myport
)->UnTie() : -1);
496 EXPORT jack_nframes_t
jack_port_get_latency(jack_port_t
* port
)
498 #ifdef __CLIENTDEBUG__
499 JackGlobals::CheckContext("jack_port_get_latency");
501 uintptr_t port_aux
= (uintptr_t)port
;
502 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
503 if (!CheckPort(myport
)) {
504 jack_error("jack_port_get_latency called with an incorrect port %ld", myport
);
508 JackGraphManager
* manager
= GetGraphManager();
509 return (manager
? manager
->GetPort(myport
)->GetLatency() : 0);
513 EXPORT
void jack_port_set_latency(jack_port_t
* port
, jack_nframes_t frames
)
515 #ifdef __CLIENTDEBUG__
516 JackGlobals::CheckContext("jack_port_set_latency");
518 uintptr_t port_aux
= (uintptr_t)port
;
519 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
520 if (!CheckPort(myport
)) {
521 jack_error("jack_port_set_latency called with an incorrect port %ld", myport
);
523 JackGraphManager
* manager
= GetGraphManager();
525 manager
->GetPort(myport
)->SetLatency(frames
);
529 EXPORT
int jack_recompute_total_latency(jack_client_t
* ext_client
, jack_port_t
* port
)
531 #ifdef __CLIENTDEBUG__
532 JackGlobals::CheckContext("jack_recompute_total_latency");
535 JackClient
* client
= (JackClient
*)ext_client
;
536 uintptr_t port_aux
= (uintptr_t)port
;
537 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
538 if (client
== NULL
) {
539 jack_error("jack_recompute_total_latencies called with a NULL client");
541 } else if (!CheckPort(myport
)) {
542 jack_error("jack_recompute_total_latencies called with a NULL port");
546 JackGraphManager
* manager
= GetGraphManager();
547 return (manager
? manager
->ComputeTotalLatency(myport
) : -1);
551 EXPORT
int jack_recompute_total_latencies(jack_client_t
* ext_client
)
553 #ifdef __CLIENTDEBUG__
554 JackGlobals::CheckContext("jack_recompute_total_latencies");
557 JackClient
* client
= (JackClient
*)ext_client
;
558 if (client
== NULL
) {
559 jack_error("jack_recompute_total_latencies called with a NULL client");
563 JackGraphManager
* manager
= GetGraphManager();
564 return (manager
? manager
->ComputeTotalLatencies() : -1);
569 This is unsafe if case of concurrent access, and should be "serialized" doing a server call.
572 EXPORT
int jack_port_set_name(jack_port_t
* port
, const char* name
)
574 #ifdef __CLIENTDEBUG__
575 JackGlobals::CheckContext("jack_port_set_name");
577 uintptr_t port_aux
= (uintptr_t)port
;
578 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
579 if (!CheckPort(myport
)) {
580 jack_error("jack_port_set_name called with an incorrect port %ld", myport
);
582 } else if (name
== NULL
) {
583 jack_error("jack_port_set_name called with a NULL port name");
586 JackGraphManager
* manager
= GetGraphManager();
588 if (manager
&& ((refnum
= manager
->GetPort(myport
)->GetRefNum()) > 0)) {
589 JackClient
* client
= JackGlobals::fClientTable
[refnum
];
591 return client
->PortRename(myport
, name
);
598 EXPORT
int jack_port_set_alias(jack_port_t
* port
, const char* name
)
600 #ifdef __CLIENTDEBUG__
601 JackGlobals::CheckContext("jack_port_set_alias");
603 uintptr_t port_aux
= (uintptr_t)port
;
604 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
605 if (!CheckPort(myport
)) {
606 jack_error("jack_port_set_alias called with an incorrect port %ld", myport
);
608 } else if (name
== NULL
) {
609 jack_error("jack_port_set_alias called with a NULL port name");
612 JackGraphManager
* manager
= GetGraphManager();
613 return (manager
? manager
->GetPort(myport
)->SetAlias(name
) : -1);
617 EXPORT
int jack_port_unset_alias(jack_port_t
* port
, const char* name
)
619 #ifdef __CLIENTDEBUG__
620 JackGlobals::CheckContext("jack_port_unset_alias");
622 uintptr_t port_aux
= (uintptr_t)port
;
623 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
624 if (!CheckPort(myport
)) {
625 jack_error("jack_port_unset_alias called with an incorrect port %ld", myport
);
627 } else if (name
== NULL
) {
628 jack_error("jack_port_unset_alias called with a NULL port name");
631 JackGraphManager
* manager
= GetGraphManager();
632 return (manager
? manager
->GetPort(myport
)->UnsetAlias(name
) : -1);
636 EXPORT
int jack_port_get_aliases(const jack_port_t
* port
, char* const aliases
[2])
638 #ifdef __CLIENTDEBUG__
639 JackGlobals::CheckContext("jack_port_get_aliases");
641 uintptr_t port_aux
= (uintptr_t)port
;
642 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
643 if (!CheckPort(myport
)) {
644 jack_error("jack_port_get_aliases called with an incorrect port %ld", myport
);
647 JackGraphManager
* manager
= GetGraphManager();
648 return (manager
? manager
->GetPort(myport
)->GetAliases(aliases
) : -1);
652 EXPORT
int jack_port_request_monitor(jack_port_t
* port
, int onoff
)
654 #ifdef __CLIENTDEBUG__
655 JackGlobals::CheckContext("jack_port_request_monitor");
657 uintptr_t port_aux
= (uintptr_t)port
;
658 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
659 if (!CheckPort(myport
)) {
660 jack_error("jack_port_request_monitor called with an incorrect port %ld", myport
);
663 JackGraphManager
* manager
= GetGraphManager();
664 return (manager
? manager
->RequestMonitor(myport
, onoff
) : -1);
668 EXPORT
int jack_port_request_monitor_by_name(jack_client_t
* ext_client
, const char* port_name
, int onoff
)
670 #ifdef __CLIENTDEBUG__
671 JackGlobals::CheckContext("jack_port_request_monitor_by_name");
673 JackClient
* client
= (JackClient
*)ext_client
;
674 if (client
== NULL
) {
675 jack_error("jack_port_request_monitor_by_name called with a NULL client");
678 JackGraphManager
* manager
= GetGraphManager();
681 jack_port_id_t myport
= manager
->GetPort(port_name
);
682 if (!CheckPort(myport
)) {
683 jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name
);
686 return manager
->RequestMonitor(myport
, onoff
);
691 EXPORT
int jack_port_ensure_monitor(jack_port_t
* port
, int onoff
)
693 #ifdef __CLIENTDEBUG__
694 JackGlobals::CheckContext("jack_port_ensure_monitor");
696 uintptr_t port_aux
= (uintptr_t)port
;
697 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
698 if (!CheckPort(myport
)) {
699 jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport
);
702 JackGraphManager
* manager
= GetGraphManager();
703 return (manager
? manager
->GetPort(myport
)->EnsureMonitor(onoff
) : -1);
707 EXPORT
int jack_port_monitoring_input(jack_port_t
* port
)
709 #ifdef __CLIENTDEBUG__
710 JackGlobals::CheckContext("jack_port_monitoring_input");
712 uintptr_t port_aux
= (uintptr_t)port
;
713 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
714 if (!CheckPort(myport
)) {
715 jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport
);
718 JackGraphManager
* manager
= GetGraphManager();
719 return (manager
? manager
->GetPort(myport
)->MonitoringInput() : -1);
723 EXPORT
int jack_is_realtime(jack_client_t
* ext_client
)
725 #ifdef __CLIENTDEBUG__
726 JackGlobals::CheckContext("jack_is_realtime");
728 JackClient
* client
= (JackClient
*)ext_client
;
729 if (client
== NULL
) {
730 jack_error("jack_is_realtime called with a NULL client");
733 JackEngineControl
* control
= GetEngineControl();
734 return (control
? control
->fRealTime
: -1);
738 EXPORT
void jack_on_shutdown(jack_client_t
* ext_client
, JackShutdownCallback callback
, void* arg
)
740 #ifdef __CLIENTDEBUG__
741 JackGlobals::CheckContext("jack_on_shutdown");
743 JackClient
* client
= (JackClient
*)ext_client
;
744 if (client
== NULL
) {
745 jack_error("jack_on_shutdown called with a NULL client");
747 client
->OnShutdown(callback
, arg
);
751 EXPORT
void jack_on_info_shutdown(jack_client_t
* ext_client
, JackInfoShutdownCallback callback
, void* arg
)
753 #ifdef __CLIENTDEBUG__
754 JackGlobals::CheckContext("jack_on_info_shutdown");
756 JackClient
* client
= (JackClient
*)ext_client
;
757 if (client
== NULL
) {
758 jack_error("jack_on_info_shutdown called with a NULL client");
760 client
->OnInfoShutdown(callback
, arg
);
764 EXPORT
int jack_set_process_callback(jack_client_t
* ext_client
, JackProcessCallback callback
, void* arg
)
766 #ifdef __CLIENTDEBUG__
767 JackGlobals::CheckContext("jack_set_process_callback");
769 JackClient
* client
= (JackClient
*)ext_client
;
770 if (client
== NULL
) {
771 jack_error("jack_set_process_callback called with a NULL client");
774 return client
->SetProcessCallback(callback
, arg
);
778 EXPORT jack_nframes_t
jack_thread_wait(jack_client_t
* ext_client
, int status
)
780 #ifdef __CLIENTDEBUG__
781 JackGlobals::CheckContext("jack_thread_wait");
783 JackClient
* client
= (JackClient
*)ext_client
;
784 if (client
== NULL
) {
785 jack_error("jack_thread_wait called with a NULL client");
788 jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
793 EXPORT jack_nframes_t
jack_cycle_wait(jack_client_t
* ext_client
)
795 #ifdef __CLIENTDEBUG__
796 JackGlobals::CheckContext("jack_cycle_wait");
798 JackClient
* client
= (JackClient
*)ext_client
;
799 if (client
== NULL
) {
800 jack_error("jack_cycle_wait called with a NULL client");
803 return client
->CycleWait();
807 EXPORT
void jack_cycle_signal(jack_client_t
* ext_client
, int status
)
809 #ifdef __CLIENTDEBUG__
810 JackGlobals::CheckContext("jack_cycle_signal");
812 JackClient
* client
= (JackClient
*)ext_client
;
813 if (client
== NULL
) {
814 jack_error("jack_cycle_signal called with a NULL client");
816 client
->CycleSignal(status
);
820 EXPORT
int jack_set_process_thread(jack_client_t
* ext_client
, JackThreadCallback fun
, void *arg
)
822 #ifdef __CLIENTDEBUG__
823 JackGlobals::CheckContext("jack_set_process_thread");
825 JackClient
* client
= (JackClient
*)ext_client
;
826 if (client
== NULL
) {
827 jack_error("jack_set_process_thread called with a NULL client");
830 return client
->SetProcessThread(fun
, arg
);
834 EXPORT
int jack_set_freewheel_callback(jack_client_t
* ext_client
, JackFreewheelCallback freewheel_callback
, void* arg
)
836 #ifdef __CLIENTDEBUG__
837 JackGlobals::CheckContext("jack_set_freewheel_callback");
839 JackClient
* client
= (JackClient
*)ext_client
;
840 if (client
== NULL
) {
841 jack_error("jack_set_freewheel_callback called with a NULL client");
844 return client
->SetFreewheelCallback(freewheel_callback
, arg
);
848 EXPORT
int jack_set_freewheel(jack_client_t
* ext_client
, int onoff
)
850 #ifdef __CLIENTDEBUG__
851 JackGlobals::CheckContext("jack_set_freewheel");
853 JackClient
* client
= (JackClient
*)ext_client
;
854 if (client
== NULL
) {
855 jack_error("jack_set_freewheel called with a NULL client");
858 return client
->SetFreeWheel(onoff
);
862 EXPORT
int jack_set_buffer_size(jack_client_t
* ext_client
, jack_nframes_t buffer_size
)
864 #ifdef __CLIENTDEBUG__
865 JackGlobals::CheckContext("jack_set_buffer_size");
867 JackClient
* client
= (JackClient
*)ext_client
;
868 if (client
== NULL
) {
869 jack_error("jack_set_buffer_size called with a NULL client");
871 } else if (!CheckBufferSize(buffer_size
)) {
874 return client
->SetBufferSize(buffer_size
);
878 EXPORT
int jack_set_buffer_size_callback(jack_client_t
* ext_client
, JackBufferSizeCallback bufsize_callback
, void* arg
)
880 #ifdef __CLIENTDEBUG__
881 JackGlobals::CheckContext("jack_set_buffer_size_callback");
883 JackClient
* client
= (JackClient
*)ext_client
;
884 if (client
== NULL
) {
885 jack_error("jack_set_buffer_size_callback called with a NULL client");
888 return client
->SetBufferSizeCallback(bufsize_callback
, arg
);
892 EXPORT
int jack_set_sample_rate_callback(jack_client_t
* ext_client
, JackSampleRateCallback srate_callback
, void* arg
)
894 #ifdef __CLIENTDEBUG__
895 JackGlobals::CheckContext("jack_set_sample_rate_callback");
897 JackClient
* client
= (JackClient
*)ext_client
;
898 if (client
== NULL
) {
899 jack_error("jack_set_sample_rate_callback called with a NULL client");
902 return client
->SetSampleRateCallback(srate_callback
, arg
);
906 EXPORT
int jack_set_client_registration_callback(jack_client_t
* ext_client
, JackClientRegistrationCallback registration_callback
, void* arg
)
908 #ifdef __CLIENTDEBUG__
909 JackGlobals::CheckContext("jack_set_client_registration_callback");
911 JackClient
* client
= (JackClient
*)ext_client
;
912 if (client
== NULL
) {
913 jack_error("jack_set_client_registration_callback called with a NULL client");
916 return client
->SetClientRegistrationCallback(registration_callback
, arg
);
920 EXPORT
int jack_set_port_registration_callback(jack_client_t
* ext_client
, JackPortRegistrationCallback registration_callback
, void* arg
)
922 #ifdef __CLIENTDEBUG__
923 JackGlobals::CheckContext("jack_set_port_registration_callback");
925 JackClient
* client
= (JackClient
*)ext_client
;
926 if (client
== NULL
) {
927 jack_error("jack_set_port_registration_callback called with a NULL client");
930 return client
->SetPortRegistrationCallback(registration_callback
, arg
);
934 EXPORT
int jack_set_port_connect_callback(jack_client_t
* ext_client
, JackPortConnectCallback portconnect_callback
, void* arg
)
936 #ifdef __CLIENTDEBUG__
937 JackGlobals::CheckContext("jack_set_port_connect_callback");
939 JackClient
* client
= (JackClient
*)ext_client
;
940 if (client
== NULL
) {
941 jack_error("jack_set_port_connect_callback called with a NULL client");
944 return client
->SetPortConnectCallback(portconnect_callback
, arg
);
948 EXPORT
int jack_set_port_rename_callback(jack_client_t
* ext_client
, JackPortRenameCallback rename_callback
, void* arg
)
950 #ifdef __CLIENTDEBUG__
951 JackGlobals::CheckContext("jack_set_port_rename_callback");
953 JackClient
* client
= (JackClient
*)ext_client
;
954 if (client
== NULL
) {
955 jack_error("jack_set_port_rename_callback called with a NULL client");
958 return client
->SetPortRenameCallback(rename_callback
, arg
);
962 EXPORT
int jack_set_graph_order_callback(jack_client_t
* ext_client
, JackGraphOrderCallback graph_callback
, void* arg
)
964 #ifdef __CLIENTDEBUG__
965 JackGlobals::CheckContext("jack_set_graph_order_callback");
967 JackClient
* client
= (JackClient
*)ext_client
;
968 jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client
, client
);
969 if (client
== NULL
) {
970 jack_error("jack_set_graph_order_callback called with a NULL client");
973 return client
->SetGraphOrderCallback(graph_callback
, arg
);
977 EXPORT
int jack_set_xrun_callback(jack_client_t
* ext_client
, JackXRunCallback xrun_callback
, void* arg
)
979 #ifdef __CLIENTDEBUG__
980 JackGlobals::CheckContext("jack_set_xrun_callback");
982 JackClient
* client
= (JackClient
*)ext_client
;
983 if (client
== NULL
) {
984 jack_error("jack_set_xrun_callback called with a NULL client");
987 return client
->SetXRunCallback(xrun_callback
, arg
);
991 EXPORT
int jack_set_thread_init_callback(jack_client_t
* ext_client
, JackThreadInitCallback init_callback
, void *arg
)
993 #ifdef __CLIENTDEBUG__
994 JackGlobals::CheckContext("jack_set_thread_init_callback");
996 JackClient
* client
= (JackClient
*)ext_client
;
997 jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client
, client
);
998 if (client
== NULL
) {
999 jack_error("jack_set_thread_init_callback called with a NULL client");
1002 return client
->SetInitCallback(init_callback
, arg
);
1006 EXPORT
int jack_activate(jack_client_t
* ext_client
)
1008 #ifdef __CLIENTDEBUG__
1009 JackGlobals::CheckContext("jack_activate");
1011 JackClient
* client
= (JackClient
*)ext_client
;
1012 if (client
== NULL
) {
1013 jack_error("jack_activate called with a NULL client");
1016 return client
->Activate();
1020 EXPORT
int jack_deactivate(jack_client_t
* ext_client
)
1022 #ifdef __CLIENTDEBUG__
1023 JackGlobals::CheckContext("jack_deactivate");
1025 JackClient
* client
= (JackClient
*)ext_client
;
1026 if (client
== NULL
) {
1027 jack_error("jack_deactivate called with a NULL client");
1030 return client
->Deactivate();
1034 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
)
1036 #ifdef __CLIENTDEBUG__
1037 JackGlobals::CheckContext("jack_port_register");
1039 JackClient
* client
= (JackClient
*)ext_client
;
1040 if (client
== NULL
) {
1041 jack_error("jack_port_register called with a NULL client");
1043 } else if ((port_name
== NULL
) || (port_type
== NULL
)) {
1044 jack_error("jack_port_register called with a NULL port name or a NULL port_type");
1047 return (jack_port_t
*)((uintptr_t)client
->PortRegister(port_name
, port_type
, flags
, buffer_size
));
1051 EXPORT
int jack_port_unregister(jack_client_t
* ext_client
, jack_port_t
* port
)
1053 #ifdef __CLIENTDEBUG__
1054 JackGlobals::CheckContext("jack_port_unregister");
1056 JackClient
* client
= (JackClient
*)ext_client
;
1057 if (client
== NULL
) {
1058 jack_error("jack_port_unregister called with a NULL client");
1061 uintptr_t port_aux
= (uintptr_t)port
;
1062 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1063 if (!CheckPort(myport
)) {
1064 jack_error("jack_port_unregister called with an incorrect port %ld", myport
);
1067 return client
->PortUnRegister(myport
);
1070 EXPORT
int jack_port_is_mine(const jack_client_t
* ext_client
, const jack_port_t
* port
)
1072 #ifdef __CLIENTDEBUG__
1073 JackGlobals::CheckContext("jack_port_is_mine");
1075 JackClient
* client
= (JackClient
*)ext_client
;
1076 if (client
== NULL
) {
1077 jack_error("jack_port_is_mine called with a NULL client");
1080 uintptr_t port_aux
= (uintptr_t)port
;
1081 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1082 if (!CheckPort(myport
)) {
1083 jack_error("jack_port_is_mine called with an incorrect port %ld", myport
);
1086 return client
->PortIsMine(myport
);
1089 EXPORT
const char** jack_port_get_connections(const jack_port_t
* port
)
1091 #ifdef __CLIENTDEBUG__
1092 JackGlobals::CheckContext("jack_port_get_connections");
1094 uintptr_t port_aux
= (uintptr_t)port
;
1095 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1096 if (!CheckPort(myport
)) {
1097 jack_error("jack_port_get_connections called with an incorrect port %ld", myport
);
1101 JackGraphManager
* manager
= GetGraphManager();
1102 return (manager
? manager
->GetConnections(myport
) : NULL
);
1106 // Calling client does not need to "own" the port
1107 EXPORT
const char** jack_port_get_all_connections(const jack_client_t
* ext_client
, const jack_port_t
* port
)
1109 #ifdef __CLIENTDEBUG__
1110 JackGlobals::CheckContext("jack_port_get_all_connections");
1112 JackClient
* client
= (JackClient
*)ext_client
;
1113 if (client
== NULL
) {
1114 jack_error("jack_port_get_all_connections called with a NULL client");
1118 uintptr_t port_aux
= (uintptr_t)port
;
1119 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1120 if (!CheckPort(myport
)) {
1121 jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport
);
1125 JackGraphManager
* manager
= GetGraphManager();
1126 return (manager
? manager
->GetConnections(myport
) : NULL
);
1130 EXPORT jack_nframes_t
jack_port_get_total_latency(jack_client_t
* ext_client
, jack_port_t
* port
)
1132 #ifdef __CLIENTDEBUG__
1133 JackGlobals::CheckContext("jack_port_get_total_latency");
1135 JackClient
* client
= (JackClient
*)ext_client
;
1136 if (client
== NULL
) {
1137 jack_error("jack_port_get_total_latency called with a NULL client");
1141 uintptr_t port_aux
= (uintptr_t)port
;
1142 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1143 if (!CheckPort(myport
)) {
1144 jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport
);
1148 JackGraphManager
* manager
= GetGraphManager();
1150 manager
->ComputeTotalLatency(myport
);
1151 return manager
->GetPort(myport
)->GetTotalLatency();
1158 EXPORT
int jack_connect(jack_client_t
* ext_client
, const char* src
, const char* dst
)
1160 #ifdef __CLIENTDEBUG__
1161 JackGlobals::CheckContext("jack_connect");
1163 JackClient
* client
= (JackClient
*)ext_client
;
1164 if (client
== NULL
) {
1165 jack_error("jack_connect called with a NULL client");
1167 } else if ((src
== NULL
) || (dst
== NULL
)) {
1168 jack_error("jack_connect called with a NULL port name");
1171 return client
->PortConnect(src
, dst
);
1175 EXPORT
int jack_disconnect(jack_client_t
* ext_client
, const char* src
, const char* dst
)
1177 #ifdef __CLIENTDEBUG__
1178 JackGlobals::CheckContext("jack_disconnect");
1180 JackClient
* client
= (JackClient
*)ext_client
;
1181 if (client
== NULL
) {
1182 jack_error("jack_disconnect called with a NULL client");
1184 } else if ((src
== NULL
) || (dst
== NULL
)) {
1185 jack_error("jack_connect called with a NULL port name");
1188 return client
->PortDisconnect(src
, dst
);
1192 EXPORT
int jack_port_disconnect(jack_client_t
* ext_client
, jack_port_t
* src
)
1194 #ifdef __CLIENTDEBUG__
1195 JackGlobals::CheckContext("jack_port_disconnect");
1197 JackClient
* client
= (JackClient
*)ext_client
;
1198 if (client
== NULL
) {
1199 jack_error("jack_port_disconnect called with a NULL client");
1202 uintptr_t port_aux
= (uintptr_t)src
;
1203 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1204 if (!CheckPort(myport
)) {
1205 jack_error("jack_port_disconnect called with an incorrect port %ld", myport
);
1208 return client
->PortDisconnect(myport
);
1211 EXPORT jack_nframes_t
jack_get_sample_rate(jack_client_t
* ext_client
)
1213 #ifdef __CLIENTDEBUG__
1214 JackGlobals::CheckContext("jack_get_sample_rate");
1216 JackClient
* client
= (JackClient
*)ext_client
;
1217 if (client
== NULL
) {
1218 jack_error("jack_get_sample_rate called with a NULL client");
1221 JackEngineControl
* control
= GetEngineControl();
1222 return (control
? control
->fSampleRate
: 0);
1226 EXPORT jack_nframes_t
jack_get_buffer_size(jack_client_t
* ext_client
)
1228 #ifdef __CLIENTDEBUG__
1229 JackGlobals::CheckContext("jack_get_buffer_size");
1231 JackClient
* client
= (JackClient
*)ext_client
;
1232 if (client
== NULL
) {
1233 jack_error("jack_get_buffer_size called with a NULL client");
1236 JackEngineControl
* control
= GetEngineControl();
1237 return (control
? control
->fBufferSize
: 0);
1241 EXPORT
const char** jack_get_ports(jack_client_t
* ext_client
, const char* port_name_pattern
, const char* type_name_pattern
, unsigned long flags
)
1243 #ifdef __CLIENTDEBUG__
1244 JackGlobals::CheckContext("jack_get_ports");
1246 JackClient
* client
= (JackClient
*)ext_client
;
1247 if (client
== NULL
) {
1248 jack_error("jack_get_ports called with a NULL client");
1251 JackGraphManager
* manager
= GetGraphManager();
1252 return (manager
? manager
->GetPorts(port_name_pattern
, type_name_pattern
, flags
) : NULL
);
1255 EXPORT jack_port_t
* jack_port_by_name(jack_client_t
* ext_client
, const char* portname
)
1257 #ifdef __CLIENTDEBUG__
1258 JackGlobals::CheckContext("jack_port_by_name");
1260 JackClient
* client
= (JackClient
*)ext_client
;
1261 if (client
== NULL
) {
1262 jack_error("jack_get_ports called with a NULL client");
1266 if (portname
== NULL
) {
1267 jack_error("jack_port_by_name called with a NULL port name");
1270 JackGraphManager
* manager
= GetGraphManager();
1273 int res
= manager
->GetPort(portname
); // returns a port index at least > 1
1274 return (res
== NO_PORT
) ? NULL
: (jack_port_t
*)((uintptr_t)res
);
1278 EXPORT jack_port_t
* jack_port_by_id(jack_client_t
* ext_client
, jack_port_id_t id
)
1280 #ifdef __CLIENTDEBUG__
1281 JackGlobals::CheckContext("jack_port_by_id");
1283 /* jack_port_t* type is actually the port index */
1284 return (jack_port_t
*)((uintptr_t)id
);
1287 EXPORT
int jack_engine_takeover_timebase(jack_client_t
* ext_client
)
1289 #ifdef __CLIENTDEBUG__
1290 JackGlobals::CheckContext("jack_engine_takeover_timebase");
1292 JackClient
* client
= (JackClient
*)ext_client
;
1293 if (client
== NULL
) {
1294 jack_error("jack_engine_takeover_timebase called with a NULL client");
1297 jack_error("jack_engine_takeover_timebase: deprecated\n");
1302 EXPORT jack_nframes_t
jack_frames_since_cycle_start(const jack_client_t
* ext_client
)
1304 #ifdef __CLIENTDEBUG__
1305 JackGlobals::CheckContext("jack_frames_since_cycle_start");
1308 JackEngineControl
* control
= GetEngineControl();
1310 control
->ReadFrameTime(&timer
);
1311 return timer
.FramesSinceCycleStart(GetMicroSeconds(), control
->fSampleRate
);
1317 EXPORT jack_time_t
jack_get_time()
1319 #ifdef __CLIENTDEBUG__
1320 JackGlobals::CheckContext("jack_get_time");
1322 return GetMicroSeconds();
1325 EXPORT jack_time_t
jack_frames_to_time(const jack_client_t
* ext_client
, jack_nframes_t frames
)
1327 #ifdef __CLIENTDEBUG__
1328 JackGlobals::CheckContext("jack_frames_to_time");
1330 JackClient
* client
= (JackClient
*)ext_client
;
1331 if (client
== NULL
) {
1332 jack_error("jack_frames_to_time called with a NULL client");
1336 JackEngineControl
* control
= GetEngineControl();
1338 control
->ReadFrameTime(&timer
);
1339 return timer
.Frames2Time(frames
, control
->fBufferSize
);
1346 EXPORT jack_nframes_t
jack_time_to_frames(const jack_client_t
* ext_client
, jack_time_t time
)
1348 #ifdef __CLIENTDEBUG__
1349 JackGlobals::CheckContext("jack_time_to_frames");
1351 JackClient
* client
= (JackClient
*)ext_client
;
1352 if (client
== NULL
) {
1353 jack_error("jack_time_to_frames called with a NULL client");
1357 JackEngineControl
* control
= GetEngineControl();
1359 control
->ReadFrameTime(&timer
);
1360 return timer
.Time2Frames(time
, control
->fBufferSize
);
1367 EXPORT jack_nframes_t
jack_frame_time(const jack_client_t
* ext_client
)
1369 #ifdef __CLIENTDEBUG__
1370 JackGlobals::CheckContext("jack_frame_time");
1372 return jack_time_to_frames(ext_client
, GetMicroSeconds());
1375 EXPORT jack_nframes_t
jack_last_frame_time(const jack_client_t
* ext_client
)
1377 #ifdef __CLIENTDEBUG__
1378 JackGlobals::CheckContext("jack_last_frame_time");
1380 JackEngineControl
* control
= GetEngineControl();
1381 return (control
) ? control
->fFrameTimer
.ReadCurrentState()->CurFrame() : 0;
1384 EXPORT
float jack_cpu_load(jack_client_t
* ext_client
)
1386 #ifdef __CLIENTDEBUG__
1387 JackGlobals::CheckContext("jack_cpu_load");
1389 JackClient
* client
= (JackClient
*)ext_client
;
1390 if (client
== NULL
) {
1391 jack_error("jack_cpu_load called with a NULL client");
1394 JackEngineControl
* control
= GetEngineControl();
1395 return (control
? control
->fCPULoad
: 0.0f
);
1399 EXPORT pthread_t
jack_client_thread_id(jack_client_t
* ext_client
)
1401 #ifdef __CLIENTDEBUG__
1402 JackGlobals::CheckContext("jack_client_thread_id");
1404 JackClient
* client
= (JackClient
*)ext_client
;
1405 if (client
== NULL
) {
1406 jack_error("jack_client_thread_id called with a NULL client");
1407 return (pthread_t
)NULL
;
1409 return client
->GetThreadID();
1413 EXPORT
char* jack_get_client_name(jack_client_t
* ext_client
)
1415 #ifdef __CLIENTDEBUG__
1416 JackGlobals::CheckContext("jack_get_client_name");
1418 JackClient
* client
= (JackClient
*)ext_client
;
1419 if (client
== NULL
) {
1420 jack_error("jack_get_client_name called with a NULL client");
1423 return client
->GetClientControl()->fName
;
1427 EXPORT
int jack_client_name_size(void)
1429 return JACK_CLIENT_NAME_SIZE
;
1432 EXPORT
int jack_port_name_size(void)
1434 return JACK_PORT_NAME_SIZE
;
1437 EXPORT
int jack_port_type_size(void)
1439 return JACK_PORT_TYPE_SIZE
;
1443 EXPORT
int jack_release_timebase(jack_client_t
* ext_client
)
1445 #ifdef __CLIENTDEBUG__
1446 JackGlobals::CheckContext("jack_release_timebase");
1448 JackClient
* client
= (JackClient
*)ext_client
;
1449 if (client
== NULL
) {
1450 jack_error("jack_release_timebase called with a NULL client");
1453 return client
->ReleaseTimebase();
1457 EXPORT
int jack_set_sync_callback(jack_client_t
* ext_client
, JackSyncCallback sync_callback
, void *arg
)
1459 #ifdef __CLIENTDEBUG__
1460 JackGlobals::CheckContext("jack_set_sync_callback");
1462 JackClient
* client
= (JackClient
*)ext_client
;
1463 if (client
== NULL
) {
1464 jack_error("jack_set_sync_callback called with a NULL client");
1467 return client
->SetSyncCallback(sync_callback
, arg
);
1471 EXPORT
int jack_set_sync_timeout(jack_client_t
* ext_client
, jack_time_t timeout
)
1473 #ifdef __CLIENTDEBUG__
1474 JackGlobals::CheckContext("jack_set_sync_timeout");
1476 JackClient
* client
= (JackClient
*)ext_client
;
1477 if (client
== NULL
) {
1478 jack_error("jack_set_sync_timeout called with a NULL client");
1481 return client
->SetSyncTimeout(timeout
);
1485 EXPORT
int jack_set_timebase_callback(jack_client_t
* ext_client
, int conditional
, JackTimebaseCallback timebase_callback
, void* arg
)
1487 #ifdef __CLIENTDEBUG__
1488 JackGlobals::CheckContext("jack_set_timebase_callback");
1490 JackClient
* client
= (JackClient
*)ext_client
;
1491 if (client
== NULL
) {
1492 jack_error("jack_set_timebase_callback called with a NULL client");
1495 return client
->SetTimebaseCallback(conditional
, timebase_callback
, arg
);
1499 EXPORT
int jack_transport_locate(jack_client_t
* ext_client
, jack_nframes_t frame
)
1501 #ifdef __CLIENTDEBUG__
1502 JackGlobals::CheckContext("jack_transport_locate");
1504 JackClient
* client
= (JackClient
*)ext_client
;
1505 if (client
== NULL
) {
1506 jack_error("jack_transport_locate called with a NULL client");
1509 client
->TransportLocate(frame
);
1514 EXPORT jack_transport_state_t
jack_transport_query(const jack_client_t
* ext_client
, jack_position_t
* pos
)
1516 #ifdef __CLIENTDEBUG__
1517 JackGlobals::CheckContext("jack_transport_query");
1519 JackClient
* client
= (JackClient
*)ext_client
;
1520 if (client
== NULL
) {
1521 jack_error("jack_transport_query called with a NULL client");
1522 return JackTransportStopped
;
1524 return client
->TransportQuery(pos
);
1528 EXPORT jack_nframes_t
jack_get_current_transport_frame(const jack_client_t
* ext_client
)
1530 #ifdef __CLIENTDEBUG__
1531 JackGlobals::CheckContext("jack_get_current_transport_frame");
1533 JackClient
* client
= (JackClient
*)ext_client
;
1534 if (client
== NULL
) {
1535 jack_error("jack_get_current_transport_frame called with a NULL client");
1538 return client
->GetCurrentTransportFrame();
1542 EXPORT
int jack_transport_reposition(jack_client_t
* ext_client
, jack_position_t
* pos
)
1544 #ifdef __CLIENTDEBUG__
1545 JackGlobals::CheckContext("jack_transport_reposition");
1547 JackClient
* client
= (JackClient
*)ext_client
;
1548 if (client
== NULL
) {
1549 jack_error("jack_transport_reposition called with a NULL client");
1552 client
->TransportReposition(pos
);
1557 EXPORT
void jack_transport_start(jack_client_t
* ext_client
)
1559 #ifdef __CLIENTDEBUG__
1560 JackGlobals::CheckContext("jack_transport_start");
1562 JackClient
* client
= (JackClient
*)ext_client
;
1563 if (client
== NULL
) {
1564 jack_error("jack_transport_start called with a NULL client");
1566 client
->TransportStart();
1570 EXPORT
void jack_transport_stop(jack_client_t
* ext_client
)
1572 #ifdef __CLIENTDEBUG__
1573 JackGlobals::CheckContext("jack_transport_stop");
1575 JackClient
* client
= (JackClient
*)ext_client
;
1576 if (client
== NULL
) {
1577 jack_error("jack_transport_stop called with a NULL client");
1579 client
->TransportStop();
1584 EXPORT
void jack_get_transport_info(jack_client_t
* ext_client
, jack_transport_info_t
* tinfo
)
1586 #ifdef __CLIENTDEBUG__
1587 JackGlobals::CheckContext("jack_get_transport_info");
1589 jack_error("jack_get_transport_info: deprecated");
1591 memset(tinfo
, 0, sizeof(jack_transport_info_t
));
1594 EXPORT
void jack_set_transport_info(jack_client_t
* ext_client
, jack_transport_info_t
* tinfo
)
1596 #ifdef __CLIENTDEBUG__
1597 JackGlobals::CheckContext("jack_set_transport_info");
1599 jack_error("jack_set_transport_info: deprecated");
1601 memset(tinfo
, 0, sizeof(jack_transport_info_t
));
1605 EXPORT
float jack_get_max_delayed_usecs(jack_client_t
* ext_client
)
1607 #ifdef __CLIENTDEBUG__
1608 JackGlobals::CheckContext("jack_get_max_delayed_usecs");
1610 JackClient
* client
= (JackClient
*)ext_client
;
1611 if (client
== NULL
) {
1612 jack_error("jack_get_max_delayed_usecs called with a NULL client");
1615 JackEngineControl
* control
= GetEngineControl();
1616 return (control
? control
->fMaxDelayedUsecs
: 0.f
);
1620 EXPORT
float jack_get_xrun_delayed_usecs(jack_client_t
* ext_client
)
1622 #ifdef __CLIENTDEBUG__
1623 JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
1625 JackClient
* client
= (JackClient
*)ext_client
;
1626 if (client
== NULL
) {
1627 jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
1630 JackEngineControl
* control
= GetEngineControl();
1631 return (control
? control
->fXrunDelayedUsecs
: 0.f
);
1635 EXPORT
void jack_reset_max_delayed_usecs(jack_client_t
* ext_client
)
1637 #ifdef __CLIENTDEBUG__
1638 JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
1640 JackClient
* client
= (JackClient
*)ext_client
;
1641 if (client
== NULL
) {
1642 jack_error("jack_reset_max_delayed_usecs called with a NULL client");
1644 JackEngineControl
* control
= GetEngineControl();
1645 control
->ResetXRun();
1650 EXPORT
int jack_client_real_time_priority(jack_client_t
* ext_client
)
1652 #ifdef __CLIENTDEBUG__
1653 JackGlobals::CheckContext("jack_client_real_time_priority");
1655 JackClient
* client
= (JackClient
*)ext_client
;
1656 if (client
== NULL
) {
1657 jack_error("jack_client_real_time_priority called with a NULL client");
1660 JackEngineControl
* control
= GetEngineControl();
1661 return (control
->fRealTime
) ? control
->fClientPriority
: -1;
1665 EXPORT
int jack_client_max_real_time_priority(jack_client_t
* ext_client
)
1667 #ifdef __CLIENTDEBUG__
1668 JackGlobals::CheckContext("jack_client_max_real_time_priority");
1670 JackClient
* client
= (JackClient
*)ext_client
;
1671 if (client
== NULL
) {
1672 jack_error("jack_client_max_real_time_priority called with a NULL client");
1675 JackEngineControl
* control
= GetEngineControl();
1676 return (control
->fRealTime
) ? control
->fMaxClientPriority
: -1;
1680 EXPORT
int jack_acquire_real_time_scheduling(pthread_t thread
, int priority
)
1682 JackEngineControl
* control
= GetEngineControl();
1683 return (control
? JackThread::AcquireRealTimeImp(thread
, priority
, GetEngineControl()->fPeriod
, GetEngineControl()->fComputation
, GetEngineControl()->fConstraint
) : -1);
1686 EXPORT
int jack_client_create_thread(jack_client_t
* client
,
1689 int realtime
, /* boolean */
1690 thread_routine routine
,
1693 #ifdef __CLIENTDEBUG__
1694 JackGlobals::CheckContext("jack_client_create_thread");
1696 return JackThread::StartImp(thread
, priority
, realtime
, routine
, arg
);
1699 EXPORT
int jack_drop_real_time_scheduling(pthread_t thread
)
1701 return JackThread::DropRealTimeImp(thread
);
1704 EXPORT
int jack_client_stop_thread(jack_client_t
* client
, pthread_t thread
)
1706 #ifdef __CLIENTDEBUG__
1707 JackGlobals::CheckContext("jack_client_stop_thread");
1709 return JackThread::StopImp(thread
);
1712 EXPORT
int jack_client_kill_thread(jack_client_t
* client
, pthread_t thread
)
1714 #ifdef __CLIENTDEBUG__
1715 JackGlobals::CheckContext("jack_client_kill_thread");
1717 return JackThread::KillImp(thread
);
1721 EXPORT
void jack_set_thread_creator (jack_thread_creator_t jtc
)
1723 JackGlobals::fJackThreadCreator
= (jtc
== NULL
) ? pthread_create
: jtc
;
1728 EXPORT
int jack_internal_client_new (const char *client_name
,
1729 const char *load_name
,
1730 const char *load_init
)
1732 jack_error("jack_internal_client_new: deprecated");
1736 EXPORT
void jack_internal_client_close (const char *client_name
)
1738 jack_error("jack_internal_client_close: deprecated");
1741 EXPORT
char* jack_get_internal_client_name(jack_client_t
* ext_client
, jack_intclient_t intclient
)
1743 #ifdef __CLIENTDEBUG__
1744 JackGlobals::CheckContext("jack_get_internal_client_name");
1746 JackClient
* client
= (JackClient
*)ext_client
;
1747 if (client
== NULL
) {
1748 jack_error("jack_get_internal_client_name called with a NULL client");
1750 } else if (intclient
>= CLIENT_NUM
) {
1751 jack_error("jack_get_internal_client_name: incorrect client");
1754 return client
->GetInternalClientName(intclient
);
1758 EXPORT jack_intclient_t
jack_internal_client_handle(jack_client_t
* ext_client
, const char* client_name
, jack_status_t
* status
)
1760 #ifdef __CLIENTDEBUG__
1761 JackGlobals::CheckContext("jack_internal_client_handle");
1763 JackClient
* client
= (JackClient
*)ext_client
;
1764 if (client
== NULL
) {
1765 jack_error("jack_internal_client_handle called with a NULL client");
1768 jack_status_t my_status
;
1769 if (status
== NULL
) /* no status from caller? */
1770 status
= &my_status
; /* use local status word */
1771 *status
= (jack_status_t
)0;
1772 return client
->InternalClientHandle(client_name
, status
);
1776 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
)
1778 #ifdef __CLIENTDEBUG__
1779 JackGlobals::CheckContext("jack_internal_client_load_aux");
1781 JackClient
* client
= (JackClient
*)ext_client
;
1782 if (client
== NULL
) {
1783 jack_error("jack_internal_client_load called with a NULL client");
1787 jack_status_t my_status
;
1789 if (status
== NULL
) /* no status from caller? */
1790 status
= &my_status
; /* use local status word */
1791 *status
= (jack_status_t
)0;
1793 /* validate parameters */
1794 if ((options
& ~JackLoadOptions
)) {
1795 int my_status1
= *status
| (JackFailure
| JackInvalidOption
);
1796 *status
= (jack_status_t
)my_status1
;
1800 /* parse variable arguments */
1801 jack_varargs_parse(options
, ap
, &va
);
1802 return client
->InternalClientLoad(client_name
, options
, status
, &va
);
1806 EXPORT jack_intclient_t
jack_internal_client_load(jack_client_t
*client
, const char *client_name
, jack_options_t options
, jack_status_t
*status
, ...)
1809 va_start(ap
, status
);
1810 jack_intclient_t res
= jack_internal_client_load_aux(client
, client_name
, options
, status
, ap
);
1815 EXPORT jack_status_t
jack_internal_client_unload(jack_client_t
* ext_client
, jack_intclient_t intclient
)
1817 #ifdef __CLIENTDEBUG__
1818 JackGlobals::CheckContext("jack_internal_client_load");
1820 JackClient
* client
= (JackClient
*)ext_client
;
1821 if (client
== NULL
) {
1822 jack_error("jack_internal_client_unload called with a NULL client");
1823 return (jack_status_t
)(JackNoSuchClient
| JackFailure
);
1824 } else if (intclient
>= CLIENT_NUM
) {
1825 jack_error("jack_internal_client_unload: incorrect client");
1826 return (jack_status_t
)(JackNoSuchClient
| JackFailure
);
1828 jack_status_t my_status
;
1829 client
->InternalClientUnload(intclient
, &my_status
);
1842 // FIXME: We need these comming from build system
1851 jack_get_version_string()
1856 EXPORT
void jack_free(void* ptr
)