Struct music_theory::theory::chord::Chord
source · pub struct Chord(pub Vec<Note>);
Expand description
A Chord
only encodes the quality of the the chord.
No root from which it is build is defined.
Example:
use music_theory::theory::*;
let chord = Chord::new(&MAJOR);
assert!(chord.contains_all(&POWER));
Tuple Fields§
§0: Vec<Note>
Implementations§
source§impl Chord
impl Chord
sourcepub fn new(intervals: &[Note]) -> Self
pub fn new(intervals: &[Note]) -> Self
Create a chord from an array of unsigned note intervals.
Example:
use music_theory::theory::*;
let chord = Chord::new(&MAJOR);
assert!(chord.contains_all(&POWER));
sourcepub fn same_intervals(&self, blueprint: &[Note]) -> bool
pub fn same_intervals(&self, blueprint: &[Note]) -> bool
Returns true if the blueprint is the same as the inner wrapper value.
Example:
use music_theory::theory::*;
let chord = Chord::new(&MAJOR);
assert!(chord.same_intervals(&MAJOR));
sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
Returns a normalised version of the chord. Intervals will be mapped into one octave (from Z to Z_12). The intervals will also be sorted duplicates will be removed. This means any form of voicing will be lost and the core quality will remain.
Example:
use music_theory::theory::*;
use interval::note_interval as ni;
assert_eq!(
Chord::new(&[ni::MAJ2, ni::MAJ3, ni::PER5, ni::MAJ7, ni::MAJ9, ni::PER5])
.normalized().unwrap(),
vec![ni::MAJ2, ni::MAJ3, ni::PER5, ni::MAJ7]
);
sourcepub fn quality(&self, basestr: String, style: ChordStyle) -> String
pub fn quality(&self, basestr: String, style: ChordStyle) -> String
Returns the quality of a chord as a string. Takes a ChordStyle to determine the formatting style. The base string is a prefix to the stringified quality. The algorithm works with normalised chords and does not take into account voicing, it aims to determine the core quality of the chord. It is not an exhaustive search style or optimalisation style algorithm and may not produce the very best quality you could assign to the input.
Example:
use music_theory::theory::*;
let std = ChordStyle::Std(MStyle::Symbol, EStyle::Symbol);
let base = String::from("BASESTRING");
assert_eq!(&Chord::new(&MINOR_MAJOR_SEVENTH).quality(base, std), "BASESTRING-Δ");
sourcepub fn as_string(&self, style: ChordStyle) -> String
pub fn as_string(&self, style: ChordStyle) -> String
Stringify the chord
Example:
use music_theory::theory::*;
let std = ChordStyle::Std(MStyle::Symbol, EStyle::Symbol);
assert_eq!(&Chord::new(&MINOR_MAJOR_SEVENTH).as_string(std), "X-Δ");
Trait Implementations§
source§impl Ord for Chord
impl Ord for Chord
source§impl PartialEq<Chord> for Chord
impl PartialEq<Chord> for Chord
source§impl PartialOrd<Chord> for Chord
impl PartialOrd<Chord> for Chord
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