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.

2006 lines
70KB

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