From e423ca22a35796f680cdf319ad10ce4cf9f91414 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sat, 10 Jul 2021 10:16:23 +0200 Subject: [PATCH] fixes and debug logging --- src/nodes/node_conf.rs | 8 +++++-- src/nodes/node_exec.rs | 53 ++++++++++++++---------------------------- src/nodes/node_prog.rs | 15 ++++++++---- 3 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/nodes/node_conf.rs b/src/nodes/node_conf.rs index 1db8578..686c197 100644 --- a/src/nodes/node_conf.rs +++ b/src/nodes/node_conf.rs @@ -354,15 +354,18 @@ impl NodeConfigurator { if let Some(modamt) = &mut nparam.modamt { mod_idx = Some(modamt.0); modamt.1 = v.unwrap_or(0.0); + println!("SET NPARAM MOD AMT {:?} {:?} {}", param, mod_idx, modamt.1); } } - // Check if the modulation amount was already set, if not, we need - // to reconstruct the graph and upload an updated NodeProg. + + // Check if the modulation amount was already set, if not, the caller + // needs to reconstruct the graph and upload an updated NodeProg. if let Some(_old_modamt) = self.param_modamt.get(¶m).copied().flatten() { if v.is_none() { + println!("SET NEW NONE MOD AMT {:?}", param); self.param_modamt.insert(param, v); true @@ -371,6 +374,7 @@ impl NodeConfigurator { self.param_modamt.insert(param, v); if let Some(mod_idx) = mod_idx { + println!("SET UPD MOD AMT {:?} {:?} {:?}", param, mod_idx, modamt); let _ = self.shared.quick_update_prod.push( QuickMessage::ModamtUpdate { mod_idx, modamt }); diff --git a/src/nodes/node_exec.rs b/src/nodes/node_exec.rs index 646f111..dc30cd3 100644 --- a/src/nodes/node_exec.rs +++ b/src/nodes/node_exec.rs @@ -318,6 +318,13 @@ impl NodeExecutor { #[inline] pub fn get_prog(&self) -> &NodeProg { &self.prog } + #[inline] + fn set_modamt(&mut self, mod_idx: usize, modamt: f32) { + if mod_idx < self.prog.modops.len() { + self.prog.modops[mod_idx].set_amt(modamt); + } + } + #[inline] fn set_param(&mut self, input_idx: usize, value: f32) { let prog = &mut self.prog; @@ -398,10 +405,8 @@ impl NodeExecutor { QuickMessage::ParamUpdate { input_idx, value } => { self.set_param(input_idx, value); }, - // TODO: MODAMT - // QuickMessage::ModamtUpdate { input_idx, modamt } => { - QuickMessage::ModamtUpdate { .. } => { - // assign to NodeProg + QuickMessage::ModamtUpdate { mod_idx, modamt } => { + self.set_modamt(mod_idx, modamt); }, QuickMessage::SetMonitor { bufs } => { self.monitor_signal_cur_inp_indices = bufs; @@ -425,41 +430,19 @@ impl NodeExecutor { let prog_out_fb = prog.out_feedback.input_buffer(); - for op in prog.prog.iter() { - let out = op.out_idxlen; - let inp = op.in_idxlen; - let at = op.at_idxlen; + let nframes = ctx.nframes(); + for op in prog.prog.iter() { + let out = op.out_idxlen; + let inp = op.in_idxlen; + let at = op.at_idxlen; + let md = op.mod_idxlen; let ctx_idx = op.idx as usize * 2; - /* MOD AMOUNT APPLYING PSEUDO CODE: - - for (amt, range, modbuf, outbuf, inpbuf) in - prog.mod[mod.0..mod.1].iter() - { - match range { - ModRange::Bipol => { - for frame in 0..ctx.nframes() { - modbuf.write(frame, - modbuf.read(frame) - * ((outbuf.read(frame) + 1.0) * 0.5) - .clamp(0.0, 1.0) - + inpbuf.read(frame)); - } - }, - ModRange::Unipol => { - for frame in 0..ctx.nframes() { - modbuf.write(frame, - modbuf.read(frame) - * outbuf.read(frame).clamp(0.0, 1.0) - + inpbuf.read(frame)); - } - }, - } + for modop in prog.modops[md.0..md.1].iter_mut() { + modop.process(nframes); } - */ - nodes[op.idx as usize] .process( ctx, @@ -470,7 +453,7 @@ impl NodeExecutor { &mut prog.out[out.0..out.1], &ctx_vals[ctx_idx..ctx_idx + 2]); - let last_frame_idx = ctx.nframes() - 1; + let last_frame_idx = nframes - 1; for (pb, out_buf_idx) in prog.out[out.0..out.1].iter() .zip(out.0..out.1) diff --git a/src/nodes/node_prog.rs b/src/nodes/node_prog.rs index 578e064..aeb9f5c 100644 --- a/src/nodes/node_prog.rs +++ b/src/nodes/node_prog.rs @@ -33,9 +33,11 @@ impl ModOp { self.amount = amt; } - pub fn lock(&mut self, inbuf: ProcBuf, outbuf: ProcBuf) { + pub fn lock(&mut self, inbuf: ProcBuf, outbuf: ProcBuf) -> ProcBuf { + println!("LOCK MA {}", self.amount); self.inbuf = inbuf; self.outbuf = outbuf; + self.modbuf } pub fn unlock(&mut self) { @@ -49,11 +51,12 @@ impl ModOp { let inbuf = &mut self.inbuf; let outbuf = &mut self.outbuf; + println!("PROCMA {}", self.amount); + for frame in 0..nframes { modbuf.write(frame, - modbuf.read(frame) - * outbuf.read(frame) - + inbuf.read(frame)); + inbuf.read(frame) + + (self.amount * outbuf.read(frame))); } } } @@ -299,6 +302,7 @@ impl NodeProg { pub fn assign_outputs(&mut self) { for op in self.prog.iter() { + println!("ASSIGN OUTPUTS: {}", op); // First step is copying the ProcBufs to the `cur_inp` current // input buffer vector. It holds the data for smoothed paramter // inputs or just constant values since the last smoothing. @@ -328,7 +332,8 @@ impl NodeProg { input_bufs[io.1] = out_bufs[io.0]; if let Some(idx) = io.2 { - self.modops[idx].lock(self.inp[io.1], out_bufs[io.0]); + input_bufs[io.1] = + self.modops[idx].lock(self.inp[io.1], out_bufs[io.0]); } } }