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.

JackBridge.hpp 18KB

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