Jack2  1.9.9
JackAPI.cpp
1 /*
2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2008 Grame
4 
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.
9 
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.
14 
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.
18 
19 */
20 
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 "JackPortType.h"
29 #include <math.h>
30 
31 using namespace Jack;
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38  typedef void (*print_function)(const char*);
39  typedef void *(*thread_routine)(void*);
40 
41  LIB_EXPORT
42  void
43  jack_get_version(
44  int *major_ptr,
45  int *minor_ptr,
46  int *micro_ptr,
47  int *proto_ptr);
48 
49  LIB_EXPORT
50  const char*
51  jack_get_version_string();
52 
53  jack_client_t * jack_client_new_aux(const char* client_name,
54  jack_options_t options,
55  jack_status_t *status);
56 
57  LIB_EXPORT jack_client_t * jack_client_open(const char* client_name,
58  jack_options_t options,
59  jack_status_t *status, ...);
60  LIB_EXPORT jack_client_t * jack_client_new(const char* client_name);
61  LIB_EXPORT int jack_client_name_size(void);
62  LIB_EXPORT char* jack_get_client_name(jack_client_t *client);
63  LIB_EXPORT int jack_internal_client_new(const char* client_name,
64  const char* load_name,
65  const char* load_init);
66  LIB_EXPORT void jack_internal_client_close(const char* client_name);
67  LIB_EXPORT int jack_is_realtime(jack_client_t *client);
68  LIB_EXPORT void jack_on_shutdown(jack_client_t *client,
69  JackShutdownCallback shutdown_callback, void *arg);
70  LIB_EXPORT void jack_on_info_shutdown(jack_client_t *client,
71  JackInfoShutdownCallback shutdown_callback, void *arg);
72  LIB_EXPORT int jack_set_process_callback(jack_client_t *client,
73  JackProcessCallback process_callback,
74  void *arg);
75  LIB_EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status);
76 
77  // new
78  LIB_EXPORT jack_nframes_t jack_cycle_wait(jack_client_t*);
79  LIB_EXPORT void jack_cycle_signal(jack_client_t*, int status);
80  LIB_EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg);
81 
82  LIB_EXPORT int jack_set_thread_init_callback(jack_client_t *client,
83  JackThreadInitCallback thread_init_callback,
84  void *arg);
85  LIB_EXPORT int jack_set_freewheel_callback(jack_client_t *client,
86  JackFreewheelCallback freewheel_callback,
87  void *arg);
88  LIB_EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
89  LIB_EXPORT int jack_set_buffer_size(jack_client_t *client, jack_nframes_t nframes);
90  LIB_EXPORT int jack_set_buffer_size_callback(jack_client_t *client,
91  JackBufferSizeCallback bufsize_callback,
92  void *arg);
93  LIB_EXPORT int jack_set_sample_rate_callback(jack_client_t *client,
94  JackSampleRateCallback srate_callback,
95  void *arg);
96  LIB_EXPORT int jack_set_client_registration_callback(jack_client_t *,
97  JackClientRegistrationCallback
98  registration_callback, void *arg);
99  LIB_EXPORT int jack_set_port_registration_callback(jack_client_t *,
100  JackPortRegistrationCallback
101  registration_callback, void *arg);
102  LIB_EXPORT int jack_set_port_connect_callback(jack_client_t *,
103  JackPortConnectCallback
104  connect_callback, void *arg);
105  LIB_EXPORT int jack_set_port_rename_callback(jack_client_t *,
106  JackPortRenameCallback
107  rename_callback, void *arg);
108  LIB_EXPORT int jack_set_graph_order_callback(jack_client_t *,
109  JackGraphOrderCallback graph_callback,
110  void *);
111  LIB_EXPORT int jack_set_xrun_callback(jack_client_t *,
112  JackXRunCallback xrun_callback, void *arg);
113  LIB_EXPORT int jack_set_latency_callback(jack_client_t *client,
114  JackLatencyCallback latency_callback, void *arg);
115 
116  LIB_EXPORT int jack_activate(jack_client_t *client);
117  LIB_EXPORT int jack_deactivate(jack_client_t *client);
118  LIB_EXPORT jack_port_t * jack_port_register(jack_client_t *client,
119  const char* port_name,
120  const char* port_type,
121  unsigned long flags,
122  unsigned long buffer_size);
123  LIB_EXPORT int jack_port_unregister(jack_client_t *, jack_port_t *);
124  LIB_EXPORT void * jack_port_get_buffer(jack_port_t *, jack_nframes_t);
125  LIB_EXPORT const char* jack_port_name(const jack_port_t *port);
126  LIB_EXPORT const char* jack_port_short_name(const jack_port_t *port);
127  LIB_EXPORT int jack_port_flags(const jack_port_t *port);
128  LIB_EXPORT const char* jack_port_type(const jack_port_t *port);
129  LIB_EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port);
130  LIB_EXPORT int jack_port_is_mine(const jack_client_t *, const jack_port_t *port);
131  LIB_EXPORT int jack_port_connected(const jack_port_t *port);
132  LIB_EXPORT int jack_port_connected_to(const jack_port_t *port,
133  const char* port_name);
134  LIB_EXPORT const char* * jack_port_get_connections(const jack_port_t *port);
135  LIB_EXPORT const char* * jack_port_get_all_connections(const jack_client_t *client,
136  const jack_port_t *port);
137  LIB_EXPORT int jack_port_tie(jack_port_t *src, jack_port_t *dst);
138  LIB_EXPORT int jack_port_untie(jack_port_t *port);
139 
140  // Old latency API
141  LIB_EXPORT jack_nframes_t jack_port_get_latency(jack_port_t *port);
142  LIB_EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t *,
143  jack_port_t *port);
144  LIB_EXPORT void jack_port_set_latency(jack_port_t *, jack_nframes_t);
145  LIB_EXPORT int jack_recompute_total_latency(jack_client_t*, jack_port_t* port);
146 
147  // New latency API
148  LIB_EXPORT void jack_port_get_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range);
149  LIB_EXPORT void jack_port_set_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range);
150  LIB_EXPORT int jack_recompute_total_latencies(jack_client_t*);
151 
152  LIB_EXPORT int jack_port_set_name(jack_port_t *port, const char* port_name);
153  LIB_EXPORT int jack_port_set_alias(jack_port_t *port, const char* alias);
154  LIB_EXPORT int jack_port_unset_alias(jack_port_t *port, const char* alias);
155  LIB_EXPORT int jack_port_get_aliases(const jack_port_t *port, char* const aliases[2]);
156  LIB_EXPORT int jack_port_request_monitor(jack_port_t *port, int onoff);
157  LIB_EXPORT int jack_port_request_monitor_by_name(jack_client_t *client,
158  const char* port_name, int onoff);
159  LIB_EXPORT int jack_port_ensure_monitor(jack_port_t *port, int onoff);
160  LIB_EXPORT int jack_port_monitoring_input(jack_port_t *port);
161  LIB_EXPORT int jack_connect(jack_client_t *,
162  const char* source_port,
163  const char* destination_port);
164  LIB_EXPORT int jack_disconnect(jack_client_t *,
165  const char* source_port,
166  const char* destination_port);
167  LIB_EXPORT int jack_port_disconnect(jack_client_t *, jack_port_t *);
168  LIB_EXPORT int jack_port_name_size(void);
169  LIB_EXPORT int jack_port_type_size(void);
170  LIB_EXPORT size_t jack_port_type_get_buffer_size(jack_client_t *client, const char* port_type);
171  LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t *);
172  LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t *);
173  LIB_EXPORT const char* * jack_get_ports(jack_client_t *,
174  const char* port_name_pattern,
175  const char* type_name_pattern,
176  unsigned long flags);
177  LIB_EXPORT jack_port_t * jack_port_by_name(jack_client_t *, const char* port_name);
178  LIB_EXPORT jack_port_t * jack_port_by_id(jack_client_t *client,
179  jack_port_id_t port_id);
180  LIB_EXPORT int jack_engine_takeover_timebase(jack_client_t *);
181  LIB_EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t *);
182  LIB_EXPORT jack_time_t jack_get_time();
183  LIB_EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t usecs);
184  LIB_EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames);
185  LIB_EXPORT jack_nframes_t jack_frame_time(const jack_client_t *);
186  LIB_EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t *client);
187  LIB_EXPORT int jack_get_cycle_times(const jack_client_t *client,
188  jack_nframes_t *current_frames,
189  jack_time_t *current_usecs,
190  jack_time_t *next_usecs,
191  float *period_usecs);
192  LIB_EXPORT float jack_cpu_load(jack_client_t *client);
193  LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t *);
194  LIB_EXPORT void jack_set_error_function(print_function);
195  LIB_EXPORT void jack_set_info_function(print_function);
196 
197  LIB_EXPORT float jack_get_max_delayed_usecs(jack_client_t *client);
198  LIB_EXPORT float jack_get_xrun_delayed_usecs(jack_client_t *client);
199  LIB_EXPORT void jack_reset_max_delayed_usecs(jack_client_t *client);
200 
201  LIB_EXPORT int jack_release_timebase(jack_client_t *client);
202  LIB_EXPORT int jack_set_sync_callback(jack_client_t *client,
203  JackSyncCallback sync_callback,
204  void *arg);
205  LIB_EXPORT int jack_set_sync_timeout(jack_client_t *client,
206  jack_time_t timeout);
207  LIB_EXPORT int jack_set_timebase_callback(jack_client_t *client,
208  int conditional,
209  JackTimebaseCallback timebase_callback,
210  void *arg);
211  LIB_EXPORT int jack_transport_locate(jack_client_t *client,
212  jack_nframes_t frame);
213  LIB_EXPORT jack_transport_state_t jack_transport_query(const jack_client_t *client,
214  jack_position_t *pos);
215  LIB_EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t *client);
216  LIB_EXPORT int jack_transport_reposition(jack_client_t *client,
217  const jack_position_t *pos);
218  LIB_EXPORT void jack_transport_start(jack_client_t *client);
219  LIB_EXPORT void jack_transport_stop(jack_client_t *client);
220  LIB_EXPORT void jack_get_transport_info(jack_client_t *client,
221  jack_transport_info_t *tinfo);
222  LIB_EXPORT void jack_set_transport_info(jack_client_t *client,
223  jack_transport_info_t *tinfo);
224 
225  LIB_EXPORT int jack_client_real_time_priority(jack_client_t*);
226  LIB_EXPORT int jack_client_max_real_time_priority(jack_client_t*);
227  LIB_EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority);
228  LIB_EXPORT int jack_client_create_thread(jack_client_t* client,
229  jack_native_thread_t *thread,
230  int priority,
231  int realtime, // boolean
232  thread_routine routine,
233  void *arg);
234  LIB_EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread);
235 
236  LIB_EXPORT int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread);
237  LIB_EXPORT int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread);
238 #ifndef WIN32
239  LIB_EXPORT void jack_set_thread_creator(jack_thread_creator_t jtc);
240 #endif
241  LIB_EXPORT char * jack_get_internal_client_name(jack_client_t *client,
242  jack_intclient_t intclient);
243  LIB_EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t *client,
244  const char* client_name,
245  jack_status_t *status);
246  LIB_EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client,
247  const char* client_name,
248  jack_options_t options,
249  jack_status_t *status, ...);
250 
251  LIB_EXPORT jack_status_t jack_internal_client_unload(jack_client_t *client,
252  jack_intclient_t intclient);
253  LIB_EXPORT void jack_free(void* ptr);
254 
255  LIB_EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg);
256  LIB_EXPORT jack_session_command_t *jack_session_notify(jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path);
257  LIB_EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event);
258  LIB_EXPORT void jack_session_event_free(jack_session_event_t* ev);
259  LIB_EXPORT char* jack_client_get_uuid (jack_client_t *client);
260  LIB_EXPORT char* jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name);
261  LIB_EXPORT char* jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid);
262  LIB_EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* name, const char* uuid);
263  LIB_EXPORT void jack_session_commands_free(jack_session_command_t *cmds);
264  LIB_EXPORT int jack_client_has_session_callback(jack_client_t *client, const char* client_name);
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 static inline bool CheckPort(jack_port_id_t port_index)
271 {
272  return (port_index > 0 && port_index < PORT_NUM_MAX);
273 }
274 
275 static inline bool CheckBufferSize(jack_nframes_t buffer_size)
276 {
277  return (buffer_size >= 1 && buffer_size <= BUFFER_SIZE_MAX);
278 }
279 
280 static inline void WaitGraphChange()
281 {
282  /*
283  TLS key that is set only in RT thread, so never waits for pending
284  graph change in RT context (just read the current graph state).
285  */
286 
287  if (jack_tls_get(JackGlobals::fRealTimeThread) == NULL) {
288  JackGraphManager* manager = GetGraphManager();
289  JackEngineControl* control = GetEngineControl();
290  assert(manager);
291  assert(control);
292  if (manager->IsPendingChange()) {
293  jack_log("WaitGraphChange...");
294  JackSleep(int(control->fPeriodUsecs * 1.1f));
295  }
296  }
297 }
298 
299 LIB_EXPORT void jack_set_error_function(print_function func)
300 {
301  jack_error_callback = (func == NULL) ? &default_jack_error_callback : func;
302 }
303 
304 LIB_EXPORT void jack_set_info_function(print_function func)
305 {
306  jack_info_callback = (func == NULL) ? &default_jack_info_callback : func;
307 }
308 
309 LIB_EXPORT jack_client_t* jack_client_new(const char* client_name)
310 {
311  JackGlobals::CheckContext("jack_client_new");
312 
313  try {
314  assert(JackGlobals::fOpenMutex);
315  JackGlobals::fOpenMutex->Lock();
316  jack_error("jack_client_new: deprecated");
317  int options = JackUseExactName;
318  if (getenv("JACK_START_SERVER") == NULL) {
319  options |= JackNoStartServer;
320  }
321  jack_client_t* res = jack_client_new_aux(client_name, (jack_options_t)options, NULL);
322  JackGlobals::fOpenMutex->Unlock();
323  return res;
324  } catch (std::bad_alloc& e) {
325  jack_error("Memory allocation error...");
326  return NULL;
327  } catch (...) {
328  jack_error("Unknown error...");
329  return NULL;
330  }
331 }
332 
333 LIB_EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
334 {
335  JackGlobals::CheckContext("jack_port_get_buffer");
336 
337  uintptr_t port_aux = (uintptr_t)port;
338  jack_port_id_t myport = (jack_port_id_t)port_aux;
339  if (!CheckPort(myport)) {
340  jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
341  return NULL;
342  } else {
343  JackGraphManager* manager = GetGraphManager();
344  return (manager ? manager->GetBuffer(myport, frames) : NULL);
345  }
346 }
347 
348 LIB_EXPORT const char* jack_port_name(const jack_port_t* port)
349 {
350  JackGlobals::CheckContext("jack_port_name");
351 
352  uintptr_t port_aux = (uintptr_t)port;
353  jack_port_id_t myport = (jack_port_id_t)port_aux;
354  if (!CheckPort(myport)) {
355  jack_error("jack_port_name called with an incorrect port %ld", myport);
356  return NULL;
357  } else {
358  JackGraphManager* manager = GetGraphManager();
359  return (manager ? manager->GetPort(myport)->GetName() : NULL);
360  }
361 }
362 
363 LIB_EXPORT const char* jack_port_short_name(const jack_port_t* port)
364 {
365  JackGlobals::CheckContext("jack_port_short_name");
366 
367  uintptr_t port_aux = (uintptr_t)port;
368  jack_port_id_t myport = (jack_port_id_t)port_aux;
369  if (!CheckPort(myport)) {
370  jack_error("jack_port_short_name called with an incorrect port %ld", myport);
371  return NULL;
372  } else {
373  JackGraphManager* manager = GetGraphManager();
374  return (manager ? manager->GetPort(myport)->GetShortName() : NULL);
375  }
376 }
377 
378 LIB_EXPORT int jack_port_flags(const jack_port_t* port)
379 {
380  JackGlobals::CheckContext("jack_port_flags");
381 
382  uintptr_t port_aux = (uintptr_t)port;
383  jack_port_id_t myport = (jack_port_id_t)port_aux;
384  if (!CheckPort(myport)) {
385  jack_error("jack_port_flags called with an incorrect port %ld", myport);
386  return -1;
387  } else {
388  JackGraphManager* manager = GetGraphManager();
389  return (manager ? manager->GetPort(myport)->GetFlags() : -1);
390  }
391 }
392 
393 LIB_EXPORT const char* jack_port_type(const jack_port_t* port)
394 {
395  JackGlobals::CheckContext("jack_port_type");
396 
397  uintptr_t port_aux = (uintptr_t)port;
398  jack_port_id_t myport = (jack_port_id_t)port_aux;
399  if (!CheckPort(myport)) {
400  jack_error("jack_port_flags called an incorrect port %ld", myport);
401  return NULL;
402  } else {
403  JackGraphManager* manager = GetGraphManager();
404  return (manager ? manager->GetPort(myport)->GetType() : NULL);
405  }
406 }
407 
408 LIB_EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
409 {
410  JackGlobals::CheckContext("jack_port_type_id");
411 
412  uintptr_t port_aux = (uintptr_t)port;
413  jack_port_id_t myport = (jack_port_id_t)port_aux;
414  if (!CheckPort(myport)) {
415  jack_error("jack_port_type_id called an incorrect port %ld", myport);
416  return 0;
417  } else {
418  JackGraphManager* manager = GetGraphManager();
419  return (manager ? GetPortTypeId(manager->GetPort(myport)->GetType()) : 0);
420  }
421 }
422 
423 LIB_EXPORT int jack_port_connected(const jack_port_t* port)
424 {
425  JackGlobals::CheckContext("jack_port_connected");
426 
427  uintptr_t port_aux = (uintptr_t)port;
428  jack_port_id_t myport = (jack_port_id_t)port_aux;
429  if (!CheckPort(myport)) {
430  jack_error("jack_port_connected called with an incorrect port %ld", myport);
431  return -1;
432  } else {
433  WaitGraphChange();
434  JackGraphManager* manager = GetGraphManager();
435  return (manager ? manager->GetConnectionsNum(myport) : -1);
436  }
437 }
438 
439 LIB_EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name)
440 {
441  JackGlobals::CheckContext("jack_port_connected_to");
442 
443  uintptr_t port_aux = (uintptr_t)port;
444  jack_port_id_t src = (jack_port_id_t)port_aux;
445  if (!CheckPort(src)) {
446  jack_error("jack_port_connected_to called with an incorrect port %ld", src);
447  return -1;
448  } else if (port_name == NULL) {
449  jack_error("jack_port_connected_to called with a NULL port name");
450  return -1;
451  } else {
452  WaitGraphChange();
453  JackGraphManager* manager = GetGraphManager();
454  jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT);
455  if (dst == NO_PORT) {
456  jack_error("Unknown destination port port_name = %s", port_name);
457  return 0;
458  } else {
459  return manager->IsConnected(src, dst);
460  }
461  }
462 }
463 
464 LIB_EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
465 {
466  JackGlobals::CheckContext("jack_port_tie");
467 
468  uintptr_t src_aux = (uintptr_t)src;
469  jack_port_id_t mysrc = (jack_port_id_t)src_aux;
470  if (!CheckPort(mysrc)) {
471  jack_error("jack_port_tie called with a NULL src port");
472  return -1;
473  }
474  uintptr_t dst_aux = (uintptr_t)dst;
475  jack_port_id_t mydst = (jack_port_id_t)dst_aux;
476  if (!CheckPort(mydst)) {
477  jack_error("jack_port_tie called with a NULL dst port");
478  return -1;
479  }
480  JackGraphManager* manager = GetGraphManager();
481  if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) {
482  jack_error("jack_port_tie called with ports not belonging to the same client");
483  return -1;
484  } else {
485  return manager->GetPort(mydst)->Tie(mysrc);
486  }
487 }
488 
489 LIB_EXPORT int jack_port_untie(jack_port_t* port)
490 {
491  JackGlobals::CheckContext("jack_port_untie");
492 
493  uintptr_t port_aux = (uintptr_t)port;
494  jack_port_id_t myport = (jack_port_id_t)port_aux;
495  if (!CheckPort(myport)) {
496  jack_error("jack_port_untie called with an incorrect port %ld", myport);
497  return -1;
498  } else {
499  JackGraphManager* manager = GetGraphManager();
500  return (manager ? manager->GetPort(myport)->UnTie() : -1);
501  }
502 }
503 
504 LIB_EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
505 {
506  JackGlobals::CheckContext("jack_port_get_latency");
507 
508  uintptr_t port_aux = (uintptr_t)port;
509  jack_port_id_t myport = (jack_port_id_t)port_aux;
510  if (!CheckPort(myport)) {
511  jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
512  return 0;
513  } else {
514  WaitGraphChange();
515  JackGraphManager* manager = GetGraphManager();
516  return (manager ? manager->GetPort(myport)->GetLatency() : 0);
517  }
518 }
519 
520 LIB_EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
521 {
522  JackGlobals::CheckContext("jack_port_set_latency");
523 
524  uintptr_t port_aux = (uintptr_t)port;
525  jack_port_id_t myport = (jack_port_id_t)port_aux;
526  if (!CheckPort(myport)) {
527  jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
528  } else {
529  JackGraphManager* manager = GetGraphManager();
530  if (manager)
531  manager->GetPort(myport)->SetLatency(frames);
532  }
533 }
534 
535 LIB_EXPORT void jack_port_get_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
536 {
537  JackGlobals::CheckContext("jack_port_get_latency_range");
538 
539  uintptr_t port_aux = (uintptr_t)port;
540  jack_port_id_t myport = (jack_port_id_t)port_aux;
541  if (!CheckPort(myport)) {
542  jack_error("jack_port_get_latency_range called with an incorrect port %ld", myport);
543  } else {
544  WaitGraphChange();
545  JackGraphManager* manager = GetGraphManager();
546  if (manager)
547  manager->GetPort(myport)->GetLatencyRange(mode, range);
548  }
549 }
550 
551 LIB_EXPORT void jack_port_set_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
552 {
553  JackGlobals::CheckContext("jack_port_set_latency_range");
554 
555  uintptr_t port_aux = (uintptr_t)port;
556  jack_port_id_t myport = (jack_port_id_t)port_aux;
557  if (!CheckPort(myport)) {
558  jack_error("jack_port_set_latency_range called with an incorrect port %ld", myport);
559  } else {
560  WaitGraphChange();
561  JackGraphManager* manager = GetGraphManager();
562  if (manager)
563  manager->GetPort(myport)->SetLatencyRange(mode, range);
564  }
565 }
566 
567 LIB_EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
568 {
569  JackGlobals::CheckContext("jack_recompute_total_latency");
570 
571 
572  JackClient* client = (JackClient*)ext_client;
573  uintptr_t port_aux = (uintptr_t)port;
574  jack_port_id_t myport = (jack_port_id_t)port_aux;
575  if (client == NULL) {
576  jack_error("jack_recompute_total_latency called with a NULL client");
577  return -1;
578  } else if (!CheckPort(myport)) {
579  jack_error("jack_recompute_total_latency called with a NULL port");
580  return -1;
581  } else {
582  WaitGraphChange();
583  JackGraphManager* manager = GetGraphManager();
584  return (manager ? manager->ComputeTotalLatency(myport) : -1);
585  }
586 }
587 
588 LIB_EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
589 {
590  JackGlobals::CheckContext("jack_recompute_total_latencies");
591 
592  JackClient* client = (JackClient*)ext_client;
593  if (client == NULL) {
594  jack_error("jack_recompute_total_latencies called with a NULL client");
595  return -1;
596  } else {
597  return client->ComputeTotalLatencies();
598  }
599 }
600 
601 LIB_EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
602 {
603  JackGlobals::CheckContext("jack_port_set_name");
604 
605  uintptr_t port_aux = (uintptr_t)port;
606  jack_port_id_t myport = (jack_port_id_t)port_aux;
607  if (!CheckPort(myport)) {
608  jack_error("jack_port_set_name called with an incorrect port %ld", myport);
609  return -1;
610  } else if (name == NULL) {
611  jack_error("jack_port_set_name called with a NULL port name");
612  return -1;
613  } else {
614  JackClient* client = NULL;
615  for (int i = 0; i < CLIENT_NUM; i++) {
616  // Find a valid client
617  if ((client = JackGlobals::fClientTable[i])) {
618  break;
619  }
620  }
621  return (client) ? client->PortRename(myport, name) : -1;
622  }
623 }
624 
625 LIB_EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
626 {
627  JackGlobals::CheckContext("jack_port_set_alias");
628 
629  uintptr_t port_aux = (uintptr_t)port;
630  jack_port_id_t myport = (jack_port_id_t)port_aux;
631  if (!CheckPort(myport)) {
632  jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
633  return -1;
634  } else if (name == NULL) {
635  jack_error("jack_port_set_alias called with a NULL port name");
636  return -1;
637  } else {
638  JackGraphManager* manager = GetGraphManager();
639  return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
640  }
641 }
642 
643 LIB_EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
644 {
645  JackGlobals::CheckContext("jack_port_unset_alias");
646 
647  uintptr_t port_aux = (uintptr_t)port;
648  jack_port_id_t myport = (jack_port_id_t)port_aux;
649  if (!CheckPort(myport)) {
650  jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
651  return -1;
652  } else if (name == NULL) {
653  jack_error("jack_port_unset_alias called with a NULL port name");
654  return -1;
655  } else {
656  JackGraphManager* manager = GetGraphManager();
657  return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
658  }
659 }
660 
661 LIB_EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
662 {
663  JackGlobals::CheckContext("jack_port_get_aliases");
664 
665  uintptr_t port_aux = (uintptr_t)port;
666  jack_port_id_t myport = (jack_port_id_t)port_aux;
667  if (!CheckPort(myport)) {
668  jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
669  return -1;
670  } else {
671  JackGraphManager* manager = GetGraphManager();
672  return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
673  }
674 }
675 
676 LIB_EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
677 {
678  JackGlobals::CheckContext("jack_port_request_monitor");
679 
680  uintptr_t port_aux = (uintptr_t)port;
681  jack_port_id_t myport = (jack_port_id_t)port_aux;
682  if (!CheckPort(myport)) {
683  jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
684  return -1;
685  } else {
686  JackGraphManager* manager = GetGraphManager();
687  return (manager ? manager->RequestMonitor(myport, onoff) : -1);
688  }
689 }
690 
691 LIB_EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
692 {
693  JackGlobals::CheckContext("jack_port_request_monitor_by_name");
694 
695  JackClient* client = (JackClient*)ext_client;
696  if (client == NULL) {
697  jack_error("jack_port_request_monitor_by_name called with a NULL client");
698  return -1;
699  } else {
700  JackGraphManager* manager = GetGraphManager();
701  if (!manager)
702  return -1;
703  jack_port_id_t myport = manager->GetPort(port_name);
704  if (!CheckPort(myport)) {
705  jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
706  return -1;
707  } else {
708  return manager->RequestMonitor(myport, onoff);
709  }
710  }
711 }
712 
713 LIB_EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
714 {
715  JackGlobals::CheckContext("jack_port_ensure_monitor");
716 
717  uintptr_t port_aux = (uintptr_t)port;
718  jack_port_id_t myport = (jack_port_id_t)port_aux;
719  if (!CheckPort(myport)) {
720  jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
721  return -1;
722  } else {
723  JackGraphManager* manager = GetGraphManager();
724  return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
725  }
726 }
727 
728 LIB_EXPORT int jack_port_monitoring_input(jack_port_t* port)
729 {
730  JackGlobals::CheckContext("jack_port_monitoring_input");
731 
732  uintptr_t port_aux = (uintptr_t)port;
733  jack_port_id_t myport = (jack_port_id_t)port_aux;
734  if (!CheckPort(myport)) {
735  jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
736  return -1;
737  } else {
738  JackGraphManager* manager = GetGraphManager();
739  return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
740  }
741 }
742 
743 LIB_EXPORT int jack_is_realtime(jack_client_t* ext_client)
744 {
745  JackGlobals::CheckContext("jack_is_realtime");
746 
747  JackClient* client = (JackClient*)ext_client;
748  if (client == NULL) {
749  jack_error("jack_is_realtime called with a NULL client");
750  return -1;
751  } else {
752  JackEngineControl* control = GetEngineControl();
753  return (control ? control->fRealTime : -1);
754  }
755 }
756 
757 LIB_EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
758 {
759  JackGlobals::CheckContext("jack_on_shutdown");
760 
761  JackClient* client = (JackClient*)ext_client;
762  if (client == NULL) {
763  jack_error("jack_on_shutdown called with a NULL client");
764  } else {
765  client->OnShutdown(callback, arg);
766  }
767 }
768 
769 LIB_EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
770 {
771  JackGlobals::CheckContext("jack_on_info_shutdown");
772 
773  JackClient* client = (JackClient*)ext_client;
774  if (client == NULL) {
775  jack_error("jack_on_info_shutdown called with a NULL client");
776  } else {
777  client->OnInfoShutdown(callback, arg);
778  }
779 }
780 
781 LIB_EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
782 {
783  JackGlobals::CheckContext("jack_set_process_callback");
784 
785  JackClient* client = (JackClient*)ext_client;
786  if (client == NULL) {
787  jack_error("jack_set_process_callback called with a NULL client");
788  return -1;
789  } else {
790  return client->SetProcessCallback(callback, arg);
791  }
792 }
793 
794 LIB_EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
795 {
796  JackGlobals::CheckContext("jack_thread_wait");
797 
798  JackClient* client = (JackClient*)ext_client;
799  if (client == NULL) {
800  jack_error("jack_thread_wait called with a NULL client");
801  return 0;
802  } else {
803  jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
804  return 0;
805  }
806 }
807 
808 LIB_EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
809 {
810  JackGlobals::CheckContext("jack_cycle_wait");
811 
812  JackClient* client = (JackClient*)ext_client;
813  if (client == NULL) {
814  jack_error("jack_cycle_wait called with a NULL client");
815  return 0;
816  } else {
817  return client->CycleWait();
818  }
819 }
820 
821 LIB_EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
822 {
823  JackGlobals::CheckContext("jack_cycle_signal");
824 
825  JackClient* client = (JackClient*)ext_client;
826  if (client == NULL) {
827  jack_error("jack_cycle_signal called with a NULL client");
828  } else {
829  client->CycleSignal(status);
830  }
831 }
832 
833 LIB_EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
834 {
835  JackGlobals::CheckContext("jack_set_process_thread");
836 
837  JackClient* client = (JackClient*)ext_client;
838  if (client == NULL) {
839  jack_error("jack_set_process_thread called with a NULL client");
840  return -1;
841  } else {
842  return client->SetProcessThread(fun, arg);
843  }
844 }
845 
846 LIB_EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
847 {
848  JackGlobals::CheckContext("jack_set_freewheel_callback");
849 
850  JackClient* client = (JackClient*)ext_client;
851  if (client == NULL) {
852  jack_error("jack_set_freewheel_callback called with a NULL client");
853  return -1;
854  } else {
855  return client->SetFreewheelCallback(freewheel_callback, arg);
856  }
857 }
858 
859 LIB_EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
860 {
861  JackGlobals::CheckContext("jack_set_freewheel");
862 
863  JackClient* client = (JackClient*)ext_client;
864  if (client == NULL) {
865  jack_error("jack_set_freewheel called with a NULL client");
866  return -1;
867  } else {
868  return client->SetFreeWheel(onoff);
869  }
870 }
871 
872 LIB_EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
873 {
874  JackGlobals::CheckContext("jack_set_buffer_size");
875 
876  JackClient* client = (JackClient*)ext_client;
877  if (client == NULL) {
878  jack_error("jack_set_buffer_size called with a NULL client");
879  return -1;
880  } else if (!CheckBufferSize(buffer_size)) {
881  return -1;
882  } else {
883  return client->SetBufferSize(buffer_size);
884  }
885 }
886 
887 LIB_EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
888 {
889  JackGlobals::CheckContext("jack_set_buffer_size_callback");
890 
891  JackClient* client = (JackClient*)ext_client;
892  if (client == NULL) {
893  jack_error("jack_set_buffer_size_callback called with a NULL client");
894  return -1;
895  } else {
896  return client->SetBufferSizeCallback(bufsize_callback, arg);
897  }
898 }
899 
900 LIB_EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
901 {
902  JackGlobals::CheckContext("jack_set_sample_rate_callback");
903 
904  JackClient* client = (JackClient*)ext_client;
905  if (client == NULL) {
906  jack_error("jack_set_sample_rate_callback called with a NULL client");
907  return -1;
908  } else {
909  return client->SetSampleRateCallback(srate_callback, arg);
910  }
911 }
912 
913 LIB_EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
914 {
915  JackGlobals::CheckContext("jack_set_client_registration_callback");
916 
917  JackClient* client = (JackClient*)ext_client;
918  if (client == NULL) {
919  jack_error("jack_set_client_registration_callback called with a NULL client");
920  return -1;
921  } else {
922  return client->SetClientRegistrationCallback(registration_callback, arg);
923  }
924 }
925 
926 LIB_EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
927 {
928  JackGlobals::CheckContext("jack_set_port_registration_callback");
929 
930  JackClient* client = (JackClient*)ext_client;
931  if (client == NULL) {
932  jack_error("jack_set_port_registration_callback called with a NULL client");
933  return -1;
934  } else {
935  return client->SetPortRegistrationCallback(registration_callback, arg);
936  }
937 }
938 
939 LIB_EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
940 {
941  JackGlobals::CheckContext("jack_set_port_connect_callback");
942 
943  JackClient* client = (JackClient*)ext_client;
944  if (client == NULL) {
945  jack_error("jack_set_port_connect_callback called with a NULL client");
946  return -1;
947  } else {
948  return client->SetPortConnectCallback(portconnect_callback, arg);
949  }
950 }
951 
952 LIB_EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
953 {
954  JackGlobals::CheckContext("jack_set_port_rename_callback");
955 
956  JackClient* client = (JackClient*)ext_client;
957  if (client == NULL) {
958  jack_error("jack_set_port_rename_callback called with a NULL client");
959  return -1;
960  } else {
961  return client->SetPortRenameCallback(rename_callback, arg);
962  }
963 }
964 
965 LIB_EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
966 {
967  JackGlobals::CheckContext("jack_set_graph_order_callback");
968 
969  JackClient* client = (JackClient*)ext_client;
970  jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
971  if (client == NULL) {
972  jack_error("jack_set_graph_order_callback called with a NULL client");
973  return -1;
974  } else {
975  return client->SetGraphOrderCallback(graph_callback, arg);
976  }
977 }
978 
979 LIB_EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
980 {
981  JackGlobals::CheckContext("jack_set_xrun_callback");
982 
983  JackClient* client = (JackClient*)ext_client;
984  if (client == NULL) {
985  jack_error("jack_set_xrun_callback called with a NULL client");
986  return -1;
987  } else {
988  return client->SetXRunCallback(xrun_callback, arg);
989  }
990 }
991 
992 LIB_EXPORT int jack_set_latency_callback(jack_client_t* ext_client, JackLatencyCallback latency_callback, void *arg)
993 {
994  JackGlobals::CheckContext("jack_set_latency_callback");
995 
996  JackClient* client = (JackClient*)ext_client;
997  if (client == NULL) {
998  jack_error("jack_set_latency_callback called with a NULL client");
999  return -1;
1000  } else {
1001  return client->SetLatencyCallback(latency_callback, arg);
1002  }
1003 }
1004 
1005 LIB_EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
1006 {
1007  JackGlobals::CheckContext("jack_set_thread_init_callback");
1008 
1009  JackClient* client = (JackClient*)ext_client;
1010  jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
1011  if (client == NULL) {
1012  jack_error("jack_set_thread_init_callback called with a NULL client");
1013  return -1;
1014  } else {
1015  return client->SetInitCallback(init_callback, arg);
1016  }
1017 }
1018 
1019 LIB_EXPORT int jack_activate(jack_client_t* ext_client)
1020 {
1021  JackGlobals::CheckContext("jack_activate");
1022 
1023  JackClient* client = (JackClient*)ext_client;
1024  if (client == NULL) {
1025  jack_error("jack_activate called with a NULL client");
1026  return -1;
1027  } else {
1028  return client->Activate();
1029  }
1030 }
1031 
1032 LIB_EXPORT int jack_deactivate(jack_client_t* ext_client)
1033 {
1034  JackGlobals::CheckContext("jack_deactivate");
1035 
1036  JackClient* client = (JackClient*)ext_client;
1037  if (client == NULL) {
1038  jack_error("jack_deactivate called with a NULL client");
1039  return -1;
1040  } else {
1041  return client->Deactivate();
1042  }
1043 }
1044 
1045 LIB_EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
1046 {
1047  JackGlobals::CheckContext("jack_port_register");
1048 
1049  JackClient* client = (JackClient*)ext_client;
1050  if (client == NULL) {
1051  jack_error("jack_port_register called with a NULL client");
1052  return NULL;
1053  } else if ((port_name == NULL) || (port_type == NULL)) {
1054  jack_error("jack_port_register called with a NULL port name or a NULL port_type");
1055  return NULL;
1056  } else {
1057  return (jack_port_t *)((uintptr_t)client->PortRegister(port_name, port_type, flags, buffer_size));
1058  }
1059 }
1060 
1061 LIB_EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
1062 {
1063  JackGlobals::CheckContext("jack_port_unregister");
1064 
1065  JackClient* client = (JackClient*)ext_client;
1066  if (client == NULL) {
1067  jack_error("jack_port_unregister called with a NULL client");
1068  return -1;
1069  }
1070  uintptr_t port_aux = (uintptr_t)port;
1071  jack_port_id_t myport = (jack_port_id_t)port_aux;
1072  if (!CheckPort(myport)) {
1073  jack_error("jack_port_unregister called with an incorrect port %ld", myport);
1074  return -1;
1075  }
1076  return client->PortUnRegister(myport);
1077 }
1078 
1079 LIB_EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
1080 {
1081  JackGlobals::CheckContext("jack_port_is_mine");
1082 
1083  JackClient* client = (JackClient*)ext_client;
1084  if (client == NULL) {
1085  jack_error("jack_port_is_mine called with a NULL client");
1086  return -1;
1087  }
1088  uintptr_t port_aux = (uintptr_t)port;
1089  jack_port_id_t myport = (jack_port_id_t)port_aux;
1090  if (!CheckPort(myport)) {
1091  jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
1092  return -1;
1093  }
1094  return client->PortIsMine(myport);
1095 }
1096 
1097 LIB_EXPORT const char** jack_port_get_connections(const jack_port_t* port)
1098 {
1099  JackGlobals::CheckContext("jack_port_get_connections");
1100 
1101  uintptr_t port_aux = (uintptr_t)port;
1102  jack_port_id_t myport = (jack_port_id_t)port_aux;
1103  if (!CheckPort(myport)) {
1104  jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
1105  return NULL;
1106  } else {
1107  WaitGraphChange();
1108  JackGraphManager* manager = GetGraphManager();
1109  return (manager ? manager->GetConnections(myport) : NULL);
1110  }
1111 }
1112 
1113 // Calling client does not need to "own" the port
1114 LIB_EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
1115 {
1116  JackGlobals::CheckContext("jack_port_get_all_connections");
1117 
1118  JackClient* client = (JackClient*)ext_client;
1119  if (client == NULL) {
1120  jack_error("jack_port_get_all_connections called with a NULL client");
1121  return NULL;
1122  }
1123 
1124  uintptr_t port_aux = (uintptr_t)port;
1125  jack_port_id_t myport = (jack_port_id_t)port_aux;
1126  if (!CheckPort(myport)) {
1127  jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
1128  return NULL;
1129  } else {
1130  WaitGraphChange();
1131  JackGraphManager* manager = GetGraphManager();
1132  return (manager ? manager->GetConnections(myport) : NULL);
1133  }
1134 }
1135 
1136 LIB_EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
1137 {
1138  JackGlobals::CheckContext("jack_port_get_total_latency");
1139 
1140  JackClient* client = (JackClient*)ext_client;
1141  if (client == NULL) {
1142  jack_error("jack_port_get_total_latency called with a NULL client");
1143  return 0;
1144  }
1145 
1146  uintptr_t port_aux = (uintptr_t)port;
1147  jack_port_id_t myport = (jack_port_id_t)port_aux;
1148  if (!CheckPort(myport)) {
1149  jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
1150  return 0;
1151  } else {
1152  WaitGraphChange();
1153  JackGraphManager* manager = GetGraphManager();
1154  if (manager) {
1155  manager->ComputeTotalLatency(myport);
1156  return manager->GetPort(myport)->GetTotalLatency();
1157  } else {
1158  return 0;
1159  }
1160  }
1161 }
1162 
1163 LIB_EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
1164 {
1165  JackGlobals::CheckContext("jack_connect");
1166 
1167  JackClient* client = (JackClient*)ext_client;
1168  if (client == NULL) {
1169  jack_error("jack_connect called with a NULL client");
1170  return -1;
1171  } else if ((src == NULL) || (dst == NULL)) {
1172  jack_error("jack_connect called with a NULL port name");
1173  return -1;
1174  } else {
1175  return client->PortConnect(src, dst);
1176  }
1177 }
1178 
1179 LIB_EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
1180 {
1181  JackGlobals::CheckContext("jack_disconnect");
1182 
1183  JackClient* client = (JackClient*)ext_client;
1184  if (client == NULL) {
1185  jack_error("jack_disconnect called with a NULL client");
1186  return -1;
1187  } else if ((src == NULL) || (dst == NULL)) {
1188  jack_error("jack_disconnect called with a NULL port name");
1189  return -1;
1190  } else {
1191  return client->PortDisconnect(src, dst);
1192  }
1193 }
1194 
1195 LIB_EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
1196 {
1197  JackGlobals::CheckContext("jack_port_disconnect");
1198 
1199  JackClient* client = (JackClient*)ext_client;
1200  if (client == NULL) {
1201  jack_error("jack_port_disconnect called with a NULL client");
1202  return -1;
1203  }
1204  uintptr_t port_aux = (uintptr_t)src;
1205  jack_port_id_t myport = (jack_port_id_t)port_aux;
1206  if (!CheckPort(myport)) {
1207  jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
1208  return -1;
1209  }
1210  return client->PortDisconnect(myport);
1211 }
1212 
1213 LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
1214 {
1215  JackGlobals::CheckContext("jack_get_sample_rate");
1216 
1217  JackClient* client = (JackClient*)ext_client;
1218  if (client == NULL) {
1219  jack_error("jack_get_sample_rate called with a NULL client");
1220  return 0;
1221  } else {
1222  JackEngineControl* control = GetEngineControl();
1223  return (control ? control->fSampleRate : 0);
1224  }
1225 }
1226 
1227 LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
1228 {
1229  JackGlobals::CheckContext("jack_get_buffer_size");
1230 
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);
1238  }
1239 }
1240 
1241 LIB_EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
1242 {
1243  JackGlobals::CheckContext("jack_get_ports");
1244 
1245  JackClient* client = (JackClient*)ext_client;
1246  if (client == NULL) {
1247  jack_error("jack_get_ports called with a NULL client");
1248  return NULL;
1249  }
1250  JackGraphManager* manager = GetGraphManager();
1251  return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
1252 }
1253 
1254 LIB_EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
1255 {
1256  JackGlobals::CheckContext("jack_port_by_name");
1257 
1258  JackClient* client = (JackClient*)ext_client;
1259  if (client == NULL) {
1260  jack_error("jack_get_ports called with a NULL client");
1261  return 0;
1262  }
1263 
1264  if (portname == NULL) {
1265  jack_error("jack_port_by_name called with a NULL port name");
1266  return NULL;
1267  } else {
1268  JackGraphManager* manager = GetGraphManager();
1269  if (!manager)
1270  return NULL;
1271  int res = manager->GetPort(portname); // returns a port index at least > 1
1272  return (res == NO_PORT) ? NULL : (jack_port_t*)((uintptr_t)res);
1273  }
1274 }
1275 
1276 LIB_EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
1277 {
1278  JackGlobals::CheckContext("jack_port_by_id");
1279 
1280  /* jack_port_t* type is actually the port index */
1281  return (jack_port_t*)((uintptr_t)id);
1282 }
1283 
1284 LIB_EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
1285 {
1286  JackGlobals::CheckContext("jack_engine_takeover_timebase");
1287 
1288  JackClient* client = (JackClient*)ext_client;
1289  if (client == NULL) {
1290  jack_error("jack_engine_takeover_timebase called with a NULL client");
1291  return -1;
1292  } else {
1293  jack_error("jack_engine_takeover_timebase: deprecated\n");
1294  return 0;
1295  }
1296 }
1297 
1298 LIB_EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
1299 {
1300  JackGlobals::CheckContext("jack_frames_since_cycle_start");
1301 
1302  JackTimer timer;
1303  JackEngineControl* control = GetEngineControl();
1304  if (control) {
1305  control->ReadFrameTime(&timer);
1306  return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
1307  } else {
1308  return 0;
1309  }
1310 }
1311 
1312 LIB_EXPORT jack_time_t jack_get_time()
1313 {
1314  JackGlobals::CheckContext("jack_get_time");
1315 
1316  return GetMicroSeconds();
1317 }
1318 
1319 LIB_EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
1320 {
1321  JackGlobals::CheckContext("jack_frames_to_time");
1322 
1323  JackClient* client = (JackClient*)ext_client;
1324  if (client == NULL) {
1325  jack_error("jack_frames_to_time called with a NULL client");
1326  return 0;
1327  } else {
1328  JackTimer timer;
1329  JackEngineControl* control = GetEngineControl();
1330  if (control) {
1331  control->ReadFrameTime(&timer);
1332  return timer.Frames2Time(frames, control->fBufferSize);
1333  } else {
1334  return 0;
1335  }
1336  }
1337 }
1338 
1339 LIB_EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t usecs)
1340 {
1341  JackGlobals::CheckContext("jack_time_to_frames");
1342 
1343  JackClient* client = (JackClient*)ext_client;
1344  if (client == NULL) {
1345  jack_error("jack_time_to_frames called with a NULL client");
1346  return 0;
1347  } else {
1348  JackTimer timer;
1349  JackEngineControl* control = GetEngineControl();
1350  if (control) {
1351  control->ReadFrameTime(&timer);
1352  return timer.Time2Frames(usecs, control->fBufferSize);
1353  } else {
1354  return 0;
1355  }
1356  }
1357 }
1358 
1359 LIB_EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
1360 {
1361  JackGlobals::CheckContext("jack_frame_time");
1362 
1363  return jack_time_to_frames(ext_client, GetMicroSeconds());
1364 }
1365 
1366 LIB_EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
1367 {
1368  JackGlobals::CheckContext("jack_last_frame_time");
1369 
1370  JackEngineControl* control = GetEngineControl();
1371  return (control) ? control->fFrameTimer.ReadCurrentState()->CurFrame() : 0;
1372 }
1373 
1374 LIB_EXPORT int jack_get_cycle_times(const jack_client_t *client,
1375  jack_nframes_t *current_frames,
1376  jack_time_t *current_usecs,
1377  jack_time_t *next_usecs,
1378  float *period_usecs)
1379 {
1380  JackGlobals::CheckContext("jack_get_cycle_times");
1381 
1382  JackEngineControl* control = GetEngineControl();
1383  if (control) {
1384  JackTimer timer;
1385  control->ReadFrameTime(&timer);
1386  return timer.GetCycleTimes(current_frames, current_usecs, next_usecs, period_usecs);
1387  } else {
1388  return -1;
1389  }
1390 }
1391 
1392 LIB_EXPORT float jack_cpu_load(jack_client_t* ext_client)
1393 {
1394  JackGlobals::CheckContext("jack_cpu_load");
1395 
1396  JackClient* client = (JackClient*)ext_client;
1397  if (client == NULL) {
1398  jack_error("jack_cpu_load called with a NULL client");
1399  return 0.0f;
1400  } else {
1401  JackEngineControl* control = GetEngineControl();
1402  return (control ? control->fCPULoad : 0.0f);
1403  }
1404 }
1405 
1406 LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t* ext_client)
1407 {
1408  JackGlobals::CheckContext("jack_client_thread_id");
1409 
1410  JackClient* client = (JackClient*)ext_client;
1411  if (client == NULL) {
1412  jack_error("jack_client_thread_id called with a NULL client");
1413  return (jack_native_thread_t)NULL;
1414  } else {
1415  return client->GetThreadID();
1416  }
1417 }
1418 
1419 LIB_EXPORT char* jack_get_client_name(jack_client_t* ext_client)
1420 {
1421  JackGlobals::CheckContext("jack_get_client_name");
1422 
1423  JackClient* client = (JackClient*)ext_client;
1424  if (client == NULL) {
1425  jack_error("jack_get_client_name called with a NULL client");
1426  return NULL;
1427  } else {
1428  return client->GetClientControl()->fName;
1429  }
1430 }
1431 
1432 LIB_EXPORT int jack_client_name_size(void)
1433 {
1434  return JACK_CLIENT_NAME_SIZE;
1435 }
1436 
1437 LIB_EXPORT int jack_port_name_size(void)
1438 {
1439  return REAL_JACK_PORT_NAME_SIZE;
1440 }
1441 
1442 LIB_EXPORT int jack_port_type_size(void)
1443 {
1444  return JACK_PORT_TYPE_SIZE;
1445 }
1446 
1447 LIB_EXPORT size_t jack_port_type_get_buffer_size(jack_client_t* ext_client, const char* port_type)
1448 {
1449  JackGlobals::CheckContext("jack_port_type_get_buffer_size");
1450 
1451  JackClient* client = (JackClient*)ext_client;
1452  if (client == NULL) {
1453  jack_error("jack_port_type_get_buffer_size called with a NULL client");
1454  return 0;
1455  } else {
1456  jack_port_type_id_t port_id = GetPortTypeId(port_type);
1457  if (port_id == PORT_TYPES_MAX) {
1458  jack_error("jack_port_type_get_buffer_size called with an unknown port type = %s", port_type);
1459  return 0;
1460  } else {
1461  return GetPortType(port_id)->size();
1462  }
1463  }
1464 }
1465 
1466 // transport.h
1467 LIB_EXPORT int jack_release_timebase(jack_client_t* ext_client)
1468 {
1469  JackGlobals::CheckContext("jack_release_timebase");
1470 
1471  JackClient* client = (JackClient*)ext_client;
1472  if (client == NULL) {
1473  jack_error("jack_release_timebase called with a NULL client");
1474  return -1;
1475  } else {
1476  return client->ReleaseTimebase();
1477  }
1478 }
1479 
1480 LIB_EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
1481 {
1482  JackGlobals::CheckContext("jack_set_sync_callback");
1483 
1484  JackClient* client = (JackClient*)ext_client;
1485  if (client == NULL) {
1486  jack_error("jack_set_sync_callback called with a NULL client");
1487  return -1;
1488  } else {
1489  return client->SetSyncCallback(sync_callback, arg);
1490  }
1491 }
1492 
1493 LIB_EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
1494 {
1495  JackGlobals::CheckContext("jack_set_sync_timeout");
1496 
1497  JackClient* client = (JackClient*)ext_client;
1498  if (client == NULL) {
1499  jack_error("jack_set_sync_timeout called with a NULL client");
1500  return -1;
1501  } else {
1502  return client->SetSyncTimeout(timeout);
1503  }
1504 }
1505 
1506 LIB_EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
1507 {
1508  JackGlobals::CheckContext("jack_set_timebase_callback");
1509 
1510  JackClient* client = (JackClient*)ext_client;
1511  if (client == NULL) {
1512  jack_error("jack_set_timebase_callback called with a NULL client");
1513  return -1;
1514  } else {
1515  return client->SetTimebaseCallback(conditional, timebase_callback, arg);
1516  }
1517 }
1518 
1519 LIB_EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
1520 {
1521  JackGlobals::CheckContext("jack_transport_locate");
1522 
1523  JackClient* client = (JackClient*)ext_client;
1524  if (client == NULL) {
1525  jack_error("jack_transport_locate called with a NULL client");
1526  return -1;
1527  } else {
1528  client->TransportLocate(frame);
1529  return 0;
1530  }
1531 }
1532 
1533 LIB_EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
1534 {
1535  JackGlobals::CheckContext("jack_transport_query");
1536 
1537  JackClient* client = (JackClient*)ext_client;
1538  if (client == NULL) {
1539  jack_error("jack_transport_query called with a NULL client");
1540  return JackTransportStopped;
1541  } else {
1542  return client->TransportQuery(pos);
1543  }
1544 }
1545 
1546 LIB_EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
1547 {
1548  JackGlobals::CheckContext("jack_get_current_transport_frame");
1549 
1550  JackClient* client = (JackClient*)ext_client;
1551  if (client == NULL) {
1552  jack_error("jack_get_current_transport_frame called with a NULL client");
1553  return 0;
1554  } else {
1555  return client->GetCurrentTransportFrame();
1556  }
1557 }
1558 
1559 LIB_EXPORT int jack_transport_reposition(jack_client_t* ext_client, const jack_position_t* pos)
1560 {
1561  JackGlobals::CheckContext("jack_transport_reposition");
1562 
1563  JackClient* client = (JackClient*)ext_client;
1564  if (client == NULL) {
1565  jack_error("jack_transport_reposition called with a NULL client");
1566  return -1;
1567  } else {
1568  client->TransportReposition(pos);
1569  return 0;
1570  }
1571 }
1572 
1573 LIB_EXPORT void jack_transport_start(jack_client_t* ext_client)
1574 {
1575  JackGlobals::CheckContext("jack_transport_start");
1576 
1577  JackClient* client = (JackClient*)ext_client;
1578  if (client == NULL) {
1579  jack_error("jack_transport_start called with a NULL client");
1580  } else {
1581  client->TransportStart();
1582  }
1583 }
1584 
1585 LIB_EXPORT void jack_transport_stop(jack_client_t* ext_client)
1586 {
1587  JackGlobals::CheckContext("jack_transport_stop");
1588 
1589  JackClient* client = (JackClient*)ext_client;
1590  if (client == NULL) {
1591  jack_error("jack_transport_stop called with a NULL client");
1592  } else {
1593  client->TransportStop();
1594  }
1595 }
1596 
1597 // deprecated
1598 LIB_EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
1599 {
1600  JackGlobals::CheckContext("jack_get_transport_info");
1601 
1602  jack_error("jack_get_transport_info: deprecated");
1603  if (tinfo)
1604  memset(tinfo, 0, sizeof(jack_transport_info_t));
1605 }
1606 
1607 LIB_EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
1608 {
1609  JackGlobals::CheckContext("jack_set_transport_info");
1610 
1611  jack_error("jack_set_transport_info: deprecated");
1612  if (tinfo)
1613  memset(tinfo, 0, sizeof(jack_transport_info_t));
1614 }
1615 
1616 // statistics.h
1617 LIB_EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
1618 {
1619  JackGlobals::CheckContext("jack_get_max_delayed_usecs");
1620 
1621  JackClient* client = (JackClient*)ext_client;
1622  if (client == NULL) {
1623  jack_error("jack_get_max_delayed_usecs called with a NULL client");
1624  return 0.f;
1625  } else {
1626  JackEngineControl* control = GetEngineControl();
1627  return (control ? control->fMaxDelayedUsecs : 0.f);
1628  }
1629  }
1630 
1631 LIB_EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
1632 {
1633  JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
1634 
1635  JackClient* client = (JackClient*)ext_client;
1636  if (client == NULL) {
1637  jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
1638  return 0.f;
1639  } else {
1640  JackEngineControl* control = GetEngineControl();
1641  return (control ? control->fXrunDelayedUsecs : 0.f);
1642  }
1643 }
1644 
1645 LIB_EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
1646 {
1647  JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
1648 
1649  JackClient* client = (JackClient*)ext_client;
1650  if (client == NULL) {
1651  jack_error("jack_reset_max_delayed_usecs called with a NULL client");
1652  } else {
1653  JackEngineControl* control = GetEngineControl();
1654  control->ResetXRun();
1655  }
1656 }
1657 
1658 // thread.h
1659 LIB_EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
1660 {
1661  JackGlobals::CheckContext("jack_client_real_time_priority");
1662 
1663  JackClient* client = (JackClient*)ext_client;
1664  if (client == NULL) {
1665  jack_error("jack_client_real_time_priority called with a NULL client");
1666  return -1;
1667  } else {
1668  JackEngineControl* control = GetEngineControl();
1669  return (control->fRealTime) ? control->fClientPriority : -1;
1670  }
1671 }
1672 
1673 LIB_EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
1674 {
1675  JackGlobals::CheckContext("jack_client_max_real_time_priority");
1676 
1677  JackClient* client = (JackClient*)ext_client;
1678  if (client == NULL) {
1679  jack_error("jack_client_max_real_time_priority called with a NULL client");
1680  return -1;
1681  } else {
1682  JackEngineControl* control = GetEngineControl();
1683  return (control->fRealTime) ? control->fMaxClientPriority : -1;
1684  }
1685 }
1686 
1687 LIB_EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority)
1688 {
1689  JackEngineControl* control = GetEngineControl();
1690  return (control
1691  ? JackThread::AcquireRealTimeImp(thread, priority, control->fPeriod, control->fComputation, control->fConstraint)
1692  : -1);
1693 }
1694 
1695 LIB_EXPORT int jack_client_create_thread(jack_client_t* client,
1696  jack_native_thread_t *thread,
1697  int priority,
1698  int realtime, /* boolean */
1699  thread_routine routine,
1700  void *arg)
1701 {
1702  JackGlobals::CheckContext("jack_client_create_thread");
1703 
1704  JackEngineControl* control = GetEngineControl();
1705  int res = JackThread::StartImp(thread, priority, realtime, routine, arg);
1706  return (res == 0)
1707  ? ((realtime ? JackThread::AcquireRealTimeImp(*thread, priority, control->fPeriod, control->fComputation, control->fConstraint) : res))
1708  : res;
1709 }
1710 
1711 LIB_EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread)
1712 {
1713  return JackThread::DropRealTimeImp(thread);
1714 }
1715 
1716 LIB_EXPORT int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread)
1717 {
1718  JackGlobals::CheckContext("jack_client_stop_thread");
1719 
1720  return JackThread::StopImp(thread);
1721 }
1722 
1723 LIB_EXPORT int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread)
1724 {
1725  JackGlobals::CheckContext("jack_client_kill_thread");
1726 
1727  return JackThread::KillImp(thread);
1728 }
1729 
1730 #ifndef WIN32
1731 LIB_EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
1732 {
1733  if (jtc == NULL) {
1734  JackGlobals::fJackThreadCreator = pthread_create;
1735  } else {
1736  JackGlobals::fJackThreadCreator = jtc;
1737  }
1738 }
1739 #endif
1740 
1741 // intclient.h
1742 LIB_EXPORT int jack_internal_client_new (const char* client_name,
1743  const char* load_name,
1744  const char* load_init)
1745 {
1746  JackGlobals::CheckContext("jack_internal_client_new");
1747 
1748  jack_error("jack_internal_client_new: deprecated");
1749  return -1;
1750 }
1751 
1752 LIB_EXPORT void jack_internal_client_close (const char* client_name)
1753 {
1754  JackGlobals::CheckContext("jack_internal_client_close");
1755 
1756  jack_error("jack_internal_client_close: deprecated");
1757 }
1758 
1759 LIB_EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
1760 {
1761  JackGlobals::CheckContext("jack_get_internal_client_name");
1762 
1763  JackClient* client = (JackClient*)ext_client;
1764  if (client == NULL) {
1765  jack_error("jack_get_internal_client_name called with a NULL client");
1766  return NULL;
1767  } else if (intclient >= CLIENT_NUM) {
1768  jack_error("jack_get_internal_client_name: incorrect client");
1769  return NULL;
1770  } else {
1771  return client->GetInternalClientName(intclient);
1772  }
1773 }
1774 
1775 LIB_EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
1776 {
1777  JackGlobals::CheckContext("jack_internal_client_handle");
1778 
1779  JackClient* client = (JackClient*)ext_client;
1780  if (client == NULL) {
1781  jack_error("jack_internal_client_handle called with a NULL client");
1782  return 0;
1783  } else {
1784  jack_status_t my_status;
1785  if (status == NULL) /* no status from caller? */
1786  status = &my_status; /* use local status word */
1787  *status = (jack_status_t)0;
1788  return client->InternalClientHandle(client_name, status);
1789  }
1790 }
1791 
1792 static jack_intclient_t jack_internal_client_load_aux(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
1793 {
1794  JackGlobals::CheckContext("jack_internal_client_load_aux");
1795 
1796  JackClient* client = (JackClient*)ext_client;
1797  if (client == NULL) {
1798  jack_error("jack_internal_client_load called with a NULL client");
1799  return 0;
1800  } else {
1801  jack_varargs_t va;
1802  jack_status_t my_status;
1803 
1804  if (status == NULL) /* no status from caller? */
1805  status = &my_status; /* use local status word */
1806  *status = (jack_status_t)0;
1807 
1808  /* validate parameters */
1809  if ((options & ~JackLoadOptions)) {
1810  int my_status1 = *status | (JackFailure | JackInvalidOption);
1811  *status = (jack_status_t)my_status1;
1812  return 0;
1813  }
1814 
1815  /* parse variable arguments */
1816  jack_varargs_parse(options, ap, &va);
1817  return client->InternalClientLoad(client_name, options, status, &va);
1818  }
1819 }
1820 
1821 LIB_EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client, const char* client_name, jack_options_t options, jack_status_t *status, ...)
1822 {
1823  JackGlobals::CheckContext("jack_internal_client_load");
1824 
1825  va_list ap;
1826  va_start(ap, status);
1827  jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
1828  va_end(ap);
1829  return res;
1830 }
1831 
1832 LIB_EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
1833 {
1834  JackGlobals::CheckContext("jack_internal_client_load");
1835 
1836  JackClient* client = (JackClient*)ext_client;
1837  if (client == NULL) {
1838  jack_error("jack_internal_client_unload called with a NULL client");
1839  return (jack_status_t)(JackNoSuchClient | JackFailure);
1840  } else if (intclient >= CLIENT_NUM) {
1841  jack_error("jack_internal_client_unload: incorrect client");
1842  return (jack_status_t)(JackNoSuchClient | JackFailure);
1843  } else {
1844  jack_status_t my_status;
1845  client->InternalClientUnload(intclient, &my_status);
1846  return my_status;
1847  }
1848 }
1849 
1850 LIB_EXPORT void jack_get_version(int *major_ptr,
1851  int *minor_ptr,
1852  int *micro_ptr,
1853  int *proto_ptr)
1854 {
1855  JackGlobals::CheckContext("jack_get_version");
1856 
1857  // FIXME: We need these comming from build system
1858  *major_ptr = 0;
1859  *minor_ptr = 0;
1860  *micro_ptr = 0;
1861  *proto_ptr = 0;
1862 }
1863 
1864 LIB_EXPORT const char* jack_get_version_string()
1865 {
1866  JackGlobals::CheckContext("jack_get_version_string");
1867 
1868  return VERSION;
1869 }
1870 
1871 LIB_EXPORT void jack_free(void* ptr)
1872 {
1873  JackGlobals::CheckContext("jack_free");
1874 
1875  if (ptr) {
1876  free(ptr);
1877  }
1878 }
1879 
1880 // session.h
1881 LIB_EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg)
1882 {
1883  JackGlobals::CheckContext("jack_set_session_callback");
1884 
1885  JackClient* client = (JackClient*)ext_client;
1886  jack_log("jack_set_session_callback ext_client %x client %x ", ext_client, client);
1887  if (client == NULL) {
1888  jack_error("jack_set_session_callback called with a NULL client");
1889  return -1;
1890  } else {
1891  return client->SetSessionCallback(session_callback, arg);
1892  }
1893 }
1894 
1895 LIB_EXPORT jack_session_command_t* jack_session_notify(jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path)
1896 {
1897  JackGlobals::CheckContext("jack_session_notify");
1898 
1899  JackClient* client = (JackClient*)ext_client;
1900  jack_log("jack_session_notify ext_client %x client %x ", ext_client, client);
1901  if (client == NULL) {
1902  jack_error("jack_session_notify called with a NULL client");
1903  return NULL;
1904  } else {
1905  return client->SessionNotify(target, ev_type, path);
1906  }
1907 }
1908 
1909 LIB_EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event)
1910 {
1911  JackGlobals::CheckContext("jack_session_reply");
1912 
1913  JackClient* client = (JackClient*)ext_client;
1914  jack_log("jack_session_reply ext_client %x client %x ", ext_client, client);
1915  if (client == NULL) {
1916  jack_error("jack_session_reply called with a NULL client");
1917  return -1;
1918  } else {
1919  return client->SessionReply(event);
1920  }
1921 }
1922 
1924 {
1925  JackGlobals::CheckContext("jack_session_event_free");
1926 
1927  if (ev) {
1928  if (ev->session_dir)
1929  free((void *)ev->session_dir);
1930  if (ev->client_uuid)
1931  free((void *)ev->client_uuid);
1932  if (ev->command_line)
1933  free(ev->command_line);
1934  free(ev);
1935  }
1936 }
1937 
1938 LIB_EXPORT char *jack_client_get_uuid(jack_client_t* ext_client)
1939 {
1940  JackGlobals::CheckContext("jack_client_get_uuid");
1941 
1942  JackClient* client = (JackClient*)ext_client;
1943  if (client == NULL) {
1944  jack_error("jack_client_get_uuid called with a NULL client");
1945  return NULL;
1946  } else {
1947  char retval[16];
1948  snprintf(retval, sizeof(retval), "%d", client->GetClientControl()->fSessionID);
1949  return strdup(retval);
1950  }
1951 }
1952 
1953 LIB_EXPORT char* jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name)
1954 {
1955  JackGlobals::CheckContext("jack_get_uuid_for_client_name");
1956 
1957  JackClient* client = (JackClient*)ext_client;
1958  jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client, client);
1959  if (client == NULL) {
1960  jack_error("jack_get_uuid_for_client_name called with a NULL client");
1961  return NULL;
1962  } else {
1963  return client->GetUUIDForClientName(client_name);
1964  }
1965 }
1966 
1967 LIB_EXPORT char* jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid)
1968 {
1969  JackGlobals::CheckContext("jack_get_client_name_by_uuid");
1970 
1971  JackClient* client = (JackClient*)ext_client;
1972  jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client, client);
1973  if (client == NULL) {
1974  jack_error("jack_get_client_name_by_uuid called with a NULL client");
1975  return NULL;
1976  } else {
1977  return client->GetClientNameByUUID(client_uuid);
1978  }
1979 }
1980 
1981 LIB_EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* client_name, const char* uuid)
1982 {
1983  JackGlobals::CheckContext("jack_reserve_client_name");
1984 
1985  JackClient* client = (JackClient*)ext_client;
1986  jack_log("jack_reserve_client_name ext_client %x client %x ", ext_client, client);
1987  if (client == NULL) {
1988  jack_error("jack_reserve_client_name called with a NULL client");
1989  return -1;
1990  } else {
1991  return client->ReserveClientName(client_name, uuid);
1992  }
1993 }
1994 
1996 {
1997  JackGlobals::CheckContext("jack_session_commands_free");
1998 
1999 
2000  if (!cmds) {
2001  return;
2002  }
2003 
2004  int i = 0;
2005  while (1) {
2006  if (cmds[i].client_name) {
2007  free ((char *)cmds[i].client_name);
2008  }
2009  if (cmds[i].command) {
2010  free ((char *)cmds[i].command);
2011  }
2012  if (cmds[i].uuid) {
2013  free ((char *)cmds[i].uuid);
2014  } else {
2015  break;
2016  }
2017 
2018  i += 1;
2019  }
2020 
2021  free(cmds);
2022 }
2023 
2024 LIB_EXPORT int jack_client_has_session_callback(jack_client_t* ext_client, const char* client_name)
2025 {
2026  JackGlobals::CheckContext("jack_client_has_session_callback");
2027 
2028  JackClient* client = (JackClient*)ext_client;
2029  jack_log("jack_client_has_session_callback ext_client %x client %x ", ext_client, client);
2030  if (client == NULL) {
2031  jack_error("jack_client_has_session_callback called with a NULL client");
2032  return -1;
2033  } else {
2034  return client->ClientHasSessionCallback(client_name);
2035  }
2036 }
LIB_EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t *, jack_port_t *port)
Definition: JackAPI.cpp:1136
LIB_EXPORT int jack_set_client_registration_callback(jack_client_t *, JackClientRegistrationCallback registration_callback, void *arg)
Definition: JackAPI.cpp:913
LIB_EXPORT int jack_port_request_monitor(jack_port_t *port, int onoff)
Definition: JackAPI.cpp:676
LIB_EXPORT int jack_set_freewheel_callback(jack_client_t *client, JackFreewheelCallback freewheel_callback, void *arg)
Definition: JackAPI.cpp:846
T * ReadCurrentState()
Returns the current state : only valid in the RT reader thread.
LIB_EXPORT int jack_set_graph_order_callback(jack_client_t *, JackGraphOrderCallback graph_callback, void *)
Definition: JackAPI.cpp:965
LIB_EXPORT int jack_set_buffer_size(jack_client_t *client, jack_nframes_t nframes)
Definition: JackAPI.cpp:872
A structure used for time management.
LIB_EXPORT int jack_port_unregister(jack_client_t *, jack_port_t *)
Definition: JackAPI.cpp:1061
SERVER_EXPORT void(* jack_info_callback)(const char *desc)
Definition: JackError.cpp:136
LIB_EXPORT int jack_port_tie(jack_port_t *src, jack_port_t *dst)
Definition: JackAPI.cpp:464
LIB_EXPORT int jack_set_thread_init_callback(jack_client_t *client, JackThreadInitCallback thread_init_callback, void *arg)
Definition: JackAPI.cpp:1005
LIB_EXPORT int jack_set_session_callback(jack_client_t *ext_client, JackSessionCallback session_callback, void *arg)
Definition: JackAPI.cpp:1881
const char * client_uuid
Definition: JackSession.h:48
LIB_EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
Definition: JackAPI.cpp:408
LIB_EXPORT int jack_port_set_name(jack_port_t *port, const char *port_name)
Definition: JackAPI.cpp:601
LIB_EXPORT jack_port_t * jack_port_by_id(jack_client_t *client, jack_port_id_t port_id)
Definition: JackAPI.cpp:1276
LIB_EXPORT void jack_port_set_latency(jack_port_t *, jack_nframes_t)
Definition: JackAPI.cpp:520
LIB_EXPORT int jack_port_set_alias(jack_port_t *port, const char *alias)
Definition: JackAPI.cpp:625
LIB_EXPORT void jack_set_transport_info(jack_client_t *client, jack_transport_info_t *tinfo)
Definition: JackAPI.cpp:1607
LIB_EXPORT int jack_port_ensure_monitor(jack_port_t *port, int onoff)
Definition: JackAPI.cpp:713
LIB_EXPORT int jack_client_real_time_priority(jack_client_t *)
Definition: JackAPI.cpp:1659
LIB_EXPORT void jack_cycle_signal(jack_client_t *, int status)
Definition: JackAPI.cpp:821
LIB_EXPORT jack_transport_state_t jack_transport_query(const jack_client_t *client, jack_position_t *pos)
Definition: JackAPI.cpp:1533
LIB_EXPORT void jack_internal_client_close(const char *client_name)
Definition: JackAPI.cpp:1752
LIB_EXPORT jack_nframes_t jack_cycle_wait(jack_client_t *)
Definition: JackAPI.cpp:808
const char * session_dir
Definition: JackSession.h:47
LIB_EXPORT int jack_port_name_size(void)
Definition: JackAPI.cpp:1437
LIB_EXPORT int jack_set_process_callback(jack_client_t *client, JackProcessCallback process_callback, void *arg)
Definition: JackAPI.cpp:781
LIB_EXPORT int jack_recompute_total_latency(jack_client_t *, jack_port_t *port)
Definition: JackAPI.cpp:567
LIB_EXPORT int jack_activate(jack_client_t *client)
Definition: JackAPI.cpp:1019
SERVER_EXPORT void(* jack_error_callback)(const char *desc)
Definition: JackError.cpp:135
LIB_EXPORT int jack_client_stop_thread(jack_client_t *client, jack_native_thread_t thread)
Definition: JackAPI.cpp:1716
LIB_EXPORT const char * jack_port_type(const jack_port_t *port)
Definition: JackAPI.cpp:393
virtual int Deactivate()
Need to stop thread after deactivating in the server.
Definition: JackClient.cpp:461
void jack_set_info_function(void(*func)(const char *)) JACK_OPTIONAL_WEAK_EXPORT
LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t *)
Definition: JackAPI.cpp:1406
LIB_EXPORT const char ** jack_port_get_connections(const jack_port_t *port)
Definition: JackAPI.cpp:1097
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:91
LIB_EXPORT int jack_port_disconnect(jack_client_t *, jack_port_t *)
Definition: JackAPI.cpp:1195
LIB_EXPORT void jack_port_set_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
Definition: JackAPI.cpp:551
LIB_EXPORT jack_time_t jack_get_time()
Definition: JackAPI.cpp:1312
LIB_EXPORT char * jack_client_get_uuid(jack_client_t *client)
Definition: JackAPI.cpp:1938
LIB_EXPORT int jack_connect(jack_client_t *, const char *source_port, const char *destination_port)
Definition: JackAPI.cpp:1163
LIB_EXPORT int jack_disconnect(jack_client_t *, const char *source_port, const char *destination_port)
Definition: JackAPI.cpp:1179
LIB_EXPORT jack_port_t * jack_port_register(jack_client_t *client, const char *port_name, const char *port_type, unsigned long flags, unsigned long buffer_size)
Definition: JackAPI.cpp:1045
LIB_EXPORT int jack_release_timebase(jack_client_t *client)
Definition: JackAPI.cpp:1467
LIB_EXPORT const char ** jack_port_get_all_connections(const jack_client_t *client, const jack_port_t *port)
Definition: JackAPI.cpp:1114
LIB_EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority)
Definition: JackAPI.cpp:1687
LIB_EXPORT int jack_port_type_size(void)
Definition: JackAPI.cpp:1442
LIB_EXPORT void jack_on_shutdown(jack_client_t *client, JackShutdownCallback shutdown_callback, void *arg)
Definition: JackAPI.cpp:757
LIB_EXPORT int jack_set_port_connect_callback(jack_client_t *, JackPortConnectCallback connect_callback, void *arg)
Definition: JackAPI.cpp:939
LIB_EXPORT jack_client_t * jack_client_open(const char *client_name, jack_options_t options, jack_status_t *status,...)
Definition: JackLibAPI.cpp:167
LIB_EXPORT char * jack_get_uuid_for_client_name(jack_client_t *ext_client, const char *client_name)
Definition: JackAPI.cpp:1953
LIB_EXPORT jack_nframes_t jack_frame_time(const jack_client_t *)
Definition: JackAPI.cpp:1359
LIB_EXPORT char * jack_get_client_name(jack_client_t *client)
Definition: JackAPI.cpp:1419
LIB_EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t *client)
Definition: JackAPI.cpp:1366
LIB_EXPORT int jack_port_monitoring_input(jack_port_t *port)
Definition: JackAPI.cpp:728
LIB_EXPORT int jack_client_has_session_callback(jack_client_t *client, const char *client_name)
Definition: JackAPI.cpp:2024
void jack_set_error_function(void(*func)(const char *)) JACK_OPTIONAL_WEAK_EXPORT
Graph manager: contains the connection manager and the port array.
LIB_EXPORT void jack_transport_start(jack_client_t *client)
Definition: JackAPI.cpp:1573
LIB_EXPORT void jack_session_commands_free(jack_session_command_t *cmds)
Definition: JackAPI.cpp:1995
LIB_EXPORT int jack_set_port_rename_callback(jack_client_t *, JackPortRenameCallback rename_callback, void *arg)
Definition: JackAPI.cpp:952
LIB_EXPORT int jack_set_xrun_callback(jack_client_t *, JackXRunCallback xrun_callback, void *arg)
Definition: JackAPI.cpp:979
LIB_EXPORT int jack_set_sync_timeout(jack_client_t *client, jack_time_t timeout)
Definition: JackAPI.cpp:1493
LIB_EXPORT jack_session_command_t * jack_session_notify(jack_client_t *ext_client, const char *target, jack_session_event_type_t ev_type, const char *path)
Definition: JackAPI.cpp:1895
virtual int Activate()
We need to start thread before activating in the server, otherwise the FW driver connected to the cli...
Definition: JackClient.cpp:428
LIB_EXPORT int jack_reserve_client_name(jack_client_t *ext_client, const char *name, const char *uuid)
Definition: JackAPI.cpp:1981
LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t *)
Definition: JackAPI.cpp:1227
LIB_EXPORT jack_nframes_t jack_port_get_latency(jack_port_t *port)
Definition: JackAPI.cpp:504
LIB_EXPORT int jack_port_untie(jack_port_t *port)
Definition: JackAPI.cpp:489
LIB_EXPORT int jack_client_max_real_time_priority(jack_client_t *)
Definition: JackAPI.cpp:1673
LIB_EXPORT void jack_set_thread_creator(jack_thread_creator_t jtc)
Definition: JackAPI.cpp:1731
LIB_EXPORT int jack_set_sample_rate_callback(jack_client_t *client, JackSampleRateCallback srate_callback, void *arg)
Definition: JackAPI.cpp:900
LIB_EXPORT int jack_transport_locate(jack_client_t *client, jack_nframes_t frame)
Definition: JackAPI.cpp:1519
LIB_EXPORT void * jack_port_get_buffer(jack_port_t *, jack_nframes_t)
Definition: JackAPI.cpp:333
LIB_EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames)
Definition: JackAPI.cpp:1319
LIB_EXPORT int jack_port_get_aliases(const jack_port_t *port, char *const aliases[2])
Definition: JackAPI.cpp:661
LIB_EXPORT void jack_transport_stop(jack_client_t *client)
Definition: JackAPI.cpp:1585
LIB_EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t *)
Definition: JackAPI.cpp:1298
LIB_EXPORT int jack_recompute_total_latencies(jack_client_t *)
Definition: JackAPI.cpp:588
LIB_EXPORT int jack_port_connected_to(const jack_port_t *port, const char *port_name)
Definition: JackAPI.cpp:439
LIB_EXPORT int jack_port_is_mine(const jack_client_t *, const jack_port_t *port)
Definition: JackAPI.cpp:1079
LIB_EXPORT int jack_port_unset_alias(jack_port_t *port, const char *alias)
Definition: JackAPI.cpp:643
LIB_EXPORT int jack_client_create_thread(jack_client_t *client, jack_native_thread_t *thread, int priority, int realtime, thread_routine routine, void *arg)
Definition: JackAPI.cpp:1695
LIB_EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread)
Definition: JackAPI.cpp:1711
LIB_EXPORT int jack_transport_reposition(jack_client_t *client, const jack_position_t *pos)
Definition: JackAPI.cpp:1559
LIB_EXPORT jack_port_t * jack_port_by_name(jack_client_t *, const char *port_name)
Definition: JackAPI.cpp:1254
LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t *)
Definition: JackAPI.cpp:1213
LIB_EXPORT int jack_set_timebase_callback(jack_client_t *client, int conditional, JackTimebaseCallback timebase_callback, void *arg)
Definition: JackAPI.cpp:1506
LIB_EXPORT size_t jack_port_type_get_buffer_size(jack_client_t *client, const char *port_type)
Definition: JackAPI.cpp:1447
LIB_EXPORT int jack_set_buffer_size_callback(jack_client_t *client, JackBufferSizeCallback bufsize_callback, void *arg)
Definition: JackAPI.cpp:887
LIB_EXPORT float jack_cpu_load(jack_client_t *client)
Definition: JackAPI.cpp:1392
LIB_EXPORT int jack_set_sync_callback(jack_client_t *client, JackSyncCallback sync_callback, void *arg)
Definition: JackAPI.cpp:1480
LIB_EXPORT int jack_port_connected(const jack_port_t *port)
Definition: JackAPI.cpp:423
LIB_EXPORT void jack_on_info_shutdown(jack_client_t *client, JackInfoShutdownCallback shutdown_callback, void *arg)
Definition: JackAPI.cpp:769
LIB_EXPORT int jack_port_request_monitor_by_name(jack_client_t *client, const char *port_name, int onoff)
Definition: JackAPI.cpp:691
int RequestMonitor(jack_port_id_t port_index, bool onoff)
LIB_EXPORT int jack_internal_client_new(const char *client_name, const char *load_name, const char *load_init)
Definition: JackAPI.cpp:1742
LIB_EXPORT int jack_session_reply(jack_client_t *ext_client, jack_session_event_t *event)
Definition: JackAPI.cpp:1909
LIB_EXPORT int jack_engine_takeover_timebase(jack_client_t *)
Definition: JackAPI.cpp:1284
LIB_EXPORT int jack_get_cycle_times(const jack_client_t *client, jack_nframes_t *current_frames, jack_time_t *current_usecs, jack_time_t *next_usecs, float *period_usecs)
Definition: JackAPI.cpp:1374
Engine control in shared memory.
LIB_EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status)
Definition: JackAPI.cpp:794
LIB_EXPORT const char * jack_port_name(const jack_port_t *port)
Definition: JackAPI.cpp:348
LIB_EXPORT int jack_client_name_size(void)
Definition: JackAPI.cpp:1432
LIB_EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t usecs)
Definition: JackAPI.cpp:1339
LIB_EXPORT const char ** jack_get_ports(jack_client_t *, const char *port_name_pattern, const char *type_name_pattern, unsigned long flags)
Definition: JackAPI.cpp:1241
LIB_EXPORT char * jack_get_client_name_by_uuid(jack_client_t *ext_client, const char *client_uuid)
Definition: JackAPI.cpp:1967
LIB_EXPORT int jack_port_flags(const jack_port_t *port)
Definition: JackAPI.cpp:378
LIB_EXPORT int jack_set_port_registration_callback(jack_client_t *, JackPortRegistrationCallback registration_callback, void *arg)
Definition: JackAPI.cpp:926
LIB_EXPORT int jack_deactivate(jack_client_t *client)
Definition: JackAPI.cpp:1032
LIB_EXPORT jack_client_t * jack_client_new(const char *client_name)
Definition: JackAPI.cpp:309
LIB_EXPORT int jack_set_process_thread(jack_client_t *client, JackThreadCallback fun, void *arg)
Definition: JackAPI.cpp:833
LIB_EXPORT void jack_get_transport_info(jack_client_t *client, jack_transport_info_t *tinfo)
Definition: JackAPI.cpp:1598
SERVER_EXPORT void jack_log(const char *fmt,...)
Definition: JackError.cpp:107
LIB_EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t *client)
Definition: JackAPI.cpp:1546
void(* JackSessionCallback)(jack_session_event_t *event, void *arg)
Definition: session.h:162
LIB_EXPORT void jack_port_get_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
Definition: JackAPI.cpp:535
LIB_EXPORT const char * jack_port_short_name(const jack_port_t *port)
Definition: JackAPI.cpp:363
int EnsureMonitor(bool onoff)
Definition: JackPort.cpp:173
The base class for clients: share part of the implementation for JackInternalClient and JackLibClient...
Definition: JackClient.h:47
LIB_EXPORT int jack_client_kill_thread(jack_client_t *client, jack_native_thread_t thread)
Definition: JackAPI.cpp:1723
LIB_EXPORT void jack_session_event_free(jack_session_event_t *ev)
Definition: JackAPI.cpp:1923
LIB_EXPORT int jack_set_freewheel(jack_client_t *client, int onoff)
Definition: JackAPI.cpp:859