use crate::{DSPNodeSigBit, DSPState, DSPNodeType, DSPNodeTypeLibrary};
use std::cell::RefCell;
use std::rc::Rc;
pub struct AccumNodeState {
pub value: f64,
}
impl AccumNodeState {
fn reset(&mut self, _state: &mut DSPState) {
*self = Self::default();
}
}
impl Default for AccumNodeState {
fn default() -> Self {
Self { value: 0.0 }
}
}
extern "C" fn process_accum_nod(v: f64, state: *mut AccumNodeState) -> f64 {
let mut state = unsafe { &mut *state };
state.value += v;
state.value
}
crate::stateful_dsp_node_type! {
AccumNodeType, AccumNodeState => process_accum_nod "accum" "vSr"
}
#[derive(Default)]
struct SinNodeType;
extern "C" fn jit_sin(v: f64) -> f64 {
v.sin()
}
impl DSPNodeType for SinNodeType {
fn name(&self) -> &str {
"sin"
}
fn function_ptr(&self) -> *const u8 {
jit_sin as *const u8
}
fn signature(&self, i: usize) -> Option<DSPNodeSigBit> {
match i {
0 => Some(DSPNodeSigBit::Value),
_ => None,
}
}
fn has_return_value(&self) -> bool {
true
}
}
pub fn get_standard_library() -> Rc<RefCell<DSPNodeTypeLibrary>> {
let lib = Rc::new(RefCell::new(DSPNodeTypeLibrary::new()));
lib.borrow_mut().add(Rc::new(SinNodeType::default()));
lib.borrow_mut().add(AccumNodeType::new_ref());
lib
}