1
0
Fork 0

Document the expected buffer format for SysEx

This commit is contained in:
Robbert van der Helm 2023-01-31 19:29:11 +01:00
parent 611dc452ec
commit 1e8bdb9d8e

View file

@ -3,16 +3,29 @@
use std::fmt::Debug; use std::fmt::Debug;
/// A type that can be converted to and from byte buffers containing MIDI SysEx messages. /// 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.
pub trait SysExMessage: Debug + Clone + PartialEq + Send + Sync { pub trait SysExMessage: Debug + Clone + PartialEq + Send + Sync {
/// The maximum SysEx message size, in bytes. /// The maximum SysEx message size, in bytes. This covers the full message, see the trait's
/// docstring for more information.
const MAX_BUFFER_SIZE: usize; const MAX_BUFFER_SIZE: usize;
/// Read a SysEx message from `buffer` and convert it to this message type if supported. /// Read a SysEx message from `buffer` and convert it to this message type if supported. This
/// `buffer`'s length matches the received message. It is not padded to `MAX_BUFFER_SIZE` bytes. /// covers the full message, see the trait's docstring for more information. `buffer`'s length
/// matches the received message. It is not padded to `MAX_BUFFER_SIZE` bytes.
fn from_buffer(buffer: &[u8]) -> Option<Self>; fn from_buffer(buffer: &[u8]) -> Option<Self>;
/// Serialize this message object as a SysEx message in `buffer`, returning the message's length /// Serialize this message object as a SysEx message in `buffer`, returning the message's length
/// in bytes. /// in bytes. This should contain the full message including headers and the EOX byte, see the
/// trait's docstring for more information.
/// ///
/// `buffer` is a `[u8; Self::MAX_BUFFER_SIZE]`, but Rust currently doesn't allow using /// `buffer` is a `[u8; Self::MAX_BUFFER_SIZE]`, but Rust currently doesn't allow using
/// associated constants in method types: /// associated constants in method types: