[][src]Enum tonality::tpc::Tpc

#[must_use]pub enum Tpc {
    Fbb,
    Cbb,
    Gbb,
    Dbb,
    Abb,
    Ebb,
    Bbb,
    Fb,
    Cb,
    Gb,
    Db,
    Ab,
    Eb,
    Bb,
    F,
    C,
    G,
    D,
    A,
    E,
    B,
    Fs,
    Cs,
    Gs,
    Ds,
    As,
    Es,
    Bs,
    Fss,
    Css,
    Gss,
    Dss,
    Ass,
    Ess,
    Bss,
}

Tonal pitch class

Has variants for all pitch classes with double or single flats, natural, double or single sharps. The numeric value of the enum corresponds to steps away from C on the "line of fifths". For instance, F is one fifth below C and has the value -1.

Note that the "s" and "ss" suffixes mean sharp and double sharp. Should not be confused with the names of flat notes, which in some languages use the -s suffix.

Variants

Fbb
Cbb
Gbb
Dbb
Abb
Ebb
Bbb
Fb
Cb
Gb
Db
Ab
Eb
Bb
F
C
G
D
A
E
B
Fs
Cs
Gs
Ds
As
Es
Bs
Fss
Css
Gss
Dss
Ass
Ess
Bss

Implementations

impl Tpc[src]

pub const MAX: Tpc[src]

The sharpest valid Tpc: B double sharp

pub const MIN: Tpc[src]

The flattest valid Tpc: F double flat

pub fn step(self) -> Step[src]

The basic step of the Tpc, or where it is placed on the staff

assert_eq!(Step::C, Tpc::C.step());
assert_eq!(Step::C, Tpc::Cs.step());
assert_eq!(Tpc::Gb.step(), Tpc::Gs.step());

#[must_use]pub fn alteration(self, key: Key) -> Alteration[src]

The number of semitones by which the tpc is altered with respect to the key

Example

// C natural is not altered in the key of A flat
assert_eq!(0, Tpc::C.alteration(Key::Ab));
// A major has C sharp, so a C natural is one semitone flat
assert_eq!(-1, Tpc::C.alteration(Key::A));
// Db major has A flat, so an A sharp is two semitones sharp
assert_eq!(2, Tpc::As.alteration(Key::Db));

pub fn altered_step(self, key: Option<Key>) -> (Step, Option<Accidental>)[src]

Find the appropriate accidental for the Tpc in a key.

If no key is given, default to C major with no fixed accidentals

Example

let tpc = Tpc::C;
let key: Option<Key> = None;
assert_eq!((Step::C, None), tpc.altered_step(key));

let key: Option<Key> = Some(Key::A);
assert_eq!((Step::C, Some(Accidental::Natural)), tpc.altered_step(key));

let tpc = Tpc::Fss;
let key: Option<Key> = None;
assert_eq!((Step::F, Some(Accidental::DblSharp)), tpc.altered_step(key));

#[must_use]pub fn alter(self, by: Alteration) -> Option<Tpc>[src]

Adjust alteration while maintaining the step value

Returns None if the alteration would be sharper than double sharp or flatter than double flat

assert_eq!(Some(Tpc::Gs), Tpc::G.alter(1));
assert_eq!(None, Tpc::Bbb.alter(-1));
assert_eq!(Some(Tpc::Abb), Tpc::As.alter(-3));

#[must_use]pub fn enharmonic(self, other: Tpc) -> bool[src]

Whether the two tpcs are enharmonic, i.e. represent the same pitch class in twelve tone equal temperament.

This relation applies even to tpcs which doesn't have a valid interval between them, such as Abb and Fss.

assert!(Tpc::Gs.enharmonic(Tpc::Ab));
assert!(Tpc::Fs.enharmonic(Tpc::Ess));
assert!(Tpc::Abb.enharmonic(Tpc::Fss));
assert!(!Tpc::Fs.enharmonic(Tpc::F));

Trait Implementations

impl Add<Interval> for Tpc[src]

type Output = Option<Tpc>

The resulting type after applying the + operator.

impl Clone for Tpc[src]

impl Copy for Tpc[src]

impl Debug for Tpc[src]

impl Eq for Tpc[src]

impl From<Tpc> for Step[src]

impl FromPrimitive for Tpc[src]

impl Ord for Tpc[src]

impl PartialEq<Tpc> for Tpc[src]

impl PartialOrd<Tpc> for Tpc[src]

impl StructuralEq for Tpc[src]

impl StructuralPartialEq for Tpc[src]

impl Sub<Interval> for Tpc[src]

type Output = Option<Tpc>

The resulting type after applying the - operator.

impl Sub<Tpc> for Tpc[src]

type Output = Option<Interval>

The resulting type after applying the - operator.

Auto Trait Implementations

impl RefUnwindSafe for Tpc

impl Send for Tpc

impl Sync for Tpc

impl Unpin for Tpc

impl UnwindSafe for Tpc

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.