Skip to content

Commit 8d8d485

Browse files
baconpaulabique
authored andcommitted
Document the special lifetime of clap_event_midi_sysex::buffer
per conversation on discord, oct 29
1 parent a5aca00 commit 8d8d485

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

include/clap/events.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,27 @@ typedef struct clap_event_midi {
297297
uint8_t data[3];
298298
} clap_event_midi_t;
299299

300+
// clap_event_midi_sysex contains a pointer to a sysex contents buffer.
301+
// The lifetime of this buffer is (from host->plugin) only the process
302+
// call in which the event is delivered or (from plugin->host) only the
303+
// duration of a try_push call.
304+
//
305+
// Since `clap_output_events.try_push` requires hosts to make a copy of
306+
// an event, host implementers receiving sysex messages from plugins need
307+
// to take care to both copy the event (so header, size, etc...) but
308+
// also memcpy the contents of the sysex pointer to host-owned memory, and
309+
// not just copy the data pointer.
310+
//
311+
// Similarly plugins retaining the sysex outside the lifetime of a single
312+
// process call must copy the sysex buffer to plugin-owned memory.
313+
//
314+
// As a consequence, the data structure pointed to by the sysex buffer
315+
// must be contiguous and copyable with `memcpy` of `size` bytes.
300316
typedef struct clap_event_midi_sysex {
301317
clap_event_header_t header;
302318

303319
uint16_t port_index;
304-
const uint8_t *buffer; // midi buffer
320+
const uint8_t *buffer; // midi buffer. See lifetime comment above.
305321
uint32_t size;
306322
} clap_event_midi_sysex_t;
307323

0 commit comments

Comments
 (0)