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.

events.h 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. #pragma once
  2. #include "private/std.h"
  3. #include "fixedpoint.h"
  4. #include "id.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. // event header
  9. // must be the first attribute of the event
  10. typedef struct clap_event_header {
  11. uint32_t size; // event size including this header, eg: sizeof (clap_event_note)
  12. uint32_t time; // sample offset within the buffer for this event
  13. uint16_t space_id; // event space, see clap_host_event_registry
  14. uint16_t type; // event type
  15. uint32_t flags; // see clap_event_flags
  16. } clap_event_header_t;
  17. // The clap core event space
  18. static const CLAP_CONSTEXPR uint16_t CLAP_CORE_EVENT_SPACE_ID = 0;
  19. enum clap_event_flags {
  20. // Indicate a live user event, for example a user turning a physical knob
  21. // or playing a physical key.
  22. CLAP_EVENT_IS_LIVE = 1 << 0,
  23. // Indicate that the event should not be recorded.
  24. // For example this is useful when a parameter changes because of a MIDI CC,
  25. // because if the host records both the MIDI CC automation and the parameter
  26. // automation there will be a conflict.
  27. CLAP_EVENT_DONT_RECORD = 1 << 1,
  28. };
  29. // Some of the following events overlap, a note on can be expressed with:
  30. // - CLAP_EVENT_NOTE_ON
  31. // - CLAP_EVENT_MIDI
  32. // - CLAP_EVENT_MIDI2
  33. //
  34. // The preferred way of sending a note event is to use CLAP_EVENT_NOTE_*.
  35. //
  36. // The same event must not be sent twice: it is forbidden to send a the same note on
  37. // encoded with both CLAP_EVENT_NOTE_ON and CLAP_EVENT_MIDI.
  38. //
  39. // The plugins are encouraged to be able to handle note events encoded as raw midi or midi2,
  40. // or implement clap_plugin_event_filter and reject raw midi and midi2 events.
  41. enum {
  42. // NOTE_ON and NOTE_OFF represent a key pressed and key released event, respectively.
  43. // A NOTE_ON with a velocity of 0 is valid and should not be interpreted as a NOTE_OFF.
  44. //
  45. // NOTE_CHOKE is meant to choke the voice(s), like in a drum machine when a closed hihat
  46. // chokes an open hihat. This event can be sent by the host to the plugin. Here are two use cases:
  47. // - a plugin is inside a drum pad in Bitwig Studio's drum machine, and this pad is choked by
  48. // another one
  49. // - the user double clicks the DAW's stop button in the transport which then stops the sound on
  50. // every tracks
  51. //
  52. // NOTE_END is sent by the plugin to the host. The port, channel, key and note_id are those given
  53. // by the host in the NOTE_ON event. In other words, this event is matched against the
  54. // plugin's note input port.
  55. // NOTE_END is useful to help the host to match the plugin's voice life time.
  56. //
  57. // When using polyphonic modulations, the host has to allocate and release voices for its
  58. // polyphonic modulator. Yet only the plugin effectively knows when the host should terminate
  59. // a voice. NOTE_END solves that issue in a non-intrusive and cooperative way.
  60. //
  61. // CLAP assumes that the host will allocate a unique voice on NOTE_ON event for a given port,
  62. // channel and key. This voice will run until the plugin will instruct the host to terminate
  63. // it by sending a NOTE_END event.
  64. //
  65. // Consider the following sequence:
  66. // - process()
  67. // Host->Plugin NoteOn(port:0, channel:0, key:16, time:t0)
  68. // Host->Plugin NoteOn(port:0, channel:0, key:64, time:t0)
  69. // Host->Plugin NoteOff(port:0, channel:0, key:16, t1)
  70. // Host->Plugin NoteOff(port:0, channel:0, key:64, t1)
  71. // # on t2, both notes did terminate
  72. // Host->Plugin NoteOn(port:0, channel:0, key:64, t3)
  73. // # Here the plugin finished processing all the frames and will tell the host
  74. // # to terminate the voice on key 16 but not 64, because a note has been started at t3
  75. // Plugin->Host NoteEnd(port:0, channel:0, key:16, time:ignored)
  76. //
  77. // These four events use clap_event_note.
  78. CLAP_EVENT_NOTE_ON,
  79. CLAP_EVENT_NOTE_OFF,
  80. CLAP_EVENT_NOTE_CHOKE,
  81. CLAP_EVENT_NOTE_END,
  82. // Represents a note expression.
  83. // Uses clap_event_note_expression.
  84. CLAP_EVENT_NOTE_EXPRESSION,
  85. // PARAM_VALUE sets the parameter's value; uses clap_event_param_value.
  86. // PARAM_MOD sets the parameter's modulation amount; uses clap_event_param_mod.
  87. //
  88. // The value heard is: param_value + param_mod.
  89. //
  90. // In case of a concurrent global value/modulation versus a polyphonic one,
  91. // the voice should only use the polyphonic one and the polyphonic modulation
  92. // amount will already include the monophonic signal.
  93. CLAP_EVENT_PARAM_VALUE,
  94. CLAP_EVENT_PARAM_MOD,
  95. // Indicates that the user started or finished adjusting a knob.
  96. // This is not mandatory to wrap parameter changes with gesture events, but this improves
  97. // the user experience a lot when recording automation or overriding automation playback.
  98. // Uses clap_event_param_gesture.
  99. CLAP_EVENT_PARAM_GESTURE_BEGIN,
  100. CLAP_EVENT_PARAM_GESTURE_END,
  101. CLAP_EVENT_TRANSPORT, // update the transport info; clap_event_transport
  102. CLAP_EVENT_MIDI, // raw midi event; clap_event_midi
  103. CLAP_EVENT_MIDI_SYSEX, // raw midi sysex event; clap_event_midi_sysex
  104. CLAP_EVENT_MIDI2, // raw midi 2 event; clap_event_midi2
  105. };
  106. // Note on, off, end and choke events.
  107. // In the case of note choke or end events:
  108. // - the velocity is ignored.
  109. // - key and channel are used to match active notes, a value of -1 matches all.
  110. typedef struct clap_event_note {
  111. clap_event_header_t header;
  112. int32_t note_id; // -1 if unspecified, otherwise >=0
  113. int16_t port_index;
  114. int16_t channel; // 0..15
  115. int16_t key; // 0..127
  116. double velocity; // 0..1
  117. } clap_event_note_t;
  118. enum {
  119. // with 0 < x <= 4, plain = 20 * log(x)
  120. CLAP_NOTE_EXPRESSION_VOLUME,
  121. // pan, 0 left, 0.5 center, 1 right
  122. CLAP_NOTE_EXPRESSION_PAN,
  123. // relative tuning in semitone, from -120 to +120
  124. CLAP_NOTE_EXPRESSION_TUNING,
  125. // 0..1
  126. CLAP_NOTE_EXPRESSION_VIBRATO,
  127. CLAP_NOTE_EXPRESSION_EXPRESSION,
  128. CLAP_NOTE_EXPRESSION_BRIGHTNESS,
  129. CLAP_NOTE_EXPRESSION_PRESSURE,
  130. };
  131. typedef int32_t clap_note_expression;
  132. typedef struct clap_event_note_expression {
  133. clap_event_header_t header;
  134. clap_note_expression expression_id;
  135. // target a specific note_id, port, key and channel, -1 for global
  136. int32_t note_id;
  137. int16_t port_index;
  138. int16_t channel;
  139. int16_t key;
  140. double value; // see expression for the range
  141. } clap_event_note_expression_t;
  142. typedef struct clap_event_param_value {
  143. clap_event_header_t header;
  144. // target parameter
  145. clap_id param_id; // @ref clap_param_info.id
  146. void *cookie; // @ref clap_param_info.cookie
  147. // target a specific note_id, port, key and channel, -1 for global
  148. int32_t note_id;
  149. int16_t port_index;
  150. int16_t channel;
  151. int16_t key;
  152. double value;
  153. } clap_event_param_value_t;
  154. typedef struct clap_event_param_mod {
  155. clap_event_header_t header;
  156. // target parameter
  157. clap_id param_id; // @ref clap_param_info.id
  158. void *cookie; // @ref clap_param_info.cookie
  159. // target a specific note_id, port, key and channel, -1 for global
  160. int32_t note_id;
  161. int16_t port_index;
  162. int16_t channel;
  163. int16_t key;
  164. double amount; // modulation amount
  165. } clap_event_param_mod_t;
  166. typedef struct clap_event_param_gesture {
  167. clap_event_header_t header;
  168. // target parameter
  169. clap_id param_id; // @ref clap_param_info.id
  170. } clap_event_param_gesture_t;
  171. enum clap_transport_flags {
  172. CLAP_TRANSPORT_HAS_TEMPO = 1 << 0,
  173. CLAP_TRANSPORT_HAS_BEATS_TIMELINE = 1 << 1,
  174. CLAP_TRANSPORT_HAS_SECONDS_TIMELINE = 1 << 2,
  175. CLAP_TRANSPORT_HAS_TIME_SIGNATURE = 1 << 3,
  176. CLAP_TRANSPORT_IS_PLAYING = 1 << 4,
  177. CLAP_TRANSPORT_IS_RECORDING = 1 << 5,
  178. CLAP_TRANSPORT_IS_LOOP_ACTIVE = 1 << 6,
  179. CLAP_TRANSPORT_IS_WITHIN_PRE_ROLL = 1 << 7,
  180. };
  181. typedef struct clap_event_transport {
  182. clap_event_header_t header;
  183. uint32_t flags; // see clap_transport_flags
  184. clap_beattime song_pos_beats; // position in beats
  185. clap_sectime song_pos_seconds; // position in seconds
  186. double tempo; // in bpm
  187. double tempo_inc; // tempo increment for each samples and until the next
  188. // time info event
  189. clap_beattime loop_start_beats;
  190. clap_beattime loop_end_beats;
  191. clap_sectime loop_start_seconds;
  192. clap_sectime loop_end_seconds;
  193. clap_beattime bar_start; // start pos of the current bar
  194. int32_t bar_number; // bar at song pos 0 has the number 0
  195. uint16_t tsig_num; // time signature numerator
  196. uint16_t tsig_denom; // time signature denominator
  197. } clap_event_transport_t;
  198. typedef struct clap_event_midi {
  199. clap_event_header_t header;
  200. uint16_t port_index;
  201. uint8_t data[3];
  202. } clap_event_midi_t;
  203. typedef struct clap_event_midi_sysex {
  204. clap_event_header_t header;
  205. uint16_t port_index;
  206. const uint8_t *buffer; // midi buffer
  207. uint32_t size;
  208. } clap_event_midi_sysex_t;
  209. // While it is possible to use a series of midi2 event to send a sysex,
  210. // prefer clap_event_midi_sysex if possible for efficiency.
  211. typedef struct clap_event_midi2 {
  212. clap_event_header_t header;
  213. uint16_t port_index;
  214. uint32_t data[4];
  215. } clap_event_midi2_t;
  216. // Input event list, events must be sorted by time.
  217. typedef struct clap_input_events {
  218. void *ctx; // reserved pointer for the list
  219. uint32_t (CLAP_ABI *size)(const struct clap_input_events *list);
  220. // Don't free the returned event, it belongs to the list
  221. const clap_event_header_t *(CLAP_ABI *get)(const struct clap_input_events *list, uint32_t index);
  222. } clap_input_events_t;
  223. // Output event list, events must be sorted by time.
  224. typedef struct clap_output_events {
  225. void *ctx; // reserved pointer for the list
  226. // Pushes a copy of the event
  227. // returns false if the event could not be pushed to the queue (out of memory?)
  228. bool (CLAP_ABI *try_push)(const struct clap_output_events *list, const clap_event_header_t *event);
  229. } clap_output_events_t;
  230. #ifdef __cplusplus
  231. }
  232. #endif