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