-
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
Add example for multithread #70
Comments
@hughrawlinson You should not need to worry about that. If your multi-threaded code compiles (and doesn't make use of If you have problems getting your code to compile in multiple threads you can use the following strategy:
As a reference you can check out my synthesizer project https://crates.io/crates/microwave. |
Is there any question still open? Otherwise I'd close this issue. |
Thanks for getting back to me. That clarifies things a bit - although, I'm not sure exactly what the library guarantees to be safe. One remaining question is: If I get a MidiOutputPort on the main thread, and pass it into another thread in the manner you described, and then I unplug the midi device, does that reference break somehow? If so, how do I catch that? Or is that not the kind of guarantee that the library makes? I also think it would be good to have an example of this - either a specific contrived example like the other examples, or perhaps a link out to the crate you mentioned? Thanks! 😄 |
@hughrawlinson yeah, you should be able to safely run it on another thread and pass the messages somewhere else. I did a small example of this with To be more specific I am shoveling the midi messages from
It's not currently possible to detect disconnected devices. In theory this can be added (at least on Linux). See #35 for more on unplugging the device. |
Hi! I'm having a hard time using midir in a threaded context. I'm using threads to model polyphony, as is typical in many synth implementations I've seen. I specifically don't know what is safe to share using Arc/Mutex. If nothing, I'm not sure how to be confident that I spin up a connection to the same port on a new thread. It looks like I can't share MidiOutputPorts between different instances of MidiOutput.
Or is it better to not use threading at all, and just keep a single thread, and handle scheduling of events?
Thanks for any insight!
The text was updated successfully, but these errors were encountered: