pub struct Key(/* private fields */);Expand description
Identifies a key for some message.
Keys are interpeted as a 7-bit number.
Each value corresponds to some Note and Octave.
Key 0 is C(-1), and Key 127 is G9.
§Example
let key_byte = 63;
let key = Key::from_databyte(key_byte).unwrap(); // 63 is between 0-127
assert_eq!(key.note(), Note::DSharp);
assert_eq!(key.octave(), Octave::new(4))Implementations§
Source§impl Key
impl Key
Sourcepub fn from_databyte<B, E>(rep: B) -> Result<Self, Error>
pub fn from_databyte<B, E>(rep: B) -> Result<Self, Error>
Create a new key.
Checks for correctness (leading 0 bit).
Sourcepub const fn new(note: Note, octave: Octave) -> Self
pub const fn new(note: Note, octave: Octave) -> Self
Create a key from a given note and octave
§Panics
if you pass in, on Octave::new(9) a Key greater than Key::G.
this is because Key::GSharp-Key::B for octave 9 is not representable
in midi.
Sourcepub fn is_sharp(&self) -> bool
pub fn is_sharp(&self) -> bool
Returns true if the note of the key is sharp. Same as is_flat
See Note::is_sharp for an example
Sourcepub fn is_flat(&self) -> bool
pub fn is_flat(&self) -> bool
Returns true if the note of the key is flat. Same as is_sharp
See Note::is_flat for an example
Trait Implementations§
Source§impl AddAssign<u8> for Key
impl AddAssign<u8> for Key
Source§fn add_assign(&mut self, rhs: u8)
fn add_assign(&mut self, rhs: u8)
Performs the
+= operation. Read moreSource§impl Ord for Key
impl Ord for Key
Source§impl PartialOrd for Key
impl PartialOrd for Key
Source§impl SubAssign<u8> for Key
impl SubAssign<u8> for Key
Source§fn sub_assign(&mut self, rhs: u8)
fn sub_assign(&mut self, rhs: u8)
Performs the
-= operation. Read moreimpl Copy for Key
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more