-
Notifications
You must be signed in to change notification settings - Fork 10
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
Vec-less API for embedded usage? #18
Comments
There are a few unfortunate constraints which make both of the above ideas difficult. Perhaps most salient is this:
Unfortunately, such a structure is not possible to represent in a bounded amount of memory. The recursive chain (as presented) could be unbounded in size, so any effort to make a fixed-size representation of a MidiMsg will fail without const-size-polymorphic type recursion (which I suspect Rust cannot do). I am not sure if this is an inherent property of the MIDI spec, or if there is a way to re-arrange the enums in this library such that there is no recursive path from a message type back to itself without violating the MIDI spec. Curious to hear if you have any thoughts on this @AlexCharlton. |
I don't believe there's any way for to build sysex messages without managing memory. Anything else assumes there is some sort of contiguous buffer that contains all of a given message's data -- as you point out -- which is not a valid assumption according to the MIDI spec. The recursive nature of MIDI messages that you describe is also due to the spec: MIDI messages can indeed contain other MIDI messages. That said no_std and sysex are not mutually exclusive, and Rust supports no_std Vecs. So I'd be interested to hear any reports of embedded usage in practice and if there are any practical performance implications to the API. |
I'm interested in using midi-msg for an embedded MIDI project, but I see that the core
MidiMsg
type relies onVec<u8>
for the internal representation of arbitrary-length message types, such as sysex messages.Do you have any thoughts on what it might take to implement a type that has
no_std
support for all message types?I could see two ways this might work:
MidiMsg
withMidiMsg<'a>
, and any internal use ofVec<u8>
would be changed to&'a [u8]
, referring to a slice of the input buffer. I'm not sure if this would work in general - are there cases where the outputVec<u8>
is not a contiguous slice of the input buffer? If every output type is a contiguous sample of the input, this seems like the best approach - no memory overhead!MidiMsg
withMidiMsg<Buffer>
, whereBuffer
could be set to something likestd::Vec<u8>
orheapless::Vec<u8,N>
, unified by a common (crate-specific) trait, and add aMessageTooLong
constructor to theParseError
type (which would not ever occur while usingstd::Vec<u8>
I'm not sure if this would work with your design intentions for the library, but I'm probably going to have to add this functionality in any case, so figured I would check if there was some approach that would be upstreamable.
The text was updated successfully, but these errors were encountered: