pub trait KeyboardMapping<K> {
    // Required method
    fn maybe_pitch_of(&self, key: K) -> Option<Pitch>;
}
Expand description

Similar to a Tuning but not designed to be surjective or injecive.

An inversion operation is not provided. In return, zero or multiple keys/notes can point to a Pitch.

Required Methods§

source

fn maybe_pitch_of(&self, key: K) -> Option<Pitch>

Returns the Pitch of the provided key or note.

Implementations on Foreign Types§

source§

impl<K, T: KeyboardMapping<K> + ?Sized> KeyboardMapping<K> for &T

impl forwarding for references.

source§

fn maybe_pitch_of(&self, key: K) -> Option<Pitch>

source§

impl<S: Borrow<Scl>, K: Borrow<Kbm>> KeyboardMapping<i32> for (S, K)

source§

fn maybe_pitch_of(&self, mapping_degree: i32) -> Option<Pitch>

source§

impl<S: Borrow<Scl>, K: Borrow<Kbm>> KeyboardMapping<PianoKey> for (S, K)

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

Implementors§