[][src]Struct tonal::Pitch

pub struct Pitch(pub i32);

Represents a musical pitch.

The pitch is stored as the number of half steps away from A4. It is valid to use the tuple constructor to create a pitch directly. In fact, this allows doing math on notes for programatic contruction of music.

The implementation of Default produces A4.

Implementations

impl Pitch[src]

pub fn new(name: Name, octave: u8) -> Self[src]

Creates a new pitch with the given note name and octave.

Examples

use tonal::*;

let a4 = Pitch::new(Name::A, 4);
assert_eq!(a4, Pitch::default());
let c3 = Pitch::new(Name::C, 3);
assert_eq!(c3, Pitch(-21));

pub fn new_from_freq(freq: f64) -> Self[src]

Creates a new pitch from the given frequency in hertz.

Because this function uses floating point math, there is a small chance the result might be off.

Panics

Panics if freq is not greater than 0.

Examples

use tonal::*;

let a4 = Pitch::new_from_freq(440.0);
assert_eq!(a4, Pitch::new(Name::A, 4));
let c3 = Pitch::new_from_freq(130.81);
assert_eq!(c3, Pitch::new(Name::C, 3));

This example will panic when run:

This example panics
use tonal::*;

let invalid = Pitch::new_from_freq(0.0);

pub fn freq(self) -> f64[src]

Calculates the frequency in hertz.

Examples

use tonal::*;

let a4 = Pitch::default();
assert!((a4.freq() - 440.0).abs() < std::f64::EPSILON);

Trait Implementations

impl Clone for Pitch[src]

impl Copy for Pitch[src]

impl Debug for Pitch[src]

impl Default for Pitch[src]

impl Eq for Pitch[src]

impl Hash for Pitch[src]

impl Ord for Pitch[src]

impl PartialEq<Pitch> for Pitch[src]

impl PartialOrd<Pitch> for Pitch[src]

impl StructuralEq for Pitch[src]

impl StructuralPartialEq for Pitch[src]

Auto Trait Implementations

impl RefUnwindSafe for Pitch

impl Send for Pitch

impl Sync for Pitch

impl Unpin for Pitch

impl UnwindSafe for Pitch

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.