let Quant give feedback and fix CQnt when no key is set.

This commit is contained in:
Weird Constructor 2021-08-29 10:59:59 +02:00
parent 172138bc19
commit a496bb1b04
4 changed files with 38 additions and 43 deletions

View file

@ -2137,14 +2137,16 @@ impl<F: Flt> TriSawLFO<F> {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Quantizer { pub struct Quantizer {
old_mask: i64, old_mask: i64,
lkup_tbl: [f32; 24], lkup_tbl: [(f32, f32); 24],
last_key: f32,
} }
impl Quantizer { impl Quantizer {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
old_mask: 0xFFFF_FFFF, old_mask: 0xFFFF_FFFF,
lkup_tbl: [0.0; 24] lkup_tbl: [(0.0, 0.0); 24],
last_key: 0.0,
} }
} }
@ -2193,17 +2195,24 @@ impl Quantizer {
} }
} }
self.lkup_tbl[i as usize] = self.lkup_tbl[i as usize] = (
(min_d_note_idx + 9).rem_euclid(12) as f32 * (0.1 / 12.0),
min_d_note_idx.rem_euclid(12) as f32 * (0.1 / 12.0) min_d_note_idx.rem_euclid(12) as f32 * (0.1 / 12.0)
+ ( if min_d_note_idx < 0 { -0.1 } + ( if min_d_note_idx < 0 { -0.1 }
else if min_d_note_idx > 11 { 0.1 } else if min_d_note_idx > 11 { 0.1 }
else { 0.0 }); else { 0.0 })
);
} }
//d// println!("TBL: {:?}", self.lkup_tbl); //d// println!("TBL: {:?}", self.lkup_tbl);
} }
#[inline] #[inline]
pub fn process(&self, inp: f32) -> f32 { pub fn last_key_pitch(&self) -> f32 {
self.last_key
}
#[inline]
pub fn process(&mut self, inp: f32) -> f32 {
let note_num = (inp * 240.0).round() as i64; let note_num = (inp * 240.0).round() as i64;
let octave = note_num.div_euclid(24); let octave = note_num.div_euclid(24);
let note_idx = note_num - octave * 24; let note_idx = note_num - octave * 24;
@ -2213,7 +2222,9 @@ impl Quantizer {
// inp, octave, note_idx, note_num, inp * 240.0); // inp, octave, note_idx, note_num, inp * 240.0);
//d// println!("TBL: {:?}", self.lkup_tbl); //d// println!("TBL: {:?}", self.lkup_tbl);
let note_pitch = self.lkup_tbl[note_idx as usize % 24]; let (ui_key_pitch, note_pitch) =
self.lkup_tbl[note_idx as usize % 24];
self.last_key = ui_key_pitch;
note_pitch + octave as f32 * 0.1 note_pitch + octave as f32 * 0.1
} }
} }
@ -2240,7 +2251,7 @@ impl CtrlPitchQuantizer {
keys: vec![0.0; 12 * 10], keys: vec![0.0; 12 * 10],
used_keys: [0.0; 12], used_keys: [0.0; 12],
mask_key_count: 0, mask_key_count: 0,
input_params: 0, input_params: 0xFFFFFFFFFF,
last_key: 0, last_key: 0,
} }
} }
@ -2254,12 +2265,7 @@ impl CtrlPitchQuantizer {
} }
#[inline] #[inline]
pub fn has_no_keys(&self) -> bool { pub fn update_keys(&mut self, mut mask: i64, min_oct: i64, max_oct: i64) {
self.keys.is_empty()
}
#[inline]
pub fn update_keys(&mut self, mask: i64, min_oct: i64, max_oct: i64) {
let inp_params = let inp_params =
(mask as u64) (mask as u64)
| ((min_oct as u64) << 8) | ((min_oct as u64) << 8)
@ -2273,9 +2279,13 @@ impl CtrlPitchQuantizer {
let mut mask_count = 0; let mut mask_count = 0;
// set all keys, if none are set!
if mask == 0x0 { mask = 0xFFFF; }
for i in 0..12 { for i in 0..12 {
if mask & (0x1 << i) > 0 { if mask & (0x1 << i) > 0 {
self.used_keys[mask_count] = (i as f32 / 12.0) * 0.1 - QUANT_TUNE_TO_A4; self.used_keys[mask_count] =
(i as f32 / 12.0) * 0.1 - QUANT_TUNE_TO_A4;
mask_count += 1; mask_count += 1;
} }
} }

View file

@ -744,7 +744,7 @@ macro_rules! node_list {
{7 0 clip setting(0) fa_map_clip 0 1} {7 0 clip setting(0) fa_map_clip 0 1}
[0 sig], [0 sig],
quant => Quant UIType::Generic UICategory::CV quant => Quant UIType::Generic UICategory::CV
(0 freq n_pit d_pit r_fq f_freq stp_d -1.0, 0.5647131, 440.0) (0 freq n_pit d_pit r_id f_freq stp_d -1.0, 0.5647131, 440.0)
(1 oct n_id d_id r_s f_def stp_d -1.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} {2 0 keys setting(0) fa_quant 0 0}
[0 sig], [0 sig],

View file

@ -101,18 +101,6 @@ impl DspNode for CQnt {
self.quant.update_keys(keys.i(), omin.i(), omax.i()); self.quant.update_keys(keys.i(), omin.i(), omax.i());
if self.quant.has_no_keys() {
for frame in 0..ctx.nframes() {
out.write(
frame,
denorm::CQnt::inp(inp, frame)
+ denorm::CQnt::oct(oct, frame));
}
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_key = 0; let mut last_key = 0;
for frame in 0..ctx.nframes() { for frame in 0..ctx.nframes() {
@ -127,4 +115,3 @@ impl DspNode for CQnt {
ctx_vals[0].set((last_pitch * 10.0 - 0.5) * 2.0); ctx_vals[0].set((last_pitch * 10.0 - 0.5) * 2.0);
} }
} }
}

View file

@ -71,15 +71,13 @@ impl DspNode for Quant {
self.quant.set_keys(keys.i()); self.quant.set_keys(keys.i());
// let mut last_key = 0;
for frame in 0..ctx.nframes() { for frame in 0..ctx.nframes() {
let pitch = self.quant.process(freq.read(frame)); let pitch = self.quant.process(freq.read(frame));
out.write(frame, pitch + denorm::Quant::oct(oct, frame)); out.write(frame, pitch + denorm::Quant::oct(oct, frame));
} }
// let last_pitch = self.quant.last_key_pitch(); let last_pitch = self.quant.last_key_pitch();
// ctx_vals[1].set(last_pitch * 10.0 + 0.0001); ctx_vals[1].set(last_pitch * 10.0 + 0.0001);
// ctx_vals[0].set((last_pitch * 10.0 - 0.5) * 2.0); ctx_vals[0].set((last_pitch * 10.0 - 0.5) * 2.0);
} }
} }