Apply srcfactor.diff patch for ticket #162.
[jack2.git] / common / JackAPI.cpp
blob0640883329db89e75ed61f1c34c85dcbafb32774
1 /*
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"
27 #include "JackTime.h"
28 #include "JackCompilerDeps.h"
29 #include "JackPortType.h"
30 #include "JackPlatformPlug.h"
31 #include <math.h>
33 #ifdef __CLIENTDEBUG__
34 #include "JackLibGlobals.h"
35 #endif
37 using namespace Jack;
39 #ifdef __cplusplus
40 extern "C"
42 #endif
44 typedef void (*print_function)(const char *);
45 typedef void *(*thread_routine)(void*);
47 EXPORT
48 void
49 jack_get_version(
50 int *major_ptr,
51 int *minor_ptr,
52 int *micro_ptr,
53 int *proto_ptr);
55 EXPORT
56 const char *
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,
79 void *arg);
80 EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status);
82 // new
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,
89 void *arg);
90 EXPORT int jack_set_freewheel_callback (jack_client_t *client,
91 JackFreewheelCallback freewheel_callback,
92 void *arg);
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,
97 void *arg);
98 EXPORT int jack_set_sample_rate_callback (jack_client_t *client,
99 JackSampleRateCallback srate_callback,
100 void *arg);
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,
115 void *);
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,
123 unsigned long flags,
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 *,
143 jack_port_t *port);
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,
193 void *arg);
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,
197 int conditional,
198 JackTimebaseCallback timebase_callback,
199 void *arg);
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,
218 pthread_t *thread,
219 int priority,
220 int realtime, // boolean
221 thread_routine routine,
222 void *arg);
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);
227 #ifndef WIN32
228 EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc);
229 #endif
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);
248 #ifdef __cplusplus
250 #endif
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();
272 assert(manager);
273 assert(control);
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");
295 #endif
296 try {
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();
305 return res;
306 } catch (std::bad_alloc& e) {
307 jack_error("Memory allocation error...");
308 return NULL;
309 } catch (...) {
310 jack_error("Unknown error...");
311 return NULL;
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");
319 #endif
320 #if defined(__x86_64__) || defined(__ppc64__)
321 uint64_t port_aux = (uint64_t)port;
322 #else
323 uint32_t port_aux = (uint32_t)port;
324 #endif
325 jack_port_id_t myport = (jack_port_id_t)port_aux;
326 if (!CheckPort(myport)) {
327 jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
328 return NULL;
329 } else {
330 JackGraphManager* manager = GetGraphManager();
331 return (manager ? manager->GetBuffer(myport, frames) : NULL);
335 EXPORT const char* jack_port_name(const jack_port_t* port)
337 #ifdef __CLIENTDEBUG__
338 JackGlobals::CheckContext("jack_port_name");
339 #endif
340 #if defined(__x86_64__) || defined(__ppc64__)
341 uint64_t port_aux = (uint64_t)port;
342 #else
343 uint32_t port_aux = (uint32_t)port;
344 #endif
345 jack_port_id_t myport = (jack_port_id_t)port_aux;
346 if (!CheckPort(myport)) {
347 jack_error("jack_port_name called with an incorrect port %ld", myport);
348 return NULL;
349 } else {
350 JackGraphManager* manager = GetGraphManager();
351 return (manager ? manager->GetPort(myport)->GetName() : NULL);
355 EXPORT const char* jack_port_short_name(const jack_port_t* port)
357 #ifdef __CLIENTDEBUG__
358 JackGlobals::CheckContext("jack_port_short_name");
359 #endif
360 #if defined(__x86_64__) || defined(__ppc64__)
361 uint64_t port_aux = (uint64_t)port;
362 #else
363 uint32_t port_aux = (uint32_t)port;
364 #endif
365 jack_port_id_t myport = (jack_port_id_t)port_aux;
366 if (!CheckPort(myport)) {
367 jack_error("jack_port_short_name called with an incorrect port %ld", myport);
368 return NULL;
369 } else {
370 JackGraphManager* manager = GetGraphManager();
371 return (manager ? manager->GetPort(myport)->GetShortName() : NULL);
375 EXPORT int jack_port_flags(const jack_port_t* port)
377 #ifdef __CLIENTDEBUG__
378 JackGlobals::CheckContext("jack_port_flags");
379 #endif
380 #if defined(__x86_64__) || defined(__ppc64__)
381 uint64_t port_aux = (uint64_t)port;
382 #else
383 uint32_t port_aux = (uint32_t)port;
384 #endif
385 jack_port_id_t myport = (jack_port_id_t)port_aux;
386 if (!CheckPort(myport)) {
387 jack_error("jack_port_flags called with an incorrect port %ld", myport);
388 return -1;
389 } else {
390 JackGraphManager* manager = GetGraphManager();
391 return (manager ? manager->GetPort(myport)->GetFlags() : -1);
395 EXPORT const char* jack_port_type(const jack_port_t* port)
397 #ifdef __CLIENTDEBUG__
398 JackGlobals::CheckContext("jack_port_type");
399 #endif
400 #if defined(__x86_64__) || defined(__ppc64__)
401 uint64_t port_aux = (uint64_t)port;
402 #else
403 uint32_t port_aux = (uint32_t)port;
404 #endif
405 jack_port_id_t myport = (jack_port_id_t)port_aux;
406 if (!CheckPort(myport)) {
407 jack_error("jack_port_flags called an incorrect port %ld", myport);
408 return NULL;
409 } else {
410 JackGraphManager* manager = GetGraphManager();
411 return (manager ? manager->GetPort(myport)->GetType() : NULL);
415 EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
417 #ifdef __CLIENTDEBUG__
418 JackGlobals::CheckContext("jack_port_type_id");
419 #endif
420 #if defined(__x86_64__) || defined(__ppc64__)
421 uint64_t port_aux = (uint64_t)port;
422 #else
423 uint32_t port_aux = (uint32_t)port;
424 #endif
425 jack_port_id_t myport = (jack_port_id_t)port_aux;
426 if (!CheckPort(myport)) {
427 jack_error("jack_port_type_id called an incorrect port %ld", myport);
428 return 0;
429 } else {
430 JackGraphManager* manager = GetGraphManager();
431 return (manager ? GetPortTypeId(manager->GetPort(myport)->GetType()) : 0);
435 EXPORT int jack_port_connected(const jack_port_t* port)
437 #ifdef __CLIENTDEBUG__
438 JackGlobals::CheckContext("jack_port_connected");
439 #endif
440 #if defined(__x86_64__) || defined(__ppc64__)
441 uint64_t port_aux = (uint64_t)port;
442 #else
443 uint32_t port_aux = (uint32_t)port;
444 #endif
445 jack_port_id_t myport = (jack_port_id_t)port_aux;
446 if (!CheckPort(myport)) {
447 jack_error("jack_port_connected called with an incorrect port %ld", myport);
448 return -1;
449 } else {
450 WaitGraphChange();
451 JackGraphManager* manager = GetGraphManager();
452 return (manager ? manager->GetConnectionsNum(myport) : -1);
456 EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name)
458 #ifdef __CLIENTDEBUG__
459 JackGlobals::CheckContext("jack_port_connected_to");
460 #endif
461 #if defined(__x86_64__) || defined(__ppc64__)
462 uint64_t port_aux = (uint64_t)port;
463 #else
464 uint32_t port_aux = (uint32_t)port;
465 #endif
466 jack_port_id_t src = (jack_port_id_t)port_aux;
467 if (!CheckPort(src)) {
468 jack_error("jack_port_connected_to called with an incorrect port %ld", src);
469 return -1;
470 } else if (port_name == NULL) {
471 jack_error("jack_port_connected_to called with a NULL port name");
472 return -1;
473 } else {
474 WaitGraphChange();
475 JackGraphManager* manager = GetGraphManager();
476 jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT);
477 if (dst == NO_PORT) {
478 jack_error("Unknown destination port port_name = %s", port_name);
479 return 0;
480 } else {
481 return manager->IsConnected(src, dst);
486 EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
488 #ifdef __CLIENTDEBUG__
489 JackGlobals::CheckContext("jack_port_tie");
490 #endif
491 #if defined(__x86_64__) || defined(__ppc64__)
492 uint64_t src_aux = (uint64_t)src;
493 #else
494 uint32_t src_aux = (uint32_t)src;
495 #endif
496 jack_port_id_t mysrc = (jack_port_id_t)src_aux;
497 if (!CheckPort(mysrc)) {
498 jack_error("jack_port_tie called with a NULL src port");
499 return -1;
501 #if defined(__x86_64__) || defined(__ppc64__)
502 uint64_t dst_aux = (uint64_t)dst;
503 #else
504 uint32_t dst_aux = (uint32_t)dst;
505 #endif
506 jack_port_id_t mydst = (jack_port_id_t)dst_aux;
507 if (!CheckPort(mydst)) {
508 jack_error("jack_port_tie called with a NULL dst port");
509 return -1;
511 JackGraphManager* manager = GetGraphManager();
512 if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) {
513 jack_error("jack_port_tie called with ports not belonging to the same client");
514 return -1;
515 } else {
516 return manager->GetPort(mydst)->Tie(mysrc);
520 EXPORT int jack_port_untie(jack_port_t* port)
522 #ifdef __CLIENTDEBUG__
523 JackGlobals::CheckContext("jack_port_untie");
524 #endif
525 #if defined(__x86_64__) || defined(__ppc64__)
526 uint64_t port_aux = (uint64_t)port;
527 #else
528 uint32_t port_aux = (uint32_t)port;
529 #endif
530 jack_port_id_t myport = (jack_port_id_t)port_aux;
531 if (!CheckPort(myport)) {
532 jack_error("jack_port_untie called with an incorrect port %ld", myport);
533 return -1;
534 } else {
535 JackGraphManager* manager = GetGraphManager();
536 return (manager ? manager->GetPort(myport)->UnTie() : -1);
540 EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
542 #ifdef __CLIENTDEBUG__
543 JackGlobals::CheckContext("jack_port_get_latency");
544 #endif
545 #if defined(__x86_64__) || defined(__ppc64__)
546 uint64_t port_aux = (uint64_t)port;
547 #else
548 uint32_t port_aux = (uint32_t)port;
549 #endif
550 jack_port_id_t myport = (jack_port_id_t)port_aux;
551 if (!CheckPort(myport)) {
552 jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
553 return 0;
554 } else {
555 WaitGraphChange();
556 JackGraphManager* manager = GetGraphManager();
557 return (manager ? manager->GetPort(myport)->GetLatency() : 0);
561 EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
563 #ifdef __CLIENTDEBUG__
564 JackGlobals::CheckContext("jack_port_set_latency");
565 #endif
566 #if defined(__x86_64__) || defined(__ppc64__)
567 uint64_t port_aux = (uint64_t)port;
568 #else
569 uint32_t port_aux = (uint32_t)port;
570 #endif
571 jack_port_id_t myport = (jack_port_id_t)port_aux;
572 if (!CheckPort(myport)) {
573 jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
574 } else {
575 JackGraphManager* manager = GetGraphManager();
576 if (manager)
577 manager->GetPort(myport)->SetLatency(frames);
581 EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
583 #ifdef __CLIENTDEBUG__
584 JackGlobals::CheckContext("jack_recompute_total_latency");
585 #endif
587 JackClient* client = (JackClient*)ext_client;
588 #if defined(__x86_64__) || defined(__ppc64__)
589 uint64_t port_aux = (uint64_t)port;
590 #else
591 uint32_t port_aux = (uint32_t)port;
592 #endif
593 jack_port_id_t myport = (jack_port_id_t)port_aux;
594 if (client == NULL) {
595 jack_error("jack_recompute_total_latencies called with a NULL client");
596 return -1;
597 } else if (!CheckPort(myport)) {
598 jack_error("jack_recompute_total_latencies called with a NULL port");
599 return -1;
600 } else {
601 WaitGraphChange();
602 JackGraphManager* manager = GetGraphManager();
603 return (manager ? manager->ComputeTotalLatency(myport) : -1);
607 EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
609 #ifdef __CLIENTDEBUG__
610 JackGlobals::CheckContext("jack_recompute_total_latencies");
611 #endif
613 JackClient* client = (JackClient*)ext_client;
614 if (client == NULL) {
615 jack_error("jack_recompute_total_latencies called with a NULL client");
616 return -1;
617 } else {
618 WaitGraphChange();
619 JackGraphManager* manager = GetGraphManager();
620 return (manager ? manager->ComputeTotalLatencies() : -1);
625 This is unsafe if case of concurrent access, and should be "serialized" doing a server call.
628 EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
630 #ifdef __CLIENTDEBUG__
631 JackGlobals::CheckContext("jack_port_set_name");
632 #endif
633 #if defined(__x86_64__) || defined(__ppc64__)
634 uint64_t port_aux = (uint64_t)port;
635 #else
636 uint32_t port_aux = (uint32_t)port;
637 #endif
638 jack_port_id_t myport = (jack_port_id_t)port_aux;
639 if (!CheckPort(myport)) {
640 jack_error("jack_port_set_name called with an incorrect port %ld", myport);
641 return -1;
642 } else if (name == NULL) {
643 jack_error("jack_port_set_name called with a NULL port name");
644 return -1;
645 } else {
646 JackGraphManager* manager = GetGraphManager();
647 int refnum;
648 if (manager && ((refnum = manager->GetPort(myport)->GetRefNum()) > 0)) {
649 JackClient* client = JackGlobals::fClientTable[refnum];
650 assert(client);
651 return client->PortRename(myport, name);
652 } else {
653 return -1;
658 EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
660 #ifdef __CLIENTDEBUG__
661 JackGlobals::CheckContext("jack_port_set_alias");
662 #endif
663 #if defined(__x86_64__) || defined(__ppc64__)
664 uint64_t port_aux = (uint64_t)port;
665 #else
666 uint32_t port_aux = (uint32_t)port;
667 #endif
668 jack_port_id_t myport = (jack_port_id_t)port_aux;
669 if (!CheckPort(myport)) {
670 jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
671 return -1;
672 } else if (name == NULL) {
673 jack_error("jack_port_set_alias called with a NULL port name");
674 return -1;
675 } else {
676 JackGraphManager* manager = GetGraphManager();
677 return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
681 EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
683 #ifdef __CLIENTDEBUG__
684 JackGlobals::CheckContext("jack_port_unset_alias");
685 #endif
686 #if defined(__x86_64__) || defined(__ppc64__)
687 uint64_t port_aux = (uint64_t)port;
688 #else
689 uint32_t port_aux = (uint32_t)port;
690 #endif
691 jack_port_id_t myport = (jack_port_id_t)port_aux;
692 if (!CheckPort(myport)) {
693 jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
694 return -1;
695 } else if (name == NULL) {
696 jack_error("jack_port_unset_alias called with a NULL port name");
697 return -1;
698 } else {
699 JackGraphManager* manager = GetGraphManager();
700 return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
704 EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
706 #ifdef __CLIENTDEBUG__
707 JackGlobals::CheckContext("jack_port_get_aliases");
708 #endif
709 #if defined(__x86_64__) || defined(__ppc64__)
710 uint64_t port_aux = (uint64_t)port;
711 #else
712 uint32_t port_aux = (uint32_t)port;
713 #endif
714 jack_port_id_t myport = (jack_port_id_t)port_aux;
715 if (!CheckPort(myport)) {
716 jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
717 return -1;
718 } else {
719 JackGraphManager* manager = GetGraphManager();
720 return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
724 EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
726 #ifdef __CLIENTDEBUG__
727 JackGlobals::CheckContext("jack_port_request_monitor");
728 #endif
729 #if defined(__x86_64__) || defined(__ppc64__)
730 uint64_t port_aux = (uint64_t)port;
731 #else
732 uint32_t port_aux = (uint32_t)port;
733 #endif
734 jack_port_id_t myport = (jack_port_id_t)port_aux;
735 if (!CheckPort(myport)) {
736 jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
737 return -1;
738 } else {
739 JackGraphManager* manager = GetGraphManager();
740 return (manager ? manager->RequestMonitor(myport, onoff) : -1);
744 EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
746 #ifdef __CLIENTDEBUG__
747 JackGlobals::CheckContext("jack_port_request_monitor_by_name");
748 #endif
749 JackClient* client = (JackClient*)ext_client;
750 if (client == NULL) {
751 jack_error("jack_port_request_monitor_by_name called with a NULL client");
752 return -1;
753 } else {
754 JackGraphManager* manager = GetGraphManager();
755 if (!manager)
756 return -1;
757 jack_port_id_t myport = manager->GetPort(port_name);
758 if (!CheckPort(myport)) {
759 jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
760 return -1;
761 } else {
762 return manager->RequestMonitor(myport, onoff);
767 EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
769 #ifdef __CLIENTDEBUG__
770 JackGlobals::CheckContext("jack_port_ensure_monitor");
771 #endif
772 #if defined(__x86_64__) || defined(__ppc64__)
773 uint64_t port_aux = (uint64_t)port;
774 #else
775 uint32_t port_aux = (uint32_t)port;
776 #endif
777 jack_port_id_t myport = (jack_port_id_t)port_aux;
778 if (!CheckPort(myport)) {
779 jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
780 return -1;
781 } else {
782 JackGraphManager* manager = GetGraphManager();
783 return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
787 EXPORT int jack_port_monitoring_input(jack_port_t* port)
789 #ifdef __CLIENTDEBUG__
790 JackGlobals::CheckContext("jack_port_monitoring_input");
791 #endif
792 #if defined(__x86_64__) || defined(__ppc64__)
793 uint64_t port_aux = (uint64_t)port;
794 #else
795 uint32_t port_aux = (uint32_t)port;
796 #endif
797 jack_port_id_t myport = (jack_port_id_t)port_aux;
798 if (!CheckPort(myport)) {
799 jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
800 return -1;
801 } else {
802 JackGraphManager* manager = GetGraphManager();
803 return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
807 EXPORT int jack_is_realtime(jack_client_t* ext_client)
809 #ifdef __CLIENTDEBUG__
810 JackGlobals::CheckContext("jack_is_realtime");
811 #endif
812 JackClient* client = (JackClient*)ext_client;
813 if (client == NULL) {
814 jack_error("jack_is_realtime called with a NULL client");
815 return -1;
816 } else {
817 JackEngineControl* control = GetEngineControl();
818 return (control ? control->fRealTime : -1);
822 EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
824 #ifdef __CLIENTDEBUG__
825 JackGlobals::CheckContext("jack_on_shutdown");
826 #endif
827 JackClient* client = (JackClient*)ext_client;
828 if (client == NULL) {
829 jack_error("jack_on_shutdown called with a NULL client");
830 } else {
831 client->OnShutdown(callback, arg);
835 EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
837 #ifdef __CLIENTDEBUG__
838 JackGlobals::CheckContext("jack_on_info_shutdown");
839 #endif
840 JackClient* client = (JackClient*)ext_client;
841 if (client == NULL) {
842 jack_error("jack_on_info_shutdown called with a NULL client");
843 } else {
844 client->OnInfoShutdown(callback, arg);
848 EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
850 #ifdef __CLIENTDEBUG__
851 JackGlobals::CheckContext("jack_set_process_callback");
852 #endif
853 JackClient* client = (JackClient*)ext_client;
854 if (client == NULL) {
855 jack_error("jack_set_process_callback called with a NULL client");
856 return -1;
857 } else {
858 return client->SetProcessCallback(callback, arg);
862 EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
864 #ifdef __CLIENTDEBUG__
865 JackGlobals::CheckContext("jack_thread_wait");
866 #endif
867 JackClient* client = (JackClient*)ext_client;
868 if (client == NULL) {
869 jack_error("jack_thread_wait called with a NULL client");
870 return 0;
871 } else {
872 jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
873 return 0;
877 EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
879 #ifdef __CLIENTDEBUG__
880 JackGlobals::CheckContext("jack_cycle_wait");
881 #endif
882 JackClient* client = (JackClient*)ext_client;
883 if (client == NULL) {
884 jack_error("jack_cycle_wait called with a NULL client");
885 return 0;
886 } else {
887 return client->CycleWait();
891 EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
893 #ifdef __CLIENTDEBUG__
894 JackGlobals::CheckContext("jack_cycle_signal");
895 #endif
896 JackClient* client = (JackClient*)ext_client;
897 if (client == NULL) {
898 jack_error("jack_cycle_signal called with a NULL client");
899 } else {
900 client->CycleSignal(status);
904 EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
906 #ifdef __CLIENTDEBUG__
907 JackGlobals::CheckContext("jack_set_process_thread");
908 #endif
909 JackClient* client = (JackClient*)ext_client;
910 if (client == NULL) {
911 jack_error("jack_set_process_thread called with a NULL client");
912 return -1;
913 } else {
914 return client->SetProcessThread(fun, arg);
918 EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
920 #ifdef __CLIENTDEBUG__
921 JackGlobals::CheckContext("jack_set_freewheel_callback");
922 #endif
923 JackClient* client = (JackClient*)ext_client;
924 if (client == NULL) {
925 jack_error("jack_set_freewheel_callback called with a NULL client");
926 return -1;
927 } else {
928 return client->SetFreewheelCallback(freewheel_callback, arg);
932 EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
934 #ifdef __CLIENTDEBUG__
935 JackGlobals::CheckContext("jack_set_freewheel");
936 #endif
937 JackClient* client = (JackClient*)ext_client;
938 if (client == NULL) {
939 jack_error("jack_set_freewheel called with a NULL client");
940 return -1;
941 } else {
942 return client->SetFreeWheel(onoff);
946 EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
948 #ifdef __CLIENTDEBUG__
949 JackGlobals::CheckContext("jack_set_buffer_size");
950 #endif
951 JackClient* client = (JackClient*)ext_client;
952 if (client == NULL) {
953 jack_error("jack_set_buffer_size called with a NULL client");
954 return -1;
955 } else if (!CheckBufferSize(buffer_size)) {
956 return -1;
957 } else {
958 return client->SetBufferSize(buffer_size);
962 EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
964 #ifdef __CLIENTDEBUG__
965 JackGlobals::CheckContext("jack_set_buffer_size_callback");
966 #endif
967 JackClient* client = (JackClient*)ext_client;
968 if (client == NULL) {
969 jack_error("jack_set_buffer_size_callback called with a NULL client");
970 return -1;
971 } else {
972 return client->SetBufferSizeCallback(bufsize_callback, arg);
976 EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
978 #ifdef __CLIENTDEBUG__
979 JackGlobals::CheckContext("jack_set_sample_rate_callback");
980 #endif
981 JackClient* client = (JackClient*)ext_client;
982 if (client == NULL) {
983 jack_error("jack_set_sample_rate_callback called with a NULL client");
984 return -1;
985 } else {
986 return client->SetSampleRateCallback(srate_callback, arg);
990 EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
992 #ifdef __CLIENTDEBUG__
993 JackGlobals::CheckContext("jack_set_client_registration_callback");
994 #endif
995 JackClient* client = (JackClient*)ext_client;
996 if (client == NULL) {
997 jack_error("jack_set_client_registration_callback called with a NULL client");
998 return -1;
999 } else {
1000 return client->SetClientRegistrationCallback(registration_callback, arg);
1004 EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
1006 #ifdef __CLIENTDEBUG__
1007 JackGlobals::CheckContext("jack_set_port_registration_callback");
1008 #endif
1009 JackClient* client = (JackClient*)ext_client;
1010 if (client == NULL) {
1011 jack_error("jack_set_port_registration_callback called with a NULL client");
1012 return -1;
1013 } else {
1014 return client->SetPortRegistrationCallback(registration_callback, arg);
1018 EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
1020 #ifdef __CLIENTDEBUG__
1021 JackGlobals::CheckContext("jack_set_port_connect_callback");
1022 #endif
1023 JackClient* client = (JackClient*)ext_client;
1024 if (client == NULL) {
1025 jack_error("jack_set_port_connect_callback called with a NULL client");
1026 return -1;
1027 } else {
1028 return client->SetPortConnectCallback(portconnect_callback, arg);
1032 EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
1034 #ifdef __CLIENTDEBUG__
1035 JackGlobals::CheckContext("jack_set_port_rename_callback");
1036 #endif
1037 JackClient* client = (JackClient*)ext_client;
1038 if (client == NULL) {
1039 jack_error("jack_set_port_rename_callback called with a NULL client");
1040 return -1;
1041 } else {
1042 return client->SetPortRenameCallback(rename_callback, arg);
1046 EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
1048 #ifdef __CLIENTDEBUG__
1049 JackGlobals::CheckContext("jack_set_graph_order_callback");
1050 #endif
1051 JackClient* client = (JackClient*)ext_client;
1052 jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
1053 if (client == NULL) {
1054 jack_error("jack_set_graph_order_callback called with a NULL client");
1055 return -1;
1056 } else {
1057 return client->SetGraphOrderCallback(graph_callback, arg);
1061 EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
1063 #ifdef __CLIENTDEBUG__
1064 JackGlobals::CheckContext("jack_set_xrun_callback");
1065 #endif
1066 JackClient* client = (JackClient*)ext_client;
1067 if (client == NULL) {
1068 jack_error("jack_set_xrun_callback called with a NULL client");
1069 return -1;
1070 } else {
1071 return client->SetXRunCallback(xrun_callback, arg);
1075 EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
1077 #ifdef __CLIENTDEBUG__
1078 JackGlobals::CheckContext("jack_set_thread_init_callback");
1079 #endif
1080 JackClient* client = (JackClient*)ext_client;
1081 jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
1082 if (client == NULL) {
1083 jack_error("jack_set_thread_init_callback called with a NULL client");
1084 return -1;
1085 } else {
1086 return client->SetInitCallback(init_callback, arg);
1090 EXPORT int jack_activate(jack_client_t* ext_client)
1092 #ifdef __CLIENTDEBUG__
1093 JackGlobals::CheckContext("jack_activate");
1094 #endif
1095 JackClient* client = (JackClient*)ext_client;
1096 if (client == NULL) {
1097 jack_error("jack_activate called with a NULL client");
1098 return -1;
1099 } else {
1100 return client->Activate();
1104 EXPORT int jack_deactivate(jack_client_t* ext_client)
1106 #ifdef __CLIENTDEBUG__
1107 JackGlobals::CheckContext("jack_deactivate");
1108 #endif
1109 JackClient* client = (JackClient*)ext_client;
1110 if (client == NULL) {
1111 jack_error("jack_deactivate called with a NULL client");
1112 return -1;
1113 } else {
1114 return client->Deactivate();
1118 EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
1120 #ifdef __CLIENTDEBUG__
1121 JackGlobals::CheckContext("jack_port_register");
1122 #endif
1123 JackClient* client = (JackClient*)ext_client;
1124 if (client == NULL) {
1125 jack_error("jack_port_register called with a NULL client");
1126 return NULL;
1127 } else if ((port_name == NULL) || (port_type == NULL)) {
1128 jack_error("jack_port_register called with a NULL port name or a NULL port_type");
1129 return NULL;
1130 } else {
1131 #if defined(__x86_64__) || defined(__ppc64__)
1132 return (jack_port_t *)((uint64_t)client->PortRegister(port_name, port_type, flags, buffer_size));
1133 #else
1134 return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
1135 #endif
1139 EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
1141 #ifdef __CLIENTDEBUG__
1142 JackGlobals::CheckContext("jack_port_unregister");
1143 #endif
1144 JackClient* client = (JackClient*)ext_client;
1145 if (client == NULL) {
1146 jack_error("jack_port_unregister called with a NULL client");
1147 return -1;
1149 #if defined(__x86_64__) || defined(__ppc64__)
1150 uint64_t port_aux = (uint64_t)port;
1151 #else
1152 uint32_t port_aux = (uint32_t)port;
1153 #endif
1154 jack_port_id_t myport = (jack_port_id_t)port_aux;
1155 if (!CheckPort(myport)) {
1156 jack_error("jack_port_unregister called with an incorrect port %ld", myport);
1157 return -1;
1159 return client->PortUnRegister(myport);
1162 EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
1164 #ifdef __CLIENTDEBUG__
1165 JackGlobals::CheckContext("jack_port_is_mine");
1166 #endif
1167 JackClient* client = (JackClient*)ext_client;
1168 if (client == NULL) {
1169 jack_error("jack_port_is_mine called with a NULL client");
1170 return -1;
1172 #if defined(__x86_64__) || defined(__ppc64__)
1173 uint64_t port_aux = (uint64_t)port;
1174 #else
1175 uint32_t port_aux = (uint32_t)port;
1176 #endif
1177 jack_port_id_t myport = (jack_port_id_t)port_aux;
1178 if (!CheckPort(myport)) {
1179 jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
1180 return -1;
1182 return client->PortIsMine(myport);
1185 EXPORT const char** jack_port_get_connections(const jack_port_t* port)
1187 #ifdef __CLIENTDEBUG__
1188 JackGlobals::CheckContext("jack_port_get_connections");
1189 #endif
1190 #if defined(__x86_64__) || defined(__ppc64__)
1191 uint64_t port_aux = (uint64_t)port;
1192 #else
1193 uint32_t port_aux = (uint32_t)port;
1194 #endif
1195 jack_port_id_t myport = (jack_port_id_t)port_aux;
1196 if (!CheckPort(myport)) {
1197 jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
1198 return NULL;
1199 } else {
1200 WaitGraphChange();
1201 JackGraphManager* manager = GetGraphManager();
1202 return (manager ? manager->GetConnections(myport) : NULL);
1206 // Calling client does not need to "own" the port
1207 EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
1209 #ifdef __CLIENTDEBUG__
1210 JackGlobals::CheckContext("jack_port_get_all_connections");
1211 #endif
1212 JackClient* client = (JackClient*)ext_client;
1213 if (client == NULL) {
1214 jack_error("jack_port_get_all_connections called with a NULL client");
1215 return NULL;
1218 #if defined(__x86_64__) || defined(__ppc64__)
1219 uint64_t port_aux = (uint64_t)port;
1220 #else
1221 uint32_t port_aux = (uint32_t)port;
1222 #endif
1223 jack_port_id_t myport = (jack_port_id_t)port_aux;
1224 if (!CheckPort(myport)) {
1225 jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
1226 return NULL;
1227 } else {
1228 WaitGraphChange();
1229 JackGraphManager* manager = GetGraphManager();
1230 return (manager ? manager->GetConnections(myport) : NULL);
1234 EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
1236 #ifdef __CLIENTDEBUG__
1237 JackGlobals::CheckContext("jack_port_get_total_latency");
1238 #endif
1239 JackClient* client = (JackClient*)ext_client;
1240 if (client == NULL) {
1241 jack_error("jack_port_get_total_latency called with a NULL client");
1242 return 0;
1245 #if defined(__x86_64__) || defined(__ppc64__)
1246 uint64_t port_aux = (uint64_t)port;
1247 #else
1248 uint32_t port_aux = (uint32_t)port;
1249 #endif
1250 jack_port_id_t myport = (jack_port_id_t)port_aux;
1251 if (!CheckPort(myport)) {
1252 jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
1253 return 0;
1254 } else {
1255 WaitGraphChange();
1256 JackGraphManager* manager = GetGraphManager();
1257 if (manager) {
1258 manager->ComputeTotalLatency(myport);
1259 return manager->GetPort(myport)->GetTotalLatency();
1260 } else {
1261 return 0;
1266 EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
1268 #ifdef __CLIENTDEBUG__
1269 JackGlobals::CheckContext("jack_connect");
1270 #endif
1271 JackClient* client = (JackClient*)ext_client;
1272 if (client == NULL) {
1273 jack_error("jack_connect called with a NULL client");
1274 return -1;
1275 } else if ((src == NULL) || (dst == NULL)) {
1276 jack_error("jack_connect called with a NULL port name");
1277 return -1;
1278 } else {
1279 return client->PortConnect(src, dst);
1283 EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
1285 #ifdef __CLIENTDEBUG__
1286 JackGlobals::CheckContext("jack_disconnect");
1287 #endif
1288 JackClient* client = (JackClient*)ext_client;
1289 if (client == NULL) {
1290 jack_error("jack_disconnect called with a NULL client");
1291 return -1;
1292 } else if ((src == NULL) || (dst == NULL)) {
1293 jack_error("jack_connect called with a NULL port name");
1294 return -1;
1295 } else {
1296 return client->PortDisconnect(src, dst);
1300 EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
1302 #ifdef __CLIENTDEBUG__
1303 JackGlobals::CheckContext("jack_port_disconnect");
1304 #endif
1305 JackClient* client = (JackClient*)ext_client;
1306 if (client == NULL) {
1307 jack_error("jack_port_disconnect called with a NULL client");
1308 return -1;
1310 #if defined(__x86_64__) || defined(__ppc64__)
1311 uint64_t port_aux = (uint64_t)src;
1312 #else
1313 uint32_t port_aux = (uint32_t)src;
1314 #endif
1315 jack_port_id_t myport = (jack_port_id_t)port_aux;
1316 if (!CheckPort(myport)) {
1317 jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
1318 return -1;
1320 return client->PortDisconnect(myport);
1323 EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
1325 #ifdef __CLIENTDEBUG__
1326 JackGlobals::CheckContext("jack_get_sample_rate");
1327 #endif
1328 JackClient* client = (JackClient*)ext_client;
1329 if (client == NULL) {
1330 jack_error("jack_get_sample_rate called with a NULL client");
1331 return 0;
1332 } else {
1333 JackEngineControl* control = GetEngineControl();
1334 return (control ? control->fSampleRate : 0);
1338 EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
1340 #ifdef __CLIENTDEBUG__
1341 JackGlobals::CheckContext("jack_get_buffer_size");
1342 #endif
1343 JackClient* client = (JackClient*)ext_client;
1344 if (client == NULL) {
1345 jack_error("jack_get_buffer_size called with a NULL client");
1346 return 0;
1347 } else {
1348 JackEngineControl* control = GetEngineControl();
1349 return (control ? control->fBufferSize : 0);
1353 EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
1355 #ifdef __CLIENTDEBUG__
1356 JackGlobals::CheckContext("jack_get_ports");
1357 #endif
1358 JackClient* client = (JackClient*)ext_client;
1359 if (client == NULL) {
1360 jack_error("jack_get_ports called with a NULL client");
1361 return NULL;
1363 JackGraphManager* manager = GetGraphManager();
1364 return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
1367 EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
1369 #ifdef __CLIENTDEBUG__
1370 JackGlobals::CheckContext("jack_port_by_name");
1371 #endif
1372 JackClient* client = (JackClient*)ext_client;
1373 if (client == NULL) {
1374 jack_error("jack_get_ports called with a NULL client");
1375 return 0;
1378 if (portname == NULL) {
1379 jack_error("jack_port_by_name called with a NULL port name");
1380 return NULL;
1381 } else {
1382 JackGraphManager* manager = GetGraphManager();
1383 if (!manager)
1384 return NULL;
1385 int res = manager->GetPort(portname); // returns a port index at least > 1
1386 #if defined(__x86_64__) || defined(__ppc64__)
1387 return (res == NO_PORT) ? NULL : (jack_port_t*)((uint64_t)res);
1388 #else
1389 return (res == NO_PORT) ? NULL : (jack_port_t*)res;
1390 #endif
1394 EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
1396 #ifdef __CLIENTDEBUG__
1397 JackGlobals::CheckContext("jack_port_by_id");
1398 #endif
1399 /* jack_port_t* type is actually the port index */
1400 #if defined(__x86_64__) || defined(__ppc64__)
1401 return (jack_port_t*)((uint64_t)id);
1402 #else
1403 return (jack_port_t*)id;
1404 #endif
1407 EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
1409 #ifdef __CLIENTDEBUG__
1410 JackGlobals::CheckContext("jack_engine_takeover_timebase");
1411 #endif
1412 JackClient* client = (JackClient*)ext_client;
1413 if (client == NULL) {
1414 jack_error("jack_engine_takeover_timebase called with a NULL client");
1415 return -1;
1416 } else {
1417 jack_error("jack_engine_takeover_timebase: deprecated\n");
1418 return 0;
1422 EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
1424 #ifdef __CLIENTDEBUG__
1425 JackGlobals::CheckContext("jack_frames_since_cycle_start");
1426 #endif
1427 JackTimer timer;
1428 JackEngineControl* control = GetEngineControl();
1429 if (control) {
1430 control->ReadFrameTime(&timer);
1431 return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
1432 } else {
1433 return 0;
1437 EXPORT jack_time_t jack_get_time()
1439 #ifdef __CLIENTDEBUG__
1440 JackGlobals::CheckContext("jack_get_time");
1441 #endif
1442 return GetMicroSeconds();
1445 EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
1447 #ifdef __CLIENTDEBUG__
1448 JackGlobals::CheckContext("jack_frames_to_time");
1449 #endif
1450 JackClient* client = (JackClient*)ext_client;
1451 if (client == NULL) {
1452 jack_error("jack_frames_to_time called with a NULL client");
1453 return 0;
1454 } else {
1455 JackTimer timer;
1456 JackEngineControl* control = GetEngineControl();
1457 if (control) {
1458 control->ReadFrameTime(&timer);
1459 return timer.Frames2Time(frames, control->fBufferSize);
1460 } else {
1461 return 0;
1466 EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
1468 #ifdef __CLIENTDEBUG__
1469 JackGlobals::CheckContext("jack_time_to_frames");
1470 #endif
1471 JackClient* client = (JackClient*)ext_client;
1472 if (client == NULL) {
1473 jack_error("jack_time_to_frames called with a NULL client");
1474 return 0;
1475 } else {
1476 JackTimer timer;
1477 JackEngineControl* control = GetEngineControl();
1478 if (control) {
1479 control->ReadFrameTime(&timer);
1480 return timer.Time2Frames(time, control->fBufferSize);
1481 } else {
1482 return 0;
1487 EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
1489 #ifdef __CLIENTDEBUG__
1490 JackGlobals::CheckContext("jack_frame_time");
1491 #endif
1492 return jack_time_to_frames(ext_client, GetMicroSeconds());
1495 EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
1497 #ifdef __CLIENTDEBUG__
1498 JackGlobals::CheckContext("jack_last_frame_time");
1499 #endif
1500 JackEngineControl* control = GetEngineControl();
1501 return (control) ? control->fFrameTimer.ReadCurrentState()->CurFrame() : 0;
1504 EXPORT float jack_cpu_load(jack_client_t* ext_client)
1506 #ifdef __CLIENTDEBUG__
1507 JackGlobals::CheckContext("jack_cpu_load");
1508 #endif
1509 JackClient* client = (JackClient*)ext_client;
1510 if (client == NULL) {
1511 jack_error("jack_cpu_load called with a NULL client");
1512 return 0.0f;
1513 } else {
1514 JackEngineControl* control = GetEngineControl();
1515 return (control ? control->fCPULoad : 0.0f);
1519 EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
1521 #ifdef __CLIENTDEBUG__
1522 JackGlobals::CheckContext("jack_client_thread_id");
1523 #endif
1524 JackClient* client = (JackClient*)ext_client;
1525 if (client == NULL) {
1526 jack_error("jack_client_thread_id called with a NULL client");
1527 return (pthread_t)NULL;
1528 } else {
1529 return client->GetThreadID();
1533 EXPORT char* jack_get_client_name(jack_client_t* ext_client)
1535 #ifdef __CLIENTDEBUG__
1536 JackGlobals::CheckContext("jack_get_client_name");
1537 #endif
1538 JackClient* client = (JackClient*)ext_client;
1539 if (client == NULL) {
1540 jack_error("jack_get_client_name called with a NULL client");
1541 return NULL;
1542 } else {
1543 return client->GetClientControl()->fName;
1547 EXPORT int jack_client_name_size(void)
1549 return JACK_CLIENT_NAME_SIZE;
1552 EXPORT int jack_port_name_size(void)
1554 return JACK_PORT_NAME_SIZE;
1557 EXPORT int jack_port_type_size(void)
1559 return JACK_PORT_TYPE_SIZE;
1562 // transport.h
1563 EXPORT int jack_release_timebase(jack_client_t* ext_client)
1565 #ifdef __CLIENTDEBUG__
1566 JackGlobals::CheckContext("jack_release_timebase");
1567 #endif
1568 JackClient* client = (JackClient*)ext_client;
1569 if (client == NULL) {
1570 jack_error("jack_release_timebase called with a NULL client");
1571 return -1;
1572 } else {
1573 return client->ReleaseTimebase();
1577 EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
1579 #ifdef __CLIENTDEBUG__
1580 JackGlobals::CheckContext("jack_set_sync_callback");
1581 #endif
1582 JackClient* client = (JackClient*)ext_client;
1583 if (client == NULL) {
1584 jack_error("jack_set_sync_callback called with a NULL client");
1585 return -1;
1586 } else {
1587 return client->SetSyncCallback(sync_callback, arg);
1591 EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
1593 #ifdef __CLIENTDEBUG__
1594 JackGlobals::CheckContext("jack_set_sync_timeout");
1595 #endif
1596 JackClient* client = (JackClient*)ext_client;
1597 if (client == NULL) {
1598 jack_error("jack_set_sync_timeout called with a NULL client");
1599 return -1;
1600 } else {
1601 return client->SetSyncTimeout(timeout);
1605 EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
1607 #ifdef __CLIENTDEBUG__
1608 JackGlobals::CheckContext("jack_set_timebase_callback");
1609 #endif
1610 JackClient* client = (JackClient*)ext_client;
1611 if (client == NULL) {
1612 jack_error("jack_set_timebase_callback called with a NULL client");
1613 return -1;
1614 } else {
1615 return client->SetTimebaseCallback(conditional, timebase_callback, arg);
1619 EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
1621 #ifdef __CLIENTDEBUG__
1622 JackGlobals::CheckContext("jack_transport_locate");
1623 #endif
1624 JackClient* client = (JackClient*)ext_client;
1625 if (client == NULL) {
1626 jack_error("jack_transport_locate called with a NULL client");
1627 return -1;
1628 } else {
1629 client->TransportLocate(frame);
1630 return 0;
1634 EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
1636 #ifdef __CLIENTDEBUG__
1637 JackGlobals::CheckContext("jack_transport_query");
1638 #endif
1639 JackClient* client = (JackClient*)ext_client;
1640 if (client == NULL) {
1641 jack_error("jack_transport_query called with a NULL client");
1642 return JackTransportStopped;
1643 } else {
1644 return client->TransportQuery(pos);
1648 EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
1650 #ifdef __CLIENTDEBUG__
1651 JackGlobals::CheckContext("jack_get_current_transport_frame");
1652 #endif
1653 JackClient* client = (JackClient*)ext_client;
1654 if (client == NULL) {
1655 jack_error("jack_get_current_transport_frame called with a NULL client");
1656 return 0;
1657 } else {
1658 return client->GetCurrentTransportFrame();
1662 EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
1664 #ifdef __CLIENTDEBUG__
1665 JackGlobals::CheckContext("jack_transport_reposition");
1666 #endif
1667 JackClient* client = (JackClient*)ext_client;
1668 if (client == NULL) {
1669 jack_error("jack_transport_reposition called with a NULL client");
1670 return -1;
1671 } else {
1672 client->TransportReposition(pos);
1673 return 0;
1677 EXPORT void jack_transport_start(jack_client_t* ext_client)
1679 #ifdef __CLIENTDEBUG__
1680 JackGlobals::CheckContext("jack_transport_start");
1681 #endif
1682 JackClient* client = (JackClient*)ext_client;
1683 if (client == NULL) {
1684 jack_error("jack_transport_start called with a NULL client");
1685 } else {
1686 client->TransportStart();
1690 EXPORT void jack_transport_stop(jack_client_t* ext_client)
1692 #ifdef __CLIENTDEBUG__
1693 JackGlobals::CheckContext("jack_transport_stop");
1694 #endif
1695 JackClient* client = (JackClient*)ext_client;
1696 if (client == NULL) {
1697 jack_error("jack_transport_stop called with a NULL client");
1698 } else {
1699 client->TransportStop();
1703 // deprecated
1704 EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
1706 #ifdef __CLIENTDEBUG__
1707 JackGlobals::CheckContext("jack_get_transport_info");
1708 #endif
1709 jack_error("jack_get_transport_info: deprecated");
1710 if (tinfo)
1711 memset(tinfo, 0, sizeof(jack_transport_info_t));
1714 EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
1716 #ifdef __CLIENTDEBUG__
1717 JackGlobals::CheckContext("jack_set_transport_info");
1718 #endif
1719 jack_error("jack_set_transport_info: deprecated");
1720 if (tinfo)
1721 memset(tinfo, 0, sizeof(jack_transport_info_t));
1724 // statistics.h
1725 EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
1727 #ifdef __CLIENTDEBUG__
1728 JackGlobals::CheckContext("jack_get_max_delayed_usecs");
1729 #endif
1730 JackClient* client = (JackClient*)ext_client;
1731 if (client == NULL) {
1732 jack_error("jack_get_max_delayed_usecs called with a NULL client");
1733 return 0.f;
1734 } else {
1735 JackEngineControl* control = GetEngineControl();
1736 return (control ? control->fMaxDelayedUsecs : 0.f);
1740 EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
1742 #ifdef __CLIENTDEBUG__
1743 JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
1744 #endif
1745 JackClient* client = (JackClient*)ext_client;
1746 if (client == NULL) {
1747 jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
1748 return 0.f;
1749 } else {
1750 JackEngineControl* control = GetEngineControl();
1751 return (control ? control->fXrunDelayedUsecs : 0.f);
1755 EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
1757 #ifdef __CLIENTDEBUG__
1758 JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
1759 #endif
1760 JackClient* client = (JackClient*)ext_client;
1761 if (client == NULL) {
1762 jack_error("jack_reset_max_delayed_usecs called with a NULL client");
1763 } else {
1764 JackEngineControl* control = GetEngineControl();
1765 control->ResetXRun();
1769 // thread.h
1770 EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
1772 #ifdef __CLIENTDEBUG__
1773 JackGlobals::CheckContext("jack_client_real_time_priority");
1774 #endif
1775 JackClient* client = (JackClient*)ext_client;
1776 if (client == NULL) {
1777 jack_error("jack_client_real_time_priority called with a NULL client");
1778 return -1;
1779 } else {
1780 JackEngineControl* control = GetEngineControl();
1781 return (control->fRealTime) ? control->fClientPriority : -1;
1785 EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
1787 #ifdef __CLIENTDEBUG__
1788 JackGlobals::CheckContext("jack_client_max_real_time_priority");
1789 #endif
1790 JackClient* client = (JackClient*)ext_client;
1791 if (client == NULL) {
1792 jack_error("jack_client_max_real_time_priority called with a NULL client");
1793 return -1;
1794 } else {
1795 JackEngineControl* control = GetEngineControl();
1796 return (control->fRealTime) ? control->fMaxClientPriority : -1;
1800 EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
1802 JackEngineControl* control = GetEngineControl();
1803 return (control ? JackThread::AcquireRealTimeImp(thread, priority, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1);
1806 EXPORT int jack_client_create_thread(jack_client_t* client,
1807 pthread_t *thread,
1808 int priority,
1809 int realtime, /* boolean */
1810 thread_routine routine,
1811 void *arg)
1813 #ifdef __CLIENTDEBUG__
1814 JackGlobals::CheckContext("jack_client_create_thread");
1815 #endif
1816 return JackThread::StartImp(thread, priority, realtime, routine, arg);
1819 EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
1821 return JackThread::DropRealTimeImp(thread);
1824 EXPORT int jack_client_stop_thread(jack_client_t* client, pthread_t thread)
1826 #ifdef __CLIENTDEBUG__
1827 JackGlobals::CheckContext("jack_client_stop_thread");
1828 #endif
1829 return JackThread::StopImp(thread);
1832 EXPORT int jack_client_kill_thread(jack_client_t* client, pthread_t thread)
1834 #ifdef __CLIENTDEBUG__
1835 JackGlobals::CheckContext("jack_client_kill_thread");
1836 #endif
1837 return JackThread::KillImp(thread);
1840 #ifndef WIN32
1841 EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
1843 JackGlobals::fJackThreadCreator = (jtc == NULL) ? pthread_create : jtc;
1845 #endif
1847 // intclient.h
1848 EXPORT int jack_internal_client_new (const char *client_name,
1849 const char *load_name,
1850 const char *load_init)
1852 jack_error("jack_internal_client_new: deprecated");
1853 return -1;
1856 EXPORT void jack_internal_client_close (const char *client_name)
1858 jack_error("jack_internal_client_close: deprecated");
1861 EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
1863 #ifdef __CLIENTDEBUG__
1864 JackGlobals::CheckContext("jack_get_internal_client_name");
1865 #endif
1866 JackClient* client = (JackClient*)ext_client;
1867 if (client == NULL) {
1868 jack_error("jack_get_internal_client_name called with a NULL client");
1869 return NULL;
1870 } else if (intclient >= CLIENT_NUM) {
1871 jack_error("jack_get_internal_client_name: incorrect client");
1872 return NULL;
1873 } else {
1874 return client->GetInternalClientName(intclient);
1878 EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
1880 #ifdef __CLIENTDEBUG__
1881 JackGlobals::CheckContext("jack_internal_client_handle");
1882 #endif
1883 JackClient* client = (JackClient*)ext_client;
1884 if (client == NULL) {
1885 jack_error("jack_internal_client_handle called with a NULL client");
1886 return 0;
1887 } else {
1888 jack_status_t my_status;
1889 if (status == NULL) /* no status from caller? */
1890 status = &my_status; /* use local status word */
1891 *status = (jack_status_t)0;
1892 return client->InternalClientHandle(client_name, status);
1896 EXPORT jack_intclient_t jack_internal_client_load_aux(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
1898 #ifdef __CLIENTDEBUG__
1899 JackGlobals::CheckContext("jack_internal_client_load_aux");
1900 #endif
1901 JackClient* client = (JackClient*)ext_client;
1902 if (client == NULL) {
1903 jack_error("jack_internal_client_load called with a NULL client");
1904 return 0;
1905 } else {
1906 jack_varargs_t va;
1907 jack_status_t my_status;
1909 if (status == NULL) /* no status from caller? */
1910 status = &my_status; /* use local status word */
1911 *status = (jack_status_t)0;
1913 /* validate parameters */
1914 if ((options & ~JackLoadOptions)) {
1915 int my_status1 = *status | (JackFailure | JackInvalidOption);
1916 *status = (jack_status_t)my_status1;
1917 return 0;
1920 /* parse variable arguments */
1921 jack_varargs_parse(options, ap, &va);
1922 return client->InternalClientLoad(client_name, options, status, &va);
1926 EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client, const char *client_name, jack_options_t options, jack_status_t *status, ...)
1928 va_list ap;
1929 va_start(ap, status);
1930 jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
1931 va_end(ap);
1932 return res;
1935 EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
1937 #ifdef __CLIENTDEBUG__
1938 JackGlobals::CheckContext("jack_internal_client_load");
1939 #endif
1940 JackClient* client = (JackClient*)ext_client;
1941 if (client == NULL) {
1942 jack_error("jack_internal_client_unload called with a NULL client");
1943 return (jack_status_t)(JackNoSuchClient | JackFailure);
1944 } else if (intclient >= CLIENT_NUM) {
1945 jack_error("jack_internal_client_unload: incorrect client");
1946 return (jack_status_t)(JackNoSuchClient | JackFailure);
1947 } else {
1948 jack_status_t my_status;
1949 client->InternalClientUnload(intclient, &my_status);
1950 return my_status;
1954 EXPORT
1955 void
1956 jack_get_version(
1957 int *major_ptr,
1958 int *minor_ptr,
1959 int *micro_ptr,
1960 int *proto_ptr)
1962 // FIXME: We need these comming from build system
1963 *major_ptr = 0;
1964 *minor_ptr = 0;
1965 *micro_ptr = 0;
1966 *proto_ptr = 0;
1969 EXPORT
1970 const char *
1971 jack_get_version_string()
1973 return VERSION;
1976 EXPORT void jack_free(void* ptr)
1978 if (ptr) {
1979 free(ptr);