pub struct UnknownEvent { /* private fields */ }Expand description
An event of an undetermined type.
CLAP event types come in a variety of different sizes. Therefore, unknown events do not have
their sizes known at compile-time, making this type a
DST which can only be
operated on through references (&).
Moreover, because CLAP supports defining using custom events, it’s possible for any host or plugin to encounter an event type it cannot possibly figure out the concrete type of.
The UnknownEvent type allows to safely work with events without knowing their type.
Their headers can be retrieved with the header() method, and they can
be directly copied around through InputEventBuffers and
OutputEventBuffers.
To try and figure out an event’s concrete type, the as_event()
method can be used to try and downcast it to a specific event type. The
as_core_event can also be used to check if the event is a
standard CLAP event, and then further matched to find its specific type.
Alternatively, one can also use the as_event_for_space and
as_event_space methods, which are respectively identical but
for custom event spaces, by checking against an ID from the event_registry extension.
Implementations§
Source§impl UnknownEvent
impl UnknownEvent
Sourcepub const fn header(&self) -> &EventHeader
pub const fn header(&self) -> &EventHeader
Returns the header of this event.
Sourcepub fn as_event<'s, E>(&self) -> Option<&E>where
E: Event<EventSpace<'s> = CoreEventSpace<'s>>,
pub fn as_event<'s, E>(&self) -> Option<&E>where
E: Event<EventSpace<'s> = CoreEventSpace<'s>>,
Attempts to downcast this event to a specific standard CLAP event type.
This returns a down-casted reference to the event if the event matches the given type, or
None if it doesn’t.
§Example
use clack_common::events::event_types::NoteOnEvent;
use clack_common::events::UnknownEvent;
fn handle_event(event: &UnknownEvent) {
if let Some(note_on_event) = event.as_event::<NoteOnEvent>() {
// Handle the Note On event
} else {
// This is not a Note On event
}
}
Sourcepub fn as_core_event(&self) -> Option<CoreEventSpace<'_>>
pub fn as_core_event(&self) -> Option<CoreEventSpace<'_>>
Attempts to downcast this event to the core event space, allowing it to be match against all the standard CLAP event types.
This returns None instead if the given event doesn’t match the known standard events.
§Example
use clack_common::events::event_types::NoteOnEvent;
use clack_common::events::UnknownEvent;
fn handle_event(event: &UnknownEvent) {
use clack_common::events::spaces::CoreEventSpace::*;
let Some(core_event) = event.as_core_event() else {
// This is not a known standard event.
return;
};
match core_event {
NoteOn(e) => { /* Handle the Note On event */ }
NoteOff(e) => { /* Handle the Note Off event */ }
ParamValue(e) => { /* Handle the Parameter Value event */ }
_ => { /* This is another event type than the ones we chose to handle */ }
}
}
Sourcepub fn as_event_for_space<E>(
&self,
space_id: EventSpaceId<<E as Event>::EventSpace<'_>>,
) -> Option<&E>where
E: Event,
pub fn as_event_for_space<E>(
&self,
space_id: EventSpaceId<<E as Event>::EventSpace<'_>>,
) -> Option<&E>where
E: Event,
Attempts to downcast this event to a specific event type from a given event space.
This returns a down-casted reference to the event if the event matches the given type and
space, or None if it doesn’t.
Sourcepub fn as_event_space<'s, S>(&'s self, space_id: EventSpaceId<S>) -> Option<S>where
S: EventSpace<'s>,
pub fn as_event_space<'s, S>(&'s self, space_id: EventSpaceId<S>) -> Option<S>where
S: EventSpace<'s>,
Attempts to downcast this event to the given event space, allowing it to be match against all the event types of that space.
This returns None instead if the given event doesn’t match the known events from that
event space.
Sourcepub unsafe fn as_event_unchecked<E>(&self) -> &Ewhere
E: Event,
pub unsafe fn as_event_unchecked<E>(&self) -> &Ewhere
E: Event,
Casts this event as an event of a given type, without performing any checks.
§Safety
The caller must ensure the event is of the given type, otherwise this will perform an incorrect cast, leading to Undefined Behavior.
Sourcepub const unsafe fn from_raw<'e>(
header: *const clap_event_header,
) -> &'e UnknownEvent
pub const unsafe fn from_raw<'e>( header: *const clap_event_header, ) -> &'e UnknownEvent
Gets an unknown event from a raw event header.
§Safety
The caller must ensure that not only the contents of the header are valid, but also that they are immediately preceding the rest of the event struct matching the event and space IDs in the header.
Sourcepub const fn as_raw(&self) -> *const clap_event_header
pub const fn as_raw(&self) -> *const clap_event_header
Returns a raw, C-FFI compatible event header pointer to this event.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the event as a raw byte buffer. This includes the event’s (header)EventHeader.
Sourcepub const unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &UnknownEvent
pub const unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &UnknownEvent
Retrieves an event from a byte buffer, without performing any checks.
The given buffer must include the event’s (header)EventHeader.
§Safety
The caller must ensure the byte buffer is properly aligned, and that is also contains a valid event header as well as the remaining of the event struct.
Trait Implementations§
Source§impl AsRef<UnknownEvent> for MidiEvent
impl AsRef<UnknownEvent> for MidiEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for MidiSysExEvent
impl AsRef<UnknownEvent> for MidiSysExEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for Midi2Event
impl AsRef<UnknownEvent> for Midi2Event
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for NoteOnEvent
impl AsRef<UnknownEvent> for NoteOnEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for NoteOffEvent
impl AsRef<UnknownEvent> for NoteOffEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for NoteChokeEvent
impl AsRef<UnknownEvent> for NoteChokeEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for NoteEndEvent
impl AsRef<UnknownEvent> for NoteEndEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for NoteExpressionEvent
impl AsRef<UnknownEvent> for NoteExpressionEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for ParamValueEvent
impl AsRef<UnknownEvent> for ParamValueEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for ParamModEvent
impl AsRef<UnknownEvent> for ParamModEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for ParamGestureBeginEvent
impl AsRef<UnknownEvent> for ParamGestureBeginEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for ParamGestureEndEvent
impl AsRef<UnknownEvent> for ParamGestureEndEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for TransportEvent
impl AsRef<UnknownEvent> for TransportEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl AsRef<UnknownEvent> for UnknownEvent
impl AsRef<UnknownEvent> for UnknownEvent
Source§fn as_ref(&self) -> &UnknownEvent
fn as_ref(&self) -> &UnknownEvent
Source§impl Debug for UnknownEvent
impl Debug for UnknownEvent
Source§impl<'a, 'b> Extend<&'b UnknownEvent> for OutputEvents<'a>where
'a: 'b,
impl<'a, 'b> Extend<&'b UnknownEvent> for OutputEvents<'a>where
'a: 'b,
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = &'b UnknownEvent>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = &'b UnknownEvent>,
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)