Add a string parameter to server ==> client notification, add a new InfoShutdown...
[jack2.git] / common / JackAPI.cpp
blob34e591e4a8411c2432155866ea297c7db2a93260
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);
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 assert(JackGlobals::fOpenMutex);
294 JackGlobals::fOpenMutex->Lock();
295 jack_error("jack_client_new: deprecated");
296 int options = JackUseExactName;
297 if (getenv("JACK_START_SERVER") == NULL)
298 options |= JackNoStartServer;
299 jack_client_t* res = jack_client_open_aux(client_name, (jack_options_t)options, NULL, NULL);
300 JackGlobals::fOpenMutex->Unlock();
301 return res;
304 EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
306 #ifdef __CLIENTDEBUG__
307 JackLibGlobals::CheckContext();
308 #endif
309 #if defined(__x86_64__) || defined(__ppc64__)
310 uint64_t port_aux = (uint64_t)port;
311 #else
312 uint32_t port_aux = (uint32_t)port;
313 #endif
314 jack_port_id_t myport = (jack_port_id_t)port_aux;
315 if (!CheckPort(myport)) {
316 jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
317 return NULL;
318 } else {
319 JackGraphManager* manager = GetGraphManager();
320 return (manager ? manager->GetBuffer(myport, frames) : NULL);
324 EXPORT const char* jack_port_name(const jack_port_t* port)
326 #ifdef __CLIENTDEBUG__
327 JackLibGlobals::CheckContext();
328 #endif
329 #if defined(__x86_64__) || defined(__ppc64__)
330 uint64_t port_aux = (uint64_t)port;
331 #else
332 uint32_t port_aux = (uint32_t)port;
333 #endif
334 jack_port_id_t myport = (jack_port_id_t)port_aux;
335 if (!CheckPort(myport)) {
336 jack_error("jack_port_name called with an incorrect port %ld", myport);
337 return NULL;
338 } else {
339 JackGraphManager* manager = GetGraphManager();
340 return (manager ? manager->GetPort(myport)->GetName() : NULL);
344 EXPORT const char* jack_port_short_name(const jack_port_t* port)
346 #ifdef __CLIENTDEBUG__
347 JackLibGlobals::CheckContext();
348 #endif
349 #if defined(__x86_64__) || defined(__ppc64__)
350 uint64_t port_aux = (uint64_t)port;
351 #else
352 uint32_t port_aux = (uint32_t)port;
353 #endif
354 jack_port_id_t myport = (jack_port_id_t)port_aux;
355 if (!CheckPort(myport)) {
356 jack_error("jack_port_short_name called with an incorrect port %ld", myport);
357 return NULL;
358 } else {
359 JackGraphManager* manager = GetGraphManager();
360 return (manager ? manager->GetPort(myport)->GetShortName() : NULL);
364 EXPORT int jack_port_flags(const jack_port_t* port)
366 #ifdef __CLIENTDEBUG__
367 JackLibGlobals::CheckContext();
368 #endif
369 #if defined(__x86_64__) || defined(__ppc64__)
370 uint64_t port_aux = (uint64_t)port;
371 #else
372 uint32_t port_aux = (uint32_t)port;
373 #endif
374 jack_port_id_t myport = (jack_port_id_t)port_aux;
375 if (!CheckPort(myport)) {
376 jack_error("jack_port_flags called with an incorrect port %ld", myport);
377 return -1;
378 } else {
379 JackGraphManager* manager = GetGraphManager();
380 return (manager ? manager->GetPort(myport)->GetFlags() : -1);
384 EXPORT const char* jack_port_type(const jack_port_t* port)
386 #ifdef __CLIENTDEBUG__
387 JackLibGlobals::CheckContext();
388 #endif
389 #if defined(__x86_64__) || defined(__ppc64__)
390 uint64_t port_aux = (uint64_t)port;
391 #else
392 uint32_t port_aux = (uint32_t)port;
393 #endif
394 jack_port_id_t myport = (jack_port_id_t)port_aux;
395 if (!CheckPort(myport)) {
396 jack_error("jack_port_flags called an incorrect port %ld", myport);
397 return NULL;
398 } else {
399 JackGraphManager* manager = GetGraphManager();
400 return (manager ? manager->GetPort(myport)->GetType() : NULL);
404 EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
406 #ifdef __CLIENTDEBUG__
407 JackLibGlobals::CheckContext();
408 #endif
409 #if defined(__x86_64__) || defined(__ppc64__)
410 uint64_t port_aux = (uint64_t)port;
411 #else
412 uint32_t port_aux = (uint32_t)port;
413 #endif
414 jack_port_id_t myport = (jack_port_id_t)port_aux;
415 if (!CheckPort(myport)) {
416 jack_error("jack_port_type_id called an incorrect port %ld", myport);
417 return 0;
418 } else {
419 JackGraphManager* manager = GetGraphManager();
420 return (manager ? GetPortTypeId(manager->GetPort(myport)->GetType()) : 0);
424 EXPORT int jack_port_connected(const jack_port_t* port)
426 #ifdef __CLIENTDEBUG__
427 JackLibGlobals::CheckContext();
428 #endif
429 #if defined(__x86_64__) || defined(__ppc64__)
430 uint64_t port_aux = (uint64_t)port;
431 #else
432 uint32_t port_aux = (uint32_t)port;
433 #endif
434 jack_port_id_t myport = (jack_port_id_t)port_aux;
435 if (!CheckPort(myport)) {
436 jack_error("jack_port_connected called with an incorrect port %ld", myport);
437 return -1;
438 } else {
439 WaitGraphChange();
440 JackGraphManager* manager = GetGraphManager();
441 return (manager ? manager->GetConnectionsNum(myport) : -1);
445 EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name)
447 #ifdef __CLIENTDEBUG__
448 JackLibGlobals::CheckContext();
449 #endif
450 #if defined(__x86_64__) || defined(__ppc64__)
451 uint64_t port_aux = (uint64_t)port;
452 #else
453 uint32_t port_aux = (uint32_t)port;
454 #endif
455 jack_port_id_t src = (jack_port_id_t)port_aux;
456 if (!CheckPort(src)) {
457 jack_error("jack_port_connected_to called with an incorrect port %ld", src);
458 return -1;
459 } else if (port_name == NULL) {
460 jack_error("jack_port_connected_to called with a NULL port name");
461 return -1;
462 } else {
463 WaitGraphChange();
464 JackGraphManager* manager = GetGraphManager();
465 jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT);
466 if (dst == NO_PORT) {
467 jack_error("Unknown destination port port_name = %s", port_name);
468 return 0;
469 } else {
470 return manager->IsConnected(src, dst);
475 EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
477 #ifdef __CLIENTDEBUG__
478 JackLibGlobals::CheckContext();
479 #endif
480 #if defined(__x86_64__) || defined(__ppc64__)
481 uint64_t src_aux = (uint64_t)src;
482 #else
483 uint32_t src_aux = (uint32_t)src;
484 #endif
485 jack_port_id_t mysrc = (jack_port_id_t)src_aux;
486 if (!CheckPort(mysrc)) {
487 jack_error("jack_port_tie called with a NULL src port");
488 return -1;
490 #if defined(__x86_64__) || defined(__ppc64__)
491 uint64_t dst_aux = (uint64_t)dst;
492 #else
493 uint32_t dst_aux = (uint32_t)dst;
494 #endif
495 jack_port_id_t mydst = (jack_port_id_t)dst_aux;
496 if (!CheckPort(mydst)) {
497 jack_error("jack_port_tie called with a NULL dst port");
498 return -1;
500 JackGraphManager* manager = GetGraphManager();
501 if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) {
502 jack_error("jack_port_tie called with ports not belonging to the same client");
503 return -1;
504 } else {
505 return manager->GetPort(mydst)->Tie(mysrc);
509 EXPORT int jack_port_untie(jack_port_t* port)
511 #ifdef __CLIENTDEBUG__
512 JackLibGlobals::CheckContext();
513 #endif
514 #if defined(__x86_64__) || defined(__ppc64__)
515 uint64_t port_aux = (uint64_t)port;
516 #else
517 uint32_t port_aux = (uint32_t)port;
518 #endif
519 jack_port_id_t myport = (jack_port_id_t)port_aux;
520 if (!CheckPort(myport)) {
521 jack_error("jack_port_untie called with an incorrect port %ld", myport);
522 return -1;
523 } else {
524 JackGraphManager* manager = GetGraphManager();
525 return (manager ? manager->GetPort(myport)->UnTie() : -1);
529 EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
531 #ifdef __CLIENTDEBUG__
532 JackLibGlobals::CheckContext();
533 #endif
534 #if defined(__x86_64__) || defined(__ppc64__)
535 uint64_t port_aux = (uint64_t)port;
536 #else
537 uint32_t port_aux = (uint32_t)port;
538 #endif
539 jack_port_id_t myport = (jack_port_id_t)port_aux;
540 if (!CheckPort(myport)) {
541 jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
542 return 0;
543 } else {
544 WaitGraphChange();
545 JackGraphManager* manager = GetGraphManager();
546 return (manager ? manager->GetPort(myport)->GetLatency() : 0);
550 EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
552 #ifdef __CLIENTDEBUG__
553 JackLibGlobals::CheckContext();
554 #endif
555 #if defined(__x86_64__) || defined(__ppc64__)
556 uint64_t port_aux = (uint64_t)port;
557 #else
558 uint32_t port_aux = (uint32_t)port;
559 #endif
560 jack_port_id_t myport = (jack_port_id_t)port_aux;
561 if (!CheckPort(myport)) {
562 jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
563 } else {
564 JackGraphManager* manager = GetGraphManager();
565 if (manager)
566 manager->GetPort(myport)->SetLatency(frames);
570 EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
572 #ifdef __CLIENTDEBUG__
573 JackLibGlobals::CheckContext();
574 #endif
576 JackClient* client = (JackClient*)ext_client;
577 #if defined(__x86_64__) || defined(__ppc64__)
578 uint64_t port_aux = (uint64_t)port;
579 #else
580 uint32_t port_aux = (uint32_t)port;
581 #endif
582 jack_port_id_t myport = (jack_port_id_t)port_aux;
583 if (client == NULL) {
584 jack_error("jack_recompute_total_latencies called with a NULL client");
585 return -1;
586 } else if (!CheckPort(myport)) {
587 jack_error("jack_recompute_total_latencies called with a NULL port");
588 return -1;
589 } else {
590 WaitGraphChange();
591 JackGraphManager* manager = GetGraphManager();
592 return (manager ? manager->ComputeTotalLatency(myport) : -1);
596 EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
598 #ifdef __CLIENTDEBUG__
599 JackLibGlobals::CheckContext();
600 #endif
602 JackClient* client = (JackClient*)ext_client;
603 if (client == NULL) {
604 jack_error("jack_recompute_total_latencies called with a NULL client");
605 return -1;
606 } else {
607 WaitGraphChange();
608 JackGraphManager* manager = GetGraphManager();
609 return (manager ? manager->ComputeTotalLatencies() : -1);
614 This is unsafe if case of concurrent access, and should be "serialized" doing a server call.
617 EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
619 #ifdef __CLIENTDEBUG__
620 JackLibGlobals::CheckContext();
621 #endif
622 #if defined(__x86_64__) || defined(__ppc64__)
623 uint64_t port_aux = (uint64_t)port;
624 #else
625 uint32_t port_aux = (uint32_t)port;
626 #endif
627 jack_port_id_t myport = (jack_port_id_t)port_aux;
628 if (!CheckPort(myport)) {
629 jack_error("jack_port_set_name called with an incorrect port %ld", myport);
630 return -1;
631 } else if (name == NULL) {
632 jack_error("jack_port_set_name called with a NULL port name");
633 return -1;
634 } else {
635 JackGraphManager* manager = GetGraphManager();
636 int refnum;
637 if (manager && ((refnum = manager->GetPort(myport)->GetRefNum()) > 0)) {
638 JackClient* client = JackGlobals::fClientTable[refnum];
639 assert(client);
640 return client->PortRename(myport, name);
641 } else {
642 return -1;
647 EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
649 #ifdef __CLIENTDEBUG__
650 JackLibGlobals::CheckContext();
651 #endif
652 #if defined(__x86_64__) || defined(__ppc64__)
653 uint64_t port_aux = (uint64_t)port;
654 #else
655 uint32_t port_aux = (uint32_t)port;
656 #endif
657 jack_port_id_t myport = (jack_port_id_t)port_aux;
658 if (!CheckPort(myport)) {
659 jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
660 return -1;
661 } else if (name == NULL) {
662 jack_error("jack_port_set_alias called with a NULL port name");
663 return -1;
664 } else {
665 JackGraphManager* manager = GetGraphManager();
666 return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
670 EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
672 #ifdef __CLIENTDEBUG__
673 JackLibGlobals::CheckContext();
674 #endif
675 #if defined(__x86_64__) || defined(__ppc64__)
676 uint64_t port_aux = (uint64_t)port;
677 #else
678 uint32_t port_aux = (uint32_t)port;
679 #endif
680 jack_port_id_t myport = (jack_port_id_t)port_aux;
681 if (!CheckPort(myport)) {
682 jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
683 return -1;
684 } else if (name == NULL) {
685 jack_error("jack_port_unset_alias called with a NULL port name");
686 return -1;
687 } else {
688 JackGraphManager* manager = GetGraphManager();
689 return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
693 EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
695 #ifdef __CLIENTDEBUG__
696 JackLibGlobals::CheckContext();
697 #endif
698 #if defined(__x86_64__) || defined(__ppc64__)
699 uint64_t port_aux = (uint64_t)port;
700 #else
701 uint32_t port_aux = (uint32_t)port;
702 #endif
703 jack_port_id_t myport = (jack_port_id_t)port_aux;
704 if (!CheckPort(myport)) {
705 jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
706 return -1;
707 } else {
708 JackGraphManager* manager = GetGraphManager();
709 return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
713 EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
715 #ifdef __CLIENTDEBUG__
716 JackLibGlobals::CheckContext();
717 #endif
718 #if defined(__x86_64__) || defined(__ppc64__)
719 uint64_t port_aux = (uint64_t)port;
720 #else
721 uint32_t port_aux = (uint32_t)port;
722 #endif
723 jack_port_id_t myport = (jack_port_id_t)port_aux;
724 if (!CheckPort(myport)) {
725 jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
726 return -1;
727 } else {
728 JackGraphManager* manager = GetGraphManager();
729 return (manager ? manager->RequestMonitor(myport, onoff) : -1);
733 EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
735 #ifdef __CLIENTDEBUG__
736 JackLibGlobals::CheckContext();
737 #endif
738 JackClient* client = (JackClient*)ext_client;
739 if (client == NULL) {
740 jack_error("jack_port_request_monitor_by_name called with a NULL client");
741 return -1;
742 } else {
743 JackGraphManager* manager = GetGraphManager();
744 if (!manager)
745 return -1;
746 jack_port_id_t myport = manager->GetPort(port_name);
747 if (!CheckPort(myport)) {
748 jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
749 return -1;
750 } else {
751 return manager->RequestMonitor(myport, onoff);
756 EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
758 #ifdef __CLIENTDEBUG__
759 JackLibGlobals::CheckContext();
760 #endif
761 #if defined(__x86_64__) || defined(__ppc64__)
762 uint64_t port_aux = (uint64_t)port;
763 #else
764 uint32_t port_aux = (uint32_t)port;
765 #endif
766 jack_port_id_t myport = (jack_port_id_t)port_aux;
767 if (!CheckPort(myport)) {
768 jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
769 return -1;
770 } else {
771 JackGraphManager* manager = GetGraphManager();
772 return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
776 EXPORT int jack_port_monitoring_input(jack_port_t* port)
778 #ifdef __CLIENTDEBUG__
779 JackLibGlobals::CheckContext();
780 #endif
781 #if defined(__x86_64__) || defined(__ppc64__)
782 uint64_t port_aux = (uint64_t)port;
783 #else
784 uint32_t port_aux = (uint32_t)port;
785 #endif
786 jack_port_id_t myport = (jack_port_id_t)port_aux;
787 if (!CheckPort(myport)) {
788 jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
789 return -1;
790 } else {
791 JackGraphManager* manager = GetGraphManager();
792 return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
796 EXPORT int jack_is_realtime(jack_client_t* ext_client)
798 #ifdef __CLIENTDEBUG__
799 JackLibGlobals::CheckContext();
800 #endif
801 JackClient* client = (JackClient*)ext_client;
802 if (client == NULL) {
803 jack_error("jack_is_realtime called with a NULL client");
804 return -1;
805 } else {
806 JackEngineControl* control = GetEngineControl();
807 return (control ? control->fRealTime : -1);
811 EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
813 #ifdef __CLIENTDEBUG__
814 JackLibGlobals::CheckContext();
815 #endif
816 JackClient* client = (JackClient*)ext_client;
817 jack_error("jack_on_shutdown: deprecated, use jack_on_info_shutdown");
818 if (client == NULL) {
819 jack_error("jack_on_shutdown called with a NULL client");
820 } else {
821 client->OnShutdown(callback, arg);
825 EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
827 #ifdef __CLIENTDEBUG__
828 JackLibGlobals::CheckContext();
829 #endif
830 JackClient* client = (JackClient*)ext_client;
831 if (client == NULL) {
832 jack_error("jack_on_info_shutdown called with a NULL client");
833 } else {
834 client->OnInfoShutdown(callback, arg);
838 EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
840 #ifdef __CLIENTDEBUG__
841 JackLibGlobals::CheckContext();
842 #endif
843 JackClient* client = (JackClient*)ext_client;
844 if (client == NULL) {
845 jack_error("jack_set_process_callback called with a NULL client");
846 return -1;
847 } else {
848 return client->SetProcessCallback(callback, arg);
852 EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
854 #ifdef __CLIENTDEBUG__
855 JackLibGlobals::CheckContext();
856 #endif
857 JackClient* client = (JackClient*)ext_client;
858 if (client == NULL) {
859 jack_error("jack_thread_wait called with a NULL client");
860 return 0;
861 } else {
862 jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
863 return 0;
867 EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
869 #ifdef __CLIENTDEBUG__
870 JackLibGlobals::CheckContext();
871 #endif
872 JackClient* client = (JackClient*)ext_client;
873 if (client == NULL) {
874 jack_error("jack_cycle_wait called with a NULL client");
875 return 0;
876 } else {
877 return client->CycleWait();
881 EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
883 #ifdef __CLIENTDEBUG__
884 JackLibGlobals::CheckContext();
885 #endif
886 JackClient* client = (JackClient*)ext_client;
887 if (client == NULL) {
888 jack_error("jack_cycle_signal called with a NULL client");
889 } else {
890 client->CycleSignal(status);
894 EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
896 #ifdef __CLIENTDEBUG__
897 JackLibGlobals::CheckContext();
898 #endif
899 JackClient* client = (JackClient*)ext_client;
900 if (client == NULL) {
901 jack_error("jack_set_process_thread called with a NULL client");
902 return -1;
903 } else {
904 return client->SetProcessThread(fun, arg);
908 EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
910 #ifdef __CLIENTDEBUG__
911 JackLibGlobals::CheckContext();
912 #endif
913 JackClient* client = (JackClient*)ext_client;
914 if (client == NULL) {
915 jack_error("jack_set_freewheel_callback called with a NULL client");
916 return -1;
917 } else {
918 return client->SetFreewheelCallback(freewheel_callback, arg);
922 EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
924 #ifdef __CLIENTDEBUG__
925 JackLibGlobals::CheckContext();
926 #endif
927 JackClient* client = (JackClient*)ext_client;
928 if (client == NULL) {
929 jack_error("jack_set_freewheel called with a NULL client");
930 return -1;
931 } else {
932 return client->SetFreeWheel(onoff);
936 EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
938 #ifdef __CLIENTDEBUG__
939 JackLibGlobals::CheckContext();
940 #endif
941 JackClient* client = (JackClient*)ext_client;
942 if (client == NULL) {
943 jack_error("jack_set_buffer_size called with a NULL client");
944 return -1;
945 } else if (!CheckBufferSize(buffer_size)) {
946 return -1;
947 } else {
948 return client->SetBufferSize(buffer_size);
952 EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
954 #ifdef __CLIENTDEBUG__
955 JackLibGlobals::CheckContext();
956 #endif
957 JackClient* client = (JackClient*)ext_client;
958 if (client == NULL) {
959 jack_error("jack_set_buffer_size_callback called with a NULL client");
960 return -1;
961 } else {
962 return client->SetBufferSizeCallback(bufsize_callback, arg);
966 EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
968 #ifdef __CLIENTDEBUG__
969 JackLibGlobals::CheckContext();
970 #endif
971 JackClient* client = (JackClient*)ext_client;
972 if (client == NULL) {
973 jack_error("jack_set_sample_rate_callback called with a NULL client");
974 return -1;
975 } else {
976 return client->SetSampleRateCallback(srate_callback, arg);
980 EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
982 #ifdef __CLIENTDEBUG__
983 JackLibGlobals::CheckContext();
984 #endif
985 JackClient* client = (JackClient*)ext_client;
986 if (client == NULL) {
987 jack_error("jack_set_client_registration_callback called with a NULL client");
988 return -1;
989 } else {
990 return client->SetClientRegistrationCallback(registration_callback, arg);
994 EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
996 #ifdef __CLIENTDEBUG__
997 JackLibGlobals::CheckContext();
998 #endif
999 JackClient* client = (JackClient*)ext_client;
1000 if (client == NULL) {
1001 jack_error("jack_set_port_registration_callback called with a NULL client");
1002 return -1;
1003 } else {
1004 return client->SetPortRegistrationCallback(registration_callback, arg);
1008 EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
1010 #ifdef __CLIENTDEBUG__
1011 JackLibGlobals::CheckContext();
1012 #endif
1013 JackClient* client = (JackClient*)ext_client;
1014 if (client == NULL) {
1015 jack_error("jack_set_port_connect_callback called with a NULL client");
1016 return -1;
1017 } else {
1018 return client->SetPortConnectCallback(portconnect_callback, arg);
1022 EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
1024 #ifdef __CLIENTDEBUG__
1025 JackLibGlobals::CheckContext();
1026 #endif
1027 JackClient* client = (JackClient*)ext_client;
1028 if (client == NULL) {
1029 jack_error("jack_set_port_rename_callback called with a NULL client");
1030 return -1;
1031 } else {
1032 return client->SetPortRenameCallback(rename_callback, arg);
1036 EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
1038 #ifdef __CLIENTDEBUG__
1039 JackLibGlobals::CheckContext();
1040 #endif
1041 JackClient* client = (JackClient*)ext_client;
1042 jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
1043 if (client == NULL) {
1044 jack_error("jack_set_graph_order_callback called with a NULL client");
1045 return -1;
1046 } else {
1047 return client->SetGraphOrderCallback(graph_callback, arg);
1051 EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
1053 #ifdef __CLIENTDEBUG__
1054 JackLibGlobals::CheckContext();
1055 #endif
1056 JackClient* client = (JackClient*)ext_client;
1057 if (client == NULL) {
1058 jack_error("jack_set_xrun_callback called with a NULL client");
1059 return -1;
1060 } else {
1061 return client->SetXRunCallback(xrun_callback, arg);
1065 EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
1067 #ifdef __CLIENTDEBUG__
1068 JackLibGlobals::CheckContext();
1069 #endif
1070 JackClient* client = (JackClient*)ext_client;
1071 jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
1072 if (client == NULL) {
1073 jack_error("jack_set_thread_init_callback called with a NULL client");
1074 return -1;
1075 } else {
1076 return client->SetInitCallback(init_callback, arg);
1080 EXPORT int jack_activate(jack_client_t* ext_client)
1082 #ifdef __CLIENTDEBUG__
1083 JackLibGlobals::CheckContext();
1084 #endif
1085 JackClient* client = (JackClient*)ext_client;
1086 if (client == NULL) {
1087 jack_error("jack_activate called with a NULL client");
1088 return -1;
1089 } else {
1090 return client->Activate();
1094 EXPORT int jack_deactivate(jack_client_t* ext_client)
1096 #ifdef __CLIENTDEBUG__
1097 JackLibGlobals::CheckContext();
1098 #endif
1099 JackClient* client = (JackClient*)ext_client;
1100 if (client == NULL) {
1101 jack_error("jack_deactivate called with a NULL client");
1102 return -1;
1103 } else {
1104 return client->Deactivate();
1108 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)
1110 #ifdef __CLIENTDEBUG__
1111 JackLibGlobals::CheckContext();
1112 #endif
1113 JackClient* client = (JackClient*)ext_client;
1114 if (client == NULL) {
1115 jack_error("jack_port_register called with a NULL client");
1116 return NULL;
1117 } else if ((port_name == NULL) || (port_type == NULL)) {
1118 jack_error("jack_port_register called with a NULL port name or a NULL port_type");
1119 return NULL;
1120 } else {
1121 #if defined(__x86_64__) || defined(__ppc64__)
1122 return (jack_port_t *)((uint64_t)client->PortRegister(port_name, port_type, flags, buffer_size));
1123 #else
1124 return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
1125 #endif
1129 EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
1131 #ifdef __CLIENTDEBUG__
1132 JackLibGlobals::CheckContext();
1133 #endif
1134 JackClient* client = (JackClient*)ext_client;
1135 if (client == NULL) {
1136 jack_error("jack_port_unregister called with a NULL client");
1137 return -1;
1139 #if defined(__x86_64__) || defined(__ppc64__)
1140 uint64_t port_aux = (uint64_t)port;
1141 #else
1142 uint32_t port_aux = (uint32_t)port;
1143 #endif
1144 jack_port_id_t myport = (jack_port_id_t)port_aux;
1145 if (!CheckPort(myport)) {
1146 jack_error("jack_port_unregister called with an incorrect port %ld", myport);
1147 return -1;
1149 return client->PortUnRegister(myport);
1152 EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
1154 #ifdef __CLIENTDEBUG__
1155 JackLibGlobals::CheckContext();
1156 #endif
1157 JackClient* client = (JackClient*)ext_client;
1158 if (client == NULL) {
1159 jack_error("jack_port_is_mine called with a NULL client");
1160 return -1;
1162 #if defined(__x86_64__) || defined(__ppc64__)
1163 uint64_t port_aux = (uint64_t)port;
1164 #else
1165 uint32_t port_aux = (uint32_t)port;
1166 #endif
1167 jack_port_id_t myport = (jack_port_id_t)port_aux;
1168 if (!CheckPort(myport)) {
1169 jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
1170 return -1;
1172 return client->PortIsMine(myport);
1175 EXPORT const char** jack_port_get_connections(const jack_port_t* port)
1177 #ifdef __CLIENTDEBUG__
1178 JackLibGlobals::CheckContext();
1179 #endif
1180 #if defined(__x86_64__) || defined(__ppc64__)
1181 uint64_t port_aux = (uint64_t)port;
1182 #else
1183 uint32_t port_aux = (uint32_t)port;
1184 #endif
1185 jack_port_id_t myport = (jack_port_id_t)port_aux;
1186 if (!CheckPort(myport)) {
1187 jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
1188 return NULL;
1189 } else {
1190 WaitGraphChange();
1191 JackGraphManager* manager = GetGraphManager();
1192 return (manager ? manager->GetConnections(myport) : NULL);
1196 // Calling client does not need to "own" the port
1197 EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
1199 #ifdef __CLIENTDEBUG__
1200 JackLibGlobals::CheckContext();
1201 #endif
1202 JackClient* client = (JackClient*)ext_client;
1203 if (client == NULL) {
1204 jack_error("jack_port_get_all_connections called with a NULL client");
1205 return NULL;
1208 #if defined(__x86_64__) || defined(__ppc64__)
1209 uint64_t port_aux = (uint64_t)port;
1210 #else
1211 uint32_t port_aux = (uint32_t)port;
1212 #endif
1213 jack_port_id_t myport = (jack_port_id_t)port_aux;
1214 if (!CheckPort(myport)) {
1215 jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
1216 return NULL;
1217 } else {
1218 WaitGraphChange();
1219 JackGraphManager* manager = GetGraphManager();
1220 return (manager ? manager->GetConnections(myport) : NULL);
1224 EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
1226 #ifdef __CLIENTDEBUG__
1227 JackLibGlobals::CheckContext();
1228 #endif
1229 JackClient* client = (JackClient*)ext_client;
1230 if (client == NULL) {
1231 jack_error("jack_port_get_total_latency called with a NULL client");
1232 return 0;
1235 #if defined(__x86_64__) || defined(__ppc64__)
1236 uint64_t port_aux = (uint64_t)port;
1237 #else
1238 uint32_t port_aux = (uint32_t)port;
1239 #endif
1240 jack_port_id_t myport = (jack_port_id_t)port_aux;
1241 if (!CheckPort(myport)) {
1242 jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
1243 return 0;
1244 } else {
1245 WaitGraphChange();
1246 JackGraphManager* manager = GetGraphManager();
1247 if (manager) {
1248 manager->ComputeTotalLatency(myport);
1249 return manager->GetPort(myport)->GetTotalLatency();
1250 } else {
1251 return 0;
1256 EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
1258 #ifdef __CLIENTDEBUG__
1259 JackLibGlobals::CheckContext();
1260 #endif
1261 JackClient* client = (JackClient*)ext_client;
1262 if (client == NULL) {
1263 jack_error("jack_connect called with a NULL client");
1264 return -1;
1265 } else if ((src == NULL) || (dst == NULL)) {
1266 jack_error("jack_connect called with a NULL port name");
1267 return -1;
1268 } else {
1269 return client->PortConnect(src, dst);
1273 EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
1275 #ifdef __CLIENTDEBUG__
1276 JackLibGlobals::CheckContext();
1277 #endif
1278 JackClient* client = (JackClient*)ext_client;
1279 if (client == NULL) {
1280 jack_error("jack_disconnect called with a NULL client");
1281 return -1;
1282 } else if ((src == NULL) || (dst == NULL)) {
1283 jack_error("jack_connect called with a NULL port name");
1284 return -1;
1285 } else {
1286 return client->PortDisconnect(src, dst);
1290 EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
1292 #ifdef __CLIENTDEBUG__
1293 JackLibGlobals::CheckContext();
1294 #endif
1295 JackClient* client = (JackClient*)ext_client;
1296 if (client == NULL) {
1297 jack_error("jack_port_disconnect called with a NULL client");
1298 return -1;
1300 #if defined(__x86_64__) || defined(__ppc64__)
1301 uint64_t port_aux = (uint64_t)src;
1302 #else
1303 uint32_t port_aux = (uint32_t)src;
1304 #endif
1305 jack_port_id_t myport = (jack_port_id_t)port_aux;
1306 if (!CheckPort(myport)) {
1307 jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
1308 return -1;
1310 return client->PortDisconnect(myport);
1313 EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
1315 #ifdef __CLIENTDEBUG__
1316 JackLibGlobals::CheckContext();
1317 #endif
1318 JackClient* client = (JackClient*)ext_client;
1319 if (client == NULL) {
1320 jack_error("jack_get_sample_rate called with a NULL client");
1321 return 0;
1322 } else {
1323 JackEngineControl* control = GetEngineControl();
1324 return (control ? control->fSampleRate : 0);
1328 EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
1330 #ifdef __CLIENTDEBUG__
1331 JackLibGlobals::CheckContext();
1332 #endif
1333 JackClient* client = (JackClient*)ext_client;
1334 if (client == NULL) {
1335 jack_error("jack_get_buffer_size called with a NULL client");
1336 return 0;
1337 } else {
1338 JackEngineControl* control = GetEngineControl();
1339 return (control ? control->fBufferSize : 0);
1343 EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
1345 #ifdef __CLIENTDEBUG__
1346 JackLibGlobals::CheckContext();
1347 #endif
1348 JackClient* client = (JackClient*)ext_client;
1349 if (client == NULL) {
1350 jack_error("jack_get_ports called with a NULL client");
1351 return NULL;
1353 JackGraphManager* manager = GetGraphManager();
1354 return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
1357 EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
1359 #ifdef __CLIENTDEBUG__
1360 JackLibGlobals::CheckContext();
1361 #endif
1362 JackClient* client = (JackClient*)ext_client;
1363 if (client == NULL) {
1364 jack_error("jack_get_ports called with a NULL client");
1365 return 0;
1368 if (portname == NULL) {
1369 jack_error("jack_port_by_name called with a NULL port name");
1370 return NULL;
1371 } else {
1372 JackGraphManager* manager = GetGraphManager();
1373 if (!manager)
1374 return NULL;
1375 int res = manager->GetPort(portname); // returns a port index at least > 1
1376 #if defined(__x86_64__) || defined(__ppc64__)
1377 return (res == NO_PORT) ? NULL : (jack_port_t*)((uint64_t)res);
1378 #else
1379 return (res == NO_PORT) ? NULL : (jack_port_t*)res;
1380 #endif
1384 EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
1386 #ifdef __CLIENTDEBUG__
1387 JackLibGlobals::CheckContext();
1388 #endif
1389 /* jack_port_t* type is actually the port index */
1390 #if defined(__x86_64__) || defined(__ppc64__)
1391 return (jack_port_t*)((uint64_t)id);
1392 #else
1393 return (jack_port_t*)id;
1394 #endif
1397 EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
1399 #ifdef __CLIENTDEBUG__
1400 JackLibGlobals::CheckContext();
1401 #endif
1402 JackClient* client = (JackClient*)ext_client;
1403 if (client == NULL) {
1404 jack_error("jack_engine_takeover_timebase called with a NULL client");
1405 return -1;
1406 } else {
1407 jack_error("jack_engine_takeover_timebase: deprecated\n");
1408 return 0;
1412 EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
1414 #ifdef __CLIENTDEBUG__
1415 JackLibGlobals::CheckContext();
1416 #endif
1417 JackTimer timer;
1418 JackEngineControl* control = GetEngineControl();
1419 if (control) {
1420 control->ReadFrameTime(&timer);
1421 return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
1422 } else {
1423 return 0;
1427 EXPORT jack_time_t jack_get_time()
1429 return GetMicroSeconds();
1432 EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
1434 #ifdef __CLIENTDEBUG__
1435 JackLibGlobals::CheckContext();
1436 #endif
1437 JackClient* client = (JackClient*)ext_client;
1438 if (client == NULL) {
1439 jack_error("jack_frames_to_time called with a NULL client");
1440 return 0;
1441 } else {
1442 JackTimer timer;
1443 JackEngineControl* control = GetEngineControl();
1444 if (control) {
1445 control->ReadFrameTime(&timer);
1446 return timer.Frames2Time(frames, control->fBufferSize);
1447 } else {
1448 return 0;
1453 EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
1455 #ifdef __CLIENTDEBUG__
1456 JackLibGlobals::CheckContext();
1457 #endif
1458 JackClient* client = (JackClient*)ext_client;
1459 if (client == NULL) {
1460 jack_error("jack_time_to_frames called with a NULL client");
1461 return 0;
1462 } else {
1463 JackTimer timer;
1464 JackEngineControl* control = GetEngineControl();
1465 if (control) {
1466 control->ReadFrameTime(&timer);
1467 return timer.Time2Frames(time, control->fBufferSize);
1468 } else {
1469 return 0;
1474 EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
1476 return jack_time_to_frames(ext_client, GetMicroSeconds());
1479 EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
1481 #ifdef __CLIENTDEBUG__
1482 JackLibGlobals::CheckContext();
1483 #endif
1484 JackEngineControl* control = GetEngineControl();
1485 return (control) ? control->fFrameTimer.ReadCurrentState()->CurFrame() : 0;
1488 EXPORT float jack_cpu_load(jack_client_t* ext_client)
1490 #ifdef __CLIENTDEBUG__
1491 JackLibGlobals::CheckContext();
1492 #endif
1493 JackClient* client = (JackClient*)ext_client;
1494 if (client == NULL) {
1495 jack_error("jack_cpu_load called with a NULL client");
1496 return 0.0f;
1497 } else {
1498 JackEngineControl* control = GetEngineControl();
1499 return (control ? control->fCPULoad : 0.0f);
1503 EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
1505 #ifdef __CLIENTDEBUG__
1506 JackLibGlobals::CheckContext();
1507 #endif
1508 JackClient* client = (JackClient*)ext_client;
1509 if (client == NULL) {
1510 jack_error("jack_client_thread_id called with a NULL client");
1511 return (pthread_t)NULL;
1512 } else {
1513 return client->GetThreadID();
1517 EXPORT char* jack_get_client_name(jack_client_t* ext_client)
1519 #ifdef __CLIENTDEBUG__
1520 JackLibGlobals::CheckContext();
1521 #endif
1522 JackClient* client = (JackClient*)ext_client;
1523 if (client == NULL) {
1524 jack_error("jack_get_client_name called with a NULL client");
1525 return NULL;
1526 } else {
1527 return client->GetClientControl()->fName;
1531 EXPORT int jack_client_name_size(void)
1533 return JACK_CLIENT_NAME_SIZE;
1536 EXPORT int jack_port_name_size(void)
1538 return JACK_PORT_NAME_SIZE;
1541 EXPORT int jack_port_type_size(void)
1543 return JACK_PORT_TYPE_SIZE;
1546 // transport.h
1547 EXPORT int jack_release_timebase(jack_client_t* ext_client)
1549 #ifdef __CLIENTDEBUG__
1550 JackLibGlobals::CheckContext();
1551 #endif
1552 JackClient* client = (JackClient*)ext_client;
1553 if (client == NULL) {
1554 jack_error("jack_release_timebase called with a NULL client");
1555 return -1;
1556 } else {
1557 return client->ReleaseTimebase();
1561 EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
1563 #ifdef __CLIENTDEBUG__
1564 JackLibGlobals::CheckContext();
1565 #endif
1566 JackClient* client = (JackClient*)ext_client;
1567 if (client == NULL) {
1568 jack_error("jack_set_sync_callback called with a NULL client");
1569 return -1;
1570 } else {
1571 return client->SetSyncCallback(sync_callback, arg);
1575 EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
1577 #ifdef __CLIENTDEBUG__
1578 JackLibGlobals::CheckContext();
1579 #endif
1580 JackClient* client = (JackClient*)ext_client;
1581 if (client == NULL) {
1582 jack_error("jack_set_sync_timeout called with a NULL client");
1583 return -1;
1584 } else {
1585 return client->SetSyncTimeout(timeout);
1589 EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
1591 #ifdef __CLIENTDEBUG__
1592 JackLibGlobals::CheckContext();
1593 #endif
1594 JackClient* client = (JackClient*)ext_client;
1595 if (client == NULL) {
1596 jack_error("jack_set_timebase_callback called with a NULL client");
1597 return -1;
1598 } else {
1599 return client->SetTimebaseCallback(conditional, timebase_callback, arg);
1603 EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
1605 #ifdef __CLIENTDEBUG__
1606 JackLibGlobals::CheckContext();
1607 #endif
1608 JackClient* client = (JackClient*)ext_client;
1609 if (client == NULL) {
1610 jack_error("jack_transport_locate called with a NULL client");
1611 return -1;
1612 } else {
1613 client->TransportLocate(frame);
1614 return 0;
1618 EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
1620 #ifdef __CLIENTDEBUG__
1621 JackLibGlobals::CheckContext();
1622 #endif
1623 JackClient* client = (JackClient*)ext_client;
1624 if (client == NULL) {
1625 jack_error("jack_transport_query called with a NULL client");
1626 return JackTransportStopped;
1627 } else {
1628 return client->TransportQuery(pos);
1632 EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
1634 #ifdef __CLIENTDEBUG__
1635 JackLibGlobals::CheckContext();
1636 #endif
1637 JackClient* client = (JackClient*)ext_client;
1638 if (client == NULL) {
1639 jack_error("jack_get_current_transport_frame called with a NULL client");
1640 return 0;
1641 } else {
1642 return client->GetCurrentTransportFrame();
1646 EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
1648 #ifdef __CLIENTDEBUG__
1649 JackLibGlobals::CheckContext();
1650 #endif
1651 JackClient* client = (JackClient*)ext_client;
1652 if (client == NULL) {
1653 jack_error("jack_transport_reposition called with a NULL client");
1654 return -1;
1655 } else {
1656 client->TransportReposition(pos);
1657 return 0;
1661 EXPORT void jack_transport_start(jack_client_t* ext_client)
1663 #ifdef __CLIENTDEBUG__
1664 JackLibGlobals::CheckContext();
1665 #endif
1666 JackClient* client = (JackClient*)ext_client;
1667 if (client == NULL) {
1668 jack_error("jack_transport_start called with a NULL client");
1669 } else {
1670 client->TransportStart();
1674 EXPORT void jack_transport_stop(jack_client_t* ext_client)
1676 #ifdef __CLIENTDEBUG__
1677 JackLibGlobals::CheckContext();
1678 #endif
1679 JackClient* client = (JackClient*)ext_client;
1680 if (client == NULL) {
1681 jack_error("jack_transport_stop called with a NULL client");
1682 } else {
1683 client->TransportStop();
1687 // deprecated
1688 EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
1690 jack_error("jack_get_transport_info: deprecated");
1691 if (tinfo)
1692 memset(tinfo, 0, sizeof(jack_transport_info_t));
1695 EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
1697 jack_error("jack_set_transport_info: deprecated");
1698 if (tinfo)
1699 memset(tinfo, 0, sizeof(jack_transport_info_t));
1702 // statistics.h
1703 EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
1705 #ifdef __CLIENTDEBUG__
1706 JackLibGlobals::CheckContext();
1707 #endif
1708 JackClient* client = (JackClient*)ext_client;
1709 if (client == NULL) {
1710 jack_error("jack_get_max_delayed_usecs called with a NULL client");
1711 return 0.f;
1712 } else {
1713 JackEngineControl* control = GetEngineControl();
1714 return (control ? control->fMaxDelayedUsecs : 0.f);
1718 EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
1720 #ifdef __CLIENTDEBUG__
1721 JackLibGlobals::CheckContext();
1722 #endif
1723 JackClient* client = (JackClient*)ext_client;
1724 if (client == NULL) {
1725 jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
1726 return 0.f;
1727 } else {
1728 JackEngineControl* control = GetEngineControl();
1729 return (control ? control->fXrunDelayedUsecs : 0.f);
1733 EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
1735 #ifdef __CLIENTDEBUG__
1736 JackLibGlobals::CheckContext();
1737 #endif
1738 JackClient* client = (JackClient*)ext_client;
1739 if (client == NULL) {
1740 jack_error("jack_reset_max_delayed_usecs called with a NULL client");
1741 } else {
1742 JackEngineControl* control = GetEngineControl();
1743 control->ResetXRun();
1747 // thread.h
1748 EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
1750 #ifdef __CLIENTDEBUG__
1751 JackLibGlobals::CheckContext();
1752 #endif
1753 JackClient* client = (JackClient*)ext_client;
1754 if (client == NULL) {
1755 jack_error("jack_client_real_time_priority called with a NULL client");
1756 return -1;
1757 } else {
1758 JackEngineControl* control = GetEngineControl();
1759 return (control->fRealTime) ? control->fClientPriority : -1;
1763 EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
1765 #ifdef __CLIENTDEBUG__
1766 JackLibGlobals::CheckContext();
1767 #endif
1768 JackClient* client = (JackClient*)ext_client;
1769 if (client == NULL) {
1770 jack_error("jack_client_max_real_time_priority called with a NULL client");
1771 return -1;
1772 } else {
1773 JackEngineControl* control = GetEngineControl();
1774 return (control->fRealTime) ? control->fMaxClientPriority : -1;
1778 EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
1780 JackEngineControl* control = GetEngineControl();
1781 return (control ? JackThread::AcquireRealTimeImp(thread, priority, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1);
1784 EXPORT int jack_client_create_thread(jack_client_t* client,
1785 pthread_t *thread,
1786 int priority,
1787 int realtime, /* boolean */
1788 thread_routine routine,
1789 void *arg)
1791 return JackThread::StartImp(thread, priority, realtime, routine, arg);
1794 EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
1796 return JackThread::DropRealTimeImp(thread);
1799 EXPORT int jack_client_stop_thread(jack_client_t* client, pthread_t thread)
1801 return JackThread::StopImp(thread);
1804 EXPORT int jack_client_kill_thread(jack_client_t* client, pthread_t thread)
1806 return JackThread::KillImp(thread);
1809 #ifndef WIN32
1810 EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
1812 JackGlobals::fJackThreadCreator = (jtc == NULL) ? pthread_create : jtc;
1814 #endif
1816 // intclient.h
1817 EXPORT int jack_internal_client_new (const char *client_name,
1818 const char *load_name,
1819 const char *load_init)
1821 jack_error("jack_internal_client_new: deprecated");
1822 return -1;
1825 EXPORT void jack_internal_client_close (const char *client_name)
1827 jack_error("jack_internal_client_close: deprecated");
1830 EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
1832 #ifdef __CLIENTDEBUG__
1833 JackLibGlobals::CheckContext();
1834 #endif
1835 JackClient* client = (JackClient*)ext_client;
1836 if (client == NULL) {
1837 jack_error("jack_get_internal_client_name called with a NULL client");
1838 return NULL;
1839 } else if (intclient >= CLIENT_NUM) {
1840 jack_error("jack_get_internal_client_name: incorrect client");
1841 return NULL;
1842 } else {
1843 return client->GetInternalClientName(intclient);
1847 EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
1849 #ifdef __CLIENTDEBUG__
1850 JackLibGlobals::CheckContext();
1851 #endif
1852 JackClient* client = (JackClient*)ext_client;
1853 if (client == NULL) {
1854 jack_error("jack_internal_client_handle called with a NULL client");
1855 return 0;
1856 } else {
1857 jack_status_t my_status;
1858 if (status == NULL) /* no status from caller? */
1859 status = &my_status; /* use local status word */
1860 *status = (jack_status_t)0;
1861 return client->InternalClientHandle(client_name, status);
1865 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)
1867 #ifdef __CLIENTDEBUG__
1868 JackLibGlobals::CheckContext();
1869 #endif
1870 JackClient* client = (JackClient*)ext_client;
1871 if (client == NULL) {
1872 jack_error("jack_internal_client_load called with a NULL client");
1873 return 0;
1874 } else {
1875 jack_varargs_t va;
1876 jack_status_t my_status;
1878 if (status == NULL) /* no status from caller? */
1879 status = &my_status; /* use local status word */
1880 *status = (jack_status_t)0;
1882 /* validate parameters */
1883 if ((options & ~JackLoadOptions)) {
1884 int my_status1 = *status | (JackFailure | JackInvalidOption);
1885 *status = (jack_status_t)my_status1;
1886 return 0;
1889 /* parse variable arguments */
1890 jack_varargs_parse(options, ap, &va);
1891 return client->InternalClientLoad(client_name, options, status, &va);
1895 EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client, const char *client_name, jack_options_t options, jack_status_t *status, ...)
1897 va_list ap;
1898 va_start(ap, status);
1899 jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
1900 va_end(ap);
1901 return res;
1904 EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
1906 #ifdef __CLIENTDEBUG__
1907 JackLibGlobals::CheckContext();
1908 #endif
1909 JackClient* client = (JackClient*)ext_client;
1910 if (client == NULL) {
1911 jack_error("jack_internal_client_unload called with a NULL client");
1912 return (jack_status_t)(JackNoSuchClient | JackFailure);
1913 } else if (intclient >= CLIENT_NUM) {
1914 jack_error("jack_internal_client_unload: incorrect client");
1915 return (jack_status_t)(JackNoSuchClient | JackFailure);
1916 } else {
1917 jack_status_t my_status;
1918 client->InternalClientUnload(intclient, &my_status);
1919 return my_status;
1923 EXPORT
1924 void
1925 jack_get_version(
1926 int *major_ptr,
1927 int *minor_ptr,
1928 int *micro_ptr,
1929 int *proto_ptr)
1931 // FIXME: We need these comming from build system
1932 *major_ptr = 0;
1933 *minor_ptr = 0;
1934 *micro_ptr = 0;
1935 *proto_ptr = 0;
1938 EXPORT
1939 const char *
1940 jack_get_version_string()
1942 return VERSION;
1945 EXPORT void jack_free(void* ptr)
1947 free(ptr);