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

source

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));
source

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));
source

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]
);
source

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-Δ");
source

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 AsScale for Chord

source§

fn as_scale(&self, root: Note) -> Scale

Borrow self and return Scale. Note is either the root of the scale or the octave.
source§

impl AsSubs for Chord

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 Chord

source§

fn clone(&self) -> Chord

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 Chord

source§

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

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

impl Default for Chord

source§

fn default() -> Chord

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

impl Hash for Chord

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 Index<usize> for Chord

§

type Output = Note

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Chord

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl Ord for Chord

source§

fn cmp(&self, other: &Chord) -> 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<Chord> for Chord

source§

fn eq(&self, other: &Chord) -> 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<Chord> for Chord

source§

fn partial_cmp(&self, other: &Chord) -> 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 VecWrapper for Chord

§

type Item = Note

The type the new type wraps.
source§

fn len(&self) -> usize

Return the length of the inner vector.
source§

fn is_empty(&self) -> bool

Return whether the inner vector is empty or not.
source§

fn iter(&self) -> Iter<'_, Self::Item>

Iterate over the inner vector.
source§

fn contains(&self, item: &Self::Item) -> bool

Returns whether the inner vector contains an item.
source§

fn contains_all(&self, items: &[Self::Item]) -> bool

Returns whether the inner vector contains all of the given items.
source§

fn contains_any(&self, items: &[Self::Item]) -> bool

Returns whether the inner vector contains any of the given items.
source§

impl Wrapper for Chord

§

type Inner = Vec<Note, Global>

The type the new type wraps.
source§

fn wrap(scale: Self::Inner) -> Option<Self>

Try to wrap a Self::Inner type into the Self type.
source§

fn unwrap(self) -> Self::Inner

Unwrap a Self type into a Self::Inner type.
source§

impl Eq for Chord

source§

impl StructuralEq for Chord

source§

impl StructuralPartialEq for Chord

Auto Trait Implementations§

§

impl RefUnwindSafe for Chord

§

impl Send for Chord

§

impl Sync for Chord

§

impl Unpin for Chord

§

impl UnwindSafe for Chord

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> ToScale for Twhere T: AsScale,

source§

fn to_scale(self, note: Note) -> Scale

Take self and return Scale. Note is either the root of the scale or the octave.
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.