Trait nih_plug::midi::sysex::SysExMessage
source · pub trait SysExMessage: Debug + Clone + PartialEq + Send + Sync {
type Buffer: Default + Borrow<[u8]> + BorrowMut<[u8]>;
// Required methods
fn from_buffer(buffer: &[u8]) -> Option<Self>;
fn to_buffer(self) -> (Self::Buffer, usize);
}
Expand description
A type that can be converted to and from byte buffers containing MIDI SysEx messages.
SysEx buffers
For maximum flexibility this trait works with RAW MIDI messages. This means that status bytes and end of SysEx (EOX) bytes are included in the input, and should also be included in the output. A consequence of this is that it is also possible to support system common and system real time messages as needed, as long as the plugin API supports those.
For example, the message to turn general MIDI mode on is [0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7]
,
and has a length of 6 bytes. Note that this includes the 0xf0
start byte and 0xf7
end byte.
Required Associated Types§
sourcetype Buffer: Default + Borrow<[u8]> + BorrowMut<[u8]>
type Buffer: Default + Borrow<[u8]> + BorrowMut<[u8]>
The byte array buffer the messages are read from and serialized to. Should be a [u8; N]
,
where N
is the maximum supported message length in bytes. This covers the full message,
see the trait’s docstring for more information.
Ideally this could just be a const generic but Rust doesn’t let you use those as array lengths just yet.
Required Methods§
sourcefn from_buffer(buffer: &[u8]) -> Option<Self>
fn from_buffer(buffer: &[u8]) -> Option<Self>
Read a SysEx message from buffer
and convert it to this message type if supported. This
covers the full message, see the trait’s docstring for more information. buffer
’s length
matches the received message. It is not padded to match Buffer
.
sourcefn to_buffer(self) -> (Self::Buffer, usize)
fn to_buffer(self) -> (Self::Buffer, usize)
Serialize this message object as a SysEx message in a byte buffer. This returns a buffer alongside the message’s length in bytes. The buffer may contain padding at the end. This should contain the full message including headers and the EOX byte, see the trait’s docstring for more information.
Implementations on Foreign Types§
source§impl SysExMessage for ()
impl SysExMessage for ()
A default implementation plugins that don’t need SysEx support can use.