Arkham / elm-chords / Chords

Parse chords and chord sheets in Elm


type Chord
    = Chord Note Quality

A chord has a note which gives it a name and a general quality.


type Quality
    = Fifth
    | Tertian TertianQuality
    | Sus2 TertianQuality
    | Sus4 TertianQuality
    | Add9 TertianQuality
    | Add11 TertianQuality
    | NewRoot Note TertianQuality

The quality of the chord. Most well known chord types are described by a tertian quality, which means a chord characterized by a root note, a third and a fifth. We might want to have less notes, or more notes, or replace the root note with another.


type TertianQuality
    = Major
    | Minor
    | Augmented
    | Diminished
    | Dominant7
    | Major7
    | Minor7
    | AugmentedDominant7
    | AugmentedMajor7
    | Diminished7
    | Major6
    | Minor6
    | Dominant9
    | Major9
    | Minor9

This type contains chords characterized by a root note, a third (minor or major) and a fifth (diminished, perfect or augmented)

Converting

toString : Chord -> String

Converts a Chord to a string.

toIntegerNotation : Chord -> ( Note, List Basics.Int )

Converts a Chord to its integer notation, which is the distance in semitones of every note from the root.

Parsing Chords


type Token
    = Parsed Chord
    | Lyrics String

This type represents either a successfully parsed Chord or a portion of the song lyrics. Thanks to the design of the line parser, the lyrics will always be non-empty.

chordParser : Parser Chord

The actual chord parser. Using this you can create your own line parser, for example if you want to parse chords separated by spaces, or curly brackets.

lineParser : Parser (List Token)

The actual line parser. You can use this if you want to customize the line parsing, for example if you want to parse the whole song together.

parseChord : String -> Result (List Parser.DeadEnd) Chord

Parses a string to a Chord. The return value is a result which either returns a Chord or a String that describes why we couldn't parse successfully.

parseLine : String -> Result (List Parser.DeadEnd) (List Token)

Parses a line of a song to a list of Tokens. When we cannot parse the line successfully, we will return a description of why the parsing failed. We will also automatically merge adjacent lyrics tokens.

parseSheet : String -> List (Result (List Parser.DeadEnd) (List Token))

Parses a full song line by line.

Chord Voicings


type alias Fret =
Basics.Int

Which fret it is being pressed.


type alias Voicing =
List (Maybe ( Fret
, Pitch )
}

For each string of our instrument, we could be muting the string, playing an open string or pressing a particular fret.

voicingToString : Voicing -> String

Converts a Voicing to a compact string representation. For example, the C Major chord is written as "032010", while the D Major chord is written as "XX0232".