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.

2065 lines
72KB

  1. /*
  2. * JackBridge (Part 1, JACK functions)
  3. * Copyright (C) 2013-2015 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. #ifdef __WINE__
  19. # include <windows.h>
  20. # include <pthread.h>
  21. #endif
  22. #if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  23. # define JACKSYM_API __cdecl
  24. #else
  25. # define JACKSYM_API
  26. #endif
  27. #include <cerrno>
  28. #include "CarlaLibUtils.hpp"
  29. // -----------------------------------------------------------------------------
  30. extern "C" {
  31. typedef void (JACKSYM_API *JackSymLatencyCallback)(jack_latency_callback_mode_t, void*);
  32. typedef int (JACKSYM_API *JackSymProcessCallback)(jack_nframes_t, void*);
  33. typedef void (JACKSYM_API *JackSymThreadInitCallback)(void*);
  34. typedef int (JACKSYM_API *JackSymGraphOrderCallback)(void*);
  35. typedef int (JACKSYM_API *JackSymXRunCallback)(void*);
  36. typedef int (JACKSYM_API *JackSymBufferSizeCallback)(jack_nframes_t, void*);
  37. typedef int (JACKSYM_API *JackSymSampleRateCallback)(jack_nframes_t, void*);
  38. typedef void (JACKSYM_API *JackSymPortRegistrationCallback)(jack_port_id_t, int, void*);
  39. typedef void (JACKSYM_API *JackSymClientRegistrationCallback)(const char*, int, void*);
  40. typedef void (JACKSYM_API *JackSymPortConnectCallback)(jack_port_id_t, jack_port_id_t, int, void*);
  41. typedef void (JACKSYM_API *JackSymPortRenameCallback)(jack_port_id_t, const char*, const char*, void*);
  42. typedef void (JACKSYM_API *JackSymFreewheelCallback)(int, void*);
  43. typedef void (JACKSYM_API *JackSymShutdownCallback)(void*);
  44. typedef void (JACKSYM_API *JackSymInfoShutdownCallback)(jack_status_t, const char*, void*);
  45. typedef int (JACKSYM_API *JackSymSyncCallback)(jack_transport_state_t, jack_position_t*, void*);
  46. typedef void (JACKSYM_API *JackSymTimebaseCallback)(jack_transport_state_t, jack_nframes_t, jack_position_t*, int, void*);
  47. typedef void (JACKSYM_API *JackSymSessionCallback)(jack_session_event_t*, void*);
  48. typedef void (JACKSYM_API *JackSymPropertyChangeCallback)(jack_uuid_t, const char*, jack_property_change_t, void*);
  49. typedef void (JACKSYM_API *jacksym_get_version)(int*, int*, int*, int*);
  50. typedef const char* (JACKSYM_API *jacksym_get_version_string)(void);
  51. typedef jack_client_t* (JACKSYM_API *jacksym_client_open)(const char*, jack_options_t, jack_status_t*, ...);
  52. typedef int (JACKSYM_API *jacksym_client_close)(jack_client_t*);
  53. typedef int (JACKSYM_API *jacksym_client_name_size)(void);
  54. typedef char* (JACKSYM_API *jacksym_get_client_name)(jack_client_t*);
  55. typedef char* (JACKSYM_API *jacksym_client_get_uuid)(jack_client_t*);
  56. typedef char* (JACKSYM_API *jacksym_get_uuid_for_client_name)(jack_client_t*, const char*);
  57. typedef char* (JACKSYM_API *jacksym_get_client_name_by_uuid)(jack_client_t*, const char*);
  58. typedef int (JACKBRIDGE_API *jacksym_uuid_parse)(const char*, jack_uuid_t*);
  59. typedef int (JACKSYM_API *jacksym_activate)(jack_client_t*);
  60. typedef int (JACKSYM_API *jacksym_deactivate)(jack_client_t*);
  61. typedef int (JACKSYM_API *jacksym_is_realtime)(jack_client_t*);
  62. typedef int (JACKSYM_API *jacksym_set_thread_init_callback)(jack_client_t*, JackSymThreadInitCallback, void*);
  63. typedef void (JACKSYM_API *jacksym_on_shutdown)(jack_client_t*, JackSymShutdownCallback, void*);
  64. typedef void (JACKSYM_API *jacksym_on_info_shutdown)(jack_client_t*, JackSymInfoShutdownCallback, void*);
  65. typedef int (JACKSYM_API *jacksym_set_process_callback)(jack_client_t*, JackSymProcessCallback, void*);
  66. typedef int (JACKSYM_API *jacksym_set_freewheel_callback)(jack_client_t*, JackSymFreewheelCallback, void*);
  67. typedef int (JACKSYM_API *jacksym_set_buffer_size_callback)(jack_client_t*, JackSymBufferSizeCallback, void*);
  68. typedef int (JACKSYM_API *jacksym_set_sample_rate_callback)(jack_client_t*, JackSymSampleRateCallback, void*);
  69. typedef int (JACKSYM_API *jacksym_set_client_registration_callback)(jack_client_t*, JackSymClientRegistrationCallback, void*);
  70. typedef int (JACKSYM_API *jacksym_set_port_registration_callback)(jack_client_t*, JackSymPortRegistrationCallback, void*);
  71. typedef int (JACKSYM_API *jacksym_set_port_rename_callback)(jack_client_t*, JackSymPortRenameCallback, void*);
  72. typedef int (JACKSYM_API *jacksym_set_port_connect_callback)(jack_client_t*, JackSymPortConnectCallback, void*);
  73. typedef int (JACKSYM_API *jacksym_set_graph_order_callback)(jack_client_t*, JackSymGraphOrderCallback, void*);
  74. typedef int (JACKSYM_API *jacksym_set_xrun_callback)(jack_client_t*, JackSymXRunCallback, void*);
  75. typedef int (JACKSYM_API *jacksym_set_latency_callback)(jack_client_t*, JackSymLatencyCallback, void*);
  76. typedef int (JACKSYM_API *jacksym_set_freewheel)(jack_client_t*, int);
  77. typedef int (JACKSYM_API *jacksym_set_buffer_size)(jack_client_t*, jack_nframes_t);
  78. typedef jack_nframes_t (JACKSYM_API *jacksym_get_sample_rate)(jack_client_t*);
  79. typedef jack_nframes_t (JACKSYM_API *jacksym_get_buffer_size)(jack_client_t*);
  80. typedef float (JACKSYM_API *jacksym_cpu_load)(jack_client_t*);
  81. typedef jack_port_t* (JACKSYM_API *jacksym_port_register)(jack_client_t*, const char*, const char*, ulong, ulong);
  82. typedef int (JACKSYM_API *jacksym_port_unregister)(jack_client_t*, jack_port_t*);
  83. typedef void* (JACKSYM_API *jacksym_port_get_buffer)(jack_port_t*, jack_nframes_t);
  84. typedef const char* (JACKSYM_API *jacksym_port_name)(const jack_port_t*);
  85. typedef jack_uuid_t (JACKSYM_API *jacksym_port_uuid)(const jack_port_t*);
  86. typedef const char* (JACKSYM_API *jacksym_port_short_name)(const jack_port_t*);
  87. typedef int (JACKSYM_API *jacksym_port_flags)(const jack_port_t*);
  88. typedef const char* (JACKSYM_API *jacksym_port_type)(const jack_port_t*);
  89. typedef int (JACKSYM_API *jacksym_port_is_mine)(const jack_client_t*, const jack_port_t*);
  90. typedef int (JACKSYM_API *jacksym_port_connected)(const jack_port_t*);
  91. typedef int (JACKSYM_API *jacksym_port_connected_to)(const jack_port_t*, const char*);
  92. typedef const char** (JACKSYM_API *jacksym_port_get_connections)(const jack_port_t*);
  93. typedef const char** (JACKSYM_API *jacksym_port_get_all_connections)(const jack_client_t*, const jack_port_t*);
  94. typedef int (JACKSYM_API *jacksym_port_rename)(jack_client_t*, jack_port_t*, const char*);
  95. typedef int (JACKSYM_API *jacksym_port_set_name)(jack_port_t*, const char*);
  96. typedef int (JACKSYM_API *jacksym_port_set_alias)(jack_port_t*, const char*);
  97. typedef int (JACKSYM_API *jacksym_port_unset_alias)(jack_port_t*, const char*);
  98. typedef int (JACKSYM_API *jacksym_port_get_aliases)(const jack_port_t*, char* const aliases[2]);
  99. typedef int (JACKSYM_API *jacksym_port_request_monitor)(jack_port_t*, int);
  100. typedef int (JACKSYM_API *jacksym_port_request_monitor_by_name)(jack_client_t*, const char*, int);
  101. typedef int (JACKSYM_API *jacksym_port_ensure_monitor)(jack_port_t*, int);
  102. typedef int (JACKSYM_API *jacksym_port_monitoring_input)(jack_port_t*);
  103. typedef int (JACKSYM_API *jacksym_connect)(jack_client_t*, const char*, const char*);
  104. typedef int (JACKSYM_API *jacksym_disconnect)(jack_client_t*, const char*, const char*);
  105. typedef int (JACKSYM_API *jacksym_port_disconnect)(jack_client_t*, jack_port_t*);
  106. typedef int (JACKSYM_API *jacksym_port_name_size)(void);
  107. typedef int (JACKSYM_API *jacksym_port_type_size)(void);
  108. typedef size_t (JACKSYM_API *jacksym_port_type_get_buffer_size)(jack_client_t*, const char*);
  109. typedef void (JACKSYM_API *jacksym_port_get_latency_range)(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t*);
  110. typedef void (JACKSYM_API *jacksym_port_set_latency_range)(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t*);
  111. typedef int (JACKSYM_API *jacksym_recompute_total_latencies)(jack_client_t*);
  112. typedef const char** (JACKSYM_API *jacksym_get_ports)(jack_client_t*, const char*, const char*, ulong);
  113. typedef jack_port_t* (JACKSYM_API *jacksym_port_by_name)(jack_client_t*, const char*);
  114. typedef jack_port_t* (JACKSYM_API *jacksym_port_by_id)(jack_client_t*, jack_port_id_t);
  115. typedef void (JACKSYM_API *jacksym_free)(void*);
  116. typedef uint32_t (JACKSYM_API *jacksym_midi_get_event_count)(void*);
  117. typedef int (JACKSYM_API *jacksym_midi_event_get)(jack_midi_event_t*, void*, uint32_t);
  118. typedef void (JACKSYM_API *jacksym_midi_clear_buffer)(void*);
  119. typedef int (JACKSYM_API *jacksym_midi_event_write)(void*, jack_nframes_t, const jack_midi_data_t*, size_t);
  120. typedef jack_midi_data_t* (JACKSYM_API *jacksym_midi_event_reserve)(void*, jack_nframes_t, size_t);
  121. typedef int (JACKSYM_API *jacksym_release_timebase)(jack_client_t*);
  122. typedef int (JACKSYM_API *jacksym_set_sync_callback)(jack_client_t*, JackSymSyncCallback, void*);
  123. typedef int (JACKSYM_API *jacksym_set_sync_timeout)(jack_client_t*, jack_time_t);
  124. typedef int (JACKSYM_API *jacksym_set_timebase_callback)(jack_client_t*, int, JackSymTimebaseCallback, void*);
  125. typedef int (JACKSYM_API *jacksym_transport_locate)(jack_client_t*, jack_nframes_t);
  126. typedef jack_transport_state_t (JACKSYM_API *jacksym_transport_query)(const jack_client_t*, jack_position_t*);
  127. typedef jack_nframes_t (JACKSYM_API *jacksym_get_current_transport_frame)(const jack_client_t*);
  128. typedef int (JACKSYM_API *jacksym_transport_reposition)(jack_client_t*, const jack_position_t*);
  129. typedef void (JACKSYM_API *jacksym_transport_start)(jack_client_t*);
  130. typedef void (JACKSYM_API *jacksym_transport_stop)(jack_client_t*);
  131. typedef int (JACKSYM_API *jacksym_set_property)(jack_client_t*, jack_uuid_t, const char*, const char*, const char*);
  132. typedef int (JACKSYM_API *jacksym_get_property)(jack_uuid_t, const char*, char**, char**);
  133. typedef void (JACKSYM_API *jacksym_free_description)(jack_description_t*, int);
  134. typedef int (JACKSYM_API *jacksym_get_properties)(jack_uuid_t, jack_description_t*);
  135. typedef int (JACKSYM_API *jacksym_get_all_properties)(jack_description_t**);
  136. typedef int (JACKSYM_API *jacksym_remove_property)(jack_client_t*, jack_uuid_t, const char*);
  137. typedef int (JACKSYM_API *jacksym_remove_properties)(jack_client_t*, jack_uuid_t);
  138. typedef int (JACKSYM_API *jacksym_remove_all_properties)(jack_client_t*);
  139. typedef int (JACKSYM_API *jacksym_set_property_change_callback)(jack_client_t*, JackSymPropertyChangeCallback, void*);
  140. #ifdef __WINE__
  141. typedef int (JACKSYM_API *jacksym_thread_creator_t)(pthread_t*, const pthread_attr_t*, void *(*)(void*), void*);
  142. typedef void (JACKSYM_API *jacksym_set_thread_creator)(jacksym_thread_creator_t);
  143. #endif
  144. } // extern "C"
  145. // -----------------------------------------------------------------------------
  146. struct JackBridge {
  147. lib_t lib;
  148. jacksym_get_version get_version_ptr;
  149. jacksym_get_version_string get_version_string_ptr;
  150. jacksym_client_open client_open_ptr;
  151. jacksym_client_close client_close_ptr;
  152. jacksym_client_name_size client_name_size_ptr;
  153. jacksym_get_client_name get_client_name_ptr;
  154. jacksym_client_get_uuid client_get_uuid_ptr;
  155. jacksym_get_uuid_for_client_name get_uuid_for_client_name_ptr;
  156. jacksym_get_client_name_by_uuid get_client_name_by_uuid_ptr;
  157. jacksym_uuid_parse uuid_parse_ptr;
  158. jacksym_activate activate_ptr;
  159. jacksym_deactivate deactivate_ptr;
  160. jacksym_is_realtime is_realtime_ptr;
  161. jacksym_set_thread_init_callback set_thread_init_callback_ptr;
  162. jacksym_on_shutdown on_shutdown_ptr;
  163. jacksym_on_info_shutdown on_info_shutdown_ptr;
  164. jacksym_set_process_callback set_process_callback_ptr;
  165. jacksym_set_freewheel_callback set_freewheel_callback_ptr;
  166. jacksym_set_buffer_size_callback set_buffer_size_callback_ptr;
  167. jacksym_set_sample_rate_callback set_sample_rate_callback_ptr;
  168. jacksym_set_client_registration_callback set_client_registration_callback_ptr;
  169. jacksym_set_port_registration_callback set_port_registration_callback_ptr;
  170. jacksym_set_port_rename_callback set_port_rename_callback_ptr;
  171. jacksym_set_port_connect_callback set_port_connect_callback_ptr;
  172. jacksym_set_graph_order_callback set_graph_order_callback_ptr;
  173. jacksym_set_xrun_callback set_xrun_callback_ptr;
  174. jacksym_set_latency_callback set_latency_callback_ptr;
  175. jacksym_set_freewheel set_freewheel_ptr;
  176. jacksym_set_buffer_size set_buffer_size_ptr;
  177. jacksym_get_sample_rate get_sample_rate_ptr;
  178. jacksym_get_buffer_size get_buffer_size_ptr;
  179. jacksym_cpu_load cpu_load_ptr;
  180. jacksym_port_register port_register_ptr;
  181. jacksym_port_unregister port_unregister_ptr;
  182. jacksym_port_get_buffer port_get_buffer_ptr;
  183. jacksym_port_name port_name_ptr;
  184. jacksym_port_uuid port_uuid_ptr;
  185. jacksym_port_short_name port_short_name_ptr;
  186. jacksym_port_flags port_flags_ptr;
  187. jacksym_port_type port_type_ptr;
  188. jacksym_port_is_mine port_is_mine_ptr;
  189. jacksym_port_connected port_connected_ptr;
  190. jacksym_port_connected_to port_connected_to_ptr;
  191. jacksym_port_get_connections port_get_connections_ptr;
  192. jacksym_port_get_all_connections port_get_all_connections_ptr;
  193. jacksym_port_rename port_rename_ptr;
  194. jacksym_port_set_name port_set_name_ptr;
  195. jacksym_port_set_alias port_set_alias_ptr;
  196. jacksym_port_unset_alias port_unset_alias_ptr;
  197. jacksym_port_get_aliases port_get_aliases_ptr;
  198. jacksym_port_request_monitor port_request_monitor_ptr;
  199. jacksym_port_request_monitor_by_name port_request_monitor_by_name_ptr;
  200. jacksym_port_ensure_monitor port_ensure_monitor_ptr;
  201. jacksym_port_monitoring_input port_monitoring_input_ptr;
  202. jacksym_connect connect_ptr;
  203. jacksym_disconnect disconnect_ptr;
  204. jacksym_port_disconnect port_disconnect_ptr;
  205. jacksym_port_name_size port_name_size_ptr;
  206. jacksym_port_type_size port_type_size_ptr;
  207. jacksym_port_type_get_buffer_size port_type_get_buffer_size_ptr;
  208. jacksym_port_get_latency_range port_get_latency_range_ptr;
  209. jacksym_port_set_latency_range port_set_latency_range_ptr;
  210. jacksym_recompute_total_latencies recompute_total_latencies_ptr;
  211. jacksym_get_ports get_ports_ptr;
  212. jacksym_port_by_name port_by_name_ptr;
  213. jacksym_port_by_id port_by_id_ptr;
  214. jacksym_free free_ptr;
  215. jacksym_midi_get_event_count midi_get_event_count_ptr;
  216. jacksym_midi_event_get midi_event_get_ptr;
  217. jacksym_midi_clear_buffer midi_clear_buffer_ptr;
  218. jacksym_midi_event_write midi_event_write_ptr;
  219. jacksym_midi_event_reserve midi_event_reserve_ptr;
  220. jacksym_release_timebase release_timebase_ptr;
  221. jacksym_set_sync_callback set_sync_callback_ptr;
  222. jacksym_set_sync_timeout set_sync_timeout_ptr;
  223. jacksym_set_timebase_callback set_timebase_callback_ptr;
  224. jacksym_transport_locate transport_locate_ptr;
  225. jacksym_transport_query transport_query_ptr;
  226. jacksym_get_current_transport_frame get_current_transport_frame_ptr;
  227. jacksym_transport_reposition transport_reposition_ptr;
  228. jacksym_transport_start transport_start_ptr;
  229. jacksym_transport_stop transport_stop_ptr;
  230. jacksym_set_property set_property_ptr;
  231. jacksym_get_property get_property_ptr;
  232. jacksym_free_description free_description_ptr;
  233. jacksym_get_properties get_properties_ptr;
  234. jacksym_get_all_properties get_all_properties_ptr;
  235. jacksym_remove_property remove_property_ptr;
  236. jacksym_remove_properties remove_properties_ptr;
  237. jacksym_remove_all_properties remove_all_properties_ptr;
  238. jacksym_set_property_change_callback set_property_change_callback_ptr;
  239. #ifdef __WINE__
  240. jacksym_set_thread_creator set_thread_creator_ptr;
  241. #endif
  242. JackBridge()
  243. : lib(nullptr),
  244. get_version_ptr(nullptr),
  245. get_version_string_ptr(nullptr),
  246. client_open_ptr(nullptr),
  247. client_close_ptr(nullptr),
  248. client_name_size_ptr(nullptr),
  249. get_client_name_ptr(nullptr),
  250. client_get_uuid_ptr(nullptr),
  251. get_uuid_for_client_name_ptr(nullptr),
  252. get_client_name_by_uuid_ptr(nullptr),
  253. uuid_parse_ptr(nullptr),
  254. activate_ptr(nullptr),
  255. deactivate_ptr(nullptr),
  256. is_realtime_ptr(nullptr),
  257. set_thread_init_callback_ptr(nullptr),
  258. on_shutdown_ptr(nullptr),
  259. on_info_shutdown_ptr(nullptr),
  260. set_process_callback_ptr(nullptr),
  261. set_freewheel_callback_ptr(nullptr),
  262. set_buffer_size_callback_ptr(nullptr),
  263. set_sample_rate_callback_ptr(nullptr),
  264. set_client_registration_callback_ptr(nullptr),
  265. set_port_registration_callback_ptr(nullptr),
  266. set_port_rename_callback_ptr(nullptr),
  267. set_port_connect_callback_ptr(nullptr),
  268. set_graph_order_callback_ptr(nullptr),
  269. set_xrun_callback_ptr(nullptr),
  270. set_latency_callback_ptr(nullptr),
  271. set_freewheel_ptr(nullptr),
  272. set_buffer_size_ptr(nullptr),
  273. get_sample_rate_ptr(nullptr),
  274. get_buffer_size_ptr(nullptr),
  275. cpu_load_ptr(nullptr),
  276. port_register_ptr(nullptr),
  277. port_unregister_ptr(nullptr),
  278. port_get_buffer_ptr(nullptr),
  279. port_name_ptr(nullptr),
  280. port_uuid_ptr(nullptr),
  281. port_short_name_ptr(nullptr),
  282. port_flags_ptr(nullptr),
  283. port_type_ptr(nullptr),
  284. port_is_mine_ptr(nullptr),
  285. port_connected_ptr(nullptr),
  286. port_connected_to_ptr(nullptr),
  287. port_get_connections_ptr(nullptr),
  288. port_get_all_connections_ptr(nullptr),
  289. port_rename_ptr(nullptr),
  290. port_set_name_ptr(nullptr),
  291. port_set_alias_ptr(nullptr),
  292. port_unset_alias_ptr(nullptr),
  293. port_get_aliases_ptr(nullptr),
  294. port_request_monitor_ptr(nullptr),
  295. port_request_monitor_by_name_ptr(nullptr),
  296. port_ensure_monitor_ptr(nullptr),
  297. port_monitoring_input_ptr(nullptr),
  298. connect_ptr(nullptr),
  299. disconnect_ptr(nullptr),
  300. port_disconnect_ptr(nullptr),
  301. port_name_size_ptr(nullptr),
  302. port_type_size_ptr(nullptr),
  303. port_type_get_buffer_size_ptr(nullptr),
  304. port_get_latency_range_ptr(nullptr),
  305. port_set_latency_range_ptr(nullptr),
  306. recompute_total_latencies_ptr(nullptr),
  307. get_ports_ptr(nullptr),
  308. port_by_name_ptr(nullptr),
  309. port_by_id_ptr(nullptr),
  310. free_ptr(nullptr),
  311. midi_get_event_count_ptr(nullptr),
  312. midi_event_get_ptr(nullptr),
  313. midi_clear_buffer_ptr(nullptr),
  314. midi_event_write_ptr(nullptr),
  315. midi_event_reserve_ptr(nullptr),
  316. release_timebase_ptr(nullptr),
  317. set_sync_callback_ptr(nullptr),
  318. set_sync_timeout_ptr(nullptr),
  319. set_timebase_callback_ptr(nullptr),
  320. transport_locate_ptr(nullptr),
  321. transport_query_ptr(nullptr),
  322. get_current_transport_frame_ptr(nullptr),
  323. transport_reposition_ptr(nullptr),
  324. transport_start_ptr(nullptr),
  325. transport_stop_ptr(nullptr),
  326. set_property_ptr(nullptr),
  327. get_property_ptr(nullptr),
  328. free_description_ptr(nullptr),
  329. get_properties_ptr(nullptr),
  330. get_all_properties_ptr(nullptr),
  331. remove_property_ptr(nullptr),
  332. remove_properties_ptr(nullptr),
  333. remove_all_properties_ptr(nullptr),
  334. set_property_change_callback_ptr(nullptr)
  335. #ifdef __WINE__
  336. , set_thread_creator_ptr(nullptr)
  337. #endif
  338. {
  339. # if defined(CARLA_OS_MAC)
  340. const char* const filename("libjack.dylib");
  341. # elif defined(CARLA_OS_WIN64)
  342. const char* const filename("libjack64.dll");
  343. # elif defined(CARLA_OS_WIN)
  344. const char* const filename("libjack.dll");
  345. # else
  346. const char* const filename("libjack.so.0");
  347. # endif
  348. lib = lib_open(filename);
  349. if (lib == nullptr)
  350. {
  351. fprintf(stderr, "Failed to load JACK DLL, reason:\n%s\n", lib_error(filename));
  352. return;
  353. }
  354. else
  355. {
  356. fprintf(stdout, "%s loaded sucessfully!\n", filename);
  357. }
  358. #define JOIN(a, b) a ## b
  359. #define LIB_SYMBOL(NAME) JOIN(NAME, _ptr) = lib_symbol<jacksym_##NAME>(lib, "jack_" #NAME);
  360. LIB_SYMBOL(get_version)
  361. LIB_SYMBOL(get_version_string)
  362. LIB_SYMBOL(client_open)
  363. LIB_SYMBOL(client_close)
  364. LIB_SYMBOL(client_name_size)
  365. LIB_SYMBOL(get_client_name)
  366. LIB_SYMBOL(client_get_uuid)
  367. LIB_SYMBOL(get_uuid_for_client_name)
  368. LIB_SYMBOL(get_client_name_by_uuid)
  369. LIB_SYMBOL(uuid_parse)
  370. LIB_SYMBOL(activate)
  371. LIB_SYMBOL(deactivate)
  372. LIB_SYMBOL(is_realtime)
  373. LIB_SYMBOL(set_thread_init_callback)
  374. LIB_SYMBOL(on_shutdown)
  375. LIB_SYMBOL(on_info_shutdown)
  376. LIB_SYMBOL(set_process_callback)
  377. LIB_SYMBOL(set_freewheel_callback)
  378. LIB_SYMBOL(set_buffer_size_callback)
  379. LIB_SYMBOL(set_sample_rate_callback)
  380. LIB_SYMBOL(set_client_registration_callback)
  381. LIB_SYMBOL(set_port_registration_callback)
  382. LIB_SYMBOL(set_port_rename_callback)
  383. LIB_SYMBOL(set_port_connect_callback)
  384. LIB_SYMBOL(set_graph_order_callback)
  385. LIB_SYMBOL(set_xrun_callback)
  386. LIB_SYMBOL(set_latency_callback)
  387. LIB_SYMBOL(set_freewheel)
  388. LIB_SYMBOL(set_buffer_size)
  389. LIB_SYMBOL(get_sample_rate)
  390. LIB_SYMBOL(get_buffer_size)
  391. LIB_SYMBOL(cpu_load)
  392. LIB_SYMBOL(port_register)
  393. LIB_SYMBOL(port_unregister)
  394. LIB_SYMBOL(port_get_buffer)
  395. LIB_SYMBOL(port_name)
  396. LIB_SYMBOL(port_uuid)
  397. LIB_SYMBOL(port_short_name)
  398. LIB_SYMBOL(port_flags)
  399. LIB_SYMBOL(port_type)
  400. LIB_SYMBOL(port_is_mine)
  401. LIB_SYMBOL(port_connected)
  402. LIB_SYMBOL(port_connected_to)
  403. LIB_SYMBOL(port_get_connections)
  404. LIB_SYMBOL(port_get_all_connections)
  405. LIB_SYMBOL(port_rename)
  406. LIB_SYMBOL(port_set_name)
  407. LIB_SYMBOL(port_set_alias)
  408. LIB_SYMBOL(port_unset_alias)
  409. LIB_SYMBOL(port_get_aliases)
  410. LIB_SYMBOL(port_request_monitor)
  411. LIB_SYMBOL(port_request_monitor_by_name)
  412. LIB_SYMBOL(port_ensure_monitor)
  413. LIB_SYMBOL(port_monitoring_input)
  414. LIB_SYMBOL(connect)
  415. LIB_SYMBOL(disconnect)
  416. LIB_SYMBOL(port_disconnect)
  417. LIB_SYMBOL(port_name_size)
  418. LIB_SYMBOL(port_type_size)
  419. LIB_SYMBOL(port_type_get_buffer_size)
  420. LIB_SYMBOL(port_get_latency_range)
  421. LIB_SYMBOL(port_set_latency_range)
  422. LIB_SYMBOL(recompute_total_latencies)
  423. LIB_SYMBOL(get_ports)
  424. LIB_SYMBOL(port_by_name)
  425. LIB_SYMBOL(port_by_id)
  426. LIB_SYMBOL(free)
  427. LIB_SYMBOL(midi_get_event_count)
  428. LIB_SYMBOL(midi_event_get)
  429. LIB_SYMBOL(midi_clear_buffer)
  430. LIB_SYMBOL(midi_event_write)
  431. LIB_SYMBOL(midi_event_reserve)
  432. LIB_SYMBOL(release_timebase)
  433. LIB_SYMBOL(set_sync_callback)
  434. LIB_SYMBOL(set_sync_timeout)
  435. LIB_SYMBOL(set_timebase_callback)
  436. LIB_SYMBOL(transport_locate)
  437. LIB_SYMBOL(transport_query)
  438. LIB_SYMBOL(get_current_transport_frame)
  439. LIB_SYMBOL(transport_reposition)
  440. LIB_SYMBOL(transport_start)
  441. LIB_SYMBOL(transport_stop)
  442. LIB_SYMBOL(set_property)
  443. LIB_SYMBOL(get_property)
  444. LIB_SYMBOL(free_description)
  445. LIB_SYMBOL(get_properties)
  446. LIB_SYMBOL(get_all_properties)
  447. LIB_SYMBOL(remove_property)
  448. LIB_SYMBOL(remove_properties)
  449. LIB_SYMBOL(remove_all_properties)
  450. LIB_SYMBOL(set_property_change_callback)
  451. #ifdef __WINE__
  452. LIB_SYMBOL(set_thread_creator)
  453. #endif
  454. #undef JOIN
  455. #undef LIB_SYMBOL
  456. }
  457. ~JackBridge() noexcept
  458. {
  459. if (lib != nullptr)
  460. {
  461. lib_close(lib);
  462. lib = nullptr;
  463. }
  464. }
  465. CARLA_DECLARE_NON_COPY_STRUCT(JackBridge);
  466. };
  467. // -----------------------------------------------------------------------------
  468. static const JackBridge& getBridgeInstance() noexcept
  469. {
  470. static const JackBridge bridge;
  471. return bridge;
  472. }
  473. #endif // ! (defined(JACKBRIDGE_DIRECT) || defined(JACKBRIDGE_DUMMY))
  474. // -----------------------------------------------------------------------------
  475. #if defined(__WINE__) && ! defined(JACKBRIDGE_DIRECT)
  476. struct WineBridge {
  477. void* ptr;
  478. JackLatencyCallback latency_cb;
  479. JackProcessCallback process_cb;
  480. JackThreadInitCallback thread_init_cb;
  481. JackGraphOrderCallback graph_order_cb;
  482. JackXRunCallback xrun_cb;
  483. JackBufferSizeCallback bufsize_cb;
  484. JackSampleRateCallback srate_cb;
  485. JackPortRegistrationCallback port_reg_cb;
  486. JackClientRegistrationCallback client_reg_cb;
  487. JackPortConnectCallback port_conn_cb;
  488. JackPortRenameCallback port_rename_cb;
  489. JackFreewheelCallback freewheel_cb;
  490. JackShutdownCallback shutdown_cb;
  491. JackInfoShutdownCallback info_shutdown_cb;
  492. JackSyncCallback sync_cb;
  493. JackTimebaseCallback timebase_cb;
  494. JackSessionCallback session_cb;
  495. JackPropertyChangeCallback prop_change_cb;
  496. void* (*creator_func)(void*);
  497. void* creator_arg;
  498. HANDLE creator_handle;
  499. pthread_t creator_pthread;
  500. WineBridge() noexcept
  501. : ptr(nullptr),
  502. latency_cb(nullptr),
  503. process_cb(nullptr),
  504. thread_init_cb(nullptr),
  505. graph_order_cb(nullptr),
  506. xrun_cb(nullptr),
  507. bufsize_cb(nullptr),
  508. srate_cb(nullptr),
  509. port_reg_cb(nullptr),
  510. client_reg_cb(nullptr),
  511. port_conn_cb(nullptr),
  512. port_rename_cb(nullptr),
  513. freewheel_cb(nullptr),
  514. shutdown_cb(nullptr),
  515. info_shutdown_cb(nullptr),
  516. sync_cb(nullptr),
  517. timebase_cb(nullptr),
  518. session_cb(nullptr),
  519. prop_change_cb(nullptr),
  520. creator_func(nullptr),
  521. creator_arg(nullptr),
  522. creator_handle(nullptr),
  523. creator_pthread(0) {}
  524. static WineBridge& getInstance() noexcept
  525. {
  526. static WineBridge bridge;
  527. return bridge;
  528. }
  529. void set_latency (JackLatencyCallback cb) noexcept { latency_cb = cb; }
  530. void set_process (JackProcessCallback cb) noexcept { process_cb = cb; }
  531. void set_thread_init (JackThreadInitCallback cb) noexcept { thread_init_cb = cb; }
  532. void set_graph_order (JackGraphOrderCallback cb) noexcept { graph_order_cb = cb; }
  533. void set_xrun (JackXRunCallback cb) noexcept { xrun_cb = cb; }
  534. void set_bufsize (JackBufferSizeCallback cb) noexcept { bufsize_cb = cb; }
  535. void set_srate (JackSampleRateCallback cb) noexcept { srate_cb = cb; }
  536. void set_port_reg (JackPortRegistrationCallback cb) noexcept { port_reg_cb = cb; }
  537. void set_client_reg (JackClientRegistrationCallback cb) noexcept { client_reg_cb = cb; }
  538. void set_port_conn (JackPortConnectCallback cb) noexcept { port_conn_cb = cb; }
  539. void set_port_rename (JackPortRenameCallback cb) noexcept { port_rename_cb = cb; }
  540. void set_freewheel (JackFreewheelCallback cb) noexcept { freewheel_cb = cb; }
  541. void set_shutdown (JackShutdownCallback cb) noexcept { shutdown_cb = cb; }
  542. void set_info_shutdown(JackInfoShutdownCallback cb) noexcept { info_shutdown_cb = cb; }
  543. void set_sync (JackSyncCallback cb) noexcept { sync_cb = cb; }
  544. void set_timebase (JackTimebaseCallback cb) noexcept { timebase_cb = cb; }
  545. void set_session (JackSessionCallback cb) noexcept { session_cb = cb; }
  546. void set_prop_change (JackPropertyChangeCallback cb) noexcept { prop_change_cb = cb; }
  547. static DWORD WINAPI thread_creator_helper(LPVOID)
  548. {
  549. WineBridge& inst(getInstance());
  550. inst.creator_pthread = pthread_self();
  551. SetEvent(inst.creator_handle);
  552. inst.creator_func(inst.creator_arg);
  553. return 0;
  554. }
  555. static int thread_creator(pthread_t* thread_id, const pthread_attr_t*, void *(*function)(void*), void* arg)
  556. {
  557. WineBridge& inst(getInstance());
  558. inst.creator_func = function;
  559. inst.creator_arg = arg;
  560. inst.creator_handle = ::CreateEventW(nullptr, false, false, nullptr);
  561. #if 0
  562. ::CreateThread(nullptr, 0, thread_creator_helper, arg, 0, nullptr);
  563. #else
  564. HANDLE handle = ::CreateThread(nullptr, 0, thread_creator_helper, arg, CREATE_SUSPENDED, nullptr);
  565. if (handle == INVALID_HANDLE_VALUE)
  566. return 1;
  567. // TODO read attrs and decide this
  568. ::SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
  569. ::ResumeThread(handle);
  570. #endif
  571. ::WaitForSingleObject(inst.creator_handle, INFINITE);
  572. *thread_id = inst.creator_pthread;
  573. return 0;
  574. }
  575. static void latency(jack_latency_callback_mode_t mode, void* arg)
  576. {
  577. return getInstance().latency_cb(mode, arg);
  578. }
  579. static int process(jack_nframes_t nframes, void* arg)
  580. {
  581. return getInstance().process_cb(nframes, arg);
  582. }
  583. static void thread_init(void* arg)
  584. {
  585. return getInstance().thread_init_cb(arg);
  586. }
  587. static int graph_order(void* arg)
  588. {
  589. return getInstance().graph_order_cb(arg);
  590. }
  591. static int xrun(void* arg)
  592. {
  593. return getInstance().xrun_cb(arg);
  594. }
  595. static int bufsize(jack_nframes_t nframes, void* arg)
  596. {
  597. return getInstance().bufsize_cb(nframes, arg);
  598. }
  599. static int srate(jack_nframes_t nframes, void* arg)
  600. {
  601. return getInstance().srate_cb(nframes, arg);
  602. }
  603. static void port_reg(jack_port_id_t port, int register_, void* arg)
  604. {
  605. return getInstance().port_reg_cb(port, register_, arg);
  606. }
  607. static void client_reg(const char* name, int register_, void* arg)
  608. {
  609. return getInstance().client_reg_cb(name, register_, arg);
  610. }
  611. static void port_conn(jack_port_id_t a, jack_port_id_t b, int connect, void* arg)
  612. {
  613. return getInstance().port_conn_cb(a, b, connect, arg);
  614. }
  615. static void port_rename(jack_port_id_t port, const char* old_name, const char* new_name, void* arg)
  616. {
  617. getInstance().port_rename_cb(port, old_name, new_name, arg);
  618. }
  619. static void freewheel(int starting, void* arg)
  620. {
  621. return getInstance().freewheel_cb(starting, arg);
  622. }
  623. static void shutdown(void* arg)
  624. {
  625. return getInstance().shutdown_cb(arg);
  626. }
  627. static void info_shutdown(jack_status_t code, const char* reason, void* arg)
  628. {
  629. return getInstance().info_shutdown_cb(code, reason, arg);
  630. }
  631. static int sync(jack_transport_state_t state, jack_position_t* pos, void* arg)
  632. {
  633. return getInstance().sync_cb(state, pos, arg);
  634. }
  635. static void timebase(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg)
  636. {
  637. return getInstance().timebase_cb(state, nframes, pos, new_pos, arg);
  638. }
  639. static void session(jack_session_event_t* event, void* arg)
  640. {
  641. return getInstance().session_cb(event, arg);
  642. }
  643. static void prop_change(jack_uuid_t subject, const char* key, jack_property_change_t change, void* arg)
  644. {
  645. return getInstance().prop_change_cb(subject, key, change, arg);
  646. }
  647. CARLA_DECLARE_NON_COPY_STRUCT(WineBridge);
  648. };
  649. #endif // __WINE__ && ! JACKBRIDGE_DIRECT
  650. // -----------------------------------------------------------------------------
  651. bool jackbridge_is_ok() noexcept
  652. {
  653. #if defined(JACKBRIDGE_DUMMY)
  654. return false;
  655. #elif defined(JACKBRIDGE_DIRECT)
  656. return true;
  657. #else
  658. return (getBridgeInstance().lib != nullptr);
  659. #endif
  660. }
  661. void jackbridge_init()
  662. {
  663. #if defined(__WINE__) && ! defined(JACKBRIDGE_DIRECT)
  664. if (getBridgeInstance().set_thread_creator_ptr != nullptr)
  665. getBridgeInstance().set_thread_creator_ptr(WineBridge::thread_creator);
  666. #endif
  667. }
  668. // -----------------------------------------------------------------------------
  669. void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr)
  670. {
  671. #if defined(JACKBRIDGE_DUMMY)
  672. #elif defined(JACKBRIDGE_DIRECT)
  673. return jack_get_version(major_ptr, minor_ptr, micro_ptr, proto_ptr);
  674. #else
  675. if (getBridgeInstance().get_version_ptr != nullptr)
  676. return getBridgeInstance().get_version_ptr(major_ptr, minor_ptr, micro_ptr, proto_ptr);
  677. #endif
  678. if (major_ptr != nullptr)
  679. *major_ptr = 0;
  680. if (minor_ptr != nullptr)
  681. *minor_ptr = 0;
  682. if (micro_ptr != nullptr)
  683. *micro_ptr = 0;
  684. if (proto_ptr != nullptr)
  685. *proto_ptr = 0;
  686. }
  687. const char* jackbridge_get_version_string()
  688. {
  689. #if defined(JACKBRIDGE_DUMMY)
  690. #elif defined(JACKBRIDGE_DIRECT)
  691. return jack_get_version_string();
  692. #else
  693. if (getBridgeInstance().get_version_string_ptr != nullptr)
  694. return getBridgeInstance().get_version_string_ptr();
  695. #endif
  696. return nullptr;
  697. }
  698. // -----------------------------------------------------------------------------
  699. jack_client_t* jackbridge_client_open(const char* client_name, uint32_t options, jack_status_t* status)
  700. {
  701. #if defined(JACKBRIDGE_DUMMY)
  702. #elif defined(JACKBRIDGE_DIRECT)
  703. return jack_client_open(client_name, static_cast<jack_options_t>(options), status);
  704. #else
  705. if (getBridgeInstance().client_open_ptr != nullptr)
  706. return getBridgeInstance().client_open_ptr(client_name, static_cast<jack_options_t>(options), status);
  707. #endif
  708. if (status != nullptr)
  709. *status = JackServerError;
  710. return nullptr;
  711. }
  712. bool jackbridge_client_close(jack_client_t* client)
  713. {
  714. #if defined(JACKBRIDGE_DUMMY)
  715. #elif defined(JACKBRIDGE_DIRECT)
  716. return (jack_client_close(client) == 0);
  717. #else
  718. if (getBridgeInstance().client_close_ptr != nullptr)
  719. return (getBridgeInstance().client_close_ptr(client) == 0);
  720. #endif
  721. return false;
  722. }
  723. // -----------------------------------------------------------------------------
  724. int jackbridge_client_name_size()
  725. {
  726. #if defined(JACKBRIDGE_DUMMY)
  727. #elif defined(JACKBRIDGE_DIRECT)
  728. return jack_client_name_size();
  729. #else
  730. if (getBridgeInstance().client_name_size_ptr != nullptr)
  731. return getBridgeInstance().client_name_size_ptr();
  732. #endif
  733. return 33;
  734. }
  735. char* jackbridge_get_client_name(jack_client_t* client)
  736. {
  737. #if defined(JACKBRIDGE_DUMMY)
  738. #elif defined(JACKBRIDGE_DIRECT)
  739. return jack_get_client_name(client);
  740. #else
  741. if (getBridgeInstance().get_client_name_ptr != nullptr)
  742. return getBridgeInstance().get_client_name_ptr(client);
  743. #endif
  744. return nullptr;
  745. }
  746. // -----------------------------------------------------------------------------
  747. char* jackbridge_client_get_uuid(jack_client_t* client)
  748. {
  749. #if defined(JACKBRIDGE_DUMMY)
  750. #elif defined(JACKBRIDGE_DIRECT)
  751. return jack_client_get_uuid(client);
  752. #else
  753. if (const jacksym_client_get_uuid func = getBridgeInstance().client_get_uuid_ptr)
  754. return func(client);
  755. #endif
  756. return nullptr;
  757. }
  758. char* jackbridge_get_uuid_for_client_name(jack_client_t* client, const char* name)
  759. {
  760. #if defined(JACKBRIDGE_DUMMY)
  761. #elif defined(JACKBRIDGE_DIRECT)
  762. return jack_get_uuid_for_client_name(client, name);
  763. #else
  764. if (getBridgeInstance().get_uuid_for_client_name_ptr != nullptr)
  765. return getBridgeInstance().get_uuid_for_client_name_ptr(client, name);
  766. #endif
  767. return nullptr;
  768. }
  769. char* jackbridge_get_client_name_by_uuid(jack_client_t* client, const char* uuid)
  770. {
  771. #if defined(JACKBRIDGE_DUMMY)
  772. #elif defined(JACKBRIDGE_DIRECT)
  773. return jack_get_client_name_by_uuid(client, uuid);
  774. #else
  775. if (getBridgeInstance().get_client_name_by_uuid_ptr != nullptr)
  776. return getBridgeInstance().get_client_name_by_uuid_ptr(client, uuid);
  777. #endif
  778. return nullptr;
  779. }
  780. // -----------------------------------------------------------------------------
  781. bool jackbridge_uuid_parse(const char* buf, jack_uuid_t* uuid)
  782. {
  783. #if defined(JACKBRIDGE_DUMMY)
  784. #elif defined(JACKBRIDGE_DIRECT)
  785. return (jack_uuid_parse(buf, uuid) == 0);
  786. #else
  787. if (const jacksym_uuid_parse func = getBridgeInstance().uuid_parse_ptr)
  788. return (func(buf, uuid) == 0);
  789. #endif
  790. return false;
  791. }
  792. // -----------------------------------------------------------------------------
  793. bool jackbridge_activate(jack_client_t* client)
  794. {
  795. #if defined(JACKBRIDGE_DUMMY)
  796. #elif defined(JACKBRIDGE_DIRECT)
  797. return (jack_activate(client) == 0);
  798. #else
  799. if (getBridgeInstance().activate_ptr != nullptr)
  800. return (getBridgeInstance().activate_ptr(client) == 0);
  801. #endif
  802. return false;
  803. }
  804. bool jackbridge_deactivate(jack_client_t* client)
  805. {
  806. #if defined(JACKBRIDGE_DUMMY)
  807. #elif defined(JACKBRIDGE_DIRECT)
  808. return (jack_deactivate(client) == 0);
  809. #else
  810. if (getBridgeInstance().deactivate_ptr != nullptr)
  811. return (getBridgeInstance().deactivate_ptr(client) == 0);
  812. #endif
  813. return false;
  814. }
  815. bool jackbridge_is_realtime(jack_client_t* client)
  816. {
  817. #if defined(JACKBRIDGE_DUMMY)
  818. #elif defined(JACKBRIDGE_DIRECT)
  819. return jack_is_realtime(client);
  820. #else
  821. if (getBridgeInstance().is_realtime_ptr != nullptr)
  822. return getBridgeInstance().is_realtime_ptr(client);
  823. #endif
  824. return false;
  825. }
  826. // -----------------------------------------------------------------------------
  827. bool jackbridge_set_thread_init_callback(jack_client_t* client, JackThreadInitCallback thread_init_callback, void* arg)
  828. {
  829. #if defined(JACKBRIDGE_DUMMY)
  830. #elif defined(JACKBRIDGE_DIRECT)
  831. return (jack_set_thread_init_callback(client, thread_init_callback, arg) == 0);
  832. #else
  833. if (getBridgeInstance().set_thread_init_callback_ptr != nullptr)
  834. {
  835. # ifdef __WINE__
  836. WineBridge::getInstance().set_thread_init(thread_init_callback);
  837. return (getBridgeInstance().set_thread_init_callback_ptr(client, WineBridge::thread_init, arg) == 0);
  838. # else
  839. return (getBridgeInstance().set_thread_init_callback_ptr(client, thread_init_callback, arg) == 0);
  840. # endif
  841. }
  842. #endif
  843. return false;
  844. }
  845. void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg)
  846. {
  847. #if defined(JACKBRIDGE_DUMMY)
  848. #elif defined(JACKBRIDGE_DIRECT)
  849. jack_on_shutdown(client, shutdown_callback, arg);
  850. #else
  851. if (getBridgeInstance().on_shutdown_ptr != nullptr)
  852. {
  853. # ifdef __WINE__
  854. WineBridge::getInstance().set_shutdown(shutdown_callback);
  855. getBridgeInstance().on_shutdown_ptr(client, WineBridge::shutdown, arg);
  856. # else
  857. getBridgeInstance().on_shutdown_ptr(client, shutdown_callback, arg);
  858. # endif
  859. }
  860. #endif
  861. }
  862. void jackbridge_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg)
  863. {
  864. #if defined(JACKBRIDGE_DUMMY)
  865. #elif defined(JACKBRIDGE_DIRECT)
  866. jack_on_info_shutdown(client, shutdown_callback, arg);
  867. #else
  868. if (getBridgeInstance().on_info_shutdown_ptr != nullptr)
  869. {
  870. # ifdef __WINE__
  871. WineBridge::getInstance().set_info_shutdown(shutdown_callback);
  872. getBridgeInstance().on_info_shutdown_ptr(client, WineBridge::info_shutdown, arg);
  873. # else
  874. getBridgeInstance().on_info_shutdown_ptr(client, shutdown_callback, arg);
  875. # endif
  876. }
  877. #endif
  878. }
  879. bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg)
  880. {
  881. #if defined(JACKBRIDGE_DUMMY)
  882. #elif defined(JACKBRIDGE_DIRECT)
  883. return (jack_set_process_callback(client, process_callback, arg) == 0);
  884. #else
  885. if (getBridgeInstance().set_process_callback_ptr != nullptr)
  886. {
  887. # ifdef __WINE__
  888. WineBridge::getInstance().set_process(process_callback);
  889. return (getBridgeInstance().set_process_callback_ptr(client, WineBridge::process, arg) == 0);
  890. # else
  891. return (getBridgeInstance().set_process_callback_ptr(client, process_callback, arg) == 0);
  892. # endif
  893. }
  894. #endif
  895. return false;
  896. }
  897. bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg)
  898. {
  899. #if defined(JACKBRIDGE_DUMMY)
  900. #elif defined(JACKBRIDGE_DIRECT)
  901. return (jack_set_freewheel_callback(client, freewheel_callback, arg) == 0);
  902. #else
  903. if (getBridgeInstance().set_freewheel_callback_ptr != nullptr)
  904. {
  905. # ifdef __WINE__
  906. WineBridge::getInstance().set_freewheel(freewheel_callback);
  907. return (getBridgeInstance().set_freewheel_callback_ptr(client, WineBridge::freewheel, arg) == 0);
  908. # else
  909. return (getBridgeInstance().set_freewheel_callback_ptr(client, freewheel_callback, arg) == 0);
  910. # endif
  911. }
  912. #endif
  913. return false;
  914. }
  915. bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg)
  916. {
  917. #if defined(JACKBRIDGE_DUMMY)
  918. #elif defined(JACKBRIDGE_DIRECT)
  919. return (jack_set_buffer_size_callback(client, bufsize_callback, arg) == 0);
  920. #else
  921. if (getBridgeInstance().set_buffer_size_callback_ptr != nullptr)
  922. {
  923. # ifdef __WINE__
  924. WineBridge::getInstance().set_bufsize(bufsize_callback);
  925. return (getBridgeInstance().set_buffer_size_callback_ptr(client, WineBridge::bufsize, arg) == 0);
  926. # else
  927. return (getBridgeInstance().set_buffer_size_callback_ptr(client, bufsize_callback, arg) == 0);
  928. # endif
  929. }
  930. #endif
  931. return false;
  932. }
  933. bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg)
  934. {
  935. #if defined(JACKBRIDGE_DUMMY)
  936. #elif defined(JACKBRIDGE_DIRECT)
  937. return (jack_set_sample_rate_callback(client, srate_callback, arg) == 0);
  938. #else
  939. if (getBridgeInstance().set_sample_rate_callback_ptr != nullptr)
  940. {
  941. # ifdef __WINE__
  942. WineBridge::getInstance().set_srate(srate_callback);
  943. return (getBridgeInstance().set_sample_rate_callback_ptr(client, WineBridge::srate, arg) == 0);
  944. # else
  945. return (getBridgeInstance().set_sample_rate_callback_ptr(client, srate_callback, arg) == 0);
  946. # endif
  947. }
  948. #endif
  949. return false;
  950. }
  951. bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg)
  952. {
  953. #if defined(JACKBRIDGE_DUMMY)
  954. #elif defined(JACKBRIDGE_DIRECT)
  955. return (jack_set_client_registration_callback(client, registration_callback, arg) == 0);
  956. #else
  957. if (getBridgeInstance().set_client_registration_callback_ptr != nullptr)
  958. {
  959. # ifdef __WINE__
  960. WineBridge::getInstance().set_client_reg(registration_callback);
  961. return (getBridgeInstance().set_client_registration_callback_ptr(client, WineBridge::client_reg, arg) == 0);
  962. # else
  963. return (getBridgeInstance().set_client_registration_callback_ptr(client, registration_callback, arg) == 0);
  964. # endif
  965. }
  966. #endif
  967. return false;
  968. }
  969. bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void *arg)
  970. {
  971. #if defined(JACKBRIDGE_DUMMY)
  972. #elif defined(JACKBRIDGE_DIRECT)
  973. return (jack_set_port_registration_callback(client, registration_callback, arg) == 0);
  974. #else
  975. if (getBridgeInstance().set_port_registration_callback_ptr != nullptr)
  976. {
  977. # ifdef __WINE__
  978. WineBridge::getInstance().set_port_reg(registration_callback);
  979. return (getBridgeInstance().set_port_registration_callback_ptr(client, WineBridge::port_reg, arg) == 0);
  980. # else
  981. return (getBridgeInstance().set_port_registration_callback_ptr(client, registration_callback, arg) == 0);
  982. # endif
  983. }
  984. #endif
  985. return false;
  986. }
  987. bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg)
  988. {
  989. #if defined(JACKBRIDGE_DUMMY)
  990. #elif defined(JACKBRIDGE_DIRECT)
  991. return (jack_set_port_rename_callback(client, rename_callback, arg) == 0);
  992. #else
  993. if (getBridgeInstance().set_port_rename_callback_ptr != nullptr)
  994. {
  995. # ifdef __WINE__
  996. WineBridge::getInstance().set_port_rename(rename_callback);
  997. return (getBridgeInstance().set_port_rename_callback_ptr(client, WineBridge::port_rename, arg) == 0);
  998. # else
  999. return (getBridgeInstance().set_port_rename_callback_ptr(client, rename_callback, arg) == 0);
  1000. # endif
  1001. }
  1002. #endif
  1003. return false;
  1004. }
  1005. bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg)
  1006. {
  1007. #if defined(JACKBRIDGE_DUMMY)
  1008. #elif defined(JACKBRIDGE_DIRECT)
  1009. return (jack_set_port_connect_callback(client, connect_callback, arg) == 0);
  1010. #else
  1011. if (getBridgeInstance().set_port_connect_callback_ptr != nullptr)
  1012. {
  1013. # ifdef __WINE__
  1014. WineBridge::getInstance().set_port_conn(connect_callback);
  1015. return (getBridgeInstance().set_port_connect_callback_ptr(client, WineBridge::port_conn, arg) == 0);
  1016. # else
  1017. return (getBridgeInstance().set_port_connect_callback_ptr(client, connect_callback, arg) == 0);
  1018. # endif
  1019. }
  1020. #endif
  1021. return false;
  1022. }
  1023. bool jackbridge_set_graph_order_callback(jack_client_t* client, JackGraphOrderCallback graph_callback, void* arg)
  1024. {
  1025. #if defined(JACKBRIDGE_DUMMY)
  1026. #elif defined(JACKBRIDGE_DIRECT)
  1027. return (jack_set_graph_order_callback(client, graph_callback, arg) == 0);
  1028. #else
  1029. if (getBridgeInstance().set_graph_order_callback_ptr != nullptr)
  1030. {
  1031. # ifdef __WINE__
  1032. WineBridge::getInstance().set_graph_order(graph_callback);
  1033. return (getBridgeInstance().set_graph_order_callback_ptr(client, WineBridge::graph_order, arg) == 0);
  1034. # else
  1035. return (getBridgeInstance().set_graph_order_callback_ptr(client, graph_callback, arg) == 0);
  1036. # endif
  1037. }
  1038. #endif
  1039. return false;
  1040. }
  1041. bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg)
  1042. {
  1043. #if defined(JACKBRIDGE_DUMMY)
  1044. #elif defined(JACKBRIDGE_DIRECT)
  1045. return (jack_set_xrun_callback(client, xrun_callback, arg) == 0);
  1046. #else
  1047. if (getBridgeInstance().set_xrun_callback_ptr != nullptr)
  1048. {
  1049. # ifdef __WINE__
  1050. WineBridge::getInstance().set_xrun(xrun_callback);
  1051. return (getBridgeInstance().set_xrun_callback_ptr(client, WineBridge::xrun, arg) == 0);
  1052. # else
  1053. return (getBridgeInstance().set_xrun_callback_ptr(client, xrun_callback, arg) == 0);
  1054. # endif
  1055. }
  1056. #endif
  1057. return false;
  1058. }
  1059. bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg)
  1060. {
  1061. #if defined(JACKBRIDGE_DUMMY)
  1062. #elif defined(JACKBRIDGE_DIRECT)
  1063. return (jack_set_latency_callback(client, latency_callback, arg) == 0);
  1064. #else
  1065. if (getBridgeInstance().set_latency_callback_ptr != nullptr)
  1066. {
  1067. # ifdef __WINE__
  1068. WineBridge::getInstance().set_latency(latency_callback);
  1069. return (getBridgeInstance().set_latency_callback_ptr(client, WineBridge::latency, arg) == 0);
  1070. # else
  1071. return (getBridgeInstance().set_latency_callback_ptr(client, latency_callback, arg) == 0);
  1072. # endif
  1073. }
  1074. #endif
  1075. return false;
  1076. }
  1077. // -----------------------------------------------------------------------------
  1078. bool jackbridge_set_freewheel(jack_client_t* client, bool onoff)
  1079. {
  1080. #if defined(JACKBRIDGE_DUMMY)
  1081. #elif defined(JACKBRIDGE_DIRECT)
  1082. return jack_set_freewheel(client, onoff);
  1083. #else
  1084. if (getBridgeInstance().set_freewheel_ptr != nullptr)
  1085. return getBridgeInstance().set_freewheel_ptr(client, onoff);
  1086. #endif
  1087. return false;
  1088. }
  1089. bool jackbridge_set_buffer_size(jack_client_t* client, jack_nframes_t nframes)
  1090. {
  1091. #if defined(JACKBRIDGE_DUMMY)
  1092. #elif defined(JACKBRIDGE_DIRECT)
  1093. return jack_set_buffer_size(client, nframes);
  1094. #else
  1095. if (getBridgeInstance().set_buffer_size_ptr != nullptr)
  1096. return getBridgeInstance().set_buffer_size_ptr(client, nframes);
  1097. #endif
  1098. return false;
  1099. }
  1100. // -----------------------------------------------------------------------------
  1101. jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client)
  1102. {
  1103. #if defined(JACKBRIDGE_DUMMY)
  1104. #elif defined(JACKBRIDGE_DIRECT)
  1105. return jack_get_sample_rate(client);
  1106. #else
  1107. if (getBridgeInstance().get_sample_rate_ptr != nullptr)
  1108. return getBridgeInstance().get_sample_rate_ptr(client);
  1109. #endif
  1110. return 0;
  1111. }
  1112. jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client)
  1113. {
  1114. #if defined(JACKBRIDGE_DUMMY)
  1115. #elif defined(JACKBRIDGE_DIRECT)
  1116. return jack_get_buffer_size(client);
  1117. #else
  1118. if (getBridgeInstance().get_buffer_size_ptr != nullptr)
  1119. return getBridgeInstance().get_buffer_size_ptr(client);
  1120. #endif
  1121. return 0;
  1122. }
  1123. float jackbridge_cpu_load(jack_client_t* client)
  1124. {
  1125. #if defined(JACKBRIDGE_DUMMY)
  1126. #elif defined(JACKBRIDGE_DIRECT)
  1127. return jack_cpu_load(client);
  1128. #else
  1129. if (getBridgeInstance().cpu_load_ptr != nullptr)
  1130. return getBridgeInstance().cpu_load_ptr(client);
  1131. #endif
  1132. return 0.0f;
  1133. }
  1134. // -----------------------------------------------------------------------------
  1135. jack_port_t* jackbridge_port_register(jack_client_t* client, const char* port_name, const char* port_type, uint64_t flags, uint64_t buffer_size)
  1136. {
  1137. #if defined(JACKBRIDGE_DUMMY)
  1138. #elif defined(JACKBRIDGE_DIRECT)
  1139. return jack_port_register(client, port_name, port_type, flags, buffer_size);
  1140. #else
  1141. if (getBridgeInstance().port_register_ptr != nullptr)
  1142. return getBridgeInstance().port_register_ptr(client, port_name, port_type,
  1143. static_cast<ulong>(flags),
  1144. static_cast<ulong>(buffer_size));
  1145. #endif
  1146. return nullptr;
  1147. }
  1148. bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port)
  1149. {
  1150. #if defined(JACKBRIDGE_DUMMY)
  1151. #elif defined(JACKBRIDGE_DIRECT)
  1152. return (jack_port_unregister(client, port) == 0);
  1153. #else
  1154. if (getBridgeInstance().port_unregister_ptr != nullptr)
  1155. return (getBridgeInstance().port_unregister_ptr(client, port) == 0);
  1156. #endif
  1157. return false;
  1158. }
  1159. void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes)
  1160. {
  1161. #if defined(JACKBRIDGE_DUMMY)
  1162. #elif defined(JACKBRIDGE_DIRECT)
  1163. return jack_port_get_buffer(port, nframes);
  1164. #else
  1165. if (getBridgeInstance().port_get_buffer_ptr != nullptr)
  1166. return getBridgeInstance().port_get_buffer_ptr(port, nframes);
  1167. #endif
  1168. return nullptr;
  1169. }
  1170. // -----------------------------------------------------------------------------
  1171. const char* jackbridge_port_name(const jack_port_t* port)
  1172. {
  1173. #if defined(JACKBRIDGE_DUMMY)
  1174. #elif defined(JACKBRIDGE_DIRECT)
  1175. return jack_port_name(port);
  1176. #else
  1177. if (getBridgeInstance().port_name_ptr != nullptr)
  1178. return getBridgeInstance().port_name_ptr(port);
  1179. #endif
  1180. return nullptr;
  1181. }
  1182. jack_uuid_t jackbridge_port_uuid(const jack_port_t* port)
  1183. {
  1184. #if defined(JACKBRIDGE_DUMMY)
  1185. #elif defined(JACKBRIDGE_DIRECT)
  1186. return jack_port_uuid(port);
  1187. #else
  1188. if (getBridgeInstance().port_uuid_ptr != nullptr)
  1189. return getBridgeInstance().port_uuid_ptr(port);
  1190. #endif
  1191. return 0;
  1192. }
  1193. const char* jackbridge_port_short_name(const jack_port_t* port)
  1194. {
  1195. #if defined(JACKBRIDGE_DUMMY)
  1196. #elif defined(JACKBRIDGE_DIRECT)
  1197. return jack_port_short_name(port);
  1198. #else
  1199. if (getBridgeInstance().port_short_name_ptr != nullptr)
  1200. return getBridgeInstance().port_short_name_ptr(port);
  1201. #endif
  1202. return nullptr;
  1203. }
  1204. int jackbridge_port_flags(const jack_port_t* port)
  1205. {
  1206. #if defined(JACKBRIDGE_DUMMY)
  1207. #elif defined(JACKBRIDGE_DIRECT)
  1208. return jack_port_flags(port);
  1209. #else
  1210. if (getBridgeInstance().port_flags_ptr != nullptr)
  1211. return getBridgeInstance().port_flags_ptr(port);
  1212. #endif
  1213. return 0x0;
  1214. }
  1215. const char* jackbridge_port_type(const jack_port_t* port)
  1216. {
  1217. #if defined(JACKBRIDGE_DUMMY)
  1218. #elif defined(JACKBRIDGE_DIRECT)
  1219. return jack_port_type(port);
  1220. #else
  1221. if (getBridgeInstance().port_type_ptr != nullptr)
  1222. return getBridgeInstance().port_type_ptr(port);
  1223. #endif
  1224. return nullptr;
  1225. }
  1226. bool jackbridge_port_is_mine(const jack_client_t* client, const jack_port_t* port)
  1227. {
  1228. #if defined(JACKBRIDGE_DUMMY)
  1229. #elif defined(JACKBRIDGE_DIRECT)
  1230. return jack_port_is_mine(client, port);
  1231. #else
  1232. if (getBridgeInstance().port_is_mine_ptr != nullptr)
  1233. return getBridgeInstance().port_is_mine_ptr(client, port);
  1234. #endif
  1235. return false;
  1236. }
  1237. int jackbridge_port_connected(const jack_port_t* port)
  1238. {
  1239. #if defined(JACKBRIDGE_DUMMY)
  1240. #elif defined(JACKBRIDGE_DIRECT)
  1241. return jack_port_connected(port);
  1242. #else
  1243. if (getBridgeInstance().port_connected_ptr != nullptr)
  1244. return getBridgeInstance().port_connected_ptr(port);
  1245. #endif
  1246. return 0;
  1247. }
  1248. bool jackbridge_port_connected_to(const jack_port_t* port, const char* port_name)
  1249. {
  1250. #if defined(JACKBRIDGE_DUMMY)
  1251. #elif defined(JACKBRIDGE_DIRECT)
  1252. return jack_port_connected_to(port, port_name);
  1253. #else
  1254. if (getBridgeInstance().port_connected_to_ptr != nullptr)
  1255. return getBridgeInstance().port_connected_to_ptr(port, port_name);
  1256. #endif
  1257. return false;
  1258. }
  1259. const char** jackbridge_port_get_connections(const jack_port_t* port)
  1260. {
  1261. #if defined(JACKBRIDGE_DUMMY)
  1262. #elif defined(JACKBRIDGE_DIRECT)
  1263. return jack_port_get_connections(port);
  1264. #else
  1265. if (getBridgeInstance().port_get_connections_ptr != nullptr)
  1266. return getBridgeInstance().port_get_connections_ptr(port);
  1267. #endif
  1268. return nullptr;
  1269. }
  1270. const char** jackbridge_port_get_all_connections(const jack_client_t* client, const jack_port_t* port)
  1271. {
  1272. #if defined(JACKBRIDGE_DUMMY)
  1273. #elif defined(JACKBRIDGE_DIRECT)
  1274. return jack_port_get_all_connections(client, port);
  1275. #else
  1276. if (getBridgeInstance().port_get_all_connections_ptr != nullptr)
  1277. return getBridgeInstance().port_get_all_connections_ptr(client, port);
  1278. #endif
  1279. return nullptr;
  1280. }
  1281. // -----------------------------------------------------------------------------
  1282. bool jackbridge_port_rename(jack_client_t* client, jack_port_t* port, const char* port_name)
  1283. {
  1284. #if defined(JACKBRIDGE_DUMMY)
  1285. #elif defined(JACKBRIDGE_DIRECT)
  1286. return (jack_port_rename(client, port, port_name) == 0);
  1287. #else
  1288. // Try new API first
  1289. if (getBridgeInstance().port_rename_ptr != nullptr)
  1290. return (getBridgeInstance().port_rename_ptr(client, port, port_name) == 0);
  1291. // Try old API if using JACK2
  1292. if (getBridgeInstance().get_version_string_ptr != nullptr && getBridgeInstance().port_set_name_ptr != nullptr)
  1293. return (getBridgeInstance().port_set_name_ptr(port, port_name) == 0);
  1294. #endif
  1295. return false;
  1296. }
  1297. bool jackbridge_port_set_alias(jack_port_t* port, const char* alias)
  1298. {
  1299. #if defined(JACKBRIDGE_DUMMY)
  1300. #elif defined(JACKBRIDGE_DIRECT)
  1301. return (jack_port_set_alias(port, alias) == 0);
  1302. #else
  1303. if (getBridgeInstance().port_set_alias_ptr != nullptr)
  1304. return (getBridgeInstance().port_set_alias_ptr(port, alias) == 0);
  1305. #endif
  1306. return false;
  1307. }
  1308. bool jackbridge_port_unset_alias(jack_port_t* port, const char* alias)
  1309. {
  1310. #if defined(JACKBRIDGE_DUMMY)
  1311. #elif defined(JACKBRIDGE_DIRECT)
  1312. return (jack_port_unset_alias(port, alias) == 0);
  1313. #else
  1314. if (getBridgeInstance().port_unset_alias_ptr != nullptr)
  1315. return (getBridgeInstance().port_unset_alias_ptr(port, alias) == 0);
  1316. #endif
  1317. return false;
  1318. }
  1319. int jackbridge_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  1320. {
  1321. #if defined(JACKBRIDGE_DUMMY)
  1322. #elif defined(JACKBRIDGE_DIRECT)
  1323. return (jack_port_get_aliases(port, aliases) == 0);
  1324. #else
  1325. if (getBridgeInstance().port_get_aliases_ptr != nullptr)
  1326. return getBridgeInstance().port_get_aliases_ptr(port, aliases);
  1327. #endif
  1328. return 0;
  1329. }
  1330. // -----------------------------------------------------------------------------
  1331. bool jackbridge_port_request_monitor(jack_port_t* port, bool onoff)
  1332. {
  1333. #if defined(JACKBRIDGE_DUMMY)
  1334. #elif defined(JACKBRIDGE_DIRECT)
  1335. return (jack_port_request_monitor(port, onoff) == 0);
  1336. #else
  1337. if (getBridgeInstance().port_request_monitor_ptr != nullptr)
  1338. return (getBridgeInstance().port_request_monitor_ptr(port, onoff) == 0);
  1339. #endif
  1340. return false;
  1341. }
  1342. bool jackbridge_port_request_monitor_by_name(jack_client_t* client, const char* port_name, bool onoff)
  1343. {
  1344. #if defined(JACKBRIDGE_DUMMY)
  1345. #elif defined(JACKBRIDGE_DIRECT)
  1346. return (jack_port_request_monitor_by_name(client, port_name, onoff) == 0);
  1347. #else
  1348. if (getBridgeInstance().port_request_monitor_by_name_ptr != nullptr)
  1349. return (getBridgeInstance().port_request_monitor_by_name_ptr(client, port_name, onoff) == 0);
  1350. #endif
  1351. return false;
  1352. }
  1353. bool jackbridge_port_ensure_monitor(jack_port_t* port, bool onoff)
  1354. {
  1355. #if defined(JACKBRIDGE_DUMMY)
  1356. #elif defined(JACKBRIDGE_DIRECT)
  1357. return (jack_port_ensure_monitor(port, onoff) == 0);
  1358. #else
  1359. if (getBridgeInstance().port_ensure_monitor_ptr != nullptr)
  1360. return (getBridgeInstance().port_ensure_monitor_ptr(port, onoff) == 0);
  1361. #endif
  1362. return false;
  1363. }
  1364. bool jackbridge_port_monitoring_input(jack_port_t* port)
  1365. {
  1366. #if defined(JACKBRIDGE_DUMMY)
  1367. #elif defined(JACKBRIDGE_DIRECT)
  1368. return jack_port_monitoring_input(port);
  1369. #else
  1370. if (getBridgeInstance().port_monitoring_input_ptr != nullptr)
  1371. return getBridgeInstance().port_monitoring_input_ptr(port);
  1372. #endif
  1373. return false;
  1374. }
  1375. // -----------------------------------------------------------------------------
  1376. bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port)
  1377. {
  1378. #if defined(JACKBRIDGE_DUMMY)
  1379. #elif defined(JACKBRIDGE_DIRECT)
  1380. return (jack_connect(client, source_port, destination_port) == 0);
  1381. #else
  1382. if (getBridgeInstance().connect_ptr != nullptr)
  1383. {
  1384. const int ret = getBridgeInstance().connect_ptr(client, source_port, destination_port);
  1385. return ret == 0 || ret == EEXIST;
  1386. }
  1387. #endif
  1388. return false;
  1389. }
  1390. bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port)
  1391. {
  1392. #if defined(JACKBRIDGE_DUMMY)
  1393. #elif defined(JACKBRIDGE_DIRECT)
  1394. return (jack_disconnect(client, source_port, destination_port) == 0);
  1395. #else
  1396. if (getBridgeInstance().disconnect_ptr != nullptr)
  1397. return (getBridgeInstance().disconnect_ptr(client, source_port, destination_port) == 0);
  1398. #endif
  1399. return false;
  1400. }
  1401. bool jackbridge_port_disconnect(jack_client_t* client, jack_port_t* port)
  1402. {
  1403. #if defined(JACKBRIDGE_DUMMY)
  1404. #elif defined(JACKBRIDGE_DIRECT)
  1405. return (jack_port_disconnect(client, port) == 0);
  1406. #else
  1407. if (getBridgeInstance().port_disconnect_ptr != nullptr)
  1408. return (getBridgeInstance().port_disconnect_ptr(client, port) == 0);
  1409. #endif
  1410. return false;
  1411. }
  1412. // -----------------------------------------------------------------------------
  1413. int jackbridge_port_name_size()
  1414. {
  1415. #if defined(JACKBRIDGE_DUMMY)
  1416. #elif defined(JACKBRIDGE_DIRECT)
  1417. return jack_port_name_size();
  1418. #else
  1419. if (getBridgeInstance().port_name_size_ptr != nullptr)
  1420. return getBridgeInstance().port_name_size_ptr();
  1421. #endif
  1422. return 256;
  1423. }
  1424. int jackbridge_port_type_size()
  1425. {
  1426. #if defined(JACKBRIDGE_DUMMY)
  1427. #elif defined(JACKBRIDGE_DIRECT)
  1428. return jack_port_type_size();
  1429. #else
  1430. if (getBridgeInstance().port_type_size_ptr != nullptr)
  1431. return getBridgeInstance().port_type_size_ptr();
  1432. #endif
  1433. return 32;
  1434. }
  1435. uint32_t jackbridge_port_type_get_buffer_size(jack_client_t* client, const char* port_type)
  1436. {
  1437. #if defined(JACKBRIDGE_DUMMY)
  1438. #elif defined(JACKBRIDGE_DIRECT)
  1439. return static_cast<uint32_t>(jack_port_type_get_buffer_size(client, port_type));
  1440. #else
  1441. if (getBridgeInstance().port_type_get_buffer_size_ptr != nullptr)
  1442. return static_cast<uint32_t>(getBridgeInstance().port_type_get_buffer_size_ptr(client, port_type));
  1443. #endif
  1444. return 0;
  1445. }
  1446. // -----------------------------------------------------------------------------
  1447. void jackbridge_port_get_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range)
  1448. {
  1449. #if defined(JACKBRIDGE_DUMMY)
  1450. #elif defined(JACKBRIDGE_DIRECT)
  1451. return jack_port_get_latency_range(port, static_cast<jack_latency_callback_mode_t>(mode), range);
  1452. #else
  1453. if (getBridgeInstance().port_get_latency_range_ptr != nullptr)
  1454. return getBridgeInstance().port_get_latency_range_ptr(port,
  1455. static_cast<jack_latency_callback_mode_t>(mode),
  1456. range);
  1457. #endif
  1458. range->min = 0;
  1459. range->max = 0;
  1460. }
  1461. void jackbridge_port_set_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range)
  1462. {
  1463. #if defined(JACKBRIDGE_DUMMY)
  1464. #elif defined(JACKBRIDGE_DIRECT)
  1465. jack_port_set_latency_range(port, static_cast<jack_latency_callback_mode_t>(mode), range);
  1466. #else
  1467. if (getBridgeInstance().port_set_latency_range_ptr != nullptr)
  1468. getBridgeInstance().port_set_latency_range_ptr(port,
  1469. static_cast<jack_latency_callback_mode_t>(mode),
  1470. range);
  1471. #endif
  1472. }
  1473. bool jackbridge_recompute_total_latencies(jack_client_t* client)
  1474. {
  1475. #if defined(JACKBRIDGE_DUMMY)
  1476. #elif defined(JACKBRIDGE_DIRECT)
  1477. return (jack_recompute_total_latencies(client) == 0);
  1478. #else
  1479. if (getBridgeInstance().recompute_total_latencies_ptr != nullptr)
  1480. return (getBridgeInstance().recompute_total_latencies_ptr(client) == 0);
  1481. #endif
  1482. return false;
  1483. }
  1484. // -----------------------------------------------------------------------------
  1485. const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, uint64_t flags)
  1486. {
  1487. #if defined(JACKBRIDGE_DUMMY)
  1488. #elif defined(JACKBRIDGE_DIRECT)
  1489. return jack_get_ports(client, port_name_pattern, type_name_pattern, flags);
  1490. #else
  1491. if (getBridgeInstance().get_ports_ptr != nullptr)
  1492. return getBridgeInstance().get_ports_ptr(client, port_name_pattern, type_name_pattern,
  1493. static_cast<ulong>(flags));
  1494. #endif
  1495. return nullptr;
  1496. }
  1497. jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name)
  1498. {
  1499. #if defined(JACKBRIDGE_DUMMY)
  1500. #elif defined(JACKBRIDGE_DIRECT)
  1501. return jack_port_by_name(client, port_name);
  1502. #else
  1503. if (getBridgeInstance().port_by_name_ptr != nullptr)
  1504. return getBridgeInstance().port_by_name_ptr(client, port_name);
  1505. #endif
  1506. return nullptr;
  1507. }
  1508. jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id)
  1509. {
  1510. #if defined(JACKBRIDGE_DUMMY)
  1511. #elif defined(JACKBRIDGE_DIRECT)
  1512. return jack_port_by_id(client, port_id);
  1513. #else
  1514. if (getBridgeInstance().port_by_id_ptr != nullptr)
  1515. return getBridgeInstance().port_by_id_ptr(client, port_id);
  1516. #endif
  1517. return nullptr;
  1518. }
  1519. // -----------------------------------------------------------------------------
  1520. void jackbridge_free(void* ptr)
  1521. {
  1522. #if defined(JACKBRIDGE_DUMMY)
  1523. #elif defined(JACKBRIDGE_DIRECT)
  1524. return jack_free(ptr);
  1525. #else
  1526. if (getBridgeInstance().free_ptr != nullptr)
  1527. return getBridgeInstance().free_ptr(ptr);
  1528. // just in case
  1529. std::free(ptr);
  1530. #endif
  1531. }
  1532. // -----------------------------------------------------------------------------
  1533. uint32_t jackbridge_midi_get_event_count(void* port_buffer)
  1534. {
  1535. #if defined(JACKBRIDGE_DUMMY)
  1536. #elif defined(JACKBRIDGE_DIRECT)
  1537. return jack_midi_get_event_count(port_buffer);
  1538. #else
  1539. if (getBridgeInstance().midi_get_event_count_ptr != nullptr)
  1540. return getBridgeInstance().midi_get_event_count_ptr(port_buffer);
  1541. #endif
  1542. return 0;
  1543. }
  1544. bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index)
  1545. {
  1546. #if defined(JACKBRIDGE_DUMMY)
  1547. #elif defined(JACKBRIDGE_DIRECT)
  1548. return (jack_midi_event_get(event, port_buffer, event_index) == 0);
  1549. #else
  1550. if (getBridgeInstance().midi_event_get_ptr != nullptr)
  1551. return (getBridgeInstance().midi_event_get_ptr(event, port_buffer, event_index) == 0);
  1552. #endif
  1553. return false;
  1554. }
  1555. void jackbridge_midi_clear_buffer(void* port_buffer)
  1556. {
  1557. #if defined(JACKBRIDGE_DUMMY)
  1558. #elif defined(JACKBRIDGE_DIRECT)
  1559. jack_midi_clear_buffer(port_buffer);
  1560. #else
  1561. if (getBridgeInstance().midi_clear_buffer_ptr != nullptr)
  1562. getBridgeInstance().midi_clear_buffer_ptr(port_buffer);
  1563. #endif
  1564. }
  1565. bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, uint32_t data_size)
  1566. {
  1567. #if defined(JACKBRIDGE_DUMMY)
  1568. #elif defined(JACKBRIDGE_DIRECT)
  1569. return (jack_midi_event_write(port_buffer, time, data, data_size) == 0);
  1570. #else
  1571. if (getBridgeInstance().midi_event_write_ptr != nullptr)
  1572. return (getBridgeInstance().midi_event_write_ptr(port_buffer, time, data, data_size) == 0);
  1573. #endif
  1574. return false;
  1575. }
  1576. jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, uint32_t data_size)
  1577. {
  1578. #if defined(JACKBRIDGE_DUMMY)
  1579. #elif defined(JACKBRIDGE_DIRECT)
  1580. return jack_midi_event_reserve(port_buffer, time, data_size);
  1581. #else
  1582. if (getBridgeInstance().midi_event_reserve_ptr != nullptr)
  1583. return getBridgeInstance().midi_event_reserve_ptr(port_buffer, time, data_size);
  1584. #endif
  1585. return nullptr;
  1586. }
  1587. // -----------------------------------------------------------------------------
  1588. bool jackbridge_release_timebase(jack_client_t* client)
  1589. {
  1590. #if defined(JACKBRIDGE_DUMMY)
  1591. #elif defined(JACKBRIDGE_DIRECT)
  1592. return (jack_release_timebase(client) == 0);
  1593. #else
  1594. if (getBridgeInstance().release_timebase_ptr != nullptr)
  1595. return (getBridgeInstance().release_timebase_ptr(client) == 0);
  1596. #endif
  1597. return false;
  1598. }
  1599. bool jackbridge_set_sync_callback(jack_client_t* client, JackSyncCallback sync_callback, void* arg)
  1600. {
  1601. #if defined(JACKBRIDGE_DUMMY)
  1602. #elif defined(JACKBRIDGE_DIRECT)
  1603. return (jack_set_sync_callback(client, sync_callback, arg) == 0);
  1604. #else
  1605. if (getBridgeInstance().set_sync_callback_ptr != nullptr)
  1606. {
  1607. # ifdef __WINE__
  1608. WineBridge::getInstance().set_sync(sync_callback);
  1609. return (getBridgeInstance().set_sync_callback_ptr(client, WineBridge::sync, arg) == 0);
  1610. # else
  1611. return (getBridgeInstance().set_sync_callback_ptr(client, sync_callback, arg) == 0);
  1612. # endif
  1613. }
  1614. #endif
  1615. return false;
  1616. }
  1617. bool jackbridge_set_sync_timeout(jack_client_t* client, jack_time_t timeout)
  1618. {
  1619. #if defined(JACKBRIDGE_DUMMY)
  1620. #elif defined(JACKBRIDGE_DIRECT)
  1621. return (jack_set_sync_timeout(client, timeout) == 0);
  1622. #else
  1623. if (getBridgeInstance().set_sync_timeout_ptr != nullptr)
  1624. return (getBridgeInstance().set_sync_timeout_ptr(client, timeout) == 0);
  1625. #endif
  1626. return false;
  1627. }
  1628. bool jackbridge_set_timebase_callback(jack_client_t* client, bool conditional, JackTimebaseCallback timebase_callback, void* arg)
  1629. {
  1630. #if defined(JACKBRIDGE_DUMMY)
  1631. #elif defined(JACKBRIDGE_DIRECT)
  1632. return (jack_set_timebase_callback(client, conditional, timebase_callback, arg) == 0);
  1633. #else
  1634. if (getBridgeInstance().set_timebase_callback_ptr != nullptr)
  1635. {
  1636. # ifdef __WINE__
  1637. WineBridge::getInstance().set_timebase(timebase_callback);
  1638. return (getBridgeInstance().set_timebase_callback_ptr(client, conditional, WineBridge::timebase, arg) == 0);
  1639. # else
  1640. return (getBridgeInstance().set_timebase_callback_ptr(client, conditional, timebase_callback, arg) == 0);
  1641. # endif
  1642. }
  1643. #endif
  1644. return false;
  1645. }
  1646. bool jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame)
  1647. {
  1648. #if defined(JACKBRIDGE_DUMMY)
  1649. #elif defined(JACKBRIDGE_DIRECT)
  1650. return (jack_transport_locate(client, frame) == 0);
  1651. #else
  1652. if (getBridgeInstance().transport_locate_ptr != nullptr)
  1653. return (getBridgeInstance().transport_locate_ptr(client, frame) == 0);
  1654. #endif
  1655. return false;
  1656. }
  1657. uint32_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos)
  1658. {
  1659. #if defined(JACKBRIDGE_DUMMY)
  1660. #elif defined(JACKBRIDGE_DIRECT)
  1661. return jack_transport_query(client, pos);
  1662. #else
  1663. if (getBridgeInstance().transport_query_ptr != nullptr)
  1664. return getBridgeInstance().transport_query_ptr(client, pos);
  1665. #endif
  1666. if (pos != nullptr)
  1667. {
  1668. // invalidate
  1669. pos->unique_1 = 0;
  1670. pos->unique_2 = 1;
  1671. }
  1672. return JackTransportStopped;
  1673. }
  1674. jack_nframes_t jackbridge_get_current_transport_frame(const jack_client_t* client)
  1675. {
  1676. #if defined(JACKBRIDGE_DUMMY)
  1677. #elif defined(JACKBRIDGE_DIRECT)
  1678. return jack_get_current_transport_frame(client);
  1679. #else
  1680. if (getBridgeInstance().get_current_transport_frame_ptr != nullptr)
  1681. return getBridgeInstance().get_current_transport_frame_ptr(client);
  1682. #endif
  1683. return 0;
  1684. }
  1685. bool jackbridge_transport_reposition(jack_client_t* client, const jack_position_t* pos)
  1686. {
  1687. #if defined(JACKBRIDGE_DUMMY)
  1688. #elif defined(JACKBRIDGE_DIRECT)
  1689. return (jack_transport_reposition(client, pos) == 0);
  1690. #else
  1691. if (getBridgeInstance().transport_reposition_ptr != nullptr)
  1692. return (getBridgeInstance().transport_reposition_ptr(client, pos) == 0);
  1693. #endif
  1694. return false;
  1695. }
  1696. void jackbridge_transport_start(jack_client_t* client)
  1697. {
  1698. #if defined(JACKBRIDGE_DUMMY)
  1699. #elif defined(JACKBRIDGE_DIRECT)
  1700. jack_transport_start(client);
  1701. #else
  1702. if (getBridgeInstance().transport_start_ptr != nullptr)
  1703. getBridgeInstance().transport_start_ptr(client);
  1704. #endif
  1705. }
  1706. void jackbridge_transport_stop(jack_client_t* client)
  1707. {
  1708. #if defined(JACKBRIDGE_DUMMY)
  1709. #elif defined(JACKBRIDGE_DIRECT)
  1710. jack_transport_stop(client);
  1711. #else
  1712. if (getBridgeInstance().transport_stop_ptr != nullptr)
  1713. getBridgeInstance().transport_stop_ptr(client);
  1714. #endif
  1715. }
  1716. // -----------------------------------------------------------------------------
  1717. bool jackbridge_set_property(jack_client_t* client, jack_uuid_t subject, const char* key, const char* value, const char* type)
  1718. {
  1719. #if defined(JACKBRIDGE_DUMMY)
  1720. #elif defined(JACKBRIDGE_DIRECT)
  1721. return (jack_set_property(client, subject, key, value, type) == 0);
  1722. #else
  1723. if (getBridgeInstance().set_property_ptr != nullptr)
  1724. return (getBridgeInstance().set_property_ptr(client, subject, key, value, type) == 0);
  1725. #endif
  1726. return false;
  1727. }
  1728. bool jackbridge_get_property(jack_uuid_t subject, const char* key, char** value, char** type)
  1729. {
  1730. #if defined(JACKBRIDGE_DUMMY)
  1731. #elif defined(JACKBRIDGE_DIRECT)
  1732. return (jack_get_property(subject, key, value, type) == 0);
  1733. #else
  1734. if (getBridgeInstance().get_property_ptr != nullptr)
  1735. return (getBridgeInstance().get_property_ptr(subject, key, value, type) == 0);
  1736. #endif
  1737. return false;
  1738. }
  1739. void jackbridge_free_description(jack_description_t* desc, bool free_description_itself)
  1740. {
  1741. #if defined(JACKBRIDGE_DUMMY)
  1742. #elif defined(JACKBRIDGE_DIRECT)
  1743. jack_free_description(desc, free_description_itself);
  1744. #else
  1745. if (getBridgeInstance().free_description_ptr != nullptr)
  1746. getBridgeInstance().free_description_ptr(desc, free_description_itself);
  1747. #endif
  1748. }
  1749. bool jackbridge_get_properties(jack_uuid_t subject, jack_description_t* desc)
  1750. {
  1751. #if defined(JACKBRIDGE_DUMMY)
  1752. #elif defined(JACKBRIDGE_DIRECT)
  1753. return (jack_get_properties(subject, desc) == 0);
  1754. #else
  1755. if (getBridgeInstance().get_properties_ptr != nullptr)
  1756. return (getBridgeInstance().get_properties_ptr(subject, desc) == 0);
  1757. #endif
  1758. return false;
  1759. }
  1760. bool jackbridge_get_all_properties(jack_description_t** descs)
  1761. {
  1762. #if defined(JACKBRIDGE_DUMMY)
  1763. #elif defined(JACKBRIDGE_DIRECT)
  1764. return (jack_get_all_properties(descs) == 0);
  1765. #else
  1766. if (getBridgeInstance().get_all_properties_ptr != nullptr)
  1767. return (getBridgeInstance().get_all_properties_ptr(descs) == 0);
  1768. #endif
  1769. return false;
  1770. }
  1771. bool jackbridge_remove_property(jack_client_t* client, jack_uuid_t subject, const char* key)
  1772. {
  1773. #if defined(JACKBRIDGE_DUMMY)
  1774. #elif defined(JACKBRIDGE_DIRECT)
  1775. return (jack_remove_property(client, subject, key) == 0);
  1776. #else
  1777. if (getBridgeInstance().remove_property_ptr != nullptr)
  1778. return (getBridgeInstance().remove_property_ptr(client, subject, key) == 0);
  1779. #endif
  1780. return false;
  1781. }
  1782. int jackbridge_remove_properties(jack_client_t* client, jack_uuid_t subject)
  1783. {
  1784. #if defined(JACKBRIDGE_DUMMY)
  1785. #elif defined(JACKBRIDGE_DIRECT)
  1786. return jack_remove_properties(client, subject);
  1787. #else
  1788. if (getBridgeInstance().remove_properties_ptr != nullptr)
  1789. return getBridgeInstance().remove_properties_ptr(client, subject);
  1790. #endif
  1791. return 0;
  1792. }
  1793. bool jackbridge_remove_all_properties(jack_client_t* client)
  1794. {
  1795. #if defined(JACKBRIDGE_DUMMY)
  1796. #elif defined(JACKBRIDGE_DIRECT)
  1797. return (jack_remove_all_properties(client) == 0);
  1798. #else
  1799. if (getBridgeInstance().remove_all_properties_ptr != nullptr)
  1800. return (getBridgeInstance().remove_all_properties_ptr(client) == 0);
  1801. #endif
  1802. return false;
  1803. }
  1804. bool jackbridge_set_property_change_callback(jack_client_t* client, JackPropertyChangeCallback callback, void* arg)
  1805. {
  1806. #if defined(JACKBRIDGE_DUMMY)
  1807. #elif defined(JACKBRIDGE_DIRECT)
  1808. return (jack_set_property_change_callback(client, callback, arg) == 0);
  1809. #else
  1810. if (getBridgeInstance().set_property_change_callback_ptr != nullptr)
  1811. {
  1812. # ifdef __WINE__
  1813. WineBridge::getInstance().set_prop_change(callback);
  1814. return (getBridgeInstance().set_property_change_callback_ptr(client, WineBridge::prop_change, arg) == 0);
  1815. # else
  1816. return (getBridgeInstance().set_property_change_callback_ptr(client, callback, arg) == 0);
  1817. # endif
  1818. }
  1819. #endif
  1820. return false;
  1821. }
  1822. // -----------------------------------------------------------------------------