jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1137 lines
53KB

  1. /*
  2. Copyright (C) 2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include "types.h"
  16. #include "jack.h"
  17. #include "JackExports.h"
  18. #include <dlfcn.h>
  19. #include <stdarg.h>
  20. #include <stdio.h>
  21. #include <dirent.h>
  22. #include <string.h>
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. EXPORT int jack_client_name_size (void);
  28. EXPORT char* jack_get_client_name (jack_client_t *client);
  29. EXPORT int jack_internal_client_new (const char *client_name, // deprecated
  30. const char *load_name,
  31. const char *load_init);
  32. EXPORT void jack_internal_client_close (const char *client_name); // deprecated
  33. EXPORT int jack_is_realtime (jack_client_t *client);
  34. EXPORT void jack_on_shutdown (jack_client_t *client,
  35. void (*function)(void *arg), void *arg);
  36. EXPORT int jack_set_process_callback (jack_client_t *client,
  37. JackProcessCallback process_callback,
  38. void *arg);
  39. //
  40. EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status);
  41. // new
  42. EXPORT jack_nframes_t jack_cycle_wait (jack_client_t*);
  43. EXPORT void jack_cycle_signal (jack_client_t*, int status);
  44. EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg);
  45. EXPORT int jack_set_thread_init_callback (jack_client_t *client,
  46. JackThreadInitCallback thread_init_callback,
  47. void *arg);
  48. EXPORT int jack_set_freewheel_callback (jack_client_t *client,
  49. JackFreewheelCallback freewheel_callback,
  50. void *arg);
  51. EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
  52. EXPORT int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
  53. EXPORT int jack_set_buffer_size_callback (jack_client_t *client,
  54. JackBufferSizeCallback bufsize_callback,
  55. void *arg);
  56. EXPORT int jack_set_sample_rate_callback (jack_client_t *client,
  57. JackSampleRateCallback srate_callback,
  58. void *arg);
  59. EXPORT int jack_set_client_registration_callback (jack_client_t *,
  60. JackClientRegistrationCallback
  61. registration_callback, void *arg);
  62. EXPORT int jack_set_port_registration_callback (jack_client_t *,
  63. JackPortRegistrationCallback
  64. registration_callback, void *arg);
  65. EXPORT int jack_set_port_connect_callback (jack_client_t *,
  66. JackPortConnectCallback
  67. connect_callback, void *arg);
  68. EXPORT int jack_set_graph_order_callback (jack_client_t *,
  69. JackGraphOrderCallback graph_callback,
  70. void *);
  71. EXPORT int jack_set_xrun_callback (jack_client_t *,
  72. JackXRunCallback xrun_callback, void *arg);
  73. EXPORT int jack_activate (jack_client_t *client);
  74. EXPORT int jack_deactivate (jack_client_t *client);
  75. EXPORT jack_port_t * jack_port_register (jack_client_t *client,
  76. const char *port_name,
  77. const char *port_type,
  78. unsigned long flags,
  79. unsigned long buffer_size);
  80. EXPORT int jack_port_unregister (jack_client_t *, jack_port_t *);
  81. EXPORT void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  82. EXPORT const char * jack_port_name (const jack_port_t *port);
  83. EXPORT const char * jack_port_short_name (const jack_port_t *port);
  84. EXPORT int jack_port_flags (const jack_port_t *port);
  85. EXPORT const char * jack_port_type (const jack_port_t *port);
  86. EXPORT int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  87. EXPORT int jack_port_connected (const jack_port_t *port);
  88. EXPORT int jack_port_connected_to (const jack_port_t *port,
  89. const char *port_name);
  90. EXPORT const char ** jack_port_get_connections (const jack_port_t *port);
  91. EXPORT const char ** jack_port_get_all_connections (const jack_client_t *client,
  92. const jack_port_t *port);
  93. EXPORT int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  94. EXPORT int jack_port_untie (jack_port_t *port);
  95. EXPORT jack_nframes_t jack_port_get_latency (jack_port_t *port);
  96. EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *,
  97. jack_port_t *port);
  98. EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  99. EXPORT int jack_recompute_total_latency (jack_client_t*, jack_port_t* port);
  100. EXPORT int jack_recompute_total_latencies (jack_client_t*);
  101. EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name);
  102. EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias);
  103. EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias);
  104. EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
  105. EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff);
  106. EXPORT int jack_port_request_monitor_by_name (jack_client_t *client,
  107. const char *port_name, int onoff);
  108. EXPORT int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  109. EXPORT int jack_port_monitoring_input (jack_port_t *port);
  110. EXPORT int jack_connect (jack_client_t *,
  111. const char *source_port,
  112. const char *destination_port);
  113. EXPORT int jack_disconnect (jack_client_t *,
  114. const char *source_port,
  115. const char *destination_port);
  116. EXPORT int jack_port_disconnect (jack_client_t *, jack_port_t *);
  117. EXPORT int jack_port_name_size(void);
  118. EXPORT int jack_port_type_size(void);
  119. EXPORT jack_nframes_t jack_get_sample_rate (jack_client_t *);
  120. EXPORT jack_nframes_t jack_get_buffer_size (jack_client_t *);
  121. EXPORT const char ** jack_get_ports (jack_client_t *,
  122. const char *port_name_pattern,
  123. const char *type_name_pattern,
  124. unsigned long flags);
  125. EXPORT jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
  126. EXPORT jack_port_t * jack_port_by_id (jack_client_t *client,
  127. jack_port_id_t port_id);
  128. EXPORT int jack_engine_takeover_timebase (jack_client_t *);
  129. EXPORT jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  130. EXPORT jack_time_t jack_get_time();
  131. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t time);
  132. EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames);
  133. EXPORT jack_nframes_t jack_frame_time (const jack_client_t *);
  134. EXPORT jack_nframes_t jack_last_frame_time (const jack_client_t *client);
  135. EXPORT float jack_cpu_load (jack_client_t *client);
  136. EXPORT pthread_t jack_client_thread_id (jack_client_t *);
  137. EXPORT void jack_set_error_function (void (*func)(const char *));
  138. EXPORT float jack_get_max_delayed_usecs (jack_client_t *client);
  139. EXPORT float jack_get_xrun_delayed_usecs (jack_client_t *client);
  140. EXPORT void jack_reset_max_delayed_usecs (jack_client_t *client);
  141. EXPORT int jack_release_timebase (jack_client_t *client);
  142. EXPORT int jack_set_sync_callback (jack_client_t *client,
  143. JackSyncCallback sync_callback,
  144. void *arg);
  145. EXPORT int jack_set_sync_timeout (jack_client_t *client,
  146. jack_time_t timeout);
  147. EXPORT int jack_set_timebase_callback (jack_client_t *client,
  148. int conditional,
  149. JackTimebaseCallback timebase_callback,
  150. void *arg);
  151. EXPORT int jack_transport_locate (jack_client_t *client,
  152. jack_nframes_t frame);
  153. EXPORT jack_transport_state_t jack_transport_query (const jack_client_t *client,
  154. jack_position_t *pos);
  155. EXPORT jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client);
  156. EXPORT int jack_transport_reposition (jack_client_t *client,
  157. jack_position_t *pos);
  158. EXPORT void jack_transport_start (jack_client_t *client);
  159. EXPORT void jack_transport_stop (jack_client_t *client);
  160. EXPORT void jack_get_transport_info (jack_client_t *client,
  161. jack_transport_info_t *tinfo);
  162. EXPORT void jack_set_transport_info (jack_client_t *client,
  163. jack_transport_info_t *tinfo);
  164. EXPORT int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
  165. EXPORT int jack_client_create_thread (jack_client_t* client,
  166. pthread_t *thread,
  167. int priority,
  168. int realtime, // boolean
  169. void *(*start_routine)(void*),
  170. void *arg);
  171. EXPORT int jack_drop_real_time_scheduling (pthread_t thread);
  172. EXPORT char * jack_get_internal_client_name (jack_client_t *client,
  173. jack_intclient_t intclient);
  174. EXPORT jack_intclient_t jack_internal_client_handle (jack_client_t *client,
  175. const char *client_name,
  176. jack_status_t *status);
  177. EXPORT jack_intclient_t jack_internal_client_load (jack_client_t *client,
  178. const char *client_name,
  179. jack_options_t options,
  180. jack_status_t *status, ...);
  181. EXPORT jack_status_t jack_internal_client_unload (jack_client_t *client,
  182. jack_intclient_t intclient);
  183. EXPORT jack_client_t * jack_client_open (const char *client_name,
  184. jack_options_t options,
  185. jack_status_t *status, ...);
  186. EXPORT jack_client_t * jack_client_new (const char *client_name);
  187. EXPORT int jack_client_close (jack_client_t *client);
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #define JACK_LIB "libjack.so.0.0"
  192. #define JACKMP_LIB "libjackmp.so"
  193. // Function definition
  194. typedef void* (*jack_port_get_buffer_fun_def)(jack_port_t* port, jack_nframes_t frames);
  195. static jack_port_get_buffer_fun_def jack_port_get_buffer_fun = 0;
  196. EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
  197. {
  198. return (*jack_port_get_buffer_fun)(port, frames);
  199. }
  200. typedef const char* (*jack_port_name_fun_def)(const jack_port_t* port);
  201. static jack_port_name_fun_def jack_port_name_fun = 0;
  202. EXPORT const char* jack_port_name(const jack_port_t* port)
  203. {
  204. return (*jack_port_name_fun)(port);
  205. }
  206. typedef const char* (*jack_port_short_name_fun_def) (const jack_port_t* port);
  207. static jack_port_short_name_fun_def jack_port_short_name_fun = 0;
  208. EXPORT const char* jack_port_short_name(const jack_port_t* port)
  209. {
  210. return (*jack_port_short_name_fun)(port);
  211. }
  212. typedef int (*jack_port_flags_fun_def)(const jack_port_t* port);
  213. static jack_port_flags_fun_def jack_port_flags_fun = 0;
  214. EXPORT int jack_port_flags(const jack_port_t* port)
  215. {
  216. return (*jack_port_flags_fun)(port);
  217. }
  218. typedef const char* (*jack_port_type_fun_def)(const jack_port_t* port);
  219. static jack_port_type_fun_def jack_port_type_fun = 0;
  220. EXPORT const char* jack_port_type(const jack_port_t* port)
  221. {
  222. return (*jack_port_type_fun)(port);
  223. }
  224. typedef int (*jack_port_connected_fun_def)(const jack_port_t* port);
  225. static jack_port_connected_fun_def jack_port_connected_fun = 0;
  226. EXPORT int jack_port_connected(const jack_port_t* port)
  227. {
  228. return (*jack_port_connected_fun)(port);
  229. }
  230. typedef int (*jack_port_connected_to_fun_def)(const jack_port_t* port, const char* portname);
  231. static jack_port_connected_to_fun_def jack_port_connected_to_fun = 0;
  232. EXPORT int jack_port_connected_to(const jack_port_t* port, const char* portname)
  233. {
  234. return (*jack_port_connected_to_fun)(port, portname);
  235. }
  236. typedef int (*jack_port_tie_fun_def)(jack_port_t* src, jack_port_t* dst);
  237. static jack_port_tie_fun_def jack_port_tie_fun = 0;
  238. EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  239. {
  240. return (*jack_port_tie_fun)(src, dst);
  241. }
  242. typedef int (*jack_port_untie_fun_def)(jack_port_t* port);
  243. static jack_port_untie_fun_def jack_port_untie_fun = 0;
  244. EXPORT int jack_port_untie(jack_port_t* port)
  245. {
  246. return (*jack_port_untie_fun)(port);
  247. }
  248. typedef jack_nframes_t (*jack_port_get_latency_fun_def)(jack_port_t* port);
  249. static jack_port_get_latency_fun_def jack_port_get_latency_fun = 0;
  250. EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
  251. {
  252. return (*jack_port_get_latency)(port);
  253. }
  254. typedef void (*jack_port_set_latency_fun_def)(jack_port_t* port, jack_nframes_t frames);
  255. static jack_port_set_latency_fun_def jack_port_set_latency_fun = 0;
  256. EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
  257. {
  258. (*jack_port_set_latency_fun)(port, frames);
  259. }
  260. typedef int (*jack_recompute_total_latency_fun_def)(jack_client_t* ext_client, jack_port_t* port);
  261. static jack_recompute_total_latency_fun_def jack_recompute_total_latency_fun = 0;
  262. EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
  263. {
  264. return (*jack_recompute_total_latency_fun)(ext_client, port);
  265. }
  266. typedef int (*jack_recompute_total_latencies_fun_def)(jack_client_t* ext_client);
  267. static jack_recompute_total_latencies_fun_def jack_recompute_total_latencies_fun = 0;
  268. EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
  269. {
  270. return (*jack_recompute_total_latencies_fun)(ext_client);
  271. }
  272. typedef int (*jack_port_set_name_fun_def)(jack_port_t* port, const char* name);
  273. static jack_port_set_name_fun_def jack_port_set_name_fun = 0;
  274. EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
  275. {
  276. return (*jack_port_set_name_fun)(port, name);
  277. }
  278. typedef int (*jack_port_set_alias_fun_def)(jack_port_t* port, const char* alias);
  279. static jack_port_set_alias_fun_def jack_port_set_alias_fun = 0;
  280. EXPORT int jack_port_set_alias(jack_port_t* port, const char* alias)
  281. {
  282. return (*jack_port_set_alias_fun)(port, alias);
  283. }
  284. typedef int (*jack_port_unset_alias_fun_def)(jack_port_t* port, const char* alias);
  285. static jack_port_unset_alias_fun_def jack_port_unset_alias_fun = 0;
  286. EXPORT int jack_port_unset_alias(jack_port_t* port, const char* alias)
  287. {
  288. return (*jack_port_unset_alias_fun)(port, alias);
  289. }
  290. typedef int (*jack_port_get_aliases_fun_def)(jack_port_t* port, char* const aliases[2]);
  291. static jack_port_get_aliases_fun_def jack_port_get_aliases_fun = 0;
  292. EXPORT int jack_port_get_aliases(jack_port_t* port, char* const aliases[2])
  293. {
  294. return (*jack_port_get_aliases_fun)(port, aliases);
  295. }
  296. typedef int (*jack_port_request_monitor_fun_def)(jack_port_t* port, int onoff);
  297. static jack_port_request_monitor_fun_def jack_port_request_monitor_fun = 0;
  298. EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  299. {
  300. return (*jack_port_request_monitor_fun)(port, onoff);
  301. }
  302. typedef int (*jack_port_request_monitor_by_name_fun_def)(jack_client_t* ext_client, const char* port_name, int onoff);
  303. static jack_port_request_monitor_by_name_fun_def jack_port_request_monitor_by_name_fun = 0;
  304. EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  305. {
  306. return (*jack_port_request_monitor_by_name_fun)(ext_client, port_name, onoff);
  307. }
  308. typedef int (*jack_port_ensure_monitor_fun_def)(jack_port_t* port, int onoff);
  309. static jack_port_ensure_monitor_fun_def jack_port_ensure_monitor_fun = 0;
  310. EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  311. {
  312. return (*jack_port_ensure_monitor_fun)(port, onoff);
  313. }
  314. typedef int (*jack_port_monitoring_input_fun_def)(jack_port_t* port);
  315. static jack_port_monitoring_input_fun_def jack_port_monitoring_input_fun = 0;
  316. EXPORT int jack_port_monitoring_input(jack_port_t* port)
  317. {
  318. return (*jack_port_monitoring_input_fun)(port);
  319. }
  320. typedef int (*jack_is_realtime_fun_def)(jack_client_t* ext_client);
  321. static jack_is_realtime_fun_def jack_is_realtime_fun = 0;
  322. EXPORT int jack_is_realtime(jack_client_t* ext_client)
  323. {
  324. return (*jack_is_realtime_fun)(ext_client);
  325. }
  326. typedef void (*shutdown_fun)(void* arg);
  327. typedef void (*jack_on_shutdown_fun_def)(jack_client_t* ext_client, shutdown_fun callback, void* arg);
  328. static jack_on_shutdown_fun_def jack_on_shutdown_fun = 0;
  329. EXPORT void jack_on_shutdown(jack_client_t* ext_client, shutdown_fun callback, void* arg)
  330. {
  331. (*jack_on_shutdown_fun)(ext_client, callback, arg);
  332. }
  333. typedef int (*jack_set_process_callback_fun_def)(jack_client_t* ext_client, JackProcessCallback callback, void* arg);
  334. static jack_set_process_callback_fun_def jack_set_process_callback_fun = 0;
  335. EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  336. {
  337. return (*jack_set_process_callback_fun)(ext_client, callback, arg);
  338. }
  339. typedef int (*jack_set_freewheel_callback_fun_def)(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg);
  340. static jack_set_freewheel_callback_fun_def jack_set_freewheel_callback_fun = 0;
  341. EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  342. {
  343. return (*jack_set_freewheel_callback_fun)(ext_client, freewheel_callback, arg);
  344. }
  345. typedef int (*jack_set_freewheel_fun_def)(jack_client_t* ext_client, int onoff);
  346. static jack_set_freewheel_fun_def jack_set_freewheel_fun = 0;
  347. EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  348. {
  349. return (*jack_set_freewheel_fun)(ext_client, onoff);
  350. }
  351. typedef int (*jack_set_buffer_size_fun_def)(jack_client_t* ext_client, jack_nframes_t buffer_size);
  352. static jack_set_buffer_size_fun_def jack_set_buffer_size_fun = 0;
  353. EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  354. {
  355. return (*jack_set_buffer_size_fun)(ext_client, buffer_size);
  356. }
  357. typedef int (*jack_set_buffer_size_callback_fun_def)(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg);
  358. static jack_set_buffer_size_callback_fun_def jack_set_buffer_size_callback_fun = 0;
  359. EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  360. {
  361. return (*jack_set_buffer_size_callback_fun)(ext_client, bufsize_callback, arg);
  362. }
  363. typedef int (*jack_set_sample_rate_callback_fun_def)(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg);
  364. static jack_set_sample_rate_callback_fun_def jack_set_sample_rate_callback_fun = 0;
  365. EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  366. {
  367. return (*jack_set_sample_rate_callback_fun)(ext_client, srate_callback, arg);
  368. }
  369. typedef int (*jack_set_client_registration_callback_fun_def)(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg);
  370. static jack_set_client_registration_callback_fun_def jack_set_client_registration_callback_fun = 0;
  371. EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  372. {
  373. return (*jack_set_client_registration_callback_fun)(ext_client, registration_callback, arg);
  374. }
  375. typedef int (*jack_set_port_registration_callback_fun_def)(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg);
  376. static jack_set_port_registration_callback_fun_def jack_set_port_registration_callback_fun = 0;
  377. EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  378. {
  379. return (*jack_set_port_registration_callback_fun)(ext_client, registration_callback, arg);
  380. }
  381. typedef int (*jack_set_port_connect_callback_fun_def)(jack_client_t* ext_client, JackPortConnectCallback connect_callback, void* arg);
  382. static jack_set_port_connect_callback_fun_def jack_set_port_connect_callback_fun = 0;
  383. EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback connect_callback, void* arg)
  384. {
  385. return (*jack_set_port_connect_callback_fun)(ext_client, connect_callback, arg);
  386. }
  387. typedef int (*jack_set_graph_order_callback_fun_def)(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg);
  388. static jack_set_graph_order_callback_fun_def jack_set_graph_order_callback_fun = 0;
  389. EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  390. {
  391. return (*jack_set_graph_order_callback_fun)(ext_client, graph_callback, arg);
  392. }
  393. typedef int (*jack_set_xrun_callback_fun_def)(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg);
  394. static jack_set_xrun_callback_fun_def jack_set_xrun_callback_fun = 0;
  395. EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  396. {
  397. return (*jack_set_xrun_callback_fun)(ext_client, xrun_callback, arg);
  398. }
  399. typedef int (*jack_set_thread_init_callback_fun_def)(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg);
  400. static jack_set_thread_init_callback_fun_def jack_set_thread_init_callback_fun = 0;
  401. EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  402. {
  403. return (*jack_set_thread_init_callback_fun)(ext_client, init_callback, arg);
  404. }
  405. typedef int (*jack_activate_fun_def)(jack_client_t* ext_client);
  406. static jack_activate_fun_def jack_activate_fun = 0;
  407. EXPORT int jack_activate(jack_client_t* ext_client)
  408. {
  409. return (*jack_activate_fun)(ext_client);
  410. }
  411. typedef int (*jack_deactivate_fun_def)(jack_client_t* ext_client);
  412. static jack_deactivate_fun_def jack_deactivate_fun = 0;
  413. EXPORT int jack_deactivate(jack_client_t* ext_client)
  414. {
  415. return (*jack_deactivate_fun)(ext_client);
  416. }
  417. typedef jack_port_t* (*jack_port_register_fun_def)(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
  418. static jack_port_register_fun_def jack_port_register_fun = 0;
  419. 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)
  420. {
  421. return (*jack_port_register_fun)(ext_client, port_name, port_type, flags, buffer_size);
  422. }
  423. typedef int (*jack_port_unregister_fun_def)(jack_client_t* ext_client, jack_port_t* port);
  424. static jack_port_unregister_fun_def jack_port_unregister_fun = 0;
  425. EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  426. {
  427. return (*jack_port_unregister_fun)(ext_client, port);
  428. }
  429. typedef int (*jack_port_is_mine_fun_def)(const jack_client_t* ext_client, const jack_port_t* port);
  430. static jack_port_is_mine_fun_def jack_port_is_mine_fun = 0;
  431. EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  432. {
  433. return (*jack_port_is_mine_fun)(ext_client, port);
  434. }
  435. typedef const char** (*jack_port_get_connections_fun_def)(const jack_port_t* port);
  436. static jack_port_get_connections_fun_def jack_port_get_connections_fun = 0;
  437. EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  438. {
  439. return (*jack_port_get_connections_fun)(port);
  440. }
  441. // Calling client does not need to "own" the port
  442. typedef const char** (*jack_port_get_all_connections_fun_def)(const jack_client_t* ext_client, const jack_port_t* port);
  443. static jack_port_get_all_connections_fun_def jack_port_get_all_connections_fun = 0;
  444. EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  445. {
  446. return (*jack_port_get_all_connections_fun)(ext_client, port);
  447. }
  448. typedef jack_nframes_t (*jack_port_get_total_latency_fun_def)(jack_client_t* ext_client, jack_port_t* port);
  449. static jack_port_get_total_latency_fun_def jack_port_get_total_latency_fun = 0;
  450. EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  451. {
  452. return (*jack_port_get_total_latency_fun)(ext_client, port);
  453. }
  454. typedef int (*jack_connect_fun_def)(jack_client_t* ext_client, const char* src, const char* dst);
  455. static jack_connect_fun_def jack_connect_fun = 0;
  456. EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  457. {
  458. return (*jack_connect_fun)(ext_client, src, dst);
  459. }
  460. typedef int (*jack_disconnect_fun_def)(jack_client_t* ext_client, const char* src, const char* dst);
  461. static jack_disconnect_fun_def jack_disconnect_fun = 0;
  462. EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  463. {
  464. return (*jack_disconnect_fun)(ext_client, src, dst);
  465. }
  466. typedef int (*jack_port_connect_fun_def)(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst);
  467. static jack_port_connect_fun_def jack_port_connect_fun = 0;
  468. EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst)
  469. {
  470. return (*jack_port_connect_fun)(ext_client, src, dst);
  471. }
  472. typedef int (*jack_port_disconnect_fun_def)(jack_client_t* ext_client, jack_port_t* src);
  473. static jack_port_disconnect_fun_def jack_port_disconnect_fun = 0;
  474. EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  475. {
  476. return (*jack_port_disconnect_fun)(ext_client, src);
  477. }
  478. typedef jack_nframes_t (*jack_get_sample_rate_fun_def)(jack_client_t* ext_client);
  479. static jack_get_sample_rate_fun_def jack_get_sample_rate_fun = 0;
  480. EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  481. {
  482. return (*jack_get_sample_rate_fun)(ext_client);
  483. }
  484. typedef jack_nframes_t (*jack_get_buffer_size_fun_def)(jack_client_t* ext_client);
  485. static jack_get_buffer_size_fun_def jack_get_buffer_size_fun = 0;
  486. EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  487. {
  488. return (*jack_get_buffer_size_fun)(ext_client);
  489. }
  490. typedef const char** (*jack_get_ports_fun_def)(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
  491. static jack_get_ports_fun_def jack_get_ports_fun = 0;
  492. EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  493. {
  494. return (*jack_get_ports_fun)(ext_client, port_name_pattern, type_name_pattern, flags);
  495. }
  496. typedef jack_port_t* (*jack_port_by_name_fun_def)(jack_client_t* ext_client, const char* portname);
  497. static jack_port_by_name_fun_def jack_port_by_name_fun = 0;
  498. EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  499. {
  500. return (*jack_port_by_name_fun)(ext_client, portname);
  501. }
  502. typedef jack_port_t* (*jack_port_by_id_fun_def)(const jack_client_t* ext_client, jack_port_id_t id);
  503. static jack_port_by_id_fun_def jack_port_by_id_fun = 0;
  504. EXPORT jack_port_t* jack_port_by_id(const jack_client_t* ext_client, jack_port_id_t id)
  505. {
  506. return (*jack_port_by_id_fun)(ext_client, id);
  507. }
  508. typedef int (*jack_engine_takeover_timebase_fun_def)(jack_client_t* ext_client);
  509. static jack_engine_takeover_timebase_fun_def jack_engine_takeover_timebase_fun = 0;
  510. EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  511. {
  512. return (*jack_engine_takeover_timebase_fun)(ext_client);
  513. }
  514. typedef jack_nframes_t (*jack_frames_since_cycle_start_fun_def)(const jack_client_t* ext_client);
  515. static jack_frames_since_cycle_start_fun_def jack_frames_since_cycle_start_fun = 0;
  516. EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  517. {
  518. return (*jack_frames_since_cycle_start_fun)(ext_client);
  519. }
  520. typedef jack_time_t (*jack_get_time_fun_def)();
  521. static jack_get_time_fun_def jack_get_time_fun = 0;
  522. EXPORT jack_time_t jack_get_time()
  523. {
  524. return (*jack_get_time_fun)();
  525. }
  526. typedef jack_nframes_t (*jack_time_to_frames_fun_def)(const jack_client_t* ext_client, jack_time_t time);
  527. static jack_time_to_frames_fun_def jack_time_to_frames_fun = 0;
  528. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  529. {
  530. return (*jack_time_to_frames_fun)(ext_client, time);
  531. }
  532. typedef jack_time_t (*jack_frames_to_time_fun_def)(const jack_client_t* ext_client, jack_nframes_t frames);
  533. static jack_frames_to_time_fun_def jack_frames_to_time_fun = 0;
  534. EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  535. {
  536. return (*jack_frames_to_time_fun)(ext_client, frames);
  537. }
  538. typedef jack_nframes_t (*jack_frame_time_fun_def)(const jack_client_t* ext_client);
  539. static jack_frame_time_fun_def jack_frame_time_fun = 0;
  540. EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  541. {
  542. return (*jack_frame_time_fun)(ext_client);
  543. }
  544. typedef jack_nframes_t (*jack_last_frame_time_fun_def)(const jack_client_t* ext_client);
  545. static jack_last_frame_time_fun_def jack_last_frame_time_fun = 0;
  546. EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  547. {
  548. return (*jack_last_frame_time_fun)(ext_client);
  549. }
  550. typedef float (*jack_cpu_load_fun_def)(jack_client_t* ext_client);
  551. static jack_cpu_load_fun_def jack_cpu_load_fun = 0;
  552. EXPORT float jack_cpu_load(jack_client_t* ext_client)
  553. {
  554. return (*jack_cpu_load_fun)(ext_client);
  555. }
  556. typedef pthread_t (*jack_client_thread_id_fun_def)(jack_client_t* ext_client);
  557. static jack_client_thread_id_fun_def jack_client_thread_id_fun = 0;
  558. EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
  559. {
  560. return (*jack_client_thread_id_fun)(ext_client);
  561. }
  562. typedef void (*jack_set_error_function_fun_def)(void (*func)(const char *));
  563. static jack_set_error_function_fun_def jack_set_error_function_fun = 0;
  564. EXPORT void jack_set_error_function(void (*func)(const char *))
  565. {
  566. (*jack_set_error_function_fun)(func);
  567. }
  568. typedef char* (*jack_get_client_name_fun_def)(jack_client_t* ext_client);
  569. static jack_get_client_name_fun_def jack_get_client_name_fun = 0;
  570. EXPORT char* jack_get_client_name (jack_client_t* ext_client)
  571. {
  572. return (*jack_get_client_name_fun)(ext_client);
  573. }
  574. typedef int (*jack_internal_client_new_fun_def)(const char *client_name,
  575. const char *load_name,
  576. const char *load_init);
  577. static jack_internal_client_new_fun_def jack_internal_client_new_fun = 0;
  578. EXPORT int jack_internal_client_new (const char *client_name,
  579. const char *load_name,
  580. const char *load_init)
  581. {
  582. return (*jack_internal_client_new_fun)(client_name, load_name, load_init);
  583. }
  584. typedef void (*jack_internal_client_close_fun_def)(const char *client_name);
  585. static jack_internal_client_close_fun_def jack_internal_client_close_fun = 0;
  586. EXPORT void jack_internal_client_close (const char *client_name)
  587. {
  588. (*jack_internal_client_close_fun)(client_name);
  589. }
  590. typedef int (*jack_client_name_size_fun_def)(void);
  591. static jack_client_name_size_fun_def jack_client_name_size_fun = 0;
  592. EXPORT int jack_client_name_size(void)
  593. {
  594. return (*jack_client_name_size_fun)();
  595. }
  596. typedef int (*jack_port_name_size_fun_def)(void);
  597. static jack_port_name_size_fun_def jack_port_name_size_fun = 0;
  598. EXPORT int jack_port_name_size(void)
  599. {
  600. return (*jack_port_name_size_fun)();
  601. }
  602. typedef int (*jack_port_type_size_fun_def)(void);
  603. static jack_port_type_size_fun_def jack_port_type_size_fun = 0;
  604. EXPORT int jack_port_type_size(void)
  605. {
  606. return (*jack_port_type_size_fun)();
  607. }
  608. // transport.h
  609. typedef int (*jack_release_timebase_fun_def)(jack_client_t* ext_client);
  610. static jack_release_timebase_fun_def jack_release_timebase_fun = 0;
  611. EXPORT int jack_release_timebase(jack_client_t* ext_client)
  612. {
  613. return (*jack_release_timebase_fun)(ext_client);
  614. }
  615. typedef int (*jack_set_sync_callback_fun_def)(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg);
  616. static jack_set_sync_callback_fun_def jack_set_sync_callback_fun = 0;
  617. EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  618. {
  619. return (*jack_set_sync_callback_fun)(ext_client, sync_callback, arg);
  620. }
  621. typedef int (*jack_set_sync_timeout_fun_def)(jack_client_t* ext_client, jack_time_t timeout);
  622. static jack_set_sync_timeout_fun_def jack_set_sync_timeout_fun = 0;
  623. EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  624. {
  625. return (*jack_set_sync_timeout_fun)(ext_client, timeout);
  626. }
  627. typedef int (*jack_set_timebase_callback_fun_def)(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg);
  628. static jack_set_timebase_callback_fun_def jack_set_timebase_callback_fun = 0;
  629. EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  630. {
  631. return (*jack_set_timebase_callback_fun)(ext_client, conditional, timebase_callback, arg);
  632. }
  633. typedef int (*jack_transport_locate_fun_def)(jack_client_t* ext_client, jack_nframes_t frame);
  634. static jack_transport_locate_fun_def jack_transport_locate_fun = 0;
  635. EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  636. {
  637. return (*jack_transport_locate_fun)(ext_client, frame);
  638. }
  639. typedef jack_transport_state_t (*jack_transport_query_fun_def)(const jack_client_t* ext_client, jack_position_t* pos);
  640. static jack_transport_query_fun_def jack_transport_query_fun = 0;
  641. EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  642. {
  643. return (*jack_transport_query_fun)(ext_client, pos);
  644. }
  645. typedef jack_nframes_t (*jack_get_current_transport_frame_fun_def)(const jack_client_t* ext_client);
  646. static jack_get_current_transport_frame_fun_def jack_get_current_transport_frame_fun = 0;
  647. EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  648. {
  649. return (*jack_get_current_transport_frame_fun)(ext_client);
  650. }
  651. typedef int (*jack_transport_reposition_fun_def)(jack_client_t* ext_client, jack_position_t* pos);
  652. static jack_transport_reposition_fun_def jack_transport_reposition_fun = 0;
  653. EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
  654. {
  655. return (*jack_transport_reposition_fun)(ext_client, pos);
  656. }
  657. typedef void (*jack_transport_start_fun_def)(jack_client_t* ext_client);
  658. static jack_transport_start_fun_def jack_transport_start_fun = 0;
  659. EXPORT void jack_transport_start(jack_client_t* ext_client)
  660. {
  661. (*jack_transport_start_fun)(ext_client);
  662. }
  663. typedef void (*jack_transport_stop_fun_def)(jack_client_t* ext_client);
  664. static jack_transport_stop_fun_def jack_transport_stop_fun = 0;
  665. EXPORT void jack_transport_stop(jack_client_t* ext_client)
  666. {
  667. (*jack_transport_stop_fun)(ext_client);
  668. }
  669. // deprecated
  670. typedef void (*jack_get_transport_info_fun_def)(jack_client_t* ext_client, jack_transport_info_t* tinfo);
  671. static jack_get_transport_info_fun_def jack_get_transport_info_fun = 0;
  672. EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  673. {
  674. (*jack_get_transport_info_fun)(ext_client, tinfo);
  675. }
  676. typedef void (*jack_set_transport_info_fun_def)(jack_client_t* ext_client, jack_transport_info_t* tinfo);
  677. static jack_set_transport_info_fun_def jack_set_transport_info_fun = 0;
  678. EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  679. {
  680. (*jack_set_transport_info_fun)(ext_client, tinfo);
  681. }
  682. // statistics.h
  683. typedef float (*jack_get_max_delayed_usecs_fun_def)(jack_client_t* ext_client);
  684. static jack_get_max_delayed_usecs_fun_def jack_get_max_delayed_usecs_fun = 0;
  685. EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  686. {
  687. return (*jack_get_max_delayed_usecs_fun)(ext_client);
  688. }
  689. typedef float (*jack_get_xrun_delayed_usecs_fun_def)(jack_client_t* ext_client);
  690. static jack_get_xrun_delayed_usecs_fun_def jack_get_xrun_delayed_usecs_fun = 0;
  691. EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  692. {
  693. return (*jack_get_xrun_delayed_usecs_fun)(ext_client);
  694. }
  695. typedef void (*jack_reset_max_delayed_usecs_fun_def)(jack_client_t* ext_client);
  696. static jack_reset_max_delayed_usecs_fun_def jack_reset_max_delayed_usecs_fun = 0;
  697. EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  698. {
  699. (*jack_reset_max_delayed_usecs)(ext_client);
  700. }
  701. // thread.h
  702. typedef int (*jack_acquire_real_time_scheduling_fun_def)(pthread_t thread, int priority);
  703. static jack_acquire_real_time_scheduling_fun_def jack_acquire_real_time_scheduling_fun = 0;
  704. EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
  705. {
  706. return (*jack_acquire_real_time_scheduling_fun)(thread, priority);
  707. }
  708. typedef void *(*start_routine)(void*);
  709. typedef int (*jack_client_create_thread_fun_def)(jack_client_t* client,
  710. pthread_t *thread,
  711. int priority,
  712. int realtime, // boolean
  713. start_routine callback,
  714. void *arg);
  715. static jack_client_create_thread_fun_def jack_client_create_thread_fun = 0;
  716. EXPORT int jack_client_create_thread(jack_client_t* client,
  717. pthread_t *thread,
  718. int priority,
  719. int realtime, // boolean
  720. start_routine callback,
  721. void *arg)
  722. {
  723. return (*jack_client_create_thread_fun)(client, thread, priority, realtime, callback, arg);
  724. }
  725. typedef int (*jack_drop_real_time_scheduling_fun_def)(pthread_t thread);
  726. static jack_drop_real_time_scheduling_fun_def jack_drop_real_time_scheduling_fun = 0;
  727. EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
  728. {
  729. return (*jack_drop_real_time_scheduling_fun)(thread);
  730. }
  731. // intclient.h
  732. typedef char* (*jack_get_internal_client_name_fun_def)(jack_client_t* ext_client, jack_intclient_t intclient);
  733. static jack_get_internal_client_name_fun_def jack_get_internal_client_name_fun = 0;
  734. EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  735. {
  736. return (*jack_get_internal_client_name_fun)(ext_client, intclient);
  737. }
  738. typedef jack_intclient_t (*jack_internal_client_handle_fun_def)(jack_client_t* ext_client, const char* client_name, jack_status_t* status);
  739. static jack_internal_client_handle_fun_def jack_internal_client_handle_fun = 0;
  740. EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  741. {
  742. return (*jack_internal_client_handle_fun)(ext_client, client_name, status);
  743. }
  744. typedef jack_intclient_t (*jack_internal_client_load_fun_def)(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...);
  745. static jack_internal_client_load_fun_def jack_internal_client_load_fun = 0;
  746. EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...)
  747. {
  748. va_list ap;
  749. va_start(ap, status);
  750. jack_intclient_t res = (*jack_internal_client_load_fun)(ext_client, client_name, options, status, ap);
  751. va_end(ap);
  752. return res;
  753. }
  754. typedef jack_status_t (*jack_internal_client_unload_fun_def)(jack_client_t* ext_client, jack_intclient_t intclient);
  755. static jack_internal_client_unload_fun_def jack_internal_client_unload_fun = 0;
  756. EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  757. {
  758. return (*jack_internal_client_unload_fun)(ext_client, intclient);
  759. }
  760. // client
  761. static long gClientCount = 0;
  762. static void* gLibrary = 0;
  763. static bool init_library();
  764. static bool open_library();
  765. static void close_library();
  766. typedef jack_client_t * (*jack_client_open_fun_def)(const char *client_name, jack_options_t options, jack_status_t *status, ...);
  767. static jack_client_open_fun_def jack_client_open_fun = 0;
  768. EXPORT jack_client_t * jack_client_open(const char *client_name, jack_options_t options, jack_status_t *status, ...)
  769. {
  770. // TODO : in "autodstart mode", has to load jackdrc file and figure out which server has to be started...
  771. // Library check...
  772. if (!open_library())
  773. return 0;
  774. va_list ap;
  775. va_start(ap, status);
  776. jack_client_t* res = (*jack_client_open_fun)(client_name, options, status, ap);
  777. va_end(ap);
  778. return res;
  779. }
  780. typedef jack_client_t * (*jack_client_new_fun_def)(const char *client_name);
  781. static jack_client_new_fun_def jack_client_new_fun = 0;
  782. EXPORT jack_client_t * jack_client_new(const char *client_name)
  783. {
  784. // Library check...
  785. if (!open_library())
  786. return 0;
  787. return (*jack_client_new_fun)(client_name);
  788. }
  789. typedef int (*jack_client_close_fun_def)(jack_client_t *client);
  790. static jack_client_close_fun_def jack_client_close_fun = 0;
  791. EXPORT int jack_client_close(jack_client_t *client)
  792. {
  793. int res = (*jack_client_close_fun)(client);
  794. close_library();
  795. return res;
  796. }
  797. // Library loader
  798. static bool get_jack_library_in_directory(const char* dir_name, const char* library_name, char* library_res_name)
  799. {
  800. printf("get_jack_library_in_directory\n");
  801. struct dirent * dir_entry;
  802. DIR * dir_stream = opendir(dir_name);
  803. if (!dir_stream)
  804. return false;
  805. while ((dir_entry = readdir(dir_stream))) {
  806. if (strncmp(library_name, dir_entry->d_name, strlen(library_name)) == 0) {
  807. printf("found\n");
  808. sprintf(library_res_name, "%s/%s", dir_name, dir_entry->d_name);
  809. closedir(dir_stream);
  810. return true;
  811. }
  812. }
  813. closedir(dir_stream);
  814. return false;
  815. }
  816. static bool get_jack_library(const char* library_name, char* library_res_name)
  817. {
  818. if (get_jack_library_in_directory("/usr/lib", library_name, library_res_name))
  819. return true;
  820. if (get_jack_library_in_directory("/usr/local/lib", library_name, library_res_name))
  821. return true;
  822. return false;
  823. }
  824. static bool open_library()
  825. {
  826. printf("open_library %ld \n", gClientCount);
  827. if (gClientCount++ == 0) {
  828. return init_library();
  829. } else {
  830. return true;
  831. }
  832. }
  833. static void close_library()
  834. {
  835. printf("close_library\n");
  836. if (--gClientCount == 0) {
  837. dlclose(gLibrary);
  838. gLibrary = 0;
  839. }
  840. }
  841. static bool check_client(void* library)
  842. {
  843. jack_client_t* client = 0;
  844. printf("check_library\n");
  845. // Get "new", "open" and "close" entry points...
  846. jack_client_new_fun = (jack_client_new_fun_def)dlsym(library, "jack_client_new");
  847. jack_client_close_fun = (jack_client_close_fun_def)dlsym(library, "jack_client_close");
  848. // Try opening a client...
  849. if ((client = (*jack_client_new_fun)("dummy"))) { // jackd server is running....
  850. printf("check_library 1 %x\n", jack_client_close_fun);
  851. (*jack_client_close_fun)(client);
  852. printf("check_library 2\n");
  853. return true;
  854. } else {
  855. printf("check_library NO\n");
  856. return false;
  857. }
  858. }
  859. static bool init_library()
  860. {
  861. char library_res_name[256];
  862. void* jackLibrary = (get_jack_library(JACK_LIB, library_res_name)) ? dlopen(library_res_name, RTLD_LAZY) : 0;
  863. void* jackmpLibrary = (get_jack_library(JACKMP_LIB, library_res_name)) ? dlopen(library_res_name, RTLD_LAZY) : 0;
  864. if (jackLibrary) {
  865. printf("jackLibrary\n");
  866. if (check_client(jackLibrary)) { // jackd is running...
  867. printf("jackd is running\n");
  868. gLibrary = jackLibrary;
  869. if (jackmpLibrary)
  870. dlclose(jackmpLibrary);
  871. printf("jackd is running OK\n");
  872. } else if (check_client(jackmpLibrary)) { // jackdmp is running...
  873. gLibrary = jackmpLibrary;
  874. if (jackLibrary)
  875. dlclose(jackLibrary);
  876. } else {
  877. goto error;
  878. }
  879. } else if (jackmpLibrary) {
  880. printf("jackmpLibrary\n");
  881. if (check_client(jackmpLibrary)) { // jackd is running...
  882. gLibrary = jackmpLibrary;
  883. } else {
  884. goto error;
  885. }
  886. } else {
  887. printf("Jack libraries not found, failure...\n");
  888. goto error;
  889. }
  890. // Load entry points...
  891. jack_client_open_fun = (jack_client_open_fun_def)dlsym(gLibrary, "jack_client_open");
  892. jack_client_new_fun = (jack_client_new_fun_def)dlsym(gLibrary, "jack_client_new");
  893. jack_client_close_fun = (jack_client_close_fun_def)dlsym(gLibrary, "jack_client_close");
  894. jack_client_name_size_fun = (jack_client_name_size_fun_def)dlsym(gLibrary, "jack_client_name_size");
  895. jack_get_client_name_fun = (jack_get_client_name_fun_def)dlsym(gLibrary, "jack_get_client_name");
  896. jack_internal_client_new_fun = (jack_internal_client_new_fun_def)dlsym(gLibrary, "jack_internal_client_new");
  897. jack_internal_client_close_fun = (jack_internal_client_close_fun_def)dlsym(gLibrary, "jack_internal_client_close");
  898. jack_is_realtime_fun = (jack_is_realtime_fun_def)dlsym(gLibrary, "jack_is_realtime");
  899. jack_on_shutdown_fun = (jack_on_shutdown_fun_def)dlsym(gLibrary, "jack_on_shutdown");
  900. jack_set_process_callback_fun = (jack_set_process_callback_fun_def)dlsym(gLibrary, "jack_set_process_callback");
  901. jack_set_thread_init_callback_fun = (jack_set_thread_init_callback_fun_def)dlsym(gLibrary, "jack_set_thread_init_callback");
  902. jack_set_freewheel_callback_fun = (jack_set_freewheel_callback_fun_def)dlsym(gLibrary, "jack_set_freewheel_callback");
  903. jack_set_freewheel_fun = (jack_set_freewheel_fun_def)dlsym(gLibrary, "jack_set_freewheel");
  904. jack_set_buffer_size_fun = (jack_set_buffer_size_fun_def)dlsym(gLibrary, "jack_set_buffer_size");
  905. jack_set_buffer_size_callback_fun = (jack_set_buffer_size_callback_fun_def)dlsym(gLibrary, "jack_set_buffer_size_callback");
  906. jack_set_sample_rate_callback_fun = (jack_set_sample_rate_callback_fun_def)dlsym(gLibrary, "jack_set_sample_rate_callback");
  907. jack_set_client_registration_callback_fun = (jack_set_client_registration_callback_fun_def)dlsym(gLibrary, "jack_set_client_registration_callback");
  908. jack_set_port_registration_callback_fun = (jack_set_port_registration_callback_fun_def)dlsym(gLibrary, "jack_set_port_registration_callback");
  909. jack_set_port_connect_callback_fun = (jack_set_port_connect_callback_fun_def)dlsym(gLibrary, "jack_set_port_connect_callback");
  910. jack_set_graph_order_callback_fun = (jack_set_graph_order_callback_fun_def)dlsym(gLibrary, "jack_set_graph_order_callback");
  911. jack_set_xrun_callback_fun = (jack_set_xrun_callback_fun_def)dlsym(gLibrary, "jack_set_xrun_callback");
  912. jack_activate_fun = (jack_activate_fun_def)dlsym(gLibrary, "jack_activate");
  913. jack_deactivate_fun = (jack_deactivate_fun_def)dlsym(gLibrary, "jack_deactivate");
  914. jack_port_register_fun = (jack_port_register_fun_def)dlsym(gLibrary, "jack_port_register");
  915. jack_port_unregister_fun = (jack_port_unregister_fun_def)dlsym(gLibrary, "jack_port_unregister");
  916. jack_port_get_buffer_fun = (jack_port_get_buffer_fun_def)dlsym(gLibrary, "jack_port_get_buffer");
  917. jack_port_name_fun = (jack_port_name_fun_def)dlsym(gLibrary, "jack_port_name");
  918. jack_port_short_name_fun = (jack_port_short_name_fun_def)dlsym(gLibrary, "jack_port_short_name");
  919. jack_port_flags_fun = (jack_port_flags_fun_def)dlsym(gLibrary, "jack_port_flags");
  920. jack_port_type_fun = (jack_port_type_fun_def)dlsym(gLibrary, "jack_port_type");
  921. jack_port_is_mine_fun = (jack_port_is_mine_fun_def)dlsym(gLibrary, "jack_port_is_mine");
  922. jack_port_connected_fun = (jack_port_connected_fun_def)dlsym(gLibrary, "jack_port_connected");
  923. jack_port_connected_to_fun = (jack_port_connected_to_fun_def)dlsym(gLibrary, "jack_port_connected_to");
  924. jack_port_get_connections_fun = (jack_port_get_connections_fun_def)dlsym(gLibrary, "jack_port_get_connections");
  925. jack_port_get_all_connections_fun = (jack_port_get_all_connections_fun_def)dlsym(gLibrary, "jack_port_get_all_connections");
  926. jack_port_tie_fun = (jack_port_tie_fun_def)dlsym(gLibrary, "jack_port_tie");
  927. jack_port_untie_fun = (jack_port_untie_fun_def)dlsym(gLibrary, "jack_port_untie");
  928. jack_port_get_latency_fun = (jack_port_get_latency_fun_def)dlsym(gLibrary, "jack_port_get_latency");
  929. jack_port_get_total_latency_fun = (jack_port_get_total_latency_fun_def)dlsym(gLibrary, "jack_port_get_total_latency");
  930. jack_port_set_latency_fun = (jack_port_set_latency_fun_def)dlsym(gLibrary, "jack_port_set_latency");
  931. jack_recompute_total_latency_fun = (jack_recompute_total_latency_fun_def)dlsym(gLibrary, "jack_recompute_total_latency");
  932. jack_recompute_total_latencies_fun = (jack_recompute_total_latencies_fun_def)dlsym(gLibrary, "jack_recompute_total_latencies");
  933. jack_port_set_name_fun = (jack_port_set_name_fun_def)dlsym(gLibrary, "jack_port_set_name");
  934. jack_port_set_alias_fun = (jack_port_set_alias_fun_def)dlsym(gLibrary, "jack_port_set_alias");
  935. jack_port_unset_alias_fun = (jack_port_unset_alias_fun_def)dlsym(gLibrary, "jack_port_unset_alias");
  936. jack_port_get_aliases_fun = (jack_port_get_aliases_fun_def)dlsym(gLibrary, "jack_port_get_aliases");
  937. jack_port_request_monitor_fun = (jack_port_request_monitor_fun_def)dlsym(gLibrary, "jack_port_request_monitor");
  938. jack_port_request_monitor_by_name_fun = (jack_port_request_monitor_by_name_fun_def)dlsym(gLibrary, "jack_port_request_monitor_by_name");
  939. jack_port_ensure_monitor_fun = (jack_port_ensure_monitor_fun_def)dlsym(gLibrary, "jack_port_ensure_monitor");
  940. jack_port_monitoring_input_fun = (jack_port_monitoring_input_fun_def)dlsym(gLibrary, "jack_port_monitoring_input");
  941. jack_connect_fun = (jack_connect_fun_def)dlsym(gLibrary, "jack_connect");
  942. jack_disconnect_fun = (jack_disconnect_fun_def)dlsym(gLibrary, "jack_disconnect");
  943. jack_port_connect_fun = (jack_port_connect_fun_def)dlsym(gLibrary, "jack_port_connect");
  944. jack_port_disconnect_fun = (jack_port_disconnect_fun_def)dlsym(gLibrary, "jack_port_disconnect");
  945. jack_port_name_size_fun = (jack_port_name_size_fun_def)dlsym(gLibrary, "jack_port_name_size");
  946. jack_port_type_size_fun = (jack_port_type_size_fun_def)dlsym(gLibrary, "jack_port_type_size");
  947. jack_get_sample_rate_fun = (jack_get_sample_rate_fun_def)dlsym(gLibrary, "jack_get_sample_rate");
  948. jack_get_buffer_size_fun = (jack_get_buffer_size_fun_def)dlsym(gLibrary, "jack_get_buffer_size");
  949. jack_get_ports_fun = (jack_get_ports_fun_def)dlsym(gLibrary, "jack_get_ports");
  950. jack_port_by_name_fun = (jack_port_by_name_fun_def)dlsym(gLibrary, "jack_port_by_name");
  951. jack_port_by_id_fun = (jack_port_by_id_fun_def)dlsym(gLibrary, "jack_port_by_id");
  952. jack_engine_takeover_timebase_fun = (jack_engine_takeover_timebase_fun_def)dlsym(gLibrary, "jack_engine_takeover_timebase");
  953. jack_frames_since_cycle_start_fun = (jack_frames_since_cycle_start_fun_def)dlsym(gLibrary, "jack_frames_since_cycle_start");
  954. jack_get_time_fun = (jack_get_time_fun_def)dlsym(gLibrary, "jack_get_time");
  955. jack_time_to_frames_fun = (jack_time_to_frames_fun_def)dlsym(gLibrary, "jack_time_to_frames");
  956. jack_frames_to_time_fun = (jack_frames_to_time_fun_def)dlsym(gLibrary, "jack_frames_to_time");
  957. jack_frame_time_fun = (jack_frame_time_fun_def)dlsym(gLibrary, "jack_frame_time");
  958. jack_last_frame_time_fun = (jack_last_frame_time_fun_def)dlsym(gLibrary, "jack_last_frame_time");
  959. jack_cpu_load_fun = (jack_cpu_load_fun_def)dlsym(gLibrary, "jack_cpu_load");
  960. jack_client_thread_id_fun = (jack_client_thread_id_fun_def)dlsym(gLibrary, "jack_client_thread_id");
  961. jack_set_error_function_fun = (jack_set_error_function_fun_def)dlsym(gLibrary, "jack_set_error_function");
  962. jack_get_max_delayed_usecs_fun = (jack_get_max_delayed_usecs_fun_def)dlsym(gLibrary, "jack_get_max_delayed_usecs");
  963. jack_get_xrun_delayed_usecs_fun = (jack_get_xrun_delayed_usecs_fun_def)dlsym(gLibrary, "jack_get_xrun_delayed_usecs");
  964. jack_reset_max_delayed_usecs_fun = (jack_reset_max_delayed_usecs_fun_def)dlsym(gLibrary, "jack_reset_max_delayed_usecs");
  965. jack_release_timebase_fun = (jack_release_timebase_fun_def)dlsym(gLibrary, "jack_release_timebase");
  966. jack_set_sync_callback_fun = (jack_set_sync_callback_fun_def)dlsym(gLibrary, "jack_set_sync_callback");
  967. jack_set_sync_timeout_fun = (jack_set_sync_timeout_fun_def)dlsym(gLibrary, "jack_set_sync_timeout");
  968. jack_set_timebase_callback_fun = (jack_set_timebase_callback_fun_def)dlsym(gLibrary, "jack_set_timebase_callback");
  969. jack_transport_locate_fun = (jack_transport_locate_fun_def)dlsym(gLibrary, "jack_transport_locate_fun");
  970. jack_transport_query_fun = (jack_transport_query_fun_def)dlsym(gLibrary, "jack_transport_query");
  971. jack_get_current_transport_frame_fun = (jack_get_current_transport_frame_fun_def)dlsym(gLibrary, "jack_get_current_transport_frame");
  972. jack_transport_reposition_fun = (jack_transport_reposition_fun_def)dlsym(gLibrary, "jack_transport_reposition");
  973. jack_transport_start_fun = (jack_transport_start_fun_def)dlsym(gLibrary, "jack_transport_start");
  974. jack_transport_stop_fun = (jack_transport_stop_fun_def)dlsym(gLibrary, "jack_transport_stop");
  975. jack_get_transport_info_fun = (jack_get_transport_info_fun_def)dlsym(gLibrary, "jack_get_transport_info");
  976. jack_set_transport_info_fun = (jack_set_transport_info_fun_def)dlsym(gLibrary, "jack_set_transport_info");
  977. jack_acquire_real_time_scheduling_fun = (jack_acquire_real_time_scheduling_fun_def)dlsym(gLibrary, "jack_acquire_real_time_scheduling");
  978. jack_client_create_thread_fun = (jack_client_create_thread_fun_def)dlsym(gLibrary, "jack_client_create_thread");
  979. jack_drop_real_time_scheduling_fun = (jack_drop_real_time_scheduling_fun_def)dlsym(gLibrary, "jack_drop_real_time_scheduling");
  980. jack_get_internal_client_name_fun = (jack_get_internal_client_name_fun_def)dlsym(gLibrary, "jack_get_internal_client_name");
  981. jack_internal_client_handle_fun = (jack_internal_client_handle_fun_def)dlsym(gLibrary, "jack_internal_client_handle");
  982. jack_internal_client_load_fun = (jack_internal_client_load_fun_def)dlsym(gLibrary, "jack_internal_client_load");
  983. jack_internal_client_unload_fun = (jack_internal_client_unload_fun_def)dlsym(gLibrary, "jack_internal_client_unload");
  984. printf("init_library OK\n");
  985. return true;
  986. error:
  987. if (jackLibrary)
  988. dlclose(jackLibrary);
  989. if (jackmpLibrary)
  990. dlclose(jackmpLibrary);
  991. gLibrary = 0;
  992. return false;
  993. }