2021-05-18 03:11:19 +00:00
|
|
|
// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
|
|
|
|
// This is a part of HexoDSP. Released under (A)GPLv3 or any later.
|
|
|
|
// See README.md and COPYING for details.
|
|
|
|
|
2021-06-02 01:59:21 +00:00
|
|
|
use crate::nodes::{NodeAudioContext, NodeExecContext};
|
2021-06-03 03:10:29 +00:00
|
|
|
use crate::dsp::{NodeId, SAtom, ProcBuf, GraphFun, GraphAtomData, DspNode, LedPhaseVals};
|
2021-06-23 03:07:32 +00:00
|
|
|
use crate::dsp::helpers::{TrigSignal};
|
2021-05-18 03:11:19 +00:00
|
|
|
|
2021-06-04 16:14:41 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! fa_test_s { ($formatter: expr, $v: expr, $denorm_v: expr) => { {
|
|
|
|
let s =
|
|
|
|
match ($v.round() as usize) {
|
|
|
|
0 => "Zero",
|
|
|
|
1 => "One",
|
|
|
|
2 => "Two",
|
|
|
|
3 => "Three",
|
|
|
|
4 => "Four",
|
|
|
|
5 => "Five",
|
|
|
|
6 => "Six",
|
|
|
|
7 => "Seven",
|
|
|
|
8 => "Eigth",
|
|
|
|
9 => "Nine",
|
|
|
|
10 => "Ten",
|
|
|
|
_ => "?",
|
|
|
|
};
|
|
|
|
write!($formatter, "{}", s)
|
|
|
|
} } }
|
|
|
|
|
2021-05-18 03:11:19 +00:00
|
|
|
/// A simple amplifier
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Test {
|
2021-06-23 03:07:32 +00:00
|
|
|
trig_sig: TrigSignal,
|
|
|
|
trigger: bool,
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Test {
|
2021-06-03 03:10:29 +00:00
|
|
|
pub fn new(_nid: &NodeId) -> Self {
|
2021-05-18 03:11:19 +00:00
|
|
|
Self {
|
2021-06-23 03:07:32 +00:00
|
|
|
trigger: false,
|
|
|
|
trig_sig: TrigSignal::new(),
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-23 03:07:32 +00:00
|
|
|
|
2021-05-18 03:11:19 +00:00
|
|
|
pub const f : &'static str = "F Test";
|
2021-06-23 03:07:32 +00:00
|
|
|
pub const p : &'static str = "Test p\nAn unsmoothed parameter for automated tests.";
|
|
|
|
pub const trig: &'static str = "Test trig\nA trigger input, that will create a short pulse on the 'tsig' output.\nRange: (-1..1)";
|
2021-06-16 01:54:46 +00:00
|
|
|
pub const sig : &'static str = "Test sig\nThe output of p as signal";
|
2021-06-23 03:07:32 +00:00
|
|
|
pub const tsig : &'static str = "Test tsig\nA short trigger pulse will be generated when the 'trig' input is triggered.";
|
|
|
|
|
|
|
|
pub const DESC : &'static str = r#""#;
|
|
|
|
pub const HELP : &'static str = r#""#;
|
|
|
|
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DspNode for Test {
|
2021-06-23 03:07:32 +00:00
|
|
|
fn outputs() -> usize { 2 }
|
|
|
|
|
|
|
|
fn set_sample_rate(&mut self, srate: f32) {
|
|
|
|
self.trig_sig.set_sample_rate(srate);
|
|
|
|
}
|
2021-05-18 03:11:19 +00:00
|
|
|
|
2021-06-23 03:07:32 +00:00
|
|
|
fn reset(&mut self) {
|
|
|
|
self.trig_sig.reset();
|
|
|
|
}
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn process<T: NodeAudioContext>(
|
2021-06-16 01:54:46 +00:00
|
|
|
&mut self, ctx: &mut T, _ectx: &mut NodeExecContext,
|
|
|
|
atoms: &[SAtom], _params: &[ProcBuf], _inputs: &[ProcBuf],
|
|
|
|
outputs: &mut [ProcBuf], _led: LedPhaseVals)
|
2021-05-18 03:11:19 +00:00
|
|
|
{
|
2021-06-23 03:07:32 +00:00
|
|
|
use crate::dsp::{out_idx, at};
|
2021-06-16 01:54:46 +00:00
|
|
|
|
|
|
|
let p = at::Test::p(atoms);
|
2021-06-23 03:07:32 +00:00
|
|
|
let trig = at::Test::trig(atoms);
|
|
|
|
let tsig = out_idx::Test::tsig();
|
|
|
|
|
|
|
|
let (out, tsig) = outputs.split_at_mut(tsig);
|
|
|
|
let out = &mut out[0];
|
|
|
|
let tsig = &mut tsig[0];
|
|
|
|
|
|
|
|
let mut trigger = trig.i();
|
|
|
|
if !self.trigger && trigger > 0 {
|
|
|
|
self.trigger = true;
|
|
|
|
|
|
|
|
} else if !self.trigger && trigger == 0 {
|
|
|
|
self.trigger = false;
|
|
|
|
|
|
|
|
} else if self.trigger {
|
|
|
|
trigger = 0;
|
|
|
|
}
|
|
|
|
|
2021-06-16 01:54:46 +00:00
|
|
|
for frame in 0..ctx.nframes() {
|
2021-06-23 03:07:32 +00:00
|
|
|
if trigger > 0 {
|
|
|
|
self.trig_sig.trigger();
|
|
|
|
trigger = 0;
|
|
|
|
}
|
|
|
|
|
2021-06-16 01:54:46 +00:00
|
|
|
out.write(frame, p.f());
|
2021-06-23 03:07:32 +00:00
|
|
|
let t = self.trig_sig.next();
|
|
|
|
tsig.write(frame, t);
|
2021-06-16 01:54:46 +00:00
|
|
|
}
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn graph_fun() -> Option<GraphFun> {
|
|
|
|
Some(Box::new(|_gd: &dyn GraphAtomData, _init: bool, x: f32| -> f32 {
|
|
|
|
x
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|