Audio plugin host https://kx.studio/carla
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.

1515 lines
48KB

  1. /*
  2. * JackBridge (Part 1, JACK functions)
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "JackBridge.hpp"
  17. #if ! (defined(JACKBRIDGE_DIRECT) || defined(JACKBRIDGE_DUMMY))
  18. #include "CarlaLibUtils.hpp"
  19. // -----------------------------------------------------------------------------
  20. typedef void (*jacksym_get_version)(int*, int*, int*, int*);
  21. typedef const char* (*jacksym_get_version_string)();
  22. typedef jack_client_t* (*jacksym_client_open)(const char*, jack_options_t, jack_status_t*, ...);
  23. typedef const char* (*jacksym_client_rename)(jack_client_t* client, const char* new_name);
  24. typedef int (*jacksym_client_close)(jack_client_t*);
  25. typedef int (*jacksym_client_name_size)();
  26. typedef char* (*jacksym_get_client_name)(jack_client_t*);
  27. typedef int (*jacksym_activate)(jack_client_t*);
  28. typedef int (*jacksym_deactivate)(jack_client_t*);
  29. typedef int (*jacksym_get_client_pid)(const char*);
  30. typedef int (*jacksym_is_realtime)(jack_client_t*);
  31. typedef int (*jacksym_set_thread_init_callback)(jack_client_t*, JackThreadInitCallback, void*);
  32. typedef void (*jacksym_on_shutdown)(jack_client_t*, JackShutdownCallback, void*);
  33. typedef void (*jacksym_on_info_shutdown)(jack_client_t*, JackInfoShutdownCallback, void*);
  34. typedef int (*jacksym_set_process_callback)(jack_client_t*, JackProcessCallback, void*);
  35. typedef int (*jacksym_set_freewheel_callback)(jack_client_t*, JackFreewheelCallback, void*);
  36. typedef int (*jacksym_set_buffer_size_callback)(jack_client_t*, JackBufferSizeCallback, void*);
  37. typedef int (*jacksym_set_sample_rate_callback)(jack_client_t*, JackSampleRateCallback, void*);
  38. typedef int (*jacksym_set_client_registration_callback)(jack_client_t*, JackClientRegistrationCallback, void*);
  39. typedef int (*jacksym_set_client_rename_callback)(jack_client_t*, JackClientRenameCallback, void*);
  40. typedef int (*jacksym_set_port_registration_callback)(jack_client_t*, JackPortRegistrationCallback, void*);
  41. typedef int (*jacksym_set_port_connect_callback)(jack_client_t*, JackPortConnectCallback, void*);
  42. typedef int (*jacksym_set_port_rename_callback)(jack_client_t*, JackPortRenameCallback, void*);
  43. typedef int (*jacksym_set_graph_order_callback)(jack_client_t*, JackGraphOrderCallback, void*);
  44. typedef int (*jacksym_set_xrun_callback)(jack_client_t*, JackXRunCallback, void*);
  45. typedef int (*jacksym_set_latency_callback)(jack_client_t*, JackLatencyCallback, void*);
  46. typedef int (*jacksym_set_freewheel)(jack_client_t*, int);
  47. typedef int (*jacksym_set_buffer_size)(jack_client_t*, jack_nframes_t);
  48. typedef jack_nframes_t (*jacksym_get_sample_rate)(jack_client_t*);
  49. typedef jack_nframes_t (*jacksym_get_buffer_size)(jack_client_t*);
  50. typedef float (*jacksym_cpu_load)(jack_client_t*);
  51. typedef jack_port_t* (*jacksym_port_register)(jack_client_t*, const char*, const char*, unsigned long, unsigned long);
  52. typedef int (*jacksym_port_unregister)(jack_client_t*, jack_port_t*);
  53. typedef void* (*jacksym_port_get_buffer)(jack_port_t*, jack_nframes_t);
  54. typedef const char* (*jacksym_port_name)(const jack_port_t*);
  55. typedef const char* (*jacksym_port_short_name)(const jack_port_t*);
  56. typedef int (*jacksym_port_flags)(const jack_port_t*);
  57. typedef const char* (*jacksym_port_type)(const jack_port_t*);
  58. typedef int (*jacksym_port_is_mine)(const jack_client_t*, const jack_port_t*);
  59. typedef int (*jacksym_port_connected)(const jack_port_t*);
  60. typedef int (*jacksym_port_connected_to)(const jack_port_t*, const char*);
  61. typedef const char** (*jacksym_port_get_connections)(const jack_port_t*);
  62. typedef const char** (*jacksym_port_get_all_connections)(const jack_client_t*, const jack_port_t*);
  63. typedef int (*jacksym_port_set_name)(jack_port_t*, const char*);
  64. typedef int (*jacksym_port_set_alias)(jack_port_t*, const char*);
  65. typedef int (*jacksym_port_unset_alias)(jack_port_t*, const char*);
  66. typedef int (*jacksym_port_get_aliases)(const jack_port_t*, char* const aliases[2]);
  67. typedef int (*jacksym_port_request_monitor)(jack_port_t*, int);
  68. typedef int (*jacksym_port_request_monitor_by_name)(jack_client_t*, const char*, int);
  69. typedef int (*jacksym_port_ensure_monitor)(jack_port_t*, int);
  70. typedef int (*jacksym_port_monitoring_input)(jack_port_t*);
  71. typedef int (*jacksym_connect)(jack_client_t*, const char*, const char*);
  72. typedef int (*jacksym_disconnect)(jack_client_t*, const char*, const char*);
  73. typedef int (*jacksym_port_disconnect)(jack_client_t*, jack_port_t*);
  74. typedef int (*jacksym_port_name_size)();
  75. typedef int (*jacksym_port_type_size)();
  76. typedef size_t (*jacksym_port_type_get_buffer_size)(jack_client_t*, const char*);
  77. typedef void (*jacksym_port_get_latency_range)(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t*);
  78. typedef void (*jacksym_port_set_latency_range)(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t*);
  79. typedef int (*jacksym_recompute_total_latencies)(jack_client_t*);
  80. typedef const char** (*jacksym_get_ports)(jack_client_t*, const char*, const char*, unsigned long);
  81. typedef jack_port_t* (*jacksym_port_by_name)(jack_client_t*, const char*);
  82. typedef jack_port_t* (*jacksym_port_by_id)(jack_client_t*, jack_port_id_t);
  83. typedef void (*jacksym_free)(void*);
  84. typedef uint32_t (*jacksym_midi_get_event_count)(void*);
  85. typedef int (*jacksym_midi_event_get)(jack_midi_event_t*, void*, uint32_t);
  86. typedef void (*jacksym_midi_clear_buffer)(void*);
  87. typedef int (*jacksym_midi_event_write)(void*, jack_nframes_t, const jack_midi_data_t*, size_t);
  88. typedef jack_midi_data_t* (*jacksym_midi_event_reserve)(void*, jack_nframes_t, size_t);
  89. typedef int (*jacksym_release_timebase)(jack_client_t*);
  90. typedef int (*jacksym_set_sync_callback)(jack_client_t*, JackSyncCallback, void*);
  91. typedef int (*jacksym_set_sync_timeout)(jack_client_t*, jack_time_t);
  92. typedef int (*jacksym_set_timebase_callback)(jack_client_t*, int, JackTimebaseCallback, void*);
  93. typedef int (*jacksym_transport_locate)(jack_client_t*, jack_nframes_t);
  94. typedef jack_transport_state_t (*jacksym_transport_query)(const jack_client_t*, jack_position_t*);
  95. typedef jack_nframes_t (*jacksym_get_current_transport_frame)(const jack_client_t*);
  96. typedef int (*jacksym_transport_reposition)(jack_client_t*, const jack_position_t*);
  97. typedef void (*jacksym_transport_start)(jack_client_t*);
  98. typedef void (*jacksym_transport_stop)(jack_client_t*);
  99. typedef int (*jacksym_custom_publish_data)(jack_client_t*, const char*, const void*, size_t);
  100. typedef int (*jacksym_custom_get_data)(jack_client_t*, const char*, const char*, void**, size_t*);
  101. typedef int (*jacksym_custom_unpublish_data)(jack_client_t*, const char*);
  102. typedef int (*jacksym_custom_set_data_appearance_callback)(jack_client_t*, JackCustomDataAppearanceCallback, void*);
  103. typedef const char** (*jacksym_custom_get_keys)(jack_client_t*, const char*);
  104. // -----------------------------------------------------------------------------
  105. struct JackBridge {
  106. void* lib;
  107. jacksym_get_version get_version_ptr;
  108. jacksym_get_version_string get_version_string_ptr;
  109. jacksym_client_open client_open_ptr;
  110. jacksym_client_rename client_rename_ptr;
  111. jacksym_client_close client_close_ptr;
  112. jacksym_client_name_size client_name_size_ptr;
  113. jacksym_get_client_name get_client_name_ptr;
  114. jacksym_activate activate_ptr;
  115. jacksym_deactivate deactivate_ptr;
  116. jacksym_get_client_pid get_client_pid_ptr;
  117. jacksym_is_realtime is_realtime_ptr;
  118. jacksym_set_thread_init_callback set_thread_init_callback_ptr;
  119. jacksym_on_shutdown on_shutdown_ptr;
  120. jacksym_on_info_shutdown on_info_shutdown_ptr;
  121. jacksym_set_process_callback set_process_callback_ptr;
  122. jacksym_set_freewheel_callback set_freewheel_callback_ptr;
  123. jacksym_set_buffer_size_callback set_buffer_size_callback_ptr;
  124. jacksym_set_sample_rate_callback set_sample_rate_callback_ptr;
  125. jacksym_set_client_registration_callback set_client_registration_callback_ptr;
  126. jacksym_set_client_rename_callback set_client_rename_callback_ptr;
  127. jacksym_set_port_registration_callback set_port_registration_callback_ptr;
  128. jacksym_set_port_connect_callback set_port_connect_callback_ptr;
  129. jacksym_set_port_rename_callback set_port_rename_callback_ptr;
  130. jacksym_set_xrun_callback set_xrun_callback_ptr;
  131. jacksym_set_latency_callback set_latency_callback_ptr;
  132. jacksym_set_freewheel set_freewheel_ptr;
  133. jacksym_set_buffer_size set_buffer_size_ptr;
  134. jacksym_get_sample_rate get_sample_rate_ptr;
  135. jacksym_get_buffer_size get_buffer_size_ptr;
  136. jacksym_cpu_load cpu_load_ptr;
  137. jacksym_port_register port_register_ptr;
  138. jacksym_port_unregister port_unregister_ptr;
  139. jacksym_port_get_buffer port_get_buffer_ptr;
  140. jacksym_port_name port_name_ptr;
  141. jacksym_port_short_name port_short_name_ptr;
  142. jacksym_port_flags port_flags_ptr;
  143. jacksym_port_type port_type_ptr;
  144. jacksym_port_is_mine port_is_mine_ptr;
  145. jacksym_port_connected port_connected_ptr;
  146. jacksym_port_connected_to port_connected_to_ptr;
  147. jacksym_port_get_connections port_get_connections_ptr;
  148. jacksym_port_get_all_connections port_get_all_connections_ptr;
  149. jacksym_port_set_name port_set_name_ptr;
  150. jacksym_port_set_alias port_set_alias_ptr;
  151. jacksym_port_unset_alias port_unset_alias_ptr;
  152. jacksym_port_get_aliases port_get_aliases_ptr;
  153. jacksym_port_request_monitor port_request_monitor_ptr;
  154. jacksym_port_request_monitor_by_name port_request_monitor_by_name_ptr;
  155. jacksym_port_ensure_monitor port_ensure_monitor_ptr;
  156. jacksym_port_monitoring_input port_monitoring_input_ptr;
  157. jacksym_connect connect_ptr;
  158. jacksym_disconnect disconnect_ptr;
  159. jacksym_port_disconnect port_disconnect_ptr;
  160. jacksym_port_name_size port_name_size_ptr;
  161. jacksym_port_type_size port_type_size_ptr;
  162. jacksym_port_type_get_buffer_size port_type_get_buffer_size_ptr;
  163. jacksym_port_get_latency_range port_get_latency_range_ptr;
  164. jacksym_port_set_latency_range port_set_latency_range_ptr;
  165. jacksym_recompute_total_latencies recompute_total_latencies_ptr;
  166. jacksym_get_ports get_ports_ptr;
  167. jacksym_port_by_name port_by_name_ptr;
  168. jacksym_port_by_id port_by_id_ptr;
  169. jacksym_free free_ptr;
  170. jacksym_midi_get_event_count midi_get_event_count_ptr;
  171. jacksym_midi_event_get midi_event_get_ptr;
  172. jacksym_midi_clear_buffer midi_clear_buffer_ptr;
  173. jacksym_midi_event_write midi_event_write_ptr;
  174. jacksym_midi_event_reserve midi_event_reserve_ptr;
  175. jacksym_release_timebase release_timebase_ptr;
  176. jacksym_set_sync_callback set_sync_callback_ptr;
  177. jacksym_set_sync_timeout set_sync_timeout_ptr;
  178. jacksym_set_timebase_callback set_timebase_callback_ptr;
  179. jacksym_transport_locate transport_locate_ptr;
  180. jacksym_transport_query transport_query_ptr;
  181. jacksym_get_current_transport_frame get_current_transport_frame_ptr;
  182. jacksym_transport_reposition transport_reposition_ptr;
  183. jacksym_transport_start transport_start_ptr;
  184. jacksym_transport_stop transport_stop_ptr;
  185. jacksym_custom_publish_data custom_publish_data_ptr;
  186. jacksym_custom_get_data custom_get_data_ptr;
  187. jacksym_custom_unpublish_data custom_unpublish_data_ptr;
  188. jacksym_custom_set_data_appearance_callback custom_set_data_appearance_callback_ptr;
  189. jacksym_custom_get_keys custom_get_keys_ptr;
  190. JackBridge()
  191. : lib(nullptr),
  192. get_version_ptr(nullptr),
  193. get_version_string_ptr(nullptr),
  194. client_open_ptr(nullptr),
  195. client_rename_ptr(nullptr),
  196. client_close_ptr(nullptr),
  197. client_name_size_ptr(nullptr),
  198. get_client_name_ptr(nullptr),
  199. activate_ptr(nullptr),
  200. deactivate_ptr(nullptr),
  201. get_client_pid_ptr(nullptr),
  202. is_realtime_ptr(nullptr),
  203. set_thread_init_callback_ptr(nullptr),
  204. on_shutdown_ptr(nullptr),
  205. on_info_shutdown_ptr(nullptr),
  206. set_process_callback_ptr(nullptr),
  207. set_freewheel_callback_ptr(nullptr),
  208. set_buffer_size_callback_ptr(nullptr),
  209. set_sample_rate_callback_ptr(nullptr),
  210. set_client_registration_callback_ptr(nullptr),
  211. set_client_rename_callback_ptr(nullptr),
  212. set_port_registration_callback_ptr(nullptr),
  213. set_port_connect_callback_ptr(nullptr),
  214. set_port_rename_callback_ptr(nullptr),
  215. set_xrun_callback_ptr(nullptr),
  216. set_latency_callback_ptr(nullptr),
  217. set_freewheel_ptr(nullptr),
  218. set_buffer_size_ptr(nullptr),
  219. get_sample_rate_ptr(nullptr),
  220. get_buffer_size_ptr(nullptr),
  221. cpu_load_ptr(nullptr),
  222. port_register_ptr(nullptr),
  223. port_unregister_ptr(nullptr),
  224. port_get_buffer_ptr(nullptr),
  225. port_name_ptr(nullptr),
  226. port_short_name_ptr(nullptr),
  227. port_flags_ptr(nullptr),
  228. port_type_ptr(nullptr),
  229. port_is_mine_ptr(nullptr),
  230. port_connected_ptr(nullptr),
  231. port_connected_to_ptr(nullptr),
  232. port_get_connections_ptr(nullptr),
  233. port_get_all_connections_ptr(nullptr),
  234. port_set_name_ptr(nullptr),
  235. port_set_alias_ptr(nullptr),
  236. port_unset_alias_ptr(nullptr),
  237. port_get_aliases_ptr(nullptr),
  238. port_request_monitor_ptr(nullptr),
  239. port_request_monitor_by_name_ptr(nullptr),
  240. port_ensure_monitor_ptr(nullptr),
  241. port_monitoring_input_ptr(nullptr),
  242. connect_ptr(nullptr),
  243. disconnect_ptr(nullptr),
  244. port_disconnect_ptr(nullptr),
  245. port_name_size_ptr(nullptr),
  246. port_type_size_ptr(nullptr),
  247. port_type_get_buffer_size_ptr(nullptr),
  248. port_get_latency_range_ptr(nullptr),
  249. port_set_latency_range_ptr(nullptr),
  250. recompute_total_latencies_ptr(nullptr),
  251. get_ports_ptr(nullptr),
  252. port_by_name_ptr(nullptr),
  253. port_by_id_ptr(nullptr),
  254. free_ptr(nullptr),
  255. midi_get_event_count_ptr(nullptr),
  256. midi_event_get_ptr(nullptr),
  257. midi_clear_buffer_ptr(nullptr),
  258. midi_event_write_ptr(nullptr),
  259. midi_event_reserve_ptr(nullptr),
  260. release_timebase_ptr(nullptr),
  261. set_sync_callback_ptr(nullptr),
  262. set_sync_timeout_ptr(nullptr),
  263. set_timebase_callback_ptr(nullptr),
  264. transport_locate_ptr(nullptr),
  265. transport_query_ptr(nullptr),
  266. get_current_transport_frame_ptr(nullptr),
  267. transport_reposition_ptr(nullptr),
  268. transport_start_ptr(nullptr),
  269. transport_stop_ptr(nullptr),
  270. custom_publish_data_ptr(nullptr),
  271. custom_get_data_ptr(nullptr),
  272. custom_unpublish_data_ptr(nullptr),
  273. custom_set_data_appearance_callback_ptr(nullptr),
  274. custom_get_keys_ptr(nullptr)
  275. {
  276. # if defined(CARLA_OS_MAC)
  277. const char* const filename("libjack.dylib");
  278. # elif defined(CARLA_OS_WIN)
  279. const char* const filename("libjack.dll");
  280. # else
  281. const char* const filename("libjack.so.0");
  282. # endif
  283. lib = lib_open(filename);
  284. if (lib == nullptr)
  285. {
  286. fprintf(stderr, "Failed to load JACK DLL, reason:\n%s\n", lib_error(filename));
  287. return;
  288. }
  289. else
  290. {
  291. fprintf(stdout, "%s loaded sucessfully!\n", filename);
  292. }
  293. #define JOIN(a, b) a ## b
  294. #define LIB_SYMBOL(NAME) JOIN(NAME, _ptr) = (jacksym_##NAME)lib_symbol(lib, "jack_" #NAME);
  295. LIB_SYMBOL(get_version)
  296. LIB_SYMBOL(get_version_string)
  297. LIB_SYMBOL(client_open)
  298. LIB_SYMBOL(client_rename)
  299. LIB_SYMBOL(client_close)
  300. LIB_SYMBOL(client_name_size)
  301. LIB_SYMBOL(get_client_name)
  302. LIB_SYMBOL(activate)
  303. LIB_SYMBOL(deactivate)
  304. LIB_SYMBOL(get_client_pid)
  305. LIB_SYMBOL(is_realtime)
  306. LIB_SYMBOL(set_thread_init_callback)
  307. LIB_SYMBOL(on_shutdown)
  308. LIB_SYMBOL(on_info_shutdown)
  309. LIB_SYMBOL(set_process_callback)
  310. LIB_SYMBOL(set_freewheel_callback)
  311. LIB_SYMBOL(set_buffer_size_callback)
  312. LIB_SYMBOL(set_sample_rate_callback)
  313. LIB_SYMBOL(set_client_registration_callback)
  314. LIB_SYMBOL(set_client_rename_callback)
  315. LIB_SYMBOL(set_port_registration_callback)
  316. LIB_SYMBOL(set_port_connect_callback)
  317. LIB_SYMBOL(set_port_rename_callback)
  318. LIB_SYMBOL(set_xrun_callback)
  319. LIB_SYMBOL(set_latency_callback)
  320. LIB_SYMBOL(set_freewheel)
  321. LIB_SYMBOL(set_buffer_size)
  322. LIB_SYMBOL(get_sample_rate)
  323. LIB_SYMBOL(get_buffer_size)
  324. LIB_SYMBOL(cpu_load)
  325. LIB_SYMBOL(port_register)
  326. LIB_SYMBOL(port_unregister)
  327. LIB_SYMBOL(port_get_buffer)
  328. LIB_SYMBOL(port_name)
  329. LIB_SYMBOL(port_short_name)
  330. LIB_SYMBOL(port_flags)
  331. LIB_SYMBOL(port_type)
  332. LIB_SYMBOL(port_is_mine)
  333. LIB_SYMBOL(port_connected)
  334. LIB_SYMBOL(port_connected_to)
  335. LIB_SYMBOL(port_get_connections)
  336. LIB_SYMBOL(port_get_all_connections)
  337. LIB_SYMBOL(port_set_name)
  338. LIB_SYMBOL(port_set_alias)
  339. LIB_SYMBOL(port_unset_alias)
  340. LIB_SYMBOL(port_get_aliases)
  341. LIB_SYMBOL(port_request_monitor)
  342. LIB_SYMBOL(port_request_monitor_by_name)
  343. LIB_SYMBOL(port_ensure_monitor)
  344. LIB_SYMBOL(port_monitoring_input)
  345. LIB_SYMBOL(connect)
  346. LIB_SYMBOL(disconnect)
  347. LIB_SYMBOL(port_disconnect)
  348. LIB_SYMBOL(port_name_size)
  349. LIB_SYMBOL(port_type_size)
  350. LIB_SYMBOL(port_type_get_buffer_size)
  351. LIB_SYMBOL(port_get_latency_range)
  352. LIB_SYMBOL(port_set_latency_range)
  353. LIB_SYMBOL(recompute_total_latencies)
  354. LIB_SYMBOL(get_ports)
  355. LIB_SYMBOL(port_by_name)
  356. LIB_SYMBOL(port_by_id)
  357. LIB_SYMBOL(free)
  358. LIB_SYMBOL(midi_get_event_count)
  359. LIB_SYMBOL(midi_event_get)
  360. LIB_SYMBOL(midi_clear_buffer)
  361. LIB_SYMBOL(midi_event_write)
  362. LIB_SYMBOL(midi_event_reserve)
  363. LIB_SYMBOL(release_timebase)
  364. LIB_SYMBOL(set_sync_callback)
  365. LIB_SYMBOL(set_sync_timeout)
  366. LIB_SYMBOL(set_timebase_callback)
  367. LIB_SYMBOL(transport_locate)
  368. LIB_SYMBOL(transport_query)
  369. LIB_SYMBOL(get_current_transport_frame)
  370. LIB_SYMBOL(transport_reposition)
  371. LIB_SYMBOL(transport_start)
  372. LIB_SYMBOL(transport_stop)
  373. LIB_SYMBOL(custom_publish_data)
  374. LIB_SYMBOL(custom_get_data)
  375. LIB_SYMBOL(custom_unpublish_data)
  376. LIB_SYMBOL(custom_set_data_appearance_callback)
  377. LIB_SYMBOL(custom_get_keys)
  378. #undef JOIN
  379. #undef LIB_SYMBOL
  380. }
  381. ~JackBridge()
  382. {
  383. if (lib != nullptr)
  384. lib_close(lib);
  385. }
  386. };
  387. static JackBridge bridge;
  388. #endif // ! JACKBRIDGE_DIRECT
  389. // -----------------------------------------------------------------------------
  390. void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr)
  391. {
  392. #if JACKBRIDGE_DUMMY
  393. #elif JACKBRIDGE_DIRECT
  394. return jack_get_version(major_ptr, minor_ptr, micro_ptr, proto_ptr);
  395. #else
  396. if (bridge.get_version_ptr != nullptr)
  397. return bridge.get_version_ptr(major_ptr, minor_ptr, micro_ptr, proto_ptr);
  398. #endif
  399. if (major_ptr != nullptr)
  400. *major_ptr = 0;
  401. if (minor_ptr != nullptr)
  402. *minor_ptr = 0;
  403. if (micro_ptr != nullptr)
  404. *micro_ptr = 0;
  405. if (proto_ptr != nullptr)
  406. *proto_ptr = 0;
  407. }
  408. const char* jackbridge_get_version_string()
  409. {
  410. #if JACKBRIDGE_DUMMY
  411. #elif JACKBRIDGE_DIRECT
  412. return jack_get_version_string();
  413. #else
  414. if (bridge.get_version_string_ptr != nullptr)
  415. return bridge.get_version_string_ptr();
  416. #endif
  417. return nullptr;
  418. }
  419. // -----------------------------------------------------------------------------
  420. jack_client_t* jackbridge_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  421. {
  422. #if JACKBRIDGE_DUMMY
  423. #elif JACKBRIDGE_DIRECT
  424. return jack_client_open(client_name, options, status);
  425. #else
  426. if (bridge.client_open_ptr != nullptr)
  427. return bridge.client_open_ptr(client_name, options, status);
  428. #endif
  429. if (status != nullptr)
  430. *status = JackServerError;
  431. return nullptr;
  432. }
  433. const char* jackbridge_client_rename(jack_client_t* client, const char* new_name)
  434. {
  435. #if JACKBRIDGE_DUMMY
  436. #elif JACKBRIDGE_DIRECT
  437. return jack_client_rename(client, new_name);
  438. #else
  439. if (bridge.client_rename_ptr != nullptr)
  440. return bridge.client_rename_ptr(client, new_name);
  441. #endif
  442. return nullptr;
  443. }
  444. bool jackbridge_client_close(jack_client_t* client)
  445. {
  446. #if JACKBRIDGE_DUMMY
  447. #elif JACKBRIDGE_DIRECT
  448. return (jack_client_close(client) == 0);
  449. #else
  450. if (bridge.client_close_ptr != nullptr)
  451. return (bridge.client_close_ptr(client) == 0);
  452. #endif
  453. return false;
  454. }
  455. // -----------------------------------------------------------------------------
  456. int jackbridge_client_name_size()
  457. {
  458. #if JACKBRIDGE_DUMMY
  459. #elif JACKBRIDGE_DIRECT
  460. return jack_client_name_size();
  461. #else
  462. if (bridge.client_name_size_ptr != nullptr)
  463. return bridge.client_name_size_ptr();
  464. #endif
  465. return 0;
  466. }
  467. char* jackbridge_get_client_name(jack_client_t* client)
  468. {
  469. #if JACKBRIDGE_DUMMY
  470. #elif JACKBRIDGE_DIRECT
  471. return jack_get_client_name(client);
  472. #else
  473. if (bridge.get_client_name_ptr != nullptr)
  474. return bridge.get_client_name_ptr(client);
  475. #endif
  476. return nullptr;
  477. }
  478. // -----------------------------------------------------------------------------
  479. bool jackbridge_activate(jack_client_t* client)
  480. {
  481. #if JACKBRIDGE_DUMMY
  482. #elif JACKBRIDGE_DIRECT
  483. return (jack_activate(client) == 0);
  484. #else
  485. if (bridge.activate_ptr != nullptr)
  486. return (bridge.activate_ptr(client) == 0);
  487. #endif
  488. return false;
  489. }
  490. bool jackbridge_deactivate(jack_client_t* client)
  491. {
  492. #if JACKBRIDGE_DUMMY
  493. #elif JACKBRIDGE_DIRECT
  494. return (jack_deactivate(client) == 0);
  495. #else
  496. if (bridge.deactivate_ptr != nullptr)
  497. return (bridge.deactivate_ptr(client) == 0);
  498. #endif
  499. return false;
  500. }
  501. // -----------------------------------------------------------------------------
  502. int jackbridge_get_client_pid(const char* name)
  503. {
  504. #if JACKBRIDGE_DUMMY
  505. #elif JACKBRIDGE_DIRECT
  506. return jack_get_client_pid(name);
  507. #else
  508. if (bridge.get_client_pid_ptr != nullptr)
  509. return bridge.get_client_pid_ptr(name);
  510. #endif
  511. return 0;
  512. }
  513. bool jackbridge_is_realtime(jack_client_t* client)
  514. {
  515. #if JACKBRIDGE_DUMMY
  516. #elif JACKBRIDGE_DIRECT
  517. return jack_is_realtime(client);
  518. #else
  519. if (bridge.is_realtime_ptr != nullptr)
  520. return bridge.is_realtime_ptr(client);
  521. #endif
  522. return false;
  523. }
  524. // -----------------------------------------------------------------------------
  525. bool jackbridge_set_thread_init_callback(jack_client_t* client, JackThreadInitCallback thread_init_callback, void* arg)
  526. {
  527. #if JACKBRIDGE_DUMMY
  528. #elif JACKBRIDGE_DIRECT
  529. return (jack_set_thread_init_callback(client, thread_init_callback, arg) == 0);
  530. #else
  531. if (bridge.set_thread_init_callback_ptr != nullptr)
  532. return (bridge.set_thread_init_callback_ptr(client, thread_init_callback, arg) == 0);
  533. #endif
  534. return false;
  535. }
  536. void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg)
  537. {
  538. #if JACKBRIDGE_DUMMY
  539. #elif JACKBRIDGE_DIRECT
  540. jack_on_shutdown(client, shutdown_callback, arg);
  541. #else
  542. if (bridge.on_shutdown_ptr != nullptr)
  543. bridge.on_shutdown_ptr(client, shutdown_callback, arg);
  544. #endif
  545. }
  546. void jackbridge_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg)
  547. {
  548. #if JACKBRIDGE_DUMMY
  549. #elif JACKBRIDGE_DIRECT
  550. jack_on_info_shutdown(client, shutdown_callback, arg);
  551. #else
  552. if (bridge.on_info_shutdown_ptr != nullptr)
  553. bridge.on_info_shutdown_ptr(client, shutdown_callback, arg);
  554. #endif
  555. }
  556. bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg)
  557. {
  558. #if JACKBRIDGE_DUMMY
  559. #elif JACKBRIDGE_DIRECT
  560. return (jack_set_process_callback(client, process_callback, arg) == 0);
  561. #else
  562. if (bridge.set_process_callback_ptr != nullptr)
  563. return (bridge.set_process_callback_ptr(client, process_callback, arg) == 0);
  564. #endif
  565. return false;
  566. }
  567. bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg)
  568. {
  569. #if JACKBRIDGE_DUMMY
  570. #elif JACKBRIDGE_DIRECT
  571. return (jack_set_freewheel_callback(client, freewheel_callback, arg) == 0);
  572. #else
  573. if (bridge.set_freewheel_callback_ptr != nullptr)
  574. return (bridge.set_freewheel_callback_ptr(client, freewheel_callback, arg) == 0);
  575. #endif
  576. return false;
  577. }
  578. bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg)
  579. {
  580. #if JACKBRIDGE_DUMMY
  581. #elif JACKBRIDGE_DIRECT
  582. return (jack_set_buffer_size_callback(client, bufsize_callback, arg) == 0);
  583. #else
  584. if (bridge.set_buffer_size_callback_ptr != nullptr)
  585. return (bridge.set_buffer_size_callback_ptr(client, bufsize_callback, arg) == 0);
  586. #endif
  587. return false;
  588. }
  589. bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg)
  590. {
  591. #if JACKBRIDGE_DUMMY
  592. #elif JACKBRIDGE_DIRECT
  593. return (jack_set_sample_rate_callback(client, srate_callback, arg) == 0);
  594. #else
  595. if (bridge.set_sample_rate_callback_ptr != nullptr)
  596. return (bridge.set_sample_rate_callback_ptr(client, srate_callback, arg) == 0);
  597. #endif
  598. return false;
  599. }
  600. bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg)
  601. {
  602. #if JACKBRIDGE_DUMMY
  603. #elif JACKBRIDGE_DIRECT
  604. return (jack_set_client_registration_callback(client, registration_callback, arg) == 0);
  605. #else
  606. if (bridge.set_client_registration_callback_ptr != nullptr)
  607. return (bridge.set_client_registration_callback_ptr(client, registration_callback, arg) == 0);
  608. #endif
  609. return false;
  610. }
  611. bool jackbridge_set_client_rename_callback(jack_client_t* client, JackClientRenameCallback rename_callback, void* arg)
  612. {
  613. #if JACKBRIDGE_DUMMY
  614. #elif JACKBRIDGE_DIRECT
  615. return (jack_set_client_rename_callback(client, registration_callback, arg) == 0);
  616. #else
  617. if (bridge.set_client_rename_callback_ptr != nullptr)
  618. return (bridge.set_client_rename_callback_ptr(client, rename_callback, arg) == 0);
  619. #endif
  620. return false;
  621. }
  622. bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void *arg)
  623. {
  624. #if JACKBRIDGE_DUMMY
  625. #elif JACKBRIDGE_DIRECT
  626. return (jack_set_port_registration_callback(client, registration_callback, arg) == 0);
  627. #else
  628. if (bridge.set_port_registration_callback_ptr != nullptr)
  629. return (bridge.set_port_registration_callback_ptr(client, registration_callback, arg) == 0);
  630. #endif
  631. return false;
  632. }
  633. bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg)
  634. {
  635. #if JACKBRIDGE_DUMMY
  636. #elif JACKBRIDGE_DIRECT
  637. return (jack_set_port_connect_callback(client, connect_callback, arg) == 0);
  638. #else
  639. if (bridge.set_port_connect_callback_ptr != nullptr)
  640. return (bridge.set_port_connect_callback_ptr(client, connect_callback, arg) == 0);
  641. #endif
  642. return false;
  643. }
  644. bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg)
  645. {
  646. #if JACKBRIDGE_DUMMY
  647. #elif JACKBRIDGE_DIRECT
  648. return (jack_set_port_rename_callback(client, rename_callback, arg) == 0);
  649. #else
  650. if (bridge.set_port_rename_callback_ptr != nullptr)
  651. return (bridge.set_port_rename_callback_ptr(client, rename_callback, arg) == 0);
  652. #endif
  653. return false;
  654. }
  655. bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg)
  656. {
  657. #if JACKBRIDGE_DUMMY
  658. #elif JACKBRIDGE_DIRECT
  659. return (jack_set_xrun_callback(client, xrun_callback, arg) == 0);
  660. #else
  661. if (bridge.set_xrun_callback_ptr != nullptr)
  662. return (bridge.set_xrun_callback_ptr(client, xrun_callback, arg) == 0);
  663. #endif
  664. return false;
  665. }
  666. bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg)
  667. {
  668. #if JACKBRIDGE_DUMMY
  669. #elif JACKBRIDGE_DIRECT
  670. return (jack_set_latency_callback(client, latency_callback, arg) == 0);
  671. #else
  672. if (bridge.set_latency_callback_ptr != nullptr)
  673. return (bridge.set_latency_callback_ptr(client, latency_callback, arg) == 0);
  674. #endif
  675. return false;
  676. }
  677. // -----------------------------------------------------------------------------
  678. bool jackbridge_set_freewheel(jack_client_t* client, bool onoff)
  679. {
  680. #if JACKBRIDGE_DUMMY
  681. #elif JACKBRIDGE_DIRECT
  682. return jack_set_freewheel(client, onoff);
  683. #else
  684. if (bridge.set_freewheel_ptr != nullptr)
  685. return bridge.set_freewheel_ptr(client, onoff);
  686. #endif
  687. return false;
  688. }
  689. bool jackbridge_set_buffer_size(jack_client_t* client, jack_nframes_t nframes)
  690. {
  691. #if JACKBRIDGE_DUMMY
  692. #elif JACKBRIDGE_DIRECT
  693. return jack_set_buffer_size(client, nframes);
  694. #else
  695. if (bridge.set_buffer_size_ptr != nullptr)
  696. return bridge.set_buffer_size_ptr(client, nframes);
  697. #endif
  698. return false;
  699. }
  700. // -----------------------------------------------------------------------------
  701. jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client)
  702. {
  703. #if JACKBRIDGE_DUMMY
  704. #elif JACKBRIDGE_DIRECT
  705. return jack_get_sample_rate(client);
  706. #else
  707. if (bridge.get_sample_rate_ptr != nullptr)
  708. return bridge.get_sample_rate_ptr(client);
  709. #endif
  710. return 0;
  711. }
  712. jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client)
  713. {
  714. #if JACKBRIDGE_DUMMY
  715. #elif JACKBRIDGE_DIRECT
  716. return jack_get_buffer_size(client);
  717. #else
  718. if (bridge.get_buffer_size_ptr != nullptr)
  719. return bridge.get_buffer_size_ptr(client);
  720. #endif
  721. return 0;
  722. }
  723. float jackbridge_cpu_load(jack_client_t* client)
  724. {
  725. #if JACKBRIDGE_DUMMY
  726. #elif JACKBRIDGE_DIRECT
  727. return jack_cpu_load(client);
  728. #else
  729. if (bridge.cpu_load_ptr != nullptr)
  730. return bridge.cpu_load_ptr(client);
  731. #endif
  732. return 0.0f;
  733. }
  734. // -----------------------------------------------------------------------------
  735. jack_port_t* jackbridge_port_register(jack_client_t* client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
  736. {
  737. #if JACKBRIDGE_DUMMY
  738. #elif JACKBRIDGE_DIRECT
  739. return jack_port_register(client, port_name, port_type, flags, buffer_size);
  740. #else
  741. if (bridge.port_register_ptr != nullptr)
  742. return bridge.port_register_ptr(client, port_name, port_type, flags, buffer_size);
  743. #endif
  744. return nullptr;
  745. }
  746. bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port)
  747. {
  748. #if JACKBRIDGE_DUMMY
  749. #elif JACKBRIDGE_DIRECT
  750. return (jack_port_unregister(client, port) == 0);
  751. #else
  752. if (bridge.port_unregister_ptr != nullptr)
  753. return (bridge.port_unregister_ptr(client, port) == 0);
  754. #endif
  755. return false;
  756. }
  757. void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes)
  758. {
  759. #if JACKBRIDGE_DUMMY
  760. #elif JACKBRIDGE_DIRECT
  761. return jack_port_get_buffer(port, nframes);
  762. #else
  763. if (bridge.port_get_buffer_ptr != nullptr)
  764. return bridge.port_get_buffer_ptr(port, nframes);
  765. #endif
  766. return nullptr;
  767. }
  768. // -----------------------------------------------------------------------------
  769. const char* jackbridge_port_name(const jack_port_t* port)
  770. {
  771. #if JACKBRIDGE_DUMMY
  772. #elif JACKBRIDGE_DIRECT
  773. return jack_port_name(port);
  774. #else
  775. if (bridge.port_name_ptr != nullptr)
  776. return bridge.port_name_ptr(port);
  777. #endif
  778. return nullptr;
  779. }
  780. const char* jackbridge_port_short_name(const jack_port_t* port)
  781. {
  782. #if JACKBRIDGE_DUMMY
  783. #elif JACKBRIDGE_DIRECT
  784. return jack_port_short_name(port);
  785. #else
  786. if (bridge.port_short_name_ptr != nullptr)
  787. return bridge.port_short_name_ptr(port);
  788. #endif
  789. return nullptr;
  790. }
  791. int jackbridge_port_flags(const jack_port_t* port)
  792. {
  793. #if JACKBRIDGE_DUMMY
  794. #elif JACKBRIDGE_DIRECT
  795. return jack_port_flags(port);
  796. #else
  797. if (bridge.port_flags_ptr != nullptr)
  798. return bridge.port_flags_ptr(port);
  799. #endif
  800. return 0x0;
  801. }
  802. const char* jackbridge_port_type(const jack_port_t* port)
  803. {
  804. #if JACKBRIDGE_DUMMY
  805. #elif JACKBRIDGE_DIRECT
  806. return jack_port_type(port);
  807. #else
  808. if (bridge.port_type_ptr != nullptr)
  809. return bridge.port_type_ptr(port);
  810. #endif
  811. return nullptr;
  812. }
  813. bool jackbridge_port_is_mine(const jack_client_t* client, const jack_port_t* port)
  814. {
  815. #if JACKBRIDGE_DUMMY
  816. #elif JACKBRIDGE_DIRECT
  817. return jack_port_is_mine(client, port);
  818. #else
  819. if (bridge.port_is_mine_ptr != nullptr)
  820. return bridge.port_is_mine_ptr(client, port);
  821. #endif
  822. return false;
  823. }
  824. bool jackbridge_port_connected(const jack_port_t* port)
  825. {
  826. #if JACKBRIDGE_DUMMY
  827. #elif JACKBRIDGE_DIRECT
  828. return jack_port_connected(port);
  829. #else
  830. if (bridge.port_connected_ptr != nullptr)
  831. return bridge.port_connected_ptr(port);
  832. #endif
  833. return false;
  834. }
  835. bool jackbridge_port_connected_to(const jack_port_t* port, const char* port_name)
  836. {
  837. #if JACKBRIDGE_DUMMY
  838. #elif JACKBRIDGE_DIRECT
  839. return jack_port_connected_to(port, port_name);
  840. #else
  841. if (bridge.port_connected_to_ptr != nullptr)
  842. return bridge.port_connected_to_ptr(port, port_name);
  843. #endif
  844. return false;
  845. }
  846. const char** jackbridge_port_get_connections(const jack_port_t* port)
  847. {
  848. #if JACKBRIDGE_DUMMY
  849. #elif JACKBRIDGE_DIRECT
  850. return jack_port_get_connections(port);
  851. #else
  852. if (bridge.port_get_connections_ptr != nullptr)
  853. return bridge.port_get_connections_ptr(port);
  854. #endif
  855. return nullptr;
  856. }
  857. const char** jackbridge_port_get_all_connections(const jack_client_t* client, const jack_port_t* port)
  858. {
  859. #if JACKBRIDGE_DUMMY
  860. #elif JACKBRIDGE_DIRECT
  861. return jack_port_get_all_connections(client, port);
  862. #else
  863. if (bridge.port_get_all_connections_ptr != nullptr)
  864. return bridge.port_get_all_connections_ptr(client, port);
  865. #endif
  866. return nullptr;
  867. }
  868. // -----------------------------------------------------------------------------
  869. bool jackbridge_port_set_name(jack_port_t* port, const char* port_name)
  870. {
  871. #if JACKBRIDGE_DUMMY
  872. #elif JACKBRIDGE_DIRECT
  873. return (jack_port_set_name(port, port_name) == 0);
  874. #else
  875. if (bridge.port_set_name_ptr != nullptr)
  876. return (bridge.port_set_name_ptr(port, port_name) == 0);
  877. #endif
  878. return false;
  879. }
  880. bool jackbridge_port_set_alias(jack_port_t* port, const char* alias)
  881. {
  882. #if JACKBRIDGE_DUMMY
  883. #elif JACKBRIDGE_DIRECT
  884. return (jack_port_set_alias(port, alias) == 0);
  885. #else
  886. if (bridge.port_set_alias_ptr != nullptr)
  887. return (bridge.port_set_alias_ptr(port, alias) == 0);
  888. #endif
  889. return false;
  890. }
  891. bool jackbridge_port_unset_alias(jack_port_t* port, const char* alias)
  892. {
  893. #if JACKBRIDGE_DUMMY
  894. #elif JACKBRIDGE_DIRECT
  895. return (jack_port_unset_alias(port, alias) == 0);
  896. #else
  897. if (bridge.port_unset_alias_ptr != nullptr)
  898. return (bridge.port_unset_alias_ptr(port, alias) == 0);
  899. #endif
  900. return false;
  901. }
  902. int jackbridge_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  903. {
  904. #if JACKBRIDGE_DUMMY
  905. #elif JACKBRIDGE_DIRECT
  906. return (jack_port_get_aliases(port, aliases) == 0);
  907. #else
  908. if (bridge.port_get_aliases_ptr != nullptr)
  909. return (bridge.port_get_aliases_ptr(port, aliases) == 0);
  910. #endif
  911. return 0;
  912. }
  913. // -----------------------------------------------------------------------------
  914. bool jackbridge_port_request_monitor(jack_port_t* port, bool onoff)
  915. {
  916. #if JACKBRIDGE_DUMMY
  917. #elif JACKBRIDGE_DIRECT
  918. return (jack_port_request_monitor(port, onoff) == 0);
  919. #else
  920. if (bridge.port_request_monitor_ptr != nullptr)
  921. return (bridge.port_request_monitor_ptr(port, onoff) == 0);
  922. #endif
  923. return false;
  924. }
  925. bool jackbridge_port_request_monitor_by_name(jack_client_t* client, const char* port_name, bool onoff)
  926. {
  927. #if JACKBRIDGE_DUMMY
  928. #elif JACKBRIDGE_DIRECT
  929. return (jack_port_request_monitor_by_name(client, port_name, onoff) == 0);
  930. #else
  931. if (bridge.port_request_monitor_by_name_ptr != nullptr)
  932. return (bridge.port_request_monitor_by_name_ptr(client, port_name, onoff) == 0);
  933. #endif
  934. return false;
  935. }
  936. bool jackbridge_port_ensure_monitor(jack_port_t* port, bool onoff)
  937. {
  938. #if JACKBRIDGE_DUMMY
  939. #elif JACKBRIDGE_DIRECT
  940. return (jack_port_ensure_monitor(port, onoff) == 0);
  941. #else
  942. if (bridge.port_ensure_monitor_ptr != nullptr)
  943. return (bridge.port_ensure_monitor_ptr(port, onoff) == 0);
  944. #endif
  945. return false;
  946. }
  947. bool jackbridge_port_monitoring_input(jack_port_t* port)
  948. {
  949. #if JACKBRIDGE_DUMMY
  950. #elif JACKBRIDGE_DIRECT
  951. return jack_port_monitoring_input(port);
  952. #else
  953. if (bridge.port_monitoring_input_ptr != nullptr)
  954. return bridge.port_monitoring_input_ptr(port);
  955. #endif
  956. return false;
  957. }
  958. // -----------------------------------------------------------------------------
  959. bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port)
  960. {
  961. #if JACKBRIDGE_DUMMY
  962. #elif JACKBRIDGE_DIRECT
  963. return (jack_connect(client, source_port, destination_port) == 0);
  964. #else
  965. if (bridge.connect_ptr != nullptr)
  966. return (bridge.connect_ptr(client, source_port, destination_port) == 0);
  967. #endif
  968. return false;
  969. }
  970. bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port)
  971. {
  972. #if JACKBRIDGE_DUMMY
  973. #elif JACKBRIDGE_DIRECT
  974. return (jack_disconnect(client, source_port, destination_port) == 0);
  975. #else
  976. if (bridge.disconnect_ptr != nullptr)
  977. return (bridge.disconnect_ptr(client, source_port, destination_port) == 0);
  978. #endif
  979. return false;
  980. }
  981. bool jackbridge_port_disconnect(jack_client_t* client, jack_port_t* port)
  982. {
  983. #if JACKBRIDGE_DUMMY
  984. #elif JACKBRIDGE_DIRECT
  985. return (jack_port_disconnect(client, port) == 0);
  986. #else
  987. if (bridge.port_disconnect_ptr != nullptr)
  988. return (bridge.port_disconnect_ptr(client, port) == 0);
  989. #endif
  990. return false;
  991. }
  992. // -----------------------------------------------------------------------------
  993. int jackbridge_port_name_size()
  994. {
  995. #if JACKBRIDGE_DUMMY
  996. #elif JACKBRIDGE_DIRECT
  997. return jack_port_name_size();
  998. #else
  999. if (bridge.port_name_size_ptr != nullptr)
  1000. return bridge.port_name_size_ptr();
  1001. #endif
  1002. return 0;
  1003. }
  1004. int jackbridge_port_type_size()
  1005. {
  1006. #if JACKBRIDGE_DUMMY
  1007. #elif JACKBRIDGE_DIRECT
  1008. return jack_port_type_size();
  1009. #else
  1010. if (bridge.port_type_size_ptr != nullptr)
  1011. return bridge.port_type_size_ptr();
  1012. #endif
  1013. return 0;
  1014. }
  1015. size_t jackbridge_port_type_get_buffer_size(jack_client_t* client, const char* port_type)
  1016. {
  1017. #if JACKBRIDGE_DUMMY
  1018. #elif JACKBRIDGE_DIRECT
  1019. return jack_port_type_get_buffer_size(client, port_type);
  1020. #else
  1021. if (bridge.port_type_get_buffer_size_ptr != nullptr)
  1022. return bridge.port_type_get_buffer_size_ptr(client, port_type);
  1023. #endif
  1024. return 0;
  1025. }
  1026. // -----------------------------------------------------------------------------
  1027. void jackbridge_port_get_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  1028. {
  1029. #if JACKBRIDGE_DUMMY
  1030. #elif JACKBRIDGE_DIRECT
  1031. jack_port_get_latency_range(port, mode, range);
  1032. #else
  1033. if (bridge.port_get_latency_range_ptr != nullptr)
  1034. bridge.port_get_latency_range_ptr(port, mode, range);
  1035. #endif
  1036. }
  1037. void jackbridge_port_set_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  1038. {
  1039. #if JACKBRIDGE_DUMMY
  1040. #elif JACKBRIDGE_DIRECT
  1041. jack_port_set_latency_range(port, mode, range);
  1042. #else
  1043. if (bridge.port_set_latency_range_ptr != nullptr)
  1044. bridge.port_set_latency_range_ptr(port, mode, range);
  1045. #endif
  1046. }
  1047. bool jackbridge_recompute_total_latencies(jack_client_t* client)
  1048. {
  1049. #if JACKBRIDGE_DUMMY
  1050. #elif JACKBRIDGE_DIRECT
  1051. return (jack_recompute_total_latencies(client) == 0);
  1052. #else
  1053. if (bridge.recompute_total_latencies_ptr != nullptr)
  1054. return (bridge.recompute_total_latencies_ptr(client) == 0);
  1055. #endif
  1056. return false;
  1057. }
  1058. // -----------------------------------------------------------------------------
  1059. const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  1060. {
  1061. #if JACKBRIDGE_DUMMY
  1062. #elif JACKBRIDGE_DIRECT
  1063. return jack_get_ports(client, port_name_pattern, type_name_pattern, flags);
  1064. #else
  1065. if (bridge.get_ports_ptr != nullptr)
  1066. return bridge.get_ports_ptr(client, port_name_pattern, type_name_pattern, flags);
  1067. #endif
  1068. return nullptr;
  1069. }
  1070. jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name)
  1071. {
  1072. #if JACKBRIDGE_DUMMY
  1073. #elif JACKBRIDGE_DIRECT
  1074. return jack_port_by_name(client, port_name);
  1075. #else
  1076. if (bridge.port_by_name_ptr != nullptr)
  1077. return bridge.port_by_name_ptr(client, port_name);
  1078. #endif
  1079. return nullptr;
  1080. }
  1081. jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id)
  1082. {
  1083. #if JACKBRIDGE_DUMMY
  1084. #elif JACKBRIDGE_DIRECT
  1085. return jack_port_by_id(client, port_id);
  1086. #else
  1087. if (bridge.port_by_id_ptr != nullptr)
  1088. return bridge.port_by_id_ptr(client, port_id);
  1089. #endif
  1090. return nullptr;
  1091. }
  1092. // -----------------------------------------------------------------------------
  1093. void jackbridge_free(void* ptr)
  1094. {
  1095. #if JACKBRIDGE_DUMMY
  1096. #elif JACKBRIDGE_DIRECT
  1097. return jack_free(ptr);
  1098. #else
  1099. if (bridge.free_ptr != nullptr)
  1100. return bridge.free_ptr(ptr);
  1101. // just in case
  1102. std::free(ptr);
  1103. #endif
  1104. }
  1105. // -----------------------------------------------------------------------------
  1106. uint32_t jackbridge_midi_get_event_count(void* port_buffer)
  1107. {
  1108. #if JACKBRIDGE_DUMMY
  1109. #elif JACKBRIDGE_DIRECT
  1110. return jack_midi_get_event_count(port_buffer);
  1111. #else
  1112. if (bridge.midi_get_event_count_ptr != nullptr)
  1113. return bridge.midi_get_event_count_ptr(port_buffer);
  1114. #endif
  1115. return 0;
  1116. }
  1117. bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index)
  1118. {
  1119. #if JACKBRIDGE_DUMMY
  1120. #elif JACKBRIDGE_DIRECT
  1121. return (jack_midi_event_get(event, port_buffer, event_index) == 0);
  1122. #else
  1123. if (bridge.midi_event_get_ptr != nullptr)
  1124. return (bridge.midi_event_get_ptr(event, port_buffer, event_index) == 0);
  1125. #endif
  1126. return false;
  1127. }
  1128. void jackbridge_midi_clear_buffer(void* port_buffer)
  1129. {
  1130. #if JACKBRIDGE_DUMMY
  1131. #elif JACKBRIDGE_DIRECT
  1132. jack_midi_clear_buffer(port_buffer);
  1133. #else
  1134. if (bridge.midi_clear_buffer_ptr != nullptr)
  1135. bridge.midi_clear_buffer_ptr(port_buffer);
  1136. #endif
  1137. }
  1138. bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, size_t data_size)
  1139. {
  1140. #if JACKBRIDGE_DUMMY
  1141. #elif JACKBRIDGE_DIRECT
  1142. return (jack_midi_event_write(port_buffer, time, data, data_size) == 0);
  1143. #else
  1144. if (bridge.midi_event_write_ptr != nullptr)
  1145. return (bridge.midi_event_write_ptr(port_buffer, time, data, data_size) == 0);
  1146. #endif
  1147. return false;
  1148. }
  1149. jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size)
  1150. {
  1151. #if JACKBRIDGE_DUMMY
  1152. #elif JACKBRIDGE_DIRECT
  1153. return jack_midi_event_reserve(port_buffer, time, data_size);
  1154. #else
  1155. if (bridge.midi_event_reserve_ptr != nullptr)
  1156. return bridge.midi_event_reserve_ptr(port_buffer, time, data_size);
  1157. #endif
  1158. return nullptr;
  1159. }
  1160. // -----------------------------------------------------------------------------
  1161. bool jackbridge_release_timebase(jack_client_t* client)
  1162. {
  1163. #if JACKBRIDGE_DUMMY
  1164. #elif JACKBRIDGE_DIRECT
  1165. return (jack_release_timebase(client) == 0);
  1166. #else
  1167. if (bridge.release_timebase_ptr != nullptr)
  1168. return (bridge.release_timebase_ptr(client) == 0);
  1169. #endif
  1170. return false;
  1171. }
  1172. bool jackbridge_set_sync_callback(jack_client_t* client, JackSyncCallback sync_callback, void* arg)
  1173. {
  1174. #if JACKBRIDGE_DUMMY
  1175. #elif JACKBRIDGE_DIRECT
  1176. return (jack_set_sync_callback(client, sync_callback, arg) == 0);
  1177. #else
  1178. if (bridge.set_sync_callback_ptr != nullptr)
  1179. return (bridge.set_sync_callback_ptr(client, sync_callback, arg) == 0);
  1180. #endif
  1181. return false;
  1182. }
  1183. bool jackbridge_set_sync_timeout(jack_client_t* client, jack_time_t timeout)
  1184. {
  1185. #if JACKBRIDGE_DUMMY
  1186. #elif JACKBRIDGE_DIRECT
  1187. return (jack_set_sync_timeout(client, timeout) == 0);
  1188. #else
  1189. if (bridge.set_sync_timeout_ptr != nullptr)
  1190. return (bridge.set_sync_timeout_ptr(client, timeout) == 0);
  1191. #endif
  1192. return false;
  1193. }
  1194. bool jackbridge_set_timebase_callback(jack_client_t* client, bool conditional, JackTimebaseCallback timebase_callback, void* arg)
  1195. {
  1196. #if JACKBRIDGE_DUMMY
  1197. #elif JACKBRIDGE_DIRECT
  1198. return (jack_set_timebase_callback(client, conditional, timebase_callback, arg) == 0);
  1199. #else
  1200. if (bridge.set_timebase_callback_ptr != nullptr)
  1201. return (bridge.set_timebase_callback_ptr(client, conditional, timebase_callback, arg) == 0);
  1202. #endif
  1203. return false;
  1204. }
  1205. bool jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame)
  1206. {
  1207. #if JACKBRIDGE_DUMMY
  1208. #elif JACKBRIDGE_DIRECT
  1209. return (jack_transport_locate(client, frame) == 0);
  1210. #else
  1211. if (bridge.transport_locate_ptr != nullptr)
  1212. return (bridge.transport_locate_ptr(client, frame) == 0);
  1213. #endif
  1214. return false;
  1215. }
  1216. jack_transport_state_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos)
  1217. {
  1218. #if JACKBRIDGE_DUMMY
  1219. #elif JACKBRIDGE_DIRECT
  1220. return jack_transport_query(client, pos);
  1221. #else
  1222. if (bridge.transport_query_ptr != nullptr)
  1223. return bridge.transport_query_ptr(client, pos);
  1224. #endif
  1225. if (pos != nullptr)
  1226. {
  1227. // invalidate
  1228. pos->unique_1 = 0;
  1229. pos->unique_2 = 1;
  1230. }
  1231. return JackTransportStopped;
  1232. }
  1233. jack_nframes_t jackbridge_get_current_transport_frame(const jack_client_t* client)
  1234. {
  1235. #if JACKBRIDGE_DUMMY
  1236. #elif JACKBRIDGE_DIRECT
  1237. return jack_get_current_transport_frame(client);
  1238. #else
  1239. if (bridge.get_current_transport_frame_ptr != nullptr)
  1240. return bridge.get_current_transport_frame_ptr(client);
  1241. #endif
  1242. return 0;
  1243. }
  1244. bool jackbridge_transport_reposition(jack_client_t* client, const jack_position_t* pos)
  1245. {
  1246. #if JACKBRIDGE_DUMMY
  1247. #elif JACKBRIDGE_DIRECT
  1248. return (jack_transport_reposition(client, pos) == 0);
  1249. #else
  1250. if (bridge.transport_reposition_ptr != nullptr)
  1251. return (bridge.transport_reposition_ptr(client, pos) == 0);
  1252. #endif
  1253. return false;
  1254. }
  1255. void jackbridge_transport_start(jack_client_t* client)
  1256. {
  1257. #if JACKBRIDGE_DUMMY
  1258. #elif JACKBRIDGE_DIRECT
  1259. jack_transport_start(client);
  1260. #else
  1261. if (bridge.transport_start_ptr != nullptr)
  1262. bridge.transport_start_ptr(client);
  1263. #endif
  1264. }
  1265. void jackbridge_transport_stop(jack_client_t* client)
  1266. {
  1267. #if JACKBRIDGE_DUMMY
  1268. #elif JACKBRIDGE_DIRECT
  1269. jack_transport_stop(client);
  1270. #else
  1271. if (bridge.transport_stop_ptr != nullptr)
  1272. bridge.transport_stop_ptr(client);
  1273. #endif
  1274. }
  1275. // -----------------------------------------------------------------------------
  1276. bool jackbridge_custom_publish_data(jack_client_t* client, const char* key, const void* data, size_t size)
  1277. {
  1278. #if JACKBRIDGE_DUMMY
  1279. #elif JACKBRIDGE_DIRECT
  1280. return (jack_custom_publish_data(client, key, data, size) == 0);
  1281. #else
  1282. if (bridge.custom_publish_data_ptr != nullptr)
  1283. return (bridge.custom_publish_data_ptr(client, key, data, size) == 0);
  1284. #endif
  1285. return false;
  1286. }
  1287. bool jackbridge_custom_get_data(jack_client_t* client, const char* client_name, const char* key, void** data, size_t* size)
  1288. {
  1289. #if JACKBRIDGE_DUMMY
  1290. #elif JACKBRIDGE_DIRECT
  1291. return (jack_custom_get_data(client, client_name, key, data, size) == 0);
  1292. #else
  1293. if (bridge.custom_get_data_ptr != nullptr)
  1294. return (bridge.custom_get_data_ptr(client, client_name, key, data, size) == 0);
  1295. #endif
  1296. return false;
  1297. }
  1298. bool jackbridge_custom_unpublish_data(jack_client_t* client, const char* key)
  1299. {
  1300. #if JACKBRIDGE_DUMMY
  1301. #elif JACKBRIDGE_DIRECT
  1302. return (jack_custom_unpublish_data(client, key) == 0);
  1303. #else
  1304. if (bridge.custom_unpublish_data_ptr != nullptr)
  1305. return (bridge.custom_unpublish_data_ptr(client, key) == 0);
  1306. #endif
  1307. return false;
  1308. }
  1309. bool jackbridge_custom_set_data_appearance_callback(jack_client_t* client, JackCustomDataAppearanceCallback callback, void* arg)
  1310. {
  1311. #if JACKBRIDGE_DUMMY
  1312. #elif JACKBRIDGE_DIRECT
  1313. return (jack_custom_set_data_appearance_callback(client, callback, arg) == 0);
  1314. #else
  1315. if (bridge.custom_set_data_appearance_callback_ptr != nullptr)
  1316. return (bridge.custom_set_data_appearance_callback_ptr(client, callback, arg) == 0);
  1317. #endif
  1318. return false;
  1319. }
  1320. const char** jackbridge_custom_get_keys(jack_client_t* client, const char* client_name)
  1321. {
  1322. #if JACKBRIDGE_DUMMY
  1323. #elif JACKBRIDGE_DIRECT
  1324. return jack_custom_get_keys(client, client_name);
  1325. #else
  1326. if (bridge.custom_get_keys_ptr != nullptr)
  1327. return bridge.custom_get_keys_ptr(client, client_name);
  1328. #endif
  1329. return nullptr;
  1330. }
  1331. // -----------------------------------------------------------------------------