Skip to main content

nice_plug_core/context/
init.rs

1//! A context passed during plugin initialization.
2
3use super::PluginApi;
4use crate::plugin::Plugin;
5
6/// Callbacks the plugin can make while it is being initialized. This is passed to the plugin during
7/// [`Plugin::initialize()`][crate::plugin::Plugin::initialize()].
8//
9// # Safety
10//
11// The implementing wrapper needs to be able to handle concurrent requests, and it should perform
12// the actual callback within [MainThreadQueue::schedule_gui].
13pub trait InitContext<P: Plugin> {
14    /// Get the current plugin API.
15    fn plugin_api(&self) -> PluginApi;
16
17    /// Run a task directly on this thread. This ensures that the task has finished executing before
18    /// the plugin finishes initializing.
19    ///
20    /// # Note
21    ///
22    /// There is no asynchronous alternative for this function as that may result in incorrect
23    /// behavior when doing offline rendering.
24    fn execute(&self, task: P::BackgroundTask);
25
26    /// Update the current latency of the plugin. If the plugin is currently processing audio, then
27    /// this may cause audio playback to be restarted.
28    fn set_latency_samples(&self, samples: u32);
29
30    /// Set the current voice **capacity** for this plugin (so not the number of currently active
31    /// voices). This may only be called if `ClapPlugin::CLAP_POLY_MODULATION_CONFIG` is set.
32    /// `capacity` must be between 1 and the configured maximum capacity. Changing this at runtime
33    /// allows the host to better optimize polyphonic modulation, or to switch to strictly monophonic
34    /// modulation when dropping the capacity down to 1.
35    fn set_current_voice_capacity(&self, capacity: u32);
36}