Added omin/omax octave range to Quant

This commit is contained in:
Weird Constructor 2021-08-24 03:59:41 +02:00
parent c5f70252e3
commit 46de4b442d
2 changed files with 74 additions and 9 deletions

View file

@ -89,6 +89,8 @@ 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 node_amp::Amp;
use node_sin::Sin;
@ -736,9 +738,11 @@ macro_rules! node_list {
{7 0 clip setting(0) fa_map_clip 0 1}
[0 sig],
quant => Quant UIType::Generic UICategory::CV
(0 inp n_id d_id r_id f_def stp_d -1.0, 1.0, 0.0)
(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_id 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}
[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)

View file

@ -11,6 +11,34 @@ macro_rules! fa_quant { ($formatter: expr, $v: expr, $denorm_v: expr) => { {
write!($formatter, "?")
} } }
#[macro_export]
macro_rules! fa_quant_omin { ($formatter: expr, $v: expr, $denorm_v: expr) => { {
let s =
match ($v.round() as usize) {
0 => "-0",
1 => "-1",
2 => "-2",
3 => "-3",
4 => "-4",
_ => "?",
};
write!($formatter, "{}", s)
} } }
#[macro_export]
macro_rules! fa_quant_omax { ($formatter: expr, $v: expr, $denorm_v: expr) => { {
let s =
match ($v.round() as usize) {
0 => "+0",
1 => "+1",
2 => "+2",
3 => "+3",
4 => "+4",
_ => "?",
};
write!($formatter, "{}", s)
} } }
/// A 9 channel signal multiplexer
#[derive(Debug, Clone)]
pub struct Quant {
@ -25,6 +53,10 @@ impl Quant {
"Quant inp\n\nRange: (0..1)";
pub const oct : &'static str =
"Quant oct\n\nRange: (-1..1)";
pub const omin : &'static str =
"Quant omin\n\nRange: (-1..1)";
pub const omax : &'static str =
"Quant omax\n\nRange: (-1..1)";
pub const sig : &'static str =
"Quant sig\n\nRange: (-1..1)";
pub const keys : &'static str =
@ -37,7 +69,6 @@ r#"Pitch/Note Quantizer
r#"Quant - A pitch quantizer
"#;
}
impl DspNode for Quant {
@ -59,6 +90,8 @@ impl DspNode for Quant {
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 mut key_count = 0;
let mut used_keys = [0.0; 12];
@ -71,6 +104,7 @@ impl DspNode for Quant {
key_count += 1;
}
}
for i in 9..12 {
let key_pitch_idx = (i + 9 + 12) % 12;
if mask & (0x1 << i) > 0 {
@ -79,8 +113,33 @@ impl DspNode for Quant {
}
}
let mut all_keys = [0.0; 12 * 10]; // -4 and +4 octaves + 1 center
let mut max_all = 0;
if key_count == 0 {
let omin = omin.i() as usize;
for o in 0..omin {
let o = omin - o;
for i in 0..key_count {
all_keys[max_all] = used_keys[i] - (o as f32) * 0.1;
max_all += 1;
}
}
for i in 0..key_count {
all_keys[max_all] = used_keys[i];
max_all += 1;
}
let omax = omax.i() as usize;
for o in 1..=omax {
for i in 0..key_count {
all_keys[max_all] = used_keys[i] + (o as f32) * 0.1;
max_all += 1;
}
}
if max_all == 0 {
for frame in 0..ctx.nframes() {
out.write(
frame,
@ -90,19 +149,21 @@ impl DspNode for Quant {
ctx_vals[1].set(100.0); // some unreachable value for Keys widget
ctx_vals[0].set(out.read(ctx.nframes() - 1));
} else {
let mut last_pitch = 0.0;
let mut last_key = 0;
for frame in 0..ctx.nframes() {
let key =
(denorm::Quant::inp(inp, frame) * (key_count as f32))
(denorm::Quant::inp(inp, frame) * (max_all as f32))
.floor();
let key = key as usize % key_count;
let pitch = used_keys[key];
last_pitch = pitch;
let key = key as usize % max_all;
let pitch = all_keys[key];
last_key = key;
out.write(frame, pitch + denorm::Quant::oct(oct, frame));
}
let last_pitch = used_keys[last_key as usize % key_count];
ctx_vals[1].set((last_pitch + tune_to_a4) * 10.0 + 0.0001);
ctx_vals[0].set(((last_pitch + tune_to_a4) * 10.0 - 0.5) * 2.0);
}