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.

1522 lines
49KB

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