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.

1600 lines
52KB

  1. /*
  2. * JackBridge (Part 1, JACK functions)
  3. * Copyright (C) 2013-2014 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. #include "CarlaLibUtils.hpp"
  19. // -----------------------------------------------------------------------------
  20. typedef void (*jacksym_get_version)(int*, int*, int*, int*);
  21. typedef const char* (*jacksym_get_version_string)();
  22. typedef jack_client_t* (*jacksym_client_open)(const char*, jack_options_t, jack_status_t*, ...);
  23. typedef const char* (*jacksym_client_rename)(jack_client_t* client, const char* new_name);
  24. typedef int (*jacksym_client_close)(jack_client_t*);
  25. typedef int (*jacksym_client_name_size)();
  26. typedef char* (*jacksym_get_client_name)(jack_client_t*);
  27. typedef char* (*jacksym_get_uuid_for_client_name)(jack_client_t*, const char*);
  28. typedef char* (*jacksym_get_client_name_by_uuid)(jack_client_t*, const char*);
  29. typedef int (*jacksym_activate)(jack_client_t*);
  30. typedef int (*jacksym_deactivate)(jack_client_t*);
  31. typedef int (*jacksym_is_realtime)(jack_client_t*);
  32. typedef int (*jacksym_set_thread_init_callback)(jack_client_t*, JackThreadInitCallback, void*);
  33. typedef void (*jacksym_on_shutdown)(jack_client_t*, JackShutdownCallback, void*);
  34. typedef void (*jacksym_on_info_shutdown)(jack_client_t*, JackInfoShutdownCallback, void*);
  35. typedef int (*jacksym_set_process_callback)(jack_client_t*, JackProcessCallback, void*);
  36. typedef int (*jacksym_set_freewheel_callback)(jack_client_t*, JackFreewheelCallback, void*);
  37. typedef int (*jacksym_set_buffer_size_callback)(jack_client_t*, JackBufferSizeCallback, void*);
  38. typedef int (*jacksym_set_sample_rate_callback)(jack_client_t*, JackSampleRateCallback, void*);
  39. typedef int (*jacksym_set_client_registration_callback)(jack_client_t*, JackClientRegistrationCallback, void*);
  40. typedef int (*jacksym_set_port_registration_callback)(jack_client_t*, JackPortRegistrationCallback, void*);
  41. typedef int (*jacksym_set_port_rename_callback)(jack_client_t*, JackPortRenameCallback, void*);
  42. typedef int (*jacksym_set_port_connect_callback)(jack_client_t*, JackPortConnectCallback, void*);
  43. typedef int (*jacksym_set_graph_order_callback)(jack_client_t*, JackGraphOrderCallback, void*);
  44. typedef int (*jacksym_set_xrun_callback)(jack_client_t*, JackXRunCallback, void*);
  45. typedef int (*jacksym_set_latency_callback)(jack_client_t*, JackLatencyCallback, void*);
  46. typedef int (*jacksym_set_freewheel)(jack_client_t*, int);
  47. typedef int (*jacksym_set_buffer_size)(jack_client_t*, jack_nframes_t);
  48. typedef jack_nframes_t (*jacksym_get_sample_rate)(jack_client_t*);
  49. typedef jack_nframes_t (*jacksym_get_buffer_size)(jack_client_t*);
  50. typedef float (*jacksym_cpu_load)(jack_client_t*);
  51. typedef jack_port_t* (*jacksym_port_register)(jack_client_t*, const char*, const char*, unsigned long, unsigned long);
  52. typedef int (*jacksym_port_unregister)(jack_client_t*, jack_port_t*);
  53. typedef void* (*jacksym_port_get_buffer)(jack_port_t*, jack_nframes_t);
  54. typedef const char* (*jacksym_port_name)(const jack_port_t*);
  55. typedef jack_uuid_t (*jacksym_port_uuid)(const jack_port_t*);
  56. typedef const char* (*jacksym_port_short_name)(const jack_port_t*);
  57. typedef int (*jacksym_port_flags)(const jack_port_t*);
  58. typedef const char* (*jacksym_port_type)(const jack_port_t*);
  59. typedef int (*jacksym_port_is_mine)(const jack_client_t*, const jack_port_t*);
  60. typedef int (*jacksym_port_connected)(const jack_port_t*);
  61. typedef int (*jacksym_port_connected_to)(const jack_port_t*, const char*);
  62. typedef const char** (*jacksym_port_get_connections)(const jack_port_t*);
  63. typedef const char** (*jacksym_port_get_all_connections)(const jack_client_t*, const jack_port_t*);
  64. typedef int (*jacksym_port_set_name)(jack_port_t*, const char*);
  65. typedef int (*jacksym_port_set_alias)(jack_port_t*, const char*);
  66. typedef int (*jacksym_port_unset_alias)(jack_port_t*, const char*);
  67. typedef int (*jacksym_port_get_aliases)(const jack_port_t*, char* const aliases[2]);
  68. typedef int (*jacksym_port_request_monitor)(jack_port_t*, int);
  69. typedef int (*jacksym_port_request_monitor_by_name)(jack_client_t*, const char*, int);
  70. typedef int (*jacksym_port_ensure_monitor)(jack_port_t*, int);
  71. typedef int (*jacksym_port_monitoring_input)(jack_port_t*);
  72. typedef int (*jacksym_connect)(jack_client_t*, const char*, const char*);
  73. typedef int (*jacksym_disconnect)(jack_client_t*, const char*, const char*);
  74. typedef int (*jacksym_port_disconnect)(jack_client_t*, jack_port_t*);
  75. typedef int (*jacksym_port_name_size)();
  76. typedef int (*jacksym_port_type_size)();
  77. typedef size_t (*jacksym_port_type_get_buffer_size)(jack_client_t*, const char*);
  78. typedef void (*jacksym_port_get_latency_range)(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t*);
  79. typedef void (*jacksym_port_set_latency_range)(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t*);
  80. typedef int (*jacksym_recompute_total_latencies)(jack_client_t*);
  81. typedef const char** (*jacksym_get_ports)(jack_client_t*, const char*, const char*, unsigned long);
  82. typedef jack_port_t* (*jacksym_port_by_name)(jack_client_t*, const char*);
  83. typedef jack_port_t* (*jacksym_port_by_id)(jack_client_t*, jack_port_id_t);
  84. typedef void (*jacksym_free)(void*);
  85. typedef uint32_t (*jacksym_midi_get_event_count)(void*);
  86. typedef int (*jacksym_midi_event_get)(jack_midi_event_t*, void*, uint32_t);
  87. typedef void (*jacksym_midi_clear_buffer)(void*);
  88. typedef int (*jacksym_midi_event_write)(void*, jack_nframes_t, const jack_midi_data_t*, size_t);
  89. typedef jack_midi_data_t* (*jacksym_midi_event_reserve)(void*, jack_nframes_t, size_t);
  90. typedef int (*jacksym_release_timebase)(jack_client_t*);
  91. typedef int (*jacksym_set_sync_callback)(jack_client_t*, JackSyncCallback, void*);
  92. typedef int (*jacksym_set_sync_timeout)(jack_client_t*, jack_time_t);
  93. typedef int (*jacksym_set_timebase_callback)(jack_client_t*, int, JackTimebaseCallback, void*);
  94. typedef int (*jacksym_transport_locate)(jack_client_t*, jack_nframes_t);
  95. typedef jack_transport_state_t (*jacksym_transport_query)(const jack_client_t*, jack_position_t*);
  96. typedef jack_nframes_t (*jacksym_get_current_transport_frame)(const jack_client_t*);
  97. typedef int (*jacksym_transport_reposition)(jack_client_t*, const jack_position_t*);
  98. typedef void (*jacksym_transport_start)(jack_client_t*);
  99. typedef void (*jacksym_transport_stop)(jack_client_t*);
  100. typedef int (*jacksym_set_property)(jack_client_t*, jack_uuid_t, const char*, const char*, const char*);
  101. typedef int (*jacksym_get_property)(jack_uuid_t, const char*, char**, char**);
  102. typedef void (*jacksym_free_description)(jack_description_t*, int);
  103. typedef int (*jacksym_get_properties)(jack_uuid_t, jack_description_t*);
  104. typedef int (*jacksym_get_all_properties)(jack_description_t**);
  105. typedef int (*jacksym_remove_property)(jack_client_t*, jack_uuid_t, const char*);
  106. typedef int (*jacksym_remove_properties)(jack_client_t*, jack_uuid_t);
  107. typedef int (*jacksym_remove_all_properties)(jack_client_t*);
  108. typedef int (*jacksym_set_property_change_callback)(jack_client_t*, JackPropertyChangeCallback, void*);
  109. // -----------------------------------------------------------------------------
  110. struct JackBridge {
  111. void* lib;
  112. jacksym_get_version get_version_ptr;
  113. jacksym_get_version_string get_version_string_ptr;
  114. jacksym_client_open client_open_ptr;
  115. jacksym_client_rename client_rename_ptr;
  116. jacksym_client_close client_close_ptr;
  117. jacksym_client_name_size client_name_size_ptr;
  118. jacksym_get_client_name get_client_name_ptr;
  119. jacksym_get_uuid_for_client_name get_uuid_for_client_name_ptr;
  120. jacksym_get_client_name_by_uuid get_client_name_by_uuid_ptr;
  121. jacksym_activate activate_ptr;
  122. jacksym_deactivate deactivate_ptr;
  123. jacksym_is_realtime is_realtime_ptr;
  124. jacksym_set_thread_init_callback set_thread_init_callback_ptr;
  125. jacksym_on_shutdown on_shutdown_ptr;
  126. jacksym_on_info_shutdown on_info_shutdown_ptr;
  127. jacksym_set_process_callback set_process_callback_ptr;
  128. jacksym_set_freewheel_callback set_freewheel_callback_ptr;
  129. jacksym_set_buffer_size_callback set_buffer_size_callback_ptr;
  130. jacksym_set_sample_rate_callback set_sample_rate_callback_ptr;
  131. jacksym_set_client_registration_callback set_client_registration_callback_ptr;
  132. jacksym_set_port_registration_callback set_port_registration_callback_ptr;
  133. jacksym_set_port_rename_callback set_port_rename_callback_ptr;
  134. jacksym_set_port_connect_callback set_port_connect_callback_ptr;
  135. jacksym_set_xrun_callback set_xrun_callback_ptr;
  136. jacksym_set_latency_callback set_latency_callback_ptr;
  137. jacksym_set_freewheel set_freewheel_ptr;
  138. jacksym_set_buffer_size set_buffer_size_ptr;
  139. jacksym_get_sample_rate get_sample_rate_ptr;
  140. jacksym_get_buffer_size get_buffer_size_ptr;
  141. jacksym_cpu_load cpu_load_ptr;
  142. jacksym_port_register port_register_ptr;
  143. jacksym_port_unregister port_unregister_ptr;
  144. jacksym_port_get_buffer port_get_buffer_ptr;
  145. jacksym_port_name port_name_ptr;
  146. jacksym_port_uuid port_uuid_ptr;
  147. jacksym_port_short_name port_short_name_ptr;
  148. jacksym_port_flags port_flags_ptr;
  149. jacksym_port_type port_type_ptr;
  150. jacksym_port_is_mine port_is_mine_ptr;
  151. jacksym_port_connected port_connected_ptr;
  152. jacksym_port_connected_to port_connected_to_ptr;
  153. jacksym_port_get_connections port_get_connections_ptr;
  154. jacksym_port_get_all_connections port_get_all_connections_ptr;
  155. jacksym_port_set_name port_set_name_ptr;
  156. jacksym_port_set_alias port_set_alias_ptr;
  157. jacksym_port_unset_alias port_unset_alias_ptr;
  158. jacksym_port_get_aliases port_get_aliases_ptr;
  159. jacksym_port_request_monitor port_request_monitor_ptr;
  160. jacksym_port_request_monitor_by_name port_request_monitor_by_name_ptr;
  161. jacksym_port_ensure_monitor port_ensure_monitor_ptr;
  162. jacksym_port_monitoring_input port_monitoring_input_ptr;
  163. jacksym_connect connect_ptr;
  164. jacksym_disconnect disconnect_ptr;
  165. jacksym_port_disconnect port_disconnect_ptr;
  166. jacksym_port_name_size port_name_size_ptr;
  167. jacksym_port_type_size port_type_size_ptr;
  168. jacksym_port_type_get_buffer_size port_type_get_buffer_size_ptr;
  169. jacksym_port_get_latency_range port_get_latency_range_ptr;
  170. jacksym_port_set_latency_range port_set_latency_range_ptr;
  171. jacksym_recompute_total_latencies recompute_total_latencies_ptr;
  172. jacksym_get_ports get_ports_ptr;
  173. jacksym_port_by_name port_by_name_ptr;
  174. jacksym_port_by_id port_by_id_ptr;
  175. jacksym_free free_ptr;
  176. jacksym_midi_get_event_count midi_get_event_count_ptr;
  177. jacksym_midi_event_get midi_event_get_ptr;
  178. jacksym_midi_clear_buffer midi_clear_buffer_ptr;
  179. jacksym_midi_event_write midi_event_write_ptr;
  180. jacksym_midi_event_reserve midi_event_reserve_ptr;
  181. jacksym_release_timebase release_timebase_ptr;
  182. jacksym_set_sync_callback set_sync_callback_ptr;
  183. jacksym_set_sync_timeout set_sync_timeout_ptr;
  184. jacksym_set_timebase_callback set_timebase_callback_ptr;
  185. jacksym_transport_locate transport_locate_ptr;
  186. jacksym_transport_query transport_query_ptr;
  187. jacksym_get_current_transport_frame get_current_transport_frame_ptr;
  188. jacksym_transport_reposition transport_reposition_ptr;
  189. jacksym_transport_start transport_start_ptr;
  190. jacksym_transport_stop transport_stop_ptr;
  191. jacksym_set_property set_property_ptr;
  192. jacksym_get_property get_property_ptr;
  193. jacksym_free_description free_description_ptr;
  194. jacksym_get_properties get_properties_ptr;
  195. jacksym_get_all_properties get_all_properties_ptr;
  196. jacksym_remove_property remove_property_ptr;
  197. jacksym_remove_properties remove_properties_ptr;
  198. jacksym_remove_all_properties remove_all_properties_ptr;
  199. jacksym_set_property_change_callback set_property_change_callback_ptr;
  200. JackBridge()
  201. : lib(nullptr),
  202. get_version_ptr(nullptr),
  203. get_version_string_ptr(nullptr),
  204. client_open_ptr(nullptr),
  205. client_rename_ptr(nullptr),
  206. client_close_ptr(nullptr),
  207. client_name_size_ptr(nullptr),
  208. get_client_name_ptr(nullptr),
  209. get_uuid_for_client_name_ptr(nullptr),
  210. get_client_name_by_uuid_ptr(nullptr),
  211. activate_ptr(nullptr),
  212. deactivate_ptr(nullptr),
  213. is_realtime_ptr(nullptr),
  214. set_thread_init_callback_ptr(nullptr),
  215. on_shutdown_ptr(nullptr),
  216. on_info_shutdown_ptr(nullptr),
  217. set_process_callback_ptr(nullptr),
  218. set_freewheel_callback_ptr(nullptr),
  219. set_buffer_size_callback_ptr(nullptr),
  220. set_sample_rate_callback_ptr(nullptr),
  221. set_client_registration_callback_ptr(nullptr),
  222. set_port_registration_callback_ptr(nullptr),
  223. set_port_rename_callback_ptr(nullptr),
  224. set_port_connect_callback_ptr(nullptr),
  225. set_xrun_callback_ptr(nullptr),
  226. set_latency_callback_ptr(nullptr),
  227. set_freewheel_ptr(nullptr),
  228. set_buffer_size_ptr(nullptr),
  229. get_sample_rate_ptr(nullptr),
  230. get_buffer_size_ptr(nullptr),
  231. cpu_load_ptr(nullptr),
  232. port_register_ptr(nullptr),
  233. port_unregister_ptr(nullptr),
  234. port_get_buffer_ptr(nullptr),
  235. port_name_ptr(nullptr),
  236. port_uuid_ptr(nullptr),
  237. port_short_name_ptr(nullptr),
  238. port_flags_ptr(nullptr),
  239. port_type_ptr(nullptr),
  240. port_is_mine_ptr(nullptr),
  241. port_connected_ptr(nullptr),
  242. port_connected_to_ptr(nullptr),
  243. port_get_connections_ptr(nullptr),
  244. port_get_all_connections_ptr(nullptr),
  245. port_set_name_ptr(nullptr),
  246. port_set_alias_ptr(nullptr),
  247. port_unset_alias_ptr(nullptr),
  248. port_get_aliases_ptr(nullptr),
  249. port_request_monitor_ptr(nullptr),
  250. port_request_monitor_by_name_ptr(nullptr),
  251. port_ensure_monitor_ptr(nullptr),
  252. port_monitoring_input_ptr(nullptr),
  253. connect_ptr(nullptr),
  254. disconnect_ptr(nullptr),
  255. port_disconnect_ptr(nullptr),
  256. port_name_size_ptr(nullptr),
  257. port_type_size_ptr(nullptr),
  258. port_type_get_buffer_size_ptr(nullptr),
  259. port_get_latency_range_ptr(nullptr),
  260. port_set_latency_range_ptr(nullptr),
  261. recompute_total_latencies_ptr(nullptr),
  262. get_ports_ptr(nullptr),
  263. port_by_name_ptr(nullptr),
  264. port_by_id_ptr(nullptr),
  265. free_ptr(nullptr),
  266. midi_get_event_count_ptr(nullptr),
  267. midi_event_get_ptr(nullptr),
  268. midi_clear_buffer_ptr(nullptr),
  269. midi_event_write_ptr(nullptr),
  270. midi_event_reserve_ptr(nullptr),
  271. release_timebase_ptr(nullptr),
  272. set_sync_callback_ptr(nullptr),
  273. set_sync_timeout_ptr(nullptr),
  274. set_timebase_callback_ptr(nullptr),
  275. transport_locate_ptr(nullptr),
  276. transport_query_ptr(nullptr),
  277. get_current_transport_frame_ptr(nullptr),
  278. transport_reposition_ptr(nullptr),
  279. transport_start_ptr(nullptr),
  280. transport_stop_ptr(nullptr),
  281. set_property_ptr(nullptr),
  282. get_property_ptr(nullptr),
  283. free_description_ptr(nullptr),
  284. get_properties_ptr(nullptr),
  285. get_all_properties_ptr(nullptr),
  286. remove_property_ptr(nullptr),
  287. remove_properties_ptr(nullptr),
  288. remove_all_properties_ptr(nullptr),
  289. set_property_change_callback_ptr(nullptr)
  290. {
  291. # if defined(CARLA_OS_MAC)
  292. const char* const filename("libjack.dylib");
  293. # elif defined(CARLA_OS_WIN)
  294. const char* const filename("libjack.dll");
  295. # else
  296. const char* const filename("libjack.so.0");
  297. # endif
  298. lib = lib_open(filename);
  299. if (lib == nullptr)
  300. {
  301. fprintf(stderr, "Failed to load JACK DLL, reason:\n%s\n", lib_error(filename));
  302. return;
  303. }
  304. else
  305. {
  306. fprintf(stdout, "%s loaded sucessfully!\n", filename);
  307. }
  308. #define JOIN(a, b) a ## b
  309. #define LIB_SYMBOL(NAME) JOIN(NAME, _ptr) = (jacksym_##NAME)lib_symbol(lib, "jack_" #NAME);
  310. LIB_SYMBOL(get_version)
  311. LIB_SYMBOL(get_version_string)
  312. LIB_SYMBOL(client_open)
  313. LIB_SYMBOL(client_rename)
  314. LIB_SYMBOL(client_close)
  315. LIB_SYMBOL(client_name_size)
  316. LIB_SYMBOL(get_client_name)
  317. LIB_SYMBOL(get_uuid_for_client_name)
  318. LIB_SYMBOL(get_client_name_by_uuid)
  319. LIB_SYMBOL(activate)
  320. LIB_SYMBOL(deactivate)
  321. LIB_SYMBOL(is_realtime)
  322. LIB_SYMBOL(set_thread_init_callback)
  323. LIB_SYMBOL(on_shutdown)
  324. LIB_SYMBOL(on_info_shutdown)
  325. LIB_SYMBOL(set_process_callback)
  326. LIB_SYMBOL(set_freewheel_callback)
  327. LIB_SYMBOL(set_buffer_size_callback)
  328. LIB_SYMBOL(set_sample_rate_callback)
  329. LIB_SYMBOL(set_client_registration_callback)
  330. LIB_SYMBOL(set_port_registration_callback)
  331. LIB_SYMBOL(set_port_rename_callback)
  332. LIB_SYMBOL(set_port_connect_callback)
  333. LIB_SYMBOL(set_xrun_callback)
  334. LIB_SYMBOL(set_latency_callback)
  335. LIB_SYMBOL(set_freewheel)
  336. LIB_SYMBOL(set_buffer_size)
  337. LIB_SYMBOL(get_sample_rate)
  338. LIB_SYMBOL(get_buffer_size)
  339. LIB_SYMBOL(cpu_load)
  340. LIB_SYMBOL(port_register)
  341. LIB_SYMBOL(port_unregister)
  342. LIB_SYMBOL(port_get_buffer)
  343. LIB_SYMBOL(port_name)
  344. LIB_SYMBOL(port_uuid)
  345. LIB_SYMBOL(port_short_name)
  346. LIB_SYMBOL(port_flags)
  347. LIB_SYMBOL(port_type)
  348. LIB_SYMBOL(port_is_mine)
  349. LIB_SYMBOL(port_connected)
  350. LIB_SYMBOL(port_connected_to)
  351. LIB_SYMBOL(port_get_connections)
  352. LIB_SYMBOL(port_get_all_connections)
  353. LIB_SYMBOL(port_set_name)
  354. LIB_SYMBOL(port_set_alias)
  355. LIB_SYMBOL(port_unset_alias)
  356. LIB_SYMBOL(port_get_aliases)
  357. LIB_SYMBOL(port_request_monitor)
  358. LIB_SYMBOL(port_request_monitor_by_name)
  359. LIB_SYMBOL(port_ensure_monitor)
  360. LIB_SYMBOL(port_monitoring_input)
  361. LIB_SYMBOL(connect)
  362. LIB_SYMBOL(disconnect)
  363. LIB_SYMBOL(port_disconnect)
  364. LIB_SYMBOL(port_name_size)
  365. LIB_SYMBOL(port_type_size)
  366. LIB_SYMBOL(port_type_get_buffer_size)
  367. LIB_SYMBOL(port_get_latency_range)
  368. LIB_SYMBOL(port_set_latency_range)
  369. LIB_SYMBOL(recompute_total_latencies)
  370. LIB_SYMBOL(get_ports)
  371. LIB_SYMBOL(port_by_name)
  372. LIB_SYMBOL(port_by_id)
  373. LIB_SYMBOL(free)
  374. LIB_SYMBOL(midi_get_event_count)
  375. LIB_SYMBOL(midi_event_get)
  376. LIB_SYMBOL(midi_clear_buffer)
  377. LIB_SYMBOL(midi_event_write)
  378. LIB_SYMBOL(midi_event_reserve)
  379. LIB_SYMBOL(release_timebase)
  380. LIB_SYMBOL(set_sync_callback)
  381. LIB_SYMBOL(set_sync_timeout)
  382. LIB_SYMBOL(set_timebase_callback)
  383. LIB_SYMBOL(transport_locate)
  384. LIB_SYMBOL(transport_query)
  385. LIB_SYMBOL(get_current_transport_frame)
  386. LIB_SYMBOL(transport_reposition)
  387. LIB_SYMBOL(transport_start)
  388. LIB_SYMBOL(transport_stop)
  389. LIB_SYMBOL(set_property)
  390. LIB_SYMBOL(get_property)
  391. LIB_SYMBOL(free_description)
  392. LIB_SYMBOL(get_properties)
  393. LIB_SYMBOL(get_all_properties)
  394. LIB_SYMBOL(remove_property)
  395. LIB_SYMBOL(remove_properties)
  396. LIB_SYMBOL(remove_all_properties)
  397. LIB_SYMBOL(set_property_change_callback)
  398. #undef JOIN
  399. #undef LIB_SYMBOL
  400. }
  401. ~JackBridge()
  402. {
  403. if (lib != nullptr)
  404. {
  405. lib_close(lib);
  406. lib = nullptr;
  407. }
  408. }
  409. CARLA_DECLARE_NON_COPY_STRUCT(JackBridge);
  410. };
  411. static const JackBridge bridge;
  412. #endif // ! JACKBRIDGE_DIRECT
  413. // -----------------------------------------------------------------------------
  414. bool jackbridge_is_ok() noexcept
  415. {
  416. #if defined(JACKBRIDGE_DUMMY) || defined(JACKBRIDGE_DIRECT)
  417. return true;
  418. #else
  419. return (bridge.lib != nullptr);
  420. #endif
  421. }
  422. // -----------------------------------------------------------------------------
  423. void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr)
  424. {
  425. #if defined(JACKBRIDGE_DUMMY)
  426. #elif defined(JACKBRIDGE_DIRECT)
  427. return jack_get_version(major_ptr, minor_ptr, micro_ptr, proto_ptr);
  428. #else
  429. if (bridge.get_version_ptr != nullptr)
  430. return bridge.get_version_ptr(major_ptr, minor_ptr, micro_ptr, proto_ptr);
  431. #endif
  432. if (major_ptr != nullptr)
  433. *major_ptr = 0;
  434. if (minor_ptr != nullptr)
  435. *minor_ptr = 0;
  436. if (micro_ptr != nullptr)
  437. *micro_ptr = 0;
  438. if (proto_ptr != nullptr)
  439. *proto_ptr = 0;
  440. }
  441. const char* jackbridge_get_version_string()
  442. {
  443. #if defined(JACKBRIDGE_DUMMY)
  444. #elif defined(JACKBRIDGE_DIRECT)
  445. return jack_get_version_string();
  446. #else
  447. if (bridge.get_version_string_ptr != nullptr)
  448. return bridge.get_version_string_ptr();
  449. #endif
  450. return nullptr;
  451. }
  452. // -----------------------------------------------------------------------------
  453. jack_client_t* jackbridge_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  454. {
  455. #if defined(JACKBRIDGE_DUMMY)
  456. #elif defined(JACKBRIDGE_DIRECT)
  457. return jack_client_open(client_name, options, status);
  458. #else
  459. if (bridge.client_open_ptr != nullptr)
  460. return bridge.client_open_ptr(client_name, options, status);
  461. #endif
  462. if (status != nullptr)
  463. *status = JackServerError;
  464. return nullptr;
  465. }
  466. bool jackbridge_client_close(jack_client_t* client)
  467. {
  468. #if defined(JACKBRIDGE_DUMMY)
  469. #elif defined(JACKBRIDGE_DIRECT)
  470. return (jack_client_close(client) == 0);
  471. #else
  472. if (bridge.client_close_ptr != nullptr)
  473. return (bridge.client_close_ptr(client) == 0);
  474. #endif
  475. return false;
  476. }
  477. // -----------------------------------------------------------------------------
  478. int jackbridge_client_name_size()
  479. {
  480. #if defined(JACKBRIDGE_DUMMY)
  481. #elif defined(JACKBRIDGE_DIRECT)
  482. return jack_client_name_size();
  483. #else
  484. if (bridge.client_name_size_ptr != nullptr)
  485. return bridge.client_name_size_ptr();
  486. #endif
  487. return 0;
  488. }
  489. char* jackbridge_get_client_name(jack_client_t* client)
  490. {
  491. #if defined(JACKBRIDGE_DUMMY)
  492. #elif defined(JACKBRIDGE_DIRECT)
  493. return jack_get_client_name(client);
  494. #else
  495. if (bridge.get_client_name_ptr != nullptr)
  496. return bridge.get_client_name_ptr(client);
  497. #endif
  498. return nullptr;
  499. }
  500. // -----------------------------------------------------------------------------
  501. char* jackbridge_get_uuid_for_client_name(jack_client_t* client, const char* name)
  502. {
  503. #if defined(JACKBRIDGE_DUMMY)
  504. #elif defined(JACKBRIDGE_DIRECT)
  505. return jack_get_uuid_for_client_name(client, name);
  506. #else
  507. if (bridge.get_uuid_for_client_name_ptr != nullptr)
  508. return bridge.get_uuid_for_client_name_ptr(client, name);
  509. #endif
  510. return nullptr;
  511. }
  512. char* jackbridge_get_client_name_by_uuid(jack_client_t* client, const char* uuid)
  513. {
  514. #if defined(JACKBRIDGE_DUMMY)
  515. #elif defined(JACKBRIDGE_DIRECT)
  516. return jack_get_client_name_by_uuid(client, uuid);
  517. #else
  518. if (bridge.get_client_name_by_uuid_ptr != nullptr)
  519. return bridge.get_client_name_by_uuid_ptr(client, uuid);
  520. #endif
  521. return nullptr;
  522. }
  523. // -----------------------------------------------------------------------------
  524. bool jackbridge_activate(jack_client_t* client)
  525. {
  526. #if defined(JACKBRIDGE_DUMMY)
  527. #elif defined(JACKBRIDGE_DIRECT)
  528. return (jack_activate(client) == 0);
  529. #else
  530. if (bridge.activate_ptr != nullptr)
  531. return (bridge.activate_ptr(client) == 0);
  532. #endif
  533. return false;
  534. }
  535. bool jackbridge_deactivate(jack_client_t* client)
  536. {
  537. #if defined(JACKBRIDGE_DUMMY)
  538. #elif defined(JACKBRIDGE_DIRECT)
  539. return (jack_deactivate(client) == 0);
  540. #else
  541. if (bridge.deactivate_ptr != nullptr)
  542. return (bridge.deactivate_ptr(client) == 0);
  543. #endif
  544. return false;
  545. }
  546. bool jackbridge_is_realtime(jack_client_t* client)
  547. {
  548. #if defined(JACKBRIDGE_DUMMY)
  549. #elif defined(JACKBRIDGE_DIRECT)
  550. return jack_is_realtime(client);
  551. #else
  552. if (bridge.is_realtime_ptr != nullptr)
  553. return bridge.is_realtime_ptr(client);
  554. #endif
  555. return false;
  556. }
  557. // -----------------------------------------------------------------------------
  558. bool jackbridge_set_thread_init_callback(jack_client_t* client, JackThreadInitCallback thread_init_callback, void* arg)
  559. {
  560. #if defined(JACKBRIDGE_DUMMY)
  561. #elif defined(JACKBRIDGE_DIRECT)
  562. return (jack_set_thread_init_callback(client, thread_init_callback, arg) == 0);
  563. #else
  564. if (bridge.set_thread_init_callback_ptr != nullptr)
  565. return (bridge.set_thread_init_callback_ptr(client, thread_init_callback, arg) == 0);
  566. #endif
  567. return false;
  568. }
  569. void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg)
  570. {
  571. #if defined(JACKBRIDGE_DUMMY)
  572. #elif defined(JACKBRIDGE_DIRECT)
  573. jack_on_shutdown(client, shutdown_callback, arg);
  574. #else
  575. if (bridge.on_shutdown_ptr != nullptr)
  576. bridge.on_shutdown_ptr(client, shutdown_callback, arg);
  577. #endif
  578. }
  579. void jackbridge_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg)
  580. {
  581. #if defined(JACKBRIDGE_DUMMY)
  582. #elif defined(JACKBRIDGE_DIRECT)
  583. jack_on_info_shutdown(client, shutdown_callback, arg);
  584. #else
  585. if (bridge.on_info_shutdown_ptr != nullptr)
  586. bridge.on_info_shutdown_ptr(client, shutdown_callback, arg);
  587. #endif
  588. }
  589. bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg)
  590. {
  591. #if defined(JACKBRIDGE_DUMMY)
  592. #elif defined(JACKBRIDGE_DIRECT)
  593. return (jack_set_process_callback(client, process_callback, arg) == 0);
  594. #else
  595. if (bridge.set_process_callback_ptr != nullptr)
  596. return (bridge.set_process_callback_ptr(client, process_callback, arg) == 0);
  597. #endif
  598. return false;
  599. }
  600. bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg)
  601. {
  602. #if defined(JACKBRIDGE_DUMMY)
  603. #elif defined(JACKBRIDGE_DIRECT)
  604. return (jack_set_freewheel_callback(client, freewheel_callback, arg) == 0);
  605. #else
  606. if (bridge.set_freewheel_callback_ptr != nullptr)
  607. return (bridge.set_freewheel_callback_ptr(client, freewheel_callback, arg) == 0);
  608. #endif
  609. return false;
  610. }
  611. bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg)
  612. {
  613. #if defined(JACKBRIDGE_DUMMY)
  614. #elif defined(JACKBRIDGE_DIRECT)
  615. return (jack_set_buffer_size_callback(client, bufsize_callback, arg) == 0);
  616. #else
  617. if (bridge.set_buffer_size_callback_ptr != nullptr)
  618. return (bridge.set_buffer_size_callback_ptr(client, bufsize_callback, arg) == 0);
  619. #endif
  620. return false;
  621. }
  622. bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg)
  623. {
  624. #if defined(JACKBRIDGE_DUMMY)
  625. #elif defined(JACKBRIDGE_DIRECT)
  626. return (jack_set_sample_rate_callback(client, srate_callback, arg) == 0);
  627. #else
  628. if (bridge.set_sample_rate_callback_ptr != nullptr)
  629. return (bridge.set_sample_rate_callback_ptr(client, srate_callback, arg) == 0);
  630. #endif
  631. return false;
  632. }
  633. bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg)
  634. {
  635. #if defined(JACKBRIDGE_DUMMY)
  636. #elif defined(JACKBRIDGE_DIRECT)
  637. return (jack_set_client_registration_callback(client, registration_callback, arg) == 0);
  638. #else
  639. if (bridge.set_client_registration_callback_ptr != nullptr)
  640. return (bridge.set_client_registration_callback_ptr(client, registration_callback, arg) == 0);
  641. #endif
  642. return false;
  643. }
  644. bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void *arg)
  645. {
  646. #if defined(JACKBRIDGE_DUMMY)
  647. #elif defined(JACKBRIDGE_DIRECT)
  648. return (jack_set_port_registration_callback(client, registration_callback, arg) == 0);
  649. #else
  650. if (bridge.set_port_registration_callback_ptr != nullptr)
  651. return (bridge.set_port_registration_callback_ptr(client, registration_callback, arg) == 0);
  652. #endif
  653. return false;
  654. }
  655. bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg)
  656. {
  657. #if defined(JACKBRIDGE_DUMMY)
  658. #elif defined(JACKBRIDGE_DIRECT)
  659. return (jack_set_port_rename_callback(client, rename_callback, arg) == 0);
  660. #else
  661. if (bridge.set_port_rename_callback_ptr != nullptr)
  662. return (bridge.set_port_rename_callback_ptr(client, rename_callback, arg) == 0);
  663. #endif
  664. return false;
  665. }
  666. bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg)
  667. {
  668. #if defined(JACKBRIDGE_DUMMY)
  669. #elif defined(JACKBRIDGE_DIRECT)
  670. return (jack_set_port_connect_callback(client, connect_callback, arg) == 0);
  671. #else
  672. if (bridge.set_port_connect_callback_ptr != nullptr)
  673. return (bridge.set_port_connect_callback_ptr(client, connect_callback, arg) == 0);
  674. #endif
  675. return false;
  676. }
  677. bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg)
  678. {
  679. #if defined(JACKBRIDGE_DUMMY)
  680. #elif defined(JACKBRIDGE_DIRECT)
  681. return (jack_set_xrun_callback(client, xrun_callback, arg) == 0);
  682. #else
  683. if (bridge.set_xrun_callback_ptr != nullptr)
  684. return (bridge.set_xrun_callback_ptr(client, xrun_callback, arg) == 0);
  685. #endif
  686. return false;
  687. }
  688. bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg)
  689. {
  690. #if defined(JACKBRIDGE_DUMMY)
  691. #elif defined(JACKBRIDGE_DIRECT)
  692. return (jack_set_latency_callback(client, latency_callback, arg) == 0);
  693. #else
  694. if (bridge.set_latency_callback_ptr != nullptr)
  695. return (bridge.set_latency_callback_ptr(client, latency_callback, arg) == 0);
  696. #endif
  697. return false;
  698. }
  699. // -----------------------------------------------------------------------------
  700. bool jackbridge_set_freewheel(jack_client_t* client, bool onoff)
  701. {
  702. #if defined(JACKBRIDGE_DUMMY)
  703. #elif defined(JACKBRIDGE_DIRECT)
  704. return jack_set_freewheel(client, onoff);
  705. #else
  706. if (bridge.set_freewheel_ptr != nullptr)
  707. return bridge.set_freewheel_ptr(client, onoff);
  708. #endif
  709. return false;
  710. }
  711. bool jackbridge_set_buffer_size(jack_client_t* client, jack_nframes_t nframes)
  712. {
  713. #if defined(JACKBRIDGE_DUMMY)
  714. #elif defined(JACKBRIDGE_DIRECT)
  715. return jack_set_buffer_size(client, nframes);
  716. #else
  717. if (bridge.set_buffer_size_ptr != nullptr)
  718. return bridge.set_buffer_size_ptr(client, nframes);
  719. #endif
  720. return false;
  721. }
  722. // -----------------------------------------------------------------------------
  723. jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client)
  724. {
  725. #if defined(JACKBRIDGE_DUMMY)
  726. #elif defined(JACKBRIDGE_DIRECT)
  727. return jack_get_sample_rate(client);
  728. #else
  729. if (bridge.get_sample_rate_ptr != nullptr)
  730. return bridge.get_sample_rate_ptr(client);
  731. #endif
  732. return 0;
  733. }
  734. jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client)
  735. {
  736. #if defined(JACKBRIDGE_DUMMY)
  737. #elif defined(JACKBRIDGE_DIRECT)
  738. return jack_get_buffer_size(client);
  739. #else
  740. if (bridge.get_buffer_size_ptr != nullptr)
  741. return bridge.get_buffer_size_ptr(client);
  742. #endif
  743. return 0;
  744. }
  745. float jackbridge_cpu_load(jack_client_t* client)
  746. {
  747. #if defined(JACKBRIDGE_DUMMY)
  748. #elif defined(JACKBRIDGE_DIRECT)
  749. return jack_cpu_load(client);
  750. #else
  751. if (bridge.cpu_load_ptr != nullptr)
  752. return bridge.cpu_load_ptr(client);
  753. #endif
  754. return 0.0f;
  755. }
  756. // -----------------------------------------------------------------------------
  757. jack_port_t* jackbridge_port_register(jack_client_t* client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
  758. {
  759. #if defined(JACKBRIDGE_DUMMY)
  760. #elif defined(JACKBRIDGE_DIRECT)
  761. return jack_port_register(client, port_name, port_type, flags, buffer_size);
  762. #else
  763. if (bridge.port_register_ptr != nullptr)
  764. return bridge.port_register_ptr(client, port_name, port_type, flags, buffer_size);
  765. #endif
  766. return nullptr;
  767. }
  768. bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port)
  769. {
  770. #if defined(JACKBRIDGE_DUMMY)
  771. #elif defined(JACKBRIDGE_DIRECT)
  772. return (jack_port_unregister(client, port) == 0);
  773. #else
  774. if (bridge.port_unregister_ptr != nullptr)
  775. return (bridge.port_unregister_ptr(client, port) == 0);
  776. #endif
  777. return false;
  778. }
  779. void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes)
  780. {
  781. #if defined(JACKBRIDGE_DUMMY)
  782. #elif defined(JACKBRIDGE_DIRECT)
  783. return jack_port_get_buffer(port, nframes);
  784. #else
  785. if (bridge.port_get_buffer_ptr != nullptr)
  786. return bridge.port_get_buffer_ptr(port, nframes);
  787. #endif
  788. return nullptr;
  789. }
  790. // -----------------------------------------------------------------------------
  791. const char* jackbridge_port_name(const jack_port_t* port)
  792. {
  793. #if defined(JACKBRIDGE_DUMMY)
  794. #elif defined(JACKBRIDGE_DIRECT)
  795. return jack_port_name(port);
  796. #else
  797. if (bridge.port_name_ptr != nullptr)
  798. return bridge.port_name_ptr(port);
  799. #endif
  800. return nullptr;
  801. }
  802. jack_uuid_t jackbridge_port_uuid(const jack_port_t* port)
  803. {
  804. #if defined(JACKBRIDGE_DUMMY)
  805. #elif defined(JACKBRIDGE_DIRECT)
  806. return jack_port_uuid(port);
  807. #else
  808. if (bridge.port_uuid_ptr != nullptr)
  809. return bridge.port_uuid_ptr(port);
  810. #endif
  811. return 0;
  812. }
  813. const char* jackbridge_port_short_name(const jack_port_t* port)
  814. {
  815. #if defined(JACKBRIDGE_DUMMY)
  816. #elif defined(JACKBRIDGE_DIRECT)
  817. return jack_port_short_name(port);
  818. #else
  819. if (bridge.port_short_name_ptr != nullptr)
  820. return bridge.port_short_name_ptr(port);
  821. #endif
  822. return nullptr;
  823. }
  824. int jackbridge_port_flags(const jack_port_t* port)
  825. {
  826. #if defined(JACKBRIDGE_DUMMY)
  827. #elif defined(JACKBRIDGE_DIRECT)
  828. return jack_port_flags(port);
  829. #else
  830. if (bridge.port_flags_ptr != nullptr)
  831. return bridge.port_flags_ptr(port);
  832. #endif
  833. return 0x0;
  834. }
  835. const char* jackbridge_port_type(const jack_port_t* port)
  836. {
  837. #if defined(JACKBRIDGE_DUMMY)
  838. #elif defined(JACKBRIDGE_DIRECT)
  839. return jack_port_type(port);
  840. #else
  841. if (bridge.port_type_ptr != nullptr)
  842. return bridge.port_type_ptr(port);
  843. #endif
  844. return nullptr;
  845. }
  846. bool jackbridge_port_is_mine(const jack_client_t* client, const jack_port_t* port)
  847. {
  848. #if defined(JACKBRIDGE_DUMMY)
  849. #elif defined(JACKBRIDGE_DIRECT)
  850. return jack_port_is_mine(client, port);
  851. #else
  852. if (bridge.port_is_mine_ptr != nullptr)
  853. return bridge.port_is_mine_ptr(client, port);
  854. #endif
  855. return false;
  856. }
  857. int jackbridge_port_connected(const jack_port_t* port)
  858. {
  859. #if defined(JACKBRIDGE_DUMMY)
  860. #elif defined(JACKBRIDGE_DIRECT)
  861. return jack_port_connected(port);
  862. #else
  863. if (bridge.port_connected_ptr != nullptr)
  864. return bridge.port_connected_ptr(port);
  865. #endif
  866. return 0;
  867. }
  868. bool jackbridge_port_connected_to(const jack_port_t* port, const char* port_name)
  869. {
  870. #if defined(JACKBRIDGE_DUMMY)
  871. #elif defined(JACKBRIDGE_DIRECT)
  872. return jack_port_connected_to(port, port_name);
  873. #else
  874. if (bridge.port_connected_to_ptr != nullptr)
  875. return bridge.port_connected_to_ptr(port, port_name);
  876. #endif
  877. return false;
  878. }
  879. const char** jackbridge_port_get_connections(const jack_port_t* port)
  880. {
  881. #if defined(JACKBRIDGE_DUMMY)
  882. #elif defined(JACKBRIDGE_DIRECT)
  883. return jack_port_get_connections(port);
  884. #else
  885. if (bridge.port_get_connections_ptr != nullptr)
  886. return bridge.port_get_connections_ptr(port);
  887. #endif
  888. return nullptr;
  889. }
  890. const char** jackbridge_port_get_all_connections(const jack_client_t* client, const jack_port_t* port)
  891. {
  892. #if defined(JACKBRIDGE_DUMMY)
  893. #elif defined(JACKBRIDGE_DIRECT)
  894. return jack_port_get_all_connections(client, port);
  895. #else
  896. if (bridge.port_get_all_connections_ptr != nullptr)
  897. return bridge.port_get_all_connections_ptr(client, port);
  898. #endif
  899. return nullptr;
  900. }
  901. // -----------------------------------------------------------------------------
  902. bool jackbridge_port_set_name(jack_port_t* port, const char* port_name)
  903. {
  904. #if defined(JACKBRIDGE_DUMMY)
  905. #elif defined(JACKBRIDGE_DIRECT)
  906. return (jack_port_set_name(port, port_name) == 0);
  907. #else
  908. if (bridge.port_set_name_ptr != nullptr)
  909. return (bridge.port_set_name_ptr(port, port_name) == 0);
  910. #endif
  911. return false;
  912. }
  913. bool jackbridge_port_set_alias(jack_port_t* port, const char* alias)
  914. {
  915. #if defined(JACKBRIDGE_DUMMY)
  916. #elif defined(JACKBRIDGE_DIRECT)
  917. return (jack_port_set_alias(port, alias) == 0);
  918. #else
  919. if (bridge.port_set_alias_ptr != nullptr)
  920. return (bridge.port_set_alias_ptr(port, alias) == 0);
  921. #endif
  922. return false;
  923. }
  924. bool jackbridge_port_unset_alias(jack_port_t* port, const char* alias)
  925. {
  926. #if defined(JACKBRIDGE_DUMMY)
  927. #elif defined(JACKBRIDGE_DIRECT)
  928. return (jack_port_unset_alias(port, alias) == 0);
  929. #else
  930. if (bridge.port_unset_alias_ptr != nullptr)
  931. return (bridge.port_unset_alias_ptr(port, alias) == 0);
  932. #endif
  933. return false;
  934. }
  935. int jackbridge_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  936. {
  937. #if defined(JACKBRIDGE_DUMMY)
  938. #elif defined(JACKBRIDGE_DIRECT)
  939. return (jack_port_get_aliases(port, aliases) == 0);
  940. #else
  941. if (bridge.port_get_aliases_ptr != nullptr)
  942. return bridge.port_get_aliases_ptr(port, aliases);
  943. #endif
  944. return 0;
  945. }
  946. // -----------------------------------------------------------------------------
  947. bool jackbridge_port_request_monitor(jack_port_t* port, bool onoff)
  948. {
  949. #if defined(JACKBRIDGE_DUMMY)
  950. #elif defined(JACKBRIDGE_DIRECT)
  951. return (jack_port_request_monitor(port, onoff) == 0);
  952. #else
  953. if (bridge.port_request_monitor_ptr != nullptr)
  954. return (bridge.port_request_monitor_ptr(port, onoff) == 0);
  955. #endif
  956. return false;
  957. }
  958. bool jackbridge_port_request_monitor_by_name(jack_client_t* client, const char* port_name, bool onoff)
  959. {
  960. #if defined(JACKBRIDGE_DUMMY)
  961. #elif defined(JACKBRIDGE_DIRECT)
  962. return (jack_port_request_monitor_by_name(client, port_name, onoff) == 0);
  963. #else
  964. if (bridge.port_request_monitor_by_name_ptr != nullptr)
  965. return (bridge.port_request_monitor_by_name_ptr(client, port_name, onoff) == 0);
  966. #endif
  967. return false;
  968. }
  969. bool jackbridge_port_ensure_monitor(jack_port_t* port, bool onoff)
  970. {
  971. #if defined(JACKBRIDGE_DUMMY)
  972. #elif defined(JACKBRIDGE_DIRECT)
  973. return (jack_port_ensure_monitor(port, onoff) == 0);
  974. #else
  975. if (bridge.port_ensure_monitor_ptr != nullptr)
  976. return (bridge.port_ensure_monitor_ptr(port, onoff) == 0);
  977. #endif
  978. return false;
  979. }
  980. bool jackbridge_port_monitoring_input(jack_port_t* port)
  981. {
  982. #if defined(JACKBRIDGE_DUMMY)
  983. #elif defined(JACKBRIDGE_DIRECT)
  984. return jack_port_monitoring_input(port);
  985. #else
  986. if (bridge.port_monitoring_input_ptr != nullptr)
  987. return bridge.port_monitoring_input_ptr(port);
  988. #endif
  989. return false;
  990. }
  991. // -----------------------------------------------------------------------------
  992. bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port)
  993. {
  994. #if defined(JACKBRIDGE_DUMMY)
  995. #elif defined(JACKBRIDGE_DIRECT)
  996. return (jack_connect(client, source_port, destination_port) == 0);
  997. #else
  998. if (bridge.connect_ptr != nullptr)
  999. return (bridge.connect_ptr(client, source_port, destination_port) == 0);
  1000. #endif
  1001. return false;
  1002. }
  1003. bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port)
  1004. {
  1005. #if defined(JACKBRIDGE_DUMMY)
  1006. #elif defined(JACKBRIDGE_DIRECT)
  1007. return (jack_disconnect(client, source_port, destination_port) == 0);
  1008. #else
  1009. if (bridge.disconnect_ptr != nullptr)
  1010. return (bridge.disconnect_ptr(client, source_port, destination_port) == 0);
  1011. #endif
  1012. return false;
  1013. }
  1014. bool jackbridge_port_disconnect(jack_client_t* client, jack_port_t* port)
  1015. {
  1016. #if defined(JACKBRIDGE_DUMMY)
  1017. #elif defined(JACKBRIDGE_DIRECT)
  1018. return (jack_port_disconnect(client, port) == 0);
  1019. #else
  1020. if (bridge.port_disconnect_ptr != nullptr)
  1021. return (bridge.port_disconnect_ptr(client, port) == 0);
  1022. #endif
  1023. return false;
  1024. }
  1025. // -----------------------------------------------------------------------------
  1026. int jackbridge_port_name_size()
  1027. {
  1028. #if defined(JACKBRIDGE_DUMMY)
  1029. #elif defined(JACKBRIDGE_DIRECT)
  1030. return jack_port_name_size();
  1031. #else
  1032. if (bridge.port_name_size_ptr != nullptr)
  1033. return bridge.port_name_size_ptr();
  1034. #endif
  1035. return 0;
  1036. }
  1037. int jackbridge_port_type_size()
  1038. {
  1039. #if defined(JACKBRIDGE_DUMMY)
  1040. #elif defined(JACKBRIDGE_DIRECT)
  1041. return jack_port_type_size();
  1042. #else
  1043. if (bridge.port_type_size_ptr != nullptr)
  1044. return bridge.port_type_size_ptr();
  1045. #endif
  1046. return 0;
  1047. }
  1048. size_t jackbridge_port_type_get_buffer_size(jack_client_t* client, const char* port_type)
  1049. {
  1050. #if defined(JACKBRIDGE_DUMMY)
  1051. #elif defined(JACKBRIDGE_DIRECT)
  1052. return jack_port_type_get_buffer_size(client, port_type);
  1053. #else
  1054. if (bridge.port_type_get_buffer_size_ptr != nullptr)
  1055. return bridge.port_type_get_buffer_size_ptr(client, port_type);
  1056. #endif
  1057. return 0;
  1058. }
  1059. // -----------------------------------------------------------------------------
  1060. void jackbridge_port_get_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  1061. {
  1062. #if defined(JACKBRIDGE_DUMMY)
  1063. #elif defined(JACKBRIDGE_DIRECT)
  1064. return jack_port_get_latency_range(port, mode, range);
  1065. #else
  1066. if (bridge.port_get_latency_range_ptr != nullptr)
  1067. return bridge.port_get_latency_range_ptr(port, mode, range);
  1068. #endif
  1069. range->min = 0;
  1070. range->max = 0;
  1071. }
  1072. void jackbridge_port_set_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  1073. {
  1074. #if defined(JACKBRIDGE_DUMMY)
  1075. #elif defined(JACKBRIDGE_DIRECT)
  1076. jack_port_set_latency_range(port, mode, range);
  1077. #else
  1078. if (bridge.port_set_latency_range_ptr != nullptr)
  1079. bridge.port_set_latency_range_ptr(port, mode, range);
  1080. #endif
  1081. }
  1082. bool jackbridge_recompute_total_latencies(jack_client_t* client)
  1083. {
  1084. #if defined(JACKBRIDGE_DUMMY)
  1085. #elif defined(JACKBRIDGE_DIRECT)
  1086. return (jack_recompute_total_latencies(client) == 0);
  1087. #else
  1088. if (bridge.recompute_total_latencies_ptr != nullptr)
  1089. return (bridge.recompute_total_latencies_ptr(client) == 0);
  1090. #endif
  1091. return false;
  1092. }
  1093. // -----------------------------------------------------------------------------
  1094. const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  1095. {
  1096. #if defined(JACKBRIDGE_DUMMY)
  1097. #elif defined(JACKBRIDGE_DIRECT)
  1098. return jack_get_ports(client, port_name_pattern, type_name_pattern, flags);
  1099. #else
  1100. if (bridge.get_ports_ptr != nullptr)
  1101. return bridge.get_ports_ptr(client, port_name_pattern, type_name_pattern, flags);
  1102. #endif
  1103. return nullptr;
  1104. }
  1105. jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name)
  1106. {
  1107. #if defined(JACKBRIDGE_DUMMY)
  1108. #elif defined(JACKBRIDGE_DIRECT)
  1109. return jack_port_by_name(client, port_name);
  1110. #else
  1111. if (bridge.port_by_name_ptr != nullptr)
  1112. return bridge.port_by_name_ptr(client, port_name);
  1113. #endif
  1114. return nullptr;
  1115. }
  1116. jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id)
  1117. {
  1118. #if defined(JACKBRIDGE_DUMMY)
  1119. #elif defined(JACKBRIDGE_DIRECT)
  1120. return jack_port_by_id(client, port_id);
  1121. #else
  1122. if (bridge.port_by_id_ptr != nullptr)
  1123. return bridge.port_by_id_ptr(client, port_id);
  1124. #endif
  1125. return nullptr;
  1126. }
  1127. // -----------------------------------------------------------------------------
  1128. void jackbridge_free(void* ptr)
  1129. {
  1130. #if defined(JACKBRIDGE_DUMMY)
  1131. #elif defined(JACKBRIDGE_DIRECT)
  1132. return jack_free(ptr);
  1133. #else
  1134. if (bridge.free_ptr != nullptr)
  1135. return bridge.free_ptr(ptr);
  1136. // just in case
  1137. std::free(ptr);
  1138. #endif
  1139. }
  1140. // -----------------------------------------------------------------------------
  1141. uint32_t jackbridge_midi_get_event_count(void* port_buffer)
  1142. {
  1143. #if defined(JACKBRIDGE_DUMMY)
  1144. #elif defined(JACKBRIDGE_DIRECT)
  1145. return jack_midi_get_event_count(port_buffer);
  1146. #else
  1147. if (bridge.midi_get_event_count_ptr != nullptr)
  1148. return bridge.midi_get_event_count_ptr(port_buffer);
  1149. #endif
  1150. return 0;
  1151. }
  1152. bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index)
  1153. {
  1154. #if defined(JACKBRIDGE_DUMMY)
  1155. #elif defined(JACKBRIDGE_DIRECT)
  1156. return (jack_midi_event_get(event, port_buffer, event_index) == 0);
  1157. #else
  1158. if (bridge.midi_event_get_ptr != nullptr)
  1159. return (bridge.midi_event_get_ptr(event, port_buffer, event_index) == 0);
  1160. #endif
  1161. return false;
  1162. }
  1163. void jackbridge_midi_clear_buffer(void* port_buffer)
  1164. {
  1165. #if defined(JACKBRIDGE_DUMMY)
  1166. #elif defined(JACKBRIDGE_DIRECT)
  1167. jack_midi_clear_buffer(port_buffer);
  1168. #else
  1169. if (bridge.midi_clear_buffer_ptr != nullptr)
  1170. bridge.midi_clear_buffer_ptr(port_buffer);
  1171. #endif
  1172. }
  1173. bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, size_t data_size)
  1174. {
  1175. #if defined(JACKBRIDGE_DUMMY)
  1176. #elif defined(JACKBRIDGE_DIRECT)
  1177. return (jack_midi_event_write(port_buffer, time, data, data_size) == 0);
  1178. #else
  1179. if (bridge.midi_event_write_ptr != nullptr)
  1180. return (bridge.midi_event_write_ptr(port_buffer, time, data, data_size) == 0);
  1181. #endif
  1182. return false;
  1183. }
  1184. jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size)
  1185. {
  1186. #if defined(JACKBRIDGE_DUMMY)
  1187. #elif defined(JACKBRIDGE_DIRECT)
  1188. return jack_midi_event_reserve(port_buffer, time, data_size);
  1189. #else
  1190. if (bridge.midi_event_reserve_ptr != nullptr)
  1191. return bridge.midi_event_reserve_ptr(port_buffer, time, data_size);
  1192. #endif
  1193. return nullptr;
  1194. }
  1195. // -----------------------------------------------------------------------------
  1196. bool jackbridge_release_timebase(jack_client_t* client)
  1197. {
  1198. #if defined(JACKBRIDGE_DUMMY)
  1199. #elif defined(JACKBRIDGE_DIRECT)
  1200. return (jack_release_timebase(client) == 0);
  1201. #else
  1202. if (bridge.release_timebase_ptr != nullptr)
  1203. return (bridge.release_timebase_ptr(client) == 0);
  1204. #endif
  1205. return false;
  1206. }
  1207. bool jackbridge_set_sync_callback(jack_client_t* client, JackSyncCallback sync_callback, void* arg)
  1208. {
  1209. #if defined(JACKBRIDGE_DUMMY)
  1210. #elif defined(JACKBRIDGE_DIRECT)
  1211. return (jack_set_sync_callback(client, sync_callback, arg) == 0);
  1212. #else
  1213. if (bridge.set_sync_callback_ptr != nullptr)
  1214. return (bridge.set_sync_callback_ptr(client, sync_callback, arg) == 0);
  1215. #endif
  1216. return false;
  1217. }
  1218. bool jackbridge_set_sync_timeout(jack_client_t* client, jack_time_t timeout)
  1219. {
  1220. #if defined(JACKBRIDGE_DUMMY)
  1221. #elif defined(JACKBRIDGE_DIRECT)
  1222. return (jack_set_sync_timeout(client, timeout) == 0);
  1223. #else
  1224. if (bridge.set_sync_timeout_ptr != nullptr)
  1225. return (bridge.set_sync_timeout_ptr(client, timeout) == 0);
  1226. #endif
  1227. return false;
  1228. }
  1229. bool jackbridge_set_timebase_callback(jack_client_t* client, bool conditional, JackTimebaseCallback timebase_callback, void* arg)
  1230. {
  1231. #if defined(JACKBRIDGE_DUMMY)
  1232. #elif defined(JACKBRIDGE_DIRECT)
  1233. return (jack_set_timebase_callback(client, conditional, timebase_callback, arg) == 0);
  1234. #else
  1235. if (bridge.set_timebase_callback_ptr != nullptr)
  1236. return (bridge.set_timebase_callback_ptr(client, conditional, timebase_callback, arg) == 0);
  1237. #endif
  1238. return false;
  1239. }
  1240. bool jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame)
  1241. {
  1242. #if defined(JACKBRIDGE_DUMMY)
  1243. #elif defined(JACKBRIDGE_DIRECT)
  1244. return (jack_transport_locate(client, frame) == 0);
  1245. #else
  1246. if (bridge.transport_locate_ptr != nullptr)
  1247. return (bridge.transport_locate_ptr(client, frame) == 0);
  1248. #endif
  1249. return false;
  1250. }
  1251. jack_transport_state_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos)
  1252. {
  1253. #if defined(JACKBRIDGE_DUMMY)
  1254. #elif defined(JACKBRIDGE_DIRECT)
  1255. return jack_transport_query(client, pos);
  1256. #else
  1257. if (bridge.transport_query_ptr != nullptr)
  1258. return bridge.transport_query_ptr(client, pos);
  1259. #endif
  1260. if (pos != nullptr)
  1261. {
  1262. // invalidate
  1263. pos->unique_1 = 0;
  1264. pos->unique_2 = 1;
  1265. }
  1266. return JackTransportStopped;
  1267. }
  1268. jack_nframes_t jackbridge_get_current_transport_frame(const jack_client_t* client)
  1269. {
  1270. #if defined(JACKBRIDGE_DUMMY)
  1271. #elif defined(JACKBRIDGE_DIRECT)
  1272. return jack_get_current_transport_frame(client);
  1273. #else
  1274. if (bridge.get_current_transport_frame_ptr != nullptr)
  1275. return bridge.get_current_transport_frame_ptr(client);
  1276. #endif
  1277. return 0;
  1278. }
  1279. bool jackbridge_transport_reposition(jack_client_t* client, const jack_position_t* pos)
  1280. {
  1281. #if defined(JACKBRIDGE_DUMMY)
  1282. #elif defined(JACKBRIDGE_DIRECT)
  1283. return (jack_transport_reposition(client, pos) == 0);
  1284. #else
  1285. if (bridge.transport_reposition_ptr != nullptr)
  1286. return (bridge.transport_reposition_ptr(client, pos) == 0);
  1287. #endif
  1288. return false;
  1289. }
  1290. void jackbridge_transport_start(jack_client_t* client)
  1291. {
  1292. #if defined(JACKBRIDGE_DUMMY)
  1293. #elif defined(JACKBRIDGE_DIRECT)
  1294. jack_transport_start(client);
  1295. #else
  1296. if (bridge.transport_start_ptr != nullptr)
  1297. bridge.transport_start_ptr(client);
  1298. #endif
  1299. }
  1300. void jackbridge_transport_stop(jack_client_t* client)
  1301. {
  1302. #if defined(JACKBRIDGE_DUMMY)
  1303. #elif defined(JACKBRIDGE_DIRECT)
  1304. jack_transport_stop(client);
  1305. #else
  1306. if (bridge.transport_stop_ptr != nullptr)
  1307. bridge.transport_stop_ptr(client);
  1308. #endif
  1309. }
  1310. // -----------------------------------------------------------------------------
  1311. bool jackbridge_set_property(jack_client_t* client, jack_uuid_t subject, const char* key, const char* value, const char* type)
  1312. {
  1313. #if defined(JACKBRIDGE_DUMMY)
  1314. #elif defined(JACKBRIDGE_DIRECT)
  1315. return (jack_set_property(client, subject, key, value, type) == 0);
  1316. #else
  1317. if (bridge.set_property_ptr != nullptr)
  1318. return (bridge.set_property_ptr(client, subject, key, value, type) == 0);
  1319. #endif
  1320. return false;
  1321. }
  1322. bool jackbridge_get_property(jack_uuid_t subject, const char* key, char** value, char** type)
  1323. {
  1324. #if defined(JACKBRIDGE_DUMMY)
  1325. #elif defined(JACKBRIDGE_DIRECT)
  1326. return (jack_get_property(subject, key, value, type) == 0);
  1327. #else
  1328. if (bridge.get_property_ptr != nullptr)
  1329. return (bridge.get_property_ptr(subject, key, value, type) == 0);
  1330. #endif
  1331. return false;
  1332. }
  1333. void jackbridge_free_description(jack_description_t* desc, bool free_description_itself)
  1334. {
  1335. #if defined(JACKBRIDGE_DUMMY)
  1336. #elif defined(JACKBRIDGE_DIRECT)
  1337. jack_free_description(desc, free_description_itself);
  1338. #else
  1339. if (bridge.free_description_ptr != nullptr)
  1340. bridge.free_description_ptr(desc, free_description_itself);
  1341. #endif
  1342. }
  1343. bool jackbridge_get_properties(jack_uuid_t subject, jack_description_t* desc)
  1344. {
  1345. #if defined(JACKBRIDGE_DUMMY)
  1346. #elif defined(JACKBRIDGE_DIRECT)
  1347. return (jack_get_properties(subject, desc) == 0);
  1348. #else
  1349. if (bridge.get_properties_ptr != nullptr)
  1350. return (bridge.get_properties_ptr(subject, desc) == 0);
  1351. #endif
  1352. return false;
  1353. }
  1354. bool jackbridge_get_all_properties(jack_description_t** descs)
  1355. {
  1356. #if defined(JACKBRIDGE_DUMMY)
  1357. #elif defined(JACKBRIDGE_DIRECT)
  1358. return (jack_get_all_properties(descs) == 0);
  1359. #else
  1360. if (bridge.get_all_properties_ptr != nullptr)
  1361. return (bridge.get_all_properties_ptr(descs) == 0);
  1362. #endif
  1363. return false;
  1364. }
  1365. bool jackbridge_remove_property(jack_client_t* client, jack_uuid_t subject, const char* key)
  1366. {
  1367. #if defined(JACKBRIDGE_DUMMY)
  1368. #elif defined(JACKBRIDGE_DIRECT)
  1369. return (jack_remove_property(client, subject, key) == 0);
  1370. #else
  1371. if (bridge.remove_property_ptr != nullptr)
  1372. return (bridge.remove_property_ptr(client, subject, key) == 0);
  1373. #endif
  1374. return false;
  1375. }
  1376. int jackbridge_remove_properties(jack_client_t* client, jack_uuid_t subject)
  1377. {
  1378. #if defined(JACKBRIDGE_DUMMY)
  1379. #elif defined(JACKBRIDGE_DIRECT)
  1380. return jack_remove_properties(client, subject);
  1381. #else
  1382. if (bridge.remove_properties_ptr != nullptr)
  1383. return bridge.remove_properties_ptr(client, subject);
  1384. #endif
  1385. return 0;
  1386. }
  1387. bool jackbridge_remove_all_properties(jack_client_t* client)
  1388. {
  1389. #if defined(JACKBRIDGE_DUMMY)
  1390. #elif defined(JACKBRIDGE_DIRECT)
  1391. return (jack_remove_all_properties(client) == 0);
  1392. #else
  1393. if (bridge.remove_all_properties_ptr != nullptr)
  1394. return (bridge.remove_all_properties_ptr(client) == 0);
  1395. #endif
  1396. return false;
  1397. }
  1398. bool jackbridge_set_property_change_callback(jack_client_t* client, JackPropertyChangeCallback callback, void* arg)
  1399. {
  1400. #if defined(JACKBRIDGE_DUMMY)
  1401. #elif defined(JACKBRIDGE_DIRECT)
  1402. return (jack_set_property_change_callback(client, callback, arg) == 0);
  1403. #else
  1404. if (bridge.set_property_change_callback_ptr != nullptr)
  1405. return (bridge.set_property_change_callback_ptr(client, callback, arg) == 0);
  1406. #endif
  1407. return false;
  1408. }
  1409. // -----------------------------------------------------------------------------