2021-05-18 03:11:19 +00:00
|
|
|
// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
|
2021-08-04 01:58:43 +00:00
|
|
|
// This file is a part of HexoDSP. Released under GPL-3.0-or-later.
|
2021-05-18 03:11:19 +00:00
|
|
|
// See README.md and COPYING for details.
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
use crate::dsp::{at, denorm, inp, DspNode, LedPhaseVals, NodeContext, NodeId, ProcBuf, SAtom};
|
2021-06-02 01:59:21 +00:00
|
|
|
use crate::nodes::{NodeAudioContext, NodeExecContext};
|
2021-05-18 03:11:19 +00:00
|
|
|
|
2021-06-04 03:06:41 +00:00
|
|
|
#[macro_export]
|
2022-07-17 09:58:28 +00:00
|
|
|
macro_rules! fa_out_mono {
|
|
|
|
($formatter: expr, $v: expr, $denorm_v: expr) => {{
|
|
|
|
let s = match ($v.round() as usize) {
|
|
|
|
0 => "Stereo",
|
|
|
|
1 => "Mono",
|
|
|
|
_ => "?",
|
2021-06-04 03:06:41 +00:00
|
|
|
};
|
2022-07-17 09:58:28 +00:00
|
|
|
write!($formatter, "{}", s)
|
|
|
|
}};
|
|
|
|
}
|
2021-06-04 03:06:41 +00:00
|
|
|
|
2021-05-18 03:11:19 +00:00
|
|
|
/// The (stereo) output port of the plugin
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Out {
|
|
|
|
/// - 0: signal channel 1
|
|
|
|
/// - 1: signal channel 2
|
2022-07-03 05:18:43 +00:00
|
|
|
#[allow(dead_code)]
|
2022-07-17 09:58:28 +00:00
|
|
|
input: [f32; 2],
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Out {
|
2021-06-03 03:10:29 +00:00
|
|
|
pub fn new(_nid: &NodeId) -> Self {
|
2022-07-17 09:58:28 +00:00
|
|
|
Self { input: [0.0; 2] }
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const mono: &'static str =
|
2021-06-08 03:08:52 +00:00
|
|
|
"Out mono\nIf set to 'Mono', ch1 will be sent to both output channels.\n(UI only)";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const gain: &'static str =
|
2021-06-15 03:12:53 +00:00
|
|
|
"Out gain\nThe main gain of the synthesizer output, applied to all channels. \
|
|
|
|
Please note that this is a linear control, to prevent inaccuracies for 1.0. \
|
|
|
|
\nRange: (0..1)";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const ch1: &'static str = "Out ch1\nAudio channel 1 (left)\nRange: (-1..1)";
|
|
|
|
pub const ch2: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
2021-05-18 03:11:19 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const ch3: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch4: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch5: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch6: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch7: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch8: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch9: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
2021-05-18 03:11:19 +00:00
|
|
|
pub const ch10: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch11: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch12: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch13: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch14: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch15: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch16: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
|
|
|
pub const ch17: &'static str = "Out ch2\nAudio channel 2 (right)\nRange: (-1..1)";
|
2021-06-07 03:00:10 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const DESC: &'static str = "Audio Output Port\n\n\
|
2021-06-08 03:03:45 +00:00
|
|
|
This output port node allows you to send audio signals \
|
|
|
|
to audio devices or tracks in your DAW.";
|
2022-07-17 09:58:28 +00:00
|
|
|
pub const HELP: &'static str = r#"Audio Output Port
|
2021-06-08 03:03:45 +00:00
|
|
|
|
|
|
|
This output port node allows you to send audio signals to audio devices
|
|
|
|
or tracks in your DAW. If you need a stereo output but only have a mono
|
|
|
|
signal you can use the 'mono' setting to duplicate the signal on the 'ch1'
|
|
|
|
input to the second channel 'ch2'.
|
|
|
|
"#;
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DspNode for Out {
|
2022-07-17 09:58:28 +00:00
|
|
|
fn outputs() -> usize {
|
|
|
|
0
|
|
|
|
}
|
2021-05-18 03:11:19 +00:00
|
|
|
|
2022-07-17 09:58:28 +00:00
|
|
|
fn set_sample_rate(&mut self, _srate: f32) {}
|
|
|
|
fn reset(&mut self) {}
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn process<T: NodeAudioContext>(
|
2022-07-17 09:58:28 +00:00
|
|
|
&mut self,
|
|
|
|
ctx: &mut T,
|
|
|
|
_ectx: &mut NodeExecContext,
|
2021-07-10 19:27:18 +00:00
|
|
|
_nctx: &NodeContext,
|
2022-07-17 09:58:28 +00:00
|
|
|
atoms: &[SAtom],
|
|
|
|
inputs: &[ProcBuf],
|
|
|
|
_outputs: &mut [ProcBuf],
|
|
|
|
ctx_vals: LedPhaseVals,
|
|
|
|
) {
|
|
|
|
let in1 = inp::Out::ch1(inputs);
|
2021-06-08 03:03:45 +00:00
|
|
|
let gain = inp::Out::gain(inputs);
|
2021-05-18 03:11:19 +00:00
|
|
|
|
|
|
|
if at::Out::mono(atoms).i() > 0 {
|
|
|
|
for frame in 0..ctx.nframes() {
|
2021-06-08 03:03:45 +00:00
|
|
|
let gain = denorm::Out::gain(gain, frame);
|
|
|
|
ctx.output(0, frame, gain * in1.read(frame));
|
|
|
|
ctx.output(1, frame, gain * in1.read(frame));
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let in2 = inp::Out::ch2(inputs);
|
|
|
|
|
|
|
|
for frame in 0..ctx.nframes() {
|
2021-06-08 03:03:45 +00:00
|
|
|
let gain = denorm::Out::gain(gain, frame);
|
|
|
|
ctx.output(0, frame, gain * in1.read(frame));
|
|
|
|
ctx.output(1, frame, gain * in2.read(frame));
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let last_val = in1.read(ctx.nframes() - 1);
|
|
|
|
ctx_vals[0].set(last_val);
|
|
|
|
}
|
|
|
|
}
|