Struct tune::scala::KbmRoot [−][src]
Expand description
Defines an absolute horizontal and vertical location of a scale.
KbmRoot
is intended to be used in combination with Scl
to form a Tuning
.
The interesting thing about a Tuning
is that it offers a bidirectional key-to-pitch mapping.
This means it is possible to find the best matching PianoKey
for a given Pitch
input.
The pitch input can be a continuous value, e.g. the location of a mouse pointer.
In order to enable invertibility the mapping described by KbmRoot
is linear.
In other words, the keyboard mapping degree and the scale degree are the same number.
If the mapping is required to be non-linear KbmRoot
needs to be surrounded by the more general Kbm
struct.
Fields
origin: PianoKey
The PianoKey
that maps to degree 0 of the keyboard mapping.
If a Kbm
surrounding is used with the first entry being n, origin
maps to scale degree n.
ref_pitch: Pitch
A Pitch
that is guaranteed to be present in a Tuning
but which might be skipped in the KeyboardMapping
spanned by the Kbm
surrounding.
ref_degree: i32
The scale degree for which ref_pitch
is given as a reference.
Implementations
Shifts the origin
of a scale by num_degrees
conserving the scale’s vertical location.
Examples
let kbm_root = KbmRoot {
origin: PianoKey::from_midi_number(67),
ref_pitch: Pitch::from_hz(432.0),
ref_degree: 2,
};
assert_eq!(
kbm_root.shift_origin_by(-7),
KbmRoot {
origin: PianoKey::from_midi_number(60),
ref_pitch: Pitch::from_hz(432.0),
ref_degree: 9,
}
);
Creates a quasi-equivalent Kbm
surrounding which can be exported.
Examples
let kbm_root = KbmRoot::from(Note::from_midi_number(62));
let kbm = kbm_root.to_kbm();
assert_eq!(kbm.kbm_root(), kbm_root);
assert_eq!(kbm.range(), PianoKey::from_midi_number(0)..PianoKey::from_midi_number(128));
assert_eq!(kbm.formal_octave(), 1);
assert_eq!(kbm.num_items(), 1);
assert_eq!(kbm.scale_degree_of(PianoKey::from_midi_number(61)), Some(-1));
assert_eq!(kbm.scale_degree_of(PianoKey::from_midi_number(62)), Some(0));
assert_eq!(kbm.scale_degree_of(PianoKey::from_midi_number(63)), Some(1));
let exported = kbm.export();
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for KbmRoot
impl UnwindSafe for KbmRoot
Blanket Implementations
Mutably borrows from an owned value. Read more