use crate::{
Decibels, Mix, Parameter, Value,
effect::{Effect, EffectBuilder},
};
use super::{Distortion, DistortionKind, command_writers_and_readers, handle::DistortionHandle};
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct DistortionBuilder {
pub kind: DistortionKind,
pub drive: Value<Decibels>,
pub mix: Value<Mix>,
}
impl DistortionBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use = "This method consumes self and returns a modified DistortionBuilder, so the return value should be used"]
pub fn kind(self, kind: DistortionKind) -> Self {
Self { kind, ..self }
}
#[must_use = "This method consumes self and returns a modified DistortionBuilder, so the return value should be used"]
pub fn drive(self, drive: impl Into<Value<Decibels>>) -> Self {
Self {
drive: drive.into(),
..self
}
}
#[must_use = "This method consumes self and returns a modified DistortionBuilder, 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 DistortionBuilder {
fn default() -> Self {
Self {
kind: Default::default(),
drive: Value::Fixed(Decibels::IDENTITY),
mix: Value::Fixed(Mix::WET),
}
}
}
impl EffectBuilder for DistortionBuilder {
type Handle = DistortionHandle;
fn build(self) -> (Box<dyn Effect>, Self::Handle) {
let (command_writers, command_readers) = command_writers_and_readers();
(
Box::new(Distortion {
command_readers,
kind: self.kind,
drive: Parameter::new(self.drive, Decibels::IDENTITY),
mix: Parameter::new(self.mix, Mix::WET),
}),
DistortionHandle { command_writers },
)
}
}