pub struct KbmMapping {
pub map_size: usize,
pub first_midi: u8,
pub last_midi: u8,
pub middle_note: u8,
pub reference_note: u8,
pub reference_freq: f64,
pub octave_degree: usize,
pub mapping: [i16; 128],
}Expand description
A parsed Scala keyboard mapping. Fixed-size, Copy, heap-free.
Fields§
§map_size: usizeNumber of valid entries in mapping (the map repeats every map_size keys).
first_midi: u8First MIDI key to retune.
last_midi: u8Last MIDI key to retune.
middle_note: u8The MIDI key that carries scale degree 0 (1/1).
reference_note: u8The MIDI key whose absolute frequency is pinned by reference_freq.
reference_freq: f64Absolute frequency (Hz) assigned to reference_note.
octave_degree: usizeScale degree that constitutes the formal octave/period (typically the scale size).
mapping: [i16; 128]Per-key scale degree, or KBM_UNMAPPED. Only [0, map_size) is meaningful.
Implementations§
Source§impl KbmMapping
impl KbmMapping
Sourcepub fn linear(
map_size: usize,
middle_note: u8,
reference_note: u8,
reference_freq: f64,
) -> KbmMapping
pub fn linear( map_size: usize, middle_note: u8, reference_note: u8, reference_freq: f64, ) -> KbmMapping
A linear (identity) mapping: map_size keys map to scale degrees 0,1,…,map_size-1,
with octave_degree == map_size. This is the implicit default when no .kbm accompanies
a scale. The reference key/frequency and middle key are explicit parameters — nothing is
hardcoded; A4=440 is only the caller’s choice, not a baked assumption.
Sourcepub fn linear_12(reference_freq: f64) -> KbmMapping
pub fn linear_12(reference_freq: f64) -> KbmMapping
The canonical 12-key linear map anchored at A4 (reference_note = 69 → reference_freq Hz)
with middle_note = 60. Pass the reference frequency explicitly (e.g. 440.0 or 432.0).
Sourcepub fn absolute_degree(&self, note: u8) -> Option<i32>
pub fn absolute_degree(&self, note: u8) -> Option<i32>
Scale degree a MIDI key maps to under this keyboard map, or None if the key is
unmapped or outside [first_midi, last_midi]. Returns the ABSOLUTE scale degree,
i.e. octave * octave_degree + degree_within_period (may be negative for low keys).