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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * JackBridge
  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. #ifndef __JACKBRIDGE_HPP__
  17. #define __JACKBRIDGE_HPP__
  18. #include "CarlaDefines.hpp"
  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. #else
  28. #include <cstddef>
  29. #ifdef CARLA_PROPER_CPP11_SUPPORT
  30. # include <cstdint>
  31. #else
  32. # include <stdint.h>
  33. #endif
  34. #ifndef POST_PACKED_STRUCTURE
  35. # ifdef __GNUC__
  36. /* POST_PACKED_STRUCTURE needs to be a macro which
  37. expands into a compiler directive. The directive must
  38. tell the compiler to arrange the preceding structure
  39. declaration so that it is packed on byte-boundaries rather
  40. than use the natural alignment of the processor and/or
  41. compiler.
  42. */
  43. #define PRE_PACKED_STRUCTURE
  44. #define POST_PACKED_STRUCTURE __attribute__((__packed__))
  45. # else
  46. #ifdef _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 // _MSC_VER
  63. # endif // __GNUC__
  64. #endif
  65. #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
  66. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  67. #define JACK_HAS_CUSTOM_DATA_API 1
  68. #define JACK_HAS_PORT_IS_CONTROL_VOLTAGE_FLAG 1
  69. #define JackOpenOptions (JackSessionID|JackServerName|JackNoStartServer|JackUseExactName)
  70. #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
  71. #define JACK_POSITION_MASK (JackPositionBBT|JackPositionTimecode)
  72. #define EXTENDED_TIME_INFO
  73. enum JackOptions {
  74. JackNullOption = 0x00,
  75. JackNoStartServer = 0x01,
  76. JackUseExactName = 0x02,
  77. JackServerName = 0x04,
  78. JackLoadName = 0x08,
  79. JackLoadInit = 0x10,
  80. JackSessionID = 0x20
  81. };
  82. enum JackStatus {
  83. JackFailure = 0x01,
  84. JackInvalidOption = 0x02,
  85. JackNameNotUnique = 0x04,
  86. JackServerStarted = 0x08,
  87. JackServerFailed = 0x10,
  88. JackServerError = 0x20,
  89. JackNoSuchClient = 0x40,
  90. JackLoadFailure = 0x80,
  91. JackInitFailure = 0x100,
  92. JackShmFailure = 0x200,
  93. JackVersionError = 0x400,
  94. JackBackendError = 0x800,
  95. JackClientZombie = 0x1000
  96. };
  97. enum JackLatencyCallbackMode {
  98. JackCaptureLatency,
  99. JackPlaybackLatency
  100. };
  101. enum JackPortFlags {
  102. JackPortIsInput = 0x1,
  103. JackPortIsOutput = 0x2,
  104. JackPortIsPhysical = 0x4,
  105. JackPortCanMonitor = 0x8,
  106. JackPortIsTerminal = 0x10,
  107. JackPortIsControlVoltage = 0x100
  108. };
  109. enum JackTransportState {
  110. JackTransportStopped = 0,
  111. JackTransportRolling = 1,
  112. JackTransportLooping = 2,
  113. JackTransportStarting = 3,
  114. JackTransportNetStarting = 4
  115. };
  116. enum JackPositionBits {
  117. JackPositionBBT = 0x010,
  118. JackPositionTimecode = 0x020,
  119. JackBBTFrameOffset = 0x040,
  120. JackAudioVideoRatio = 0x080,
  121. JackVideoFrameOffset = 0x100
  122. };
  123. enum JackSessionEventType {
  124. JackSessionSave = 1,
  125. JackSessionSaveAndQuit = 2,
  126. JackSessionSaveTemplate = 3
  127. };
  128. enum JackSessionFlags {
  129. JackSessionSaveError = 0x01,
  130. JackSessionNeedTerminal = 0x02
  131. };
  132. enum JackCustomChange {
  133. JackCustomRemoved,
  134. JackCustomAdded,
  135. JackCustomReplaced
  136. };
  137. typedef uint32_t jack_nframes_t;
  138. typedef uint32_t jack_port_id_t;
  139. typedef uint64_t jack_time_t;
  140. typedef uint64_t jack_unique_t;
  141. typedef unsigned char jack_midi_data_t;
  142. typedef float jack_default_audio_sample_t;
  143. typedef enum JackOptions jack_options_t;
  144. typedef enum JackStatus jack_status_t;
  145. typedef enum JackLatencyCallbackMode jack_latency_callback_mode_t;
  146. typedef enum JackTransportState jack_transport_state_t;
  147. typedef enum JackPositionBits jack_position_bits_t;
  148. typedef enum JackSessionEventType jack_session_event_type_t;
  149. typedef enum JackSessionFlags jack_session_flags_t;
  150. typedef enum JackCustomChange jack_custom_change_t;
  151. struct _jack_midi_event {
  152. jack_nframes_t time;
  153. size_t size;
  154. jack_midi_data_t* buffer;
  155. };
  156. PRE_PACKED_STRUCTURE
  157. struct _jack_latency_range {
  158. jack_nframes_t min;
  159. jack_nframes_t max;
  160. } POST_PACKED_STRUCTURE;
  161. PRE_PACKED_STRUCTURE
  162. struct _jack_position {
  163. jack_unique_t unique_1;
  164. jack_time_t usecs;
  165. jack_nframes_t frame_rate;
  166. jack_nframes_t frame;
  167. jack_position_bits_t valid;
  168. int32_t bar;
  169. int32_t beat;
  170. int32_t tick;
  171. double bar_start_tick;
  172. float beats_per_bar;
  173. float beat_type;
  174. double ticks_per_beat;
  175. double beats_per_minute;
  176. double frame_time;
  177. double next_time;
  178. jack_nframes_t bbt_offset;
  179. float audio_frames_per_video_frame;
  180. jack_nframes_t video_offset;
  181. int32_t padding[7];
  182. jack_unique_t unique_2;
  183. } POST_PACKED_STRUCTURE;
  184. struct _jack_session_event {
  185. jack_session_event_type_t type;
  186. const char* session_dir;
  187. const char* client_uuid;
  188. char* command_line;
  189. jack_session_flags_t flags;
  190. uint32_t future;
  191. };
  192. struct _jack_session_command_t {
  193. const char* uuid;
  194. const char* client_name;
  195. const char* command;
  196. jack_session_flags_t flags;
  197. };
  198. typedef struct _jack_port jack_port_t;
  199. typedef struct _jack_client jack_client_t;
  200. typedef struct _jack_midi_event jack_midi_event_t;
  201. typedef struct _jack_latency_range jack_latency_range_t;
  202. typedef struct _jack_position jack_position_t;
  203. typedef struct _jack_session_event jack_session_event_t;
  204. typedef struct _jack_session_command_t jack_session_command_t;
  205. typedef void (*JackLatencyCallback)(jack_latency_callback_mode_t mode, void* arg);
  206. typedef int (*JackProcessCallback)(jack_nframes_t nframes, void* arg);
  207. typedef void (*JackThreadInitCallback)(void *arg);
  208. typedef int (*JackGraphOrderCallback)(void *arg);
  209. typedef int (*JackXRunCallback)(void* arg);
  210. typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void* arg);
  211. typedef int (*JackSampleRateCallback)(jack_nframes_t nframes, void* arg);
  212. typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int register_, void* arg);
  213. typedef void (*JackClientRegistrationCallback)(const char* name, int register_, void* arg);
  214. typedef int (*JackClientRenameCallback)(const char* old_name, const char* new_name, void* arg);
  215. typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
  216. typedef int (*JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void* arg);
  217. typedef void (*JackFreewheelCallback)(int starting, void* arg);
  218. typedef void (*JackShutdownCallback)(void* arg);
  219. typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, void* arg);
  220. typedef int (*JackSyncCallback)(jack_transport_state_t state, jack_position_t* pos, void* arg);
  221. typedef void (*JackTimebaseCallback)(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
  222. typedef void (*JackSessionCallback)(jack_session_event_t* event, void* arg);
  223. typedef void (*JackCustomDataAppearanceCallback)(const char* client_name, const char* key, jack_custom_change_t change, void* arg);
  224. #endif // ! JACKBRIDGE_DIRECT
  225. CARLA_EXPORT const char* jackbridge_get_version_string();
  226. CARLA_EXPORT jack_client_t* jackbridge_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...);
  227. CARLA_EXPORT const char* jackbridge_client_rename(jack_client_t* client, const char* new_name);
  228. CARLA_EXPORT bool jackbridge_client_close(jack_client_t* client);
  229. CARLA_EXPORT int jackbridge_client_name_size();
  230. CARLA_EXPORT char* jackbridge_get_client_name(jack_client_t* client);
  231. CARLA_EXPORT bool jackbridge_activate(jack_client_t* client);
  232. CARLA_EXPORT bool jackbridge_deactivate(jack_client_t* client);
  233. CARLA_EXPORT int jackbridge_get_client_pid(const char* name);
  234. CARLA_EXPORT int jackbridge_is_realtime(jack_client_t* client);
  235. CARLA_EXPORT bool jackbridge_set_thread_init_callback(jack_client_t* client, JackThreadInitCallback thread_init_callback, void* arg);
  236. CARLA_EXPORT void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg);
  237. CARLA_EXPORT void jackbridge_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg);
  238. CARLA_EXPORT bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg);
  239. CARLA_EXPORT bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg);
  240. CARLA_EXPORT bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg);
  241. CARLA_EXPORT bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg);
  242. CARLA_EXPORT bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg);
  243. CARLA_EXPORT bool jackbridge_set_client_rename_callback(jack_client_t* client, JackClientRenameCallback registration_callback, void* arg);
  244. CARLA_EXPORT bool jackbridge_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void* arg);
  245. CARLA_EXPORT bool jackbridge_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg);
  246. CARLA_EXPORT bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg);
  247. CARLA_EXPORT bool jackbridge_set_graph_order_callback(jack_client_t* client, JackGraphOrderCallback graph_callback, void* arg);
  248. CARLA_EXPORT bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg);
  249. CARLA_EXPORT bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg);
  250. CARLA_EXPORT bool jackbridge_set_freewheel(jack_client_t* client, int onoff);
  251. CARLA_EXPORT bool jackbridge_set_buffer_size(jack_client_t* client, jack_nframes_t nframes);
  252. CARLA_EXPORT bool jackbridge_engine_takeover_timebase(jack_client_t* client);
  253. CARLA_EXPORT float jackbridge_cpu_load(jack_client_t* client);
  254. CARLA_EXPORT jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client);
  255. CARLA_EXPORT jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client);
  256. 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);
  257. CARLA_EXPORT bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port);
  258. CARLA_EXPORT void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes);
  259. CARLA_EXPORT const char* jackbridge_port_name(const jack_port_t* port);
  260. CARLA_EXPORT const char* jackbridge_port_short_name(const jack_port_t* port);
  261. CARLA_EXPORT int jackbridge_port_flags(const jack_port_t* port);
  262. CARLA_EXPORT const char* jackbridge_port_type(const jack_port_t* port);
  263. CARLA_EXPORT const char** jackbridge_port_get_connections(const jack_port_t* port);
  264. CARLA_EXPORT bool jackbridge_port_set_name(jack_port_t* port, const char* port_name);
  265. CARLA_EXPORT bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port);
  266. CARLA_EXPORT bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port);
  267. CARLA_EXPORT int jackbridge_port_name_size();
  268. CARLA_EXPORT void jackbridge_port_get_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range);
  269. CARLA_EXPORT void jackbridge_port_set_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range);
  270. CARLA_EXPORT bool jackbridge_recompute_total_latencies(jack_client_t* client);
  271. CARLA_EXPORT const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
  272. CARLA_EXPORT jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name);
  273. CARLA_EXPORT jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id);
  274. CARLA_EXPORT void jackbridge_free(void* ptr);
  275. CARLA_EXPORT uint32_t jackbridge_midi_get_event_count(void* port_buffer);
  276. CARLA_EXPORT bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index);
  277. CARLA_EXPORT void jackbridge_midi_clear_buffer(void* port_buffer);
  278. CARLA_EXPORT bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, size_t data_size);
  279. CARLA_EXPORT jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size);
  280. CARLA_EXPORT int jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame);
  281. CARLA_EXPORT void jackbridge_transport_start(jack_client_t* client);
  282. CARLA_EXPORT void jackbridge_transport_stop(jack_client_t* client);
  283. CARLA_EXPORT jack_transport_state_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos);
  284. CARLA_EXPORT bool jackbridge_custom_publish_data(jack_client_t* client, const char* key, const void* data, size_t size);
  285. CARLA_EXPORT bool jackbridge_custom_get_data(jack_client_t* client, const char* client_name, const char* key, void** data, size_t* size);
  286. CARLA_EXPORT bool jackbridge_custom_unpublish_data(jack_client_t* client, const char* key);
  287. CARLA_EXPORT bool jackbridge_custom_set_data_appearance_callback(jack_client_t* client, JackCustomDataAppearanceCallback callback, void* arg);
  288. CARLA_EXPORT const char** jackbridge_custom_get_keys(jack_client_t* client, const char* client_name);
  289. CARLA_EXPORT bool jackbridge_sem_post(void* sem);
  290. CARLA_EXPORT bool jackbridge_sem_timedwait(void* sem, int secs);
  291. #endif // __JACKBRIDGE_HPP__