Options
All
  • Public
  • Public/Protected
  • All
Menu

Chords consist of a root note, octave, chord template, and a base scale.

The chord template is an array of integers, each integer representing
a scale degree from the base scale(defaults to major).
The default template is the I,III,V denoted as [1,3,5]
ChordIntervals used in templates can also contain a modifier,
for a particular scale degree, such as [1,3,[5, -1]]
where -1 is flat, 0 is natural, and 1 is sharp.
It could also be written as [1,3,[5, modifier.flat]]
if you import modifier.

The following predefined templates are available:

maj maj4 maj6 maj69
maj7 maj9 maj11 maj13
maj7s11 majb5 min min4
min6 min7 minAdd9 min69
min9 min11 min13 min7b5
dom7 dom9 dom11 dom13
dom7s5 dom7b5 dom7s9 dom7b9
dom9b5 dom9s5 dom7s11 dom7s5s9
dom7s5b9 dim dim7 aug
sus2 sus4 fifth b5
s11
example
import { Chord } from "musictheoryjs";
import {ChordTemplate} from "musictheoryjs";
import {ChordInterval} from "musictheoryjs";
import {Modifier} from "musictheoryjs";
import {ChordInitializer} from "musictheoryjs";// Typescript only if needed

Hierarchy

  • Chord

Implements

  • Entity

Index

Constructors

constructor

  • example
    import { Chord, ChordTemplates, Modifier } from "musictheoryjs";

    //creates a chord with the default(1,3,5) template, root of C, in the 4th octave
    const chord = new Chord();

    // creates a chord with the pre-defined diminished template, root of Eb, in the 5th octave
    const chord = new Chord({root: 3, octave: 5, template: ChordTemplates.dim});

    // String parsing should follow the format: (root-note-name[s,#,b][octave])[chord-template-name|[chord-quality][modifiers]]
    // creates a chord from a string
    const chord = new Chord('(D4)min4');

    Parameters

    Returns Chord

Properties

id

id: string = ...

unique id for this instance

example
const chord = new Chord();
console.log(chord.id); // hal8934hll

Accessors

baseScale

  • get baseScale(): Scale
  • set baseScale(value: Scale): void
  • example
    const chord = new Chord();
    console.log(chord.baseScale); // prints the default scale(major)

    Returns Scale

  • Not a lot of good reasons to change this except for experimentation

    example
    const chord = new Chord();
    chord.baseScale = new Scale({ key: 3, octave: 5, template: [1, [3, Modifier.flat], 5] });
    console.log(chord.baseScale); // prints the minor scale

    Parameters

    Returns void

notes

  • will generate notes if needed or return the cached notes

    example
    const chord = new Chord();
    console.log(chord.notes); // prints the default notes

    Returns Note[]

octave

  • get octave(): number
  • set octave(value: number): void
  • The octave is clamped to the range [0, 9].

    example
    const chord = new Chord();
    console.log(chord.octave); // 4(octave)

    Returns number

  • The octave is clamped to the range [0, 9].

    example
    const chord = new Chord();
    chord.octave = 5; // sets the octave to 5th
    console.log(chord.octave); // 5(octave)

    Parameters

    • value: number

    Returns void

root

  • example
    const chord = new Chord();
    console.log(chord.root); // 0(semitone)

    Returns Semitone

  • Setting the root to a value outside of the range 0, 11 will
    wrap the semitone to the range [0, 11] and change the octave depending
    on how many times the semitone has been wrapped.

    example
    const chord = new Chord();
    chord.root = 4; // sets the root to 4th semitone(E)
    console.log(chord.root); // 4(semitone)

    Parameters

    Returns void

template

  • example
    const chord = new Chord();
    console.log(chord.template); // prints the default template

    Returns ChordInterval[]

  • The following predefined templates are available:

    maj maj4 maj6 maj69
    maj7 maj9 maj11 maj13
    maj7s11 majb5 min min4
    min6 min7 minAdd9 min69
    min9 min11 min13 min7b5
    dom7 dom9 dom11 dom13
    dom7s5 dom7b5 dom7s9 dom7b9
    dom9b5 dom9s5 dom7s11 dom7s5s9
    dom7s5b9 dim dim7 aug
    sus2 sus4 fifth b5
    s11
    example
    const chord = new Chord();
    chord.template = [1, [3, Modifier.flat], 5]; // sets the template to a minor chord
    console.log(chord.template); // prints the new template

    Parameters

    Returns void

Methods

augment

  • Mutates the chord in place

    chainable
    example
    const chord = new Chord();
    chord.augment();
    console.log(chord.template); // [1, 3, [5, Modifier.sharp]]

    Returns Chord

    the chord with a sharp 5th

augmented

  • chainable
    example
    const chord = new Chord();
    const copy = chord.augmented();
    console.log(copy.template); // [1, 3, [5, Modifier.sharp]]

    Returns Chord

    a copy of the chord with a sharp 5th

