A chord, in music, is any harmonic set of three or more notes that is heard as if sounding simultaneously. On lead sheets, fake books and chord charts, chords are usually represented using a shorthand notation that makes them faster to read. Your task is to convert the shorthand notation of a chord (for example: Gm7) to the sequence of notes found in that chord (for example: G A# D F).
If you're not a musician, don't worry — the progress is quite simple principle. The first thing you need to know about is the twelve notes of the chromatic scale:
C C# D D# E F F# G G# A A# B
The interval between two notes is expressed in semitones. For example, there are three semitones between the D and the F in this scale. There is no particular root note, allowing the scale to begin at any note and having the first note of scale follow the last note (but then an octave higher).
Next, you'll need to know about the different kinds or chords themselves:
chord | symbol | tones |
---|---|---|
major | (nothing) | [0, 4, 7] |
minor | m | [0, 3, 7] |
dominant seventh | 7 | [0, 4, 7, 10] |
minor seventh | m7 | [0, 3, 7, 10] |
major seventh | M7 | [0, 4, 7, 11] |
The shorthand notation of a chord consists of two parts: a root note followed by the symbolic representation of a chord type. The root note is represented as an uppercase letter, possibly followed by a hash symbol (#). The find out the notes in a chord, take the base note and then select the tones from the chromatic scale relative to the numbers in the list of tone intervals. For example, the chord Gm7 is a minor seventh chord (symbol m7) with G as its root note. We can look up the tone intervals as follows:
m7 $$\longrightarrow$$ minor seventh $$\longrightarrow$$ [0, 3, 7, 10]
The we step 0, 3, 7 and 10 semitones up from the root note G in the chromatic scale, wrapping if necessary:
[G+0, G+3, G+7, G+10] $$\longrightarrow$$ [G, A#, D, F]
Those are the notes in our chord.
Write a function decomposition that takes a string containing the shorthand notation of a chord. The function must return a tuple containing two strings that respectively describe the root note and the symbolic representation of the chord type. The major chord is symbolically represented as the empty string.
Write a function notes that takes two arguments: a string representing a root note and a list of integers representing the sequence of tone intervals in the chromatic scale of the notes found in a chord. The function must return the list of notes in the chromatic scale that are found in the chord.
Use the functions decomposition and notes to write a function chord. This function takes three arguments: i) a string containing the shorthand notation of a chord, ii) a dictionary that maps the names of a number of different chord types onto the corresponding list of tone intervals, and iii) a dictionary that maps the symbolic representation of the same chord types onto the corresponding name of those chord types. The function must return the tuple of notes in the chromatic scale that are found in the given chord.
>>> decomposition('F')
('F', '')
>>> decomposition('Gm7')
('G', 'm7')
>>> decomposition('D#M7')
('D#', 'M7')
>>> notes('F', [0, 4, 7])
['F', 'A', 'C']
>>> notes('G', [0, 3, 7, 10])
['G', 'A#', 'D', 'F']
>>> notes('D#', [0, 4, 7, 11])
['D#', 'G', 'A#', 'D']
>>> chordtypes = {'major':[0, 4, 7], 'minor':[0, 3, 7], 'dominant seventh':[0, 4, 7, 10], 'minor seventh':[0, 3, 7, 10], 'major seventh':[0, 4, 7, 11]}
>>> chordsymbols = {'':'major', 'm':'minor', '7':'dominant seventh', 'm7':'minor seventh', 'M7':'major seventh'}
>>> chord('F', chordtypes, chordsymbols)
('F', 'A', 'C')
>>> chord('Gm7', chordtypes, chordsymbols)
('G', 'A#', 'D', 'F')
>>> chord('D#M7', chordtypes, chordsymbols)
('D#', 'G', 'A#', 'D')