From a425733a51f3983ece77f33a7260eb454f6a59b3 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Wed, 16 Jun 2021 03:54:46 +0200 Subject: [PATCH] made node_test finally useful for... tests! --- src/dsp/mod.rs | 7 ++++--- src/dsp/node_test.rs | 31 +++++++++++++------------------ tests/node_test.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 tests/node_test.rs diff --git a/src/dsp/mod.rs b/src/dsp/mod.rs index 6391a91..b887302 100644 --- a/src/dsp/mod.rs +++ b/src/dsp/mod.rs @@ -439,7 +439,8 @@ macro_rules! node_list { [1 eoet], test => Test UIType::Generic UICategory::IOUtil (0 f n_id d_id r_id f_def stp_d 0.0, 1.0, 0.5) - {1 0 s setting(0) fa_test_s 0 10}, + {1 0 p param(0.0) fa_test_s 0 10} + [0 sig], } } } @@ -1052,14 +1053,14 @@ macro_rules! make_node_info_enum { pub fn norm(&self, in_idx: usize, x: f32) -> f32 { match in_idx { $($in_idx => crate::dsp::norm_v::$variant::$para(x),)+ - _ => 0.0, + _ => x, } } pub fn denorm(&self, in_idx: usize, x: f32) -> f32 { match in_idx { $($in_idx => crate::dsp::denorm_v::$variant::$para(x),)+ - _ => 0.0, + _ => x, } } diff --git a/src/dsp/node_test.rs b/src/dsp/node_test.rs index b1c65f7..cdc94ac 100644 --- a/src/dsp/node_test.rs +++ b/src/dsp/node_test.rs @@ -39,11 +39,8 @@ impl Test { } } pub const f : &'static str = "F Test"; - pub const s : &'static str = "S Test"; -// pub const gain : &'static str = -// "Amp gain\nGain input\nRange: (0..1)\n"; -// pub const sig : &'static str = -// "Amp sig\nAmplified signal output\nRange: (-1..1)\n"; + pub const p : &'static str = "Test p\nJust an unsmoothed parameter for tests."; + pub const sig : &'static str = "Test sig\nThe output of p as signal"; } impl DspNode for Test { @@ -54,20 +51,18 @@ impl DspNode for Test { #[inline] fn process( - &mut self, _ctx: &mut T, _ectx: &mut NodeExecContext, - _atoms: &[SAtom], _params: &[ProcBuf], _inputs: &[ProcBuf], - _outputs: &mut [ProcBuf], _led: LedPhaseVals) + &mut self, ctx: &mut T, _ectx: &mut NodeExecContext, + atoms: &[SAtom], _params: &[ProcBuf], _inputs: &[ProcBuf], + outputs: &mut [ProcBuf], _led: LedPhaseVals) { -// use crate::dsp::out; -// use crate::dsp::inp; -// use crate::dsp::denorm; -// -// let gain = inp::Test::gain(inputs); -// let inp = inp::Test::inp(inputs); -// let out = out::Test::sig(outputs); -// for frame in 0..ctx.nframes() { -// out.write(frame, inp.read(frame) * denorm::Test::gain(gain, frame)); -// } + use crate::dsp::{out, at}; + + let p = at::Test::p(atoms); + let out = out::Test::sig(outputs); + for frame in 0..ctx.nframes() { + println!("R {}", p.f()); + out.write(frame, p.f()); + } } fn graph_fun() -> Option { diff --git a/tests/node_test.rs b/tests/node_test.rs new file mode 100644 index 0000000..96c4c9c --- /dev/null +++ b/tests/node_test.rs @@ -0,0 +1,30 @@ +mod common; +use common::*; + +#[test] +fn check_node_test_1() { + let (node_conf, mut node_exec) = new_node_engine(); + let mut matrix = Matrix::new(node_conf, 3, 3); + + let test = NodeId::Test(0); + let out = NodeId::Out(0); + matrix.place(0, 0, Cell::empty(test) + .out(None, None, test.out("sig"))); + matrix.place(0, 1, Cell::empty(out) + .input(out.inp("ch1"), None, None)); + matrix.sync().unwrap(); + + let p = test.inp_param("p").unwrap(); + + matrix.set_param(p, SAtom::param(1.0)); + let res = run_for_ms(&mut node_exec, 2.0); + assert_decimated_feq!(res.0, 1, vec![ 1.0; 10 ]); + + matrix.set_param(p, SAtom::param(0.5)); + let res = run_for_ms(&mut node_exec, 2.0); + assert_decimated_feq!(res.0, 1, vec![ 0.5; 10 ]); + + matrix.set_param(p, SAtom::param(0.0)); + let res = run_for_ms(&mut node_exec, 1.0); + assert_decimated_feq!(res.0, 1, vec![ 0.0; 10 ]); +}