-
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 MidiInputPort::id()
and MidiOutputPort::id()
#157
Conversation
MidiInputPort::id()
and MidiOutputPort::id()
MidiInputPort::id()
and MidiOutputPort::id()
Thanks for the PR! The idea certainly makes sence, but I have to admit I don't really understand this sentence:
Maybe I just don't know enoguh about tauri ... but how is serialization helpful without deserialization? How can you reconnect to the same port based on the Anyway, I'm on vacation now until the beginning of November, so it might take a while until I get back to you. |
With Tauri we define a set of commands in Rust that can be called from the webview to do MIDI actions. These look like:
We also maintain two maps in Rust which contain a mapping between the id and the input/output (Eg. Basically In pratice with the previous system of identify ports by name the call to
The ID being returned is a I think keeping it as a string makes the most sense because it doesn't require any special integration with serialization libraries and it also allows joining the two different internal identifier used by Alsa into one. |
Okay, so the "deserialization" basically enumerates all input/output ports and picks the one where the In that case, I think it would make sense to also have a method |
Basically. When the webview calls We then put the socket into a shared map (keyed by the id) which holds the input/output between open, send and close calls so we don't open, send then close a new Midi input/output on every send call from the webview. This helps us match the semantics of the WebMIDI API.
I suppose this does make sense, implemented. This would remove a tiny bit of code from our open methods which is nice. Also if you do wanna have to look the implementation of |
Thanks, this is exactly what I had in mind 🙂 |
Fixed! |
Thanks again, and sorry that it took me so long to get back to you! |
I also published version 0.10.1 which includes this. |
Allows getting a unique reference to the port as an opaque string. The main advantage of this over just using the
MidiInputPort
andMidiOutputPort
structs is that this identifier can be serialized.In my case i'm trying to make
tauri-plugin-midi
work with many different devices that have the same device name. Being able to serialize these identifiers means we can share them with the webview and use them to address any communications.By using the identifiers from the OS midi stuff, we should also be able to get identifier which are stable across restarts of the application (and potentially the system but that's really up to the OS).
I think this might close #34
One implication of the code in this PR is that it does some lossy string conversions. I suppose we could probs add in a 3rd party dependency or extra logic to not lossily encode them but i'm not sure it's worth doing unless it does actually become a problem but happy to see what you think.