prepared delay boilerplate

This commit is contained in:
Weird Constructor 2021-06-19 10:50:39 +02:00
parent a89433c320
commit 337ffa12f5
2 changed files with 94 additions and 2 deletions

View file

@ -18,6 +18,8 @@ mod node_sampl;
mod node_fbwr_fbrd;
#[allow(non_upper_case_globals)]
mod node_ad;
#[allow(non_upper_case_globals)]
mod node_delay;
pub mod tracker;
mod satom;
@ -51,6 +53,7 @@ use node_sampl::Sampl;
use node_fbwr_fbrd::FbWr;
use node_fbwr_fbrd::FbRd;
use node_ad::Ad;
use node_delay::Delay;
pub const MIDI_MAX_FREQ : f32 = 13289.75;
@ -275,7 +278,7 @@ macro_rules! r_det { ($x: expr, $coarse: expr) => {
} }
/// The rounding function for milliseconds knobs
macro_rules! r_ms { ($x: expr, $coarse: expr) => {
macro_rules! r_dc_ms { ($x: expr, $coarse: expr) => {
if $coarse {
n_declick!((d_declick!($x)).round())
} else {
@ -292,6 +295,16 @@ macro_rules! r_ems { ($x: expr, $coarse: expr) => {
}
} }
/// The rounding function for milliseconds knobs
macro_rules! r_tms { ($x: expr, $coarse: expr) => {
if $coarse {
n_time!((d_time!($x)).round())
} else {
n_time!((d_time!($x) * 10.0).round() / 10.0)
}
} }
/// The default steps function:
macro_rules! stp_d { () => { (20.0, 100.0) } }
/// The UI steps to control parameters with a finer fine control:
@ -353,6 +366,7 @@ define_exp!{n_env d_env 0.0, 1000.0}
// Special linear gain factor for the Out node, to be able
// to reach more exact "1.0".
define_lin!{n_ogin d_ogin 0.0, 2.0}
define_lin!{n_time d_time 0.0, 5000.0}
// A note about the input-indicies:
//
@ -401,7 +415,7 @@ macro_rules! node_list {
(1 trig n_id n_id r_id f_def stp_d -1.0, 1.0, 0.0)
(2 offs n_id n_id r_id f_def stp_d 0.0, 1.0, 0.0)
(3 len n_id n_id r_id f_def stp_d 0.0, 1.0, 1.0)
(4 dcms n_declick d_declick r_ms f_ms stp_m 0.0, 1.0, 3.0)
(4 dcms n_declick d_declick r_dc_ms f_ms stp_m 0.0, 1.0, 3.0)
(5 det n_det d_det r_det f_det stp_f -0.2, 0.2, 0.0)
{6 0 sample audio_unloaded("") f_def 0 0}
{7 1 pmode setting(0) fa_sampl_pmode 0 1}
@ -440,6 +454,12 @@ macro_rules! node_list {
{6 0 mult setting(0) fa_ad_mult 0 2}
[0 sig]
[1 eoet],
delay => Delay UIType::Generic UICategory::Signal
(0 inp n_id d_id r_id f_def stp_d -1.0, 1.0, 1.0)
(1 time n_time d_time r_tms f_ms stp_m 0.0, 1.0, 0.5)
(2 fb n_id d_id r_id f_def stp_d 0.0, 1.0, 0.0)
(3 mix n_id d_id r_id f_def stp_d 0.0, 1.0, 0.5)
[0 sig],
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 p param(0.0) fa_test_s 0 10}

72
src/dsp/node_delay.rs Normal file
View file

@ -0,0 +1,72 @@
// 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.
use crate::nodes::{NodeAudioContext, NodeExecContext};
use crate::dsp::{NodeId, SAtom, ProcBuf, GraphFun, GraphAtomData, DspNode, LedPhaseVals};
#[macro_export]
macro_rules! fa_dly_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)
} } }
/// A simple amplifier
#[derive(Debug, Clone)]
pub struct Delay {
}
impl Delay {
pub const DESC : &'static str = r#""#;
pub const HELP : &'static str = r#""#;
pub fn new(_nid: &NodeId) -> Self {
Self {
}
}
pub const f : &'static str = "F Delay";
pub const p : &'static str = "Delay p\nJust an unsmoothed parameter for tests.";
pub const sig : &'static str = "Delay sig\nThe output of p as signal";
}
impl DspNode for Delay {
fn outputs() -> usize { 1 }
fn set_sample_rate(&mut self, _srate: f32) { }
fn reset(&mut self) { }
#[inline]
fn process<T: NodeAudioContext>(
&mut self, ctx: &mut T, _ectx: &mut NodeExecContext,
atoms: &[SAtom], _params: &[ProcBuf], _inputs: &[ProcBuf],
outputs: &mut [ProcBuf], _led: LedPhaseVals)
{
use crate::dsp::{out, at};
let p = at::Delay::p(atoms);
let out = out::Delay::sig(outputs);
for frame in 0..ctx.nframes() {
out.write(frame, p.f());
}
}
fn graph_fun() -> Option<GraphFun> {
Some(Box::new(|_gd: &dyn GraphAtomData, _init: bool, x: f32| -> f32 {
x
}))
}
}