use crate::math::Transcendental;
use crate::time::ClockTick;
use crate::traits::ParamValue;
use crate::traits::ProcessResult;
pub struct ActionContext<'a> {
pub tick: &'a ClockTick,
}
impl<'a> ActionContext<'a> {
pub fn new(tick: &'a ClockTick) -> Self {
Self { tick }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AlgorithmCategory {
Generator,
Filter,
Effect,
Analyzer,
Utility,
}
impl AlgorithmCategory {
pub const fn name(&self) -> &'static str {
match self {
Self::Generator => "generator",
Self::Filter => "filter",
Self::Effect => "effect",
Self::Analyzer => "analyzer",
Self::Utility => "utility",
}
}
}
#[derive(Debug, Clone)]
pub struct AlgorithmMetadata {
pub name: &'static str,
pub category: AlgorithmCategory,
pub description: &'static str,
pub author: &'static str,
pub version: &'static str,
}
impl AlgorithmMetadata {
pub const fn empty() -> Self {
Self {
name: "",
category: AlgorithmCategory::Utility,
description: "",
author: "",
version: "",
}
}
}
pub trait Algorithm<T: Transcendental>: Send + Sync {
fn process(&mut self, input: Option<&[T]>, output: &mut [T]) -> ProcessResult<()>;
fn apply_command(&mut self, _value: T) {}
fn init(&mut self, _sample_rate: f32) {}
fn reset(&mut self);
fn metadata(&self) -> AlgorithmMetadata {
AlgorithmMetadata::empty()
}
}
pub trait ParameterizedAlgorithm<T: Transcendental>: Algorithm<T> {
type Params: Clone + Send + Sync;
fn params(&self) -> &Self::Params;
fn set_params(&mut self, params: Self::Params);
fn set_parameter(&mut self, _name: &str, _value: ParamValue) -> Result<(), &'static str> {
Err(format!("Parameter '{}' not supported", _name).leak())
}
}