copy

  • chainable
    example
    const chord = new Chord();
    const copy = chord.copy();
    console.log(chord.equals(copy)); // true

    Returns Chord

    a copy of the chord

diminish

  • Mutates the chord in place

    chainable
    example
    const chord = new Chord();
    chord.diminish();
    console.log(chord.template); // [1, 3, [5, Modifier.flat]]

    Returns Chord

    the chord with a flat 5th

diminished

  • chainable
    example
    const chord = new Chord();
    const copy = chord.diminished();
    console.log(copy.template); // [1, 3, [5, Modifier.flat]]

    Returns Chord

    a copy of the chord with a flat 5th

equals

  • equals(other: Chord): boolean
  • example
    const chord = new Chord();
    const copy = chord.copy();
    console.log(chord.equals(copy)); // true

    Parameters

    • other: Chord

      the other chord to compare to

    Returns boolean

    true if the two chords are equal

getNoteNames

  • getNoteNames(): string[]
  • example
    const chord = new Chord();
    console.log(chord.getNoteNames()); // ['C4', 'E4', 'G4']

    Returns string[]

    the note names -> ['C4', 'E4', 'G4']

halfDiminish

  • Mutates the chord in place

    chainable
    example
    const chord = new Chord();
    chord.halfDiminish();
    console.log(chord.template); // [1, [3, Modifier.flat], [5, Modifier.flat], [7, Modifier.flat]]

    Returns Chord

    the chord with a flat 3,5, and 7th

halfDiminished

  • chainable
    example
    const chord = new Chord();
    const copy = chord.halfDiminished();
    console.log(copy.template); // [1, 3, [5, Modifier.flat], [7, Modifier.flat]]

    Returns Chord

    a copy of the chord with a flat 3,5, and 7th

invert

  • Mutates the chord in place

    chainable
    example
    const chord = new Chord();
    console.log(chord.template); // [1,3,5]
    console.log(chord.getNoteNames()); // ['C4', 'E4', 'G4']
    chord.invert();
    console.log(chord.template); // [3,5,1]
    console.log(chord.getNoteNames()); // ['E4', 'G4', 'C5']

    Returns Chord

    the chord with with the first note moved to the end up one octave

inverted

  • chainable
    example
    const chord = new Chord();
    console.log(chord.template); // [1,3,5]
    console.log(chord.getNoteNames()); // ['C4', 'E4', 'G4']
    const copy = chord.inverted();
    console.log(copy.template); // [3,5,1]
    console.log(copy.getNoteNames()); // ['E4', 'G4', 'C5']

    Returns Chord

    a copy of the chord with with the first note moved to the end up one octave

isAugmented

  • isAugmented(): boolean
  • example
    const chord = new Chord();
    console.log(chord.isAugmented()); // false
    chord.augment();
    console.log(chord.isAugmented()); // true

    Returns boolean

    true if the chord has a sharp 5th

isDiminished

  • isDiminished(): boolean
  • example
    const chord = new Chord();
    console.log(chord.isDiminished()); // false
    chord.diminish();
    console.log(chord.isDiminished()); // true

    Returns boolean

    true if the chord has a flat 5th

isHalfDiminished

  • isHalfDiminished(): boolean
  • example
    const chord = new Chord();
    console.log(chord.isHalfDiminished()); // false
    chord.halfDiminish();
    console.log(chord.isHalfDiminished()); // true

    Returns boolean

    true if the chord has a flat 3,5, and 7th

isMajor

  • isMajor(): boolean
  • example
    const chord = new Chord();
    console.log(chord.isMajor()); // true

    Returns boolean

    true if the chord has a natural 3rd

isMinor

  • isMinor(): boolean
  • example
    const chord = new Chord();
    console.log(chord.isMinor()); // false
    chord.minor();
    console.log(chord.isMinor()); // true

    Returns boolean

    true if the chord has a flat 3rd

major

  • mutates the chord in place

    chainable
    example
    const chord = new Chord();
    chord.minor();
    chord.major();
    console.log(chord.template); // [1,3,5]

    Returns Chord

    the chord with a natrual 3rd

majored

  • chainable
    example
    const chord = new Chord();
    chord.minor();
    const copy = chord.majored();
    console.log(copy.template); // [1,3,5]

    Returns Chord

    a copy of the chord with a natural 3rd

minor

  • mutates the chord in place

    chainable
    example
    const chord = new Chord();
    chord.minor();
    console.log(chord.template); // [1,[3,-1],5]

    Returns Chord

    the chord with a flat 3rd

minored

  • chainable
    example
    const chord = new Chord();
    const copy = chord.minored();
    console.log(copy.template); // [1,[3,-1],5]

    Returns Chord

    a copy of the chord with a flat 3rd

toString

  • toString(): string
  • example
    const chord = new Chord();
    console.log(chord.toString()); // '(C4)maj'

    Returns string

    the string form of the chord

Generated using TypeDoc