pub trait Tuning<K> {
// Required methods
fn pitch_of(&self, key: K) -> Pitch;
fn find_by_pitch(&self, pitch: Pitch) -> Approximation<K>;
// Provided method
fn as_linear_mapping(self) -> LinearMapping<Self>
where Self: Sized { ... }
}
Required Methods§
sourcefn find_by_pitch(&self, pitch: Pitch) -> Approximation<K>
fn find_by_pitch(&self, pitch: Pitch) -> Approximation<K>
Finds a closest key or note Approximation
for the given Pitch
in the current Tuning
.
Examples
use tune::tuning::Tuning;
let standard_tuning = ConcertPitch::default();
let a5 = NoteLetter::A.in_octave(5);
let detuned_a5_pitch = Pitch::of(a5) * Ratio::from_cents(10.0);
let approximation = standard_tuning.find_by_pitch(detuned_a5_pitch);
assert_eq!(approximation.approx_value, a5);
assert_approx_eq!(approximation.deviation.as_cents(), 10.0);
Provided Methods§
sourcefn as_linear_mapping(self) -> LinearMapping<Self>where
Self: Sized,
fn as_linear_mapping(self) -> LinearMapping<Self>where
Self: Sized,
Wraps self
in a type adapter s.t. it can be used in functions that are generic over KeyboardMapping<K>
.
Implementations on Foreign Types§
source§impl Tuning<Note> for ()
impl Tuning<Note> for ()
Convenience implementation enabling to write ()
instead of ConcertPitch::default()
.
Examples
use tune::pitch::Pitched;
assert_eq!(Pitch::from_hz(880.0).find_in_tuning(()).approx_value, Note::from_midi_number(81));
source§impl<K, T: Tuning<K> + ?Sized> Tuning<K> for &T
impl<K, T: Tuning<K> + ?Sized> Tuning<K> for &T
impl
forwarding for references.
fn pitch_of(&self, key: K) -> Pitch
fn find_by_pitch(&self, pitch: Pitch) -> Approximation<K>
Implementors§
impl Tuning<Note> for ConcertPitch
A ConcertPitch
maps Note
s to Pitch
es and is considered a Tuning
.
Examples
use tune::tuning::Tuning;
let c4 = NoteLetter::C.in_octave(4);
let a4 = NoteLetter::A.in_octave(4);
let standard_tuning = ConcertPitch::default();
assert_approx_eq!(standard_tuning.pitch_of(c4).as_hz(), 261.625565);
assert_approx_eq!(standard_tuning.pitch_of(a4).as_hz(), 440.0);
let healing_tuning = ConcertPitch::from_a4_pitch(Pitch::from_hz(432.0));
assert_approx_eq!(healing_tuning.pitch_of(c4).as_hz(), 256.868737);
assert_approx_eq!(healing_tuning.pitch_of(a4).as_hz(), 432.0);