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.

417 lines
19KB

  1. /*
  2. * JackBridge
  3. * Copyright (C) 2013-2019 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. #ifndef JACKBRIDGE_HPP_INCLUDED
  17. #define JACKBRIDGE_HPP_INCLUDED
  18. #ifdef __WINE__
  19. # if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
  20. # define __WINE64__
  21. # endif
  22. # undef WIN32
  23. # undef WIN64
  24. # undef _WIN32
  25. # undef _WIN64
  26. # undef __WIN32__
  27. # undef __WIN64__
  28. #endif
  29. #include "CarlaDefines.h"
  30. #if (defined(__WINE__) || defined(CARLA_OS_WIN)) && defined(__cdecl)
  31. # define JACKBRIDGE_API __cdecl
  32. #else
  33. # define JACKBRIDGE_API
  34. #endif
  35. #ifdef JACKBRIDGE_DIRECT
  36. # include <jack/jack.h>
  37. # include <jack/midiport.h>
  38. # include <jack/transport.h>
  39. # include <jack/session.h>
  40. # include <jack/metadata.h>
  41. # include <jack/uuid.h>
  42. #else
  43. #include <cstddef>
  44. #ifdef CARLA_PROPER_CPP11_SUPPORT
  45. # include <cstdint>
  46. #else
  47. # include <stdint.h>
  48. #endif
  49. #ifndef POST_PACKED_STRUCTURE
  50. # if defined(__GNUC__)
  51. /* POST_PACKED_STRUCTURE needs to be a macro which
  52. expands into a compiler directive. The directive must
  53. tell the compiler to arrange the preceding structure
  54. declaration so that it is packed on byte-boundaries rather
  55. than use the natural alignment of the processor and/or
  56. compiler.
  57. */
  58. #define PRE_PACKED_STRUCTURE
  59. #define POST_PACKED_STRUCTURE __attribute__((__packed__))
  60. # elif defined(_MSC_VER)
  61. #define PRE_PACKED_STRUCTURE1 __pragma(pack(push,1))
  62. #define PRE_PACKED_STRUCTURE PRE_PACKED_STRUCTURE1
  63. /* PRE_PACKED_STRUCTURE needs to be a macro which
  64. expands into a compiler directive. The directive must
  65. tell the compiler to arrange the following structure
  66. declaration so that it is packed on byte-boundaries rather
  67. than use the natural alignment of the processor and/or
  68. compiler.
  69. */
  70. #define POST_PACKED_STRUCTURE ;__pragma(pack(pop))
  71. /* and POST_PACKED_STRUCTURE needs to be a macro which
  72. restores the packing to its previous setting */
  73. # else
  74. #define PRE_PACKED_STRUCTURE
  75. #define POST_PACKED_STRUCTURE
  76. # endif
  77. #endif
  78. #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
  79. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  80. #define JACK_MAX_FRAMES (4294967295U)
  81. #define JackOpenOptions (JackSessionID|JackServerName|JackNoStartServer|JackUseExactName)
  82. #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
  83. #define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode|JackBBTFrameOffset|JackAudioVideoRatio|JackVideoFrameOffset)
  84. #define EXTENDED_TIME_INFO
  85. extern "C" {
  86. enum JackOptions {
  87. JackNullOption = 0x00,
  88. JackNoStartServer = 0x01,
  89. JackUseExactName = 0x02,
  90. JackServerName = 0x04,
  91. JackLoadName = 0x08,
  92. JackLoadInit = 0x10,
  93. JackSessionID = 0x20
  94. };
  95. enum JackStatus {
  96. JackFailure = 0x0001,
  97. JackInvalidOption = 0x0002,
  98. JackNameNotUnique = 0x0004,
  99. JackServerStarted = 0x0008,
  100. JackServerFailed = 0x0010,
  101. JackServerError = 0x0020,
  102. JackNoSuchClient = 0x0040,
  103. JackLoadFailure = 0x0080,
  104. JackInitFailure = 0x0100,
  105. JackShmFailure = 0x0200,
  106. JackVersionError = 0x0400,
  107. JackBackendError = 0x0800,
  108. JackClientZombie = 0x1000
  109. };
  110. enum JackLatencyCallbackMode {
  111. JackCaptureLatency,
  112. JackPlaybackLatency
  113. };
  114. enum JackPortFlags {
  115. JackPortIsInput = 0x01,
  116. JackPortIsOutput = 0x02,
  117. JackPortIsPhysical = 0x04,
  118. JackPortCanMonitor = 0x08,
  119. JackPortIsTerminal = 0x10
  120. };
  121. enum JackTransportState {
  122. JackTransportStopped = 0,
  123. JackTransportRolling = 1,
  124. JackTransportLooping = 2,
  125. JackTransportStarting = 3
  126. };
  127. enum JackPositionBits {
  128. JackPositionBBT = 0x010,
  129. JackPositionTimecode = 0x020,
  130. JackBBTFrameOffset = 0x040,
  131. JackAudioVideoRatio = 0x080,
  132. JackVideoFrameOffset = 0x100
  133. };
  134. enum JackSessionEventType {
  135. JackSessionSave = 1,
  136. JackSessionSaveAndQuit = 2,
  137. JackSessionSaveTemplate = 3
  138. };
  139. enum JackSessionFlags {
  140. JackSessionSaveError = 0x1,
  141. JackSessionNeedTerminal = 0x2
  142. };
  143. enum JackPropertyChange {
  144. PropertyCreated,
  145. PropertyChanged,
  146. PropertyDeleted
  147. };
  148. typedef uint32_t jack_nframes_t;
  149. typedef uint32_t jack_port_id_t;
  150. typedef uint64_t jack_time_t;
  151. typedef uint64_t jack_uuid_t;
  152. typedef uint64_t jack_unique_t;
  153. typedef uchar jack_midi_data_t;
  154. typedef float jack_default_audio_sample_t;
  155. typedef enum JackOptions jack_options_t;
  156. typedef enum JackStatus jack_status_t;
  157. typedef enum JackLatencyCallbackMode jack_latency_callback_mode_t;
  158. typedef enum JackTransportState jack_transport_state_t;
  159. typedef enum JackPositionBits jack_position_bits_t;
  160. typedef enum JackSessionEventType jack_session_event_type_t;
  161. typedef enum JackSessionFlags jack_session_flags_t;
  162. typedef enum JackPropertyChange jack_property_change_t;
  163. struct _jack_midi_event {
  164. jack_nframes_t time;
  165. size_t size;
  166. jack_midi_data_t* buffer;
  167. };
  168. // NOTE: packed in JACK2 but not in JACK1
  169. PRE_PACKED_STRUCTURE
  170. struct _jack_latency_range {
  171. jack_nframes_t min;
  172. jack_nframes_t max;
  173. } POST_PACKED_STRUCTURE;
  174. PRE_PACKED_STRUCTURE
  175. struct _jack_position {
  176. jack_unique_t unique_1;
  177. jack_time_t usecs;
  178. jack_nframes_t frame_rate;
  179. jack_nframes_t frame;
  180. jack_position_bits_t valid;
  181. int32_t bar;
  182. int32_t beat;
  183. int32_t tick;
  184. double bar_start_tick;
  185. float beats_per_bar;
  186. float beat_type;
  187. double ticks_per_beat;
  188. double beats_per_minute;
  189. double frame_time;
  190. double next_time;
  191. jack_nframes_t bbt_offset;
  192. float audio_frames_per_video_frame;
  193. jack_nframes_t video_offset;
  194. int32_t padding[7];
  195. jack_unique_t unique_2;
  196. } POST_PACKED_STRUCTURE;
  197. struct _jack_session_event {
  198. jack_session_event_type_t type;
  199. const char* session_dir;
  200. const char* client_uuid;
  201. char* command_line;
  202. jack_session_flags_t flags;
  203. uint32_t future;
  204. };
  205. struct _jack_session_command_t {
  206. const char* uuid;
  207. const char* client_name;
  208. const char* command;
  209. jack_session_flags_t flags;
  210. };
  211. typedef struct {
  212. const char* key;
  213. const char* data;
  214. const char* type;
  215. } jack_property_t;
  216. typedef struct {
  217. jack_uuid_t subject;
  218. uint32_t property_cnt;
  219. jack_property_t* properties;
  220. uint32_t property_size;
  221. } jack_description_t;
  222. typedef struct _jack_port jack_port_t;
  223. typedef struct _jack_client jack_client_t;
  224. typedef struct _jack_midi_event jack_midi_event_t;
  225. typedef struct _jack_latency_range jack_latency_range_t;
  226. typedef struct _jack_position jack_position_t;
  227. typedef struct _jack_session_event jack_session_event_t;
  228. typedef struct _jack_session_command_t jack_session_command_t;
  229. typedef void (JACKBRIDGE_API *JackLatencyCallback)(jack_latency_callback_mode_t mode, void* arg);
  230. typedef int (JACKBRIDGE_API *JackProcessCallback)(jack_nframes_t nframes, void* arg);
  231. typedef void (JACKBRIDGE_API *JackThreadInitCallback)(void* arg);
  232. typedef int (JACKBRIDGE_API *JackGraphOrderCallback)(void* arg);
  233. typedef int (JACKBRIDGE_API *JackXRunCallback)(void* arg);
  234. typedef int (JACKBRIDGE_API *JackBufferSizeCallback)(jack_nframes_t nframes, void* arg);
  235. typedef int (JACKBRIDGE_API *JackSampleRateCallback)(jack_nframes_t nframes, void* arg);
  236. typedef void (JACKBRIDGE_API *JackPortRegistrationCallback)(jack_port_id_t port, int register_, void* arg);
  237. typedef void (JACKBRIDGE_API *JackClientRegistrationCallback)(const char* name, int register_, void* arg);
  238. typedef void (JACKBRIDGE_API *JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
  239. typedef void (JACKBRIDGE_API *JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void* arg);
  240. typedef void (JACKBRIDGE_API *JackFreewheelCallback)(int starting, void* arg);
  241. typedef void (JACKBRIDGE_API *JackShutdownCallback)(void* arg);
  242. typedef void (JACKBRIDGE_API *JackInfoShutdownCallback)(jack_status_t code, const char* reason, void* arg);
  243. typedef int (JACKBRIDGE_API *JackSyncCallback)(jack_transport_state_t state, jack_position_t* pos, void* arg);
  244. typedef void (JACKBRIDGE_API *JackTimebaseCallback)(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
  245. typedef void (JACKBRIDGE_API *JackSessionCallback)(jack_session_event_t* event, void* arg);
  246. typedef void (JACKBRIDGE_API *JackPropertyChangeCallback)(jack_uuid_t subject, const char* key, jack_property_change_t change, void* arg);
  247. } // extern "C"
  248. #endif // ! JACKBRIDGE_DIRECT
  249. JACKBRIDGE_API bool jackbridge_is_ok() noexcept;
  250. JACKBRIDGE_API void jackbridge_init();
  251. JACKBRIDGE_API void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr);
  252. JACKBRIDGE_API const char* jackbridge_get_version_string();
  253. JACKBRIDGE_API jack_client_t* jackbridge_client_open(const char* client_name, uint32_t options, jack_status_t* status);
  254. JACKBRIDGE_API bool jackbridge_client_close(jack_client_t* client);
  255. JACKBRIDGE_API int jackbridge_client_name_size();
  256. JACKBRIDGE_API char* jackbridge_get_client_name(jack_client_t* client);
  257. JACKBRIDGE_API char* jackbridge_client_get_uuid(jack_client_t* client);
  258. JACKBRIDGE_API char* jackbridge_get_uuid_for_client_name(jack_client_t* client, const char* name);
  259. JACKBRIDGE_API char* jackbridge_get_client_name_by_uuid(jack_client_t* client, const char* uuid);
  260. JACKBRIDGE_API bool jackbridge_uuid_parse(const char* buf, jack_uuid_t* uuid);
  261. JACKBRIDGE_API bool jackbridge_activate(jack_client_t* client);
  262. JACKBRIDGE_API bool jackbridge_deactivate(jack_client_t* client);
  263. JACKBRIDGE_API bool jackbridge_is_realtime(jack_client_t* client);
  264. JACKBRIDGE_API bool jackbridge_set_thread_init_callback(jack_client_t* client, JackThreadInitCallback thread_init_callback, void* arg);
  265. JACKBRIDGE_API void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg);
  266. JACKBRIDGE_API void jackbridge_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg);
  267. JACKBRIDGE_API bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg);
  268. JACKBRIDGE_API bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg);
  269. JACKBRIDGE_API bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg);
  270. JACKBRIDGE_API bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg);
  271. JACKBRIDGE_API bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg);
  272. JACKBRIDGE_API bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void* arg);
  273. JACKBRIDGE_API bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg);
  274. JACKBRIDGE_API bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg);
  275. JACKBRIDGE_API bool jackbridge_set_graph_order_callback(jack_client_t* client, JackGraphOrderCallback graph_callback, void* arg);
  276. JACKBRIDGE_API bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg);
  277. JACKBRIDGE_API bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg);
  278. JACKBRIDGE_API bool jackbridge_set_freewheel(jack_client_t* client, bool onoff);
  279. JACKBRIDGE_API bool jackbridge_set_buffer_size(jack_client_t* client, jack_nframes_t nframes);
  280. JACKBRIDGE_API jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client);
  281. JACKBRIDGE_API jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client);
  282. JACKBRIDGE_API float jackbridge_cpu_load(jack_client_t* client);
  283. JACKBRIDGE_API jack_port_t* jackbridge_port_register(jack_client_t* client, const char* port_name, const char* port_type, uint64_t flags, uint64_t buffer_size);
  284. JACKBRIDGE_API bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port);
  285. JACKBRIDGE_API void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes);
  286. JACKBRIDGE_API const char* jackbridge_port_name(const jack_port_t* port);
  287. JACKBRIDGE_API jack_uuid_t jackbridge_port_uuid(const jack_port_t* port);
  288. JACKBRIDGE_API const char* jackbridge_port_short_name(const jack_port_t* port);
  289. JACKBRIDGE_API int jackbridge_port_flags(const jack_port_t* port);
  290. JACKBRIDGE_API const char* jackbridge_port_type(const jack_port_t* port);
  291. JACKBRIDGE_API bool jackbridge_port_is_mine(const jack_client_t* client, const jack_port_t* port);
  292. JACKBRIDGE_API int jackbridge_port_connected(const jack_port_t* port);
  293. JACKBRIDGE_API bool jackbridge_port_connected_to(const jack_port_t* port, const char* port_name);
  294. JACKBRIDGE_API const char** jackbridge_port_get_connections(const jack_port_t* port);
  295. JACKBRIDGE_API const char** jackbridge_port_get_all_connections(const jack_client_t* client, const jack_port_t* port);
  296. JACKBRIDGE_API bool jackbridge_port_rename(jack_client_t* client, jack_port_t* port, const char* port_name);
  297. JACKBRIDGE_API bool jackbridge_port_set_alias(jack_port_t* port, const char* alias);
  298. JACKBRIDGE_API bool jackbridge_port_unset_alias(jack_port_t* port, const char* alias);
  299. JACKBRIDGE_API int jackbridge_port_get_aliases(const jack_port_t* port, char* const al[2]);
  300. JACKBRIDGE_API bool jackbridge_port_request_monitor(jack_port_t* port, bool onoff);
  301. JACKBRIDGE_API bool jackbridge_port_request_monitor_by_name(jack_client_t* client, const char* port_name, bool onoff);
  302. JACKBRIDGE_API bool jackbridge_port_ensure_monitor(jack_port_t* port, bool onoff);
  303. JACKBRIDGE_API bool jackbridge_port_monitoring_input(jack_port_t* port);
  304. JACKBRIDGE_API bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port);
  305. JACKBRIDGE_API bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port);
  306. JACKBRIDGE_API bool jackbridge_port_disconnect(jack_client_t* client, jack_port_t* port);
  307. JACKBRIDGE_API int jackbridge_port_name_size();
  308. JACKBRIDGE_API int jackbridge_port_type_size();
  309. JACKBRIDGE_API uint32_t jackbridge_port_type_get_buffer_size(jack_client_t* client, const char* port_type);
  310. JACKBRIDGE_API void jackbridge_port_get_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range);
  311. JACKBRIDGE_API void jackbridge_port_set_latency_range(jack_port_t* port, uint32_t mode, jack_latency_range_t* range);
  312. JACKBRIDGE_API bool jackbridge_recompute_total_latencies(jack_client_t* client);
  313. JACKBRIDGE_API const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, uint64_t flags);
  314. JACKBRIDGE_API jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name);
  315. JACKBRIDGE_API jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id);
  316. JACKBRIDGE_API void jackbridge_free(void* ptr);
  317. JACKBRIDGE_API uint32_t jackbridge_midi_get_event_count(void* port_buffer);
  318. JACKBRIDGE_API bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index);
  319. JACKBRIDGE_API void jackbridge_midi_clear_buffer(void* port_buffer);
  320. JACKBRIDGE_API bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, uint32_t data_size);
  321. JACKBRIDGE_API jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, uint32_t data_size);
  322. JACKBRIDGE_API bool jackbridge_release_timebase(jack_client_t* client);
  323. JACKBRIDGE_API bool jackbridge_set_sync_callback(jack_client_t* client, JackSyncCallback sync_callback, void* arg);
  324. JACKBRIDGE_API bool jackbridge_set_sync_timeout(jack_client_t* client, jack_time_t timeout);
  325. JACKBRIDGE_API bool jackbridge_set_timebase_callback(jack_client_t* client, bool conditional, JackTimebaseCallback timebase_callback, void* arg);
  326. JACKBRIDGE_API bool jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame);
  327. JACKBRIDGE_API uint32_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos);
  328. JACKBRIDGE_API jack_nframes_t jackbridge_get_current_transport_frame(const jack_client_t* client);
  329. JACKBRIDGE_API bool jackbridge_transport_reposition(jack_client_t* client, const jack_position_t* pos);
  330. JACKBRIDGE_API void jackbridge_transport_start(jack_client_t* client);
  331. JACKBRIDGE_API void jackbridge_transport_stop(jack_client_t* client);
  332. JACKBRIDGE_API bool jackbridge_set_property(jack_client_t* client, jack_uuid_t subject, const char* key, const char* value, const char* type);
  333. JACKBRIDGE_API bool jackbridge_get_property(jack_uuid_t subject, const char* key, char** value, char** type);
  334. JACKBRIDGE_API void jackbridge_free_description(jack_description_t* desc, bool free_description_itself);
  335. JACKBRIDGE_API bool jackbridge_get_properties(jack_uuid_t subject, jack_description_t* desc);
  336. JACKBRIDGE_API bool jackbridge_get_all_properties(jack_description_t** descs);
  337. JACKBRIDGE_API bool jackbridge_remove_property(jack_client_t* client, jack_uuid_t subject, const char* key);
  338. JACKBRIDGE_API int jackbridge_remove_properties(jack_client_t* client, jack_uuid_t subject);
  339. JACKBRIDGE_API bool jackbridge_remove_all_properties(jack_client_t* client);
  340. JACKBRIDGE_API bool jackbridge_set_property_change_callback(jack_client_t* client, JackPropertyChangeCallback callback, void* arg);
  341. JACKBRIDGE_API bool jackbridge_sem_init(void* sem) noexcept;
  342. JACKBRIDGE_API void jackbridge_sem_destroy(void* sem) noexcept;
  343. JACKBRIDGE_API bool jackbridge_sem_connect(void* sem) noexcept;
  344. JACKBRIDGE_API void jackbridge_sem_post(void* sem, bool server) noexcept;
  345. JACKBRIDGE_API bool jackbridge_sem_timedwait(void* sem, uint msecs, bool server) noexcept;
  346. JACKBRIDGE_API bool jackbridge_shm_is_valid(const void* shm) noexcept;
  347. JACKBRIDGE_API void jackbridge_shm_init(void* shm) noexcept;
  348. JACKBRIDGE_API void jackbridge_shm_attach(void* shm, const char* name) noexcept;
  349. JACKBRIDGE_API void jackbridge_shm_close(void* shm) noexcept;
  350. JACKBRIDGE_API void* jackbridge_shm_map(void* shm, uint64_t size) noexcept;
  351. JACKBRIDGE_API void jackbridge_shm_unmap(void* shm, void* ptr) noexcept;
  352. JACKBRIDGE_API void jackbridge_parent_deathsig(bool kill) noexcept;
  353. #endif // JACKBRIDGE_HPP_INCLUDED