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
}
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

View file

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

View file

@ -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,

View file

@ -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;

View file

@ -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<usize> for MinMaxMonitorSamples {

View file

@ -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,9 +517,7 @@ 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 {
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 {
@ -549,7 +548,6 @@ impl NodeConfigurator {
QuickMessage::SetMonitor { bufs });
}
}
}
pub fn get_pattern_data(&self, tracker_id: usize)
-> Option<Rc<RefCell<PatternData>>>
@ -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)) => {
if let (Some(input_index), Some(output_index)) =
(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 {
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})",

View file

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

View file

@ -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);

View file

@ -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::*;