From 42553cc8001646306282426cfb9b46b35e3427b1 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Wed, 25 Aug 2021 21:14:41 +0200 Subject: [PATCH] renamed Quant to CQnt, because it's more specialized than just a simple quantizer --- src/dsp/helpers.rs | 4 +- src/dsp/mod.rs | 20 ++++----- src/dsp/{node_quant.rs => node_cqnt.rs} | 58 +++++++++++++------------ 3 files changed, 43 insertions(+), 39 deletions(-) rename src/dsp/{node_quant.rs => node_cqnt.rs} (62%) diff --git a/src/dsp/helpers.rs b/src/dsp/helpers.rs index 49b8971..36bda58 100644 --- a/src/dsp/helpers.rs +++ b/src/dsp/helpers.rs @@ -2135,7 +2135,7 @@ impl TriSawLFO { } #[derive(Debug, Clone)] -pub struct Quantizer { +pub struct CtrlPitchQuantizer { /// All keys, containing the min/max octave! keys: Vec, /// Only the used keys with their pitches from the UI @@ -2150,7 +2150,7 @@ pub struct Quantizer { const QUANT_TUNE_TO_A4 : f32 = (9.0 / 12.0) * 0.1; -impl Quantizer { +impl CtrlPitchQuantizer { pub fn new() -> Self { Self { keys: vec![0.0; 12 * 10], diff --git a/src/dsp/mod.rs b/src/dsp/mod.rs index 6d9b057..ce607a6 100644 --- a/src/dsp/mod.rs +++ b/src/dsp/mod.rs @@ -49,7 +49,7 @@ mod node_rndwk; #[allow(non_upper_case_globals)] mod node_mux9; #[allow(non_upper_case_globals)] -mod node_quant; +mod node_cqnt; pub mod biquad; pub mod tracker; @@ -88,9 +88,9 @@ use crate::fa_vosc_ovrsmpl; use crate::fa_distort; use crate::fa_comb_mode; use crate::fa_mux9_in_cnt; -use crate::fa_quant; -use crate::fa_quant_omin; -use crate::fa_quant_omax; +use crate::fa_cqnt; +use crate::fa_cqnt_omin; +use crate::fa_cqnt_omax; use node_amp::Amp; use node_sin::Sin; @@ -116,7 +116,7 @@ use node_tslfo::TsLFO; use node_pverb::PVerb; use node_rndwk::RndWk; use node_mux9::Mux9; -use node_quant::Quant; +use node_cqnt::CQnt; pub const MIDI_MAX_FREQ : f32 = 13289.75; @@ -383,7 +383,7 @@ macro_rules! define_exp6 { macro_rules! n_pit { ($x: expr) => { - ((($x as f32).max(0.01) / 440.0).log2() / 10.0) + 0.1 * (($x as f32).max(0.01) / 440.0).log2() } } macro_rules! d_pit { ($x: expr) => { @@ -737,12 +737,12 @@ macro_rules! node_list { (6 max n_id d_id r_s f_def stp_d -1.0, 1.0, 1.0) {7 0 clip setting(0) fa_map_clip 0 1} [0 sig], - quant => Quant UIType::Generic UICategory::CV + cqnt => CQnt UIType::Generic UICategory::CV (0 inp n_id d_id r_id f_def stp_d 0.0, 1.0, 0.0) (1 oct n_id d_id r_s f_def stp_d -1.0, 1.0, 0.0) - {2 0 keys setting(0) fa_quant 0 0} - {3 1 omin setting(0) fa_quant_omin 0 4} - {4 2 omax setting(0) fa_quant_omax 0 4} + {2 0 keys setting(0) fa_cqnt 0 0} + {3 1 omin setting(0) fa_cqnt_omin 0 4} + {4 2 omax setting(0) fa_cqnt_omax 0 4} [0 sig], tseq => TSeq UIType::Generic UICategory::Mod (0 clock n_id d_id r_id f_def stp_d 0.0, 1.0, 0.0) diff --git a/src/dsp/node_quant.rs b/src/dsp/node_cqnt.rs similarity index 62% rename from src/dsp/node_quant.rs rename to src/dsp/node_cqnt.rs index 8acf5cf..ffedf04 100644 --- a/src/dsp/node_quant.rs +++ b/src/dsp/node_cqnt.rs @@ -4,15 +4,15 @@ use crate::nodes::{NodeAudioContext, NodeExecContext}; use crate::dsp::{NodeId, SAtom, ProcBuf, DspNode, LedPhaseVals, NodeContext}; -use crate::dsp::helpers::Quantizer; +use crate::dsp::helpers::CtrlPitchQuantizer; #[macro_export] -macro_rules! fa_quant { ($formatter: expr, $v: expr, $denorm_v: expr) => { { +macro_rules! fa_cqnt { ($formatter: expr, $v: expr, $denorm_v: expr) => { { write!($formatter, "?") } } } #[macro_export] -macro_rules! fa_quant_omin { ($formatter: expr, $v: expr, $denorm_v: expr) => { { +macro_rules! fa_cqnt_omin { ($formatter: expr, $v: expr, $denorm_v: expr) => { { let s = match ($v.round() as usize) { 0 => "-0", @@ -26,7 +26,7 @@ macro_rules! fa_quant_omin { ($formatter: expr, $v: expr, $denorm_v: expr) => { } } } #[macro_export] -macro_rules! fa_quant_omax { ($formatter: expr, $v: expr, $denorm_v: expr) => { { +macro_rules! fa_cqnt_omax { ($formatter: expr, $v: expr, $denorm_v: expr) => { { let s = match ($v.round() as usize) { 0 => "+0", @@ -41,39 +41,43 @@ macro_rules! fa_quant_omax { ($formatter: expr, $v: expr, $denorm_v: expr) => { /// A 9 channel signal multiplexer #[derive(Debug, Clone)] -pub struct Quant { - quant: Quantizer, +pub struct CQnt { + quant: Box, } -impl Quant { +impl CQnt { pub fn new(_nid: &NodeId) -> Self { Self { - quant: Quantizer::new(), + quant: Box::new(CtrlPitchQuantizer::new()), } } pub const inp : &'static str = - "Quant inp\n\nRange: (0..1)"; + "CQnt inp\n\nRange: (0..1)"; pub const oct : &'static str = - "Quant oct\n\nRange: (-1..1)"; + "CQnt oct\n\nRange: (-1..1)"; pub const omin : &'static str = - "Quant omin\n\nRange: (-1..1)"; + "CQnt omin\n\nRange: (-1..1)"; pub const omax : &'static str = - "Quant omax\n\nRange: (-1..1)"; + "CQnt omax\n\nRange: (-1..1)"; pub const sig : &'static str = - "Quant sig\n\nRange: (-1..1)"; + "CQnt sig\n\nRange: (-1..1)"; pub const keys : &'static str = - "Quant keys\n"; + "CQnt keys\n"; pub const DESC : &'static str = -r#"Pitch/Note Quantizer +r#"Control Pitch Quantizer +This special quantizer maps the 0..1 input range on 'inp' evenly to the selected keys and octaves. "#; pub const HELP : &'static str = -r#"Quant - A pitch quantizer +r#"CQnt - A control signal to pitch quantizer +This is a specialized quantizer to generate a pitch/frequency from a signal +within the 0..1 range. It does not quantize a typical -1..1 frequency signal +like the 'Quant' node. "#; } -impl DspNode for Quant { +impl DspNode for CQnt { fn outputs() -> usize { 1 } fn set_sample_rate(&mut self, _srate: f32) { } @@ -88,12 +92,12 @@ impl DspNode for Quant { { use crate::dsp::{at, out, inp, denorm}; - let inp = inp::Quant::inp(inputs); - let oct = inp::Quant::oct(inputs); - let out = out::Quant::sig(outputs); - let keys = at::Quant::keys(atoms); - let omin = at::Quant::omin(atoms); - let omax = at::Quant::omax(atoms); + let inp = inp::CQnt::inp(inputs); + let oct = inp::CQnt::oct(inputs); + let out = out::CQnt::sig(outputs); + let keys = at::CQnt::keys(atoms); + let omin = at::CQnt::omin(atoms); + let omax = at::CQnt::omax(atoms); self.quant.update_keys(keys.i(), omin.i(), omax.i()); @@ -101,8 +105,8 @@ impl DspNode for Quant { for frame in 0..ctx.nframes() { out.write( frame, - denorm::Quant::inp(inp, frame) - + denorm::Quant::oct(oct, frame)); + denorm::CQnt::inp(inp, frame) + + denorm::CQnt::oct(oct, frame)); } ctx_vals[1].set(100.0); // some unreachable value for Keys widget @@ -114,8 +118,8 @@ impl DspNode for Quant { for frame in 0..ctx.nframes() { let pitch = self.quant.signal_to_pitch( - denorm::Quant::inp(inp, frame)); - out.write(frame, pitch + denorm::Quant::oct(oct, frame)); + denorm::CQnt::inp(inp, frame)); + out.write(frame, pitch + denorm::CQnt::oct(oct, frame)); } let last_pitch = self.quant.last_key_pitch();