diff --git a/rustortion-plugin/src/editor.rs b/rustortion-plugin/src/editor.rs index 3656b38..236e9a8 100644 --- a/rustortion-plugin/src/editor.rs +++ b/rustortion-plugin/src/editor.rs @@ -141,6 +141,7 @@ impl iced_baseview::Application for PluginApp { // the freshly-opened editor has to agree with. let ir_bypassed = flags.params.ir_bypass.value(); let ir_gain = flags.params.ir_gain.value(); + let params = flags.params.clone(); let backend = PluginBackend::new(flags.params, flags.context, flags.shared_state.clone()); @@ -175,6 +176,16 @@ impl iced_baseview::Application for PluginApp { preset_handler.get_available_presets().first().cloned() }; + // Restoring: show the IR the engine is running. `set_available_irs` picked + // the first one, and no preset load is coming to correct it. + if stored_stages.is_some() { + let preset_ir = initial_preset_name + .as_ref() + .and_then(|name| preset_handler.get_preset_by_name(name)) + .and_then(|preset| preset.ir_name.clone()); + ir_cabinet.set_selected_ir(params.saved_ir_or(preset_ir)); + } + // If we have stored stages, pre-select the preset in the handler // (for display) without reloading its stages from disk. if stored_stages.is_some() @@ -192,11 +203,11 @@ impl iced_baseview::Application for PluginApp { active_tab: Tab::Amp, selected_stage_type: StageType::ALL.first().copied().unwrap_or(StageType::Preamp), ir_cabinet_control: ir_cabinet, - pitch_shift_control: PitchShiftControl::new(0), + pitch_shift_control: PitchShiftControl::new(params.pitch_shift.value()), preset_handler, peak_meter_display: PeakMeterDisplay::default(), hotkey_handler: HotkeyHandler::new(HotkeySettings::default()), - input_filter_config: rustortion_core::preset::InputFilterConfig::default(), + input_filter_config: params.input_filters(), oversampling_factor, is_recording: false, }; diff --git a/rustortion-plugin/src/lib.rs b/rustortion-plugin/src/lib.rs index 0370b67..066fcd0 100644 --- a/rustortion-plugin/src/lib.rs +++ b/rustortion-plugin/src/lib.rs @@ -837,11 +837,7 @@ impl Plugin for RustortionPlugin { // preset's on every reactivation and project reload. let ir_to_load = self .params - .ir_name - .lock() - .ok() - .and_then(|g| g.clone()) - .or_else(|| preset.as_ref().and_then(|p| p.ir_name.clone())); + .saved_ir_or(preset.as_ref().and_then(|p| p.ir_name.clone())); if let Some(ir_name) = &ir_to_load && let Some(loader) = diff --git a/rustortion-plugin/src/params.rs b/rustortion-plugin/src/params.rs index 5441602..518ff56 100644 --- a/rustortion-plugin/src/params.rs +++ b/rustortion-plugin/src/params.rs @@ -1,4 +1,5 @@ use nih_plug::prelude::*; +use rustortion_core::preset::InputFilterConfig; use rustortion_core::preset::stage_config::StageConfig; use std::sync::Arc; use std::sync::Mutex; @@ -57,6 +58,27 @@ pub struct RustortionParams { pub chain_state: Arc>>>, } +impl RustortionParams { + /// The input filter settings the host currently holds. + pub fn input_filters(&self) -> InputFilterConfig { + InputFilterConfig { + hp_enabled: self.hp_enabled.value(), + hp_cutoff: self.hp_cutoff.value(), + lp_enabled: self.lp_enabled.value(), + lp_cutoff: self.lp_cutoff.value(), + } + } + + /// The IR a restored plugin runs: the user's pick, else the preset's. + pub fn saved_ir_or(&self, preset_ir: Option) -> Option { + self.ir_name + .lock() + .ok() + .and_then(|g| g.clone()) + .or(preset_ir) + } +} + impl Default for RustortionParams { fn default() -> Self { Self { @@ -126,3 +148,30 @@ impl Default for RustortionParams { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn input_filters_map_each_param_to_its_field() { + // HP and LP defaults all differ, so a swapped field fails this. + let config = RustortionParams::default().input_filters(); + let expected = InputFilterConfig::default(); + assert_eq!(config.hp_enabled, expected.hp_enabled); + assert!((config.hp_cutoff - expected.hp_cutoff).abs() < f32::EPSILON); + assert_eq!(config.lp_enabled, expected.lp_enabled); + assert!((config.lp_cutoff - expected.lp_cutoff).abs() < f32::EPSILON); + } + + #[test] + fn saved_ir_takes_precedence_over_the_preset() { + let params = RustortionParams::default(); + let preset_ir = || Some("preset".to_owned()); + assert_eq!(params.saved_ir_or(preset_ir()), preset_ir()); + assert_eq!(params.saved_ir_or(None), None); + + *params.ir_name.lock().unwrap() = Some("picked".to_owned()); + assert_eq!(params.saved_ir_or(preset_ir()).as_deref(), Some("picked")); + } +}