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.

2017 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. #if 0
  553. ::CreateThread(nullptr, 0, thread_creator_helper, arg, 0, nullptr);
  554. #else
  555. HANDLE handle = ::CreateThread(nullptr, 0, thread_creator_helper, arg, CREATE_SUSPENDED, nullptr);
  556. if (handle == INVALID_HANDLE_VALUE)
  557. return 1;
  558. // TODO read attrs and decide this
  559. ::SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
  560. ::ResumeThread(handle);
  561. #endif
  562. ::WaitForSingleObject(inst.creator_handle, INFINITE);
  563. *thread_id = inst.creator_pthread;
  564. return 0;
  565. }
  566. static void latency(jack_latency_callback_mode_t mode, void* arg)
  567. {
  568. return getInstance().latency_cb(mode, arg);
  569. }
  570. static int process(jack_nframes_t nframes, void* arg)
  571. {
  572. return getInstance().process_cb(nframes, arg);
  573. }
  574. static void thread_init(void* arg)
  575. {
  576. return getInstance().thread_init_cb(arg);
  577. }
  578. static int graph_order(void* arg)
  579. {
  580. return getInstance().graph_order_cb(arg);
  581. }
  582. static int xrun(void* arg)
  583. {
  584. return getInstance().xrun_cb(arg);
  585. }
  586. static int bufsize(jack_nframes_t nframes, void* arg)
  587. {
  588. return getInstance().bufsize_cb(nframes, arg);
  589. }
  590. static int srate(jack_nframes_t nframes, void* arg)
  591. {
  592. return getInstance().srate_cb(nframes, arg);
  593. }
  594. static void port_reg(jack_port_id_t port, int register_, void* arg)
  595. {
  596. return getInstance().port_reg_cb(port, register_, arg);
  597. }
  598. static void client_reg(const char* name, int register_, void* arg)
  599. {
  600. return getInstance().client_reg_cb(name, register_, arg);
  601. }
  602. static void port_conn(jack_port_id_t a, jack_port_id_t b, int connect, void* arg)
  603. {
  604. return getInstance().port_conn_cb(a, b, connect, arg);
  605. }
  606. static void port_rename(jack_port_id_t port, const char* old_name, const char* new_name, void* arg)
  607. {
  608. getInstance().port_rename_cb(port, old_name, new_name, arg);
  609. }
  610. static void freewheel(int starting, void* arg)
  611. {
  612. return getInstance().freewheel_cb(starting, arg);
  613. }
  614. static void shutdown(void* arg)
  615. {
  616. return getInstance().shutdown_cb(arg);
  617. }
  618. static void info_shutdown(jack_status_t code, const char* reason, void* arg)
  619. {
  620. return getInstance().info_shutdown_cb(code, reason, arg);
  621. }
  622. static int sync(jack_transport_state_t state, jack_position_t* pos, void* arg)
  623. {
  624. return getInstance().sync_cb(state, pos, arg);
  625. }
  626. static void timebase(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg)
  627. {
  628. return getInstance().timebase_cb(state, nframes, pos, new_pos, arg);
  629. }
  630. static void session(jack_session_event_t* event, void* arg)
  631. {
  632. return getInstance().session_cb(event, arg);
  633. }
  634. static void prop_change(jack_uuid_t subject, const char* key, jack_property_change_t change, void* arg)
  635. {
  636. return getInstance().prop_change_cb(subject, key, change, arg);
  637. }
  638. CARLA_DECLARE_NON_COPY_STRUCT(WineBridge);
  639. };
  640. #endif // __WINE__ && ! JACKBRIDGE_DIRECT
  641. // -----------------------------------------------------------------------------
  642. bool jackbridge_is_ok() noexcept
  643. {
  644. #if defined(JACKBRIDGE_DUMMY)
  645. return false;
  646. #elif defined(JACKBRIDGE_DIRECT)
  647. return true;
  648. #else
  649. return (getBridgeInstance().lib != nullptr);
  650. #endif
  651. }
  652. void jackbridge_init()
  653. {
  654. #if defined(__WINE__) && ! defined(JACKBRIDGE_DIRECT)
  655. if (getBridgeInstance().set_thread_creator_ptr != nullptr)
  656. getBridgeInstance().set_thread_creator_ptr(WineBridge::thread_creator);
  657. #endif
  658. }
  659. // -----------------------------------------------------------------------------
  660. void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr)
  661. {
  662. #if defined(JACKBRIDGE_DUMMY)
  663. #elif defined(JACKBRIDGE_DIRECT)
  664. return jack_get_version(major_ptr, minor_ptr, micro_ptr, proto_ptr);
  665. #else
  666. if (getBridgeInstance().get_version_ptr != nullptr)
  667. return getBridgeInstance().get_version_ptr(major_ptr, minor_ptr, micro_ptr, proto_ptr);
  668. #endif
  669. if (major_ptr != nullptr)
  670. *major_ptr = 0;
  671. if (minor_ptr != nullptr)
  672. *minor_ptr = 0;
  673. if (micro_ptr != nullptr)
  674. *micro_ptr = 0;
  675. if (proto_ptr != nullptr)
  676. *proto_ptr = 0;
  677. }
  678. const char* jackbridge_get_version_string()
  679. {
  680. #if defined(JACKBRIDGE_DUMMY)
  681. #elif defined(JACKBRIDGE_DIRECT)
  682. return jack_get_version_string();
  683. #else
  684. if (getBridgeInstance().get_version_string_ptr != nullptr)
  685. return getBridgeInstance().get_version_string_ptr();
  686. #endif
  687. return nullptr;
  688. }
  689. // -----------------------------------------------------------------------------
  690. jack_client_t* jackbridge_client_open(const char* client_name, uint32_t options, jack_status_t* status)
  691. {
  692. #if defined(JACKBRIDGE_DUMMY)
  693. #elif defined(JACKBRIDGE_DIRECT)
  694. return jack_client_open(client_name, static_cast<jack_options_t>(options), status);
  695. #else
  696. if (getBridgeInstance().client_open_ptr != nullptr)
  697. return getBridgeInstance().client_open_ptr(client_name, static_cast<jack_options_t>(options), status);
  698. #endif
  699. if (status != nullptr)
  700. *status = JackServerError;
  701. return nullptr;
  702. }
  703. bool jackbridge_client_close(jack_client_t* client)
  704. {
  705. #if defined(JACKBRIDGE_DUMMY)
  706. #elif defined(JACKBRIDGE_DIRECT)
  707. return (jack_client_close(client) == 0);
  708. #else
  709. if (getBridgeInstance().client_close_ptr != nullptr)
  710. return (getBridgeInstance().client_close_ptr(client) == 0);
  711. #endif
  712. return false;
  713. }
  714. // -----------------------------------------------------------------------------
  715. int jackbridge_client_name_size()
  716. {
  717. #if defined(JACKBRIDGE_DUMMY)
  718. #elif defined(JACKBRIDGE_DIRECT)
  719. return jack_client_name_size();
  720. #else
  721. if (getBridgeInstance().client_name_size_ptr != nullptr)
  722. return getBridgeInstance().client_name_size_ptr();
  723. #endif
  724. return 33;
  725. }
  726. char* jackbridge_get_client_name(jack_client_t* client)
  727. {
  728. #if defined(JACKBRIDGE_DUMMY)
  729. #elif defined(JACKBRIDGE_DIRECT)
  730. return jack_get_client_name(client);
  731. #else
  732. if (getBridgeInstance().get_client_name_ptr != nullptr)
  733. return getBridgeInstance().get_client_name_ptr(client);
  734. #endif
  735. return nullptr;
  736. }
  737. // -----------------------------------------------------------------------------
  738. char* jackbridge_get_uuid_for_client_name(jack_client_t* client, const char* name)
  739. {
  740. #if defined(JACKBRIDGE_DUMMY)
  741. #elif defined(JACKBRIDGE_DIRECT)
  742. return jack_get_uuid_for_client_name(client, name);
  743. #else
  744. if (getBridgeInstance().get_uuid_for_client_name_ptr != nullptr)
  745. return getBridgeInstance().get_uuid_for_client_name_ptr(client, name);
  746. #endif
  747. return nullptr;
  748. }
  749. char* jackbridge_get_client_name_by_uuid(jack_client_t* client, const char* uuid)
  750. {
  751. #if defined(JACKBRIDGE_DUMMY)
  752. #elif defined(JACKBRIDGE_DIRECT)
  753. return jack_get_client_name_by_uuid(client, uuid);
  754. #else
  755. if (getBridgeInstance().get_client_name_by_uuid_ptr != nullptr)
  756. return getBridgeInstance().get_client_name_by_uuid_ptr(client, uuid);
  757. #endif
  758. return nullptr;
  759. }
  760. // -----------------------------------------------------------------------------
  761. bool jackbridge_activate(jack_client_t* client)
  762. {
  763. #if defined(JACKBRIDGE_DUMMY)
  764. #elif defined(JACKBRIDGE_DIRECT)
  765. return (jack_activate(client) == 0);
  766. #else
  767. if (getBridgeInstance().activate_ptr != nullptr)
  768. return (getBridgeInstance().activate_ptr(client) == 0);
  769. #endif
  770. return false;
  771. }
  772. bool jackbridge_deactivate(jack_client_t* client)
  773. {
  774. #if defined(JACKBRIDGE_DUMMY)
  775. #elif defined(JACKBRIDGE_DIRECT)
  776. return (jack_deactivate(client) == 0);
  777. #else
  778. if (getBridgeInstance().deactivate_ptr != nullptr)
  779. return (getBridgeInstance().deactivate_ptr(client) == 0);
  780. #endif
  781. return false;
  782. }
  783. bool jackbridge_is_realtime(jack_client_t* client)
  784. {
  785. #if defined(JACKBRIDGE_DUMMY)
  786. #elif defined(JACKBRIDGE_DIRECT)
  787. return jack_is_realtime(client);
  788. #else
  789. if (getBridgeInstance().is_realtime_ptr != nullptr)
  790. return getBridgeInstance().is_realtime_ptr(client);
  791. #endif
  792. return false;
  793. }
  794. // -----------------------------------------------------------------------------
  795. bool jackbridge_set_thread_init_callback(jack_client_t* client, JackThreadInitCallback thread_init_callback, void* arg)
  796. {
  797. #if defined(JACKBRIDGE_DUMMY)
  798. #elif defined(JACKBRIDGE_DIRECT)
  799. return (jack_set_thread_init_callback(client, thread_init_callback, arg) == 0);
  800. #else
  801. if (getBridgeInstance().set_thread_init_callback_ptr != nullptr)
  802. {
  803. # ifdef __WINE__
  804. WineBridge::getInstance().set_thread_init(thread_init_callback);
  805. return (getBridgeInstance().set_thread_init_callback_ptr(client, WineBridge::thread_init, arg) == 0);
  806. # else
  807. return (getBridgeInstance().set_thread_init_callback_ptr(client, thread_init_callback, arg) == 0);
  808. # endif
  809. }
  810. #endif
  811. return false;
  812. }
  813. void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg)
  814. {
  815. #if defined(JACKBRIDGE_DUMMY)
  816. #elif defined(JACKBRIDGE_DIRECT)
  817. jack_on_shutdown(client, shutdown_callback, arg);
  818. #else
  819. if (getBridgeInstance().on_shutdown_ptr != nullptr)
  820. {
  821. # ifdef __WINE__
  822. WineBridge::getInstance().set_shutdown(shutdown_callback);
  823. getBridgeInstance().on_shutdown_ptr(client, WineBridge::shutdown, arg);
  824. # else
  825. getBridgeInstance().on_shutdown_ptr(client, shutdown_callback, arg);
  826. # endif
  827. }
  828. #endif
  829. }
  830. void jackbridge_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg)
  831. {
  832. #if defined(JACKBRIDGE_DUMMY)
  833. #elif defined(JACKBRIDGE_DIRECT)
  834. jack_on_info_shutdown(client, shutdown_callback, arg);
  835. #else
  836. if (getBridgeInstance().on_info_shutdown_ptr != nullptr)
  837. {
  838. # ifdef __WINE__
  839. WineBridge::getInstance().set_info_shutdown(shutdown_callback);
  840. getBridgeInstance().on_info_shutdown_ptr(client, WineBridge::info_shutdown, arg);
  841. # else
  842. getBridgeInstance().on_info_shutdown_ptr(client, shutdown_callback, arg);
  843. # endif
  844. }
  845. #endif
  846. }
  847. bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg)
  848. {
  849. #if defined(JACKBRIDGE_DUMMY)
  850. #elif defined(JACKBRIDGE_DIRECT)
  851. return (jack_set_process_callback(client, process_callback, arg) == 0);
  852. #else
  853. if (getBridgeInstance().set_process_callback_ptr != nullptr)
  854. {
  855. # ifdef __WINE__
  856. WineBridge::getInstance().set_process(process_callback);
  857. return (getBridgeInstance().set_process_callback_ptr(client, WineBridge::process, arg) == 0);
  858. # else
  859. return (getBridgeInstance().set_process_callback_ptr(client, process_callback, arg) == 0);
  860. # endif
  861. }
  862. #endif
  863. return false;
  864. }
  865. bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg)
  866. {
  867. #if defined(JACKBRIDGE_DUMMY)
  868. #elif defined(JACKBRIDGE_DIRECT)
  869. return (jack_set_freewheel_callback(client, freewheel_callback, arg) == 0);
  870. #else
  871. if (getBridgeInstance().set_freewheel_callback_ptr != nullptr)
  872. {
  873. # ifdef __WINE__
  874. WineBridge::getInstance().set_freewheel(freewheel_callback);
  875. return (getBridgeInstance().set_freewheel_callback_ptr(client, WineBridge::freewheel, arg) == 0);
  876. # else
  877. return (getBridgeInstance().set_freewheel_callback_ptr(client, freewheel_callback, arg) == 0);
  878. # endif
  879. }
  880. #endif
  881. return false;
  882. }
  883. bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg)
  884. {
  885. #if defined(JACKBRIDGE_DUMMY)
  886. #elif defined(JACKBRIDGE_DIRECT)
  887. return (jack_set_buffer_size_callback(client, bufsize_callback, arg) == 0);
  888. #else
  889. if (getBridgeInstance().set_buffer_size_callback_ptr != nullptr)
  890. {
  891. # ifdef __WINE__
  892. WineBridge::getInstance().set_bufsize(bufsize_callback);
  893. return (getBridgeInstance().set_buffer_size_callback_ptr(client, WineBridge::bufsize, arg) == 0);
  894. # else
  895. return (getBridgeInstance().set_buffer_size_callback_ptr(client, bufsize_callback, arg) == 0);
  896. # endif
  897. }
  898. #endif
  899. return false;
  900. }
  901. bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg)
  902. {
  903. #if defined(JACKBRIDGE_DUMMY)
  904. #elif defined(JACKBRIDGE_DIRECT)
  905. return (jack_set_sample_rate_callback(client, srate_callback, arg) == 0);
  906. #else
  907. if (getBridgeInstance().set_sample_rate_callback_ptr != nullptr)
  908. {
  909. # ifdef __WINE__
  910. WineBridge::getInstance().set_srate(srate_callback);
  911. return (getBridgeInstance().set_sample_rate_callback_ptr(client, WineBridge::srate, arg) == 0);
  912. # else
  913. return (getBridgeInstance().set_sample_rate_callback_ptr(client, srate_callback, arg) == 0);
  914. # endif
  915. }
  916. #endif
  917. return false;
  918. }
  919. bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg)
  920. {
  921. #if defined(JACKBRIDGE_DUMMY)
  922. #elif defined(JACKBRIDGE_DIRECT)
  923. return (jack_set_client_registration_callback(client, registration_callback, arg) == 0);
  924. #else
  925. if (getBridgeInstance().set_client_registration_callback_ptr != nullptr)
  926. {
  927. # ifdef __WINE__
  928. WineBridge::getInstance().set_client_reg(registration_callback);
  929. return (getBridgeInstance().set_client_registration_callback_ptr(client, WineBridge::client_reg, arg) == 0);
  930. # else
  931. return (getBridgeInstance().set_client_registration_callback_ptr(client, registration_callback, arg) == 0);
  932. # endif
  933. }
  934. #endif
  935. return false;
  936. }
  937. bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void *arg)
  938. {
  939. #if defined(JACKBRIDGE_DUMMY)
  940. #elif defined(JACKBRIDGE_DIRECT)
  941. return (jack_set_port_registration_callback(client, registration_callback, arg) == 0);
  942. #else
  943. if (getBridgeInstance().set_port_registration_callback_ptr != nullptr)
  944. {
  945. # ifdef __WINE__
  946. WineBridge::getInstance().set_port_reg(registration_callback);
  947. return (getBridgeInstance().set_port_registration_callback_ptr(client, WineBridge::port_reg, arg) == 0);
  948. # else
  949. return (getBridgeInstance().set_port_registration_callback_ptr(client, registration_callback, arg) == 0);
  950. # endif
  951. }
  952. #endif
  953. return false;
  954. }
  955. bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg)
  956. {
  957. #if defined(JACKBRIDGE_DUMMY)
  958. #elif defined(JACKBRIDGE_DIRECT)
  959. return (jack_set_port_rename_callback(client, rename_callback, arg) == 0);
  960. #else
  961. if (getBridgeInstance().set_port_rename_callback_ptr != nullptr)
  962. {
  963. # ifdef __WINE__
  964. WineBridge::getInstance().set_port_rename(rename_callback);
  965. return (getBridgeInstance().set_port_rename_callback_ptr(client, WineBridge::port_rename, arg) == 0);
  966. # else
  967. return (getBridgeInstance().set_port_rename_callback_ptr(client, rename_callback, arg) == 0);
  968. # endif
  969. }
  970. #endif
  971. return false;
  972. }
  973. bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg)
  974. {
  975. #if defined(JACKBRIDGE_DUMMY)
  976. #elif defined(JACKBRIDGE_DIRECT)
  977. return (jack_set_port_connect_callback(client, connect_callback, arg) == 0);
  978. #else
  979. if (getBridgeInstance().set_port_connect_callback_ptr != nullptr)
  980. {
  981. # ifdef __WINE__
  982. WineBridge::getInstance().set_port_conn(connect_callback);
  983. return (getBridgeInstance().set_port_connect_callback_ptr(client, WineBridge::port_conn, arg) == 0);
  984. # else
  985. return (getBridgeInstance().set_port_connect_callback_ptr(client, connect_callback, arg) == 0);
  986. # endif
  987. }
  988. #endif
  989. return false;
  990. }
  991. bool jackbridge_set_graph_order_callback(jack_client_t* client, JackGraphOrderCallback graph_callback, void* arg)
  992. {
  993. #if defined(JACKBRIDGE_DUMMY)
  994. #elif defined(JACKBRIDGE_DIRECT)
  995. return (jack_set_graph_order_callback(client, graph_callback, arg) == 0);
  996. #else
  997. if (getBridgeInstance().set_graph_order_callback_ptr != nullptr)
  998. {
  999. # ifdef __WINE__
  1000. WineBridge::getInstance().set_graph_order(graph_callback);
  1001. return (getBridgeInstance().set_graph_order_callback_ptr(client, WineBridge::graph_order, arg) == 0);
  1002. # else
  1003. return (getBridgeInstance().set_graph_order_callback_ptr(client, graph_callback, arg) == 0);
  1004. # endif
  1005. }
  1006. #endif
  1007. return false;
  1008. }
  1009. bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg)
  1010. {
  1011. #if defined(JACKBRIDGE_DUMMY)
  1012. #elif defined(JACKBRIDGE_DIRECT)
  1013. return (jack_set_xrun_callback(client, xrun_callback, arg) == 0);
  1014. #else
  1015. if (getBridgeInstance().set_xrun_callback_ptr != nullptr)
  1016. {
  1017. # ifdef __WINE__
  1018. WineBridge::getInstance().set_xrun(xrun_callback);
  1019. return (getBridgeInstance().set_xrun_callback_ptr(client, WineBridge::xrun, arg) == 0);
  1020. # else
  1021. return (getBridgeInstance().set_xrun_callback_ptr(client, xrun_callback, arg) == 0);
  1022. # endif
  1023. }
  1024. #endif
  1025. return false;
  1026. }
  1027. bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg)
  1028. {
  1029. #if defined(JACKBRIDGE_DUMMY)
  1030. #elif defined(JACKBRIDGE_DIRECT)
  1031. return (jack_set_latency_callback(client, latency_callback, arg) == 0);
  1032. #else
  1033. if (getBridgeInstance().set_latency_callback_ptr != nullptr)
  1034. {
  1035. # ifdef __WINE__
  1036. WineBridge::getInstance().set_latency(latency_callback);
  1037. return (getBridgeInstance().set_latency_callback_ptr(client, WineBridge::latency, arg) == 0);
  1038. # else
  1039. return (getBridgeInstance().set_latency_callback_ptr(client, latency_callback, arg) == 0);
  1040. # endif
  1041. }
  1042. #endif
  1043. return false;
  1044. }
  1045. // -----------------------------------------------------------------------------
  1046. bool jackbridge_set_freewheel(jack_client_t* client, bool onoff)
  1047. {
  1048. #if defined(JACKBRIDGE_DUMMY)
  1049. #elif defined(JACKBRIDGE_DIRECT)
  1050. return jack_set_freewheel(client, onoff);
  1051. #else
  1052. if (getBridgeInstance().set_freewheel_ptr != nullptr)
  1053. return getBridgeInstance().set_freewheel_ptr(client, onoff);
  1054. #endif
  1055. return false;
  1056. }
  1057. bool jackbridge_set_buffer_size(jack_client_t* client, jack_nframes_t nframes)
  1058. {
  1059. #if defined(JACKBRIDGE_DUMMY)
  1060. #elif defined(JACKBRIDGE_DIRECT)
  1061. return jack_set_buffer_size(client, nframes);
  1062. #else
  1063. if (getBridgeInstance().set_buffer_size_ptr != nullptr)
  1064. return getBridgeInstance().set_buffer_size_ptr(client, nframes);
  1065. #endif
  1066. return false;
  1067. }
  1068. // -----------------------------------------------------------------------------
  1069. jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client)
  1070. {
  1071. #if defined(JACKBRIDGE_DUMMY)
  1072. #elif defined(JACKBRIDGE_DIRECT)
  1073. return jack_get_sample_rate(client);
  1074. #else
  1075. if (getBridgeInstance().get_sample_rate_ptr != nullptr)
  1076. return getBridgeInstance().get_sample_rate_ptr(client);
  1077. #endif
  1078. return 0;
  1079. }
  1080. jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client)
  1081. {
  1082. #if defined(JACKBRIDGE_DUMMY)
  1083. #elif defined(JACKBRIDGE_DIRECT)
  1084. return jack_get_buffer_size(client);
  1085. #else
  1086. if (getBridgeInstance().get_buffer_size_ptr != nullptr)
  1087. return getBridgeInstance().get_buffer_size_ptr(client);
  1088. #endif
  1089. return 0;
  1090. }
  1091. float jackbridge_cpu_load(jack_client_t* client)
  1092. {
  1093. #if defined(JACKBRIDGE_DUMMY)
  1094. #elif defined(JACKBRIDGE_DIRECT)
  1095. return jack_cpu_load(client);
  1096. #else
  1097. if (getBridgeInstance().cpu_load_ptr != nullptr)
  1098. return getBridgeInstance().cpu_load_ptr(client);
  1099. #endif
  1100. return 0.0f;
  1101. }
  1102. // -----------------------------------------------------------------------------
  1103. 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)
  1104. {
  1105. #if defined(JACKBRIDGE_DUMMY)
  1106. #elif defined(JACKBRIDGE_DIRECT)
  1107. return jack_port_register(client, port_name, port_type, flags, buffer_size);
  1108. #else
  1109. if (getBridgeInstance().port_register_ptr != nullptr)
  1110. return getBridgeInstance().port_register_ptr(client, port_name, port_type, flags, buffer_size);
  1111. #endif
  1112. return nullptr;
  1113. }
  1114. bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port)
  1115. {
  1116. #if defined(JACKBRIDGE_DUMMY)
  1117. #elif defined(JACKBRIDGE_DIRECT)
  1118. return (jack_port_unregister(client, port) == 0);
  1119. #else
  1120. if (getBridgeInstance().port_unregister_ptr != nullptr)
  1121. return (getBridgeInstance().port_unregister_ptr(client, port) == 0);
  1122. #endif
  1123. return false;
  1124. }
  1125. void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes)
  1126. {
  1127. #if defined(JACKBRIDGE_DUMMY)
  1128. #elif defined(JACKBRIDGE_DIRECT)
  1129. return jack_port_get_buffer(port, nframes);
  1130. #else
  1131. if (getBridgeInstance().port_get_buffer_ptr != nullptr)
  1132. return getBridgeInstance().port_get_buffer_ptr(port, nframes);
  1133. #endif
  1134. return nullptr;
  1135. }
  1136. // -----------------------------------------------------------------------------
  1137. const char* jackbridge_port_name(const jack_port_t* port)
  1138. {
  1139. #if defined(JACKBRIDGE_DUMMY)
  1140. #elif defined(JACKBRIDGE_DIRECT)
  1141. return jack_port_name(port);
  1142. #else
  1143. if (getBridgeInstance().port_name_ptr != nullptr)
  1144. return getBridgeInstance().port_name_ptr(port);
  1145. #endif
  1146. return nullptr;
  1147. }
  1148. jack_uuid_t jackbridge_port_uuid(const jack_port_t* port)
  1149. {
  1150. #if defined(JACKBRIDGE_DUMMY)
  1151. #elif defined(JACKBRIDGE_DIRECT)
  1152. return jack_port_uuid(port);
  1153. #else
  1154. if (getBridgeInstance().port_uuid_ptr != nullptr)
  1155. return getBridgeInstance().port_uuid_ptr(port);
  1156. #endif
  1157. return 0;
  1158. }
  1159. const char* jackbridge_port_short_name(const jack_port_t* port)
  1160. {
  1161. #if defined(JACKBRIDGE_DUMMY)
  1162. #elif defined(JACKBRIDGE_DIRECT)
  1163. return jack_port_short_name(port);
  1164. #else
  1165. if (getBridgeInstance().port_short_name_ptr != nullptr)
  1166. return getBridgeInstance().port_short_name_ptr(port);
  1167. #endif
  1168. return nullptr;
  1169. }
  1170. int jackbridge_port_flags(const jack_port_t* port)
  1171. {
  1172. #if defined(JACKBRIDGE_DUMMY)
  1173. #elif defined(JACKBRIDGE_DIRECT)
  1174. return jack_port_flags(port);
  1175. #else
  1176. if (getBridgeInstance().port_flags_ptr != nullptr)
  1177. return getBridgeInstance().port_flags_ptr(port);
  1178. #endif
  1179. return 0x0;
  1180. }
  1181. const char* jackbridge_port_type(const jack_port_t* port)
  1182. {
  1183. #if defined(JACKBRIDGE_DUMMY)
  1184. #elif defined(JACKBRIDGE_DIRECT)
  1185. return jack_port_type(port);
  1186. #else
  1187. if (getBridgeInstance().port_type_ptr != nullptr)
  1188. return getBridgeInstance().port_type_ptr(port);
  1189. #endif
  1190. return nullptr;
  1191. }
  1192. bool jackbridge_port_is_mine(const jack_client_t* client, const jack_port_t* port)
  1193. {
  1194. #if defined(JACKBRIDGE_DUMMY)
  1195. #elif defined(JACKBRIDGE_DIRECT)
  1196. return jack_port_is_mine(client, port);
  1197. #else
  1198. if (getBridgeInstance().port_is_mine_ptr != nullptr)
  1199. return getBridgeInstance().port_is_mine_ptr(client, port);
  1200. #endif
  1201. return false;
  1202. }
  1203. int jackbridge_port_connected(const jack_port_t* port)
  1204. {
  1205. #if defined(JACKBRIDGE_DUMMY)
  1206. #elif defined(JACKBRIDGE_DIRECT)
  1207. return jack_port_connected(port);
  1208. #else
  1209. if (getBridgeInstance().port_connected_ptr != nullptr)
  1210. return getBridgeInstance().port_connected_ptr(port);
  1211. #endif
  1212. return 0;
  1213. }
  1214. bool jackbridge_port_connected_to(const jack_port_t* port, const char* port_name)
  1215. {
  1216. #if defined(JACKBRIDGE_DUMMY)
  1217. #elif defined(JACKBRIDGE_DIRECT)
  1218. return jack_port_connected_to(port, port_name);
  1219. #else
  1220. if (getBridgeInstance().port_connected_to_ptr != nullptr)
  1221. return getBridgeInstance().port_connected_to_ptr(port, port_name);
  1222. #endif
  1223. return false;
  1224. }
  1225. const char** jackbridge_port_get_connections(const jack_port_t* port)
  1226. {
  1227. #if defined(JACKBRIDGE_DUMMY)
  1228. #elif defined(JACKBRIDGE_DIRECT)
  1229. return jack_port_get_connections(port);
  1230. #else
  1231. if (getBridgeInstance().port_get_connections_ptr != nullptr)
  1232. return getBridgeInstance().port_get_connections_ptr(port);
  1233. #endif
  1234. return nullptr;
  1235. }
  1236. const char** jackbridge_port_get_all_connections(const jack_client_t* client, const jack_port_t* port)
  1237. {
  1238. #if defined(JACKBRIDGE_DUMMY)
  1239. #elif defined(JACKBRIDGE_DIRECT)
  1240. return jack_port_get_all_connections(client, port);
  1241. #else
  1242. if (getBridgeInstance().port_get_all_connections_ptr != nullptr)
  1243. return getBridgeInstance().port_get_all_connections_ptr(client, port);
  1244. #endif
  1245. return nullptr;
  1246. }
  1247. // -----------------------------------------------------------------------------
  1248. bool jackbridge_port_rename(jack_client_t* client, jack_port_t* port, const char* port_name)
  1249. {
  1250. #if defined(JACKBRIDGE_DUMMY)
  1251. #elif defined(JACKBRIDGE_DIRECT)
  1252. return (jack_port_rename(client, port, port_name) == 0);
  1253. #else
  1254. // Try new API first
  1255. if (getBridgeInstance().port_rename_ptr != nullptr)
  1256. return (getBridgeInstance().port_rename_ptr(client, port, port_name) == 0);
  1257. // Try old API if using JACK2
  1258. if (getBridgeInstance().get_version_string_ptr != nullptr && getBridgeInstance().port_set_name_ptr != nullptr)
  1259. return (getBridgeInstance().port_set_name_ptr(port, port_name) == 0);
  1260. #endif
  1261. return false;
  1262. }
  1263. bool jackbridge_port_set_alias(jack_port_t* port, const char* alias)
  1264. {
  1265. #if defined(JACKBRIDGE_DUMMY)
  1266. #elif defined(JACKBRIDGE_DIRECT)
  1267. return (jack_port_set_alias(port, alias) == 0);
  1268. #else
  1269. if (getBridgeInstance().port_set_alias_ptr != nullptr)
  1270. return (getBridgeInstance().port_set_alias_ptr(port, alias) == 0);
  1271. #endif
  1272. return false;
  1273. }
  1274. bool jackbridge_port_unset_alias(jack_port_t* port, const char* alias)
  1275. {
  1276. #if defined(JACKBRIDGE_DUMMY)
  1277. #elif defined(JACKBRIDGE_DIRECT)
  1278. return (jack_port_unset_alias(port, alias) == 0);
  1279. #else
  1280. if (getBridgeInstance().port_unset_alias_ptr != nullptr)
  1281. return (getBridgeInstance().port_unset_alias_ptr(port, alias) == 0);
  1282. #endif
  1283. return false;
  1284. }
  1285. int jackbridge_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  1286. {
  1287. #if defined(JACKBRIDGE_DUMMY)
  1288. #elif defined(JACKBRIDGE_DIRECT)
  1289. return (jack_port_get_aliases(port, aliases) == 0);
  1290. #else
  1291. if (getBridgeInstance().port_get_aliases_ptr != nullptr)
  1292. return getBridgeInstance().port_get_aliases_ptr(port, aliases);
  1293. #endif
  1294. return 0;
  1295. }
  1296. // -----------------------------------------------------------------------------
  1297. bool jackbridge_port_request_monitor(jack_port_t* port, bool onoff)
  1298. {
  1299. #if defined(JACKBRIDGE_DUMMY)
  1300. #elif defined(JACKBRIDGE_DIRECT)
  1301. return (jack_port_request_monitor(port, onoff) == 0);
  1302. #else
  1303. if (getBridgeInstance().port_request_monitor_ptr != nullptr)
  1304. return (getBridgeInstance().port_request_monitor_ptr(port, onoff) == 0);
  1305. #endif
  1306. return false;
  1307. }
  1308. bool jackbridge_port_request_monitor_by_name(jack_client_t* client, const char* port_name, bool onoff)
  1309. {
  1310. #if defined(JACKBRIDGE_DUMMY)
  1311. #elif defined(JACKBRIDGE_DIRECT)
  1312. return (jack_port_request_monitor_by_name(client, port_name, onoff) == 0);
  1313. #else
  1314. if (getBridgeInstance().port_request_monitor_by_name_ptr != nullptr)
  1315. return (getBridgeInstance().port_request_monitor_by_name_ptr(client, port_name, onoff) == 0);
  1316. #endif
  1317. return false;
  1318. }
  1319. bool jackbridge_port_ensure_monitor(jack_port_t* port, bool onoff)
  1320. {
  1321. #if defined(JACKBRIDGE_DUMMY)
  1322. #elif defined(JACKBRIDGE_DIRECT)
  1323. return (jack_port_ensure_monitor(port, onoff) == 0);
  1324. #else
  1325. if (getBridgeInstance().port_ensure_monitor_ptr != nullptr)
  1326. return (getBridgeInstance().port_ensure_monitor_ptr(port, onoff) == 0);
  1327. #endif
  1328. return false;
  1329. }
  1330. bool jackbridge_port_monitoring_input(jack_port_t* port)
  1331. {
  1332. #if defined(JACKBRIDGE_DUMMY)
  1333. #elif defined(JACKBRIDGE_DIRECT)
  1334. return jack_port_monitoring_input(port);
  1335. #else
  1336. if (getBridgeInstance().port_monitoring_input_ptr != nullptr)
  1337. return getBridgeInstance().port_monitoring_input_ptr(port);
  1338. #endif
  1339. return false;
  1340. }
  1341. // -----------------------------------------------------------------------------
  1342. bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port)
  1343. {
  1344. #if defined(JACKBRIDGE_DUMMY)
  1345. #elif defined(JACKBRIDGE_DIRECT)
  1346. return (jack_connect(client, source_port, destination_port) == 0);
  1347. #else
  1348. if (getBridgeInstance().connect_ptr != nullptr)
  1349. return (getBridgeInstance().connect_ptr(client, source_port, destination_port) == 0);
  1350. #endif
  1351. return false;
  1352. }
  1353. bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port)
  1354. {
  1355. #if defined(JACKBRIDGE_DUMMY)
  1356. #elif defined(JACKBRIDGE_DIRECT)
  1357. return (jack_disconnect(client, source_port, destination_port) == 0);
  1358. #else
  1359. if (getBridgeInstance().disconnect_ptr != nullptr)
  1360. return (getBridgeInstance().disconnect_ptr(client, source_port, destination_port) == 0);
  1361. #endif
  1362. return false;
  1363. }
  1364. bool jackbridge_port_disconnect(jack_client_t* client, jack_port_t* port)
  1365. {
  1366. #if defined(JACKBRIDGE_DUMMY)
  1367. #elif defined(JACKBRIDGE_DIRECT)
  1368. return (jack_port_disconnect(client, port) == 0);
  1369. #else
  1370. if (getBridgeInstance().port_disconnect_ptr != nullptr)
  1371. return (getBridgeInstance().port_disconnect_ptr(client, port) == 0);
  1372. #endif
  1373. return false;
  1374. }
  1375. // -----------------------------------------------------------------------------
  1376. int jackbridge_port_name_size()
  1377. {
  1378. #if defined(JACKBRIDGE_DUMMY)
  1379. #elif defined(JACKBRIDGE_DIRECT)
  1380. return jack_port_name_size();
  1381. #else
  1382. if (getBridgeInstance().port_name_size_ptr != nullptr)
  1383. return getBridgeInstance().port_name_size_ptr();
  1384. #endif
  1385. return 256;
  1386. }
  1387. int jackbridge_port_type_size()
  1388. {
  1389. #if defined(JACKBRIDGE_DUMMY)
  1390. #elif defined(JACKBRIDGE_DIRECT)
  1391. return jack_port_type_size();
  1392. #else
  1393. if (getBridgeInstance().port_type_size_ptr != nullptr)
  1394. return getBridgeInstance().port_type_size_ptr();
  1395. #endif
  1396. return 32;
  1397. }
  1398. uint32_t jackbridge_port_type_get_buffer_size(jack_client_t* client, const char* port_type)
  1399. {
  1400. #if defined(JACKBRIDGE_DUMMY)
  1401. #elif defined(JACKBRIDGE_DIRECT)
  1402. return jack_port_type_get_buffer_size(client, port_type);
  1403. #else
  1404. if (getBridgeInstance().port_type_get_buffer_size_ptr != nullptr)
  1405. return static_cast<uint32_t>(getBridgeInstance().port_type_get_buffer_size_ptr(client, port_type));
  1406. #endif
  1407. return 0;
  1408. }
  1409. // -----------------------------------------------------------------------------
  1410. void jackbridge_port_get_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range)
  1411. {
  1412. #if defined(JACKBRIDGE_DUMMY)
  1413. #elif defined(JACKBRIDGE_DIRECT)
  1414. return jack_port_get_latency_range(port, static_cast<jack_latency_callback_mode_t>(mode), range);
  1415. #else
  1416. if (getBridgeInstance().port_get_latency_range_ptr != nullptr)
  1417. return getBridgeInstance().port_get_latency_range_ptr(port, static_cast<jack_latency_callback_mode_t>(mode), range);
  1418. #endif
  1419. range->min = 0;
  1420. range->max = 0;
  1421. }
  1422. void jackbridge_port_set_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range)
  1423. {
  1424. #if defined(JACKBRIDGE_DUMMY)
  1425. #elif defined(JACKBRIDGE_DIRECT)
  1426. jack_port_set_latency_range(port, static_cast<jack_latency_callback_mode_t>(mode), range);
  1427. #else
  1428. if (getBridgeInstance().port_set_latency_range_ptr != nullptr)
  1429. getBridgeInstance().port_set_latency_range_ptr(port, static_cast<jack_latency_callback_mode_t>(mode), range);
  1430. #endif
  1431. }
  1432. bool jackbridge_recompute_total_latencies(jack_client_t* client)
  1433. {
  1434. #if defined(JACKBRIDGE_DUMMY)
  1435. #elif defined(JACKBRIDGE_DIRECT)
  1436. return (jack_recompute_total_latencies(client) == 0);
  1437. #else
  1438. if (getBridgeInstance().recompute_total_latencies_ptr != nullptr)
  1439. return (getBridgeInstance().recompute_total_latencies_ptr(client) == 0);
  1440. #endif
  1441. return false;
  1442. }
  1443. // -----------------------------------------------------------------------------
  1444. const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, uint64_t flags)
  1445. {
  1446. #if defined(JACKBRIDGE_DUMMY)
  1447. #elif defined(JACKBRIDGE_DIRECT)
  1448. return jack_get_ports(client, port_name_pattern, type_name_pattern, flags);
  1449. #else
  1450. if (getBridgeInstance().get_ports_ptr != nullptr)
  1451. return getBridgeInstance().get_ports_ptr(client, port_name_pattern, type_name_pattern, flags);
  1452. #endif
  1453. return nullptr;
  1454. }
  1455. jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name)
  1456. {
  1457. #if defined(JACKBRIDGE_DUMMY)
  1458. #elif defined(JACKBRIDGE_DIRECT)
  1459. return jack_port_by_name(client, port_name);
  1460. #else
  1461. if (getBridgeInstance().port_by_name_ptr != nullptr)
  1462. return getBridgeInstance().port_by_name_ptr(client, port_name);
  1463. #endif
  1464. return nullptr;
  1465. }
  1466. jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id)
  1467. {
  1468. #if defined(JACKBRIDGE_DUMMY)
  1469. #elif defined(JACKBRIDGE_DIRECT)
  1470. return jack_port_by_id(client, port_id);
  1471. #else
  1472. if (getBridgeInstance().port_by_id_ptr != nullptr)
  1473. return getBridgeInstance().port_by_id_ptr(client, port_id);
  1474. #endif
  1475. return nullptr;
  1476. }
  1477. // -----------------------------------------------------------------------------
  1478. void jackbridge_free(void* ptr)
  1479. {
  1480. #if defined(JACKBRIDGE_DUMMY)
  1481. #elif defined(JACKBRIDGE_DIRECT)
  1482. return jack_free(ptr);
  1483. #else
  1484. if (getBridgeInstance().free_ptr != nullptr)
  1485. return getBridgeInstance().free_ptr(ptr);
  1486. // just in case
  1487. std::free(ptr);
  1488. #endif
  1489. }
  1490. // -----------------------------------------------------------------------------
  1491. uint32_t jackbridge_midi_get_event_count(void* port_buffer)
  1492. {
  1493. #if defined(JACKBRIDGE_DUMMY)
  1494. #elif defined(JACKBRIDGE_DIRECT)
  1495. return jack_midi_get_event_count(port_buffer);
  1496. #else
  1497. if (getBridgeInstance().midi_get_event_count_ptr != nullptr)
  1498. return getBridgeInstance().midi_get_event_count_ptr(port_buffer);
  1499. #endif
  1500. return 0;
  1501. }
  1502. bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index)
  1503. {
  1504. #if defined(JACKBRIDGE_DUMMY)
  1505. #elif defined(JACKBRIDGE_DIRECT)
  1506. return (jack_midi_event_get(event, port_buffer, event_index) == 0);
  1507. #else
  1508. if (getBridgeInstance().midi_event_get_ptr != nullptr)
  1509. return (getBridgeInstance().midi_event_get_ptr(event, port_buffer, event_index) == 0);
  1510. #endif
  1511. return false;
  1512. }
  1513. void jackbridge_midi_clear_buffer(void* port_buffer)
  1514. {
  1515. #if defined(JACKBRIDGE_DUMMY)
  1516. #elif defined(JACKBRIDGE_DIRECT)
  1517. jack_midi_clear_buffer(port_buffer);
  1518. #else
  1519. if (getBridgeInstance().midi_clear_buffer_ptr != nullptr)
  1520. getBridgeInstance().midi_clear_buffer_ptr(port_buffer);
  1521. #endif
  1522. }
  1523. bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, uint32_t data_size)
  1524. {
  1525. #if defined(JACKBRIDGE_DUMMY)
  1526. #elif defined(JACKBRIDGE_DIRECT)
  1527. return (jack_midi_event_write(port_buffer, time, data, data_size) == 0);
  1528. #else
  1529. if (getBridgeInstance().midi_event_write_ptr != nullptr)
  1530. return (getBridgeInstance().midi_event_write_ptr(port_buffer, time, data, data_size) == 0);
  1531. #endif
  1532. return false;
  1533. }
  1534. jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, uint32_t data_size)
  1535. {
  1536. #if defined(JACKBRIDGE_DUMMY)
  1537. #elif defined(JACKBRIDGE_DIRECT)
  1538. return jack_midi_event_reserve(port_buffer, time, data_size);
  1539. #else
  1540. if (getBridgeInstance().midi_event_reserve_ptr != nullptr)
  1541. return getBridgeInstance().midi_event_reserve_ptr(port_buffer, time, data_size);
  1542. #endif
  1543. return nullptr;
  1544. }
  1545. // -----------------------------------------------------------------------------
  1546. bool jackbridge_release_timebase(jack_client_t* client)
  1547. {
  1548. #if defined(JACKBRIDGE_DUMMY)
  1549. #elif defined(JACKBRIDGE_DIRECT)
  1550. return (jack_release_timebase(client) == 0);
  1551. #else
  1552. if (getBridgeInstance().release_timebase_ptr != nullptr)
  1553. return (getBridgeInstance().release_timebase_ptr(client) == 0);
  1554. #endif
  1555. return false;
  1556. }
  1557. bool jackbridge_set_sync_callback(jack_client_t* client, JackSyncCallback sync_callback, void* arg)
  1558. {
  1559. #if defined(JACKBRIDGE_DUMMY)
  1560. #elif defined(JACKBRIDGE_DIRECT)
  1561. return (jack_set_sync_callback(client, sync_callback, arg) == 0);
  1562. #else
  1563. if (getBridgeInstance().set_sync_callback_ptr != nullptr)
  1564. {
  1565. # ifdef __WINE__
  1566. WineBridge::getInstance().set_sync(sync_callback);
  1567. return (getBridgeInstance().set_sync_callback_ptr(client, WineBridge::sync, arg) == 0);
  1568. # else
  1569. return (getBridgeInstance().set_sync_callback_ptr(client, sync_callback, arg) == 0);
  1570. # endif
  1571. }
  1572. #endif
  1573. return false;
  1574. }
  1575. bool jackbridge_set_sync_timeout(jack_client_t* client, jack_time_t timeout)
  1576. {
  1577. #if defined(JACKBRIDGE_DUMMY)
  1578. #elif defined(JACKBRIDGE_DIRECT)
  1579. return (jack_set_sync_timeout(client, timeout) == 0);
  1580. #else
  1581. if (getBridgeInstance().set_sync_timeout_ptr != nullptr)
  1582. return (getBridgeInstance().set_sync_timeout_ptr(client, timeout) == 0);
  1583. #endif
  1584. return false;
  1585. }
  1586. bool jackbridge_set_timebase_callback(jack_client_t* client, bool conditional, JackTimebaseCallback timebase_callback, void* arg)
  1587. {
  1588. #if defined(JACKBRIDGE_DUMMY)
  1589. #elif defined(JACKBRIDGE_DIRECT)
  1590. return (jack_set_timebase_callback(client, conditional, timebase_callback, arg) == 0);
  1591. #else
  1592. if (getBridgeInstance().set_timebase_callback_ptr != nullptr)
  1593. {
  1594. # ifdef __WINE__
  1595. WineBridge::getInstance().set_timebase(timebase_callback);
  1596. return (getBridgeInstance().set_timebase_callback_ptr(client, conditional, WineBridge::timebase, arg) == 0);
  1597. # else
  1598. return (getBridgeInstance().set_timebase_callback_ptr(client, conditional, timebase_callback, arg) == 0);
  1599. # endif
  1600. }
  1601. #endif
  1602. return false;
  1603. }
  1604. bool jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame)
  1605. {
  1606. #if defined(JACKBRIDGE_DUMMY)
  1607. #elif defined(JACKBRIDGE_DIRECT)
  1608. return (jack_transport_locate(client, frame) == 0);
  1609. #else
  1610. if (getBridgeInstance().transport_locate_ptr != nullptr)
  1611. return (getBridgeInstance().transport_locate_ptr(client, frame) == 0);
  1612. #endif
  1613. return false;
  1614. }
  1615. uint32_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos)
  1616. {
  1617. #if defined(JACKBRIDGE_DUMMY)
  1618. #elif defined(JACKBRIDGE_DIRECT)
  1619. return jack_transport_query(client, pos);
  1620. #else
  1621. if (getBridgeInstance().transport_query_ptr != nullptr)
  1622. return getBridgeInstance().transport_query_ptr(client, pos);
  1623. #endif
  1624. if (pos != nullptr)
  1625. {
  1626. // invalidate
  1627. pos->unique_1 = 0;
  1628. pos->unique_2 = 1;
  1629. }
  1630. return JackTransportStopped;
  1631. }
  1632. jack_nframes_t jackbridge_get_current_transport_frame(const jack_client_t* client)
  1633. {
  1634. #if defined(JACKBRIDGE_DUMMY)
  1635. #elif defined(JACKBRIDGE_DIRECT)
  1636. return jack_get_current_transport_frame(client);
  1637. #else
  1638. if (getBridgeInstance().get_current_transport_frame_ptr != nullptr)
  1639. return getBridgeInstance().get_current_transport_frame_ptr(client);
  1640. #endif
  1641. return 0;
  1642. }
  1643. bool jackbridge_transport_reposition(jack_client_t* client, const jack_position_t* pos)
  1644. {
  1645. #if defined(JACKBRIDGE_DUMMY)
  1646. #elif defined(JACKBRIDGE_DIRECT)
  1647. return (jack_transport_reposition(client, pos) == 0);
  1648. #else
  1649. if (getBridgeInstance().transport_reposition_ptr != nullptr)
  1650. return (getBridgeInstance().transport_reposition_ptr(client, pos) == 0);
  1651. #endif
  1652. return false;
  1653. }
  1654. void jackbridge_transport_start(jack_client_t* client)
  1655. {
  1656. #if defined(JACKBRIDGE_DUMMY)
  1657. #elif defined(JACKBRIDGE_DIRECT)
  1658. jack_transport_start(client);
  1659. #else
  1660. if (getBridgeInstance().transport_start_ptr != nullptr)
  1661. getBridgeInstance().transport_start_ptr(client);
  1662. #endif
  1663. }
  1664. void jackbridge_transport_stop(jack_client_t* client)
  1665. {
  1666. #if defined(JACKBRIDGE_DUMMY)
  1667. #elif defined(JACKBRIDGE_DIRECT)
  1668. jack_transport_stop(client);
  1669. #else
  1670. if (getBridgeInstance().transport_stop_ptr != nullptr)
  1671. getBridgeInstance().transport_stop_ptr(client);
  1672. #endif
  1673. }
  1674. // -----------------------------------------------------------------------------
  1675. bool jackbridge_set_property(jack_client_t* client, jack_uuid_t subject, const char* key, const char* value, const char* type)
  1676. {
  1677. #if defined(JACKBRIDGE_DUMMY)
  1678. #elif defined(JACKBRIDGE_DIRECT)
  1679. return (jack_set_property(client, subject, key, value, type) == 0);
  1680. #else
  1681. if (getBridgeInstance().set_property_ptr != nullptr)
  1682. return (getBridgeInstance().set_property_ptr(client, subject, key, value, type) == 0);
  1683. #endif
  1684. return false;
  1685. }
  1686. bool jackbridge_get_property(jack_uuid_t subject, const char* key, char** value, char** type)
  1687. {
  1688. #if defined(JACKBRIDGE_DUMMY)
  1689. #elif defined(JACKBRIDGE_DIRECT)
  1690. return (jack_get_property(subject, key, value, type) == 0);
  1691. #else
  1692. if (getBridgeInstance().get_property_ptr != nullptr)
  1693. return (getBridgeInstance().get_property_ptr(subject, key, value, type) == 0);
  1694. #endif
  1695. return false;
  1696. }
  1697. void jackbridge_free_description(jack_description_t* desc, bool free_description_itself)
  1698. {
  1699. #if defined(JACKBRIDGE_DUMMY)
  1700. #elif defined(JACKBRIDGE_DIRECT)
  1701. jack_free_description(desc, free_description_itself);
  1702. #else
  1703. if (getBridgeInstance().free_description_ptr != nullptr)
  1704. getBridgeInstance().free_description_ptr(desc, free_description_itself);
  1705. #endif
  1706. }
  1707. bool jackbridge_get_properties(jack_uuid_t subject, jack_description_t* desc)
  1708. {
  1709. #if defined(JACKBRIDGE_DUMMY)
  1710. #elif defined(JACKBRIDGE_DIRECT)
  1711. return (jack_get_properties(subject, desc) == 0);
  1712. #else
  1713. if (getBridgeInstance().get_properties_ptr != nullptr)
  1714. return (getBridgeInstance().get_properties_ptr(subject, desc) == 0);
  1715. #endif
  1716. return false;
  1717. }
  1718. bool jackbridge_get_all_properties(jack_description_t** descs)
  1719. {
  1720. #if defined(JACKBRIDGE_DUMMY)
  1721. #elif defined(JACKBRIDGE_DIRECT)
  1722. return (jack_get_all_properties(descs) == 0);
  1723. #else
  1724. if (getBridgeInstance().get_all_properties_ptr != nullptr)
  1725. return (getBridgeInstance().get_all_properties_ptr(descs) == 0);
  1726. #endif
  1727. return false;
  1728. }
  1729. bool jackbridge_remove_property(jack_client_t* client, jack_uuid_t subject, const char* key)
  1730. {
  1731. #if defined(JACKBRIDGE_DUMMY)
  1732. #elif defined(JACKBRIDGE_DIRECT)
  1733. return (jack_remove_property(client, subject, key) == 0);
  1734. #else
  1735. if (getBridgeInstance().remove_property_ptr != nullptr)
  1736. return (getBridgeInstance().remove_property_ptr(client, subject, key) == 0);
  1737. #endif
  1738. return false;
  1739. }
  1740. int jackbridge_remove_properties(jack_client_t* client, jack_uuid_t subject)
  1741. {
  1742. #if defined(JACKBRIDGE_DUMMY)
  1743. #elif defined(JACKBRIDGE_DIRECT)
  1744. return jack_remove_properties(client, subject);
  1745. #else
  1746. if (getBridgeInstance().remove_properties_ptr != nullptr)
  1747. return getBridgeInstance().remove_properties_ptr(client, subject);
  1748. #endif
  1749. return 0;
  1750. }
  1751. bool jackbridge_remove_all_properties(jack_client_t* client)
  1752. {
  1753. #if defined(JACKBRIDGE_DUMMY)
  1754. #elif defined(JACKBRIDGE_DIRECT)
  1755. return (jack_remove_all_properties(client) == 0);
  1756. #else
  1757. if (getBridgeInstance().remove_all_properties_ptr != nullptr)
  1758. return (getBridgeInstance().remove_all_properties_ptr(client) == 0);
  1759. #endif
  1760. return false;
  1761. }
  1762. bool jackbridge_set_property_change_callback(jack_client_t* client, JackPropertyChangeCallback callback, void* arg)
  1763. {
  1764. #if defined(JACKBRIDGE_DUMMY)
  1765. #elif defined(JACKBRIDGE_DIRECT)
  1766. return (jack_set_property_change_callback(client, callback, arg) == 0);
  1767. #else
  1768. if (getBridgeInstance().set_property_change_callback_ptr != nullptr)
  1769. {
  1770. # ifdef __WINE__
  1771. WineBridge::getInstance().set_prop_change(callback);
  1772. return (getBridgeInstance().set_property_change_callback_ptr(client, WineBridge::prop_change, arg) == 0);
  1773. # else
  1774. return (getBridgeInstance().set_property_change_callback_ptr(client, callback, arg) == 0);
  1775. # endif
  1776. }
  1777. #endif
  1778. return false;
  1779. }
  1780. // -----------------------------------------------------------------------------