Struct tune::key::PianoKey[][src]

pub struct PianoKey { /* fields omitted */ }

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]

Iterates over all PianoKeys 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]

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

impl Ord for PianoKey[src]

impl PartialEq<PianoKey> for PianoKey[src]

impl PartialOrd<PianoKey> for PianoKey[src]

impl StructuralEq for PianoKey[src]

impl StructuralPartialEq for PianoKey[src]

impl<S: Borrow<Scl>, K: Borrow<KbmRoot>> Tuning<PianoKey> for (S, K)[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.