Trait tune::tuning::Tuning

source ·
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 { ... }
}
Expand description

A Tuning maps keys or notes of type K to a Pitch or vice versa.

Required Methods§

source

fn pitch_of(&self, key: K) -> Pitch

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

Examples
use tune::tuning::Tuning;

let standard_tuning = ConcertPitch::default();
let a5 = NoteLetter::A.in_octave(5);

assert_approx_eq!(standard_tuning.pitch_of(a5).as_hz(), 880.0);
source

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§

source

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

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§

fn pitch_of(&self, note: Note) -> Pitch

source§

fn find_by_pitch(&self, pitch: Pitch) -> Approximation<Note>

source§

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

impl forwarding for references.

source§

fn pitch_of(&self, key: K) -> Pitch

source§

fn find_by_pitch(&self, pitch: Pitch) -> Approximation<K>

source§

impl<S: Borrow<Scl>, K: Borrow<KbmRoot>> Tuning<i32> for (S, K)

source§

fn pitch_of(&self, degree: i32) -> Pitch

source§

fn find_by_pitch(&self, pitch: Pitch) -> Approximation<i32>

source§

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

Implementors§

source§

impl Tuning<Note> for ConcertPitch

A ConcertPitch maps Notes to Pitches 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);
source§

impl<S: Scale> Tuning<i32> for SortedTuning<S>