fix some clippy warnings

This commit is contained in:
Weird Constructor 2021-06-07 05:06:04 +02:00
parent a846242218
commit e9e84df708
10 changed files with 71 additions and 60 deletions

View file

@ -43,7 +43,7 @@ impl CellDir {
*self as u8 *self as u8
} }
pub fn to_menu_pos(&self) -> (i32, i32) { pub fn as_menu_pos(&self) -> (i32, i32) {
match self { match self {
// out 1 - TR // out 1 - TR
CellDir::TR => (0, 1), 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; let even = x % 2 == 0;
match self { match self {
// out 1 - TR // out 1 - TR

View file

@ -369,16 +369,17 @@ impl Trigger {
if input <= 0.25 { if input <= 0.25 {
self.triggered = false; self.triggered = false;
} }
false false
} else {
if input > 0.75 { } else if input > 0.75 {
self.triggered = true; self.triggered = true;
true true
} else { } else {
false false
} }
} }
}
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]

View file

@ -95,6 +95,7 @@ impl Sampl {
} }
impl Sampl { impl Sampl {
#[allow(clippy::many_single_char_names)]
#[inline] #[inline]
fn next_sample(&mut self, sr_factor: f64, speed: f64, sample_data: &[f32]) -> f32 { fn next_sample(&mut self, sr_factor: f64, speed: f64, sample_data: &[f32]) -> f32 {
let sd_len = sample_data.len(); let sd_len = sample_data.len();
@ -129,6 +130,7 @@ impl Sampl {
(((a * f) - b_neg) * f + c) * f + x0 (((a * f) - b_neg) * f + c) * f + x0
} }
#[allow(clippy::float_cmp)]
#[inline] #[inline]
fn play(&mut self, inputs: &[ProcBuf], nframes: usize, fn play(&mut self, inputs: &[ProcBuf], nframes: usize,
sample_data: &[f32], out: &mut ProcBuf, do_loop: bool, sample_data: &[f32], out: &mut ProcBuf, do_loop: bool,

View file

@ -631,7 +631,7 @@ impl Matrix {
} }
pub fn get_adjacent(&self, x: usize, y: usize, dir: CellDir) -> Option<&Cell> { 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 x = x as i32 + offs.0;
let y = y as i32 + offs.1; let y = y as i32 + offs.1;

View file

@ -183,6 +183,12 @@ impl MinMaxMonitorSamples {
} }
pub fn len(&self) -> usize { MONITOR_MINMAX_SAMPLES } 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<usize> for MinMaxMonitorSamples { impl std::ops::Index<usize> for MinMaxMonitorSamples {

View file

@ -60,7 +60,7 @@ impl NodeInstance {
pub fn mark_used(&mut self) { self.in_use = true; } pub fn mark_used(&mut self) { self.in_use = true; }
pub fn is_used(&self) -> bool { self.in_use } pub fn is_used(&self) -> bool { self.in_use }
pub fn to_op(&self) -> NodeOp { pub fn as_op(&self) -> NodeOp {
NodeOp { NodeOp {
idx: self.prog_idx as u8, idx: self.prog_idx as u8,
out_idxlen: (self.out_start, self.out_end), out_idxlen: (self.out_start, self.out_end),
@ -308,7 +308,7 @@ impl NodeConfigurator {
if param.is_atom() { if param.is_atom() {
let at = let at =
if let SAtom::AudioSample((path, None)) = at.clone() { if let SAtom::AudioSample((path, None)) = at.clone() {
if path.len() > 0 { if !path.is_empty() {
match self.sample_lib.load(&path) { match self.sample_lib.load(&path) {
Ok(sample) => sample.clone(), Ok(sample) => sample.clone(),
Err(e) => { Err(e) => {
@ -354,6 +354,7 @@ impl NodeConfigurator {
/// Dumps all set parameters (inputs and atoms). /// Dumps all set parameters (inputs and atoms).
/// Most useful for serialization and saving patches. /// Most useful for serialization and saving patches.
#[allow(clippy::type_complexity)]
pub fn dump_param_values(&self) pub fn dump_param_values(&self)
-> (Vec<(ParamId, f32)>, Vec<(ParamId, SAtom)>) -> (Vec<(ParamId, f32)>, Vec<(ParamId, SAtom)>)
{ {
@ -516,9 +517,7 @@ impl NodeConfigurator {
{ {
let mut bufs = [UNUSED_MONITOR_IDX; MON_SIG_CNT]; 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_info, Some(node_instance))) = self.node_by_id(node_id) {
if let Some(node_instance) = node_instance {
let mut i = 0; let mut i = 0;
for inp_idx in inputs.iter().take(MON_SIG_CNT / 2) { for inp_idx in inputs.iter().take(MON_SIG_CNT / 2) {
if let Some(inp_idx) = inp_idx { if let Some(inp_idx) = inp_idx {
@ -549,7 +548,6 @@ impl NodeConfigurator {
QuickMessage::SetMonitor { bufs }); QuickMessage::SetMonitor { bufs });
} }
} }
}
pub fn get_pattern_data(&self, tracker_id: usize) pub fn get_pattern_data(&self, tracker_id: usize)
-> Option<Rc<RefCell<PatternData>>> -> Option<Rc<RefCell<PatternData>>>
@ -773,7 +771,7 @@ impl NodeConfigurator {
= self.node_by_id_mut(node_id) = self.node_by_id_mut(node_id)
{ {
node_instance.mark_used(); node_instance.mark_used();
let op = node_instance.to_op(); let op = node_instance.as_op();
prog.append_op(op); prog.append_op(op);
} }
} }
@ -805,14 +803,13 @@ impl NodeConfigurator {
= self.node_by_id_mut(&node_input.0) = self.node_by_id_mut(&node_input.0)
{ {
node_instance.mark_used(); 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); let input_index = node_instance.in_local2global(node_input.1);
match (input_index, output_index) { if let (Some(input_index), Some(output_index)) =
(Some(input_index), Some(output_index)) => { (input_index, output_index)
{
prog.append_edge(op, input_index, output_index); prog.append_edge(op, input_index, output_index);
},
_ => {},
} }
} }
} }

View file

@ -149,14 +149,17 @@ impl FeedbackBuffer {
if self.sample_count > 0 { if self.sample_count > 0 {
self.sample_count -= 1; self.sample_count -= 1;
self.read_ptr = (self.read_ptr + 1) % MAX_FB_DELAY_SIZE; self.read_ptr = (self.read_ptr + 1) % MAX_FB_DELAY_SIZE;
let s = self.buffer[self.read_ptr]; self.buffer[self.read_ptr]
s
} else { } else {
0.0 0.0
} }
} }
} }
impl Default for FeedbackBuffer {
fn default() -> Self { Self::new() }
}
/// Contains global state that all nodes can access. /// Contains global state that all nodes can access.
/// This is used for instance to implement the feedbackd delay nodes. /// This is used for instance to implement the feedbackd delay nodes.
pub struct NodeExecContext { pub struct NodeExecContext {
@ -166,7 +169,7 @@ pub struct NodeExecContext {
impl NodeExecContext { impl NodeExecContext {
fn new() -> Self { fn new() -> Self {
let mut fbdb = vec![]; let mut fbdb = vec![];
fbdb.resize_with(MAX_ALLOCATED_NODES, || FeedbackBuffer::new()); fbdb.resize_with(MAX_ALLOCATED_NODES, FeedbackBuffer::new);
Self { Self {
feedback_delay_buffers: fbdb, feedback_delay_buffers: fbdb,
} }
@ -346,12 +349,7 @@ impl NodeExecutor {
} }
// Find unused smoother and set it: // Find unused smoother and set it:
if let Some(sm) = if let Some(sm) = self.smoothers.iter_mut().find(|s| s.1.is_done()) {
self.smoothers
.iter_mut()
.filter(|s| s.1.is_done())
.next()
{
sm.0 = input_idx; sm.0 = input_idx;
sm.1.set(prog.params[input_idx], value); sm.1.set(prog.params[input_idx], value);
//d// println!("SET SMOOTHER {} {:6.3} (old = {:6.3})", //d// println!("SET SMOOTHER {} {:6.3} (old = {:6.3})",

View file

@ -184,6 +184,10 @@ impl NodeGraphOrdering {
} }
} }
impl Default for NodeGraphOrdering {
fn default() -> Self { Self::new() }
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -115,16 +115,16 @@ impl NodeProg {
pub fn new(out_len: usize, inp_len: usize, at_len: usize) -> Self { pub fn new(out_len: usize, inp_len: usize, at_len: usize) -> Self {
let mut out = vec![]; 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 out_fb = vec![0.0; out_len];
let tb = TripleBuffer::new(out_fb); let tb = TripleBuffer::new(out_fb);
let (input_fb, output_fb) = tb.split(); let (input_fb, output_fb) = tb.split();
let mut inp = vec![]; let mut inp = vec![];
inp.resize_with(inp_len, || ProcBuf::new()); inp.resize_with(inp_len, ProcBuf::new);
let mut cur_inp = vec![]; 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![]; let mut params = vec![];
params.resize(inp_len, 0.0); params.resize(inp_len, 0.0);

View file

@ -53,8 +53,7 @@ impl SampleLibrary {
let channels = rd.spec().channels as usize; let channels = rd.spec().channels as usize;
let mut v = vec![]; let mut v = vec![rd.spec().sample_rate as f32];
v.push(rd.spec().sample_rate as f32);
match rd.spec().sample_format { match rd.spec().sample_format {
hound::SampleFormat::Float => { hound::SampleFormat::Float => {
@ -78,6 +77,10 @@ impl SampleLibrary {
} }
} }
impl Default for SampleLibrary {
fn default() -> Self { Self::new() }
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;