8000 midir not seeing events as they happen · Issue #129 · Boddlnagg/midir · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
midir not seeing events as they happen #129
Open
@worikgh

Description

@worikgh

I have a small midir based programme to read events from a MIDI pedal.

I compare the performance of this to aseqdump, which is working.

When I run this midir programme, and press the pedal buttons, I see nothing. Then I shut the programme down, and restart it, and I see the events. None more are detected.

Using aseqdump I see the events as they occur.

The little midir programme. I cannot see anything I have done incorrectly.

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

fn main() {
    let port_name_in: String = args().nth(1).unwrap();
    run(port_name_in).unwrap();
}

fn run(name_of_port_in: String) -> Result<(), Box<dyn Error>> {
    handle_input(name_of_port_in.as_str()).unwrap();

    let mut input = String::new();
    println!("Running....");
    stdin().read_line(&mut input)?; // wait for next enter key press                                                                                                     
    println!("Closing connection");
    Ok(())
}

fn find_port<T: MidiIO>(name: &str, midi_io: &T) -> Result<T::Port, Box<dyn Error>> {
    let ports = midi_io.ports();
    let port_names: Vec<String> = ports
        .iter()
        .map(|p| midi_io.port_name(p).unwrap())
        .collect();
    let mut names_ports = zip(ports, port_names);
    let port_name = names_ports
        .find(|x| &x.1 == name)
        .expect(format!("{} not found", name).as_str());
    Ok(port_name.0)
}


fn handle_input(port_name: &str) -> Result<(), Box<dyn Error>> {
    let midi_input = MidiInput::new("120Proof-midi-pedal-driver")?;
    let input_port = match find_port(port_name, &midi_input) {
        Ok(p) => p,
        Err(err) => panic!("Failed to bet port {port_name}: {err}"),
    };
    let _ = midi_input.connect(
        &input_port,
        "midir-read-input",
        move |stamp, message, _| {
            println!("{}: {:?} (len = {})", stamp, message, message.len());
        },
        (),
    )?;
    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0