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: AtomicU32The 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>
impl<P: ClapPlugin> Wrapper<P>
Sourcepub unsafe fn new(host_callback: *const clap_host) -> Arc<Self>
pub unsafe fn new(host_callback: *const clap_host) -> Arc<Self>
§Safety
host_callback needs to outlive the returned object.
Sourcepub fn param_id_from_ptr(&self, param: ParamPtr) -> Option<&str>
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.
Sourcepub fn queue_parameter_event(&self, event: OutputParamEvent) -> bool
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).
Sourcepub fn request_resize(&self) -> bool
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.
Sourcepub fn update_plain_value_by_hash(
&self,
hash: u32,
update_type: ClapParamUpdate,
sample_rate: Option<f32>,
) -> bool
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.
Sourcepub unsafe fn handle_in_events(
&self,
in_: &clap_input_events,
current_sample_idx: usize,
total_buffer_len: usize,
)
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).
Sourcepub 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)>
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).
Sourcepub unsafe fn handle_out_events(
&self,
out: &clap_output_events,
current_sample_idx: usize,
total_buffer_len: usize,
)
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).
Sourcepub 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,
)
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).
Sourcepub fn get_state_object(&self) -> PluginState
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.
Sourcepub fn set_state_object_from_gui(&self, state: PluginState)
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.
pub fn set_latency_samples(&self, samples: u32)
pub fn set_current_voice_capacity(&self, capacity: u32)
Sourcepub fn set_state_inner(&self, state: &mut PluginState) -> bool
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.