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.

JackBridge1.cpp 29KB

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