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.

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