gave all nodes access to NodeExecContext

This commit is contained in:
Weird Constructor 2021-06-02 03:59:21 +02:00
parent 297360e398
commit b7284b6b8a
7 changed files with 35 additions and 22 deletions

View file

@ -62,6 +62,12 @@ pub trait DspNode {
/// The code DSP function. /// 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, /// * `atoms` are un-smoothed parameters. they can hold integer settings,
/// samples or even strings. /// samples or even strings.
/// * `params` are smoother paramters, those who usually have a knob /// * `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. /// these inputs might be overwritten by outputs of other nodes.
/// * `outputs` are the output buffers of this node. /// * `outputs` are the output buffers of this node.
fn process<T: NodeAudioContext>( fn process<T: NodeAudioContext>(
&mut self, ctx: &mut T, atoms: &[SAtom], params: &[ProcBuf], &mut self, ctx: &mut T, ectx: &mut NodeExecContext,
inputs: &[ProcBuf], outputs: &mut [ProcBuf], atoms: &[SAtom], params: &[ProcBuf], inputs: &[ProcBuf],
led: LedPhaseVals); outputs: &mut [ProcBuf], led: LedPhaseVals);
/// A function factory for generating a graph for the generic node UI. /// A function factory for generating a graph for the generic node UI.
fn graph_fun() -> Option<GraphFun> { None } fn graph_fun() -> Option<GraphFun> { None }
@ -1162,7 +1168,8 @@ impl Node {
match self { match self {
Node::$v1 => {}, Node::$v1 => {},
$(Node::$variant { node } => $(Node::$variant { node } =>
node.process(ctx, atoms, params, inputs, outputs, led),)+ node.process(ctx, ectx, atoms, params,
inputs, outputs, led),)+
} }
} }
} }

View file

