4083 chords, with python

A chord in music is any harmonic set of two–three or more notes that is heard as if sounding simultaneously.[Wikipedia]

In previous posts i calculated there are 4083 chords and introduced to music21 python tools.
Let's use this smart framework for computer-aided musicology, with some python, to compute, view, explore and hear all the 4083 chords.
See setup instructions on music21 website.
We need to import 2 modules, music21 and itertools:

So, how many chords are there?
Below a function to compute the number of combination of n items taken t a t without repetitions (t may coincide with n):

Here we have the ever popular recursive factorial function:

A trivial iteration gives us the total (n = 12, the twelve tones!):

Itertools module is really great to handle permutations, combinations etc. The perfect ars combinatoria tool.
It is applied in the main function to make all combinations without repetitions:

Note some very nice music21 methods and attributes, like pitchedCommonName and addLyric.
As you may have noticed, i write all in a txt file to better explore chords:

We are now ready to generate all chords and display them with MuseScore:

Download commented source, txts, pdfs and MuseScore projects.

My Fav Chords
Here some of my favorite chords, nice labeled by music21:

Unfortunately I found a few bugs. Using numbers for pitches the contiguous notes are not written in the stream.

Furthermore, method pitchedCommonName has some problems yet to appoint chords properly.

However it was a nice trip.

No comments:

Post a Comment