Skip to content

Commit

Permalink
More clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
barafael committed Jul 15, 2023
1 parent a11a250 commit 135215e
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 87 deletions.
2 changes: 1 addition & 1 deletion examples/browser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn start() {
let token_outer = Arc::new(Mutex::new(None));
let token = token_outer.clone();
let closure: Closure<dyn FnMut()> = Closure::wrap(Box::new(move || {
if run().unwrap() == true {
if run().unwrap() {
if let Some(token) = *token.lock().unwrap() {
web_sys::window().unwrap().clear_interval_with_handle(token);
}
Expand Down
9 changes: 4 additions & 5 deletions examples/test_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use midir::{Ignore, MidiIO, MidiInput, MidiOutput};
fn main() {
match run() {
Ok(_) => (),
Err(err) => println!("Error: {}", err),
Err(err) => println!("Error: {err}"),
}
}

Expand Down Expand Up @@ -40,8 +40,7 @@ fn run() -> Result<(), Box<dyn Error>> {
)?;

println!(
"Connections open, forwarding from '{}' to '{}' (press enter to exit) ...",
in_port_name, out_port_name
"Connections open, forwarding from '{in_port_name}' to '{out_port_name}' (press enter to exit) ...",
);

let mut input = String::new();
Expand All @@ -52,12 +51,12 @@ fn run() -> Result<(), Box<dyn Error>> {
}

fn select_port<T: MidiIO>(midi_io: &T, descr: &str) -> Result<T::Port, Box<dyn Error>> {
println!("Available {} ports:", descr);
println!("Available {descr} ports:");
let midi_ports = midi_io.ports();
for (i, p) in midi_ports.iter().enumerate() {
println!("{}: {}", i, midi_io.port_name(p)?);
}
print!("Please select {} port: ", descr);
print!("Please select {descr} port: ");
stdout().flush()?;
let mut input = String::new();
stdin().read_line(&mut input)?;
Expand Down
2 changes: 1 addition & 1 deletion examples/test_list_ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use midir::{Ignore, MidiInput, MidiOutput};
fn main() {
match run() {
Ok(_) => (),
Err(err) => println!("Error: {}", err),
Err(err) => println!("Error: {err}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/test_play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use midir::{MidiOutput, MidiOutputPort};
fn main() {
match run() {
Ok(_) => (),
Err(err) => println!("Error: {}", err),
Err(err) => println!("Error: {err}"),
}
}

Expand Down
7 changes: 2 additions & 5 deletions examples/test_read_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use midir::{Ignore, MidiInput};
fn main() {
match run() {
Ok(_) => (),
Err(err) => println!("Error: {}", err),
Err(err) => println!("Error: {err}"),
}
}

Expand Down Expand Up @@ -55,10 +55,7 @@ fn run() -> Result<(), Box<dyn Error>> {
(),
)?;

println!(
"Connection open, reading input from '{}' (press enter to exit) ...",
in_port_name
);
println!("Connection open, reading input from '{in_port_name}' (press enter to exit) ...");

input.clear();
stdin().read_line(&mut input)?; // wait for next enter key press
Expand Down
11 changes: 5 additions & 6 deletions examples/test_reuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use midir::{Ignore, MidiInput, MidiOutput};
fn main() {
match run() {
Ok(_) => (),
Err(err) => println!("Error: {}", err),
Err(err) => println!("Error: {err}"),
}
}

Expand Down Expand Up @@ -70,18 +70,17 @@ fn run() -> Result<(), Box<dyn Error>> {
stdin().read_line(&mut input)?;
if input.trim() == "q" {
break;
} else {
conn_out.send(&[144, 60, 1])?;
sleep(Duration::from_millis(200));
conn_out.send(&[144, 60, 0])?;
}
conn_out.send(&[144, 60, 1])?;
sleep(Duration::from_millis(200));
conn_out.send(&[144, 60, 0])?;
}
println!("Closing connections");
let (midi_in_, log_all_bytes) = conn_in.close();
midi_in = midi_in_;
midi_out = conn_out.close();
println!("Connections closed");
println!("Received bytes: {:?}", log_all_bytes);
println!("Received bytes: {log_all_bytes:?}");
}
Ok(())
}
2 changes: 1 addition & 1 deletion examples/test_sysex.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
match example::run() {
Ok(_) => (),
Err(err) => println!("Error: {}", err),
Err(err) => println!("Error: {err}"),
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/backend/coremidi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::{Arc, Mutex};

use crate::backend::Callback;
use crate::errors::*;
use crate::{Ignore, MidiMessage};

Expand Down Expand Up @@ -279,7 +280,7 @@ struct HandlerData<T> {
message: MidiMessage,
ignore_flags: Ignore,
continue_sysex: bool,
callback: Box<dyn FnMut(u64, &[u8], &mut T) + Send>,
callback: Callback<T>,
user_data: Option<T>,
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/jack/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use jack_sys::{

pub const JACK_DEFAULT_MIDI_TYPE: &[u8] = b"8 bit raw midi\0";

bitflags! {
bitflags::bitflags! {
pub struct JackOpenOptions: u32 {
const NoStartServer = 1;
const UseExactName = 2;
Expand All @@ -27,7 +27,7 @@ bitflags! {
}
}

bitflags! {
bitflags::bitflags! {
pub struct PortFlags: u32 {
const PortIsInput = 1;
const PortIsOutput = 2;
Expand Down
1 change: 1 addition & 0 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// TODO: improve feature selection (make sure that there is always exactly one implementation, or enable dynamic backend selection)
// TODO: allow to disable build dependency on ALSA

#[allow(unused)]
pub type Callback<T> = Box<dyn FnMut(u64, &[u8], &mut T) + Send>;

#[cfg(all(target_os = "windows", not(feature = "winrt")))]
Expand Down
12 changes: 6 additions & 6 deletions src/backend/winmm/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ pub extern "system" fn handle_input<T>(
// Channel or system message
// Make sure the first byte is a status byte.
let status: u8 = (midi_message & 0x000000FF) as u8;
if !(status & 0x80 != 0) {
if status & 0x80 == 0 {
return;
}

// Determine the number of bytes in the MIDI message.
#[allow(clippy::if_same_then_else)]
let nbytes: u16 = if status < 0xC0 {
3
} else if status < 0xE0 {
Expand All @@ -47,9 +48,8 @@ pub extern "system" fn handle_input<T>(
} else if status == 0xF1 {
if data.ignore_flags.contains(Ignore::Time) {
return;
} else {
2
}
2
} else if status == 0xF2 {
3
} else if status == 0xF3 {
Expand All @@ -65,7 +65,7 @@ pub extern "system" fn handle_input<T>(
};

// Copy bytes to our MIDI message.
let ptr = (&midi_message) as *const DWORD_PTR as *const u8;
let ptr = std::ptr::addr_of!(midi_message).cast();
let bytes: &[u8] = unsafe { slice::from_raw_parts(ptr, nbytes as usize) };
data.message.bytes.extend_from_slice(bytes);
} else {
Expand All @@ -88,13 +88,13 @@ pub extern "system" fn handle_input<T>(
// buffer when an application closes and in this case, we should
// avoid requeueing it, else the computer suddenly reboots after
// one or two minutes.
if (unsafe { *data.sysex_buffer.0[sysex.dwUser as usize] }).dwBytesRecorded > 0 {
if (unsafe { *data.sysex_buffer.0[sysex.dwUser] }).dwBytesRecorded > 0 {
//if ( sysex->dwBytesRecorded > 0 ) {
let in_handle = data.in_handle.as_ref().unwrap().0.lock().unwrap();
let result = unsafe {
midiInAddBuffer(
*in_handle,
data.sysex_buffer.0[sysex.dwUser as usize],
data.sysex_buffer.0[sysex.dwUser],
mem::size_of::<MIDIHDR>() as u32,
)
};
Expand Down
Loading

0 comments on commit 135215e

Please sign in to comment.