Skip to main content

Module sonic_token

Module sonic_token 

Source
Expand description

A packed u64 SonicToken for MIDI — the qualia-audio-side bridge type.

Lane AU-MIDI-BRIDGE. This mirrors the bit layout of core-db’s net/sonic_token.rs so a later cross-crate reconciliation can map this token to that one field-for-field, but it is defined here independently (this crate takes no dependency on qualia-core-db). It exists so a canonical crate::midi::message::MidiMessage can be squeezed into a single 8-byte Copy word for the AcousticPlane hot path and recovered losslessly.

§Bit layout (mirrors core-db SonicToken::pack)

bits  0.. 8  delta_time      (u8)   — inter-event tick delta (0 here)
bits  8..12  event_type      (4b)   — 0 NoteOn, 1 NoteOff, 2 ControlChange, 3 Parametric
bits 12..16  channel         (4b)   — MIDI channel 0..=15
bits 16..24  note / data     (u8)   — note number, or CC controller number
bits 24..32  velocity/value  (u8)   — velocity, or CC value
bits 32..48  tensor_index    (u16)  — graph node hint (0 here)
bits 48..64  flags           (u16)  — provenance flags (0 here)

Only the three MIDI-mappable event types round-trip: NoteOn, NoteOff, and ControlChange. Parametric has no MIDI-1.0 equivalent, so sonic_token_to_midi returns None for it, and non-note/CC messages (pitch bend, pressure, system) return None from midi_to_sonic_token.

Epistemic note: a SonicToken is a transport encoding, not a truth claim. Whether the note it carries is a transcription proposal or an authoritative authored event is a property of its source stream (see super::from_pitch_midi vs super::to_note_events); the token itself carries no confidence.

Enums§

SonicEventType
The MIDI-relevant sonic event types (values match core-db SonicEventType).

Constants§

SONIC_MAGIC
Provenance magic byte mirrored from core-db ('S'), packed into flags.

Functions§

channel
The 4-bit channel field (0..=15).
delta_time
The 8-bit delta-time field.
event_type
The 4-bit event type carried by token.
flags
The 16-bit flags field.
midi_to_sonic_token
Encode a MidiMessage into a packed sonic-token u64.
note
The 8-bit note / CC-controller field.
pack
Pack the fields into the mirrored u64 layout.
sonic_token_to_midi
Decode a packed sonic-token u64 back into a MidiMessage.
tensor_index
The 16-bit tensor-index (graph node) field.
velocity
The 8-bit velocity / CC-value field.