mod basic_gens;
pub mod dynamics;
pub mod noise;
pub use noise::*;
pub mod random;
pub use basic_gens::*;
mod smoothing;
pub use smoothing::*;
mod osc;
use crate::{graph::NodeId, node_buffer::NodeBufferRef, resources::Resources, Sample};
pub use osc::*;
pub mod delay;
pub mod filter;
#[allow(unused)]
use crate::graph::{Connection, Graph};
#[allow(unused)]
use knyst_macro::impl_gen;
pub trait Gen {
fn process(&mut self, ctx: GenContext, resources: &mut Resources) -> GenState;
fn num_inputs(&self) -> usize;
fn num_outputs(&self) -> usize;
#[allow(unused)]
fn init(&mut self, block_size: usize, sample_rate: Sample, node_id: NodeId) {}
#[allow(unused)]
fn input_desc(&self, input: usize) -> &'static str {
""
}
#[allow(unused)]
fn output_desc(&self, output: usize) -> &'static str {
""
}
fn name(&self) -> &'static str {
"no_name"
}
}
pub struct GenContext<'a, 'b> {
pub inputs: &'a NodeBufferRef,
pub outputs: &'b mut NodeBufferRef,
pub sample_rate: Sample,
}
impl<'a, 'b> GenContext<'a, 'b> {
pub fn block_size(&self) -> usize {
self.outputs.block_size()
}
}
#[derive(Debug, Clone, Copy)]
pub enum GenState {
Continue,
FreeSelf,
FreeSelfMendConnections,
FreeGraph(usize),
FreeGraphMendConnections(usize),
}
#[derive(Debug, Clone, Copy)]
pub enum StopAction {
Continue,
FreeSelf,
FreeSelfMendConnections,
FreeGraph,
FreeGraphMendConnections,
}
impl StopAction {
#[must_use]
pub fn to_gen_state(&self, stop_sample: usize) -> GenState {
match self {
StopAction::Continue => GenState::Continue,
StopAction::FreeSelf => GenState::FreeSelf,
StopAction::FreeSelfMendConnections => GenState::FreeSelfMendConnections,
StopAction::FreeGraph => GenState::FreeGraph(stop_sample),
StopAction::FreeGraphMendConnections => GenState::FreeGraphMendConnections(stop_sample),
}
}
}