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.

411 lines
18KB

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