use crate::math::Transcendental;
use crate::time::ClockTick;
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],
ctx: &ActionContext,
) -> 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()
}
}