Browse Source

Apply more clippy lints

master^2
Andreas Linz 2 years ago
parent
commit
4e938e364f
Signed by: alinz GPG Key ID: 9BF39809C9DA580C
7 changed files with 33 additions and 41 deletions
  1. +2
    -2
      src/dsp/env_gen.rs
  2. +14
    -16
      src/dsp/filter.rs
  3. +4
    -4
      src/dsp/voice.rs
  4. +5
    -6
      src/dsp/wavetable.rs
  5. +4
    -4
      src/io/midi.rs
  6. +1
    -1
      src/io/osc.rs
  7. +3
    -8
      src/main.rs

+ 2
- 2
src/dsp/env_gen.rs View File

@ -12,8 +12,8 @@ pub enum ADSRState {
Off,
}
impl ADSRState {
fn progress(&self) -> ADSRState {
match *self {
fn progress(self) -> ADSRState {
match self {
ADSRState::Attack => ADSRState::Decay,
ADSRState::Decay => ADSRState::Sustain,
ADSRState::Sustain => ADSRState::Release,

+ 14
- 16
src/dsp/filter.rs View File

@ -107,23 +107,21 @@ impl ControllableLink for Filter {
out
}
fn handle(&mut self, msg: &ControlEvent) {
match *msg {
ControlEvent::Filter {
filter_type,
freq,
q,
} => {
if let Some(some_type) = filter_type {
self.set_filter_type(some_type)
}
if let Some(some_freq) = freq {
self.set_freq(some_freq);
}
if let Some(some_q) = q {
self.set_q(some_q)
}
if let ControlEvent::Filter {
filter_type,
freq,
q,
} = *msg
{
if let Some(some_type) = filter_type {
self.set_filter_type(some_type)
}
if let Some(some_freq) = freq {
self.set_freq(some_freq);
}
if let Some(some_q) = q {
self.set_q(some_q)
}
_ => {}
}
}
}

+ 4
- 4
src/dsp/voice.rs View File

@ -25,8 +25,8 @@ pub struct Voice {
impl Voice {
fn new(
sample_rate: usize,
wavetables: Rc<HashMap<Waveform, Vec<Wavetable>>>,
pitch_convert_handle: Rc<PitchConvert>,
wavetables: &Rc<HashMap<Waveform, Vec<Wavetable>>>,
pitch_convert_handle: &Rc<PitchConvert>,
) -> Self {
let mut levels = Vec::with_capacity(OSC_CNT);
let mut oscillators = Vec::with_capacity(OSC_CNT);
@ -156,8 +156,8 @@ impl VoiceManager {
for _ in 0..max_voices {
voices.push(Voice::new(
sample_rate,
wavetables.clone(),
pitch_convert.clone(),
&wavetables,
&pitch_convert,
));
}
VoiceManager {

+ 5
- 6
src/dsp/wavetable.rs View File

@ -97,16 +97,15 @@ pub fn generate_wavetables(
if let Ok(file) = File::open(&filename) {
let mut reader = BufReader::new(file);
decode_from(&mut reader, SizeLimit::Infinite)
.expect(&format!("could not decode wavetable: {}", filename))
.unwrap_or_else(|_| panic!("could not decode wavetable: {}", filename))
} else {
let band_limited_table = build_wavetables(*waveform, fundamental_freq, sample_rate);
let file = File::create(&filename).expect(&format!(
"could not create file for wavetable: {}",
filename
));
let file = File::create(&filename).unwrap_or_else(|_| {
panic!("could not create file for wavetable: {}", filename)
});
let mut writer = BufWriter::new(file);
encode_into(&band_limited_table, &mut writer, SizeLimit::Infinite)
.expect(&format!("could not encode wavetable: {}", filename));
.unwrap_or_else(|_| panic!("could not encode wavetable: {}", filename));
band_limited_table
}
};

+ 4
- 4
src/io/midi.rs View File

@ -52,10 +52,10 @@ impl MidiReceiver {
port.read_n(self.buf_len).map_err(RunError::MidiError)
}
fn to_control_event(&self, event: MidiEvent) -> ControlEvent {
fn to_control_event(&self, event: &MidiEvent) -> ControlEvent {
match event {
MidiEvent::NoteOn { key, velocity, .. } => ControlEvent::NoteOn { key, velocity },
MidiEvent::NoteOff { key, velocity, .. } => ControlEvent::NoteOff { key, velocity },
MidiEvent::NoteOn { key, velocity, .. } => ControlEvent::NoteOn { key: *key, velocity: *velocity },
MidiEvent::NoteOff { key, velocity, .. } => ControlEvent::NoteOff { key: *key, velocity: *velocity },
_ => ControlEvent::Unsupported,
}
}
@ -76,7 +76,7 @@ impl Receiver for MidiReceiver {
// event_buf.sort_by_key(|e| e.timestamp);
while let Some(event) = event_buf.pop() {
tx.send(self.to_control_event(MidiEvent::from(event)))
tx.send(self.to_control_event(&MidiEvent::from(event)))
.unwrap();
}

+ 1
- 1
src/io/osc.rs View File

@ -182,7 +182,7 @@ impl OscReceiver {
.unwrap()
.iter()
.map(|arg| match *arg {
OscType::Float(val) => val as Float,
OscType::Float(val) => Float::from(val),
_ => 0.0,
}).collect::<Vec<_>>();
events.push(ControlEvent::Pan(args));

+ 3
- 8
src/main.rs View File

@ -46,7 +46,6 @@ macro_rules! printerr(
struct Args {
socket_addr_in: SocketAddr,
socket_addr_out: SocketAddr,
sample_rate: usize,
}
@ -106,28 +105,24 @@ fn get_args() -> Args {
process::exit(1)
}
}).collect::<Vec<u16>>();
let (socket_addr_in, socket_addr_out) = (
SocketAddr::new(ip_addr, ports[0]),
SocketAddr::new(ip_addr, ports[1]),
);
let socket_addr_in = SocketAddr::new(ip_addr, ports[0]);
Args {
socket_addr_in,
socket_addr_out,
sample_rate,
}
}
fn main() {
let args = get_args();
run(args)
run(&args)
.map_err(|err| {
printerr!("{:?}", err);
process::exit(1)
}).unwrap();
}
fn run(args: Args) -> Result<(), RunError> {
fn run(args: &Args) -> Result<(), RunError> {
let buf = rb::SpscRb::new(BUF_SIZE);
let (producer, consumer) = (buf.producer(), buf.consumer());
let (tx_receiver, rx_dsp) = mpsc::channel();

Loading…
Cancel
Save