1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2022 Weird Constructor <weirdconstructor@gmail.com>
// This file is a part of HexoDSP. Released under GPL-3.0-or-later.
// See README.md and COPYING for details.

use crate::dsp::{
    denorm, inp, out_idx, DspNode, GraphFun, LedPhaseVals, NodeContext, NodeGlobalRef, NodeId,
    ProcBuf, SAtom,
};
use crate::nodes::{NodeAudioContext, NodeExecContext};

/// The (stereo) input port of the plugin
#[derive(Debug, Clone)]
pub struct Inp {}

impl Inp {
    pub fn new(_nid: &NodeId, _node_global: &NodeGlobalRef) -> Self {
        Self {}
    }

    pub const vol: &'static str =
        "The volume of the two plugin input ports, applied to all channels. \
        Please note that this is a linear control, to prevent inaccuracies for **1.0**. \
        ";
    pub const sig1: &'static str = "Audio input channel 1 (left)";
    pub const sig2: &'static str = "Audio input channel 2 (right)";

    pub const DESC: &'static str = "Audio Input Port\n\n\
        This node gives you access to the two input ports of the HexoSynth plugin. \
        Build effects or what ever you can imagine with this!
        ";
    pub const HELP: &'static str = r#"Audio Input Port

This node gives you access to the two input ports of the HexoSynth plugin.
You can build an effects plugin with this node and the `Out` node.
Or a synthesizer that reacts to audio rate control signals on these two
input ports.
"#;

    pub fn graph_fun() -> Option<GraphFun> {
        None
    }
}

impl DspNode for Inp {
    fn set_sample_rate(&mut self, _srate: f32) {}
    fn reset(&mut self) {}

    #[inline]
    fn process(
        &mut self,
        ctx: &mut dyn NodeAudioContext,
        _ectx: &mut NodeExecContext,
        _nctx: &NodeContext,
        _atoms: &[SAtom],
        inputs: &[ProcBuf],
        outputs: &mut [ProcBuf],
        ctx_vals: LedPhaseVals,
    ) {
        let vol = inp::Inp::vol(inputs);

        let sig_i = out_idx::Inp::sig2();
        let (sig1, sig2) = outputs.split_at_mut(sig_i);
        let sig1 = &mut sig1[0];
        let sig2 = &mut sig2[0];

        for frame in 0..ctx.nframes() {
            let vol = denorm::Inp::vol(vol, frame);
            sig1.write(frame, vol * ctx.input(0, frame));
            sig2.write(frame, vol * ctx.input(1, frame));
        }

        let last_val = sig1.read(ctx.nframes() - 1);
        ctx_vals[0].set(last_val);
    }
}