Struct music_theory::theory::chord::RootedChord
source · 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
impl RootedChord
sourcepub fn new(root: Note, intervals: &[Note]) -> Self
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]);
sourcepub fn from_chord(root: Note, chord: Chord) -> Self
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]);
sourcepub fn as_scale(&self) -> Scale
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]);
sourcepub fn to_scale(self) -> Scale
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]);
sourcepub fn normalized(self) -> Self
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])
}
);
sourcepub fn as_chordtone_wholetone_scale(&self) -> Option<Scale>
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()
);
sourcepub fn as_inversion(&self) -> Self
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(),
);
sourcepub fn to_inversion(self) -> Self
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(),
);
sourcepub fn as_all_inversions(&self) -> Vec<Self>
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(),
]
);
sourcepub fn to_all_inversions(self) -> Vec<Self>
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(),
]
);
sourcepub fn as_string(&self, style: ChordStyle) -> String
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
impl AsSubs for RootedChord
source§impl Clone for RootedChord
impl Clone for RootedChord
source§fn clone(&self) -> RootedChord
fn clone(&self) -> RootedChord
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RootedChord
impl Debug for RootedChord
source§impl Default for RootedChord
impl Default for RootedChord
source§fn default() -> RootedChord
fn default() -> RootedChord
source§impl Hash for RootedChord
impl Hash for RootedChord
source§impl Ord for RootedChord
impl Ord for RootedChord
source§fn cmp(&self, other: &RootedChord) -> Ordering
fn cmp(&self, other: &RootedChord) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<RootedChord> for RootedChord
impl PartialEq<RootedChord> for RootedChord
source§fn eq(&self, other: &RootedChord) -> bool
fn eq(&self, other: &RootedChord) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<RootedChord> for RootedChord
impl PartialOrd<RootedChord> for RootedChord
source§fn partial_cmp(&self, other: &RootedChord) -> Option<Ordering>
fn partial_cmp(&self, other: &RootedChord) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more