use std::sync::{Arc, atomic::Ordering};
use crate::{command::handle_param_setters, modulator::ModulatorId};
use super::{CommandWriters, LfoShared, Waveform};
#[derive(Debug)]
pub struct LfoHandle {
pub(super) id: ModulatorId,
pub(super) command_writers: CommandWriters,
pub(super) shared: Arc<LfoShared>,
}
impl LfoHandle {
#[must_use]
pub fn id(&self) -> ModulatorId {
self.id
}
pub fn set_waveform(&mut self, waveform: Waveform) {
self.command_writers.set_waveform.write(waveform)
}
handle_param_setters! {
frequency: f64,
amplitude: f64,
offset: f64,
}
pub fn set_phase(&mut self, phase: f64) {
self.command_writers.set_phase.write(phase)
}
}
impl Drop for LfoHandle {
fn drop(&mut self) {
self.shared.removed.store(true, Ordering::SeqCst);
}
}
impl From<&LfoHandle> for ModulatorId {
fn from(value: &LfoHandle) -> Self {
value.id
}
}