midir
midir copied to clipboard
When i press and release 2 piano keys at the same time, the callback sends the wrong message.
Introduction
Hello, i have an issue that i think might be a bug with either midir or maybe my electric piano (im not sure if this is possible).
First of all, i own an 88-key electric piano, i connected it to my Windows 10 computer and i wrote a program that does something with the key that i press on the piano, so this code will calculate a number ranging from 0 to 87 (0 is the key with the lowest pitch, and 87 is the highest). here's the code:
let mut switch = false;
let _conn_in = midi_in.connect(in_port, "midir-read-input", move |_, message, _| {
if message.len() > 1 {
let piano_key = (message[1] as f64) - 21.0;
if piano_key >= 0.0 {
if switch {
println!("Key: {} --- Message: {:?}", piano_key, message);
}
switch = !switch;
}
}
}, () )?;
What is the issue exactly?
Lets say that i press the key 1 and key 2 at the same time, the program prints these two keys like this:
Key: 1 --- Message: [144, 22, 81] Key: 2 --- Message: [144, 23 (Don't get confused, it should be 23 because i didn't subtract ), 81]
That works fine like it should, BUT when i release both of key 1 and key 2 at the same time, it prints:
Key: 1 --- Message: [144, 22, 81] Key: 1 --- Message: [144, 22, 81]
it prints key 1 two times as if i released it 2 times at the same time.. which makes no sense! THIS is what we should expect:
Key: 1 --- Message: [144, 22, 81] Key: 2 --- Message: [144, 23, 81]