Expand description
Core MIDI data model and in-memory I/O for the SIM music stack.
This crate defines the protocol-agnostic MIDI types shared across the
constellation: tick-based timing (TickTime), the bounded integer
domains used by MIDI bytes (U7, U14, Channel), the event model
(MidiEvent, MidiPayload, ChannelMessage, MetaEvent,
SysExEvent), and the streaming MidiSource/MidiSink traits with
in-memory implementations. It also provides the NoteEchoPlayer
transform, controller-number constants, tempo conversions, and the
host-registered MidiIoLib that exposes the in-memory cards to a running
SIM Cx.
Higher layers (Standard MIDI File, SysEx, live transports) build on this model rather than redefining it.
§Examples
use sim_lib_midi_core::{Channel, ChannelMessage, U7};
let note = ChannelMessage::NoteOn {
ch: Channel::new(0).unwrap(),
key: U7(60),
vel: U7(100),
};
assert!(matches!(note, ChannelMessage::NoteOn { .. }));use sim_lib_midi_core::TickTime;
// 480 ticks at 480 tpq is exactly one quarter note.
let one_quarter = TickTime::new(480, 480).unwrap();
assert_eq!(one_quarter.as_f64_quarters(), 1.0);
// Rebasing to a coarser resolution is exact here.
assert_eq!(one_quarter.rebase(96).unwrap().ticks, 96);Modules§
- meta_
view - Typed views over raw
MetaBucketpayloads. - wire
- Canonical MIDI channel-message wire bytes.
Structs§
- Channel
- A MIDI channel number in the range
0..=15. - Memory
Midi Sink - An in-memory
MidiSinkthat collects written events in tick order. - Memory
Midi Source - An in-memory
MidiSourcebacked by a time-sorted event vector. - Memory
Tracked Midi Source - An in-memory
TrackedMidiSourcebacked by a time-sorted, track-tagged event vector. - Meta
Bucket - A raw meta event: its type byte plus payload bytes.
- Midi
Event - A timestamped MIDI event with provenance.
- Midi
IoLib - Host-registered lib exporting the in-memory MIDI I/O cards and registry,
built on the shared
SurfacePackLibsubstrate. - Note
Echo Config - Configuration for the
NoteEchoPlayerecho/delay transform. - Note
Echo Player - Renders rhythmic note echoes from an input event stream per a
NoteEchoConfig. - Note
Echo Render - The result of a
NoteEchoPlayerrender: emitted events plus per-echo traces. - Note
Echo Trace - A record of a single emitted echo, linking it back to its source note.
- RawBytes
- An uninterpreted run of bytes with a status byte, used as a fallback.
- Smpte
Offset - An SMPTE timecode offset, as carried by the SMPTE-offset meta event.
- Tick
Time - A point in musical time measured in ticks at a given resolution.
- Tracked
Midi Event - A
MidiEventtagged with the track it belongs to. - U7
- A 7-bit MIDI data value in the range
0..=127. - U14
- A 14-bit MIDI data value in the range
0..=16_383, as used by pitch bend.
Enums§
- Channel
Message - A MIDI channel-voice message, carrying its target
Channeland payload. - Meta
Event - A meta event: track-scoped information that is not transmitted over the
wire, recognised types plus an
Otherescape hatch. - Midi
Error - Errors produced when constructing or converting core MIDI values.
- Midi
Payload - The payload of a
MidiEvent: one of the four event families. - Note
Echo Channel Policy - Controls which channel each echoed note is emitted on.
- Note
Echo Scale Snap - Controls whether echoed notes are snapped to a scale.
- Pump
Error - An error raised while pumping events from a source into a sink, recording which side failed.
- SysEx
Event - A system-exclusive event, distinguished by its leading status byte.
Constants§
- CC_
ALL_ NOTES_ OFF - All Notes Off (channel mode), controller 123.
- CC_
ALL_ SOUND_ OFF - All Sound Off (channel mode), controller 120.
- CC_
BALANCE_ MSB - Balance (MSB), controller 8.
- CC_
BANK_ SELECT_ MSB - Bank Select (MSB), controller 0.
- CC_
BREATH_ MSB - Breath Controller (MSB), controller 2.
- CC_
DATA_ ENTRY_ MSB - Data Entry (MSB), controller 6.
- CC_
EXPRESSION_ MSB - Expression Controller (MSB), controller 11.
- CC_
FOOT_ MSB - Foot Controller (MSB), controller 4.
- CC_
LOCAL_ CONTROL - Local Control On/Off (channel mode), controller 122.
- CC_
MOD_ WHEEL_ MSB - Modulation Wheel (MSB), controller 1.
- CC_
PAN_ MSB - Pan (MSB), controller 10.
- CC_
PORTAMENTO_ SWITCH - Portamento On/Off switch, controller 65.
- CC_
PORTAMENTO_ TIME_ MSB - Portamento Time (MSB), controller 5.
- CC_
RESET_ ALL_ CONTROLLERS - Reset All Controllers (channel mode), controller 121.
- CC_
SOFT_ PEDAL - Soft Pedal, controller 67.
- CC_
SOSTENUTO - Sostenuto Pedal, controller 66.
- CC_
SUSTAIN_ PEDAL - Sustain (damper) Pedal, controller 64.
- CC_
VOLUME_ MSB - Channel Volume (MSB), controller 7.
- DEFAULT_
US_ PER_ QUARTER - The default MIDI tempo of 500_000 microseconds per quarter (120 BPM).
Traits§
- Midi
Sink - A push-based sink that accepts
MidiEvents at a fixed resolution. - Midi
Source - A pull-based stream of
MidiEvents at a fixed resolution. - Tracked
Midi Source - A
MidiSourcethat also reports per-track membership.
Functions§
- bpm_
to_ us_ per_ quarter - Converts beats per minute to microseconds per quarter note (rounded).
- install_
midi_ io_ lib - Installs
MidiIoLibintocxonce and registers the in-memory source, sink, and tracked-source export records. - pump
- Drains every event from
sourceintosink, re-timing events to the sink’s resolution, and returns the number of events transferred. - stable_
midi_ event_ order - Sorts events into a stable, deterministic order by time and then by a payload tiebreak (note-offs before note-ons at the same tick).
- synthetic_
origin - Returns an
Origintagging events synthesised by the music stack rather than read from an input codec. - us_
per_ quarter_ to_ bpm - Converts microseconds per quarter note to beats per minute.