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 "JackPortType.h"
38 typedef void (*print_function
)(const char*);
39 typedef void *(*thread_routine
)(void*);
51 jack_get_version_string();
53 jack_client_t
* jack_client_new_aux(const char* client_name
,
54 jack_options_t options
,
55 jack_status_t
*status
);
57 LIB_EXPORT jack_client_t
* jack_client_open(const char* client_name
,
58 jack_options_t options
,
59 jack_status_t
*status
, ...);
60 LIB_EXPORT jack_client_t
* jack_client_new(const char* client_name
);
61 LIB_EXPORT
int jack_client_name_size(void);
62 LIB_EXPORT
char* jack_get_client_name(jack_client_t
*client
);
63 LIB_EXPORT
int jack_internal_client_new(const char* client_name
,
64 const char* load_name
,
65 const char* load_init
);
66 LIB_EXPORT
void jack_internal_client_close(const char* client_name
);
67 LIB_EXPORT
int jack_is_realtime(jack_client_t
*client
);
68 LIB_EXPORT
void jack_on_shutdown(jack_client_t
*client
,
69 JackShutdownCallback shutdown_callback
, void *arg
);
70 LIB_EXPORT
void jack_on_info_shutdown(jack_client_t
*client
,
71 JackInfoShutdownCallback shutdown_callback
, void *arg
);
72 LIB_EXPORT
int jack_set_process_callback(jack_client_t
*client
,
73 JackProcessCallback process_callback
,
75 LIB_EXPORT jack_nframes_t
jack_thread_wait(jack_client_t
*client
, int status
);
78 LIB_EXPORT jack_nframes_t
jack_cycle_wait(jack_client_t
*);
79 LIB_EXPORT
void jack_cycle_signal(jack_client_t
*, int status
);
80 LIB_EXPORT
int jack_set_process_thread(jack_client_t
* client
, JackThreadCallback fun
, void *arg
);
82 LIB_EXPORT
int jack_set_thread_init_callback(jack_client_t
*client
,
83 JackThreadInitCallback thread_init_callback
,
85 LIB_EXPORT
int jack_set_freewheel_callback(jack_client_t
*client
,
86 JackFreewheelCallback freewheel_callback
,
88 LIB_EXPORT
int jack_set_freewheel(jack_client_t
* client
, int onoff
);
89 LIB_EXPORT
int jack_set_buffer_size(jack_client_t
*client
, jack_nframes_t nframes
);
90 LIB_EXPORT
int jack_set_buffer_size_callback(jack_client_t
*client
,
91 JackBufferSizeCallback bufsize_callback
,
93 LIB_EXPORT
int jack_set_sample_rate_callback(jack_client_t
*client
,
94 JackSampleRateCallback srate_callback
,
96 LIB_EXPORT
int jack_set_client_registration_callback(jack_client_t
*,
97 JackClientRegistrationCallback
98 registration_callback
, void *arg
);
99 LIB_EXPORT
int jack_set_port_registration_callback(jack_client_t
*,
100 JackPortRegistrationCallback
101 registration_callback
, void *arg
);
102 LIB_EXPORT
int jack_set_port_connect_callback(jack_client_t
*,
103 JackPortConnectCallback
104 connect_callback
, void *arg
);
105 LIB_EXPORT
int jack_set_port_rename_callback(jack_client_t
*,
106 JackPortRenameCallback
107 rename_callback
, void *arg
);
108 LIB_EXPORT
int jack_set_graph_order_callback(jack_client_t
*,
109 JackGraphOrderCallback graph_callback
,
111 LIB_EXPORT
int jack_set_xrun_callback(jack_client_t
*,
112 JackXRunCallback xrun_callback
, void *arg
);
113 LIB_EXPORT
int jack_set_latency_callback(jack_client_t
*client
,
114 JackLatencyCallback latency_callback
, void *arg
);
116 LIB_EXPORT
int jack_activate(jack_client_t
*client
);
117 LIB_EXPORT
int jack_deactivate(jack_client_t
*client
);
118 LIB_EXPORT jack_port_t
* jack_port_register(jack_client_t
*client
,
119 const char* port_name
,
120 const char* port_type
,
122 unsigned long buffer_size
);
123 LIB_EXPORT
int jack_port_unregister(jack_client_t
*, jack_port_t
*);
124 LIB_EXPORT
void * jack_port_get_buffer(jack_port_t
*, jack_nframes_t
);
125 LIB_EXPORT
const char* jack_port_name(const jack_port_t
*port
);
126 LIB_EXPORT
const char* jack_port_short_name(const jack_port_t
*port
);
127 LIB_EXPORT
int jack_port_flags(const jack_port_t
*port
);
128 LIB_EXPORT
const char* jack_port_type(const jack_port_t
*port
);
129 LIB_EXPORT jack_port_type_id_t
jack_port_type_id(const jack_port_t
*port
);
130 LIB_EXPORT
int jack_port_is_mine(const jack_client_t
*, const jack_port_t
*port
);
131 LIB_EXPORT
int jack_port_connected(const jack_port_t
*port
);
132 LIB_EXPORT
int jack_port_connected_to(const jack_port_t
*port
,
133 const char* port_name
);
134 LIB_EXPORT
const char* * jack_port_get_connections(const jack_port_t
*port
);
135 LIB_EXPORT
const char* * jack_port_get_all_connections(const jack_client_t
*client
,
136 const jack_port_t
*port
);
137 LIB_EXPORT
int jack_port_tie(jack_port_t
*src
, jack_port_t
*dst
);
138 LIB_EXPORT
int jack_port_untie(jack_port_t
*port
);
141 LIB_EXPORT jack_nframes_t
jack_port_get_latency(jack_port_t
*port
);
142 LIB_EXPORT jack_nframes_t
jack_port_get_total_latency(jack_client_t
*,
144 LIB_EXPORT
void jack_port_set_latency(jack_port_t
*, jack_nframes_t
);
145 LIB_EXPORT
int jack_recompute_total_latency(jack_client_t
*, jack_port_t
* port
);
148 LIB_EXPORT
void jack_port_get_latency_range(jack_port_t
*port
, jack_latency_callback_mode_t mode
, jack_latency_range_t
*range
);
149 LIB_EXPORT
void jack_port_set_latency_range(jack_port_t
*port
, jack_latency_callback_mode_t mode
, jack_latency_range_t
*range
);
150 LIB_EXPORT
int jack_recompute_total_latencies(jack_client_t
*);
152 LIB_EXPORT
int jack_port_set_name(jack_port_t
*port
, const char* port_name
);
153 LIB_EXPORT
int jack_port_set_alias(jack_port_t
*port
, const char* alias
);
154 LIB_EXPORT
int jack_port_unset_alias(jack_port_t
*port
, const char* alias
);
155 LIB_EXPORT
int jack_port_get_aliases(const jack_port_t
*port
, char* const aliases
[2]);
156 LIB_EXPORT
int jack_port_request_monitor(jack_port_t
*port
, int onoff
);
157 LIB_EXPORT
int jack_port_request_monitor_by_name(jack_client_t
*client
,
158 const char* port_name
, int onoff
);
159 LIB_EXPORT
int jack_port_ensure_monitor(jack_port_t
*port
, int onoff
);
160 LIB_EXPORT
int jack_port_monitoring_input(jack_port_t
*port
);
161 LIB_EXPORT
int jack_connect(jack_client_t
*,
162 const char* source_port
,
163 const char* destination_port
);
164 LIB_EXPORT
int jack_disconnect(jack_client_t
*,
165 const char* source_port
,
166 const char* destination_port
);
167 LIB_EXPORT
int jack_port_disconnect(jack_client_t
*, jack_port_t
*);
168 LIB_EXPORT
int jack_port_name_size(void);
169 LIB_EXPORT
int jack_port_type_size(void);
170 LIB_EXPORT
size_t jack_port_type_get_buffer_size(jack_client_t
*client
, const char* port_type
);
171 LIB_EXPORT jack_nframes_t
jack_get_sample_rate(jack_client_t
*);
172 LIB_EXPORT jack_nframes_t
jack_get_buffer_size(jack_client_t
*);
173 LIB_EXPORT
const char* * jack_get_ports(jack_client_t
*,
174 const char* port_name_pattern
,
175 const char* type_name_pattern
,
176 unsigned long flags
);
177 LIB_EXPORT jack_port_t
* jack_port_by_name(jack_client_t
*, const char* port_name
);
178 LIB_EXPORT jack_port_t
* jack_port_by_id(jack_client_t
*client
,
179 jack_port_id_t port_id
);
180 LIB_EXPORT
int jack_engine_takeover_timebase(jack_client_t
*);
181 LIB_EXPORT jack_nframes_t
jack_frames_since_cycle_start(const jack_client_t
*);
182 LIB_EXPORT jack_time_t
jack_get_time();
183 LIB_EXPORT jack_nframes_t
jack_time_to_frames(const jack_client_t
*client
, jack_time_t usecs
);
184 LIB_EXPORT jack_time_t
jack_frames_to_time(const jack_client_t
*client
, jack_nframes_t frames
);
185 LIB_EXPORT jack_nframes_t
jack_frame_time(const jack_client_t
*);
186 LIB_EXPORT jack_nframes_t
jack_last_frame_time(const jack_client_t
*client
);
187 LIB_EXPORT
int jack_get_cycle_times(const jack_client_t
*client
,
188 jack_nframes_t
*current_frames
,
189 jack_time_t
*current_usecs
,
190 jack_time_t
*next_usecs
,
191 float *period_usecs
);
192 LIB_EXPORT
float jack_cpu_load(jack_client_t
*client
);
193 LIB_EXPORT jack_native_thread_t
jack_client_thread_id(jack_client_t
*);
194 LIB_EXPORT
void jack_set_error_function(print_function
);
195 LIB_EXPORT
void jack_set_info_function(print_function
);
197 LIB_EXPORT
float jack_get_max_delayed_usecs(jack_client_t
*client
);
198 LIB_EXPORT
float jack_get_xrun_delayed_usecs(jack_client_t
*client
);
199 LIB_EXPORT
void jack_reset_max_delayed_usecs(jack_client_t
*client
);
201 LIB_EXPORT
int jack_release_timebase(jack_client_t
*client
);
202 LIB_EXPORT
int jack_set_sync_callback(jack_client_t
*client
,
203 JackSyncCallback sync_callback
,
205 LIB_EXPORT
int jack_set_sync_timeout(jack_client_t
*client
,
206 jack_time_t timeout
);
207 LIB_EXPORT
int jack_set_timebase_callback(jack_client_t
*client
,
209 JackTimebaseCallback timebase_callback
,
211 LIB_EXPORT
int jack_transport_locate(jack_client_t
*client
,
212 jack_nframes_t frame
);
213 LIB_EXPORT jack_transport_state_t
jack_transport_query(const jack_client_t
*client
,
214 jack_position_t
*pos
);
215 LIB_EXPORT jack_nframes_t
jack_get_current_transport_frame(const jack_client_t
*client
);
216 LIB_EXPORT
int jack_transport_reposition(jack_client_t
*client
,
217 const jack_position_t
*pos
);
218 LIB_EXPORT
void jack_transport_start(jack_client_t
*client
);
219 LIB_EXPORT
void jack_transport_stop(jack_client_t
*client
);
220 LIB_EXPORT
void jack_get_transport_info(jack_client_t
*client
,
221 jack_transport_info_t
*tinfo
);
222 LIB_EXPORT
void jack_set_transport_info(jack_client_t
*client
,
223 jack_transport_info_t
*tinfo
);
225 LIB_EXPORT
int jack_client_real_time_priority(jack_client_t
*);
226 LIB_EXPORT
int jack_client_max_real_time_priority(jack_client_t
*);
227 LIB_EXPORT
int jack_acquire_real_time_scheduling(jack_native_thread_t thread
, int priority
);
228 LIB_EXPORT
int jack_client_create_thread(jack_client_t
* client
,
229 jack_native_thread_t
*thread
,
231 int realtime
, // boolean
232 thread_routine routine
,
234 LIB_EXPORT
int jack_drop_real_time_scheduling(jack_native_thread_t thread
);
236 LIB_EXPORT
int jack_client_stop_thread(jack_client_t
* client
, jack_native_thread_t thread
);
237 LIB_EXPORT
int jack_client_kill_thread(jack_client_t
* client
, jack_native_thread_t thread
);
239 LIB_EXPORT
void jack_set_thread_creator(jack_thread_creator_t jtc
);
241 LIB_EXPORT
char * jack_get_internal_client_name(jack_client_t
*client
,
242 jack_intclient_t intclient
);
243 LIB_EXPORT jack_intclient_t
jack_internal_client_handle(jack_client_t
*client
,
244 const char* client_name
,
245 jack_status_t
*status
);
246 LIB_EXPORT jack_intclient_t
jack_internal_client_load(jack_client_t
*client
,
247 const char* client_name
,
248 jack_options_t options
,
249 jack_status_t
*status
, ...);
251 LIB_EXPORT jack_status_t
jack_internal_client_unload(jack_client_t
*client
,
252 jack_intclient_t intclient
);
253 LIB_EXPORT
void jack_free(void* ptr
);
255 LIB_EXPORT
int jack_set_session_callback(jack_client_t
* ext_client
, JackSessionCallback session_callback
, void* arg
);
256 LIB_EXPORT jack_session_command_t
*jack_session_notify(jack_client_t
* ext_client
, const char* target
, jack_session_event_type_t ev_type
, const char* path
);
257 LIB_EXPORT
int jack_session_reply(jack_client_t
* ext_client
, jack_session_event_t
*event
);
258 LIB_EXPORT
void jack_session_event_free(jack_session_event_t
* ev
);
259 LIB_EXPORT
char* jack_client_get_uuid (jack_client_t
*client
);
260 LIB_EXPORT
char* jack_get_uuid_for_client_name(jack_client_t
* ext_client
, const char* client_name
);
261 LIB_EXPORT
char* jack_get_client_name_by_uuid(jack_client_t
* ext_client
, const char* client_uuid
);
262 LIB_EXPORT
int jack_reserve_client_name(jack_client_t
* ext_client
, const char* name
, const char* uuid
);
263 LIB_EXPORT
void jack_session_commands_free(jack_session_command_t
*cmds
);
264 LIB_EXPORT
int jack_client_has_session_callback(jack_client_t
*client
, const char* client_name
);
270 static inline bool CheckPort(jack_port_id_t port_index
)
272 return (port_index
> 0 && port_index
< PORT_NUM_MAX
);
275 static inline bool CheckBufferSize(jack_nframes_t buffer_size
)
277 return (buffer_size
>= 1 && buffer_size
<= BUFFER_SIZE_MAX
);
280 static inline void WaitGraphChange()
283 TLS key that is set only in RT thread, so never waits for pending
284 graph change in RT context (just read the current graph state).
287 if (jack_tls_get(JackGlobals::fRealTimeThread
) == NULL
) {
288 JackGraphManager
* manager
= GetGraphManager();
289 JackEngineControl
* control
= GetEngineControl();
292 if (manager
->IsPendingChange()) {
293 jack_log("WaitGraphChange...");
294 JackSleep(int(control
->fPeriodUsecs
* 1.1f
));
299 LIB_EXPORT
void jack_set_error_function(print_function func
)
301 jack_error_callback
= (func
== NULL
) ? &default_jack_error_callback
: func
;
304 LIB_EXPORT
void jack_set_info_function(print_function func
)
306 jack_info_callback
= (func
== NULL
) ? &default_jack_info_callback
: func
;
309 LIB_EXPORT jack_client_t
* jack_client_new(const char* client_name
)
311 JackGlobals::CheckContext("jack_client_new");
314 assert(JackGlobals::fOpenMutex
);
315 JackGlobals::fOpenMutex
->Lock();
316 jack_error("jack_client_new: deprecated");
317 int options
= JackUseExactName
;
318 if (getenv("JACK_START_SERVER") == NULL
) {
319 options
|= JackNoStartServer
;
321 jack_client_t
* res
= jack_client_new_aux(client_name
, (jack_options_t
)options
, NULL
);
322 JackGlobals::fOpenMutex
->Unlock();
324 } catch (std::bad_alloc
& e
) {
325 jack_error("Memory allocation error...");
328 jack_error("Unknown error...");
333 LIB_EXPORT
void* jack_port_get_buffer(jack_port_t
* port
, jack_nframes_t frames
)
335 JackGlobals::CheckContext("jack_port_get_buffer");
337 uintptr_t port_aux
= (uintptr_t)port
;
338 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
339 if (!CheckPort(myport
)) {
340 jack_error("jack_port_get_buffer called with an incorrect port %ld", myport
);
343 JackGraphManager
* manager
= GetGraphManager();
344 return (manager
? manager
->GetBuffer(myport
, frames
) : NULL
);
348 LIB_EXPORT
const char* jack_port_name(const jack_port_t
* port
)
350 JackGlobals::CheckContext("jack_port_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_name called with an incorrect port %ld", myport
);
358 JackGraphManager
* manager
= GetGraphManager();
359 return (manager
? manager
->GetPort(myport
)->GetName() : NULL
);
363 LIB_EXPORT
const char* jack_port_short_name(const jack_port_t
* port
)
365 JackGlobals::CheckContext("jack_port_short_name");
367 uintptr_t port_aux
= (uintptr_t)port
;
368 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
369 if (!CheckPort(myport
)) {
370 jack_error("jack_port_short_name called with an incorrect port %ld", myport
);
373 JackGraphManager
* manager
= GetGraphManager();
374 return (manager
? manager
->GetPort(myport
)->GetShortName() : NULL
);
378 LIB_EXPORT
int jack_port_flags(const jack_port_t
* port
)
380 JackGlobals::CheckContext("jack_port_flags");
382 uintptr_t port_aux
= (uintptr_t)port
;
383 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
384 if (!CheckPort(myport
)) {
385 jack_error("jack_port_flags called with an incorrect port %ld", myport
);
388 JackGraphManager
* manager
= GetGraphManager();
389 return (manager
? manager
->GetPort(myport
)->GetFlags() : -1);
393 LIB_EXPORT
const char* jack_port_type(const jack_port_t
* port
)
395 JackGlobals::CheckContext("jack_port_type");
397 uintptr_t port_aux
= (uintptr_t)port
;
398 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
399 if (!CheckPort(myport
)) {
400 jack_error("jack_port_flags called an incorrect port %ld", myport
);
403 JackGraphManager
* manager
= GetGraphManager();
404 return (manager
? manager
->GetPort(myport
)->GetType() : NULL
);
408 LIB_EXPORT jack_port_type_id_t
jack_port_type_id(const jack_port_t
*port
)
410 JackGlobals::CheckContext("jack_port_type_id");
412 uintptr_t port_aux
= (uintptr_t)port
;
413 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
414 if (!CheckPort(myport
)) {
415 jack_error("jack_port_type_id called an incorrect port %ld", myport
);
418 JackGraphManager
* manager
= GetGraphManager();
419 return (manager
? GetPortTypeId(manager
->GetPort(myport
)->GetType()) : 0);
423 LIB_EXPORT
int jack_port_connected(const jack_port_t
* port
)
425 JackGlobals::CheckContext("jack_port_connected");
427 uintptr_t port_aux
= (uintptr_t)port
;
428 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
429 if (!CheckPort(myport
)) {
430 jack_error("jack_port_connected called with an incorrect port %ld", myport
);
434 JackGraphManager
* manager
= GetGraphManager();
435 return (manager
? manager
->GetConnectionsNum(myport
) : -1);
439 LIB_EXPORT
int jack_port_connected_to(const jack_port_t
* port
, const char* port_name
)
441 JackGlobals::CheckContext("jack_port_connected_to");
443 uintptr_t port_aux
= (uintptr_t)port
;
444 jack_port_id_t src
= (jack_port_id_t
)port_aux
;
445 if (!CheckPort(src
)) {
446 jack_error("jack_port_connected_to called with an incorrect port %ld", src
);
448 } else if (port_name
== NULL
) {
449 jack_error("jack_port_connected_to called with a NULL port name");
453 JackGraphManager
* manager
= GetGraphManager();
454 jack_port_id_t dst
= (manager
? manager
->GetPort(port_name
) : NO_PORT
);
455 if (dst
== NO_PORT
) {
456 jack_error("Unknown destination port port_name = %s", port_name
);
459 return manager
->IsConnected(src
, dst
);
464 LIB_EXPORT
int jack_port_tie(jack_port_t
* src
, jack_port_t
* dst
)
466 JackGlobals::CheckContext("jack_port_tie");
468 uintptr_t src_aux
= (uintptr_t)src
;
469 jack_port_id_t mysrc
= (jack_port_id_t
)src_aux
;
470 if (!CheckPort(mysrc
)) {
471 jack_error("jack_port_tie called with a NULL src port");
474 uintptr_t dst_aux
= (uintptr_t)dst
;
475 jack_port_id_t mydst
= (jack_port_id_t
)dst_aux
;
476 if (!CheckPort(mydst
)) {
477 jack_error("jack_port_tie called with a NULL dst port");
480 JackGraphManager
* manager
= GetGraphManager();
481 if (manager
&& manager
->GetPort(mysrc
)->GetRefNum() != manager
->GetPort(mydst
)->GetRefNum()) {
482 jack_error("jack_port_tie called with ports not belonging to the same client");
485 return manager
->GetPort(mydst
)->Tie(mysrc
);
489 LIB_EXPORT
int jack_port_untie(jack_port_t
* port
)
491 JackGlobals::CheckContext("jack_port_untie");
493 uintptr_t port_aux
= (uintptr_t)port
;
494 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
495 if (!CheckPort(myport
)) {
496 jack_error("jack_port_untie called with an incorrect port %ld", myport
);
499 JackGraphManager
* manager
= GetGraphManager();
500 return (manager
? manager
->GetPort(myport
)->UnTie() : -1);
504 LIB_EXPORT jack_nframes_t
jack_port_get_latency(jack_port_t
* port
)
506 JackGlobals::CheckContext("jack_port_get_latency");
508 uintptr_t port_aux
= (uintptr_t)port
;
509 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
510 if (!CheckPort(myport
)) {
511 jack_error("jack_port_get_latency called with an incorrect port %ld", myport
);
515 JackGraphManager
* manager
= GetGraphManager();
516 return (manager
? manager
->GetPort(myport
)->GetLatency() : 0);
520 LIB_EXPORT
void jack_port_set_latency(jack_port_t
* port
, jack_nframes_t frames
)
522 JackGlobals::CheckContext("jack_port_set_latency");
524 uintptr_t port_aux
= (uintptr_t)port
;
525 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
526 if (!CheckPort(myport
)) {
527 jack_error("jack_port_set_latency called with an incorrect port %ld", myport
);
529 JackGraphManager
* manager
= GetGraphManager();
531 manager
->GetPort(myport
)->SetLatency(frames
);
535 LIB_EXPORT
void jack_port_get_latency_range(jack_port_t
*port
, jack_latency_callback_mode_t mode
, jack_latency_range_t
*range
)
537 JackGlobals::CheckContext("jack_port_get_latency_range");
539 uintptr_t port_aux
= (uintptr_t)port
;
540 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
541 if (!CheckPort(myport
)) {
542 jack_error("jack_port_get_latency_range called with an incorrect port %ld", myport
);
545 JackGraphManager
* manager
= GetGraphManager();
547 manager
->GetPort(myport
)->GetLatencyRange(mode
, range
);
551 LIB_EXPORT
void jack_port_set_latency_range(jack_port_t
*port
, jack_latency_callback_mode_t mode
, jack_latency_range_t
*range
)
553 JackGlobals::CheckContext("jack_port_set_latency_range");
555 uintptr_t port_aux
= (uintptr_t)port
;
556 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
557 if (!CheckPort(myport
)) {
558 jack_error("jack_port_set_latency_range called with an incorrect port %ld", myport
);
561 JackGraphManager
* manager
= GetGraphManager();
563 manager
->GetPort(myport
)->SetLatencyRange(mode
, range
);
567 LIB_EXPORT
int jack_recompute_total_latency(jack_client_t
* ext_client
, jack_port_t
* port
)
569 JackGlobals::CheckContext("jack_recompute_total_latency");
572 JackClient
* client
= (JackClient
*)ext_client
;
573 uintptr_t port_aux
= (uintptr_t)port
;
574 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
575 if (client
== NULL
) {
576 jack_error("jack_recompute_total_latency called with a NULL client");
578 } else if (!CheckPort(myport
)) {
579 jack_error("jack_recompute_total_latency called with a NULL port");
583 JackGraphManager
* manager
= GetGraphManager();
584 return (manager
? manager
->ComputeTotalLatency(myport
) : -1);
588 LIB_EXPORT
int jack_recompute_total_latencies(jack_client_t
* ext_client
)
590 JackGlobals::CheckContext("jack_recompute_total_latencies");
592 JackClient
* client
= (JackClient
*)ext_client
;
593 if (client
== NULL
) {
594 jack_error("jack_recompute_total_latencies called with a NULL client");
597 return client
->ComputeTotalLatencies();
601 LIB_EXPORT
int jack_port_set_name(jack_port_t
* port
, const char* name
)
603 JackGlobals::CheckContext("jack_port_set_name");
605 uintptr_t port_aux
= (uintptr_t)port
;
606 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
607 if (!CheckPort(myport
)) {
608 jack_error("jack_port_set_name called with an incorrect port %ld", myport
);
610 } else if (name
== NULL
) {
611 jack_error("jack_port_set_name called with a NULL port name");
614 JackClient
* client
= NULL
;
615 for (int i
= 0; i
< CLIENT_NUM
; i
++) {
616 // Find a valid client
617 if ((client
= JackGlobals::fClientTable
[i
])) {
621 return (client
) ? client
->PortRename(myport
, name
) : -1;
625 LIB_EXPORT
int jack_port_set_alias(jack_port_t
* port
, const char* name
)
627 JackGlobals::CheckContext("jack_port_set_alias");
629 uintptr_t port_aux
= (uintptr_t)port
;
630 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
631 if (!CheckPort(myport
)) {
632 jack_error("jack_port_set_alias called with an incorrect port %ld", myport
);
634 } else if (name
== NULL
) {
635 jack_error("jack_port_set_alias called with a NULL port name");
638 JackGraphManager
* manager
= GetGraphManager();
639 return (manager
? manager
->GetPort(myport
)->SetAlias(name
) : -1);
643 LIB_EXPORT
int jack_port_unset_alias(jack_port_t
* port
, const char* name
)
645 JackGlobals::CheckContext("jack_port_unset_alias");
647 uintptr_t port_aux
= (uintptr_t)port
;
648 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
649 if (!CheckPort(myport
)) {
650 jack_error("jack_port_unset_alias called with an incorrect port %ld", myport
);
652 } else if (name
== NULL
) {
653 jack_error("jack_port_unset_alias called with a NULL port name");
656 JackGraphManager
* manager
= GetGraphManager();
657 return (manager
? manager
->GetPort(myport
)->UnsetAlias(name
) : -1);
661 LIB_EXPORT
int jack_port_get_aliases(const jack_port_t
* port
, char* const aliases
[2])
663 JackGlobals::CheckContext("jack_port_get_aliases");
665 uintptr_t port_aux
= (uintptr_t)port
;
666 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
667 if (!CheckPort(myport
)) {
668 jack_error("jack_port_get_aliases called with an incorrect port %ld", myport
);
671 JackGraphManager
* manager
= GetGraphManager();
672 return (manager
? manager
->GetPort(myport
)->GetAliases(aliases
) : -1);
676 LIB_EXPORT
int jack_port_request_monitor(jack_port_t
* port
, int onoff
)
678 JackGlobals::CheckContext("jack_port_request_monitor");
680 uintptr_t port_aux
= (uintptr_t)port
;
681 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
682 if (!CheckPort(myport
)) {
683 jack_error("jack_port_request_monitor called with an incorrect port %ld", myport
);
686 JackGraphManager
* manager
= GetGraphManager();
687 return (manager
? manager
->RequestMonitor(myport
, onoff
) : -1);
691 LIB_EXPORT
int jack_port_request_monitor_by_name(jack_client_t
* ext_client
, const char* port_name
, int onoff
)
693 JackGlobals::CheckContext("jack_port_request_monitor_by_name");
695 JackClient
* client
= (JackClient
*)ext_client
;
696 if (client
== NULL
) {
697 jack_error("jack_port_request_monitor_by_name called with a NULL client");
700 JackGraphManager
* manager
= GetGraphManager();
703 jack_port_id_t myport
= manager
->GetPort(port_name
);
704 if (!CheckPort(myport
)) {
705 jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name
);
708 return manager
->RequestMonitor(myport
, onoff
);
713 LIB_EXPORT
int jack_port_ensure_monitor(jack_port_t
* port
, int onoff
)
715 JackGlobals::CheckContext("jack_port_ensure_monitor");
717 uintptr_t port_aux
= (uintptr_t)port
;
718 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
719 if (!CheckPort(myport
)) {
720 jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport
);
723 JackGraphManager
* manager
= GetGraphManager();
724 return (manager
? manager
->GetPort(myport
)->EnsureMonitor(onoff
) : -1);
728 LIB_EXPORT
int jack_port_monitoring_input(jack_port_t
* port
)
730 JackGlobals::CheckContext("jack_port_monitoring_input");
732 uintptr_t port_aux
= (uintptr_t)port
;
733 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
734 if (!CheckPort(myport
)) {
735 jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport
);
738 JackGraphManager
* manager
= GetGraphManager();
739 return (manager
? manager
->GetPort(myport
)->MonitoringInput() : -1);
743 LIB_EXPORT
int jack_is_realtime(jack_client_t
* ext_client
)
745 JackGlobals::CheckContext("jack_is_realtime");
747 JackClient
* client
= (JackClient
*)ext_client
;
748 if (client
== NULL
) {
749 jack_error("jack_is_realtime called with a NULL client");
752 JackEngineControl
* control
= GetEngineControl();
753 return (control
? control
->fRealTime
: -1);
757 LIB_EXPORT
void jack_on_shutdown(jack_client_t
* ext_client
, JackShutdownCallback callback
, void* arg
)
759 JackGlobals::CheckContext("jack_on_shutdown");
761 JackClient
* client
= (JackClient
*)ext_client
;
762 if (client
== NULL
) {
763 jack_error("jack_on_shutdown called with a NULL client");
765 client
->OnShutdown(callback
, arg
);
769 LIB_EXPORT
void jack_on_info_shutdown(jack_client_t
* ext_client
, JackInfoShutdownCallback callback
, void* arg
)
771 JackGlobals::CheckContext("jack_on_info_shutdown");
773 JackClient
* client
= (JackClient
*)ext_client
;
774 if (client
== NULL
) {
775 jack_error("jack_on_info_shutdown called with a NULL client");
777 client
->OnInfoShutdown(callback
, arg
);
781 LIB_EXPORT
int jack_set_process_callback(jack_client_t
* ext_client
, JackProcessCallback callback
, void* arg
)
783 JackGlobals::CheckContext("jack_set_process_callback");
785 JackClient
* client
= (JackClient
*)ext_client
;
786 if (client
== NULL
) {
787 jack_error("jack_set_process_callback called with a NULL client");
790 return client
->SetProcessCallback(callback
, arg
);
794 LIB_EXPORT jack_nframes_t
jack_thread_wait(jack_client_t
* ext_client
, int status
)
796 JackGlobals::CheckContext("jack_thread_wait");
798 JackClient
* client
= (JackClient
*)ext_client
;
799 if (client
== NULL
) {
800 jack_error("jack_thread_wait called with a NULL client");
803 jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
808 LIB_EXPORT jack_nframes_t
jack_cycle_wait(jack_client_t
* ext_client
)
810 JackGlobals::CheckContext("jack_cycle_wait");
812 JackClient
* client
= (JackClient
*)ext_client
;
813 if (client
== NULL
) {
814 jack_error("jack_cycle_wait called with a NULL client");
817 return client
->CycleWait();
821 LIB_EXPORT
void jack_cycle_signal(jack_client_t
* ext_client
, int status
)
823 JackGlobals::CheckContext("jack_cycle_signal");
825 JackClient
* client
= (JackClient
*)ext_client
;
826 if (client
== NULL
) {
827 jack_error("jack_cycle_signal called with a NULL client");
829 client
->CycleSignal(status
);
833 LIB_EXPORT
int jack_set_process_thread(jack_client_t
* ext_client
, JackThreadCallback fun
, void *arg
)
835 JackGlobals::CheckContext("jack_set_process_thread");
837 JackClient
* client
= (JackClient
*)ext_client
;
838 if (client
== NULL
) {
839 jack_error("jack_set_process_thread called with a NULL client");
842 return client
->SetProcessThread(fun
, arg
);
846 LIB_EXPORT
int jack_set_freewheel_callback(jack_client_t
* ext_client
, JackFreewheelCallback freewheel_callback
, void* arg
)
848 JackGlobals::CheckContext("jack_set_freewheel_callback");
850 JackClient
* client
= (JackClient
*)ext_client
;
851 if (client
== NULL
) {
852 jack_error("jack_set_freewheel_callback called with a NULL client");
855 return client
->SetFreewheelCallback(freewheel_callback
, arg
);
859 LIB_EXPORT
int jack_set_freewheel(jack_client_t
* ext_client
, int onoff
)
861 JackGlobals::CheckContext("jack_set_freewheel");
863 JackClient
* client
= (JackClient
*)ext_client
;
864 if (client
== NULL
) {
865 jack_error("jack_set_freewheel called with a NULL client");
868 return client
->SetFreeWheel(onoff
);
872 LIB_EXPORT
int jack_set_buffer_size(jack_client_t
* ext_client
, jack_nframes_t buffer_size
)
874 JackGlobals::CheckContext("jack_set_buffer_size");
876 JackClient
* client
= (JackClient
*)ext_client
;
877 if (client
== NULL
) {
878 jack_error("jack_set_buffer_size called with a NULL client");
880 } else if (!CheckBufferSize(buffer_size
)) {
883 return client
->SetBufferSize(buffer_size
);
887 LIB_EXPORT
int jack_set_buffer_size_callback(jack_client_t
* ext_client
, JackBufferSizeCallback bufsize_callback
, void* arg
)
889 JackGlobals::CheckContext("jack_set_buffer_size_callback");
891 JackClient
* client
= (JackClient
*)ext_client
;
892 if (client
== NULL
) {
893 jack_error("jack_set_buffer_size_callback called with a NULL client");
896 return client
->SetBufferSizeCallback(bufsize_callback
, arg
);
900 LIB_EXPORT
int jack_set_sample_rate_callback(jack_client_t
* ext_client
, JackSampleRateCallback srate_callback
, void* arg
)
902 JackGlobals::CheckContext("jack_set_sample_rate_callback");
904 JackClient
* client
= (JackClient
*)ext_client
;
905 if (client
== NULL
) {
906 jack_error("jack_set_sample_rate_callback called with a NULL client");
909 return client
->SetSampleRateCallback(srate_callback
, arg
);
913 LIB_EXPORT
int jack_set_client_registration_callback(jack_client_t
* ext_client
, JackClientRegistrationCallback registration_callback
, void* arg
)
915 JackGlobals::CheckContext("jack_set_client_registration_callback");
917 JackClient
* client
= (JackClient
*)ext_client
;
918 if (client
== NULL
) {
919 jack_error("jack_set_client_registration_callback called with a NULL client");
922 return client
->SetClientRegistrationCallback(registration_callback
, arg
);
926 LIB_EXPORT
int jack_set_port_registration_callback(jack_client_t
* ext_client
, JackPortRegistrationCallback registration_callback
, void* arg
)
928 JackGlobals::CheckContext("jack_set_port_registration_callback");
930 JackClient
* client
= (JackClient
*)ext_client
;
931 if (client
== NULL
) {
932 jack_error("jack_set_port_registration_callback called with a NULL client");
935 return client
->SetPortRegistrationCallback(registration_callback
, arg
);
939 LIB_EXPORT
int jack_set_port_connect_callback(jack_client_t
* ext_client
, JackPortConnectCallback portconnect_callback
, void* arg
)
941 JackGlobals::CheckContext("jack_set_port_connect_callback");
943 JackClient
* client
= (JackClient
*)ext_client
;
944 if (client
== NULL
) {
945 jack_error("jack_set_port_connect_callback called with a NULL client");
948 return client
->SetPortConnectCallback(portconnect_callback
, arg
);
952 LIB_EXPORT
int jack_set_port_rename_callback(jack_client_t
* ext_client
, JackPortRenameCallback rename_callback
, void* arg
)
954 JackGlobals::CheckContext("jack_set_port_rename_callback");
956 JackClient
* client
= (JackClient
*)ext_client
;
957 if (client
== NULL
) {
958 jack_error("jack_set_port_rename_callback called with a NULL client");
961 return client
->SetPortRenameCallback(rename_callback
, arg
);
965 LIB_EXPORT
int jack_set_graph_order_callback(jack_client_t
* ext_client
, JackGraphOrderCallback graph_callback
, void* arg
)
967 JackGlobals::CheckContext("jack_set_graph_order_callback");
969 JackClient
* client
= (JackClient
*)ext_client
;
970 jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client
, client
);
971 if (client
== NULL
) {
972 jack_error("jack_set_graph_order_callback called with a NULL client");
975 return client
->SetGraphOrderCallback(graph_callback
, arg
);
979 LIB_EXPORT
int jack_set_xrun_callback(jack_client_t
* ext_client
, JackXRunCallback xrun_callback
, void* arg
)
981 JackGlobals::CheckContext("jack_set_xrun_callback");
983 JackClient
* client
= (JackClient
*)ext_client
;
984 if (client
== NULL
) {
985 jack_error("jack_set_xrun_callback called with a NULL client");
988 return client
->SetXRunCallback(xrun_callback
, arg
);
992 LIB_EXPORT
int jack_set_latency_callback(jack_client_t
* ext_client
, JackLatencyCallback latency_callback
, void *arg
)
994 JackGlobals::CheckContext("jack_set_latency_callback");
996 JackClient
* client
= (JackClient
*)ext_client
;
997 if (client
== NULL
) {
998 jack_error("jack_set_latency_callback called with a NULL client");
1001 return client
->SetLatencyCallback(latency_callback
, arg
);
1005 LIB_EXPORT
int jack_set_thread_init_callback(jack_client_t
* ext_client
, JackThreadInitCallback init_callback
, void *arg
)
1007 JackGlobals::CheckContext("jack_set_thread_init_callback");
1009 JackClient
* client
= (JackClient
*)ext_client
;
1010 jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client
, client
);
1011 if (client
== NULL
) {
1012 jack_error("jack_set_thread_init_callback called with a NULL client");
1015 return client
->SetInitCallback(init_callback
, arg
);
1019 LIB_EXPORT
int jack_activate(jack_client_t
* ext_client
)
1021 JackGlobals::CheckContext("jack_activate");
1023 JackClient
* client
= (JackClient
*)ext_client
;
1024 if (client
== NULL
) {
1025 jack_error("jack_activate called with a NULL client");
1028 return client
->Activate();
1032 LIB_EXPORT
int jack_deactivate(jack_client_t
* ext_client
)
1034 JackGlobals::CheckContext("jack_deactivate");
1036 JackClient
* client
= (JackClient
*)ext_client
;
1037 if (client
== NULL
) {
1038 jack_error("jack_deactivate called with a NULL client");
1041 return client
->Deactivate();
1045 LIB_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
)
1047 JackGlobals::CheckContext("jack_port_register");
1049 JackClient
* client
= (JackClient
*)ext_client
;
1050 if (client
== NULL
) {
1051 jack_error("jack_port_register called with a NULL client");
1053 } else if ((port_name
== NULL
) || (port_type
== NULL
)) {
1054 jack_error("jack_port_register called with a NULL port name or a NULL port_type");
1057 return (jack_port_t
*)((uintptr_t)client
->PortRegister(port_name
, port_type
, flags
, buffer_size
));
1061 LIB_EXPORT
int jack_port_unregister(jack_client_t
* ext_client
, jack_port_t
* port
)
1063 JackGlobals::CheckContext("jack_port_unregister");
1065 JackClient
* client
= (JackClient
*)ext_client
;
1066 if (client
== NULL
) {
1067 jack_error("jack_port_unregister called with a NULL client");
1070 uintptr_t port_aux
= (uintptr_t)port
;
1071 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1072 if (!CheckPort(myport
)) {
1073 jack_error("jack_port_unregister called with an incorrect port %ld", myport
);
1076 return client
->PortUnRegister(myport
);
1079 LIB_EXPORT
int jack_port_is_mine(const jack_client_t
* ext_client
, const jack_port_t
* port
)
1081 JackGlobals::CheckContext("jack_port_is_mine");
1083 JackClient
* client
= (JackClient
*)ext_client
;
1084 if (client
== NULL
) {
1085 jack_error("jack_port_is_mine called with a NULL client");
1088 uintptr_t port_aux
= (uintptr_t)port
;
1089 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1090 if (!CheckPort(myport
)) {
1091 jack_error("jack_port_is_mine called with an incorrect port %ld", myport
);
1094 return client
->PortIsMine(myport
);
1097 LIB_EXPORT
const char** jack_port_get_connections(const jack_port_t
* port
)
1099 JackGlobals::CheckContext("jack_port_get_connections");
1101 uintptr_t port_aux
= (uintptr_t)port
;
1102 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1103 if (!CheckPort(myport
)) {
1104 jack_error("jack_port_get_connections called with an incorrect port %ld", myport
);
1108 JackGraphManager
* manager
= GetGraphManager();
1109 return (manager
? manager
->GetConnections(myport
) : NULL
);
1113 // Calling client does not need to "own" the port
1114 LIB_EXPORT
const char** jack_port_get_all_connections(const jack_client_t
* ext_client
, const jack_port_t
* port
)
1116 JackGlobals::CheckContext("jack_port_get_all_connections");
1118 JackClient
* client
= (JackClient
*)ext_client
;
1119 if (client
== NULL
) {
1120 jack_error("jack_port_get_all_connections called with a NULL client");
1124 uintptr_t port_aux
= (uintptr_t)port
;
1125 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1126 if (!CheckPort(myport
)) {
1127 jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport
);
1131 JackGraphManager
* manager
= GetGraphManager();
1132 return (manager
? manager
->GetConnections(myport
) : NULL
);
1136 LIB_EXPORT jack_nframes_t
jack_port_get_total_latency(jack_client_t
* ext_client
, jack_port_t
* port
)
1138 JackGlobals::CheckContext("jack_port_get_total_latency");
1140 JackClient
* client
= (JackClient
*)ext_client
;
1141 if (client
== NULL
) {
1142 jack_error("jack_port_get_total_latency called with a NULL client");
1146 uintptr_t port_aux
= (uintptr_t)port
;
1147 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1148 if (!CheckPort(myport
)) {
1149 jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport
);
1153 JackGraphManager
* manager
= GetGraphManager();
1155 manager
->ComputeTotalLatency(myport
);
1156 return manager
->GetPort(myport
)->GetTotalLatency();
1163 LIB_EXPORT
int jack_connect(jack_client_t
* ext_client
, const char* src
, const char* dst
)
1165 JackGlobals::CheckContext("jack_connect");
1167 JackClient
* client
= (JackClient
*)ext_client
;
1168 if (client
== NULL
) {
1169 jack_error("jack_connect called with a NULL client");
1171 } else if ((src
== NULL
) || (dst
== NULL
)) {
1172 jack_error("jack_connect called with a NULL port name");
1175 return client
->PortConnect(src
, dst
);
1179 LIB_EXPORT
int jack_disconnect(jack_client_t
* ext_client
, const char* src
, const char* dst
)
1181 JackGlobals::CheckContext("jack_disconnect");
1183 JackClient
* client
= (JackClient
*)ext_client
;
1184 if (client
== NULL
) {
1185 jack_error("jack_disconnect called with a NULL client");
1187 } else if ((src
== NULL
) || (dst
== NULL
)) {
1188 jack_error("jack_disconnect called with a NULL port name");
1191 return client
->PortDisconnect(src
, dst
);
1195 LIB_EXPORT
int jack_port_disconnect(jack_client_t
* ext_client
, jack_port_t
* src
)
1197 JackGlobals::CheckContext("jack_port_disconnect");
1199 JackClient
* client
= (JackClient
*)ext_client
;
1200 if (client
== NULL
) {
1201 jack_error("jack_port_disconnect called with a NULL client");
1204 uintptr_t port_aux
= (uintptr_t)src
;
1205 jack_port_id_t myport
= (jack_port_id_t
)port_aux
;
1206 if (!CheckPort(myport
)) {
1207 jack_error("jack_port_disconnect called with an incorrect port %ld", myport
);
1210 return client
->PortDisconnect(myport
);
1213 LIB_EXPORT jack_nframes_t
jack_get_sample_rate(jack_client_t
* ext_client
)
1215 JackGlobals::CheckContext("jack_get_sample_rate");
1217 JackClient
* client
= (JackClient
*)ext_client
;
1218 if (client
== NULL
) {
1219 jack_error("jack_get_sample_rate called with a NULL client");
1222 JackEngineControl
* control
= GetEngineControl();
1223 return (control
? control
->fSampleRate
: 0);
1227 LIB_EXPORT jack_nframes_t
jack_get_buffer_size(jack_client_t
* ext_client
)
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 LIB_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 JackGlobals::CheckContext("jack_get_ports");
1245 JackClient
* client
= (JackClient
*)ext_client
;
1246 if (client
== NULL
) {
1247 jack_error("jack_get_ports called with a NULL client");
1250 JackGraphManager
* manager
= GetGraphManager();
1251 return (manager
? manager
->GetPorts(port_name_pattern
, type_name_pattern
, flags
) : NULL
);
1254 LIB_EXPORT jack_port_t
* jack_port_by_name(jack_client_t
* ext_client
, const char* portname
)
1256 JackGlobals::CheckContext("jack_port_by_name");
1258 JackClient
* client
= (JackClient
*)ext_client
;
1259 if (client
== NULL
) {
1260 jack_error("jack_get_ports called with a NULL client");
1264 if (portname
== NULL
) {
1265 jack_error("jack_port_by_name called with a NULL port name");
1268 JackGraphManager
* manager
= GetGraphManager();
1271 int res
= manager
->GetPort(portname
); // returns a port index at least > 1
1272 return (res
== NO_PORT
) ? NULL
: (jack_port_t
*)((uintptr_t)res
);
1276 LIB_EXPORT jack_port_t
* jack_port_by_id(jack_client_t
* ext_client
, jack_port_id_t id
)
1278 JackGlobals::CheckContext("jack_port_by_id");
1280 /* jack_port_t* type is actually the port index */
1281 return (jack_port_t
*)((uintptr_t)id
);
1284 LIB_EXPORT
int jack_engine_takeover_timebase(jack_client_t
* ext_client
)
1286 JackGlobals::CheckContext("jack_engine_takeover_timebase");
1288 JackClient
* client
= (JackClient
*)ext_client
;
1289 if (client
== NULL
) {
1290 jack_error("jack_engine_takeover_timebase called with a NULL client");
1293 jack_error("jack_engine_takeover_timebase: deprecated\n");
1298 LIB_EXPORT jack_nframes_t
jack_frames_since_cycle_start(const jack_client_t
* ext_client
)
1300 JackGlobals::CheckContext("jack_frames_since_cycle_start");
1303 JackEngineControl
* control
= GetEngineControl();
1305 control
->ReadFrameTime(&timer
);
1306 return timer
.FramesSinceCycleStart(GetMicroSeconds(), control
->fSampleRate
);
1312 LIB_EXPORT jack_time_t
jack_get_time()
1314 JackGlobals::CheckContext("jack_get_time");
1316 return GetMicroSeconds();
1319 LIB_EXPORT jack_time_t
jack_frames_to_time(const jack_client_t
* ext_client
, jack_nframes_t frames
)
1321 JackGlobals::CheckContext("jack_frames_to_time");
1323 JackClient
* client
= (JackClient
*)ext_client
;
1324 if (client
== NULL
) {
1325 jack_error("jack_frames_to_time called with a NULL client");
1329 JackEngineControl
* control
= GetEngineControl();
1331 control
->ReadFrameTime(&timer
);
1332 return timer
.Frames2Time(frames
, control
->fBufferSize
);
1339 LIB_EXPORT jack_nframes_t
jack_time_to_frames(const jack_client_t
* ext_client
, jack_time_t usecs
)
1341 JackGlobals::CheckContext("jack_time_to_frames");
1343 JackClient
* client
= (JackClient
*)ext_client
;
1344 if (client
== NULL
) {
1345 jack_error("jack_time_to_frames called with a NULL client");
1349 JackEngineControl
* control
= GetEngineControl();
1351 control
->ReadFrameTime(&timer
);
1352 return timer
.Time2Frames(usecs
, control
->fBufferSize
);
1359 LIB_EXPORT jack_nframes_t
jack_frame_time(const jack_client_t
* ext_client
)
1361 JackGlobals::CheckContext("jack_frame_time");
1363 return jack_time_to_frames(ext_client
, GetMicroSeconds());
1366 LIB_EXPORT jack_nframes_t
jack_last_frame_time(const jack_client_t
* ext_client
)
1368 JackGlobals::CheckContext("jack_last_frame_time");
1370 JackEngineControl
* control
= GetEngineControl();
1371 return (control
) ? control
->fFrameTimer
.ReadCurrentState()->CurFrame() : 0;
1374 LIB_EXPORT
int jack_get_cycle_times(const jack_client_t
*client
,
1375 jack_nframes_t
*current_frames
,
1376 jack_time_t
*current_usecs
,
1377 jack_time_t
*next_usecs
,
1378 float *period_usecs
)
1380 JackGlobals::CheckContext("jack_get_cycle_times");
1382 JackEngineControl
* control
= GetEngineControl();
1385 control
->ReadFrameTime(&timer
);
1386 return timer
.GetCycleTimes(current_frames
, current_usecs
, next_usecs
, period_usecs
);
1392 LIB_EXPORT
float jack_cpu_load(jack_client_t
* ext_client
)
1394 JackGlobals::CheckContext("jack_cpu_load");
1396 JackClient
* client
= (JackClient
*)ext_client
;
1397 if (client
== NULL
) {
1398 jack_error("jack_cpu_load called with a NULL client");
1401 JackEngineControl
* control
= GetEngineControl();
1402 return (control
? control
->fCPULoad
: 0.0f
);
1406 LIB_EXPORT jack_native_thread_t
jack_client_thread_id(jack_client_t
* ext_client
)
1408 JackGlobals::CheckContext("jack_client_thread_id");
1410 JackClient
* client
= (JackClient
*)ext_client
;
1411 if (client
== NULL
) {
1412 jack_error("jack_client_thread_id called with a NULL client");
1413 return (jack_native_thread_t
)NULL
;
1415 return client
->GetThreadID();
1419 LIB_EXPORT
char* jack_get_client_name(jack_client_t
* ext_client
)
1421 JackGlobals::CheckContext("jack_get_client_name");
1423 JackClient
* client
= (JackClient
*)ext_client
;
1424 if (client
== NULL
) {
1425 jack_error("jack_get_client_name called with a NULL client");
1428 return client
->GetClientControl()->fName
;
1432 LIB_EXPORT
int jack_client_name_size(void)
1434 return JACK_CLIENT_NAME_SIZE
;
1437 LIB_EXPORT
int jack_port_name_size(void)
1439 return REAL_JACK_PORT_NAME_SIZE
;
1442 LIB_EXPORT
int jack_port_type_size(void)
1444 return JACK_PORT_TYPE_SIZE
;
1447 LIB_EXPORT
size_t jack_port_type_get_buffer_size(jack_client_t
* ext_client
, const char* port_type
)
1449 JackGlobals::CheckContext("jack_port_type_get_buffer_size");
1451 JackClient
* client
= (JackClient
*)ext_client
;
1452 if (client
== NULL
) {
1453 jack_error("jack_port_type_get_buffer_size called with a NULL client");
1456 jack_port_type_id_t port_id
= GetPortTypeId(port_type
);
1457 if (port_id
== PORT_TYPES_MAX
) {
1458 jack_error("jack_port_type_get_buffer_size called with an unknown port type = %s", port_type
);
1461 return GetPortType(port_id
)->size();
1467 LIB_EXPORT
int jack_release_timebase(jack_client_t
* ext_client
)
1469 JackGlobals::CheckContext("jack_release_timebase");
1471 JackClient
* client
= (JackClient
*)ext_client
;
1472 if (client
== NULL
) {
1473 jack_error("jack_release_timebase called with a NULL client");
1476 return client
->ReleaseTimebase();
1480 LIB_EXPORT
int jack_set_sync_callback(jack_client_t
* ext_client
, JackSyncCallback sync_callback
, void *arg
)
1482 JackGlobals::CheckContext("jack_set_sync_callback");
1484 JackClient
* client
= (JackClient
*)ext_client
;
1485 if (client
== NULL
) {
1486 jack_error("jack_set_sync_callback called with a NULL client");
1489 return client
->SetSyncCallback(sync_callback
, arg
);
1493 LIB_EXPORT
int jack_set_sync_timeout(jack_client_t
* ext_client
, jack_time_t timeout
)
1495 JackGlobals::CheckContext("jack_set_sync_timeout");
1497 JackClient
* client
= (JackClient
*)ext_client
;
1498 if (client
== NULL
) {
1499 jack_error("jack_set_sync_timeout called with a NULL client");
1502 return client
->SetSyncTimeout(timeout
);
1506 LIB_EXPORT
int jack_set_timebase_callback(jack_client_t
* ext_client
, int conditional
, JackTimebaseCallback timebase_callback
, void* arg
)
1508 JackGlobals::CheckContext("jack_set_timebase_callback");
1510 JackClient
* client
= (JackClient
*)ext_client
;
1511 if (client
== NULL
) {
1512 jack_error("jack_set_timebase_callback called with a NULL client");
1515 return client
->SetTimebaseCallback(conditional
, timebase_callback
, arg
);
1519 LIB_EXPORT
int jack_transport_locate(jack_client_t
* ext_client
, jack_nframes_t frame
)
1521 JackGlobals::CheckContext("jack_transport_locate");
1523 JackClient
* client
= (JackClient
*)ext_client
;
1524 if (client
== NULL
) {
1525 jack_error("jack_transport_locate called with a NULL client");
1528 client
->TransportLocate(frame
);
1533 LIB_EXPORT jack_transport_state_t
jack_transport_query(const jack_client_t
* ext_client
, jack_position_t
* pos
)
1535 JackGlobals::CheckContext("jack_transport_query");
1537 JackClient
* client
= (JackClient
*)ext_client
;
1538 if (client
== NULL
) {
1539 jack_error("jack_transport_query called with a NULL client");
1540 return JackTransportStopped
;
1542 return client
->TransportQuery(pos
);
1546 LIB_EXPORT jack_nframes_t
jack_get_current_transport_frame(const jack_client_t
* ext_client
)
1548 JackGlobals::CheckContext("jack_get_current_transport_frame");
1550 JackClient
* client
= (JackClient
*)ext_client
;
1551 if (client
== NULL
) {
1552 jack_error("jack_get_current_transport_frame called with a NULL client");
1555 return client
->GetCurrentTransportFrame();
1559 LIB_EXPORT
int jack_transport_reposition(jack_client_t
* ext_client
, const jack_position_t
* pos
)
1561 JackGlobals::CheckContext("jack_transport_reposition");
1563 JackClient
* client
= (JackClient
*)ext_client
;
1564 if (client
== NULL
) {
1565 jack_error("jack_transport_reposition called with a NULL client");
1568 client
->TransportReposition(pos
);
1573 LIB_EXPORT
void jack_transport_start(jack_client_t
* ext_client
)
1575 JackGlobals::CheckContext("jack_transport_start");
1577 JackClient
* client
= (JackClient
*)ext_client
;
1578 if (client
== NULL
) {
1579 jack_error("jack_transport_start called with a NULL client");
1581 client
->TransportStart();
1585 LIB_EXPORT
void jack_transport_stop(jack_client_t
* ext_client
)
1587 JackGlobals::CheckContext("jack_transport_stop");
1589 JackClient
* client
= (JackClient
*)ext_client
;
1590 if (client
== NULL
) {
1591 jack_error("jack_transport_stop called with a NULL client");
1593 client
->TransportStop();
1598 LIB_EXPORT
void jack_get_transport_info(jack_client_t
* ext_client
, jack_transport_info_t
* tinfo
)
1600 JackGlobals::CheckContext("jack_get_transport_info");
1602 jack_error("jack_get_transport_info: deprecated");
1604 memset(tinfo
, 0, sizeof(jack_transport_info_t
));
1607 LIB_EXPORT
void jack_set_transport_info(jack_client_t
* ext_client
, jack_transport_info_t
* tinfo
)
1609 JackGlobals::CheckContext("jack_set_transport_info");
1611 jack_error("jack_set_transport_info: deprecated");
1613 memset(tinfo
, 0, sizeof(jack_transport_info_t
));
1617 LIB_EXPORT
float jack_get_max_delayed_usecs(jack_client_t
* ext_client
)
1619 JackGlobals::CheckContext("jack_get_max_delayed_usecs");
1621 JackClient
* client
= (JackClient
*)ext_client
;
1622 if (client
== NULL
) {
1623 jack_error("jack_get_max_delayed_usecs called with a NULL client");
1626 JackEngineControl
* control
= GetEngineControl();
1627 return (control
? control
->fMaxDelayedUsecs
: 0.f
);
1631 LIB_EXPORT
float jack_get_xrun_delayed_usecs(jack_client_t
* ext_client
)
1633 JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
1635 JackClient
* client
= (JackClient
*)ext_client
;
1636 if (client
== NULL
) {
1637 jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
1640 JackEngineControl
* control
= GetEngineControl();
1641 return (control
? control
->fXrunDelayedUsecs
: 0.f
);
1645 LIB_EXPORT
void jack_reset_max_delayed_usecs(jack_client_t
* ext_client
)
1647 JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
1649 JackClient
* client
= (JackClient
*)ext_client
;
1650 if (client
== NULL
) {
1651 jack_error("jack_reset_max_delayed_usecs called with a NULL client");
1653 JackEngineControl
* control
= GetEngineControl();
1654 control
->ResetXRun();
1659 LIB_EXPORT
int jack_client_real_time_priority(jack_client_t
* ext_client
)
1661 JackGlobals::CheckContext("jack_client_real_time_priority");
1663 JackClient
* client
= (JackClient
*)ext_client
;
1664 if (client
== NULL
) {
1665 jack_error("jack_client_real_time_priority called with a NULL client");
1668 JackEngineControl
* control
= GetEngineControl();
1669 return (control
->fRealTime
) ? control
->fClientPriority
: -1;
1673 LIB_EXPORT
int jack_client_max_real_time_priority(jack_client_t
* ext_client
)
1675 JackGlobals::CheckContext("jack_client_max_real_time_priority");
1677 JackClient
* client
= (JackClient
*)ext_client
;
1678 if (client
== NULL
) {
1679 jack_error("jack_client_max_real_time_priority called with a NULL client");
1682 JackEngineControl
* control
= GetEngineControl();
1683 return (control
->fRealTime
) ? control
->fMaxClientPriority
: -1;
1687 LIB_EXPORT
int jack_acquire_real_time_scheduling(jack_native_thread_t thread
, int priority
)
1689 JackEngineControl
* control
= GetEngineControl();
1691 ? JackThread::AcquireRealTimeImp(thread
, priority
, control
->fPeriod
, control
->fComputation
, control
->fConstraint
)
1695 LIB_EXPORT
int jack_client_create_thread(jack_client_t
* client
,
1696 jack_native_thread_t
*thread
,
1698 int realtime
, /* boolean */
1699 thread_routine routine
,
1702 JackGlobals::CheckContext("jack_client_create_thread");
1704 JackEngineControl
* control
= GetEngineControl();
1705 int res
= JackThread::StartImp(thread
, priority
, realtime
, routine
, arg
);
1707 ? ((realtime
? JackThread::AcquireRealTimeImp(*thread
, priority
, control
->fPeriod
, control
->fComputation
, control
->fConstraint
) : res
))
1711 LIB_EXPORT
int jack_drop_real_time_scheduling(jack_native_thread_t thread
)
1713 return JackThread::DropRealTimeImp(thread
);
1716 LIB_EXPORT
int jack_client_stop_thread(jack_client_t
* client
, jack_native_thread_t thread
)
1718 JackGlobals::CheckContext("jack_client_stop_thread");
1720 return JackThread::StopImp(thread
);
1723 LIB_EXPORT
int jack_client_kill_thread(jack_client_t
* client
, jack_native_thread_t thread
)
1725 JackGlobals::CheckContext("jack_client_kill_thread");
1727 return JackThread::KillImp(thread
);
1731 LIB_EXPORT
void jack_set_thread_creator (jack_thread_creator_t jtc
)
1734 JackGlobals::fJackThreadCreator
= pthread_create
;
1736 JackGlobals::fJackThreadCreator
= jtc
;
1742 LIB_EXPORT
int jack_internal_client_new (const char* client_name
,
1743 const char* load_name
,
1744 const char* load_init
)
1746 JackGlobals::CheckContext("jack_internal_client_new");
1748 jack_error("jack_internal_client_new: deprecated");
1752 LIB_EXPORT
void jack_internal_client_close (const char* client_name
)
1754 JackGlobals::CheckContext("jack_internal_client_close");
1756 jack_error("jack_internal_client_close: deprecated");
1759 LIB_EXPORT
char* jack_get_internal_client_name(jack_client_t
* ext_client
, jack_intclient_t intclient
)
1761 JackGlobals::CheckContext("jack_get_internal_client_name");
1763 JackClient
* client
= (JackClient
*)ext_client
;
1764 if (client
== NULL
) {
1765 jack_error("jack_get_internal_client_name called with a NULL client");
1767 } else if (intclient
>= CLIENT_NUM
) {
1768 jack_error("jack_get_internal_client_name: incorrect client");
1771 return client
->GetInternalClientName(intclient
);
1775 LIB_EXPORT jack_intclient_t
jack_internal_client_handle(jack_client_t
* ext_client
, const char* client_name
, jack_status_t
* status
)
1777 JackGlobals::CheckContext("jack_internal_client_handle");
1779 JackClient
* client
= (JackClient
*)ext_client
;
1780 if (client
== NULL
) {
1781 jack_error("jack_internal_client_handle called with a NULL client");
1784 jack_status_t my_status
;
1785 if (status
== NULL
) /* no status from caller? */
1786 status
= &my_status
; /* use local status word */
1787 *status
= (jack_status_t
)0;
1788 return client
->InternalClientHandle(client_name
, status
);
1792 static 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
)
1794 JackGlobals::CheckContext("jack_internal_client_load_aux");
1796 JackClient
* client
= (JackClient
*)ext_client
;
1797 if (client
== NULL
) {
1798 jack_error("jack_internal_client_load called with a NULL client");
1802 jack_status_t my_status
;
1804 if (status
== NULL
) /* no status from caller? */
1805 status
= &my_status
; /* use local status word */
1806 *status
= (jack_status_t
)0;
1808 /* validate parameters */
1809 if ((options
& ~JackLoadOptions
)) {
1810 int my_status1
= *status
| (JackFailure
| JackInvalidOption
);
1811 *status
= (jack_status_t
)my_status1
;
1815 /* parse variable arguments */
1816 jack_varargs_parse(options
, ap
, &va
);
1817 return client
->InternalClientLoad(client_name
, options
, status
, &va
);
1821 LIB_EXPORT jack_intclient_t
jack_internal_client_load(jack_client_t
*client
, const char* client_name
, jack_options_t options
, jack_status_t
*status
, ...)
1823 JackGlobals::CheckContext("jack_internal_client_load");
1826 va_start(ap
, status
);
1827 jack_intclient_t res
= jack_internal_client_load_aux(client
, client_name
, options
, status
, ap
);
1832 LIB_EXPORT jack_status_t
jack_internal_client_unload(jack_client_t
* ext_client
, jack_intclient_t intclient
)
1834 JackGlobals::CheckContext("jack_internal_client_load");
1836 JackClient
* client
= (JackClient
*)ext_client
;
1837 if (client
== NULL
) {
1838 jack_error("jack_internal_client_unload called with a NULL client");
1839 return (jack_status_t
)(JackNoSuchClient
| JackFailure
);
1840 } else if (intclient
>= CLIENT_NUM
) {
1841 jack_error("jack_internal_client_unload: incorrect client");
1842 return (jack_status_t
)(JackNoSuchClient
| JackFailure
);
1844 jack_status_t my_status
;
1845 client
->InternalClientUnload(intclient
, &my_status
);
1850 LIB_EXPORT
void jack_get_version(int *major_ptr
,
1855 JackGlobals::CheckContext("jack_get_version");
1857 // FIXME: We need these comming from build system
1864 LIB_EXPORT
const char* jack_get_version_string()
1866 JackGlobals::CheckContext("jack_get_version_string");
1871 LIB_EXPORT
void jack_free(void* ptr
)
1873 JackGlobals::CheckContext("jack_free");
1881 LIB_EXPORT
int jack_set_session_callback(jack_client_t
* ext_client
, JackSessionCallback session_callback
, void* arg
)
1883 JackGlobals::CheckContext("jack_set_session_callback");
1885 JackClient
* client
= (JackClient
*)ext_client
;
1886 jack_log("jack_set_session_callback ext_client %x client %x ", ext_client
, client
);
1887 if (client
== NULL
) {
1888 jack_error("jack_set_session_callback called with a NULL client");
1891 return client
->SetSessionCallback(session_callback
, arg
);
1895 LIB_EXPORT jack_session_command_t
* jack_session_notify(jack_client_t
* ext_client
, const char* target
, jack_session_event_type_t ev_type
, const char* path
)
1897 JackGlobals::CheckContext("jack_session_notify");
1899 JackClient
* client
= (JackClient
*)ext_client
;
1900 jack_log("jack_session_notify ext_client %x client %x ", ext_client
, client
);
1901 if (client
== NULL
) {
1902 jack_error("jack_session_notify called with a NULL client");
1905 return client
->SessionNotify(target
, ev_type
, path
);
1909 LIB_EXPORT
int jack_session_reply(jack_client_t
* ext_client
, jack_session_event_t
*event
)
1911 JackGlobals::CheckContext("jack_session_reply");
1913 JackClient
* client
= (JackClient
*)ext_client
;
1914 jack_log("jack_session_reply ext_client %x client %x ", ext_client
, client
);
1915 if (client
== NULL
) {
1916 jack_error("jack_session_reply called with a NULL client");
1919 return client
->SessionReply(event
);
1923 LIB_EXPORT
void jack_session_event_free(jack_session_event_t
* ev
)
1925 JackGlobals::CheckContext("jack_session_event_free");
1928 if (ev
->session_dir
)
1929 free((void *)ev
->session_dir
);
1930 if (ev
->client_uuid
)
1931 free((void *)ev
->client_uuid
);
1932 if (ev
->command_line
)
1933 free(ev
->command_line
);
1938 LIB_EXPORT
char *jack_client_get_uuid(jack_client_t
* ext_client
)
1940 JackGlobals::CheckContext("jack_client_get_uuid");
1942 JackClient
* client
= (JackClient
*)ext_client
;
1943 if (client
== NULL
) {
1944 jack_error("jack_client_get_uuid called with a NULL client");
1948 snprintf(retval
, sizeof(retval
), "%d", client
->GetClientControl()->fSessionID
);
1949 return strdup(retval
);
1953 LIB_EXPORT
char* jack_get_uuid_for_client_name(jack_client_t
* ext_client
, const char* client_name
)
1955 JackGlobals::CheckContext("jack_get_uuid_for_client_name");
1957 JackClient
* client
= (JackClient
*)ext_client
;
1958 jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client
, client
);
1959 if (client
== NULL
) {
1960 jack_error("jack_get_uuid_for_client_name called with a NULL client");
1963 return client
->GetUUIDForClientName(client_name
);
1967 LIB_EXPORT
char* jack_get_client_name_by_uuid(jack_client_t
* ext_client
, const char* client_uuid
)
1969 JackGlobals::CheckContext("jack_get_client_name_by_uuid");
1971 JackClient
* client
= (JackClient
*)ext_client
;
1972 jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client
, client
);
1973 if (client
== NULL
) {
1974 jack_error("jack_get_client_name_by_uuid called with a NULL client");
1977 return client
->GetClientNameByUUID(client_uuid
);
1981 LIB_EXPORT
int jack_reserve_client_name(jack_client_t
* ext_client
, const char* client_name
, const char* uuid
)
1983 JackGlobals::CheckContext("jack_reserve_client_name");
1985 JackClient
* client
= (JackClient
*)ext_client
;
1986 jack_log("jack_reserve_client_name ext_client %x client %x ", ext_client
, client
);
1987 if (client
== NULL
) {
1988 jack_error("jack_reserve_client_name called with a NULL client");
1991 return client
->ReserveClientName(client_name
, uuid
);
1995 LIB_EXPORT
void jack_session_commands_free(jack_session_command_t
*cmds
)
1997 JackGlobals::CheckContext("jack_session_commands_free");
2006 if (cmds
[i
].client_name
) {
2007 free ((char *)cmds
[i
].client_name
);
2009 if (cmds
[i
].command
) {
2010 free ((char *)cmds
[i
].command
);
2013 free ((char *)cmds
[i
].uuid
);
2024 LIB_EXPORT
int jack_client_has_session_callback(jack_client_t
* ext_client
, const char* client_name
)
2026 JackGlobals::CheckContext("jack_client_has_session_callback");
2028 JackClient
* client
= (JackClient
*)ext_client
;
2029 jack_log("jack_client_has_session_callback ext_client %x client %x ", ext_client
, client
);
2030 if (client
== NULL
) {
2031 jack_error("jack_client_has_session_callback called with a NULL client");
2034 return client
->ClientHasSessionCallback(client_name
);