Persist the editor states for all plugins
This commit is contained in:
parent
b6720383a3
commit
0469bdf806
|
@ -41,7 +41,6 @@ const MAX_FILTER_FREQUENCY: f32 = 22_000.0;
|
|||
/// since this effect just turns into literal noise at high frequencies.
|
||||
struct Crisp {
|
||||
params: Arc<CrispParams>,
|
||||
editor_state: Arc<ViziaState>,
|
||||
|
||||
/// Needed for computing the filter coefficients.
|
||||
sample_rate: f32,
|
||||
|
@ -60,6 +59,11 @@ struct Crisp {
|
|||
|
||||
#[derive(Params)]
|
||||
struct CrispParams {
|
||||
/// The editor state, saved together with the parameter state so the custom scaling can be
|
||||
/// restored.
|
||||
#[persist = "editor-state"]
|
||||
editor_state: Arc<ViziaState>,
|
||||
|
||||
/// On a range of `[0, 1]`, how much of the modulated sound to mix in.
|
||||
#[id = "amount"]
|
||||
amount: FloatParam,
|
||||
|
@ -128,7 +132,6 @@ impl Default for Crisp {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
params: Arc::new(CrispParams::default()),
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
sample_rate: 1.0,
|
||||
|
||||
|
@ -147,6 +150,8 @@ impl Default for CrispParams {
|
|||
let from_f32_hz_then_khz = formatters::s2v_f32_hz_then_khz();
|
||||
|
||||
Self {
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
amount: FloatParam::new("Amount", 0.35, FloatRange::Linear { min: 0.0, max: 1.0 })
|
||||
.with_smoother(SmoothingStyle::Linear(10.0))
|
||||
.with_unit("%")
|
||||
|
@ -307,7 +312,7 @@ impl Plugin for Crisp {
|
|||
}
|
||||
|
||||
fn editor(&self) -> Option<Box<dyn Editor>> {
|
||||
editor::create(self.params.clone(), self.editor_state.clone())
|
||||
editor::create(self.params.clone(), self.params.editor_state.clone())
|
||||
}
|
||||
|
||||
fn accepts_bus_config(&self, config: &BusConfig) -> bool {
|
||||
|
|
|
@ -46,7 +46,6 @@ const MAX_AUTOMATION_STEP_SIZE: u32 = 512;
|
|||
// - A proper GUI
|
||||
struct Diopser {
|
||||
params: Arc<DiopserParams>,
|
||||
editor_state: Arc<ViziaState>,
|
||||
|
||||
/// Needed for computing the filter coefficients.
|
||||
sample_rate: f32,
|
||||
|
@ -77,6 +76,11 @@ struct Diopser {
|
|||
// resonance and filter stages parameter ranges in the GUI until the user unlocks.
|
||||
#[derive(Params)]
|
||||
struct DiopserParams {
|
||||
/// The editor state, saved together with the parameter state so the custom scaling can be
|
||||
/// restored.
|
||||
#[persist = "editor-state"]
|
||||
editor_state: Arc<ViziaState>,
|
||||
|
||||
/// The number of all-pass filters applied in series.
|
||||
#[id = "stages"]
|
||||
filter_stages: IntParam,
|
||||
|
@ -121,7 +125,6 @@ impl Default for Diopser {
|
|||
|
||||
Self {
|
||||
params: Arc::new(DiopserParams::new(should_update_filters.clone())),
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
sample_rate: 1.0,
|
||||
|
||||
|
@ -139,6 +142,8 @@ impl Default for Diopser {
|
|||
impl DiopserParams {
|
||||
fn new(should_update_filters: Arc<AtomicBool>) -> Self {
|
||||
Self {
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
filter_stages: IntParam::new(
|
||||
"Filter Stages",
|
||||
0,
|
||||
|
@ -252,7 +257,7 @@ impl Plugin for Diopser {
|
|||
}
|
||||
|
||||
fn editor(&self) -> Option<Box<dyn Editor>> {
|
||||
editor::create(self.params.clone(), self.editor_state.clone())
|
||||
editor::create(self.params.clone(), self.params.editor_state.clone())
|
||||
}
|
||||
|
||||
fn accepts_bus_config(&self, config: &BusConfig) -> bool {
|
||||
|
@ -307,7 +312,7 @@ impl Plugin for Diopser {
|
|||
}
|
||||
|
||||
// Compute a spectrum for the GUI if needed
|
||||
if self.editor_state.is_open() {
|
||||
if self.params.editor_state.is_open() {
|
||||
self.spectrum_input.compute(buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ use std::sync::Arc;
|
|||
/// This is mostly identical to the gain example, minus some fluff, and with a GUI.
|
||||
struct Gain {
|
||||
params: Arc<GainParams>,
|
||||
editor_state: Arc<EguiState>,
|
||||
|
||||
/// Needed to normalize the peak meter's response based on the sample rate.
|
||||
peak_meter_decay_weight: f32,
|
||||
|
@ -20,6 +19,11 @@ struct Gain {
|
|||
|
||||
#[derive(Params)]
|
||||
struct GainParams {
|
||||
/// The editor state, saved together with the parameter state so the custom scaling can be
|
||||
/// restored.
|
||||
#[persist = "editor-state"]
|
||||
editor_state: Arc<EguiState>,
|
||||
|
||||
#[id = "gain"]
|
||||
pub gain: FloatParam,
|
||||
|
||||
|
@ -32,7 +36,6 @@ impl Default for Gain {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
params: Arc::new(GainParams::default()),
|
||||
editor_state: EguiState::from_size(300, 180),
|
||||
|
||||
peak_meter_decay_weight: 1.0,
|
||||
peak_meter: Arc::new(AtomicF32::new(util::MINUS_INFINITY_DB)),
|
||||
|
@ -43,6 +46,8 @@ impl Default for Gain {
|
|||
impl Default for GainParams {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
editor_state: EguiState::from_size(300, 180),
|
||||
|
||||
gain: FloatParam::new(
|
||||
"Gain",
|
||||
0.0,
|
||||
|
@ -80,7 +85,7 @@ impl Plugin for Gain {
|
|||
let params = self.params.clone();
|
||||
let peak_meter = self.peak_meter.clone();
|
||||
create_egui_editor(
|
||||
self.editor_state.clone(),
|
||||
self.params.editor_state.clone(),
|
||||
(),
|
||||
move |egui_ctx, setter, _state| {
|
||||
egui::CentralPanel::default().show(egui_ctx, |ui| {
|
||||
|
@ -170,7 +175,7 @@ impl Plugin for Gain {
|
|||
|
||||
// To save resources, a plugin can (and probably should!) only perform expensive
|
||||
// calculations that are only displayed on the GUI while the GUI is open
|
||||
if self.editor_state.is_open() {
|
||||
if self.params.editor_state.is_open() {
|
||||
amplitude = (amplitude / num_samples as f32).abs();
|
||||
let current_peak_meter = self.peak_meter.load(std::sync::atomic::Ordering::Relaxed);
|
||||
let new_peak_meter = if amplitude > current_peak_meter {
|
||||
|
|
|
@ -8,7 +8,6 @@ mod editor;
|
|||
/// This is mostly identical to the gain example, minus some fluff, and with a GUI.
|
||||
struct Gain {
|
||||
params: Arc<GainParams>,
|
||||
editor_state: Arc<IcedState>,
|
||||
|
||||
/// Needed to normalize the peak meter's response based on the sample rate.
|
||||
peak_meter_decay_weight: f32,
|
||||
|
@ -22,6 +21,11 @@ struct Gain {
|
|||
|
||||
#[derive(Params)]
|
||||
struct GainParams {
|
||||
/// The editor state, saved together with the parameter state so the custom scaling can be
|
||||
/// restored.
|
||||
#[persist = "editor-state"]
|
||||
editor_state: Arc<IcedState>,
|
||||
|
||||
#[id = "gain"]
|
||||
pub gain: FloatParam,
|
||||
}
|
||||
|
@ -30,7 +34,6 @@ impl Default for Gain {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
params: Arc::new(GainParams::default()),
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
peak_meter_decay_weight: 1.0,
|
||||
peak_meter: Arc::new(AtomicF32::new(util::MINUS_INFINITY_DB)),
|
||||
|
@ -41,6 +44,8 @@ impl Default for Gain {
|
|||
impl Default for GainParams {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
gain: FloatParam::new(
|
||||
"Gain",
|
||||
0.0,
|
||||
|
@ -77,7 +82,7 @@ impl Plugin for Gain {
|
|||
editor::create(
|
||||
self.params.clone(),
|
||||
self.peak_meter.clone(),
|
||||
self.editor_state.clone(),
|
||||
self.params.editor_state.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -116,7 +121,7 @@ impl Plugin for Gain {
|
|||
|
||||
// To save resources, a plugin can (and probably should!) only perform expensive
|
||||
// calculations that are only displayed on the GUI while the GUI is open
|
||||
if self.editor_state.is_open() {
|
||||
if self.params.editor_state.is_open() {
|
||||
amplitude = (amplitude / num_samples as f32).abs();
|
||||
let current_peak_meter = self.peak_meter.load(std::sync::atomic::Ordering::Relaxed);
|
||||
let new_peak_meter = if amplitude > current_peak_meter {
|
||||
|
|
|
@ -8,7 +8,6 @@ mod editor;
|
|||
/// This is mostly identical to the gain example, minus some fluff, and with a GUI.
|
||||
pub struct Gain {
|
||||
params: Arc<GainParams>,
|
||||
editor_state: Arc<ViziaState>,
|
||||
|
||||
/// Needed to normalize the peak meter's response based on the sample rate.
|
||||
peak_meter_decay_weight: f32,
|
||||
|
@ -22,6 +21,11 @@ pub struct Gain {
|
|||
|
||||
#[derive(Params)]
|
||||
struct GainParams {
|
||||
/// The editor state, saved together with the parameter state so the custom scaling can be
|
||||
/// restored.
|
||||
#[persist = "editor-state"]
|
||||
editor_state: Arc<ViziaState>,
|
||||
|
||||
#[id = "gain"]
|
||||
pub gain: FloatParam,
|
||||
}
|
||||
|
@ -30,7 +34,6 @@ impl Default for Gain {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
params: Arc::new(GainParams::default()),
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
peak_meter_decay_weight: 1.0,
|
||||
peak_meter: Arc::new(AtomicF32::new(util::MINUS_INFINITY_DB)),
|
||||
|
@ -41,6 +44,8 @@ impl Default for Gain {
|
|||
impl Default for GainParams {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
gain: FloatParam::new(
|
||||
"Gain",
|
||||
0.0,
|
||||
|
@ -77,7 +82,7 @@ impl Plugin for Gain {
|
|||
editor::create(
|
||||
self.params.clone(),
|
||||
self.peak_meter.clone(),
|
||||
self.editor_state.clone(),
|
||||
self.params.editor_state.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -116,7 +121,7 @@ impl Plugin for Gain {
|
|||
|
||||
// To save resources, a plugin can (and probably should!) only perform expensive
|
||||
// calculations that are only displayed on the GUI while the GUI is open
|
||||
if self.editor_state.is_open() {
|
||||
if self.params.editor_state.is_open() {
|
||||
amplitude = (amplitude / num_samples as f32).abs();
|
||||
let current_peak_meter = self.peak_meter.load(std::sync::atomic::Ordering::Relaxed);
|
||||
let new_peak_meter = if amplitude > current_peak_meter {
|
||||
|
|
Loading…
Reference in a new issue