Hello all; I have just returned from Mathcamp, a five week math program for high school students. I’m not going to write in detail about life at Mathcamp, other than that it was amazing in every way.
This year at Mathcamp, I chose to do a computer programming project to ‘teach’ a computer to write ‘music’. The word ‘music’ is in quotes because what it’s expected to generate is more or less random and nothing like actual music by Bach or Mozart; on the other hand, the ‘music’ generated resembles actual music closely enough that it can still be called music, not a random string of notes. Anyways, here’s a short sample of what it can generate:
What can be considered ‘music’ in some sense here is really just a set of rules backed by a random number generator. Hence what it does is really the following:
- Generate a main melody using a bunch of rules: ie, what notes are allowed to go with each other, what rhythms are allowed to go with what notes, etc.
- Using the main melody as a sort of a baseline, generate one or more counterpoint melodies: a counterpoint melody is constrained by the same rules that the main melody must follow, but also has to harmonize with the existing melody, thus being constrained by another set of rules.
- Once all the notes are generated, the program simply uses some library — in our case JFugue – to play the notes through the speakers.
The bulk of our time was spent implementing, tweaking, and debugging the rules and the various other substeps in the above process.
The source code, mostly written by myself over about two weeks, is available as a Google Code project.