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.

270 lines
6.7KB

  1. /*
  2. * travesty, pure C VST3-compatible interface
  3. * Copyright (C) 2021-2023 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. #pragma once
  17. #include "base.h"
  18. #include "events.h"
  19. #include "align_push.h"
  20. /**
  21. * speakers
  22. */
  23. typedef uint64_t v3_speaker_arrangement;
  24. enum {
  25. V3_SPEAKER_L = 1 << 0,
  26. V3_SPEAKER_R = 1 << 1,
  27. V3_SPEAKER_M = 1 << 19
  28. };
  29. /**
  30. * process setup
  31. */
  32. enum v3_process_mode {
  33. V3_REALTIME,
  34. V3_PREFETCH,
  35. V3_OFFLINE
  36. };
  37. static inline
  38. const char* v3_process_mode_str(int32_t d)
  39. {
  40. switch (d)
  41. {
  42. case V3_REALTIME:
  43. return "V3_REALTIME";
  44. case V3_PREFETCH:
  45. return "V3_PREFETCH";
  46. case V3_OFFLINE:
  47. return "V3_OFFLINE";
  48. default:
  49. return "[unknown]";
  50. }
  51. }
  52. enum {
  53. V3_SAMPLE_32,
  54. V3_SAMPLE_64
  55. };
  56. static inline
  57. const char* v3_sample_size_str(int32_t d)
  58. {
  59. switch (d)
  60. {
  61. case V3_SAMPLE_32:
  62. return "V3_SAMPLE_32";
  63. case V3_SAMPLE_64:
  64. return "V3_SAMPLE_64";
  65. default:
  66. return "[unknown]";
  67. }
  68. }
  69. struct v3_process_setup {
  70. int32_t process_mode;
  71. int32_t symbolic_sample_size;
  72. int32_t max_block_size;
  73. double sample_rate;
  74. };
  75. /**
  76. * param changes
  77. */
  78. struct v3_param_value_queue {
  79. #ifndef __cplusplus
  80. struct v3_funknown;
  81. #endif
  82. v3_param_id (V3_API* get_param_id)(void* self);
  83. int32_t (V3_API* get_point_count)(void* self);
  84. v3_result (V3_API* get_point)(void* self, int32_t idx, int32_t* sample_offset, double* value);
  85. v3_result (V3_API* add_point)(void* self, int32_t sample_offset, double value, int32_t* idx);
  86. };
  87. static constexpr const v3_tuid v3_param_value_queue_iid =
  88. V3_ID(0x01263A18, 0xED074F6F, 0x98C9D356, 0x4686F9BA);
  89. struct v3_param_changes {
  90. #ifndef __cplusplus
  91. struct v3_funknown;
  92. #endif
  93. int32_t (V3_API* get_param_count)(void* self);
  94. struct v3_param_value_queue** (V3_API* get_param_data)(void* self, int32_t idx);
  95. struct v3_param_value_queue** (V3_API* add_param_data)(void* self, const v3_param_id* id, int32_t* idx);
  96. };
  97. static constexpr const v3_tuid v3_param_changes_iid =
  98. V3_ID(0xA4779663, 0x0BB64A56, 0xB44384A8, 0x466FEB9D);
  99. /**
  100. * process context
  101. */
  102. struct v3_frame_rate {
  103. uint32_t fps;
  104. uint32_t flags;
  105. };
  106. struct v3_chord {
  107. uint8_t key_note;
  108. uint8_t root_note;
  109. int16_t chord_mask;
  110. };
  111. enum {
  112. V3_PROCESS_CTX_PLAYING = 1 << 1,
  113. V3_PROCESS_CTX_CYCLE_ACTIVE = 1 << 2,
  114. V3_PROCESS_CTX_RECORDING = 1 << 3,
  115. V3_PROCESS_CTX_SYSTEM_TIME_VALID = 1 << 8,
  116. V3_PROCESS_CTX_PROJECT_TIME_VALID = 1 << 9,
  117. V3_PROCESS_CTX_TEMPO_VALID = 1 << 10,
  118. V3_PROCESS_CTX_BAR_POSITION_VALID = 1 << 11,
  119. V3_PROCESS_CTX_CYCLE_VALID = 1 << 12,
  120. V3_PROCESS_CTX_TIME_SIG_VALID = 1 << 13,
  121. V3_PROCESS_CTX_SMPTE_VALID = 1 << 14,
  122. V3_PROCESS_CTX_NEXT_CLOCK_VALID = 1 << 15,
  123. V3_PROCESS_CTX_CONT_TIME_VALID = 1 << 17,
  124. V3_PROCESS_CTX_CHORD_VALID = 1 << 18
  125. };
  126. struct v3_process_context {
  127. uint32_t state;
  128. double sample_rate;
  129. int64_t project_time_in_samples; // with loop
  130. int64_t system_time_ns;
  131. int64_t continuous_time_in_samples; // without loop
  132. double project_time_quarters;
  133. double bar_position_quarters;
  134. double cycle_start_quarters;
  135. double cycle_end_quarters;
  136. double bpm;
  137. int32_t time_sig_numerator;
  138. int32_t time_sig_denom;
  139. struct v3_chord chord;
  140. int32_t smpte_offset_subframes;
  141. struct v3_frame_rate frame_rate;
  142. int32_t samples_to_next_clock;
  143. };
  144. /**
  145. * process context requirements
  146. */
  147. enum {
  148. V3_PROCESS_CTX_NEED_SYSTEM_TIME = 1 << 0,
  149. V3_PROCESS_CTX_NEED_CONTINUOUS_TIME = 1 << 1,
  150. V3_PROCESS_CTX_NEED_PROJECT_TIME = 1 << 2,
  151. V3_PROCESS_CTX_NEED_BAR_POSITION = 1 << 3,
  152. V3_PROCESS_CTX_NEED_CYCLE = 1 << 4,
  153. V3_PROCESS_CTX_NEED_NEXT_CLOCK = 1 << 5,
  154. V3_PROCESS_CTX_NEED_TEMPO = 1 << 6,
  155. V3_PROCESS_CTX_NEED_TIME_SIG = 1 << 7,
  156. V3_PROCESS_CTX_NEED_CHORD = 1 << 8,
  157. V3_PROCESS_CTX_NEED_FRAME_RATE = 1 << 9,
  158. V3_PROCESS_CTX_NEED_TRANSPORT_STATE = 1 << 10
  159. };
  160. struct v3_process_context_requirements {
  161. #ifndef __cplusplus
  162. struct v3_funknown;
  163. #endif
  164. uint32_t (V3_API* get_process_context_requirements)(void* self);
  165. };
  166. static constexpr const v3_tuid v3_process_context_requirements_iid =
  167. V3_ID(0x2A654303, 0xEF764E3D, 0x95B5FE83, 0x730EF6D0);
  168. /**
  169. * process data and context
  170. */
  171. struct v3_audio_bus_buffers {
  172. int32_t num_channels;
  173. uint64_t channel_silence_bitset;
  174. union {
  175. float** channel_buffers_32;
  176. double** channel_buffers_64;
  177. };
  178. };
  179. struct v3_process_data {
  180. int32_t process_mode;
  181. int32_t symbolic_sample_size;
  182. int32_t nframes;
  183. int32_t num_input_buses;
  184. int32_t num_output_buses;
  185. struct v3_audio_bus_buffers* inputs;
  186. struct v3_audio_bus_buffers* outputs;
  187. struct v3_param_changes** input_params;
  188. struct v3_param_changes** output_params;
  189. struct v3_event_list** input_events;
  190. struct v3_event_list** output_events;
  191. struct v3_process_context* ctx;
  192. };
  193. /**
  194. * audio processor
  195. */
  196. struct v3_audio_processor {
  197. #ifndef __cplusplus
  198. struct v3_funknown;
  199. #endif
  200. v3_result (V3_API* set_bus_arrangements)(void* self, v3_speaker_arrangement* inputs, int32_t num_inputs,
  201. v3_speaker_arrangement* outputs, int32_t num_outputs);
  202. v3_result (V3_API* get_bus_arrangement)(void* self, int32_t bus_direction, int32_t idx, v3_speaker_arrangement*);
  203. v3_result (V3_API* can_process_sample_size)(void* self, int32_t symbolic_sample_size);
  204. uint32_t (V3_API* get_latency_samples)(void* self);
  205. v3_result (V3_API* setup_processing)(void* self, struct v3_process_setup* setup);
  206. v3_result (V3_API* set_processing)(void* self, v3_bool state);
  207. v3_result (V3_API* process)(void* self, struct v3_process_data* data);
  208. uint32_t (V3_API* get_tail_samples)(void* self);
  209. };
  210. static constexpr const v3_tuid v3_audio_processor_iid =
  211. V3_ID(0x42043F99, 0xB7DA453C, 0xA569E79D, 0x9AAEC33D);
  212. #ifdef __cplusplus
  213. /**
  214. * C++ variants
  215. */
  216. struct v3_param_value_queue_cpp : v3_funknown {
  217. v3_param_value_queue queue;
  218. };
  219. struct v3_param_changes_cpp : v3_funknown {
  220. v3_param_changes changes;
  221. };
  222. struct v3_process_context_requirements_cpp : v3_funknown {
  223. v3_process_context_requirements req;
  224. };
  225. struct v3_audio_processor_cpp : v3_funknown {
  226. v3_audio_processor proc;
  227. };
  228. #endif
  229. #include "align_pop.h"