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

Issue getting midi_in port and midi_in port_name #104

Closed
elmcapp opened this issue Mar 31, 2022 · 3 comments
Closed

Issue getting midi_in port and midi_in port_name #104

elmcapp opened this issue Mar 31, 2022 · 3 comments

Comments

@elmcapp
Copy link

elmcapp commented Mar 31, 2022

Having issues with getting input ports. midi_in.ports(). There is no port function or port_name function on midi_in

#[tauri::command]
fn get_device_list() {
    let mut midi_in = MidiInput::new("midir test input");

    let midi_out = MidiOutput::new("midir test output");

    let mut input = String::new();

    loop {
        println!("Available input ports:");
        for (i, p) in midi_in.ports().iter().enumerate() {
            println!("{}: {}", i, midi_in.port_name(p));
        }

        println!("\nAvailable output ports:");
        for (i, p) in midi_out.ports().iter().enumerate() {
            println!("{}: {}", i, midi_out.port_name(p));
        }

        // run in endless loop if "--loop" parameter is specified
        match ::std::env::args().nth(1) {
            Some(ref arg) if arg == "--loop" => {}
            _ => break,
        }
    }
}
@Boddlnagg
Copy link
Owner

You can get all the ports with midi_in.ports() and you can get a port's name with midi_in.port_name(port).

You did that already in the code you posted, so I don't really understand what your question is.

@elmcapp
Copy link
Author

elmcapp commented Mar 31, 2022

It working now. Sorry, Looks like I may forgot a closing backet which was giving me an error.

Please explain what the loop is for. My thoughts is that if a new midi device was connect to computer that it would then show the new midi device, however it does not. It only show devices from the list from when the function started. To see new devices plugged in after function runs I have to run the function again

@Boddlnagg
Copy link
Owner

The function midi_in.ports() returns the list of devices at the time when the function is called. Of course you need to run it again to get the updated list after a device is plugged in.
If you mean that you don't see any new devices until you restart your application, then that's probably what issue #86 is about ... are you running on macOS?

@elmcapp elmcapp closed this as completed Apr 4, 2022
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

2 participants