Reinitialize the plugin after restoring state
This lets you use the parameters to set fields on the plugin struct during `initialize()`.
This commit is contained in:
parent
c982ad9599
commit
13369e4085
2 changed files with 20 additions and 2 deletions
|
@ -87,7 +87,9 @@ pub trait Plugin: Default + Send + Sync {
|
|||
|
||||
/// Process audio. To not have to worry about aliasing, the host's input buffer have already
|
||||
/// been copied to the output buffers if they are not handling buffers in place (most hosts do
|
||||
/// however). All channels are also guarenteed to contain the same number of samples.
|
||||
/// however). All channels are also guarenteed to contain the same number of samples. Depending
|
||||
/// on how the host restores plugin state, this function may also be called twice in rapid
|
||||
/// succession.
|
||||
///
|
||||
/// TODO: Provide a way to access auxiliary input channels if the IO configuration is
|
||||
/// assymetric
|
||||
|
@ -117,7 +119,7 @@ pub struct BusConfig {
|
|||
}
|
||||
|
||||
/// Configuration for (the host's) audio buffers.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct BufferConfig {
|
||||
/// The current sample rate.
|
||||
pub sample_rate: f32,
|
||||
|
|
|
@ -107,6 +107,9 @@ struct WrapperInner<'a, P: Plugin> {
|
|||
is_processing: AtomicBool,
|
||||
/// The current bus configuration, modified through `IAudioProcessor::setBusArrangements()`.
|
||||
current_bus_config: AtomicCell<BusConfig>,
|
||||
/// The current buffer configuration, containing the sample rate and the maximum block size.
|
||||
/// Will be set in `IAudioProcessor::setupProcessing()`.
|
||||
current_buffer_config: AtomicCell<Option<BufferConfig>>,
|
||||
/// Whether the plugin is currently bypassed. This is not yet integrated with the `Plugin`
|
||||
/// trait.
|
||||
bypass_state: AtomicBool,
|
||||
|
@ -195,6 +198,7 @@ impl<P: Plugin> WrapperInner<'_, P> {
|
|||
num_input_channels: P::DEFAULT_NUM_INPUTS,
|
||||
num_output_channels: P::DEFAULT_NUM_OUTPUTS,
|
||||
}),
|
||||
current_buffer_config: AtomicCell::new(None),
|
||||
bypass_state: AtomicBool::new(false),
|
||||
last_process_status: AtomicCell::new(ProcessStatus::Normal),
|
||||
current_latency: AtomicU32::new(0),
|
||||
|
@ -520,6 +524,15 @@ impl<P: Plugin> IComponent for Wrapper<'_, P> {
|
|||
.params()
|
||||
.deserialize_fields(&state.fields);
|
||||
|
||||
// Reinitialize the plugin after loading state so it can respond to the new parmaeters
|
||||
let bus_config = self.inner.current_bus_config.load();
|
||||
if let Some(buffer_config) = self.inner.current_buffer_config.load() {
|
||||
self.inner
|
||||
.plugin
|
||||
.write()
|
||||
.initialize(&bus_config, &buffer_config, self.inner.as_ref());
|
||||
}
|
||||
|
||||
kResultOk
|
||||
}
|
||||
|
||||
|
@ -894,6 +907,9 @@ impl<P: Plugin> IAudioProcessor for Wrapper<'_, P> {
|
|||
.as_raw_vec()
|
||||
.resize_with(bus_config.num_output_channels as usize, || &mut []);
|
||||
|
||||
// Also store this for later, so we can reinitialize the plugin after restoring state
|
||||
self.inner.current_buffer_config.store(Some(buffer_config));
|
||||
|
||||
kResultOk
|
||||
} else {
|
||||
kResultFalse
|
||||
|
|
Loading…
Add table
Reference in a new issue