Sight-Reading Exercise Generator

A program which generates short musical passages with the aid of genetic algorithms.

A Brief Introduction Through Questions/Comments

What does it do?

Sight-Reading Exercise Generator is a program that is intended to generate short musical passages intended to hone a pianist's sight-reading abilities. However, in the process of developing such functionality, the project has acquired multiple generators, including a chord progression generator, bass line generator, two-part harmony generator, and so on.

As it is still a project in progress, the exercise generator is still in the works; however, the generators that have been or will be created along the way will be made available as they are finished.

How does it work?

A genetic algorithm is a technique based on the idea of evolution in biology. In order to solve a problem, a genetic algorithm first randomly generates a starting "population" of solutions. Then, it generates 2N organisms (where N is decided on by the programmer) by choosing N pairs of organisms randomly from the current pool. In choosing parent solutions, the algorithm applies selection pressure by favoring "better" solutions (as determined by some pre-defined fitness function) in choosing parents. For each pair, the algorithm exchanges parts of the solution (crossover) or randomly changes some part of the solution (mutation), giving rise to new offspring solutions. The new solutions are then introduced into the old population and the process continues until the "best-fit" organism out of the entire population satisfies some pre-determined termination condition.

Genetic algorithms are particularly well-suited for this problem since one can treat a musical score as something like biological DNA - just like how DNA has four base pairs, we can treat a note on each beat of the score as a sort of genetic "building-block." Such a treatment of musical scores lends itself easily to the operations of crossover (where one exchanges portions of the music between two different scores), or mutation (where one can randomly change a note in the score). Furthermore, if one restricts the genetic algorithm to generating music based on Baroque music theory, one can easily write a fitness function for the genetic algorithm since Baroque music theory is rigid and easily encoded yet at the same time, guarantees pieces that sound musical.

Therefore, I had to encode the ideas of music theory into classes and data structures which represent notes, chords, progressions, and so on, and use these abstractions to implement fitness functions that allow a genetic algorithm to determine what segments of music "flow" well together and sound musical.

How did you even come up with a project like this?

I had just finished playing around with one of my gists where I made a genetic algorithm that learns how to print "Hello World" by only knowing how many letters are wrong in a solution. Looking back, the program was extremely circular, but it was nevertheless mind-blowing because it generated the phrase from pure pseudorandomness - I was excited to make another project with genetic algorithms, but I did not know what to make with it.

So then, I was just playing piano, having the usual horrible time trying to learn how to sight-read sheet music, when I suddenly had the epiphany of making an exercise generator using a genetic algorithm. All has gone downhill since then.

What if I am not musically inclined/do not know how to play the piano and I just want to hear what it generates?

See samples below.

I don't like this project.

Okay. :(

Instructions

Note: SREGen produces .ly files, which can only be compiled using the free Lilypond program (program information and installer can be downloaded here).
Instructions coming soon!

Samples

Chord Progression Generator

The chord progression generator generates a sequence of chords that follows the chart for standard progressions. However, since the sequence is not generated with reference to a specific key, only the roman numeral names are used. The following progression are two progressions that were generated by the program. For those who are not familiar with music theory and reading chords as roman numerals, I have written short segments of music to demonstrate what it would sound like if a human used the generated progressions to compose music.

Sample 1: A minor progression with an authentic cadence, adapted for F-sharp minor.


Progression generated:
i -> V -> i -> VI -> iv -> iio6 -> viio6 -> i6/4 -> V -> i

What a human could compose:

Sample 2: A major progression with an authentic cadence, adapted for B major.


Progression generated:
I -> vi -> IV -> V6 -> I -> IV -> I -> I6 -> vi -> IV -> V -> I

What a human could compose: