From db01caaac0972b063d7a76b00573271787c42254 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Fri, 5 Aug 2022 19:44:40 +0200 Subject: [PATCH] Fix a lot of warnings --- Cargo.toml | 2 +- examples/jack_demo_node_api.rs | 15 --------------- src/block_compiler.rs | 17 ++++++++--------- src/blocklang.rs | 6 ++++-- src/dsp/node_code.rs | 34 ++++++++++++++++++++++++---------- src/nodes/node_conf.rs | 2 -- src/wblockdsp.rs | 6 ++---- tests/node_code.rs | 28 +++++++++++++++++++--------- 8 files changed, 58 insertions(+), 52 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a30420e..35e4260 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ synfx-dsp = "0.5.1" [dev-dependencies] num-complex = "0.2" -jack = "0.6.6" +jack = "0.10.0" rustfft = "6.0.0" cpal = "0.13.5" anyhow = "1.0.58" diff --git a/examples/jack_demo_node_api.rs b/examples/jack_demo_node_api.rs index a41a78c..6c146e4 100644 --- a/examples/jack_demo_node_api.rs +++ b/examples/jack_demo_node_api.rs @@ -147,11 +147,6 @@ impl jack::NotificationHandler for Notifications { println!("JACK: freewheel mode is {}", if is_enabled { "on" } else { "off" }); } - fn buffer_size(&mut self, _: &jack::Client, sz: jack::Frames) -> jack::Control { - println!("JACK: buffer size changed to {}", sz); - jack::Control::Continue - } - fn sample_rate(&mut self, _: &jack::Client, srate: jack::Frames) -> jack::Control { println!("JACK: sample rate changed to {}", srate); let mut ne = self.node_exec.lock().unwrap(); @@ -215,16 +210,6 @@ impl jack::NotificationHandler for Notifications { println!("JACK: xrun occurred"); jack::Control::Continue } - - fn latency(&mut self, _: &jack::Client, mode: jack::LatencyType) { - println!( - "JACK: {} latency has changed", - match mode { - jack::LatencyType::Capture => "capture", - jack::LatencyType::Playback => "playback", - } - ); - } } // This function starts the Jack backend and diff --git a/src/block_compiler.rs b/src/block_compiler.rs index f150f85..44bbe83 100644 --- a/src/block_compiler.rs +++ b/src/block_compiler.rs @@ -193,7 +193,6 @@ pub enum BlkJITCompileError { } pub struct Block2JITCompiler { - id_node_map: HashMap, idout_var_map: HashMap, lang: Rc>, tmpvar_counter: usize, @@ -210,7 +209,7 @@ enum ASTNode { impl Block2JITCompiler { pub fn new(lang: Rc>) -> Self { - Self { id_node_map: HashMap::new(), idout_var_map: HashMap::new(), lang, tmpvar_counter: 0 } + Self { idout_var_map: HashMap::new(), lang, tmpvar_counter: 0 } } pub fn next_tmpvar_name(&mut self, extra: &str) -> String { @@ -226,7 +225,7 @@ impl Block2JITCompiler { self.idout_var_map.get(&format!("{}/{}", id, out)).map(|s| &s[..]) } - pub fn trans2bjit( + fn trans2bjit( &mut self, node: &ASTNodeRef, my_out: Option, @@ -392,7 +391,7 @@ impl Block2JITCompiler { } #[cfg(feature = "synfx-dsp-jit")] - pub fn bjit2jit(&mut self, ast: &BlkASTRef) -> Result, BlkJITCompileError> { + fn bjit2jit(&mut self, ast: &BlkASTRef) -> Result, BlkJITCompileError> { use synfx_dsp_jit::build::*; match &**ast { @@ -407,11 +406,11 @@ impl Block2JITCompiler { let e = self.bjit2jit(&expr)?; Ok(assign(var, e)) } - BlkASTNode::Get { id, var: varname } => Ok(var(varname)), - BlkASTNode::Node { id, out, typ, lbl, childs } => match &typ[..] { + BlkASTNode::Get { var: varname, .. } => Ok(var(varname)), + BlkASTNode::Node { id, typ, childs, .. } => match &typ[..] { "if" => Err(BlkJITCompileError::UnknownError), "zero" => Ok(literal(0.0)), - node => { + _ => { if *id == 0 { return Err(BlkJITCompileError::NodeWithoutID(typ.to_string())); } @@ -426,7 +425,6 @@ impl Block2JITCompiler { } if inputs.len() > 0 && inputs[0] == Some("".to_string()) { - // We assume all inputs are unnamed: if inputs.len() != childs.len() { return Err(BlkJITCompileError::WrongNumberOfChilds( typ.to_string(), @@ -435,7 +433,8 @@ impl Block2JITCompiler { )); } - for (inp, c) in childs.iter() { + // We assume all inputs are unnamed: + for (_inp, c) in childs.iter() { args.push(self.bjit2jit(&c)?); } } else { diff --git a/src/blocklang.rs b/src/blocklang.rs index cb600e4..61e5c8e 100644 --- a/src/blocklang.rs +++ b/src/blocklang.rs @@ -197,11 +197,10 @@ impl Block { let c0 = if let Some(c) = self.contains.0 { c.into() } else { Value::Null }; let c1 = if let Some(c) = self.contains.1 { c.into() } else { Value::Null }; - let mut contains = json!([c0, c1]); json!({ "id": self.id as i64, "rows": self.rows as i64, - "contains": contains, + "contains": json!([c0, c1]), "expanded": self.expanded, "typ": self.typ, "lbl": self.lbl, @@ -343,12 +342,15 @@ impl BlockView for Block { #[derive(Debug)] pub struct BlockChain { /// The area ID this BlockChain was created from. + #[allow(dead_code)] area_id: usize, /// Stores the positions of the blocks of the chain inside the [BlockArea]. blocks: HashSet<(i64, i64)>, /// Stores the positions of blocks that only have output ports. + #[allow(dead_code)] sources: HashSet<(i64, i64)>, /// Stores the positions of blocks that only have input ports. + #[allow(dead_code)] sinks: HashSet<(i64, i64)>, /// This field stores _loaded_ blocks from the [BlockArea] /// into this [BlockChain] for inserting or analyzing them. diff --git a/src/dsp/node_code.rs b/src/dsp/node_code.rs index 6685897..2835211 100644 --- a/src/dsp/node_code.rs +++ b/src/dsp/node_code.rs @@ -7,7 +7,7 @@ use crate::nodes::{NodeAudioContext, NodeExecContext}; #[cfg(feature = "synfx-dsp-jit")] use crate::wblockdsp::CodeEngineBackend; -use crate::dsp::MAX_BLOCK_SIZE; +//use crate::dsp::MAX_BLOCK_SIZE; /// A WBlockDSP code execution node for JIT'ed DSP code pub struct Code { @@ -87,17 +87,20 @@ impl DspNode for Code { ctx: &mut T, _ectx: &mut NodeExecContext, _nctx: &NodeContext, - atoms: &[SAtom], + _atoms: &[SAtom], inputs: &[ProcBuf], outputs: &mut [ProcBuf], ctx_vals: LedPhaseVals, ) { - use crate::dsp::{at, denorm, inp, out, out_idx}; -// let clock = inp::TSeq::clock(inputs); -// let trig = inp::TSeq::trig(inputs); -// let cmode = at::TSeq::cmode(atoms); - let out = out::Code::sig(outputs); + use crate::dsp::{inp, out_idx}; + let in1 = inp::Code::in1(inputs); + let in2 = inp::Code::in2(inputs); + let a = inp::Code::alpha(inputs); + let b = inp::Code::beta(inputs); + let d = inp::Code::delta(inputs); + let g = inp::Code::gamma(inputs); let out_i = out_idx::Code::sig1(); + let (sig, sig1) = outputs.split_at_mut(out_i); let (sig1, sig2) = sig1.split_at_mut(1); let sig = &mut sig[0]; @@ -114,15 +117,26 @@ impl DspNode for Code { backend.process_updates(); + let mut ret = 0.0; + let mut s1 = 0.0; + #[allow(unused_assignments)] + let mut s2 = 0.0; for frame in 0..ctx.nframes() { - let (s1, s2, ret) = backend.process(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + (s1, s2, ret) = backend.process( + in1.read(frame), + in2.read(frame), + a.read(frame), + b.read(frame), + d.read(frame), + g.read(frame), + ); sig.write(frame, ret); sig1.write(frame, s1); sig2.write(frame, s2); } - ctx_vals[0].set(0.0); - ctx_vals[1].set(0.0); + ctx_vals[0].set(ret); + ctx_vals[1].set(s1); } } } diff --git a/src/nodes/node_conf.rs b/src/nodes/node_conf.rs index 266693d..a0c63bc 100644 --- a/src/nodes/node_conf.rs +++ b/src/nodes/node_conf.rs @@ -713,9 +713,7 @@ impl NodeConfigurator { let mut compiler = Block2JITCompiler::new(block_fun.block_language()); let ast = compiler.compile(&block_fun)?; - // let ast = block_compiler::compile(block_fun); if let Some(cod) = self.code_engines.get_mut(id) { - use synfx_dsp_jit::build::*; match cod.upload(ast) { Err(e) => return Err(BlkJITCompileError::JITCompileError(e)), Ok(()) => (), diff --git a/src/wblockdsp.rs b/src/wblockdsp.rs index 60b9b86..e056a02 100644 --- a/src/wblockdsp.rs +++ b/src/wblockdsp.rs @@ -6,11 +6,9 @@ use synfx_dsp_jit::*; use ringbuf::{Consumer, Producer, RingBuffer}; use std::cell::RefCell; -use std::collections::HashMap; use std::rc::Rc; const MAX_RINGBUF_SIZE: usize = 128; -const MAX_CONTEXTS: usize = 32; enum CodeUpdateMsg { UpdateFun(Box), @@ -52,7 +50,7 @@ impl CodeEngine { pub fn upload(&mut self, ast: Box) -> Result<(), JITCompileError> { let jit = JIT::new(self.lib.clone(), self.dsp_ctx.clone()); let fun = jit.compile(ASTFun::new(ast))?; - self.update_prod.push(CodeUpdateMsg::UpdateFun(fun)); + let _ = self.update_prod.push(CodeUpdateMsg::UpdateFun(fun)); Ok(()) } @@ -146,7 +144,7 @@ impl CodeEngineBackend { CodeUpdateMsg::UpdateFun(mut fun) => { std::mem::swap(&mut self.function, &mut fun); self.function.init(self.sample_rate as f64, Some(&fun)); - self.return_prod.push(CodeReturnMsg::DestroyFun(fun)); + let _ = self.return_prod.push(CodeReturnMsg::DestroyFun(fun)); } } } diff --git a/tests/node_code.rs b/tests/node_code.rs index b5f1c83..69fcf39 100644 --- a/tests/node_code.rs +++ b/tests/node_code.rs @@ -5,6 +5,8 @@ mod common; use common::*; +use hexodsp::blocklang::BlockFun; + fn setup() -> (Matrix, NodeExecutor) { let (node_conf, node_exec) = new_node_engine(); let mut matrix = Matrix::new(node_conf, 3, 3); @@ -22,6 +24,14 @@ fn setup() -> (Matrix, NodeExecutor) { (matrix, node_exec) } +fn put_n(bf: &mut BlockFun, a: usize, x: i64, y: i64, s: &str) { + bf.instanciate_at(a, x, y, s, None).expect("no put error"); +} + +fn put_v(bf: &mut BlockFun, a: usize, x: i64, y: i64, s: &str, v: &str) { + bf.instanciate_at(a, x, y, s, Some(v.to_string())).expect("no put error"); +} + #[test] fn check_node_code_1() { let (mut matrix, mut node_exec) = setup(); @@ -29,8 +39,8 @@ fn check_node_code_1() { let block_fun = matrix.get_block_function(0).expect("block fun exists"); { let mut block_fun = block_fun.lock().expect("matrix lock"); - block_fun.instanciate_at(0, 0, 1, "value", Some("0.3".to_string())); - block_fun.instanciate_at(0, 1, 1, "set", Some("&sig1".to_string())); + put_v(&mut block_fun, 0, 0, 1, "value", "0.3"); + put_v(&mut block_fun, 0, 1, 1, "set", "&sig1"); } matrix.check_block_function(0).expect("no compile error"); @@ -46,13 +56,13 @@ fn check_node_code_state() { let block_fun = matrix.get_block_function(0).expect("block fun exists"); { let mut block_fun = block_fun.lock().expect("matrix lock"); - block_fun.instanciate_at(0, 0, 2, "value", Some("220.0".to_string())); - block_fun.instanciate_at(0, 1, 2, "phase", None); - block_fun.instanciate_at(0, 1, 3, "value", Some("2.0".to_string())); - block_fun.instanciate_at(0, 2, 2, "*", None); - block_fun.instanciate_at(0, 3, 1, "-", None); - block_fun.instanciate_at(0, 2, 1, "value", Some("1.0".to_string())); - block_fun.instanciate_at(0, 4, 1, "set", Some("&sig1".to_string())); + put_v(&mut block_fun, 0, 0, 2, "value", "220.0"); + put_n(&mut block_fun, 0, 1, 2, "phase"); + put_v(&mut block_fun, 0, 1, 3, "value", "2.0"); + put_n(&mut block_fun, 0, 2, 2, "*"); + put_n(&mut block_fun, 0, 3, 1, "-"); + put_v(&mut block_fun, 0, 2, 1, "value", "1.0"); + put_v(&mut block_fun, 0, 4, 1, "set", "&sig1"); } matrix.check_block_function(0).expect("no compile error");