Skip to main content

KbmMapping

Struct KbmMapping 

Source
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: usize

Number of valid entries in mapping (the map repeats every map_size keys).

§first_midi: u8

First MIDI key to retune.

§last_midi: u8

Last MIDI key to retune.

§middle_note: u8

The MIDI key that carries scale degree 0 (1/1).

§reference_note: u8

The MIDI key whose absolute frequency is pinned by reference_freq.

§reference_freq: f64

Absolute frequency (Hz) assigned to reference_note.

§octave_degree: usize

Scale 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

Source

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.

Source

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).

Source

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).

Trait Implementations§

Source§

impl Clone for KbmMapping

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for KbmMapping

Source§

impl Debug for KbmMapping

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.