From e9e84df70832b044332bd14787e5300425e3de25 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Mon, 7 Jun 2021 05:06:04 +0200 Subject: [PATCH] fix some clippy warnings --- src/cell_dir.rs | 4 +- src/dsp/helpers.rs | 13 +++--- src/dsp/node_sampl.rs | 2 + src/matrix.rs | 2 +- src/monitor.rs | 6 +++ src/nodes/node_conf.rs | 71 +++++++++++++++----------------- src/nodes/node_exec.rs | 16 ++++--- src/nodes/node_graph_ordering.rs | 4 ++ src/nodes/node_prog.rs | 6 +-- src/sample_lib.rs | 7 +++- 10 files changed, 71 insertions(+), 60 deletions(-) diff --git a/src/cell_dir.rs b/src/cell_dir.rs index 7b27883..350fd73 100644 --- a/src/cell_dir.rs +++ b/src/cell_dir.rs @@ -43,7 +43,7 @@ impl CellDir { *self as u8 } - pub fn to_menu_pos(&self) -> (i32, i32) { + pub fn as_menu_pos(&self) -> (i32, i32) { match self { // out 1 - TR CellDir::TR => (0, 1), @@ -61,7 +61,7 @@ impl CellDir { } } - pub fn to_offs(&self, x: usize) -> (i32, i32) { + pub fn as_offs(&self, x: usize) -> (i32, i32) { let even = x % 2 == 0; match self { // out 1 - TR diff --git a/src/dsp/helpers.rs b/src/dsp/helpers.rs index e587d29..9662431 100644 --- a/src/dsp/helpers.rs +++ b/src/dsp/helpers.rs @@ -369,14 +369,15 @@ impl Trigger { if input <= 0.25 { self.triggered = false; } + false + + } else if input > 0.75 { + self.triggered = true; + true + } else { - if input > 0.75 { - self.triggered = true; - true - } else { - false - } + false } } } diff --git a/src/dsp/node_sampl.rs b/src/dsp/node_sampl.rs index 6950522..4336838 100644 --- a/src/dsp/node_sampl.rs +++ b/src/dsp/node_sampl.rs @@ -95,6 +95,7 @@ impl Sampl { } impl Sampl { + #[allow(clippy::many_single_char_names)] #[inline] fn next_sample(&mut self, sr_factor: f64, speed: f64, sample_data: &[f32]) -> f32 { let sd_len = sample_data.len(); @@ -129,6 +130,7 @@ impl Sampl { (((a * f) - b_neg) * f + c) * f + x0 } + #[allow(clippy::float_cmp)] #[inline] fn play(&mut self, inputs: &[ProcBuf], nframes: usize, sample_data: &[f32], out: &mut ProcBuf, do_loop: bool, diff --git a/src/matrix.rs b/src/matrix.rs index f9924af..74efe8c 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -631,7 +631,7 @@ impl Matrix { } pub fn get_adjacent(&self, x: usize, y: usize, dir: CellDir) -> Option<&Cell> { - let offs : (i32, i32) = dir.to_offs(x); + let offs : (i32, i32) = dir.as_offs(x); let x = x as i32 + offs.0; let y = y as i32 + offs.1; diff --git a/src/monitor.rs b/src/monitor.rs index faddafd..1290998 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -183,6 +183,12 @@ impl MinMaxMonitorSamples { } pub fn len(&self) -> usize { MONITOR_MINMAX_SAMPLES } + + pub fn is_empty(&self) -> bool { false } +} + +impl Default for MinMaxMonitorSamples { + fn default() -> Self { Self::new() } } impl std::ops::Index for MinMaxMonitorSamples { diff --git a/src/nodes/node_conf.rs b/src/nodes/node_conf.rs index 910d1c3..6965a48 100644 --- a/src/nodes/node_conf.rs +++ b/src/nodes/node_conf.rs @@ -60,7 +60,7 @@ impl NodeInstance { pub fn mark_used(&mut self) { self.in_use = true; } pub fn is_used(&self) -> bool { self.in_use } - pub fn to_op(&self) -> NodeOp { + pub fn as_op(&self) -> NodeOp { NodeOp { idx: self.prog_idx as u8, out_idxlen: (self.out_start, self.out_end), @@ -308,7 +308,7 @@ impl NodeConfigurator { if param.is_atom() { let at = if let SAtom::AudioSample((path, None)) = at.clone() { - if path.len() > 0 { + if !path.is_empty() { match self.sample_lib.load(&path) { Ok(sample) => sample.clone(), Err(e) => { @@ -354,6 +354,7 @@ impl NodeConfigurator { /// Dumps all set parameters (inputs and atoms). /// Most useful for serialization and saving patches. + #[allow(clippy::type_complexity)] pub fn dump_param_values(&self) -> (Vec<(ParamId, f32)>, Vec<(ParamId, SAtom)>) { @@ -516,38 +517,35 @@ impl NodeConfigurator { { let mut bufs = [UNUSED_MONITOR_IDX; MON_SIG_CNT]; - if let Some((_node_info, node_instance)) = self.node_by_id(node_id) { - if let Some(node_instance) = node_instance { - - let mut i = 0; - for inp_idx in inputs.iter().take(MON_SIG_CNT / 2) { - if let Some(inp_idx) = inp_idx { - if let Some(global_idx) - = node_instance.in_local2global(*inp_idx) - { - bufs[i] = global_idx; - } + if let Some((_node_info, Some(node_instance))) = self.node_by_id(node_id) { + let mut i = 0; + for inp_idx in inputs.iter().take(MON_SIG_CNT / 2) { + if let Some(inp_idx) = inp_idx { + if let Some(global_idx) + = node_instance.in_local2global(*inp_idx) + { + bufs[i] = global_idx; } - - i += 1; } - for out_idx in outputs.iter().take(MON_SIG_CNT / 2) { - if let Some(out_idx) = out_idx { - if let Some(global_idx) - = node_instance.out_local2global(*out_idx) - { - bufs[i] = global_idx; - } - } - - i += 1; - } - - let _ = - self.shared.quick_update_prod.push( - QuickMessage::SetMonitor { bufs }); + i += 1; } + + for out_idx in outputs.iter().take(MON_SIG_CNT / 2) { + if let Some(out_idx) = out_idx { + if let Some(global_idx) + = node_instance.out_local2global(*out_idx) + { + bufs[i] = global_idx; + } + } + + i += 1; + } + + let _ = + self.shared.quick_update_prod.push( + QuickMessage::SetMonitor { bufs }); } } @@ -773,7 +771,7 @@ impl NodeConfigurator { = self.node_by_id_mut(node_id) { node_instance.mark_used(); - let op = node_instance.to_op(); + let op = node_instance.as_op(); prog.append_op(op); } } @@ -805,14 +803,13 @@ impl NodeConfigurator { = self.node_by_id_mut(&node_input.0) { node_instance.mark_used(); - let op = node_instance.to_op(); + let op = node_instance.as_op(); let input_index = node_instance.in_local2global(node_input.1); - match (input_index, output_index) { - (Some(input_index), Some(output_index)) => { - prog.append_edge(op, input_index, output_index); - }, - _ => {}, + if let (Some(input_index), Some(output_index)) = + (input_index, output_index) + { + prog.append_edge(op, input_index, output_index); } } } diff --git a/src/nodes/node_exec.rs b/src/nodes/node_exec.rs index ae69c8f..76bb049 100644 --- a/src/nodes/node_exec.rs +++ b/src/nodes/node_exec.rs @@ -149,14 +149,17 @@ impl FeedbackBuffer { if self.sample_count > 0 { self.sample_count -= 1; self.read_ptr = (self.read_ptr + 1) % MAX_FB_DELAY_SIZE; - let s = self.buffer[self.read_ptr]; - s + self.buffer[self.read_ptr] } else { 0.0 } } } +impl Default for FeedbackBuffer { + fn default() -> Self { Self::new() } +} + /// Contains global state that all nodes can access. /// This is used for instance to implement the feedbackd delay nodes. pub struct NodeExecContext { @@ -166,7 +169,7 @@ pub struct NodeExecContext { impl NodeExecContext { fn new() -> Self { let mut fbdb = vec![]; - fbdb.resize_with(MAX_ALLOCATED_NODES, || FeedbackBuffer::new()); + fbdb.resize_with(MAX_ALLOCATED_NODES, FeedbackBuffer::new); Self { feedback_delay_buffers: fbdb, } @@ -346,12 +349,7 @@ impl NodeExecutor { } // Find unused smoother and set it: - if let Some(sm) = - self.smoothers - .iter_mut() - .filter(|s| s.1.is_done()) - .next() - { + if let Some(sm) = self.smoothers.iter_mut().find(|s| s.1.is_done()) { sm.0 = input_idx; sm.1.set(prog.params[input_idx], value); //d// println!("SET SMOOTHER {} {:6.3} (old = {:6.3})", diff --git a/src/nodes/node_graph_ordering.rs b/src/nodes/node_graph_ordering.rs index 4d10a99..1a9dd89 100644 --- a/src/nodes/node_graph_ordering.rs +++ b/src/nodes/node_graph_ordering.rs @@ -184,6 +184,10 @@ impl NodeGraphOrdering { } } +impl Default for NodeGraphOrdering { + fn default() -> Self { Self::new() } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/nodes/node_prog.rs b/src/nodes/node_prog.rs index f4c4631..c4eef3b 100644 --- a/src/nodes/node_prog.rs +++ b/src/nodes/node_prog.rs @@ -115,16 +115,16 @@ impl NodeProg { pub fn new(out_len: usize, inp_len: usize, at_len: usize) -> Self { let mut out = vec![]; - out.resize_with(out_len, || ProcBuf::new()); + out.resize_with(out_len, ProcBuf::new); let out_fb = vec![0.0; out_len]; let tb = TripleBuffer::new(out_fb); let (input_fb, output_fb) = tb.split(); let mut inp = vec![]; - inp.resize_with(inp_len, || ProcBuf::new()); + inp.resize_with(inp_len, ProcBuf::new); let mut cur_inp = vec![]; - cur_inp.resize_with(inp_len, || ProcBuf::null()); + cur_inp.resize_with(inp_len, ProcBuf::null); let mut params = vec![]; params.resize(inp_len, 0.0); diff --git a/src/sample_lib.rs b/src/sample_lib.rs index c5d603b..6ecdbdb 100644 --- a/src/sample_lib.rs +++ b/src/sample_lib.rs @@ -53,8 +53,7 @@ impl SampleLibrary { let channels = rd.spec().channels as usize; - let mut v = vec![]; - v.push(rd.spec().sample_rate as f32); + let mut v = vec![rd.spec().sample_rate as f32]; match rd.spec().sample_format { hound::SampleFormat::Float => { @@ -78,6 +77,10 @@ impl SampleLibrary { } } +impl Default for SampleLibrary { + fn default() -> Self { Self::new() } +} + #[cfg(test)] mod tests { use super::*;