[−][src]Struct tonal::Pitch
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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Pitch
[src]
fn cmp(&self, other: &Pitch) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Pitch> for Pitch
[src]
impl PartialOrd<Pitch> for Pitch
[src]
fn partial_cmp(&self, other: &Pitch) -> Option<Ordering>
[src]
fn lt(&self, other: &Pitch) -> bool
[src]
fn le(&self, other: &Pitch) -> bool
[src]
fn gt(&self, other: &Pitch) -> bool
[src]
fn ge(&self, other: &Pitch) -> bool
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,