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

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