use std::any::Any;
use four_cc::FourCC;
use crate::{parameter::ParameterValueUpdate, Error, Parameter, SourceTime};
pub mod chorus;
pub mod compressor;
pub mod delay;
pub mod distortion;
pub mod eq5;
pub mod filter;
pub mod gain;
pub mod gate;
pub mod pan;
pub mod reverb;
pub trait EffectMessage: Any + Send + Sync {
fn effect_name(&self) -> &'static str;
fn payload(&self) -> &dyn Any;
}
pub type EffectMessagePayload = dyn EffectMessage;
pub type EffectTime = SourceTime;
pub trait Effect: Send + Sync + 'static {
fn into_box(self) -> Box<dyn Effect>
where
Self: Sized,
{
Box::new(self)
}
fn name(&self) -> &'static str;
fn weight(&self) -> usize;
fn parameters(&self) -> Vec<&dyn Parameter>;
fn initialize(
&mut self,
sample_rate: u32,
channel_count: usize,
max_frames: usize,
) -> Result<(), Error>;
fn process_started(&mut self) {}
fn process_stopped(&mut self) {}
fn process(&mut self, output: &mut [f32], time: &EffectTime);
fn process_tail(&self) -> Option<usize> {
None
}
fn process_parameter_update(
&mut self,
id: FourCC,
value: &ParameterValueUpdate,
) -> Result<(), Error>;
fn process_parameter_updates(
&mut self,
values: &[(FourCC, ParameterValueUpdate)],
) -> Result<(), Error> {
for (id, value) in values {
self.process_parameter_update(*id, value)?;
}
Ok(())
}
fn process_message(&mut self, _message: &EffectMessagePayload) -> Result<(), Error> {
Err(Error::ParameterError(format!(
"{}: Received unexpected message payload.",
self.name()
)))
}
}
impl Effect for Box<dyn Effect> {
fn into_box(self) -> Box<dyn Effect> {
self
}
fn name(&self) -> &'static str {
(**self).name()
}
fn weight(&self) -> usize {
(**self).weight()
}
fn parameters(&self) -> Vec<&dyn Parameter> {
(**self).parameters()
}
fn initialize(
&mut self,
sample_rate: u32,
channel_count: usize,
max_frames: usize,
) -> Result<(), Error> {
(**self).initialize(sample_rate, channel_count, max_frames)
}
fn process_started(&mut self) {
(**self).process_started()
}
fn process_stopped(&mut self) {
(**self).process_stopped()
}
fn process(&mut self, output: &mut [f32], time: &EffectTime) {
(**self).process(output, time)
}
fn process_tail(&self) -> Option<usize> {
(**self).process_tail()
}
fn process_parameter_update(
&mut self,
id: FourCC,
value: &ParameterValueUpdate,
) -> Result<(), Error> {
(**self).process_parameter_update(id, value)
}
fn process_message(&mut self, message: &EffectMessagePayload) -> Result<(), Error> {
(**self).process_message(message)
}
}