pub enum Key {
Show 24 variants
CMajor,
DFlatMajor,
DMajor,
EFlatMajor,
EMajor,
FMajor,
FSharpMajor,
GMajor,
AFlatMajor,
AMajor,
BFlatMajor,
BMajor,
CMinor,
CSharpMinor,
DMinor,
EFlatMinor,
EMinor,
FMinor,
FSharpMinor,
GMinor,
GSharpMinor,
AMinor,
BFlatMinor,
BMinor,
}
Variants§
CMajor
DFlatMajor
DMajor
EFlatMajor
EMajor
FMajor
FSharpMajor
GMajor
AFlatMajor
AMajor
BFlatMajor
BMajor
CMinor
CSharpMinor
DMinor
EFlatMinor
EMinor
FMinor
FSharpMinor
GMinor
GSharpMinor
AMinor
BFlatMinor
BMinor
Implementations§
Source§impl Key
impl Key
Sourcepub fn from_string(s: &str) -> Result<Self, ()>
pub fn from_string(s: &str) -> Result<Self, ()>
Tries parsing the Key
from a string. Just a wrapper around KeyParser::try_from_string()
.
Sourcepub fn from_numeric(number: i32, is_major: bool) -> Result<Self, ()>
pub fn from_numeric(number: i32, is_major: bool) -> Result<Self, ()>
Get the key from a numeric representation. Mainly used internally.
Number needs to be from 1-12 (1=C,2=D,3=E…) and is_major defining
if you want the major or minor version of the note.
Returns an error if number is <1
or >12
.
Sourcepub fn from_numeric_wrapping(number: i32, is_major: bool) -> Self
pub fn from_numeric_wrapping(number: i32, is_major: bool) -> Self
Same as Key::from_numeric()
but number is getting wrapped.
So 0 would be wrapped to 12, -1 to 11, 13 to 1…
pub fn from_open_key_numeric(number: i32, is_major: bool) -> Result<Self, ()>
pub fn from_open_key_numeric_wrapping( number: i32, is_major: bool, ) -> Result<Self, ()>
pub fn open_key_numeric(&self) -> (i32, bool)
pub fn from_lancelot_numeric(number: i32, is_major: bool) -> Result<Self, ()>
pub fn from_lancelot_numeric_wrapping( number: i32, is_major: bool, ) -> Result<Self, ()>
pub fn lancelot_numeric(&self) -> (i32, bool)
Sourcepub fn traditional(&self) -> String
pub fn traditional(&self) -> String
Returns the traditional string representation. Eg Abm, F#m, F…
Source§impl Key
impl Key
Sourcepub fn transpose_semitones(&self, semitones: i32) -> Self
pub fn transpose_semitones(&self, semitones: i32) -> Self
Transpose this key by n semitones
Sourcepub fn transpose_tones(&self, tones: i32) -> Self
pub fn transpose_tones(&self, tones: i32) -> Self
Transpose this key by n full tones
Sourcepub fn transpose_factor(&self, factor: f32) -> Self
pub fn transpose_factor(&self, factor: f32) -> Self
Transpose this key by a factor. 0.5 would be half the tempo, 2.0 twice the tempo. (Imagine a pitch fader on a vinyl recorder)
Sourcepub fn transpose_bpm(&self, initial_bpm: f32, bpm: f32) -> Self
pub fn transpose_bpm(&self, initial_bpm: f32, bpm: f32) -> Self
Transpose this key by an initial bpm and a target bpm. Imagine a track has the Key 3A at 135.0bpm (initial_bpm) and you want to know what bpm it is at 140.4bpm (target bpm).
Sourcepub fn to_lancelot_i32(&self) -> i32
pub fn to_lancelot_i32(&self) -> i32
Return the i32 representation of this Key in the lancelot sorting. The i32 will be between 0 and 23. This is helpful for serialization and sorting.
Sourcepub fn try_from_lancelot_i32(number: i32) -> Result<Self, ()>
pub fn try_from_lancelot_i32(number: i32) -> Result<Self, ()>
Try turning an i32 in lancelot sorting into a Key object. See Key::to_lancelot_i32
.