midi-msg icon indicating copy to clipboard operation
midi-msg copied to clipboard

Vec-less API for embedded usage?

Open wyager opened this issue 1 year ago • 2 comments

I'm interested in using midi-msg for an embedded MIDI project, but I see that the core MidiMsg type relies on Vec<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:

  1. Replace MidiMsg with MidiMsg<'a>, and any internal use of Vec<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 output Vec<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!
  2. If the above won't work, replace MidiMsg with MidiMsg<Buffer>, where Buffer could be set to something like std::Vec<u8> or heapless::Vec<u8,N>, unified by a common (crate-specific) trait, and add a MessageTooLong constructor to the ParseError type (which would not ever occur while using std::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.

wyager avatar Apr 30 '23 04:04 wyager