Computer Music Generation Based on Chord Progressions

My article about automated text generation illustrates ways to simulate creativity on a computer. This approach works better when applied to generating musical pieces, as music is more forgiving in terms of construction rules than language. This process will, of course, not replace the artistic skill of a talented composer, but might be an interesting tool to study, and it can be potentially used as a starting point for more sophisticated inventions.

As with text generation, an input musical sequence is needed, which will ultimately define the output style. In this case, the input sequence should be a carefully constructed MIDI file with chord harmonies, which are edited to maintain strict boundaries and to be suitable for reassembly. The algorithm then creates a chord progression markup in a text format, which closely represents an input harmony with a symbol for every two beats.

For example, 'Yankee Doodle Boy' will have this markup: G G G D7 G G D7 D7 G G C C D7 D7 G G... Chunks with the same markup symbols (G, for instance) are considered to be equivalent and randomly interchangeable, even though the actual MIDI file may have different notes corresponding to this markup symbol occurring at various places.

A more complicated example of a markup sequence for a hypothetical tune follows, though in a real program the input sequence should be longer:

C C E7 E7 F F Fm Fm uC uC A7 A7 D G7 Cf Cf C C F F uC Am D G C7 C7 F Fm uC G7 Cf Cf C E7 F D uC G C Cf

Symbols do not need to represent proper chords or be related to any musical notation - they are only used as markers to represent sequences of matching chords. For instance, in the sequence above, uC may be employed to notify a C-keyed chunk without the bass note and Cf may be used to specify the ending (coda) chord.

Then for every two adjacent chords the program will create a table with possible resolutions of what a potential third chord may be. The calculation is done entirely with the markup symbols (MIDI is not used until the final output stage).

According to the original sequence, the generated table will have the following entries: [C C] [C E7] [E7 E7] [E7 F] [F F] [...] [C Cf] with no duplicates. For the entry [C C] the stored data will be: {E7,F} (in the original sequence symbols E7 and F have equal probabilities of appearing after 'C C'). Similarly, for the entry [F F] the stored data will be {Fm,uC}. If a certain resolution chord is more probable for a given sequence (appears multiple times in the original line), it will appear in the table multiple times, e.g. {Fm,Fm,uC}.

The program starts with two random chords, then it randomly picks the next chord (resolution chord) from the table. So, for example, for [C C] either C or E7 will be picked as the next chord. Assuming that 'E7' was picked, the output sequence will be C C E7. After this, the last two chords are taken into a pair [C E7] and the program looks up a match in the table for this tuple. The table for this tuple contains the following possible resolutions: {E7,F}, thus either E7 or F will be selected.

When a sufficient output sequence length is reached, it is then converted to MIDI by substituting symbols with small chunks of data from the original MIDI file.

To add variation to the output, a table of single chord transitions may be created (with entries such as [C] -> {C,E7,C,F,E7,C}, for example) to which a program may refer at random time intervals instead of always using a tuple-to-one table. This will generate a sequence, which resembles the original MIDI file less, allowing the melody to 'break out' of the loop.


The approach works rather well for stylistic playing, and depends mostly on the quality of a given input material and its markup. The algorithm itself is quite streamlined and does not require complex computations. Further variations can be applied to this method, such as tonality shifts, tempo variations, note shifts, etc.

I wrote two programs, RAGMIDI and CLASMIDI, to illustrate the concept. The first generates random ragtime music, and the second generates unsophisticated classical music. Both produce MIDI files with a single piano track. The following examples are available: