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.

405 lines
17KB

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