From b7284b6b8a30f5196aaca18c2402dbc82b3e2aee Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Wed, 2 Jun 2021 03:59:21 +0200 Subject: [PATCH] gave all nodes access to NodeExecContext --- src/dsp/mod.rs | 15 +++++++++++---- src/dsp/node_amp.rs | 7 ++++--- src/dsp/node_out.rs | 7 ++++--- src/dsp/node_sampl.rs | 7 ++++--- src/dsp/node_sin.rs | 7 ++++--- src/dsp/node_test.rs | 7 ++++--- src/dsp/node_tseq.rs | 7 ++++--- 7 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/dsp/mod.rs b/src/dsp/mod.rs index c379ad1..306258b 100644 --- a/src/dsp/mod.rs +++ b/src/dsp/mod.rs @@ -62,6 +62,12 @@ pub trait DspNode { /// The code DSP function. /// + /// * `ctx` is the audio context, which informs the node about + /// the number of samples to process. It also provides input/output + /// ports for the in/out nodes. + /// * `ectx` is the execution context, which provides global stuff + /// for all nodes to potentially use. For instance it's used + /// by the `FbWr` and `FbRd` nodes to share an audio buffer. /// * `atoms` are un-smoothed parameters. they can hold integer settings, /// samples or even strings. /// * `params` are smoother paramters, those who usually have a knob @@ -70,9 +76,9 @@ pub trait DspNode { /// these inputs might be overwritten by outputs of other nodes. /// * `outputs` are the output buffers of this node. fn process( - &mut self, ctx: &mut T, 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); /// A function factory for generating a graph for the generic node UI. fn graph_fun() -> Option { None } @@ -1162,7 +1168,8 @@ impl Node { match self { Node::$v1 => {}, $(Node::$variant { node } => - node.process(ctx, atoms, params, inputs, outputs, led),)+ + node.process(ctx, ectx, atoms, params, + inputs, outputs, led),)+ } } } diff --git a/src/dsp/node_amp.rs b/src/dsp/node_amp.rs index bdb8813..0a9e52b 100644 --- a/src/dsp/node_amp.rs +++ b/src/dsp/node_amp.rs @@ -2,7 +2,7 @@ // This is a part of HexoDSP. Released under (A)GPLv3 or any later. // See README.md and COPYING for details. -use crate::nodes::NodeAudioContext; +use crate::nodes::{NodeAudioContext, NodeExecContext}; use crate::dsp::{SAtom, ProcBuf, DspNode, LedPhaseVals}; /// A simple amplifier @@ -36,8 +36,9 @@ impl DspNode for Amp { #[inline] fn process( - &mut self, ctx: &mut T, atoms: &[SAtom], _params: &[ProcBuf], - inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) + &mut self, ctx: &mut T, _ectx: &mut NodeExecContext, + atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf], + outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) { use crate::dsp::{out, inp, denorm, denorm_v, inp_dir, at}; diff --git a/src/dsp/node_out.rs b/src/dsp/node_out.rs index 6c2852d..99c973b 100644 --- a/src/dsp/node_out.rs +++ b/src/dsp/node_out.rs @@ -2,7 +2,7 @@ // This is a part of HexoDSP. Released under (A)GPLv3 or any later. // See README.md and COPYING for details. -use crate::nodes::NodeAudioContext; +use crate::nodes::{NodeAudioContext, NodeExecContext}; use crate::dsp::{SAtom, ProcBuf, inp, at, DspNode, LedPhaseVals}; /// The (stereo) output port of the plugin @@ -52,8 +52,9 @@ impl DspNode for Out { #[inline] fn process( - &mut self, ctx: &mut T, atoms: &[SAtom], _params: &[ProcBuf], - inputs: &[ProcBuf], _outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) + &mut self, ctx: &mut T, _ectx: &mut NodeExecContext, + atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf], + _outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) { let in1 = inp::Out::ch1(inputs); diff --git a/src/dsp/node_sampl.rs b/src/dsp/node_sampl.rs index bd3ef18..772725f 100644 --- a/src/dsp/node_sampl.rs +++ b/src/dsp/node_sampl.rs @@ -2,7 +2,7 @@ // This is a part of HexoDSP. Released under (A)GPLv3 or any later. // See README.md and COPYING for details. -use crate::nodes::NodeAudioContext; +use crate::nodes::{NodeAudioContext, NodeExecContext}; use crate::dsp::{SAtom, ProcBuf, DspNode, LedPhaseVals}; use crate::dsp::{out, at, inp, denorm}; //, inp, denorm, denorm_v, inp_dir, at}; use super::helpers::Trigger; @@ -240,8 +240,9 @@ impl DspNode for Sampl { #[inline] fn process( - &mut self, ctx: &mut T, atoms: &[SAtom], _params: &[ProcBuf], - inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) + &mut self, ctx: &mut T, _ectx: &mut NodeExecContext, + atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf], + outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) { let sample = at::Sampl::sample(atoms); let pmode = at::Sampl::pmode(atoms); diff --git a/src/dsp/node_sin.rs b/src/dsp/node_sin.rs index f47ab6c..6b8c5a3 100644 --- a/src/dsp/node_sin.rs +++ b/src/dsp/node_sin.rs @@ -2,7 +2,7 @@ // This is a part of HexoDSP. Released under (A)GPLv3 or any later. // See README.md and COPYING for details. -use crate::nodes::NodeAudioContext; +use crate::nodes::{NodeAudioContext, NodeExecContext}; use crate::dsp::{SAtom, ProcBuf, denorm, out, inp, DspNode, LedPhaseVals}; use crate::dsp::helpers::fast_sin; @@ -44,8 +44,9 @@ impl DspNode for Sin { #[inline] fn process( - &mut self, ctx: &mut T, _atoms: &[SAtom], _params: &[ProcBuf], - inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) + &mut self, ctx: &mut T, _ectx: &mut NodeExecContext, + _atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf], + outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) { let o = out::Sin::sig(outputs); let freq = inp::Sin::freq(inputs); diff --git a/src/dsp/node_test.rs b/src/dsp/node_test.rs index 94cd33b..d3b9c3b 100644 --- a/src/dsp/node_test.rs +++ b/src/dsp/node_test.rs @@ -2,7 +2,7 @@ // This is a part of HexoDSP. Released under (A)GPLv3 or any later. // See README.md and COPYING for details. -use crate::nodes::NodeAudioContext; +use crate::nodes::{NodeAudioContext, NodeExecContext}; use crate::dsp::{SAtom, ProcBuf, GraphFun, GraphAtomData, DspNode, LedPhaseVals}; /// A simple amplifier @@ -31,8 +31,9 @@ impl DspNode for Test { #[inline] fn process( - &mut self, _ctx: &mut T, _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; diff --git a/src/dsp/node_tseq.rs b/src/dsp/node_tseq.rs index a003b58..05d1723 100644 --- a/src/dsp/node_tseq.rs +++ b/src/dsp/node_tseq.rs @@ -2,7 +2,7 @@ // This is a part of HexoDSP. Released under (A)GPLv3 or any later. // See README.md and COPYING for details. -use crate::nodes::NodeAudioContext; +use crate::nodes::{NodeAudioContext, NodeExecContext}; use crate::dsp::helpers::TriggerClock; use crate::dsp::{SAtom, ProcBuf, DspNode, LedPhaseVals}; use crate::dsp::tracker::TrackerBackend; @@ -70,8 +70,9 @@ impl DspNode for TSeq { #[inline] fn process( - &mut self, ctx: &mut T, atoms: &[SAtom], _params: &[ProcBuf], - inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) + &mut self, ctx: &mut T, _ectx: &mut NodeExecContext, + atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf], + outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) { use crate::dsp::{out, inp, at}; let clock = inp::TSeq::clock(inputs);