Struct tune::key::PianoKey [−][src]
A physical or logical key on a real or virtual instrument without any notion of a pitch.
This struct does not represent a musical key, like in “F minor”, which is why its name is PianoKey
.
Implementations
impl PianoKey
[src]
pub fn from_midi_number(midi_number: impl Into<i32>) -> Self
[src]
Creates a PianoKey
instance from the given MIDI number.
pub fn midi_number(self) -> i32
[src]
Returns the MIDI number of this PianoKey
.
pub fn checked_midi_number(self) -> Option<u8>
[src]
Returns the MIDI number of this PianoKey
if it is in the valid MIDI range [0..128).
Examples
assert_eq!(PianoKey::from_midi_number(-1).checked_midi_number(), None); assert_eq!(PianoKey::from_midi_number(0).checked_midi_number(), Some(0)); assert_eq!(PianoKey::from_midi_number(64).checked_midi_number(), Some(64)); assert_eq!(PianoKey::from_midi_number(127).checked_midi_number(), Some(127)); assert_eq!(PianoKey::from_midi_number(128).checked_midi_number(), None);
pub fn keys_before(
self,
upper_bound: PianoKey
) -> impl DoubleEndedIterator<Item = PianoKey> + ExactSizeIterator<Item = PianoKey> + 'static
[src]
self,
upper_bound: PianoKey
) -> impl DoubleEndedIterator<Item = PianoKey> + ExactSizeIterator<Item = PianoKey> + 'static
Iterates over all PianoKey
s in the range [self
, upper_bound
).
Examples
let midi_key_62 = PianoKey::from_midi_number(62); let midi_key_67 = PianoKey::from_midi_number(67); assert_eq!( midi_key_62.keys_before(midi_key_67).collect::<Vec<_>>(), (62..67).map(PianoKey::from_midi_number).collect::<Vec<_>>() ); assert!(midi_key_67.keys_before(midi_key_62).collect::<Vec<_>>().is_empty());
pub fn num_keys_before(self, other: PianoKey) -> i32
[src]
Counts the number of keys [left inclusive, right exclusive) between self
and other
.
Examples
let midi_key_62 = PianoKey::from_midi_number(62); let midi_key_67 = PianoKey::from_midi_number(67); assert_eq!(midi_key_62.num_keys_before(midi_key_67), 5); assert_eq!(midi_key_67.num_keys_before(midi_key_62), -5);
pub fn plus_steps(self, num_steps: i32) -> PianoKey
[src]
Returns the key num_steps
steps after self
.
Examples
let midi_key_62 = PianoKey::from_midi_number(62); let midi_key_67 = PianoKey::from_midi_number(67); assert_eq!(midi_key_62.plus_steps(5), midi_key_67); assert_eq!(midi_key_67.plus_steps(-5), midi_key_62);
Trait Implementations
impl Clone for PianoKey
[src]
impl Copy for PianoKey
[src]
impl Debug for PianoKey
[src]
impl Eq for PianoKey
[src]
impl Hash for PianoKey
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<S: Borrow<Scl>, K: Borrow<Kbm>> KeyboardMapping<PianoKey> for (S, K)
[src]
An (Scl
, Kbm
) pair has the complete information to define a KeyboardMapping
.
Examples
use tune::tuning::KeyboardMapping; let scl = Scl::builder() .push_cents(100.0) .build() .unwrap(); let kbm = Kbm::builder(Note::from_midi_number(62)) .push_mapped_key(0) .push_mapped_key(4) .push_unmapped_key() .push_mapped_key(4) .formal_octave(12) .build() .unwrap(); let f = |midi_number| (&scl, &kbm).maybe_pitch_of(PianoKey::from_midi_number(midi_number)); assert_approx_eq!(f(62).unwrap().as_hz(), 293.664768); assert_approx_eq!(f(63).unwrap().as_hz(), 369.994423); assert!(f(64).is_none()); assert_approx_eq!(f(65).unwrap().as_hz(), 369.994423); assert_approx_eq!(f(66).unwrap().as_hz(), 587.329536);
fn maybe_pitch_of(&self, key: PianoKey) -> Option<Pitch>
[src]
impl Ord for PianoKey
[src]
fn cmp(&self, other: &PianoKey) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<PianoKey> for PianoKey
[src]
impl PartialOrd<PianoKey> for PianoKey
[src]
fn partial_cmp(&self, other: &PianoKey) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for PianoKey
[src]
impl StructuralPartialEq for PianoKey
[src]
impl<S: Borrow<Scl>, K: Borrow<KbmRoot>> Tuning<PianoKey> for (S, K)
[src]
fn pitch_of(&self, key: PianoKey) -> Pitch
[src]
fn find_by_pitch(&self, pitch: Pitch) -> Approximation<PianoKey>
[src]
fn as_linear_mapping(self) -> LinearMapping<Self> where
Self: Sized,
[src]
Self: Sized,
Auto Trait Implementations
impl RefUnwindSafe for PianoKey
impl Send for PianoKey
impl Sync for PianoKey
impl Unpin for PianoKey
impl UnwindSafe for PianoKey
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,