Explicit device connections and packet handoff¶
The separate ravet-midi-device crate uses pinned MIT midir 0.11.0 for native
input/output enumeration and connections. Select an exact current backend ID;
there is no default fallback, automatic reconnect or hotplug subscription.
Names can duplicate and IDs can change. Connection creation/teardown and output
send belong to control/worker threads. See the dependency's
connection documentation.
PreparedMidiInput and its unique MidiReceiver share a prepared power-of-two
ring of 1..1,024 packets. Complete explicit-status short messages and complete
SysEx packets up to 1,024 bytes including F0/F7 are validated before publication.
SysEx payload bytes are seven-bit; fragmented data, embedded real-time messages,
running-status packets and UMP reject. A full ring drops the newest whole packet.
Relaxed counters report accepted, full drops and invalid input. Consumer pop
returns an owned fixed-storage packet preserving FIFO order and raw connection
timestamps. Timestamp units are microseconds with a connection-local arbitrary
origin; consumers must map them to audio blocks explicitly.
Framework capture/pop use atomic prepared storage without allocation, locks or I/O. Native backend callback allocation, scheduling and output-send behavior are outside this guarantee. Creation/drop allocate and close can synchronize threads. No audio callback should enumerate, connect, close or call native output send. Complete SysEx support here does not change Foundation's short-message decoder or add variable payloads to portable sample events.
The explicit Unix virtual-endpoint fixture creates a unique temporary destination and sends only to itself; it does not open physical MIDI hardware:
CARGO_BUILD_JOBS=2 cargo run -p ravet-midi-device --example loopback --locked
On macOS arm64, actual CoreMIDI virtual input/output transferred note, controller, bend, clock and complete SysEx messages in order, then closed both endpoints. Tests cover malformed/full queues, maximum payloads, counter rollover, 10,000 threaded transfers and 10,000 allocation-instrumented callback/consumer cycles. No physical hardware, Linux/Windows runtime, UMP or deadline is validated. See decision 0032.
MidiMessage::from_bytes requires explicit status, exact length and seven-bit
data bytes. as_bytes preserves wire representation. kind returns zero-based
channels, raw seven-bit controller/pressure/velocity values and fourteen-bit
pitch bend/song position. Pitch bend center is 8192; its semitone range belongs
to the receiver. Note-on with velocity zero decodes as note-off while retaining
the original bytes. No MIDI controller policy or synthesis is imposed.
The decoder accepts one byte at a time, preserving channel running status and partial messages across calls. Real-time messages emit immediately without interrupting the partial message. System common cancels running status; a new non-real-time status discards incomplete data. Undefined real-time status rejects without disturbing running status. Invalid non-real-time status clears it. Explicit reset clears all partial/running state when a port disconnects.
SysEx start reports UnsupportedSysEx once, then skips payload until EOX or
another non-real-time status. Real-time messages within it still emit. EOX is
reported as a short message. This avoids allocating unbounded SysEx data and
allows a caller to recover; it is not SysEx support. Data without running/partial
status reports MissingStatus.
EventData::Midi(message) carries a validated message at the event's sample
offset. Input/output capacity, ordering and zero-frame rules are unchanged.
Device adapters must supply timestamps and map them into blocks; the decoder
has no clock or scheduling policy. The current gain processor ignores MIDI, and
the current CLAP translator still accepts only global parameter-value events.
Tests cover all channel/status combinations, resolution endpoints, running status, interleaved real-time messages, common-message cancellation, malformed messages, SysEx skip/recovery and timed output preservation. Message codes follow the MIDI Association message summary.