use crate::{
Mix, Value,
effect::{Effect, EffectBuilder},
};
use super::{Filter, FilterHandle, FilterMode, command_writers_and_readers};
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct FilterBuilder {
pub mode: FilterMode,
pub cutoff: Value<f64>,
pub resonance: Value<f64>,
pub mix: Value<Mix>,
}
impl FilterBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use = "This method consumes self and returns a modified FilterBuilder, so the return value should be used"]
pub fn mode(self, mode: FilterMode) -> Self {
Self { mode, ..self }
}
#[must_use = "This method consumes self and returns a modified FilterBuilder, so the return value should be used"]
pub fn cutoff(self, cutoff: impl Into<Value<f64>>) -> Self {
Self {
cutoff: cutoff.into(),
..self
}
}
#[must_use = "This method consumes self and returns a modified FilterBuilder, so the return value should be used"]
pub fn resonance(self, resonance: impl Into<Value<f64>>) -> Self {
Self {
resonance: resonance.into(),
..self
}
}
#[must_use = "This method consumes self and returns a modified FilterBuilder, so the return value should be used"]
pub fn mix(self, mix: impl Into<Value<Mix>>) -> Self {
Self {
mix: mix.into(),
..self
}
}
}
impl Default for FilterBuilder {
fn default() -> Self {
Self {
mode: FilterMode::LowPass,
cutoff: Value::Fixed(1000.0),
resonance: Value::Fixed(0.0),
mix: Value::Fixed(Mix::WET),
}
}
}
impl EffectBuilder for FilterBuilder {
type Handle = FilterHandle;
fn build(self) -> (Box<dyn Effect>, Self::Handle) {
let (command_writers, command_readers) = command_writers_and_readers();
(
Box::new(Filter::new(self, command_readers)),
FilterHandle { command_writers },
)
}
}