pub trait Plugin: Send {
Show 19 methods
fn get_info(&self) -> Info;
fn new(host: HostCallback) -> Self
where
Self: Sized;
fn init(&mut self) { ... }
fn set_sample_rate(&mut self, rate: f32) { ... }
fn set_block_size(&mut self, size: i64) { ... }
fn resume(&mut self) { ... }
fn suspend(&mut self) { ... }
fn vendor_specific(
&mut self,
index: i32,
value: isize,
ptr: *mut c_void,
opt: f32
) -> isize { ... }
fn can_do(&self, can_do: CanDo) -> Supported { ... }
fn get_tail_size(&self) -> isize { ... }
fn process(&mut self, buffer: &mut AudioBuffer<'_, f32>) { ... }
fn process_f64(&mut self, buffer: &mut AudioBuffer<'_, f64>) { ... }
fn process_events(&mut self, events: &Events) { ... }
fn get_parameter_object(&mut self) -> Arc<dyn PluginParameters> { ... }
fn get_input_info(&self, input: i32) -> ChannelInfo { ... }
fn get_output_info(&self, output: i32) -> ChannelInfo { ... }
fn start_process(&mut self) { ... }
fn stop_process(&mut self) { ... }
fn get_editor(&mut self) -> Option<Box<dyn Editor>> { ... }
}Expand description
Must be implemented by all VST plugins.
All methods except new and get_info provide a default implementation
which does nothing and can be safely overridden.
At any time, a plugin is in one of two states: suspended or resumed.
While a plugin is in the suspended state, various processing parameters,
such as the sample rate and block size, can be changed by the host, but no
audio processing takes place. While a plugin is in the resumed state,
audio processing methods and parameter access methods can be called by
the host. A plugin starts in the suspended state and is switched between
the states by the host using the resume and suspend methods.
Hosts call methods of the plugin on two threads: the UI thread and the
processing thread. For this reason, the plugin API is separated into two
traits: The Plugin trait containing setup and processing methods, and
the PluginParameters trait containing methods for parameter access.
Required Methods§
sourcefn get_info(&self) -> Info
fn get_info(&self) -> Info
This method must return an Info struct.
sourcefn new(host: HostCallback) -> Selfwhere
Self: Sized,
fn new(host: HostCallback) -> Selfwhere
Self: Sized,
Called during initialization to pass a HostCallback to the plugin.
This method can be overridden to set host as a field in the plugin struct.
Example
// ...
use vst::plugin::HostCallback;
struct ExamplePlugin {
host: HostCallback
}
impl Plugin for ExamplePlugin {
fn new(host: HostCallback) -> ExamplePlugin {
ExamplePlugin {
host
}
}
fn init(&mut self) {
info!("loaded with host vst version: {}", self.host.vst_version());
}
// ...
}
Provided Methods§
sourcefn init(&mut self)
fn init(&mut self)
Called when plugin is fully initialized.
This method is only called while the plugin is in the suspended state.
sourcefn set_sample_rate(&mut self, rate: f32)
fn set_sample_rate(&mut self, rate: f32)
Called when sample rate is changed by host.
This method is only called while the plugin is in the suspended state.
sourcefn set_block_size(&mut self, size: i64)
fn set_block_size(&mut self, size: i64)
Called when block size is changed by host.
This method is only called while the plugin is in the suspended state.
sourcefn resume(&mut self)
fn resume(&mut self)
Called to transition the plugin into the resumed state.
sourcefn suspend(&mut self)
fn suspend(&mut self)
Called to transition the plugin into the suspended state.
sourcefn vendor_specific(
&mut self,
index: i32,
value: isize,
ptr: *mut c_void,
opt: f32
) -> isize
fn vendor_specific(
&mut self,
index: i32,
value: isize,
ptr: *mut c_void,
opt: f32
) -> isize
Vendor specific handling.
sourcefn can_do(&self, can_do: CanDo) -> Supported
fn can_do(&self, can_do: CanDo) -> Supported
Return whether plugin supports specified action.
This method is only called while the plugin is in the suspended state.
sourcefn get_tail_size(&self) -> isize
fn get_tail_size(&self) -> isize
Get the tail size of plugin when it is stopped. Used in offline processing as well.
sourcefn process(&mut self, buffer: &mut AudioBuffer<'_, f32>)
fn process(&mut self, buffer: &mut AudioBuffer<'_, f32>)
Process an audio buffer containing f32 values.
Example
// Processor that clips samples above 0.4 or below -0.4:
fn process(&mut self, buffer: &mut AudioBuffer<f32>){
// For each input and output
for (input, output) in buffer.zip() {
// For each input sample and output sample in buffer
for (in_sample, out_sample) in input.into_iter().zip(output.into_iter()) {
*out_sample = if *in_sample > 0.4 {
0.4
} else if *in_sample < -0.4 {
-0.4
} else {
*in_sample
};
}
}
}This method is only called while the plugin is in the resumed state.
sourcefn process_f64(&mut self, buffer: &mut AudioBuffer<'_, f64>)
fn process_f64(&mut self, buffer: &mut AudioBuffer<'_, f64>)
Process an audio buffer containing f64 values.
Example
// Processor that clips samples above 0.4 or below -0.4:
fn process_f64(&mut self, buffer: &mut AudioBuffer<f64>){
// For each input and output
for (input, output) in buffer.zip() {
// For each input sample and output sample in buffer
for (in_sample, out_sample) in input.into_iter().zip(output.into_iter()) {
*out_sample = if *in_sample > 0.4 {
0.4
} else if *in_sample < -0.4 {
-0.4
} else {
*in_sample
};
}
}
}This method is only called while the plugin is in the resumed state.
sourcefn process_events(&mut self, events: &Events)
fn process_events(&mut self, events: &Events)
Handle incoming events sent from the host.
This is always called before the start of process or process_f64.
This method is only called while the plugin is in the resumed state.
sourcefn get_parameter_object(&mut self) -> Arc<dyn PluginParameters>
fn get_parameter_object(&mut self) -> Arc<dyn PluginParameters>
Get a reference to the shared parameter object.
sourcefn get_input_info(&self, input: i32) -> ChannelInfo
fn get_input_info(&self, input: i32) -> ChannelInfo
Get information about an input channel. Only used by some hosts.
sourcefn get_output_info(&self, output: i32) -> ChannelInfo
fn get_output_info(&self, output: i32) -> ChannelInfo
Get information about an output channel. Only used by some hosts.
sourcefn start_process(&mut self)
fn start_process(&mut self)
Called one time before the start of process call.
This indicates that the process call will be interrupted (due to Host reconfiguration or bypass state when the plug-in doesn’t support softBypass).
This method is only called while the plugin is in the resumed state.
sourcefn stop_process(&mut self)
fn stop_process(&mut self)
Called after the stop of process call.
This method is only called while the plugin is in the resumed state.
sourcefn get_editor(&mut self) -> Option<Box<dyn Editor>>
fn get_editor(&mut self) -> Option<Box<dyn Editor>>
Return handle to plugin editor if supported.
The method need only return the object on the first call.
Subsequent calls can just return None.
The editor object will typically contain an Arc reference to the parameter
object through which it can communicate with the audio processing.