Saturday, January 8, 2011

Creating Retrograde Melodies in Auto-Generated Music System

In designing a canon style musical composition one of the variations that is widely used is what is called retrograde. retrograde means to play the melody backwards so I will show a simple way of producing it through use of the ruby language. Again this can be done in any programming language I have just chosen ruby for this article.

The first thing is to create the notes of the musical composition. In this example we will just randomly generate a pattern based off a given scale. Like a Major scale in the ruby language it would be something like this

major=[0,2,4,5,7,9,11,12] # C D E F G A B C

64.times { melody << major[rand(major.size)] }

The above code will generate a 64 note song. Now that we have all the notes generated for the composition.
Now it's time to create a retrograde version of the melody.

Retrograde is the simplest of the canon techniques to create do to the fact that retrograde means to play the melody in reverse. The ruby language gives us a simple built in method to do this called believe it or not "reverse" so to create the retrograde version of the melody can be produced with one line of code.

retrograde_melody = melody.reverse

now you can assign the retrograde version array to its own midi channel.

Take note this doesn't take in count the duration that the note is played for each note which can be changed in various ways and will be tackled in future articles. This is just to retrograde the original melody in it's raw form.

If you like to play around with the code and software that this article is based off of check it out from my github at . all you need to run the application is to have ruby installed which can be found here and a gem called midlib 1.0 which is a ruby based midi library which can be grabbed after you have ruby install by going to terminal and typing

gem install midlib

I hope that you will explore this concept more on your own and share your thoughts and ideas on this subject.

No comments:

Post a Comment