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.

1024 lines
33KB

  1. /*
  2. * JackBridge (Part 1, JACK functions)
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * For a full copy of the license see the LGPL.txt file
  15. */
  16. #include "JackBridge.hpp"
  17. #if ! (defined(JACKBRIDGE_DIRECT) || defined(JACKBRIDGE_DUMMY))
  18. #include "CarlaLibUtils.hpp"
  19. // -----------------------------------------------------------------------------
  20. typedef const char* (*jacksym_get_version_string)();
  21. typedef jack_client_t* (*jacksym_client_open)(const char*, jack_options_t, jack_status_t*, ...);
  22. typedef const char* (*jacksym_client_rename)(jack_client_t* client, const char* new_name);
  23. typedef int (*jacksym_client_close)(jack_client_t*);
  24. typedef int (*jacksym_client_name_size)();
  25. typedef char* (*jacksym_get_client_name)(jack_client_t*);
  26. typedef int (*jacksym_activate)(jack_client_t*);
  27. typedef int (*jacksym_deactivate)(jack_client_t*);
  28. typedef void (*jacksym_on_shutdown)(jack_client_t*, JackShutdownCallback, void*);
  29. typedef int (*jacksym_set_process_callback)(jack_client_t*, JackProcessCallback, void*);
  30. typedef int (*jacksym_set_freewheel_callback)(jack_client_t*, JackFreewheelCallback, void*);
  31. typedef int (*jacksym_set_buffer_size_callback)(jack_client_t*, JackBufferSizeCallback, void*);
  32. typedef int (*jacksym_set_sample_rate_callback)(jack_client_t*, JackSampleRateCallback, void*);
  33. typedef int (*jacksym_set_client_registration_callback)(jack_client_t*, JackClientRegistrationCallback, void*);
  34. typedef int (*jacksym_set_port_registration_callback)(jack_client_t*, JackPortRegistrationCallback, void*);
  35. typedef int (*jacksym_set_port_connect_callback)(jack_client_t*, JackPortConnectCallback, void*);
  36. typedef int (*jacksym_set_port_rename_callback)(jack_client_t*, JackPortRenameCallback, void*);
  37. typedef int (*jacksym_set_latency_callback)(jack_client_t*, JackLatencyCallback, void*);
  38. typedef int (*jacksym_set_xrun_callback)(jack_client_t*, JackXRunCallback, void*);
  39. typedef jack_nframes_t (*jacksym_get_sample_rate)(jack_client_t*);
  40. typedef jack_nframes_t (*jacksym_get_buffer_size)(jack_client_t*);
  41. typedef jack_port_t* (*jacksym_port_register)(jack_client_t*, const char*, const char*, unsigned long, unsigned long);
  42. typedef int (*jacksym_port_unregister)(jack_client_t*, jack_port_t*);
  43. typedef void* (*jacksym_port_get_buffer)(jack_port_t*, jack_nframes_t);
  44. typedef const char* (*jacksym_port_name)(const jack_port_t*);
  45. typedef const char* (*jacksym_port_short_name)(const jack_port_t*);
  46. typedef int (*jacksym_port_flags)(const jack_port_t*);
  47. typedef const char* (*jacksym_port_type)(const jack_port_t*);
  48. typedef const char** (*jacksym_port_get_connections)(const jack_port_t*);
  49. typedef int (*jacksym_port_set_name)(jack_port_t*, const char*);
  50. typedef int (*jacksym_connect)(jack_client_t*, const char*, const char*);
  51. typedef int (*jacksym_disconnect)(jack_client_t*, const char*, const char*);
  52. typedef int (*jacksym_port_name_size)();
  53. typedef void (*jacksym_port_get_latency_range)(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t*);
  54. typedef void (*jacksym_port_set_latency_range)(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t*);
  55. typedef int (*jacksym_recompute_total_latencies)(jack_client_t*);
  56. typedef const char** (*jacksym_get_ports)(jack_client_t*, const char*, const char*, unsigned long);
  57. typedef jack_port_t* (*jacksym_port_by_name)(jack_client_t*, const char*);
  58. typedef jack_port_t* (*jacksym_port_by_id)(jack_client_t*, jack_port_id_t);
  59. typedef void (*jacksym_free)(void*);
  60. typedef uint32_t (*jacksym_midi_get_event_count)(void*);
  61. typedef int (*jacksym_midi_event_get)(jack_midi_event_t*, void*, uint32_t);
  62. typedef void (*jacksym_midi_clear_buffer)(void*);
  63. typedef int (*jacksym_midi_event_write)(void*, jack_nframes_t, const jack_midi_data_t*, size_t);
  64. typedef jack_midi_data_t* (*jacksym_midi_event_reserve)(void*, jack_nframes_t, size_t);
  65. typedef int (*jacksym_transport_locate)(jack_client_t*, jack_nframes_t);
  66. typedef void (*jacksym_transport_start)(jack_client_t*);
  67. typedef void (*jacksym_transport_stop)(jack_client_t*);
  68. typedef jack_transport_state_t (*jacksym_transport_query)(const jack_client_t*, jack_position_t*);
  69. typedef int (*jacksym_custom_publish_data)(jack_client_t* client, const char* key, const void* data, size_t size);
  70. typedef int (*jacksym_custom_get_data)(jack_client_t* client, const char* client_name, const char* key, void** data, size_t* size);
  71. typedef int (*jacksym_custom_unpublish_data)(jack_client_t* client, const char* key);
  72. typedef int (*jacksym_custom_set_data_appearance_callback)(jack_client_t* client, JackCustomDataAppearanceCallback callback, void* arg);
  73. typedef const char** (*jacksym_custom_get_keys)(jack_client_t* client, const char* client_name);
  74. // -----------------------------------------------------------------------------
  75. struct JackBridge {
  76. void* lib;
  77. jacksym_get_version_string get_version_string_ptr;
  78. jacksym_client_open client_open_ptr;
  79. jacksym_client_rename client_rename_ptr;
  80. jacksym_client_close client_close_ptr;
  81. jacksym_client_name_size client_name_size_ptr;
  82. jacksym_get_client_name get_client_name_ptr;
  83. jacksym_activate activate_ptr;
  84. jacksym_deactivate deactivate_ptr;
  85. jacksym_on_shutdown on_shutdown_ptr;
  86. jacksym_set_process_callback set_process_callback_ptr;
  87. jacksym_set_freewheel_callback set_freewheel_callback_ptr;
  88. jacksym_set_buffer_size_callback set_buffer_size_callback_ptr;
  89. jacksym_set_sample_rate_callback set_sample_rate_callback_ptr;
  90. jacksym_set_client_registration_callback set_client_registration_callback_ptr;
  91. jacksym_set_port_registration_callback set_port_registration_callback_ptr;
  92. jacksym_set_port_connect_callback set_port_connect_callback_ptr;
  93. jacksym_set_port_rename_callback set_port_rename_callback_ptr;
  94. jacksym_set_latency_callback set_latency_callback_ptr;
  95. jacksym_set_xrun_callback set_xrun_callback_ptr;
  96. jacksym_get_sample_rate get_sample_rate_ptr;
  97. jacksym_get_buffer_size get_buffer_size_ptr;
  98. jacksym_port_register port_register_ptr;
  99. jacksym_port_unregister port_unregister_ptr;
  100. jacksym_port_get_buffer port_get_buffer_ptr;
  101. jacksym_port_name port_name_ptr;
  102. jacksym_port_short_name port_short_name_ptr;
  103. jacksym_port_flags port_flags_ptr;
  104. jacksym_port_type port_type_ptr;
  105. jacksym_port_get_connections port_get_connections_ptr;
  106. jacksym_port_set_name port_set_name_ptr;
  107. jacksym_connect connect_ptr;
  108. jacksym_disconnect disconnect_ptr;
  109. jacksym_port_name_size port_name_size_ptr;
  110. jacksym_port_get_latency_range port_get_latency_range_ptr;
  111. jacksym_port_set_latency_range port_set_latency_range_ptr;
  112. jacksym_recompute_total_latencies recompute_total_latencies_ptr;
  113. jacksym_get_ports get_ports_ptr;
  114. jacksym_port_by_name port_by_name_ptr;
  115. jacksym_port_by_id port_by_id_ptr;
  116. jacksym_free free_ptr;
  117. jacksym_midi_get_event_count midi_get_event_count_ptr;
  118. jacksym_midi_event_get midi_event_get_ptr;
  119. jacksym_midi_clear_buffer midi_clear_buffer_ptr;
  120. jacksym_midi_event_write midi_event_write_ptr;
  121. jacksym_midi_event_reserve midi_event_reserve_ptr;
  122. jacksym_transport_locate transport_locate_ptr;
  123. jacksym_transport_start transport_start_ptr;
  124. jacksym_transport_stop transport_stop_ptr;
  125. jacksym_transport_query transport_query_ptr;
  126. jacksym_custom_publish_data custom_publish_data_ptr;
  127. jacksym_custom_get_data custom_get_data_ptr;
  128. jacksym_custom_unpublish_data custom_unpublish_data_ptr;
  129. jacksym_custom_set_data_appearance_callback custom_set_data_appearance_callback_ptr;
  130. jacksym_custom_get_keys custom_get_keys_ptr;
  131. JackBridge()
  132. : lib(nullptr),
  133. get_version_string_ptr(nullptr),
  134. client_open_ptr(nullptr),
  135. client_rename_ptr(nullptr),
  136. client_close_ptr(nullptr),
  137. client_name_size_ptr(nullptr),
  138. get_client_name_ptr(nullptr),
  139. activate_ptr(nullptr),
  140. deactivate_ptr(nullptr),
  141. on_shutdown_ptr(nullptr),
  142. set_process_callback_ptr(nullptr),
  143. set_freewheel_callback_ptr(nullptr),
  144. set_buffer_size_callback_ptr(nullptr),
  145. set_sample_rate_callback_ptr(nullptr),
  146. set_client_registration_callback_ptr(nullptr),
  147. set_port_registration_callback_ptr(nullptr),
  148. set_port_connect_callback_ptr(nullptr),
  149. set_port_rename_callback_ptr(nullptr),
  150. set_latency_callback_ptr(nullptr),
  151. set_xrun_callback_ptr(nullptr),
  152. get_sample_rate_ptr(nullptr),
  153. get_buffer_size_ptr(nullptr),
  154. port_register_ptr(nullptr),
  155. port_unregister_ptr(nullptr),
  156. port_get_buffer_ptr(nullptr),
  157. port_name_ptr(nullptr),
  158. port_short_name_ptr(nullptr),
  159. port_flags_ptr(nullptr),
  160. port_type_ptr(nullptr),
  161. port_get_connections_ptr(nullptr),
  162. port_set_name_ptr(nullptr),
  163. connect_ptr(nullptr),
  164. disconnect_ptr(nullptr),
  165. port_name_size_ptr(nullptr),
  166. port_get_latency_range_ptr(nullptr),
  167. port_set_latency_range_ptr(nullptr),
  168. recompute_total_latencies_ptr(nullptr),
  169. get_ports_ptr(nullptr),
  170. port_by_name_ptr(nullptr),
  171. port_by_id_ptr(nullptr),
  172. free_ptr(nullptr),
  173. midi_get_event_count_ptr(nullptr),
  174. midi_event_get_ptr(nullptr),
  175. midi_clear_buffer_ptr(nullptr),
  176. midi_event_write_ptr(nullptr),
  177. midi_event_reserve_ptr(nullptr),
  178. transport_locate_ptr(nullptr),
  179. transport_start_ptr(nullptr),
  180. transport_stop_ptr(nullptr),
  181. transport_query_ptr(nullptr),
  182. custom_publish_data_ptr(nullptr),
  183. custom_get_data_ptr(nullptr),
  184. custom_unpublish_data_ptr(nullptr),
  185. custom_set_data_appearance_callback_ptr(nullptr),
  186. custom_get_keys_ptr(nullptr)
  187. {
  188. # if defined(CARLA_OS_MAC)
  189. const char* const filename("libjack.dylib");
  190. # elif defined(CARLA_OS_WIN)
  191. const char* const filename("libjack.dll");
  192. # else
  193. const char* const filename("libjack.so.0");
  194. # endif
  195. lib = lib_open(filename);
  196. if (lib == nullptr)
  197. {
  198. fprintf(stderr, "Failed to load JACK DLL, reason:\n%s\n", lib_error(filename));
  199. return;
  200. }
  201. else
  202. {
  203. fprintf(stdout, "%s loaded sucessfully!\n", filename);
  204. }
  205. #define JOIN(a, b) a ## b
  206. #define LIB_SYMBOL(NAME) JOIN(NAME, _ptr) = (jacksym_##NAME)lib_symbol(lib, "jack_" #NAME);
  207. LIB_SYMBOL(get_version_string)
  208. LIB_SYMBOL(client_open)
  209. LIB_SYMBOL(client_rename)
  210. LIB_SYMBOL(client_close)
  211. LIB_SYMBOL(client_name_size)
  212. LIB_SYMBOL(get_client_name)
  213. LIB_SYMBOL(activate)
  214. LIB_SYMBOL(deactivate)
  215. LIB_SYMBOL(on_shutdown)
  216. LIB_SYMBOL(set_process_callback)
  217. LIB_SYMBOL(set_freewheel_callback)
  218. LIB_SYMBOL(set_buffer_size_callback)
  219. LIB_SYMBOL(set_sample_rate_callback)
  220. LIB_SYMBOL(set_client_registration_callback)
  221. LIB_SYMBOL(set_port_registration_callback)
  222. LIB_SYMBOL(set_port_connect_callback)
  223. LIB_SYMBOL(set_port_rename_callback)
  224. LIB_SYMBOL(set_latency_callback)
  225. LIB_SYMBOL(set_xrun_callback)
  226. LIB_SYMBOL(get_sample_rate)
  227. LIB_SYMBOL(get_buffer_size)
  228. LIB_SYMBOL(port_register)
  229. LIB_SYMBOL(port_unregister)
  230. LIB_SYMBOL(port_get_buffer)
  231. LIB_SYMBOL(port_name)
  232. LIB_SYMBOL(port_short_name)
  233. LIB_SYMBOL(port_flags)
  234. LIB_SYMBOL(port_type)
  235. LIB_SYMBOL(port_get_connections)
  236. LIB_SYMBOL(port_set_name)
  237. LIB_SYMBOL(connect)
  238. LIB_SYMBOL(disconnect)
  239. LIB_SYMBOL(port_name_size)
  240. LIB_SYMBOL(port_get_latency_range)
  241. LIB_SYMBOL(port_set_latency_range)
  242. LIB_SYMBOL(recompute_total_latencies)
  243. LIB_SYMBOL(get_ports)
  244. LIB_SYMBOL(port_by_name)
  245. LIB_SYMBOL(port_by_id)
  246. LIB_SYMBOL(free)
  247. LIB_SYMBOL(midi_get_event_count)
  248. LIB_SYMBOL(midi_event_get)
  249. LIB_SYMBOL(midi_clear_buffer)
  250. LIB_SYMBOL(midi_event_write)
  251. LIB_SYMBOL(midi_event_reserve)
  252. LIB_SYMBOL(transport_locate)
  253. LIB_SYMBOL(transport_start)
  254. LIB_SYMBOL(transport_stop)
  255. LIB_SYMBOL(transport_query)
  256. LIB_SYMBOL(custom_publish_data)
  257. LIB_SYMBOL(custom_get_data)
  258. LIB_SYMBOL(custom_unpublish_data)
  259. LIB_SYMBOL(custom_set_data_appearance_callback)
  260. LIB_SYMBOL(custom_get_keys)
  261. #undef JOIN
  262. #undef LIB_SYMBOL
  263. }
  264. ~JackBridge()
  265. {
  266. if (lib != nullptr)
  267. lib_close(lib);
  268. }
  269. };
  270. static JackBridge bridge;
  271. #endif // ! JACKBRIDGE_DIRECT
  272. // -----------------------------------------------------------------------------
  273. const char* jackbridge_get_version_string()
  274. {
  275. #if JACKBRIDGE_DUMMY
  276. return nullptr;
  277. #elif JACKBRIDGE_DIRECT
  278. return jack_get_version_string();
  279. #else
  280. if (bridge.get_version_string_ptr != nullptr)
  281. return bridge.get_version_string_ptr();
  282. return nullptr;
  283. #endif
  284. }
  285. jack_client_t* jackbridge_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
  286. {
  287. #if JACKBRIDGE_DUMMY
  288. return nullptr;
  289. #elif JACKBRIDGE_DIRECT
  290. return jack_client_open(client_name, options, status);
  291. #else
  292. if (bridge.client_open_ptr != nullptr)
  293. return bridge.client_open_ptr(client_name, options, status);
  294. return nullptr;
  295. #endif
  296. }
  297. const char* jackbridge_client_rename(jack_client_t* client, const char* new_name)
  298. {
  299. #if JACKBRIDGE_DUMMY
  300. return nullptr;
  301. #elif JACKBRIDGE_DIRECT
  302. //return jack_client_rename(client, new_name);
  303. return nullptr;
  304. // unused, for now
  305. (void)client;
  306. (void)new_name;
  307. #else
  308. if (bridge.client_rename_ptr != nullptr)
  309. return bridge.client_rename_ptr(client, new_name);
  310. return nullptr;
  311. #endif
  312. }
  313. // -----------------------------------------------------------------------------
  314. bool jackbridge_client_close(jack_client_t* client)
  315. {
  316. #if JACKBRIDGE_DUMMY
  317. return false;
  318. #elif JACKBRIDGE_DIRECT
  319. return (jack_client_close(client) == 0);
  320. #else
  321. if (bridge.client_close_ptr != nullptr)
  322. return (bridge.client_close_ptr(client) == 0);
  323. return false;
  324. #endif
  325. }
  326. int jackbridge_client_name_size()
  327. {
  328. #if JACKBRIDGE_DUMMY
  329. return 0;
  330. #elif JACKBRIDGE_DIRECT
  331. return jack_client_name_size();
  332. #else
  333. if (bridge.client_name_size_ptr != nullptr)
  334. return bridge.client_name_size_ptr();
  335. return 0;
  336. #endif
  337. }
  338. char* jackbridge_get_client_name(jack_client_t* client)
  339. {
  340. #if JACKBRIDGE_DUMMY
  341. return nullptr;
  342. #elif JACKBRIDGE_DIRECT
  343. return jack_get_client_name(client);
  344. #else
  345. if (bridge.get_client_name_ptr != nullptr)
  346. return bridge.get_client_name_ptr(client);
  347. return nullptr;
  348. #endif
  349. }
  350. // -----------------------------------------------------------------------------
  351. bool jackbridge_activate(jack_client_t* client)
  352. {
  353. #if JACKBRIDGE_DUMMY
  354. return false;
  355. #elif JACKBRIDGE_DIRECT
  356. return (jack_activate(client) == 0);
  357. #else
  358. if (bridge.activate_ptr != nullptr)
  359. return (bridge.activate_ptr(client) == 0);
  360. return false;
  361. #endif
  362. }
  363. bool jackbridge_deactivate(jack_client_t* client)
  364. {
  365. #if JACKBRIDGE_DUMMY
  366. return false;
  367. #elif JACKBRIDGE_DIRECT
  368. return (jack_deactivate(client) == 0);
  369. #else
  370. if (bridge.deactivate_ptr != nullptr)
  371. return (bridge.deactivate_ptr(client) == 0);
  372. return false;
  373. #endif
  374. }
  375. void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg)
  376. {
  377. #if JACKBRIDGE_DUMMY
  378. #elif JACKBRIDGE_DIRECT
  379. jack_on_shutdown(client, shutdown_callback, arg);
  380. #else
  381. if (bridge.on_shutdown_ptr != nullptr)
  382. bridge.on_shutdown_ptr(client, shutdown_callback, arg);
  383. #endif
  384. }
  385. bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg)
  386. {
  387. #if JACKBRIDGE_DUMMY
  388. return false;
  389. #elif JACKBRIDGE_DIRECT
  390. return (jack_set_process_callback(client, process_callback, arg) == 0);
  391. #else
  392. if (bridge.set_process_callback_ptr != nullptr)
  393. return (bridge.set_process_callback_ptr(client, process_callback, arg) == 0);
  394. return false;
  395. #endif
  396. }
  397. bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg)
  398. {
  399. #if JACKBRIDGE_DUMMY
  400. return false;
  401. #elif JACKBRIDGE_DIRECT
  402. return (jack_set_freewheel_callback(client, freewheel_callback, arg) == 0);
  403. #else
  404. if (bridge.set_freewheel_callback_ptr != nullptr)
  405. return (bridge.set_freewheel_callback_ptr(client, freewheel_callback, arg) == 0);
  406. return false;
  407. #endif
  408. }
  409. bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg)
  410. {
  411. #if JACKBRIDGE_DUMMY
  412. return false;
  413. #elif JACKBRIDGE_DIRECT
  414. return (jack_set_buffer_size_callback(client, bufsize_callback, arg) == 0);
  415. #else
  416. if (bridge.set_buffer_size_callback_ptr != nullptr)
  417. return (bridge.set_buffer_size_callback_ptr(client, bufsize_callback, arg) == 0);
  418. return false;
  419. #endif
  420. }
  421. bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg)
  422. {
  423. #if JACKBRIDGE_DUMMY
  424. return false;
  425. #elif JACKBRIDGE_DIRECT
  426. return (jack_set_sample_rate_callback(client, srate_callback, arg) == 0);
  427. #else
  428. if (bridge.set_sample_rate_callback_ptr != nullptr)
  429. return (bridge.set_sample_rate_callback_ptr(client, srate_callback, arg) == 0);
  430. return false;
  431. #endif
  432. }
  433. bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg)
  434. {
  435. #if JACKBRIDGE_DUMMY
  436. return false;
  437. #elif JACKBRIDGE_DIRECT
  438. return (jack_set_client_registration_callback(client, registration_callback, arg) == 0);
  439. #else
  440. if (bridge.set_client_registration_callback_ptr != nullptr)
  441. return (bridge.set_client_registration_callback_ptr(client, registration_callback, arg) == 0);
  442. return false;
  443. #endif
  444. }
  445. bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void *arg)
  446. {
  447. #if JACKBRIDGE_DUMMY
  448. return false;
  449. #elif JACKBRIDGE_DIRECT
  450. return (jack_set_port_registration_callback(client, registration_callback, arg) == 0);
  451. #else
  452. if (bridge.set_port_registration_callback_ptr != nullptr)
  453. return (bridge.set_port_registration_callback_ptr(client, registration_callback, arg) == 0);
  454. return false;
  455. #endif
  456. }
  457. bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg)
  458. {
  459. #if JACKBRIDGE_DUMMY
  460. return false;
  461. #elif JACKBRIDGE_DIRECT
  462. return (jack_set_port_connect_callback(client, connect_callback, arg) == 0);
  463. #else
  464. if (bridge.set_port_connect_callback_ptr != nullptr)
  465. return (bridge.set_port_connect_callback_ptr(client, connect_callback, arg) == 0);
  466. return false;
  467. #endif
  468. }
  469. bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg)
  470. {
  471. #if JACKBRIDGE_DUMMY
  472. return false;
  473. #elif JACKBRIDGE_DIRECT
  474. return (jack_set_port_rename_callback(client, rename_callback, arg) == 0);
  475. #else
  476. if (bridge.set_port_rename_callback_ptr != nullptr)
  477. return (bridge.set_port_rename_callback_ptr(client, rename_callback, arg) == 0);
  478. return false;
  479. #endif
  480. }
  481. bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg)
  482. {
  483. #if JACKBRIDGE_DUMMY
  484. return false;
  485. #elif JACKBRIDGE_DIRECT
  486. return (jack_set_latency_callback(client, latency_callback, arg) == 0);
  487. #else
  488. if (bridge.set_latency_callback_ptr != nullptr)
  489. return (bridge.set_latency_callback_ptr(client, latency_callback, arg) == 0);
  490. return false;
  491. #endif
  492. }
  493. bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg)
  494. {
  495. #if JACKBRIDGE_DUMMY
  496. return false;
  497. #elif JACKBRIDGE_DIRECT
  498. return (jack_set_xrun_callback(client, xrun_callback, arg) == 0);
  499. #else
  500. if (bridge.set_xrun_callback_ptr != nullptr)
  501. return (bridge.set_xrun_callback_ptr(client, xrun_callback, arg) == 0);
  502. return false;
  503. #endif
  504. }
  505. // -----------------------------------------------------------------------------
  506. jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client)
  507. {
  508. #if JACKBRIDGE_DUMMY
  509. return 0;
  510. #elif JACKBRIDGE_DIRECT
  511. return jack_get_sample_rate(client);
  512. #else
  513. if (bridge.get_sample_rate_ptr != nullptr)
  514. return bridge.get_sample_rate_ptr(client);
  515. return 0;
  516. #endif
  517. }
  518. jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client)
  519. {
  520. #if JACKBRIDGE_DUMMY
  521. return 0;
  522. #elif JACKBRIDGE_DIRECT
  523. return jack_get_buffer_size(client);
  524. #else
  525. if (bridge.get_buffer_size_ptr != nullptr)
  526. return bridge.get_buffer_size_ptr(client);
  527. return 0;
  528. #endif
  529. }
  530. 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)
  531. {
  532. #if JACKBRIDGE_DUMMY
  533. return nullptr;
  534. #elif JACKBRIDGE_DIRECT
  535. return jack_port_register(client, port_name, port_type, flags, buffer_size);
  536. #else
  537. if (bridge.port_register_ptr != nullptr)
  538. return bridge.port_register_ptr(client, port_name, port_type, flags, buffer_size);
  539. return nullptr;
  540. #endif
  541. }
  542. bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port)
  543. {
  544. #if JACKBRIDGE_DUMMY
  545. return false;
  546. #elif JACKBRIDGE_DIRECT
  547. return (jack_port_unregister(client, port) == 0);
  548. #else
  549. if (bridge.port_unregister_ptr != nullptr)
  550. return (bridge.port_unregister_ptr(client, port) == 0);
  551. return false;
  552. #endif
  553. }
  554. void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes)
  555. {
  556. #if JACKBRIDGE_DUMMY
  557. return nullptr;
  558. #elif JACKBRIDGE_DIRECT
  559. return jack_port_get_buffer(port, nframes);
  560. #else
  561. if (bridge.port_get_buffer_ptr != nullptr)
  562. return bridge.port_get_buffer_ptr(port, nframes);
  563. return nullptr;
  564. #endif
  565. }
  566. // -----------------------------------------------------------------------------
  567. const char* jackbridge_port_name(const jack_port_t* port)
  568. {
  569. #if JACKBRIDGE_DUMMY
  570. return nullptr;
  571. #elif JACKBRIDGE_DIRECT
  572. return jack_port_name(port);
  573. #else
  574. if (bridge.port_name_ptr != nullptr)
  575. return bridge.port_name_ptr(port);
  576. return nullptr;
  577. #endif
  578. }
  579. const char* jackbridge_port_short_name(const jack_port_t* port)
  580. {
  581. #if JACKBRIDGE_DUMMY
  582. return nullptr;
  583. #elif JACKBRIDGE_DIRECT
  584. return jack_port_short_name(port);
  585. #else
  586. if (bridge.port_short_name_ptr != nullptr)
  587. return bridge.port_short_name_ptr(port);
  588. return nullptr;
  589. #endif
  590. }
  591. int jackbridge_port_flags(const jack_port_t* port)
  592. {
  593. #if JACKBRIDGE_DUMMY
  594. return 0;
  595. #elif JACKBRIDGE_DIRECT
  596. return jack_port_flags(port);
  597. #else
  598. if (bridge.port_flags_ptr != nullptr)
  599. return bridge.port_flags_ptr(port);
  600. return 0;
  601. #endif
  602. }
  603. const char* jackbridge_port_type(const jack_port_t* port)
  604. {
  605. #if JACKBRIDGE_DUMMY
  606. return nullptr;
  607. #elif JACKBRIDGE_DIRECT
  608. return jack_port_type(port);
  609. #else
  610. if (bridge.port_type_ptr != nullptr)
  611. return bridge.port_type_ptr(port);
  612. return nullptr;
  613. #endif
  614. }
  615. const char** jackbridge_port_get_connections(const jack_port_t* port)
  616. {
  617. #if JACKBRIDGE_DUMMY
  618. return nullptr;
  619. #elif JACKBRIDGE_DIRECT
  620. return jack_port_get_connections(port);
  621. #else
  622. if (bridge.port_get_connections_ptr != nullptr)
  623. return bridge.port_get_connections_ptr(port);
  624. return nullptr;
  625. #endif
  626. }
  627. // -----------------------------------------------------------------------------
  628. bool jackbridge_port_set_name(jack_port_t* port, const char* port_name)
  629. {
  630. #if JACKBRIDGE_DUMMY
  631. return false;
  632. #elif JACKBRIDGE_DIRECT
  633. return (jack_port_set_name(port, port_name) == 0);
  634. #else
  635. if (bridge.port_set_name_ptr != nullptr)
  636. return (bridge.port_set_name_ptr(port, port_name) == 0);
  637. return false;
  638. #endif
  639. }
  640. bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port)
  641. {
  642. #if JACKBRIDGE_DUMMY
  643. return false;
  644. #elif JACKBRIDGE_DIRECT
  645. return (jack_connect(client, source_port, destination_port) == 0);
  646. #else
  647. if (bridge.connect_ptr != nullptr)
  648. return (bridge.connect_ptr(client, source_port, destination_port) == 0);
  649. return false;
  650. #endif
  651. }
  652. bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port)
  653. {
  654. #if JACKBRIDGE_DUMMY
  655. return false;
  656. #elif JACKBRIDGE_DIRECT
  657. return (jack_disconnect(client, source_port, destination_port) == 0);
  658. #else
  659. if (bridge.disconnect_ptr != nullptr)
  660. return (bridge.disconnect_ptr(client, source_port, destination_port) == 0);
  661. return false;
  662. #endif
  663. }
  664. int jackbridge_port_name_size()
  665. {
  666. #if JACKBRIDGE_DUMMY
  667. return 0;
  668. #elif JACKBRIDGE_DIRECT
  669. return jack_port_name_size();
  670. #else
  671. if (bridge.port_name_size_ptr != nullptr)
  672. return bridge.port_name_size_ptr();
  673. return 0;
  674. #endif
  675. }
  676. void jackbridge_port_get_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  677. {
  678. #if JACKBRIDGE_DUMMY
  679. #elif JACKBRIDGE_DIRECT
  680. return jack_port_get_latency_range(port, mode, range);
  681. #else
  682. if (bridge.port_get_latency_range_ptr != nullptr)
  683. bridge.port_get_latency_range_ptr(port, mode, range);
  684. #endif
  685. }
  686. void jackbridge_port_set_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  687. {
  688. #if JACKBRIDGE_DUMMY
  689. #elif JACKBRIDGE_DIRECT
  690. return jack_port_set_latency_range(port, mode, range);
  691. #else
  692. if (bridge.port_set_latency_range_ptr != nullptr)
  693. bridge.port_set_latency_range_ptr(port, mode, range);
  694. #endif
  695. }
  696. bool jackbridge_recompute_total_latencies(jack_client_t* client)
  697. {
  698. #if JACKBRIDGE_DUMMY
  699. return false;
  700. #elif JACKBRIDGE_DIRECT
  701. return (jack_recompute_total_latencies(client) == 0);
  702. #else
  703. if (bridge.recompute_total_latencies_ptr != nullptr)
  704. return (bridge.recompute_total_latencies_ptr(client) == 0);
  705. return false;
  706. #endif
  707. }
  708. const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  709. {
  710. #if JACKBRIDGE_DUMMY
  711. return nullptr;
  712. #elif JACKBRIDGE_DIRECT
  713. return jack_get_ports(client, port_name_pattern, type_name_pattern, flags);
  714. #else
  715. if (bridge.get_ports_ptr != nullptr)
  716. return bridge.get_ports_ptr(client, port_name_pattern, type_name_pattern, flags);
  717. return nullptr;
  718. #endif
  719. }
  720. jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name)
  721. {
  722. #if JACKBRIDGE_DUMMY
  723. return nullptr;
  724. #elif JACKBRIDGE_DIRECT
  725. return jack_port_by_name(client, port_name);
  726. #else
  727. if (bridge.port_by_name_ptr != nullptr)
  728. return bridge.port_by_name_ptr(client, port_name);
  729. return nullptr;
  730. #endif
  731. }
  732. jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id)
  733. {
  734. #if JACKBRIDGE_DUMMY
  735. return nullptr;
  736. #elif JACKBRIDGE_DIRECT
  737. return jack_port_by_id(client, port_id);
  738. #else
  739. if (bridge.port_by_id_ptr != nullptr)
  740. return bridge.port_by_id_ptr(client, port_id);
  741. return nullptr;
  742. #endif
  743. }
  744. // -----------------------------------------------------------------------------
  745. void jackbridge_free(void* ptr)
  746. {
  747. #if JACKBRIDGE_DUMMY
  748. #elif JACKBRIDGE_DIRECT
  749. return jack_free(ptr);
  750. #else
  751. if (bridge.free_ptr != nullptr)
  752. return bridge.free_ptr(ptr);
  753. // just in case
  754. std::free(ptr);
  755. #endif
  756. }
  757. // -----------------------------------------------------------------------------
  758. uint32_t jackbridge_midi_get_event_count(void* port_buffer)
  759. {
  760. #if JACKBRIDGE_DUMMY
  761. return 0;
  762. #elif JACKBRIDGE_DIRECT
  763. return jack_midi_get_event_count(port_buffer);
  764. #else
  765. if (bridge.midi_get_event_count_ptr != nullptr)
  766. return bridge.midi_get_event_count_ptr(port_buffer);
  767. return 0;
  768. #endif
  769. }
  770. bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index)
  771. {
  772. #if JACKBRIDGE_DUMMY
  773. return false;
  774. #elif JACKBRIDGE_DIRECT
  775. return (jack_midi_event_get(event, port_buffer, event_index) == 0);
  776. #else
  777. if (bridge.midi_event_get_ptr != nullptr)
  778. return (bridge.midi_event_get_ptr(event, port_buffer, event_index) == 0);
  779. return false;
  780. #endif
  781. }
  782. void jackbridge_midi_clear_buffer(void* port_buffer)
  783. {
  784. #if JACKBRIDGE_DUMMY
  785. #elif JACKBRIDGE_DIRECT
  786. return jack_midi_clear_buffer(port_buffer);
  787. #else
  788. if (bridge.midi_clear_buffer_ptr != nullptr)
  789. bridge.midi_clear_buffer_ptr(port_buffer);
  790. #endif
  791. }
  792. bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, size_t data_size)
  793. {
  794. #if JACKBRIDGE_DUMMY
  795. return false;
  796. #elif JACKBRIDGE_DIRECT
  797. return (jack_midi_event_write(port_buffer, time, data, data_size) == 0);
  798. #else
  799. if (bridge.midi_event_write_ptr != nullptr)
  800. return (bridge.midi_event_write_ptr(port_buffer, time, data, data_size) == 0);
  801. return false;
  802. #endif
  803. }
  804. jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size)
  805. {
  806. #if JACKBRIDGE_DUMMY
  807. return nullptr;
  808. #elif JACKBRIDGE_DIRECT
  809. return jack_midi_event_reserve(port_buffer, time, data_size);
  810. #else
  811. if (bridge.midi_event_reserve_ptr != nullptr)
  812. return bridge.midi_event_reserve_ptr(port_buffer, time, data_size);
  813. return nullptr;
  814. #endif
  815. }
  816. // -----------------------------------------------------------------------------
  817. int jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame)
  818. {
  819. #if JACKBRIDGE_DUMMY
  820. return 0;
  821. #elif JACKBRIDGE_DIRECT
  822. return (jack_transport_locate(client, frame) == 0);
  823. #else
  824. if (bridge.transport_locate_ptr != nullptr)
  825. return (bridge.transport_locate_ptr(client, frame) == 0);
  826. return 0;
  827. #endif
  828. }
  829. void jackbridge_transport_start(jack_client_t* client)
  830. {
  831. #if JACKBRIDGE_DUMMY
  832. #elif JACKBRIDGE_DIRECT
  833. jack_transport_start(client);
  834. #else
  835. if (bridge.transport_start_ptr != nullptr)
  836. bridge.transport_start_ptr(client);
  837. #endif
  838. }
  839. void jackbridge_transport_stop(jack_client_t* client)
  840. {
  841. #if JACKBRIDGE_DUMMY
  842. #elif JACKBRIDGE_DIRECT
  843. jack_transport_stop(client);
  844. #else
  845. if (bridge.transport_stop_ptr != nullptr)
  846. bridge.transport_stop_ptr(client);
  847. #endif
  848. }
  849. jack_transport_state_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos)
  850. {
  851. #if JACKBRIDGE_DUMMY
  852. return JackTransportStopped;
  853. #elif JACKBRIDGE_DIRECT
  854. return jack_transport_query(client, pos);
  855. #else
  856. if (bridge.transport_query_ptr != nullptr)
  857. return bridge.transport_query_ptr(client, pos);
  858. return JackTransportStopped;
  859. #endif
  860. }
  861. // -----------------------------------------------------------------------------
  862. bool jackbridge_custom_publish_data(jack_client_t* client, const char* key, const void* data, size_t size)
  863. {
  864. #if JACKBRIDGE_DUMMY
  865. return false;
  866. #elif JACKBRIDGE_DIRECT
  867. return (jack_custom_publish_data(client, key, data, size) == 0);
  868. #else
  869. if (bridge.custom_publish_data_ptr != nullptr)
  870. return (bridge.custom_publish_data_ptr(client, key, data, size) == 0);
  871. return false;
  872. #endif
  873. }
  874. bool jackbridge_custom_get_data(jack_client_t* client, const char* client_name, const char* key, void** data, size_t* size)
  875. {
  876. #if JACKBRIDGE_DUMMY
  877. return false;
  878. #elif JACKBRIDGE_DIRECT
  879. return (jack_custom_get_data(client, client_name, key, data, size) == 0);
  880. #else
  881. if (bridge.custom_get_data_ptr != nullptr)
  882. return (bridge.custom_get_data_ptr(client, client_name, key, data, size) == 0);
  883. return false;
  884. #endif
  885. }
  886. bool jackbridge_custom_unpublish_data(jack_client_t* client, const char* key)
  887. {
  888. #if JACKBRIDGE_DUMMY
  889. return false;
  890. #elif JACKBRIDGE_DIRECT
  891. return (jack_custom_unpublish_data(client, key) == 0);
  892. #else
  893. if (bridge.custom_unpublish_data_ptr != nullptr)
  894. return (bridge.custom_unpublish_data_ptr(client, key) == 0);
  895. return false;
  896. #endif
  897. }
  898. bool jackbridge_custom_set_data_appearance_callback(jack_client_t* client, JackCustomDataAppearanceCallback callback, void* arg)
  899. {
  900. #if JACKBRIDGE_DUMMY
  901. return false;
  902. #elif JACKBRIDGE_DIRECT
  903. return (jack_custom_set_data_appearance_callback(client, callback, arg) == 0);
  904. #else
  905. if (bridge.custom_set_data_appearance_callback_ptr != nullptr)
  906. return (bridge.custom_set_data_appearance_callback_ptr(client, callback, arg) == 0);
  907. return false;
  908. #endif
  909. }
  910. const char** jackbridge_custom_get_keys(jack_client_t* client, const char* client_name)
  911. {
  912. #if JACKBRIDGE_DUMMY
  913. return nullptr;
  914. #elif JACKBRIDGE_DIRECT
  915. return jack_custom_get_keys(client, client_name);
  916. #else
  917. if (bridge.custom_get_keys_ptr != nullptr)
  918. return bridge.custom_get_keys_ptr(client, client_name);
  919. return nullptr;
  920. #endif
  921. }
  922. // -----------------------------------------------------------------------------