pub struct PianoKey { /* private fields */ }
Expand description

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

Creates a PianoKey instance from the given MIDI number.

Returns the MIDI number of this PianoKey.

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

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

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

Returns the Pitch of the provided key or note.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the Pitch of the given key or note K in the current Tuning. Read more

Finds a closest key or note Approximation for the given Pitch in the current Tuning. Read more

Wraps self in a type adapter s.t. it can be used in functions that are generic over KeyboardMapping<K>.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.