From 79c3e36eabc8dfb403f416782a1f8bf864717e8f Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sat, 5 Jun 2021 09:13:42 +0200 Subject: [PATCH] sin now has a detune UI parameter (not yet handled in DSP) --- src/dsp/mod.rs | 23 +++++++++++++++++++++++ src/dsp/node_sin.rs | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/src/dsp/mod.rs b/src/dsp/mod.rs index 93da0c8..9ac4b7d 100644 --- a/src/dsp/mod.rs +++ b/src/dsp/mod.rs @@ -249,6 +249,14 @@ macro_rules! d_pit { ($x: expr) => { } } } +// 5.0 for mapping -0.2-0.2 range to -1.0 to 1.0 +// 5.0 * 0.2 => 24.0 +// 5.0 * 0.1 => 12.0 +// 5.0 * 0.008333333 => 1.0 +// 5.0 * 0.000083333 => 0.001 +macro_rules! n_det { ($x: expr) => { ($x * 5.0 * 0.1) / 12.0 } } +macro_rules! d_det { ($x: expr) => { $x * 0.2 * 120.0 } } + // Rounding function that does nothing macro_rules! r_id { ($x: expr) => { $x } } @@ -267,6 +275,20 @@ macro_rules! f_freq { ($formatter: expr, $v: expr, $denorm_v: expr) => { } } } +macro_rules! f_det { ($formatter: expr, $v: expr, $denorm_v: expr) => { + { + let sign = if $denorm_v < 0.0 { -1.0 } else { 1.0 }; + let semitones = $denorm_v.floor().abs(); + let cents = ($denorm_v.fract() * 100.0).floor().abs(); + + if (cents > 1.0) { + write!($formatter, "{:2.0}s {:3.0}c", sign * semitones, cents) + } else { + write!($formatter, "{:2.0}s", sign * semitones) + } + } +} } + // norm-fun denorm-min // denorm-fun denorm-max define_exp!{n_gain d_gain 0.0, 2.0} @@ -328,6 +350,7 @@ macro_rules! node_list { [0 sig], sin => Sin UIType::Generic UICategory::Osc (0 freq n_pit d_pit r_id f_freq -1.0, 1.0, 440.0) + (1 det n_det d_det r_id f_det -1.0, 1.0, 0.0) [0 sig], out => Out UIType::Generic UICategory::IOUtil (0 ch1 n_id d_id r_id f_def -1.0, 1.0, 0.0) diff --git a/src/dsp/node_sin.rs b/src/dsp/node_sin.rs index 1b2fbaa..6f947f0 100644 --- a/src/dsp/node_sin.rs +++ b/src/dsp/node_sin.rs @@ -27,6 +27,12 @@ impl Sin { } pub const freq : &'static str = "Sin freq\nFrequency of the oscillator.\n\nRange: (-1..1)\n"; + pub const det : &'static str = + "Sin det\nDetune the oscillator in semitones and cents. \ + the input of this value is rounded to semitones on coarse input. \ + Fine input lets you detune in cents (rounded). \ + A signal sent to this port is not rounded.\ + \n\nRange: (-1..1)\n"; pub const sig : &'static str = "Sin sig\nOscillator signal output.\n\nRange: (-1..1)\n"; }