jackd2-pointersize.patch applied.
[jack2.git] / common / JackAPI.cpp
blob6acb364096c74a66815f08d8f35c2168197ae2db
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 uintptr_t port_aux = (uintptr_t)port;
321 jack_port_id_t myport = (jack_port_id_t)port_aux;
322 if (!CheckPort(myport)) {
323 jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
324 return NULL;
325 } else {
326 JackGraphManager* manager = GetGraphManager();
327 return (manager ? manager->GetBuffer(myport, frames) : NULL);
331 EXPORT const char* jack_port_name(const jack_port_t* port)
333 #ifdef __CLIENTDEBUG__
334 JackGlobals::CheckContext("jack_port_name");
335 #endif
336 uintptr_t port_aux = (uintptr_t)port;
337 jack_port_id_t myport = (jack_port_id_t)port_aux;
338 if (!CheckPort(myport)) {
339 jack_error("jack_port_name called with an incorrect port %ld", myport);
340 return NULL;
341 } else {
342 JackGraphManager* manager = GetGraphManager();
343 return (manager ? manager->GetPort(myport)->GetName() : NULL);
347 EXPORT const char* jack_port_short_name(const jack_port_t* port)
349 #ifdef __CLIENTDEBUG__
350 JackGlobals::CheckContext("jack_port_short_name");
351 #endif
352 uintptr_t port_aux = (uintptr_t)port;
353 jack_port_id_t myport = (jack_port_id_t)port_aux;
354 if (!CheckPort(myport)) {
355 jack_error("jack_port_short_name called with an incorrect port %ld", myport);
356 return NULL;
357 } else {
358 JackGraphManager* manager = GetGraphManager();
359 return (manager ? manager->GetPort(myport)->GetShortName() : NULL);
363 EXPORT int jack_port_flags(const jack_port_t* port)
365 #ifdef __CLIENTDEBUG__
366 JackGlobals::CheckContext("jack_port_flags");
367 #endif
368 uintptr_t port_aux = (uintptr_t)port;
369 jack_port_id_t myport = (jack_port_id_t)port_aux;
370 if (!CheckPort(myport)) {
371 jack_error("jack_port_flags called with an incorrect port %ld", myport);
372 return -1;
373 } else {
374 JackGraphManager* manager = GetGraphManager();
375 return (manager ? manager->GetPort(myport)->GetFlags() : -1);
379 EXPORT const char* jack_port_type(const jack_port_t* port)
381 #ifdef __CLIENTDEBUG__
382 JackGlobals::CheckContext("jack_port_type");
383 #endif
384 uintptr_t port_aux = (uintptr_t)port;
385 jack_port_id_t myport = (jack_port_id_t)port_aux;
386 if (!CheckPort(myport)) {
387 jack_error("jack_port_flags called an incorrect port %ld", myport);
388 return NULL;
389 } else {
390 JackGraphManager* manager = GetGraphManager();
391 return (manager ? manager->GetPort(myport)->GetType() : NULL);
395 EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
397 #ifdef __CLIENTDEBUG__
398 JackGlobals::CheckContext("jack_port_type_id");
399 #endif
400 uintptr_t port_aux = (uintptr_t)port;
401 jack_port_id_t myport = (jack_port_id_t)port_aux;
402 if (!CheckPort(myport)) {
403 jack_error("jack_port_type_id called an incorrect port %ld", myport);
404 return 0;
405 } else {
406 JackGraphManager* manager = GetGraphManager();
407 return (manager ? GetPortTypeId(manager->GetPort(myport)->GetType()) : 0);
411 EXPORT int jack_port_connected(const jack_port_t* port)
413 #ifdef __CLIENTDEBUG__
414 JackGlobals::CheckContext("jack_port_connected");
415 #endif
416 uintptr_t port_aux = (uintptr_t)port;
417 jack_port_id_t myport = (jack_port_id_t)port_aux;
418 if (!CheckPort(myport)) {
419 jack_error("jack_port_connected called with an incorrect port %ld", myport);
420 return -1;
421 } else {
422 WaitGraphChange();
423 JackGraphManager* manager = GetGraphManager();
424 return (manager ? manager->GetConnectionsNum(myport) : -1);
428 EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name)
430 #ifdef __CLIENTDEBUG__
431 JackGlobals::CheckContext("jack_port_connected_to");
432 #endif
433 uintptr_t port_aux = (uintptr_t)port;
434 jack_port_id_t src = (jack_port_id_t)port_aux;
435 if (!CheckPort(src)) {
436 jack_error("jack_port_connected_to called with an incorrect port %ld", src);
437 return -1;
438 } else if (port_name == NULL) {
439 jack_error("jack_port_connected_to called with a NULL port name");
440 return -1;
441 } else {
442 WaitGraphChange();
443 JackGraphManager* manager = GetGraphManager();
444 jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT);
445 if (dst == NO_PORT) {
446 jack_error("Unknown destination port port_name = %s", port_name);
447 return 0;
448 } else {
449 return manager->IsConnected(src, dst);
454 EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
456 #ifdef __CLIENTDEBUG__
457 JackGlobals::CheckContext("jack_port_tie");
458 #endif
459 uintptr_t src_aux = (uintptr_t)src;
460 jack_port_id_t mysrc = (jack_port_id_t)src_aux;
461 if (!CheckPort(mysrc)) {
462 jack_error("jack_port_tie called with a NULL src port");
463 return -1;
465 uintptr_t dst_aux = (uintptr_t)dst;
466 jack_port_id_t mydst = (jack_port_id_t)dst_aux;
467 if (!CheckPort(mydst)) {
468 jack_error("jack_port_tie called with a NULL dst port");
469 return -1;
471 JackGraphManager* manager = GetGraphManager();
472 if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) {
473 jack_error("jack_port_tie called with ports not belonging to the same client");
474 return -1;
475 } else {
476 return manager->GetPort(mydst)->Tie(mysrc);
480 EXPORT int jack_port_untie(jack_port_t* port)
482 #ifdef __CLIENTDEBUG__
483 JackGlobals::CheckContext("jack_port_untie");
484 #endif
485 uintptr_t port_aux = (uintptr_t)port;
486 jack_port_id_t myport = (jack_port_id_t)port_aux;
487 if (!CheckPort(myport)) {
488 jack_error("jack_port_untie called with an incorrect port %ld", myport);
489 return -1;
490 } else {
491 JackGraphManager* manager = GetGraphManager();
492 return (manager ? manager->GetPort(myport)->UnTie() : -1);
496 EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
498 #ifdef __CLIENTDEBUG__
499 JackGlobals::CheckContext("jack_port_get_latency");
500 #endif
501 uintptr_t port_aux = (uintptr_t)port;
502 jack_port_id_t myport = (jack_port_id_t)port_aux;
503 if (!CheckPort(myport)) {
504 jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
505 return 0;
506 } else {
507 WaitGraphChange();
508 JackGraphManager* manager = GetGraphManager();
509 return (manager ? manager->GetPort(myport)->GetLatency() : 0);
513 EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
515 #ifdef __CLIENTDEBUG__
516 JackGlobals::CheckContext("jack_port_set_latency");
517 #endif
518 uintptr_t port_aux = (uintptr_t)port;
519 jack_port_id_t myport = (jack_port_id_t)port_aux;
520 if (!CheckPort(myport)) {
521 jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
522 } else {
523 JackGraphManager* manager = GetGraphManager();
524 if (manager)
525 manager->GetPort(myport)->SetLatency(frames);
529 EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
531 #ifdef __CLIENTDEBUG__
532 JackGlobals::CheckContext("jack_recompute_total_latency");
533 #endif
535 JackClient* client = (JackClient*)ext_client;
536 uintptr_t port_aux = (uintptr_t)port;
537 jack_port_id_t myport = (jack_port_id_t)port_aux;
538 if (client == NULL) {
539 jack_error("jack_recompute_total_latencies called with a NULL client");
540 return -1;
541 } else if (!CheckPort(myport)) {
542 jack_error("jack_recompute_total_latencies called with a NULL port");
543 return -1;
544 } else {
545 WaitGraphChange();
546 JackGraphManager* manager = GetGraphManager();
547 return (manager ? manager->ComputeTotalLatency(myport) : -1);
551 EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
553 #ifdef __CLIENTDEBUG__
554 JackGlobals::CheckContext("jack_recompute_total_latencies");
555 #endif
557 JackClient* client = (JackClient*)ext_client;
558 if (client == NULL) {
559 jack_error("jack_recompute_total_latencies called with a NULL client");
560 return -1;
561 } else {
562 WaitGraphChange();
563 JackGraphManager* manager = GetGraphManager();
564 return (manager ? manager->ComputeTotalLatencies() : -1);
569 This is unsafe if case of concurrent access, and should be "serialized" doing a server call.
572 EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
574 #ifdef __CLIENTDEBUG__
575 JackGlobals::CheckContext("jack_port_set_name");
576 #endif
577 uintptr_t port_aux = (uintptr_t)port;
578 jack_port_id_t myport = (jack_port_id_t)port_aux;
579 if (!CheckPort(myport)) {
580 jack_error("jack_port_set_name called with an incorrect port %ld", myport);
581 return -1;
582 } else if (name == NULL) {
583 jack_error("jack_port_set_name called with a NULL port name");
584 return -1;
585 } else {
586 JackGraphManager* manager = GetGraphManager();
587 int refnum;
588 if (manager && ((refnum = manager->GetPort(myport)->GetRefNum()) > 0)) {
589 JackClient* client = JackGlobals::fClientTable[refnum];
590 assert(client);
591 return client->PortRename(myport, name);
592 } else {
593 return -1;
598 EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
600 #ifdef __CLIENTDEBUG__
601 JackGlobals::CheckContext("jack_port_set_alias");
602 #endif
603 uintptr_t port_aux = (uintptr_t)port;
604 jack_port_id_t myport = (jack_port_id_t)port_aux;
605 if (!CheckPort(myport)) {
606 jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
607 return -1;
608 } else if (name == NULL) {
609 jack_error("jack_port_set_alias called with a NULL port name");
610 return -1;
611 } else {
612 JackGraphManager* manager = GetGraphManager();
613 return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
617 EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
619 #ifdef __CLIENTDEBUG__
620 JackGlobals::CheckContext("jack_port_unset_alias");
621 #endif
622 uintptr_t port_aux = (uintptr_t)port;
623 jack_port_id_t myport = (jack_port_id_t)port_aux;
624 if (!CheckPort(myport)) {
625 jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
626 return -1;
627 } else if (name == NULL) {
628 jack_error("jack_port_unset_alias called with a NULL port name");
629 return -1;
630 } else {
631 JackGraphManager* manager = GetGraphManager();
632 return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
636 EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
638 #ifdef __CLIENTDEBUG__
639 JackGlobals::CheckContext("jack_port_get_aliases");
640 #endif
641 uintptr_t port_aux = (uintptr_t)port;
642 jack_port_id_t myport = (jack_port_id_t)port_aux;
643 if (!CheckPort(myport)) {
644 jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
645 return -1;
646 } else {
647 JackGraphManager* manager = GetGraphManager();
648 return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
652 EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
654 #ifdef __CLIENTDEBUG__
655 JackGlobals::CheckContext("jack_port_request_monitor");
656 #endif
657 uintptr_t port_aux = (uintptr_t)port;
658 jack_port_id_t myport = (jack_port_id_t)port_aux;
659 if (!CheckPort(myport)) {
660 jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
661 return -1;
662 } else {
663 JackGraphManager* manager = GetGraphManager();
664 return (manager ? manager->RequestMonitor(myport, onoff) : -1);
668 EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
670 #ifdef __CLIENTDEBUG__
671 JackGlobals::CheckContext("jack_port_request_monitor_by_name");
672 #endif
673 JackClient* client = (JackClient*)ext_client;
674 if (client == NULL) {
675 jack_error("jack_port_request_monitor_by_name called with a NULL client");
676 return -1;
677 } else {
678 JackGraphManager* manager = GetGraphManager();
679 if (!manager)
680 return -1;
681 jack_port_id_t myport = manager->GetPort(port_name);
682 if (!CheckPort(myport)) {
683 jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
684 return -1;
685 } else {
686 return manager->RequestMonitor(myport, onoff);
691 EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
693 #ifdef __CLIENTDEBUG__
694 JackGlobals::CheckContext("jack_port_ensure_monitor");
695 #endif
696 uintptr_t port_aux = (uintptr_t)port;
697 jack_port_id_t myport = (jack_port_id_t)port_aux;
698 if (!CheckPort(myport)) {
699 jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
700 return -1;
701 } else {
702 JackGraphManager* manager = GetGraphManager();
703 return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
707 EXPORT int jack_port_monitoring_input(jack_port_t* port)
709 #ifdef __CLIENTDEBUG__
710 JackGlobals::CheckContext("jack_port_monitoring_input");
711 #endif
712 uintptr_t port_aux = (uintptr_t)port;
713 jack_port_id_t myport = (jack_port_id_t)port_aux;
714 if (!CheckPort(myport)) {
715 jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
716 return -1;
717 } else {
718 JackGraphManager* manager = GetGraphManager();
719 return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
723 EXPORT int jack_is_realtime(jack_client_t* ext_client)
725 #ifdef __CLIENTDEBUG__
726 JackGlobals::CheckContext("jack_is_realtime");
727 #endif
728 JackClient* client = (JackClient*)ext_client;
729 if (client == NULL) {
730 jack_error("jack_is_realtime called with a NULL client");
731 return -1;
732 } else {
733 JackEngineControl* control = GetEngineControl();
734 return (control ? control->fRealTime : -1);
738 EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
740 #ifdef __CLIENTDEBUG__
741 JackGlobals::CheckContext("jack_on_shutdown");
742 #endif
743 JackClient* client = (JackClient*)ext_client;
744 if (client == NULL) {
745 jack_error("jack_on_shutdown called with a NULL client");
746 } else {
747 client->OnShutdown(callback, arg);
751 EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
753 #ifdef __CLIENTDEBUG__
754 JackGlobals::CheckContext("jack_on_info_shutdown");
755 #endif
756 JackClient* client = (JackClient*)ext_client;
757 if (client == NULL) {
758 jack_error("jack_on_info_shutdown called with a NULL client");
759 } else {
760 client->OnInfoShutdown(callback, arg);
764 EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
766 #ifdef __CLIENTDEBUG__
767 JackGlobals::CheckContext("jack_set_process_callback");
768 #endif
769 JackClient* client = (JackClient*)ext_client;
770 if (client == NULL) {
771 jack_error("jack_set_process_callback called with a NULL client");
772 return -1;
773 } else {
774 return client->SetProcessCallback(callback, arg);
778 EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
780 #ifdef __CLIENTDEBUG__
781 JackGlobals::CheckContext("jack_thread_wait");
782 #endif
783 JackClient* client = (JackClient*)ext_client;
784 if (client == NULL) {
785 jack_error("jack_thread_wait called with a NULL client");
786 return 0;
787 } else {
788 jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
789 return 0;
793 EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
795 #ifdef __CLIENTDEBUG__
796 JackGlobals::CheckContext("jack_cycle_wait");
797 #endif
798 JackClient* client = (JackClient*)ext_client;
799 if (client == NULL) {
800 jack_error("jack_cycle_wait called with a NULL client");
801 return 0;
802 } else {
803 return client->CycleWait();
807 EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
809 #ifdef __CLIENTDEBUG__
810 JackGlobals::CheckContext("jack_cycle_signal");
811 #endif
812 JackClient* client = (JackClient*)ext_client;
813 if (client == NULL) {
814 jack_error("jack_cycle_signal called with a NULL client");
815 } else {
816 client->CycleSignal(status);
820 EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
822 #ifdef __CLIENTDEBUG__
823 JackGlobals::CheckContext("jack_set_process_thread");
824 #endif
825 JackClient* client = (JackClient*)ext_client;
826 if (client == NULL) {
827 jack_error("jack_set_process_thread called with a NULL client");
828 return -1;
829 } else {
830 return client->SetProcessThread(fun, arg);
834 EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
836 #ifdef __CLIENTDEBUG__
837 JackGlobals::CheckContext("jack_set_freewheel_callback");
838 #endif
839 JackClient* client = (JackClient*)ext_client;
840 if (client == NULL) {
841 jack_error("jack_set_freewheel_callback called with a NULL client");
842 return -1;
843 } else {
844 return client->SetFreewheelCallback(freewheel_callback, arg);
848 EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
850 #ifdef __CLIENTDEBUG__
851 JackGlobals::CheckContext("jack_set_freewheel");
852 #endif
853 JackClient* client = (JackClient*)ext_client;
854 if (client == NULL) {
855 jack_error("jack_set_freewheel called with a NULL client");
856 return -1;
857 } else {
858 return client->SetFreeWheel(onoff);
862 EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
864 #ifdef __CLIENTDEBUG__
865 JackGlobals::CheckContext("jack_set_buffer_size");
866 #endif
867 JackClient* client = (JackClient*)ext_client;
868 if (client == NULL) {
869 jack_error("jack_set_buffer_size called with a NULL client");
870 return -1;
871 } else if (!CheckBufferSize(buffer_size)) {
872 return -1;
873 } else {
874 return client->SetBufferSize(buffer_size);
878 EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
880 #ifdef __CLIENTDEBUG__
881 JackGlobals::CheckContext("jack_set_buffer_size_callback");
882 #endif
883 JackClient* client = (JackClient*)ext_client;
884 if (client == NULL) {
885 jack_error("jack_set_buffer_size_callback called with a NULL client");
886 return -1;
887 } else {
888 return client->SetBufferSizeCallback(bufsize_callback, arg);
892 EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
894 #ifdef __CLIENTDEBUG__
895 JackGlobals::CheckContext("jack_set_sample_rate_callback");
896 #endif
897 JackClient* client = (JackClient*)ext_client;
898 if (client == NULL) {
899 jack_error("jack_set_sample_rate_callback called with a NULL client");
900 return -1;
901 } else {
902 return client->SetSampleRateCallback(srate_callback, arg);
906 EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
908 #ifdef __CLIENTDEBUG__
909 JackGlobals::CheckContext("jack_set_client_registration_callback");
910 #endif
911 JackClient* client = (JackClient*)ext_client;
912 if (client == NULL) {
913 jack_error("jack_set_client_registration_callback called with a NULL client");
914 return -1;
915 } else {
916 return client->SetClientRegistrationCallback(registration_callback, arg);
920 EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
922 #ifdef __CLIENTDEBUG__
923 JackGlobals::CheckContext("jack_set_port_registration_callback");
924 #endif
925 JackClient* client = (JackClient*)ext_client;
926 if (client == NULL) {
927 jack_error("jack_set_port_registration_callback called with a NULL client");
928 return -1;
929 } else {
930 return client->SetPortRegistrationCallback(registration_callback, arg);
934 EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
936 #ifdef __CLIENTDEBUG__
937 JackGlobals::CheckContext("jack_set_port_connect_callback");
938 #endif
939 JackClient* client = (JackClient*)ext_client;
940 if (client == NULL) {
941 jack_error("jack_set_port_connect_callback called with a NULL client");
942 return -1;
943 } else {
944 return client->SetPortConnectCallback(portconnect_callback, arg);
948 EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
950 #ifdef __CLIENTDEBUG__
951 JackGlobals::CheckContext("jack_set_port_rename_callback");
952 #endif
953 JackClient* client = (JackClient*)ext_client;
954 if (client == NULL) {
955 jack_error("jack_set_port_rename_callback called with a NULL client");
956 return -1;
957 } else {
958 return client->SetPortRenameCallback(rename_callback, arg);
962 EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
964 #ifdef __CLIENTDEBUG__
965 JackGlobals::CheckContext("jack_set_graph_order_callback");
966 #endif
967 JackClient* client = (JackClient*)ext_client;
968 jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
969 if (client == NULL) {
970 jack_error("jack_set_graph_order_callback called with a NULL client");
971 return -1;
972 } else {
973 return client->SetGraphOrderCallback(graph_callback, arg);
977 EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
979 #ifdef __CLIENTDEBUG__
980 JackGlobals::CheckContext("jack_set_xrun_callback");
981 #endif
982 JackClient* client = (JackClient*)ext_client;
983 if (client == NULL) {
984 jack_error("jack_set_xrun_callback called with a NULL client");
985 return -1;
986 } else {
987 return client->SetXRunCallback(xrun_callback, arg);
991 EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
993 #ifdef __CLIENTDEBUG__
994 JackGlobals::CheckContext("jack_set_thread_init_callback");
995 #endif
996 JackClient* client = (JackClient*)ext_client;
997 jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
998 if (client == NULL) {
999 jack_error("jack_set_thread_init_callback called with a NULL client");
1000 return -1;
1001 } else {
1002 return client->SetInitCallback(init_callback, arg);
1006 EXPORT int jack_activate(jack_client_t* ext_client)
1008 #ifdef __CLIENTDEBUG__
1009 JackGlobals::CheckContext("jack_activate");
1010 #endif
1011 JackClient* client = (JackClient*)ext_client;
1012 if (client == NULL) {
1013 jack_error("jack_activate called with a NULL client");
1014 return -1;
1015 } else {
1016 return client->Activate();
1020 EXPORT int jack_deactivate(jack_client_t* ext_client)
1022 #ifdef __CLIENTDEBUG__
1023 JackGlobals::CheckContext("jack_deactivate");
1024 #endif
1025 JackClient* client = (JackClient*)ext_client;
1026 if (client == NULL) {
1027 jack_error("jack_deactivate called with a NULL client");
1028 return -1;
1029 } else {
1030 return client->Deactivate();
1034 EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
1036 #ifdef __CLIENTDEBUG__
1037 JackGlobals::CheckContext("jack_port_register");
1038 #endif
1039 JackClient* client = (JackClient*)ext_client;
1040 if (client == NULL) {
1041 jack_error("jack_port_register called with a NULL client");
1042 return NULL;
1043 } else if ((port_name == NULL) || (port_type == NULL)) {
1044 jack_error("jack_port_register called with a NULL port name or a NULL port_type");
1045 return NULL;
1046 } else {
1047 return (jack_port_t *)((uintptr_t)client->PortRegister(port_name, port_type, flags, buffer_size));
1051 EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
1053 #ifdef __CLIENTDEBUG__
1054 JackGlobals::CheckContext("jack_port_unregister");
1055 #endif
1056 JackClient* client = (JackClient*)ext_client;
1057 if (client == NULL) {
1058 jack_error("jack_port_unregister called with a NULL client");
1059 return -1;
1061 uintptr_t port_aux = (uintptr_t)port;
1062 jack_port_id_t myport = (jack_port_id_t)port_aux;
1063 if (!CheckPort(myport)) {
1064 jack_error("jack_port_unregister called with an incorrect port %ld", myport);
1065 return -1;
1067 return client->PortUnRegister(myport);
1070 EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
1072 #ifdef __CLIENTDEBUG__
1073 JackGlobals::CheckContext("jack_port_is_mine");
1074 #endif
1075 JackClient* client = (JackClient*)ext_client;
1076 if (client == NULL) {
1077 jack_error("jack_port_is_mine called with a NULL client");
1078 return -1;
1080 uintptr_t port_aux = (uintptr_t)port;
1081 jack_port_id_t myport = (jack_port_id_t)port_aux;
1082 if (!CheckPort(myport)) {
1083 jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
1084 return -1;
1086 return client->PortIsMine(myport);
1089 EXPORT const char** jack_port_get_connections(const jack_port_t* port)
1091 #ifdef __CLIENTDEBUG__
1092 JackGlobals::CheckContext("jack_port_get_connections");
1093 #endif
1094 uintptr_t port_aux = (uintptr_t)port;
1095 jack_port_id_t myport = (jack_port_id_t)port_aux;
1096 if (!CheckPort(myport)) {
1097 jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
1098 return NULL;
1099 } else {
1100 WaitGraphChange();
1101 JackGraphManager* manager = GetGraphManager();
1102 return (manager ? manager->GetConnections(myport) : NULL);
1106 // Calling client does not need to "own" the port
1107 EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
1109 #ifdef __CLIENTDEBUG__
1110 JackGlobals::CheckContext("jack_port_get_all_connections");
1111 #endif
1112 JackClient* client = (JackClient*)ext_client;
1113 if (client == NULL) {
1114 jack_error("jack_port_get_all_connections called with a NULL client");
1115 return NULL;
1118 uintptr_t port_aux = (uintptr_t)port;
1119 jack_port_id_t myport = (jack_port_id_t)port_aux;
1120 if (!CheckPort(myport)) {
1121 jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
1122 return NULL;
1123 } else {
1124 WaitGraphChange();
1125 JackGraphManager* manager = GetGraphManager();
1126 return (manager ? manager->GetConnections(myport) : NULL);
1130 EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
1132 #ifdef __CLIENTDEBUG__
1133 JackGlobals::CheckContext("jack_port_get_total_latency");
1134 #endif
1135 JackClient* client = (JackClient*)ext_client;
1136 if (client == NULL) {
1137 jack_error("jack_port_get_total_latency called with a NULL client");
1138 return 0;
1141 uintptr_t port_aux = (uintptr_t)port;
1142 jack_port_id_t myport = (jack_port_id_t)port_aux;
1143 if (!CheckPort(myport)) {
1144 jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
1145 return 0;
1146 } else {
1147 WaitGraphChange();
1148 JackGraphManager* manager = GetGraphManager();
1149 if (manager) {
1150 manager->ComputeTotalLatency(myport);
1151 return manager->GetPort(myport)->GetTotalLatency();
1152 } else {
1153 return 0;
1158 EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
1160 #ifdef __CLIENTDEBUG__
1161 JackGlobals::CheckContext("jack_connect");
1162 #endif
1163 JackClient* client = (JackClient*)ext_client;
1164 if (client == NULL) {
1165 jack_error("jack_connect called with a NULL client");
1166 return -1;
1167 } else if ((src == NULL) || (dst == NULL)) {
1168 jack_error("jack_connect called with a NULL port name");
1169 return -1;
1170 } else {
1171 return client->PortConnect(src, dst);
1175 EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
1177 #ifdef __CLIENTDEBUG__
1178 JackGlobals::CheckContext("jack_disconnect");
1179 #endif
1180 JackClient* client = (JackClient*)ext_client;
1181 if (client == NULL) {
1182 jack_error("jack_disconnect called with a NULL client");
1183 return -1;
1184 } else if ((src == NULL) || (dst == NULL)) {
1185 jack_error("jack_connect called with a NULL port name");
1186 return -1;
1187 } else {
1188 return client->PortDisconnect(src, dst);
1192 EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
1194 #ifdef __CLIENTDEBUG__
1195 JackGlobals::CheckContext("jack_port_disconnect");
1196 #endif
1197 JackClient* client = (JackClient*)ext_client;
1198 if (client == NULL) {
1199 jack_error("jack_port_disconnect called with a NULL client");
1200 return -1;
1202 uintptr_t port_aux = (uintptr_t)src;
1203 jack_port_id_t myport = (jack_port_id_t)port_aux;
1204 if (!CheckPort(myport)) {
1205 jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
1206 return -1;
1208 return client->PortDisconnect(myport);
1211 EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
1213 #ifdef __CLIENTDEBUG__
1214 JackGlobals::CheckContext("jack_get_sample_rate");
1215 #endif
1216 JackClient* client = (JackClient*)ext_client;
1217 if (client == NULL) {
1218 jack_error("jack_get_sample_rate called with a NULL client");
1219 return 0;
1220 } else {
1221 JackEngineControl* control = GetEngineControl();
1222 return (control ? control->fSampleRate : 0);
1226 EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
1228 #ifdef __CLIENTDEBUG__
1229 JackGlobals::CheckContext("jack_get_buffer_size");
1230 #endif
1231 JackClient* client = (JackClient*)ext_client;
1232 if (client == NULL) {
1233 jack_error("jack_get_buffer_size called with a NULL client");
1234 return 0;
1235 } else {
1236 JackEngineControl* control = GetEngineControl();
1237 return (control ? control->fBufferSize : 0);
1241 EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
1243 #ifdef __CLIENTDEBUG__
1244 JackGlobals::CheckContext("jack_get_ports");
1245 #endif
1246 JackClient* client = (JackClient*)ext_client;
1247 if (client == NULL) {
1248 jack_error("jack_get_ports called with a NULL client");
1249 return NULL;
1251 JackGraphManager* manager = GetGraphManager();
1252 return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
1255 EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
1257 #ifdef __CLIENTDEBUG__
1258 JackGlobals::CheckContext("jack_port_by_name");
1259 #endif
1260 JackClient* client = (JackClient*)ext_client;
1261 if (client == NULL) {
1262 jack_error("jack_get_ports called with a NULL client");
1263 return 0;
1266 if (portname == NULL) {
1267 jack_error("jack_port_by_name called with a NULL port name");
1268 return NULL;
1269 } else {
1270 JackGraphManager* manager = GetGraphManager();
1271 if (!manager)
1272 return NULL;
1273 int res = manager->GetPort(portname); // returns a port index at least > 1
1274 return (res == NO_PORT) ? NULL : (jack_port_t*)((uintptr_t)res);
1278 EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
1280 #ifdef __CLIENTDEBUG__
1281 JackGlobals::CheckContext("jack_port_by_id");
1282 #endif
1283 /* jack_port_t* type is actually the port index */
1284 return (jack_port_t*)((uintptr_t)id);
1287 EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
1289 #ifdef __CLIENTDEBUG__
1290 JackGlobals::CheckContext("jack_engine_takeover_timebase");
1291 #endif
1292 JackClient* client = (JackClient*)ext_client;
1293 if (client == NULL) {
1294 jack_error("jack_engine_takeover_timebase called with a NULL client");
1295 return -1;
1296 } else {
1297 jack_error("jack_engine_takeover_timebase: deprecated\n");
1298 return 0;
1302 EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
1304 #ifdef __CLIENTDEBUG__
1305 JackGlobals::CheckContext("jack_frames_since_cycle_start");
1306 #endif
1307 JackTimer timer;
1308 JackEngineControl* control = GetEngineControl();
1309 if (control) {
1310 control->ReadFrameTime(&timer);
1311 return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
1312 } else {
1313 return 0;
1317 EXPORT jack_time_t jack_get_time()
1319 #ifdef __CLIENTDEBUG__
1320 JackGlobals::CheckContext("jack_get_time");
1321 #endif
1322 return GetMicroSeconds();
1325 EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
1327 #ifdef __CLIENTDEBUG__
1328 JackGlobals::CheckContext("jack_frames_to_time");
1329 #endif
1330 JackClient* client = (JackClient*)ext_client;
1331 if (client == NULL) {
1332 jack_error("jack_frames_to_time called with a NULL client");
1333 return 0;
1334 } else {
1335 JackTimer timer;
1336 JackEngineControl* control = GetEngineControl();
1337 if (control) {
1338 control->ReadFrameTime(&timer);
1339 return timer.Frames2Time(frames, control->fBufferSize);
1340 } else {
1341 return 0;
1346 EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
1348 #ifdef __CLIENTDEBUG__
1349 JackGlobals::CheckContext("jack_time_to_frames");
1350 #endif
1351 JackClient* client = (JackClient*)ext_client;
1352 if (client == NULL) {
1353 jack_error("jack_time_to_frames called with a NULL client");
1354 return 0;
1355 } else {
1356 JackTimer timer;
1357 JackEngineControl* control = GetEngineControl();
1358 if (control) {
1359 control->ReadFrameTime(&timer);
1360 return timer.Time2Frames(time, control->fBufferSize);
1361 } else {
1362 return 0;
1367 EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
1369 #ifdef __CLIENTDEBUG__
1370 JackGlobals::CheckContext("jack_frame_time");
1371 #endif
1372 return jack_time_to_frames(ext_client, GetMicroSeconds());
1375 EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
1377 #ifdef __CLIENTDEBUG__
1378 JackGlobals::CheckContext("jack_last_frame_time");
1379 #endif
1380 JackEngineControl* control = GetEngineControl();
1381 return (control) ? control->fFrameTimer.ReadCurrentState()->CurFrame() : 0;
1384 EXPORT float jack_cpu_load(jack_client_t* ext_client)
1386 #ifdef __CLIENTDEBUG__
1387 JackGlobals::CheckContext("jack_cpu_load");
1388 #endif
1389 JackClient* client = (JackClient*)ext_client;
1390 if (client == NULL) {
1391 jack_error("jack_cpu_load called with a NULL client");
1392 return 0.0f;
1393 } else {
1394 JackEngineControl* control = GetEngineControl();
1395 return (control ? control->fCPULoad : 0.0f);
1399 EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
1401 #ifdef __CLIENTDEBUG__
1402 JackGlobals::CheckContext("jack_client_thread_id");
1403 #endif
1404 JackClient* client = (JackClient*)ext_client;
1405 if (client == NULL) {
1406 jack_error("jack_client_thread_id called with a NULL client");
1407 return (pthread_t)NULL;
1408 } else {
1409 return client->GetThreadID();
1413 EXPORT char* jack_get_client_name(jack_client_t* ext_client)
1415 #ifdef __CLIENTDEBUG__
1416 JackGlobals::CheckContext("jack_get_client_name");
1417 #endif
1418 JackClient* client = (JackClient*)ext_client;
1419 if (client == NULL) {
1420 jack_error("jack_get_client_name called with a NULL client");
1421 return NULL;
1422 } else {
1423 return client->GetClientControl()->fName;
1427 EXPORT int jack_client_name_size(void)
1429 return JACK_CLIENT_NAME_SIZE;
1432 EXPORT int jack_port_name_size(void)
1434 return JACK_PORT_NAME_SIZE;
1437 EXPORT int jack_port_type_size(void)
1439 return JACK_PORT_TYPE_SIZE;
1442 // transport.h
1443 EXPORT int jack_release_timebase(jack_client_t* ext_client)
1445 #ifdef __CLIENTDEBUG__
1446 JackGlobals::CheckContext("jack_release_timebase");
1447 #endif
1448 JackClient* client = (JackClient*)ext_client;
1449 if (client == NULL) {
1450 jack_error("jack_release_timebase called with a NULL client");
1451 return -1;
1452 } else {
1453 return client->ReleaseTimebase();
1457 EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
1459 #ifdef __CLIENTDEBUG__
1460 JackGlobals::CheckContext("jack_set_sync_callback");
1461 #endif
1462 JackClient* client = (JackClient*)ext_client;
1463 if (client == NULL) {
1464 jack_error("jack_set_sync_callback called with a NULL client");
1465 return -1;
1466 } else {
1467 return client->SetSyncCallback(sync_callback, arg);
1471 EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
1473 #ifdef __CLIENTDEBUG__
1474 JackGlobals::CheckContext("jack_set_sync_timeout");
1475 #endif
1476 JackClient* client = (JackClient*)ext_client;
1477 if (client == NULL) {
1478 jack_error("jack_set_sync_timeout called with a NULL client");
1479 return -1;
1480 } else {
1481 return client->SetSyncTimeout(timeout);
1485 EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
1487 #ifdef __CLIENTDEBUG__
1488 JackGlobals::CheckContext("jack_set_timebase_callback");
1489 #endif
1490 JackClient* client = (JackClient*)ext_client;
1491 if (client == NULL) {
1492 jack_error("jack_set_timebase_callback called with a NULL client");
1493 return -1;
1494 } else {
1495 return client->SetTimebaseCallback(conditional, timebase_callback, arg);
1499 EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
1501 #ifdef __CLIENTDEBUG__
1502 JackGlobals::CheckContext("jack_transport_locate");
1503 #endif
1504 JackClient* client = (JackClient*)ext_client;
1505 if (client == NULL) {
1506 jack_error("jack_transport_locate called with a NULL client");
1507 return -1;
1508 } else {
1509 client->TransportLocate(frame);
1510 return 0;
1514 EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
1516 #ifdef __CLIENTDEBUG__
1517 JackGlobals::CheckContext("jack_transport_query");
1518 #endif
1519 JackClient* client = (JackClient*)ext_client;
1520 if (client == NULL) {
1521 jack_error("jack_transport_query called with a NULL client");
1522 return JackTransportStopped;
1523 } else {
1524 return client->TransportQuery(pos);
1528 EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
1530 #ifdef __CLIENTDEBUG__
1531 JackGlobals::CheckContext("jack_get_current_transport_frame");
1532 #endif
1533 JackClient* client = (JackClient*)ext_client;
1534 if (client == NULL) {
1535 jack_error("jack_get_current_transport_frame called with a NULL client");
1536 return 0;
1537 } else {
1538 return client->GetCurrentTransportFrame();
1542 EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
1544 #ifdef __CLIENTDEBUG__
1545 JackGlobals::CheckContext("jack_transport_reposition");
1546 #endif
1547 JackClient* client = (JackClient*)ext_client;
1548 if (client == NULL) {
1549 jack_error("jack_transport_reposition called with a NULL client");
1550 return -1;
1551 } else {
1552 client->TransportReposition(pos);
1553 return 0;
1557 EXPORT void jack_transport_start(jack_client_t* ext_client)
1559 #ifdef __CLIENTDEBUG__
1560 JackGlobals::CheckContext("jack_transport_start");
1561 #endif
1562 JackClient* client = (JackClient*)ext_client;
1563 if (client == NULL) {
1564 jack_error("jack_transport_start called with a NULL client");
1565 } else {
1566 client->TransportStart();
1570 EXPORT void jack_transport_stop(jack_client_t* ext_client)
1572 #ifdef __CLIENTDEBUG__
1573 JackGlobals::CheckContext("jack_transport_stop");
1574 #endif
1575 JackClient* client = (JackClient*)ext_client;
1576 if (client == NULL) {
1577 jack_error("jack_transport_stop called with a NULL client");
1578 } else {
1579 client->TransportStop();
1583 // deprecated
1584 EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
1586 #ifdef __CLIENTDEBUG__
1587 JackGlobals::CheckContext("jack_get_transport_info");
1588 #endif
1589 jack_error("jack_get_transport_info: deprecated");
1590 if (tinfo)
1591 memset(tinfo, 0, sizeof(jack_transport_info_t));
1594 EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
1596 #ifdef __CLIENTDEBUG__
1597 JackGlobals::CheckContext("jack_set_transport_info");
1598 #endif
1599 jack_error("jack_set_transport_info: deprecated");
1600 if (tinfo)
1601 memset(tinfo, 0, sizeof(jack_transport_info_t));
1604 // statistics.h
1605 EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
1607 #ifdef __CLIENTDEBUG__
1608 JackGlobals::CheckContext("jack_get_max_delayed_usecs");
1609 #endif
1610 JackClient* client = (JackClient*)ext_client;
1611 if (client == NULL) {
1612 jack_error("jack_get_max_delayed_usecs called with a NULL client");
1613 return 0.f;
1614 } else {
1615 JackEngineControl* control = GetEngineControl();
1616 return (control ? control->fMaxDelayedUsecs : 0.f);
1620 EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
1622 #ifdef __CLIENTDEBUG__
1623 JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
1624 #endif
1625 JackClient* client = (JackClient*)ext_client;
1626 if (client == NULL) {
1627 jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
1628 return 0.f;
1629 } else {
1630 JackEngineControl* control = GetEngineControl();
1631 return (control ? control->fXrunDelayedUsecs : 0.f);
1635 EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
1637 #ifdef __CLIENTDEBUG__
1638 JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
1639 #endif
1640 JackClient* client = (JackClient*)ext_client;
1641 if (client == NULL) {
1642 jack_error("jack_reset_max_delayed_usecs called with a NULL client");
1643 } else {
1644 JackEngineControl* control = GetEngineControl();
1645 control->ResetXRun();
1649 // thread.h
1650 EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
1652 #ifdef __CLIENTDEBUG__
1653 JackGlobals::CheckContext("jack_client_real_time_priority");
1654 #endif
1655 JackClient* client = (JackClient*)ext_client;
1656 if (client == NULL) {
1657 jack_error("jack_client_real_time_priority called with a NULL client");
1658 return -1;
1659 } else {
1660 JackEngineControl* control = GetEngineControl();
1661 return (control->fRealTime) ? control->fClientPriority : -1;
1665 EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
1667 #ifdef __CLIENTDEBUG__
1668 JackGlobals::CheckContext("jack_client_max_real_time_priority");
1669 #endif
1670 JackClient* client = (JackClient*)ext_client;
1671 if (client == NULL) {
1672 jack_error("jack_client_max_real_time_priority called with a NULL client");
1673 return -1;
1674 } else {
1675 JackEngineControl* control = GetEngineControl();
1676 return (control->fRealTime) ? control->fMaxClientPriority : -1;
1680 EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
1682 JackEngineControl* control = GetEngineControl();
1683 return (control ? JackThread::AcquireRealTimeImp(thread, priority, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1);
1686 EXPORT int jack_client_create_thread(jack_client_t* client,
1687 pthread_t *thread,
1688 int priority,
1689 int realtime, /* boolean */
1690 thread_routine routine,
1691 void *arg)
1693 #ifdef __CLIENTDEBUG__
1694 JackGlobals::CheckContext("jack_client_create_thread");
1695 #endif
1696 return JackThread::StartImp(thread, priority, realtime, routine, arg);
1699 EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
1701 return JackThread::DropRealTimeImp(thread);
1704 EXPORT int jack_client_stop_thread(jack_client_t* client, pthread_t thread)
1706 #ifdef __CLIENTDEBUG__
1707 JackGlobals::CheckContext("jack_client_stop_thread");
1708 #endif
1709 return JackThread::StopImp(thread);
1712 EXPORT int jack_client_kill_thread(jack_client_t* client, pthread_t thread)
1714 #ifdef __CLIENTDEBUG__
1715 JackGlobals::CheckContext("jack_client_kill_thread");
1716 #endif
1717 return JackThread::KillImp(thread);
1720 #ifndef WIN32
1721 EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
1723 JackGlobals::fJackThreadCreator = (jtc == NULL) ? pthread_create : jtc;
1725 #endif
1727 // intclient.h
1728 EXPORT int jack_internal_client_new (const char *client_name,
1729 const char *load_name,
1730 const char *load_init)
1732 jack_error("jack_internal_client_new: deprecated");
1733 return -1;
1736 EXPORT void jack_internal_client_close (const char *client_name)
1738 jack_error("jack_internal_client_close: deprecated");
1741 EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
1743 #ifdef __CLIENTDEBUG__
1744 JackGlobals::CheckContext("jack_get_internal_client_name");
1745 #endif
1746 JackClient* client = (JackClient*)ext_client;
1747 if (client == NULL) {
1748 jack_error("jack_get_internal_client_name called with a NULL client");
1749 return NULL;
1750 } else if (intclient >= CLIENT_NUM) {
1751 jack_error("jack_get_internal_client_name: incorrect client");
1752 return NULL;
1753 } else {
1754 return client->GetInternalClientName(intclient);
1758 EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
1760 #ifdef __CLIENTDEBUG__
1761 JackGlobals::CheckContext("jack_internal_client_handle");
1762 #endif
1763 JackClient* client = (JackClient*)ext_client;
1764 if (client == NULL) {
1765 jack_error("jack_internal_client_handle called with a NULL client");
1766 return 0;
1767 } else {
1768 jack_status_t my_status;
1769 if (status == NULL) /* no status from caller? */
1770 status = &my_status; /* use local status word */
1771 *status = (jack_status_t)0;
1772 return client->InternalClientHandle(client_name, status);
1776 EXPORT jack_intclient_t jack_internal_client_load_aux(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
1778 #ifdef __CLIENTDEBUG__
1779 JackGlobals::CheckContext("jack_internal_client_load_aux");
1780 #endif
1781 JackClient* client = (JackClient*)ext_client;
1782 if (client == NULL) {
1783 jack_error("jack_internal_client_load called with a NULL client");
1784 return 0;
1785 } else {
1786 jack_varargs_t va;
1787 jack_status_t my_status;
1789 if (status == NULL) /* no status from caller? */
1790 status = &my_status; /* use local status word */
1791 *status = (jack_status_t)0;
1793 /* validate parameters */
1794 if ((options & ~JackLoadOptions)) {
1795 int my_status1 = *status | (JackFailure | JackInvalidOption);
1796 *status = (jack_status_t)my_status1;
1797 return 0;
1800 /* parse variable arguments */
1801 jack_varargs_parse(options, ap, &va);
1802 return client->InternalClientLoad(client_name, options, status, &va);
1806 EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client, const char *client_name, jack_options_t options, jack_status_t *status, ...)
1808 va_list ap;
1809 va_start(ap, status);
1810 jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
1811 va_end(ap);
1812 return res;
1815 EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
1817 #ifdef __CLIENTDEBUG__
1818 JackGlobals::CheckContext("jack_internal_client_load");
1819 #endif
1820 JackClient* client = (JackClient*)ext_client;
1821 if (client == NULL) {
1822 jack_error("jack_internal_client_unload called with a NULL client");
1823 return (jack_status_t)(JackNoSuchClient | JackFailure);
1824 } else if (intclient >= CLIENT_NUM) {
1825 jack_error("jack_internal_client_unload: incorrect client");
1826 return (jack_status_t)(JackNoSuchClient | JackFailure);
1827 } else {
1828 jack_status_t my_status;
1829 client->InternalClientUnload(intclient, &my_status);
1830 return my_status;
1834 EXPORT
1835 void
1836 jack_get_version(
1837 int *major_ptr,
1838 int *minor_ptr,
1839 int *micro_ptr,
1840 int *proto_ptr)
1842 // FIXME: We need these comming from build system
1843 *major_ptr = 0;
1844 *minor_ptr = 0;
1845 *micro_ptr = 0;
1846 *proto_ptr = 0;
1849 EXPORT
1850 const char *
1851 jack_get_version_string()
1853 return VERSION;
1856 EXPORT void jack_free(void* ptr)
1858 if (ptr) {
1859 free(ptr);