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.

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