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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #define PRE_PACKED_STRUCTURE
  29. #define POST_PACKED_STRUCTURE __attribute__((__packed__))
  30. #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
  31. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  32. #include <cstddef>
  33. #ifdef CARLA_PROPER_CPP11_SUPPORT
  34. # include <cstdint>
  35. #else
  36. # include <stdint.h>
  37. #endif
  38. enum JackOptions {
  39. JackNullOption = 0x00,
  40. JackNoStartServer = 0x01,
  41. JackUseExactName = 0x02,
  42. JackServerName = 0x04,
  43. JackLoadName = 0x08,
  44. JackLoadInit = 0x10,
  45. JackSessionID = 0x20
  46. };
  47. enum JackStatus {
  48. JackFailure = 0x01,
  49. JackInvalidOption = 0x02,
  50. JackNameNotUnique = 0x04,
  51. JackServerStarted = 0x08,
  52. JackServerFailed = 0x10,
  53. JackServerError = 0x20,
  54. JackNoSuchClient = 0x40,
  55. JackLoadFailure = 0x80,
  56. JackInitFailure = 0x100,
  57. JackShmFailure = 0x200,
  58. JackVersionError = 0x400,
  59. JackBackendError = 0x800,
  60. JackClientZombie = 0x1000
  61. };
  62. enum JackLatencyCallbackMode {
  63. JackCaptureLatency,
  64. JackPlaybackLatency
  65. };
  66. enum JackPortFlags {
  67. JackPortIsInput = 0x1,
  68. JackPortIsOutput = 0x2,
  69. JackPortIsPhysical = 0x4,
  70. JackPortCanMonitor = 0x8,
  71. JackPortIsTerminal = 0x10,
  72. };
  73. enum JackTransportFlags {
  74. JackTransportStopped = 0,
  75. JackTransportRolling = 1,
  76. JackTransportLooping = 2,
  77. JackTransportStarting = 3,
  78. JackTransportNetStarting = 4
  79. };
  80. enum JackPositionBits {
  81. JackPositionBBT = 0x010,
  82. JackPositionTimecode = 0x020,
  83. JackBBTFrameOffset = 0x040,
  84. JackAudioVideoRatio = 0x080,
  85. JackVideoFrameOffset = 0x100
  86. };
  87. enum JackTransportBits {
  88. JackTransportState = 0x01,
  89. JackTransportPosition = 0x02,
  90. JackTransportLoop = 0x04,
  91. JackTransportSMPTE = 0x08,
  92. JackTransportBBT = 0x10
  93. };
  94. typedef uint32_t jack_nframes_t;
  95. typedef uint32_t jack_port_id_t;
  96. typedef uint64_t jack_time_t;
  97. typedef uint64_t jack_unique_t;
  98. typedef unsigned char jack_midi_data_t;
  99. typedef float jack_default_audio_sample_t;
  100. typedef enum JackOptions jack_options_t;
  101. typedef enum JackStatus jack_status_t;
  102. typedef enum JackLatencyCallbackMode jack_latency_callback_mode_t;
  103. typedef enum JackTransportFlags jack_transport_state_t;
  104. typedef enum JackPositionBits jack_position_bits_t;
  105. typedef enum JackTransportBits jack_transport_bits_t;
  106. struct _jack_midi_event {
  107. jack_nframes_t time;
  108. size_t size;
  109. jack_midi_data_t* buffer;
  110. };
  111. PRE_PACKED_STRUCTURE
  112. struct _jack_latency_range {
  113. jack_nframes_t min;
  114. jack_nframes_t max;
  115. } POST_PACKED_STRUCTURE;
  116. PRE_PACKED_STRUCTURE
  117. struct _jack_position {
  118. jack_unique_t unique_1;
  119. jack_time_t usecs;
  120. jack_nframes_t frame_rate;
  121. jack_nframes_t frame;
  122. jack_position_bits_t valid;
  123. int32_t bar;
  124. int32_t beat;
  125. int32_t tick;
  126. double bar_start_tick;
  127. float beats_per_bar;
  128. float beat_type;
  129. double ticks_per_beat;
  130. double beats_per_minute;
  131. double frame_time;
  132. double next_time;
  133. jack_nframes_t bbt_offset;
  134. float audio_frames_per_video_frame;
  135. jack_nframes_t video_offset;
  136. int32_t padding[7];
  137. jack_unique_t unique_2;
  138. } POST_PACKED_STRUCTURE;
  139. typedef struct _jack_port jack_port_t;
  140. typedef struct _jack_client jack_client_t;
  141. typedef struct _jack_latency_range jack_latency_range_t;
  142. typedef struct _jack_position jack_position_t;
  143. typedef struct _jack_midi_event jack_midi_event_t;
  144. typedef void (*JackLatencyCallback)(jack_latency_callback_mode_t mode, void *arg);
  145. typedef int (*JackProcessCallback)(jack_nframes_t nframes, void *arg);
  146. typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void *arg);
  147. typedef int (*JackSampleRateCallback)(jack_nframes_t nframes, void *arg);
  148. typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int register_, void *arg);
  149. typedef void (*JackClientRegistrationCallback)(const char* name, int register_, void *arg);
  150. typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
  151. typedef int (*JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void *arg);
  152. typedef void (*JackFreewheelCallback)(int starting, void *arg);
  153. typedef int (*JackXRunCallback)(void* arg);
  154. typedef void (*JackShutdownCallback)(void *arg);
  155. #endif // ! JACKBRIDGE_DIRECT
  156. CARLA_EXPORT const char* jackbridge_get_version_string();
  157. CARLA_EXPORT jack_client_t* jackbridge_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...);
  158. CARLA_EXPORT const char* jackbridge_client_rename(jack_client_t* client, const char* new_name);
  159. CARLA_EXPORT bool jackbridge_client_close(jack_client_t* client);
  160. CARLA_EXPORT int jackbridge_client_name_size();
  161. CARLA_EXPORT char* jackbridge_get_client_name(jack_client_t* client);
  162. CARLA_EXPORT bool jackbridge_activate(jack_client_t* client);
  163. CARLA_EXPORT bool jackbridge_deactivate(jack_client_t* client);
  164. CARLA_EXPORT void jackbridge_on_shutdown(jack_client_t* client, JackShutdownCallback shutdown_callback, void* arg);
  165. CARLA_EXPORT bool jackbridge_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg);
  166. CARLA_EXPORT bool jackbridge_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg);
  167. CARLA_EXPORT bool jackbridge_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg);
  168. CARLA_EXPORT bool jackbridge_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg);
  169. CARLA_EXPORT bool jackbridge_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg);
  170. CARLA_EXPORT bool jackbridge_set_port_registration_callback (jack_client_t* client, JackPortRegistrationCallback registration_callback, void *arg);
  171. CARLA_EXPORT bool jackbridge_set_port_connect_callback (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg);
  172. CARLA_EXPORT bool jackbridge_set_port_rename_callback (jack_client_t* client, JackPortRenameCallback rename_callback, void* arg);
  173. CARLA_EXPORT bool jackbridge_set_latency_callback(jack_client_t* client, JackLatencyCallback latency_callback, void* arg);
  174. CARLA_EXPORT bool jackbridge_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg);
  175. CARLA_EXPORT jack_nframes_t jackbridge_get_sample_rate(jack_client_t* client);
  176. CARLA_EXPORT jack_nframes_t jackbridge_get_buffer_size(jack_client_t* client);
  177. 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);
  178. CARLA_EXPORT bool jackbridge_port_unregister(jack_client_t* client, jack_port_t* port);
  179. CARLA_EXPORT void* jackbridge_port_get_buffer(jack_port_t* port, jack_nframes_t nframes);
  180. CARLA_EXPORT const char* jackbridge_port_name(const jack_port_t* port);
  181. CARLA_EXPORT const char* jackbridge_port_short_name(const jack_port_t* port);
  182. CARLA_EXPORT int jackbridge_port_flags(const jack_port_t* port);
  183. CARLA_EXPORT const char* jackbridge_port_type(const jack_port_t* port);
  184. CARLA_EXPORT const char** jackbridge_port_get_connections(const jack_port_t* port);
  185. CARLA_EXPORT bool jackbridge_port_set_name(jack_port_t* port, const char* port_name);
  186. CARLA_EXPORT bool jackbridge_connect(jack_client_t* client, const char* source_port, const char* destination_port);
  187. CARLA_EXPORT bool jackbridge_disconnect(jack_client_t* client, const char* source_port, const char* destination_port);
  188. CARLA_EXPORT int jackbridge_port_name_size();
  189. CARLA_EXPORT void jackbridge_port_get_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range);
  190. CARLA_EXPORT void jackbridge_port_set_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range);
  191. CARLA_EXPORT bool jackbridge_recompute_total_latencies(jack_client_t* client);
  192. CARLA_EXPORT const char** jackbridge_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
  193. CARLA_EXPORT jack_port_t* jackbridge_port_by_name(jack_client_t* client, const char* port_name);
  194. CARLA_EXPORT jack_port_t* jackbridge_port_by_id(jack_client_t* client, jack_port_id_t port_id);
  195. CARLA_EXPORT void jackbridge_free(void* ptr);
  196. CARLA_EXPORT uint32_t jackbridge_midi_get_event_count(void* port_buffer);
  197. CARLA_EXPORT bool jackbridge_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index);
  198. CARLA_EXPORT void jackbridge_midi_clear_buffer(void* port_buffer);
  199. CARLA_EXPORT bool jackbridge_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, size_t data_size);
  200. CARLA_EXPORT jack_midi_data_t* jackbridge_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size);
  201. CARLA_EXPORT int jackbridge_transport_locate(jack_client_t* client, jack_nframes_t frame);
  202. CARLA_EXPORT void jackbridge_transport_start(jack_client_t* client);
  203. CARLA_EXPORT void jackbridge_transport_stop(jack_client_t* client);
  204. CARLA_EXPORT jack_transport_state_t jackbridge_transport_query(const jack_client_t* client, jack_position_t* pos);
  205. CARLA_EXPORT bool jackbridge_sem_post(void* sem);
  206. CARLA_EXPORT bool jackbridge_sem_timedwait(void* sem, int secs);
  207. #endif // __JACKBRIDGE_HPP__