use crate::prelude::*;
macro_rules! unary {
($(#[doc = $doc:literal])* $id:literal, $name:ident, | $input:ident | $value:expr) => {
#[derive(Debug, Clone, Copy, Default, Node)]
#[node(id = $id, module = "unary")]
#[input($input)]
$(#[doc = $doc])*
pub struct $name;
impl $name {
fn render(&mut self, input: Input, output: &mut [Sample]) {
match input {
Input::Constant($input) => {
let v = $value;
for sample in output.iter_mut() {
*sample = v;
}
}
Input::Buffer(a) => {
for (sample, input) in (output.iter_mut(), a).zip() {
let $input = *input;
*sample = $value;
}
}
}
}
}
};
}
unary!(
1,
Abs,
|input| input.abs()
);
unary!(
2,
Acos,
|input| input.acos()
);
unary!(
3,
Acosh,
|input| input.acosh()
);
unary!(
4,
Asin,
|input| input.asin()
);
unary!(
5,
Asinh,
|input| input.asinh()
);
unary!(
6,
Atan,
|input| input.atan()
);
unary!(
7,
Atanh,
|input| input.atanh()
);
unary!(
8,
Cbrt,
|input| input.cbrt()
);
unary!(
9,
Ceil,
|input| input.ceil()
);
unary!(
10,
Cos,
|input| input.cos()
);
unary!(
11,
Cosh,
|input| input.cosh()
);
unary!(
12,
Exp,
|input| input.exp()
);
unary!(
13,
Exp2,
|input| input.exp2()
);
unary!(
14,
ExpM1,
|input| input.exp_m1()
);
unary!(
15,
Floor,
|input| input.floor()
);
unary!(
16,
Fract,
|input| input.fract()
);
unary!(
17,
Ln,
|input| input.ln()
);
unary!(
18,
Ln1p,
|input| input.ln_1p()
);
unary!(
19,
Log10,
|input| input.log10()
);
unary!(
20,
Log2,
|input| input.log2()
);
unary!(
21,
Norm,
|input| {
use core::num::FpCategory::*;
match input.classify() {
Nan => 0.0,
Infinite if input.is_sign_positive() => f64::MAX,
Infinite => f64::MIN,
Zero => 0.0,
_ => input,
}
}
);
unary!(
22,
Recip,
|input| input.recip()
);
unary!(
23,
Round,
|input| input.round()
);
unary!(
24,
Signum,
|input| input.signum()
);
unary!(
25,
Sin,
|input| input.sin()
);
unary!(
26,
Sinh,
|input| input.sinh()
);
unary!(
27,
Sqrt,
|input| input.sqrt()
);
unary!(
28,
Tan,
|input| input.tan()
);
unary!(
29,
Tanh,
|input| input.tanh()
);
unary!(
30,
ToDegrees,
|input| input.to_degrees()
);
unary!(
31,
ToRadians,
|input| input.to_radians()
);
unary!(
32,
Trunc,
|input| input.trunc()
);
unary!(
33,
Neg,
|input| -input
);
unary!(
34,
Pass,
|input| input
);