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).

C akkoord
The notes of the C major chord represented in the staff notation.
C akkoord op gitaar
A C major chord played on an acoustic guitar.

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).

chromatishe toonladder
Chromatic scale drawn as a circle: each note is equidistant from its neighbors, separated by a semitone of the same size.

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. 

Assignment

Example

>>> 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')