duncanmalashock / elm-music-theory / Music.Chord

A chord is a set of pitch classes that are meant to be sounded together to create harmony. E.g. a "G dominant seventh" chord.


type alias Chord =
Music.Internal.Chord.Chord

Helpers

chordType : Chord -> Music.Internal.ChordType.ChordType

Get a chord's type:

chordType (dominantSeventh PitchClass.a) == ChordType.dominantSeventh

root : Chord -> Music.Internal.PitchClass.PitchClass

Get a chord's root:

root (dominantSeventh PitchClass.a) == PitchClass.a

containsPitchClass : Music.Internal.PitchClass.PitchClass -> Chord -> Basics.Bool

Determine whether a chord contains a given pitch class:

containsPitchClass PitchClass.cSharp (major PitchClass.a) == True

detect : List Music.Internal.ChordType.ChordType -> List Music.Internal.PitchClass.PitchClass -> List Chord

Detect chords that contain the given pitch classes:

detect
    [ ChordType.majorSix
    , ChordType.minorSeventh
    ]
    [ PitchClass.a
    , PitchClass.c
    , PitchClass.e
    , PitchClass.g
    ]
    == [ minorSeventh PitchClass.a
       , majorSix PitchClass.c
       ]

Passing in a list of chord types to detect is required, since there exists no exhaustive list of valid chords in tonal music.

Conversion

toPitchClasses : Chord -> List Music.Internal.PitchClass.PitchClass

Get the pitch classes in a chord:

toPitchClasses (major PitchClass.a)
    == [ PitchClass.a
       , PitchClass.cSharp
       , PitchClass.e
       ]

Note: for converting a chord to pitches, I recommend looking at the functions in the Voicing chords section below.

toString : Chord -> String

Get the chord symbol for a chord:

toString (dominantNinth PitchClass.a) == "A9"

Looking for more flexibility? Look at ChordType.classify.

Voicing chords

A chord is defined by a set of pitch classes. But pitch classes can't be heard; only pitches can be. "Voicing" a chord is the process of:

  1. choosing some number of its pitch classes, and
  2. turning them into pitches within specific octaves, so that they can be played or sung.

Learn more about how this works in the Voicing.ThreePart, Voicing.FourPart, and Voicing.FivePart modules.

voiceThreeParts : { voiceOne : Music.Range.Range, voiceTwo : Music.Range.Range, voiceThree : Music.Range.Range } -> List Music.Internal.Voicing.ThreePart.VoicingMethod -> Chord -> List Music.Internal.Voicing.ThreePart.Voicing

voiceFourParts : { voiceOne : Music.Range.Range, voiceTwo : Music.Range.Range, voiceThree : Music.Range.Range, voiceFour : Music.Range.Range } -> List Music.Internal.Voicing.FourPart.VoicingMethod -> Chord -> List Music.Internal.Voicing.FourPart.Voicing

voiceFiveParts : { voiceOne : Music.Range.Range, voiceTwo : Music.Range.Range, voiceThree : Music.Range.Range, voiceFour : Music.Range.Range, voiceFive : Music.Range.Range } -> List Music.Internal.Voicing.FivePart.VoicingMethod -> Chord -> List Music.Internal.Voicing.FivePart.Voicing

Constructors

Triads

major : Music.Internal.PitchClass.PitchClass -> Chord

minor : Music.Internal.PitchClass.PitchClass -> Chord

augmented : Music.Internal.PitchClass.PitchClass -> Chord

diminished : Music.Internal.PitchClass.PitchClass -> Chord

sus2 : Music.Internal.PitchClass.PitchClass -> Chord

sus4 : Music.Internal.PitchClass.PitchClass -> Chord

Added-tone chords

majorSix : Music.Internal.PitchClass.PitchClass -> Chord

majorSixNine : Music.Internal.PitchClass.PitchClass -> Chord

minorSix : Music.Internal.PitchClass.PitchClass -> Chord

minorSixNine : Music.Internal.PitchClass.PitchClass -> Chord

majorAddNine : Music.Internal.PitchClass.PitchClass -> Chord

minorAddNine : Music.Internal.PitchClass.PitchClass -> Chord

Seventh chords

majorSeventh : Music.Internal.PitchClass.PitchClass -> Chord

majorSeventhSharpEleven : Music.Internal.PitchClass.PitchClass -> Chord

minorSeventh : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventh : Music.Internal.PitchClass.PitchClass -> Chord

diminishedSeventh : Music.Internal.PitchClass.PitchClass -> Chord

halfDiminished : Music.Internal.PitchClass.PitchClass -> Chord

augmentedDominantSeventh : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhSus4 : Music.Internal.PitchClass.PitchClass -> Chord

minorMajorSeventh : Music.Internal.PitchClass.PitchClass -> Chord

Chords with extensions

majorNinth : Music.Internal.PitchClass.PitchClass -> Chord

minorNinth : Music.Internal.PitchClass.PitchClass -> Chord

dominantNinth : Music.Internal.PitchClass.PitchClass -> Chord

minorEleventh : Music.Internal.PitchClass.PitchClass -> Chord

dominantEleventh : Music.Internal.PitchClass.PitchClass -> Chord

dominantThirteenth : Music.Internal.PitchClass.PitchClass -> Chord

Altered dominant chords

Seventh

dominantSeventhFlatNine : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhSharpNine : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhFlatNineSharpNine : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhFlatNineSharpEleven : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhSharpNineSharpEleven : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhSharpEleven : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhFlatNineFlatThirteen : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhSharpNineFlatThirteen : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhSharpElevenFlatThirteen : Music.Internal.PitchClass.PitchClass -> Chord

dominantSeventhFlatThirteen : Music.Internal.PitchClass.PitchClass -> Chord

Ninth

dominantNinthSharpEleven : Music.Internal.PitchClass.PitchClass -> Chord

dominantNinthFlatThirteen : Music.Internal.PitchClass.PitchClass -> Chord

dominantNinthSharpElevenFlatThirteen : Music.Internal.PitchClass.PitchClass -> Chord

Thirteenth

dominantThirteenthFlatNine : Music.Internal.PitchClass.PitchClass -> Chord

dominantThirteenthSharpNine : Music.Internal.PitchClass.PitchClass -> Chord

dominantThirteenthFlatNineSharpNine : Music.Internal.PitchClass.PitchClass -> Chord

dominantThirteenthFlatNineSharpEleven : Music.Internal.PitchClass.PitchClass -> Chord

dominantThirteenthSharpNineSharpEleven : Music.Internal.PitchClass.PitchClass -> Chord

dominantThirteenthSharpEleven : Music.Internal.PitchClass.PitchClass -> Chord

Custom chord types

custom : Music.Internal.PitchClass.PitchClass -> Music.Internal.ChordType.ChordType -> Chord

Create a chord from a custom chord type. For use with ChordType.custom:

myCustomChordType =
    ChordType.custom
        |> ChordType.withMinorThird
        |> ChordType.withDiminishedFifth
        |> ChordType.withMinorSeventh

myCustomChord =
    |> custom PitchClass.c myCustomChordType

-- Equivalent to `halfDiminishedSeventh PitchClass.c`

You can also use custom to construct a chord from a chord type, in cases where the chord type may vary:

custom PitchClass.c ChordType.majorSeventh
    == Chord.majorSeventh PitchClass.c