1
0
Fork 0

Update smoothers on init and state restore

Otherwise this would be filled with default values.
This commit is contained in:
Robbert van der Helm 2022-02-02 21:33:20 +01:00
parent e30a72888a
commit 1336139a65
2 changed files with 20 additions and 6 deletions

View file

@ -126,7 +126,7 @@ impl ParamPtr {
/// ///
/// Calling this function is only safe as long as the object this `ParamPtr` was created for is /// Calling this function is only safe as long as the object this `ParamPtr` was created for is
/// still alive. /// still alive.
pub unsafe fn update_smoother(&mut self, sample_rate: f32) { pub unsafe fn update_smoother(&self, sample_rate: f32) {
match &self { match &self {
ParamPtr::FloatParam(p) => (**p).update_smoother(sample_rate), ParamPtr::FloatParam(p) => (**p).update_smoother(sample_rate),
ParamPtr::IntParam(p) => (**p).update_smoother(sample_rate), ParamPtr::IntParam(p) => (**p).update_smoother(sample_rate),

View file

@ -43,7 +43,7 @@ use widestring::U16CStr;
use crate::buffer::Buffer; use crate::buffer::Buffer;
use crate::context::{EventLoop, MainThreadExecutor, OsEventLoop, ProcessContext}; use crate::context::{EventLoop, MainThreadExecutor, OsEventLoop, ProcessContext};
use crate::param::internals::ParamPtr; use crate::param::internals::ParamPtr;
use crate::param::range::{NormalizebleRange, Range}; use crate::param::range::Range;
use crate::param::Param; use crate::param::Param;
use crate::plugin::{BufferConfig, BusConfig, Plugin, ProcessStatus, Vst3Plugin}; use crate::plugin::{BufferConfig, BusConfig, Plugin, ProcessStatus, Vst3Plugin};
use crate::wrapper::state::{ParamValue, State}; use crate::wrapper::state::{ParamValue, State};
@ -275,10 +275,9 @@ impl<P: Plugin> WrapperInner<'_, P> {
} else if let Some(param_ptr) = self.param_by_hash.get(&hash) { } else if let Some(param_ptr) = self.param_by_hash.get(&hash) {
// Also update the parameter's smoothing if applicable // Also update the parameter's smoothing if applicable
match (param_ptr, sample_rate) { match (param_ptr, sample_rate) {
(ParamPtr::FloatParam(p), Some(sample_rate)) => { (_, Some(sample_rate)) => {
let plain_value = (**p).range.unnormalize(normalized_value as f32); param_ptr.set_normalized_value(normalized_value as f32);
(**p).set_plain_value(plain_value); param_ptr.update_smoother(sample_rate);
(**p).smoothed.set_target(sample_rate, plain_value);
} }
_ => param_ptr.set_normalized_value(normalized_value as f32), _ => param_ptr.set_normalized_value(normalized_value as f32),
} }
@ -489,6 +488,11 @@ impl<P: Plugin> IComponent for Wrapper<'_, P> {
} }
}; };
let sample_rate = self
.inner
.current_buffer_config
.load()
.map(|c| c.sample_rate);
for (param_id_str, param_value) in state.params { for (param_id_str, param_value) in state.params {
// Handle the bypass parameter separately // Handle the bypass parameter separately
if param_id_str == BYPASS_PARAM_ID { if param_id_str == BYPASS_PARAM_ID {
@ -529,6 +533,11 @@ impl<P: Plugin> IComponent for Wrapper<'_, P> {
); );
} }
} }
// Make sure everything starts out in sync
if let Some(sample_rate) = sample_rate {
param_ptr.update_smoother(sample_rate);
}
} }
// The plugin can also persist arbitrary fields alongside its parameters. This is useful for // The plugin can also persist arbitrary fields alongside its parameters. This is useful for
@ -923,6 +932,11 @@ impl<P: Plugin> IAudioProcessor for Wrapper<'_, P> {
max_buffer_size: setup.max_samples_per_block as u32, max_buffer_size: setup.max_samples_per_block as u32,
}; };
// Befure initializing the plugin, make sure all smoothers are set the the default values
for param in self.inner.param_by_hash.values() {
param.update_smoother(buffer_config.sample_rate);
}
if self if self
.inner .inner
.plugin .plugin