Skip to main content

Wrapper

Struct Wrapper 

Source
pub struct Wrapper<P: ClapPlugin> {
    pub task_executor: Mutex<TaskExecutor<P>>,
    pub current_process_mode: AtomicCell<ProcessMode>,
    pub current_latency: AtomicU32,
    pub clap_plugin: AtomicRefCell<clap_plugin>,
    pub param_ptr_to_hash: HashMap<ParamPtr, u32>,
    /* private fields */
}

Fields§

§task_executor: Mutex<TaskExecutor<P>>

The plugin’s background task executor closure.

§current_process_mode: AtomicCell<ProcessMode>

The current audio processing mode. Set through the render extension. Defaults to realtime.

§current_latency: AtomicU32

The current latency in samples, as set by the plugin through the ProcessContext. Uses the latency extension.

§clap_plugin: AtomicRefCell<clap_plugin>§param_ptr_to_hash: HashMap<ParamPtr, u32>

The inverse mapping from param_by_hash. This is needed to be able to have an ergonomic parameter setting API that uses references to the parameters instead of having to add a setter function to the parameter (or even worse, have it be completely untyped).

Implementations§

Source§

impl<P: ClapPlugin> Wrapper<P>

Source

pub unsafe fn new(host_callback: *const clap_host) -> Arc<Self>

§Safety

host_callback needs to outlive the returned object.

Source

pub fn param_id_from_ptr(&self, param: ParamPtr) -> Option<&str>

Get a parameter’s ID based on a ParamPtr. Used in the GuiContext implementation for the gesture checks.

Source

pub fn queue_parameter_event(&self, event: OutputParamEvent) -> bool

Queue a parameter output event to be sent to the host at the end of the audio processing cycle, and request a parameter flush from the host if the plugin is not currently processing audio. The parameter’s actual value will only be updated at that point so the value won’t change in the middle of a processing call.

Returns false if the parameter value queue was full and the update will not be sent to the host (it will still be set on the plugin either way).

Source

pub fn request_resize(&self) -> bool

Request a resize based on the editor’s current reported size. As of CLAP 0.24 this can safely be called from any thread. If this returns false, then the plugin should reset its size back to the previous value.

Source

pub fn update_plain_value_by_hash( &self, hash: u32, update_type: ClapParamUpdate, sample_rate: Option<f32>, ) -> bool

Convenience function for setting a value for a parameter as triggered by a CLAP parameter update. The same rate is for updating parameter smoothing.

§Note

These values are CLAP plain values, which include a step count multiplier for discrete parameter values.

Source

pub unsafe fn handle_in_events( &self, in_: &clap_input_events, current_sample_idx: usize, total_buffer_len: usize, )

Handle all incoming events from an event queue. This will clear self.input_events first.

§Safety

in_ must contain only pointers to valid data (Clippy insists on there being a safety section here).

Source

pub unsafe fn handle_in_events_until( &self, in_: &clap_input_events, transport_info: &mut *const clap_event_transport, current_sample_idx: usize, total_buffer_len: usize, resume_from_event_idx: usize, stop_predicate: impl Fn(*const clap_event_header) -> bool, ) -> Option<(usize, usize)>

Similar to handle_in_events(), but will stop just before an event if the predicate returns true for that events. This predicate is only called for events that occur after current_sample_idx. This is used to stop before a tempo or time signature change, or before next parameter change event with raw_event.time > current_sample_idx and return the absolute (relative to the entire buffer that’s being split) sample index of that event along with the its index in the event queue as a (sample_idx, event_idx) tuple. This allows for splitting the audio buffer into segments with distinct sample values to enable sample accurate automation without modifications to the wrapped plugin.

§Safety

in_ must contain only pointers to valid data (Clippy insists on there being a safety section here).

Source

pub unsafe fn handle_out_events( &self, out: &clap_output_events, current_sample_idx: usize, total_buffer_len: usize, )

Write the unflushed parameter changes to the host’s output event queue. The sample index is used as part of splitting up the input buffer for sample accurate automation changes. This will also modify the actual parameter values, since we should only do that while the wrapped plugin is not actually processing audio.

The total_buffer_len argument is used to clamp out of bounds events to the buffer’s length.

§Safety

out must be a valid object (Clippy insists on there being a safety section here).

Source

pub unsafe fn handle_in_event( &self, event: *const clap_event_header, input_events: &mut AtomicRefMut<'_, VecDeque<PluginNoteEvent<P>>>, transport_info: Option<&mut *const clap_event_transport>, current_sample_idx: usize, total_buffer_len: usize, )

Handle an incoming CLAP event. The sample index is provided to support block splitting for sample accurate automation. input_events must be cleared at the start of each process block.

To save on mutex operations when handing MIDI events, the lock guard for the input events need to be passed into this function.

If the event was a transport event and the transport_info argument is not None, then the pointer will be changed to point to the transport information from this event.

§Safety

in_ must contain only pointers to valid data (Clippy insists on there being a safety section here).

Source

pub fn get_state_object(&self) -> PluginState

Get the plugin’s state object, may be called by the plugin’s GUI as part of its own preset management. The wrapper doesn’t use these functions and serializes and deserializes directly the JSON in the relevant plugin API methods instead.

Source

pub fn set_state_object_from_gui(&self, state: PluginState)

Update the plugin’s internal state, called by the plugin itself from the GUI thread. To prevent corrupting data and changing parameters during processing the actual state is only updated at the end of the audio processing cycle.

Source

pub fn set_latency_samples(&self, samples: u32)

Source

pub fn set_current_voice_capacity(&self, capacity: u32)

Source

pub fn set_state_inner(&self, state: &mut PluginState) -> bool

Immediately set the plugin state. Returns false if the deserialization failed. The plugin state is set from a couple places, so this function aims to deduplicate that. Includes permit_alloc()s around the deserialization and initialization for the use case where set_state_object_from_gui() was called while the plugin is process audio.

Implicitly emits Task::ParameterValuesChanged.

§Notes

self.plugin must not be locked while calling this function or it will deadlock.

Auto Trait Implementations§

§

impl<P> !Freeze for Wrapper<P>

§

impl<P> !RefUnwindSafe for Wrapper<P>

§

impl<P> !UnwindSafe for Wrapper<P>

§

impl<P> Send for Wrapper<P>

§

impl<P> Sync for Wrapper<P>

§

impl<P> Unpin for Wrapper<P>
where P: Unpin, <P as Plugin>::SysExMessage: Unpin,

§

impl<P> UnsafeUnpin for Wrapper<P>
where P: UnsafeUnpin,

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

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.