pub struct RootedChord {
    pub root: Note,
    pub chord: Chord,
}
Expand description

Wrapper around Chord. Also has a root note and extra functionality around that.

Example:

use music_theory::theory::*;
let chord = RootedChord::new(Note::C2, &MAJOR);
assert_eq!(chord.to_scale().unwrap(), vec![Note::C2, Note::E2, Note::G2]);

Fields§

§root: Note

The root note from which the chord is build.

§chord: Chord

The quality of the chord.

Implementations§

source§

impl RootedChord

source

pub fn new(root: Note, intervals: &[Note]) -> Self

Create an new RootedChord from a root note and some unsigned intervals.

Example:

use music_theory::theory::*;
let chord = RootedChord::new(Note::C2, &MAJOR);
assert_eq!(chord.to_scale().unwrap(), vec![Note::C2, Note::E2, Note::G2]);
source

pub fn from_chord(root: Note, chord: Chord) -> Self

Create an RootedChord from a root note and a chord.

Example:

use music_theory::theory::*;
let chord = RootedChord::from_chord(Note::C2, Chord::new(&MAJOR));
assert_eq!(chord.to_scale().unwrap(), vec![Note::C2, Note::E2, Note::G2]);
source

pub fn as_scale(&self) -> Scale

Convert the RootedChord to a Scale.

Example:

use music_theory::theory::*;
let chord = RootedChord::new(Note::C2, &MAJOR);
assert_eq!(chord.as_scale().unwrap(), vec![Note::C2, Note::E2, Note::G2]);
source

pub fn to_scale(self) -> Scale

Ownership taking version of as_scale.

Example:

use music_theory::theory::*;
let chord = RootedChord::new(Note::C2, &MAJOR);
assert_eq!(chord.to_scale().unwrap(), vec![Note::C2, Note::E2, Note::G2]);
source

pub fn normalized(self) -> Self

Returns a normalised version of the RootedChord.

Example:

use music_theory::theory::*;
use interval::note_interval as ni;
assert_eq!(
    RootedChord::new(Note::C1, &[ni::MAJ2, ni::MAJ3, ni::PER5, ni::MAJ7, ni::MAJ9, ni::PER5])
        .normalized(),
    RootedChord{
        root: Note::C0,
        chord: Chord::new(&[ni::MAJ2, ni::MAJ3, ni::PER5, ni::MAJ7])
    }
);
source

pub fn as_chordtone_wholetone_scale(&self) -> Option<Scale>

Attempts to find a chordtone wholetone scale for the RootedChord.

Example:

use music_theory::theory::*;
assert_eq!(
    RootedChord::new(Note::F1, MAJOR_SEVENTH_CHORD).as_chordtone_wholetone_scale(),
    Some(Scale::wrap(
        vec![Note::F1, Note::G1, Note::A2, Note::B2, Note::C2, Note::D2, Note::E2]
    )).unwrap()
);
source

pub fn as_inversion(&self) -> Self

Returns a RootedChord that is the next inversion of the current one.

Example:

use music_theory::theory::*;
assert_eq!(
    Scale::wrap(vec![Note::A1, Note::C1, Note::E1, Note::G1])
        .unwrap().as_rooted_chord().to_inversion(),
    Scale::wrap(vec![Note::C1, Note::E1, Note::G1, Note::A2])
        .unwrap().as_rooted_chord(),
);
source

pub fn to_inversion(self) -> Self

Ownership taking version of as_inversion.

Example:

use music_theory::theory::*;
assert_eq!(
    Scale::wrap(vec![Note::A1, Note::C1, Note::E1, Note::G1])
        .unwrap().to_rooted_chord().to_inversion(),
    Scale::wrap(vec![Note::C1, Note::E1, Note::G1, Note::A2])
        .unwrap().to_rooted_chord(),
);
source

pub fn as_all_inversions(&self) -> Vec<Self>

Returns a vector of all inversions of the RootedChord.

Example:

use music_theory::theory::*;
assert_eq!(
    Scale::wrap(vec![Note::A1, Note::C1, Note::E1, Note::G1])
        .unwrap().to_rooted_chord().as_all_inversions(),
    vec![
        Scale::wrap(vec![Note::C1, Note::E1, Note::G1, Note::A2]).unwrap().to_rooted_chord(),
        Scale::wrap(vec![Note::E1, Note::G1, Note::A1, Note::C2]).unwrap().to_rooted_chord(),
        Scale::wrap(vec![Note::G1, Note::A2, Note::C2, Note::E2]).unwrap().to_rooted_chord(),
        Scale::wrap(vec![Note::A2, Note::C2, Note::E2, Note::G2]).unwrap().to_rooted_chord(),
    ]
);
source

pub fn to_all_inversions(self) -> Vec<Self>

Ownership taking version of as_all_inversions.

Example:

use music_theory::theory::*;
assert_eq!(
    Scale::wrap(vec![Note::A1, Note::C1, Note::E1, Note::G1])
        .unwrap().to_rooted_chord().to_all_inversions(),
    vec![
        Scale::wrap(vec![Note::C1, Note::E1, Note::G1, Note::A2]).unwrap().to_rooted_chord(),
        Scale::wrap(vec![Note::E1, Note::G1, Note::A1, Note::C2]).unwrap().to_rooted_chord(),
        Scale::wrap(vec![Note::G1, Note::A2, Note::C2, Note::E2]).unwrap().to_rooted_chord(),
        Scale::wrap(vec![Note::A2, Note::C2, Note::E2, Note::G2]).unwrap().to_rooted_chord(),
    ]
);
source

pub fn as_string(&self, style: ChordStyle) -> String

Stringify the RootedChord.

Example:

use music_theory::theory::*;
let std = ChordStyle::Std(MStyle::Symbol, EStyle::Symbol);
assert_eq!(&RootedChord::new(Note::C2, &MINOR_MAJOR_SEVENTH).as_string(std), "C-Δ");

Trait Implementations§

source§

impl AsSubs for RootedChord

source§

fn as_subs(&self, max_len: Option<usize>) -> Vec<Self>

Generate all subs sets with optional maximal subset length. The output size of this grows really fast with the input size so be aware: 2, 5, 16, 65, 326, 1957, 13700, 109601, 986410, 9864101, 108505112.
source§

impl Clone for RootedChord

source§

fn clone(&self) -> RootedChord

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RootedChord

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for RootedChord

source§

fn default() -> RootedChord

Returns the “default value” for a type. Read more
source§

impl Hash for RootedChord

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for RootedChord

source§

fn cmp(&self, other: &RootedChord) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<RootedChord> for RootedChord

source§

fn eq(&self, other: &RootedChord) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<RootedChord> for RootedChord

source§

fn partial_cmp(&self, other: &RootedChord) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for RootedChord

source§

impl StructuralEq for RootedChord

source§

impl StructuralPartialEq for RootedChord

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.