Skip to main content

UnknownEvent

Struct UnknownEvent 

Source
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

Source

pub const fn header(&self) -> &EventHeader

Returns the header of this event.

Source

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
    }
}
Source

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 */ }
    }
}
Source

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.

Source

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.

Source

pub unsafe fn as_event_unchecked<E>(&self) -> &E
where 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.

Source

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.

Source

pub const fn as_raw(&self) -> *const clap_event_header

Returns a raw, C-FFI compatible event header pointer to this event.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Returns the event as a raw byte buffer. This includes the event’s (header)EventHeader.

Source

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

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for MidiSysExEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for Midi2Event

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for NoteOnEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for NoteOffEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for NoteChokeEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for NoteEndEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for NoteExpressionEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for ParamValueEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for ParamModEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for ParamGestureBeginEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for ParamGestureEndEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for TransportEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UnknownEvent> for UnknownEvent

Source§

fn as_ref(&self) -> &UnknownEvent

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for UnknownEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl InputEventBuffer for &UnknownEvent

Source§

fn len(&self) -> u32

Returns the number of events in this list.
Source§

fn get(&self, index: u32) -> Option<&UnknownEvent>

Returns the event at the given index. Read more
Source§

impl<E> PartialEq<E> for UnknownEvent
where E: Event + PartialEq,

Source§

fn eq(&self, other: &E) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more