Trait tune::pitch::Pitched

source ·
pub trait Pitched {
    // Required method
    fn pitch(&self) -> Pitch;

    // Provided method
    fn find_in_tuning<K, T: Tuning<K>>(&self, tuning: T) -> Approximation<K> { ... }
}
Expand description

Objects which have a Pitch assigned.

Required Methods§

source

fn pitch(&self) -> Pitch

Retrieves the Pitch of the Pitched object.

Examples
use tune::pitch::Pitched;

assert_approx_eq!(Pitch::from_hz(123.456).pitch().as_hz(), 123.456);
assert_approx_eq!(NoteLetter::A.in_octave(5).pitch().as_hz(), 880.0);

Provided Methods§

source

fn find_in_tuning<K, T: Tuning<K>>(&self, tuning: T) -> Approximation<K>

Finds a key or note for any Pitched object in the given tuning.

Examples
use tune::pitch::Pitched;

let a4 = NoteLetter::A.in_octave(4);
let tuning = ConcertPitch::from_a4_pitch(Pitch::from_hz(432.0));

let approximation = a4.find_in_tuning(tuning);
assert_eq!(approximation.approx_value, a4);
assert_approx_eq!(approximation.deviation.as_cents(), 31.766654);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<K: Copy, T: Tuning<K> + ?Sized> Pitched for (K, T)

A key or note K paired with an appropriate Tuning<K> is considered Pitched.

Examples

use tune::pitch::Pitched;

let concert_pitch = ConcertPitch::from_a4_pitch(Pitch::from_hz(432.0));
assert_approx_eq!((NoteLetter::A.in_octave(5), concert_pitch).pitch().as_hz(), 864.0);
source§

fn pitch(&self) -> Pitch

Implementors§