Expand description
MIDI value-domain helpers: normalize / denormalize between
wire-native integers and f32 ranges.
truce’s EventBody carries MIDI events as wire-native integers
(7-bit u8, 14-bit u16, 16-bit u16, 32-bit u32) so the
framework’s representation round-trips exactly with the wire.
Plugin code that wants to multiply by a parameter, accumulate
into a phase, or otherwise use the value as a float reaches for
the helpers below.
Each pair (norm_* / denorm_*) round-trips for every
representable wire input. See the per-helper docs for endpoint
semantics - pitch-bend is asymmetric on both MIDI 1.0 and MIDI
2.0 because the spec’s center value sits one code closer to the
negative end than the positive.
Lints: the helpers do as-casts at well-defined widening or
lossless points (u8 → f32, u16 → f32, f64 → f32 after
a clamped multiply), so the cast_* lints are allowed at the
module level rather than per call.
Functions§
- denorm_
7bit f32 ∈ [0.0, 1.0]→ MIDI 1.0 7-bit unsigned (0..=127).- denorm_
pitch_ bend f32 ∈ [-1.0, 1.0]→ MIDI 1.0 14-bit pitch-bend code (0..=16383).- norm_
7bit - MIDI 1.0 7-bit unsigned (
0..=127) →f32 ∈ [0.0, 1.0]. - norm_
pitch_ bend - MIDI 1.0 14-bit pitch-bend code (
0..=16383) →f32 ∈ [-1.0, ~0.99987]. - pitch_
bend_ from_ bytes - Combine two MIDI bytes (LSB first) into a 14-bit pitch-bend code. Each input byte’s high bit is masked off before combining.
- pitch_
bend_ to_ bytes - Split a 14-bit pitch-bend code into the (LSB, MSB) byte pair the wire format carries. Each output byte has the high bit clear.