@ -2,7 +2,7 @@
// This is a part of HexoDSP. Released under (A)GPLv3 or any later. // This is a part of HexoDSP. Released under (A)GPLv3 or any later.
// See README.md and COPYING for details. // 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::{SAtom, ProcBuf, DspNode, LedPhaseVals};
/// A simple amplifier /// A simple amplifier
@ -36,8 +36,9 @@ impl DspNode for Amp {
#[inline] #[inline]
fn process<T: NodeAudioContext>( fn process<T: NodeAudioContext>(
&mut self, ctx: &mut T, atoms: &[SAtom], _params: &[ProcBuf], &mut self, ctx: &mut T, _ectx: &mut NodeExecContext,
inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf],
outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals)
{ {
use crate::dsp::{out, inp, denorm, denorm_v, inp_dir, at}; use crate::dsp::{out, inp, denorm, denorm_v, inp_dir, at};

View file

@ -2,7 +2,7 @@
// This is a part of HexoDSP. Released under (A)GPLv3 or any later. // This is a part of HexoDSP. Released under (A)GPLv3 or any later.
// See README.md and COPYING for details. // 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}; use crate::dsp::{SAtom, ProcBuf, inp, at, DspNode, LedPhaseVals};
/// The (stereo) output port of the plugin /// The (stereo) output port of the plugin
@ -52,8 +52,9 @@ impl DspNode for Out {
#[inline] #[inline]
fn process<T: NodeAudioContext>( fn process<T: NodeAudioContext>(
&mut self, ctx: &mut T, atoms: &[SAtom], _params: &[ProcBuf], &mut self, ctx: &mut T, _ectx: &mut NodeExecContext,
inputs: &[ProcBuf], _outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf],
_outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals)
{ {
let in1 = inp::Out::ch1(inputs); let in1 = inp::Out::ch1(inputs);

View file

@ -2,7 +2,7 @@
// This is a part of HexoDSP. Released under (A)GPLv3 or any later. // This is a part of HexoDSP. Released under (A)GPLv3 or any later.
// See README.md and COPYING for details. // 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::{SAtom, ProcBuf, DspNode, LedPhaseVals};
use crate::dsp::{out, at, inp, denorm}; //, inp, denorm, denorm_v, inp_dir, at}; use crate::dsp::{out, at, inp, denorm}; //, inp, denorm, denorm_v, inp_dir, at};
use super::helpers::Trigger; use super::helpers::Trigger;
@ -240,8 +240,9 @@ impl DspNode for Sampl {
#[inline] #[inline]
fn process<T: NodeAudioContext>( fn process<T: NodeAudioContext>(
&mut self, ctx: &mut T, atoms: &[SAtom], _params: &[ProcBuf], &mut self, ctx: &mut T, _ectx: &mut NodeExecContext,
inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf],
outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals)
{ {
let sample = at::Sampl::sample(atoms); let sample = at::Sampl::sample(atoms);
let pmode = at::Sampl::pmode(atoms); let pmode = at::Sampl::pmode(atoms);

View file

@ -2,7 +2,7 @@
// This is a part of HexoDSP. Released under (A)GPLv3 or any later. // This is a part of HexoDSP. Released under (A)GPLv3 or any later.
// See README.md and COPYING for details. // 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::{SAtom, ProcBuf, denorm, out, inp, DspNode, LedPhaseVals};
use crate::dsp::helpers::fast_sin; use crate::dsp::helpers::fast_sin;
@ -44,8 +44,9 @@ impl DspNode for Sin {
#[inline] #[inline]
fn process<T: NodeAudioContext>( fn process<T: NodeAudioContext>(
&mut self, ctx: &mut T, _atoms: &[SAtom], _params: &[ProcBuf], &mut self, ctx: &mut T, _ectx: &mut NodeExecContext,
inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) _atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf],
outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals)
{ {
let o = out::Sin::sig(outputs); let o = out::Sin::sig(outputs);
let freq = inp::Sin::freq(inputs); let freq = inp::Sin::freq(inputs);

View file

@ -2,7 +2,7 @@
// This is a part of HexoDSP. Released under (A)GPLv3 or any later. // This is a part of HexoDSP. Released under (A)GPLv3 or any later.
// See README.md and COPYING for details. // 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}; use crate::dsp::{SAtom, ProcBuf, GraphFun, GraphAtomData, DspNode, LedPhaseVals};
/// A simple amplifier /// A simple amplifier
@ -31,8 +31,9 @@ impl DspNode for Test {
#[inline] #[inline]
fn process<T: NodeAudioContext>( fn process<T: NodeAudioContext>(
&mut self, _ctx: &mut T, _atoms: &[SAtom], _params: &[ProcBuf], &mut self, _ctx: &mut T, _ectx: &mut NodeExecContext,
_inputs: &[ProcBuf], _outputs: &mut [ProcBuf], _led: LedPhaseVals) _atoms: &[SAtom], _params: &[ProcBuf], _inputs: &[ProcBuf],
_outputs: &mut [ProcBuf], _led: LedPhaseVals)
{ {
// use crate::dsp::out; // use crate::dsp::out;
// use crate::dsp::inp; // use crate::dsp::inp;

View file

@ -2,7 +2,7 @@
// This is a part of HexoDSP. Released under (A)GPLv3 or any later. // This is a part of HexoDSP. Released under (A)GPLv3 or any later.
// See README.md and COPYING for details. // See README.md and COPYING for details.
use crate::nodes::NodeAudioContext; use crate::nodes::{NodeAudioContext, NodeExecContext};
use crate::dsp::helpers::TriggerClock; use crate::dsp::helpers::TriggerClock;
use crate::dsp::{SAtom, ProcBuf, DspNode, LedPhaseVals}; use crate::dsp::{SAtom, ProcBuf, DspNode, LedPhaseVals};
use crate::dsp::tracker::TrackerBackend; use crate::dsp::tracker::TrackerBackend;
@ -70,8 +70,9 @@ impl DspNode for TSeq {
#[inline] #[inline]
fn process<T: NodeAudioContext>( fn process<T: NodeAudioContext>(
&mut self, ctx: &mut T, atoms: &[SAtom], _params: &[ProcBuf], &mut self, ctx: &mut T, _ectx: &mut NodeExecContext,
inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals) atoms: &[SAtom], _params: &[ProcBuf], inputs: &[ProcBuf],
outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals)
{ {
use crate::dsp::{out, inp, at}; use crate::dsp::{out, inp, at};
let clock = inp::TSeq::clock(inputs); let clock = inp::TSeq::clock(inputs);