-
Notifications
You must be signed in to change notification settings - Fork 78
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
How to identify when a midi input device got disconnected? #35
Comments
On WinRT this would be rather easy, but unfortunately at least the WinMM and the ALSA backend don't provide native ways to get device change notifications. I'd need to use other Windows resp. Linux OS APIs. In the long run I really want to have this, but it's quite a bit of work ... |
Hm, I would already be happy if this only worked on windows (8.1+), maybe with an extension trait? Btw, any idea how portmidi does it? |
I can see if I can come up with an extension trait similar to what's being done for virtual ports on non-Windows. The implementation of
So it's basically only returning an error if one has been set somewhere before, but I can't find a place in the code that sets |
Unfortunately i dont get a Whats the current state of this? |
If I run
The
|
While trying to find a way to identify midi input device disconnections (and before reading this ticket), I found this snippet in the documentation:
I tried using As a side note, I wonder if a feasible solution would be for |
@agersant Actually, this is specific to the default Windows backend ... after #38 the port name for that backend is stored in the port identifier itself, so there's no call back to a Windows API when I'm not sure whether the implementation or the documentation should be changed ... |
I think it makes sense to change the implementation of |
@Boddlnagg I'm using this function to open a midi port: pub fn open_input(
port_name: &str,
idx: Option<usize>,
) -> Result<(MidiInputConnection<()>, Receiver<LowLvlMsg>)> {
let midi = MidiInput::new("")?;
let port = midi
.ports()
.into_iter()
.filter_map(|port| midi.port_name(&port).ok().map(|name| (port, name)))
.filter_map(|(port, name)| (name == port_name).then_some(port))
.nth(idx.unwrap_or(0))
.ok_or_else(|| anyhow!("midi input port '{}' not found", port_name))?;
let (tx_midi, rx_midi) = channel();
Ok((
midi.connect(
&port,
"",
move |_stamp, msg, _| {
if let Some(msg) = LowLvlMsg::parse(msg) {
tx_midi.send(msg).unwrap();
}
},
(),
)
.map_err(|e| anyhow!("midi connect: {}", e))?,
rx_midi,
))
} I thought I could just detect if my input device got disconnected by checking if |
Probably the underlying thread that receives the MIDI events just continues to run (just won't receive events anymore) even if the device is no longer available 😕 Seems like other people also have problem with that functionality in RtMidi (which midir is based upon): micdah/RtMidi.Core#18. This is also related to #78, because even a polling solution wouldn't currently work on macOS ... @Boscop: You are using the default Windows backend (WinMM), right? (just so I can focus my efforts on that platform first) |
Yes, I'm using midir on Windows. |
Hello, did you find a solution to your problem? if so then it would be nice to post it here and close this issue 😄 |
@staurosKaragiannis Not yet. |
Any solutions guys? I really need this. But after looking through this issue comments from 2018 to 2022, it seems hard to be solved.😭 Do we have another rust crate implemented this? |
How to identify when a midi input device got disconnected?
When I open the ports as described here.
Is it possible to check the
MidiInputConnection
if the device was disconnected?My use case is, I want auto reconnect every few seconds if a midi device was disconnected.
I'm already successfully auto reconnecting output devices because they will give a
SendError
onsend()
if they are disconnected, but how to detect it for input devices? (on windows)The text was updated successfully, but these errors were encountered: