Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All MIDI events are lost when device starts sending events before midir starts listening #81

Open
Woyten opened this issue Mar 5, 2021 · 2 comments

Comments

@Woyten
Copy link

Woyten commented Mar 5, 2021

Reproduction on Linux:

  1. MIDI device is connected physically via USB
  2. Some keys are pressed (MIDI events are sent)
  3. midir starts listening

Result:

  • midir receives the events that were sent before listening started (in a burst)
  • midir does not receive any new events

In practice, this means, whenever the reception of events fails I have to:

  1. Stop my midir application
  2. Physically disconnect the MIDI device
  3. Physically reconnect the MIDI device
  4. Restart my midir application

It haven't checked whether physically disconnecting/reconnecting can be achieved in software but in any case this problem, unfortunately, is very annoying and poses a problem for real-world user applications.

@Boddlnagg
Copy link
Owner

I guess you're using the (default) ALSA backend? It would be interesting to know if this behavior is the same when you use ALSA (also alsa-rs) directly, because I can't think of anything we do in midir that would provoke this behavior. And I don't think that any other backends behave that way.

@worikgh
Copy link

worikgh commented Mar 11, 2023

I am seeing this, too, using alsa backend.

I can see the events when I use aseqdump on the device (a MIDI pedal) but when I use midir I see the events issued just before my programme ran, and then it hangs.

If I run aseqdump at the same time as my programme, my programme never gets anything.

FYI this is how I am using midir

use midir::MidiInput;
use midir::MidiInputPort;
use std::env::args;
use std::error::Error;
use std::io::stdin;
use std::iter::zip;

fn main() {
    let port_name: String = args().nth(1).unwrap();
    run(port_name).unwrap();
}
fn run(name_of_port: String) -> Result<(), Box<dyn Error>> {
    let midi_input = MidiInput::new("120Proof-midi-pedal-driver")?;
    let ports = midi_input.ports();
    let port_names: Vec<String> = ports
        .iter()
        .map(|p| midi_input.port_name(p).unwrap())
        .collect();
    let mut names_ports = zip(ports, port_names);
    let port_name: (MidiInputPort, String) = names_ports
        .find(|x| &x.1 == name_of_port.as_str())
        .expect(format!("{} not found", name_of_port).as_str());
    let input_port: MidiInputPort = port_name.0;

    let _ = midi_input.connect(
        &input_port,
        "midir-read-input",
        move |stamp, message, _| {
            println!("{}: {:?} (len = {})", stamp, message, message.len());
        },
        (),
    )?;
    let mut input = String::new();
    println!("Running....");
    stdin().read_line(&mut input)?; // wait for next enter key press                                                                                                     
    println!("Closing connection");
    Ok(())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants