MUMT 306 Final Project

James Mesich
4 min readDec 10, 2018

--

The following is a write-up for the Final Project of MUMT 306 — Audio and Music Computing 1.

Project: This project implements a Euclidean Rhythm generator using C++ and the ideas outlined by Godfried Toussaint’s paper.

Objectives:

  1. To implement a Euclidean Rhythm Generator
  2. To create an easy to use command line user interface to build rhythms
  3. To allow each rhythm to have up to 16 channels of MIDI data
  4. To allow the user to save the rhythms that they have created as a MIDI file.

Concept:

The idea outlined in Godfried Toussaint’s paper “Euclidean Algorithm Generates Tradition Musical Rhythms” is quite simple yet it connects a great number of cultures and musics. It is as follows: if given a number of boxes and a number of objects, space the objects as equally as possible in the boxes. In the image below, one can see how this would look with 8 boxes and 3 objects on the left and 8 boxes and 5 objects on the right. For example below, the left image denotes the structure of the Cuban tresillo while the right shows the Cuban cinquillo.

Going further, Euclidean rhythms can be differentiated by their rotation. By starting on a different index, the rhythm can be interpreted differently. Overall, the incredible thing about Euclidean rhythms is that they are found across cultures and continents. One can find a wide range of examples from the Brazilian Samba, to the Spanish Tango, to Bulgarian folk dances, and even to Central African Pygmy rhythms. The broad scope of this common connection is what makes it truly interesting.

Implementation:

First, to use the program, an extensive text-based UI was needed to allow users to control the sounds, volume, duration and sequence. Unfortunately, due to time constraints, the user interface is purely command line. However, the user has the ability to view, edit, add and remove individual tracks from the rhythm. Also while creating the rhythm the user can listen to the whole rhythm as well as individual tracks. Finally once the user is satisfied with their rhythm, they can save it as a MIDI file.

When creating the Euclidean rhythm, the user inputs the number of steps, the number of hits, and the rotation. From there, they can specify the volume, the duration of the notes, the instrument, and the note. After entering all the information, the user can choose to listen to the track alone or with the rest of the rhythm and decide whether they would like to keep it or discard it. Then by repeating the above task, the user can slowly but surely create a new rhythm made purely of euclidean rhythms.

Euclidean rhythms that belong to the same necklace

Challenges:

In order to allow the user to make complex rhythms made up of several tracks, each track would need to be able to have its own time scheme. The tricky part is when the user wants to play it all back in real time. Each track would need to play concurrently at their own speed. To do this, the program had to utilize threading. Each track would have its own thread controlling the sound. However there would only be one RtMidi object for all the threads so a proper use of mutexs had to be implemented. So with threads and mutexs, the user could listen to their partially-completed rhythms as they created them.

Another challenge that was faced was writing MIDI files. After the user has built a rhythm, they need to be able to save their work. To do this, an external library of files needed to incorporated with the program. The makefile needed to be redone to account for the dependency tree to be represented in the compiling of the project. Then, I needed to figure out how to use all of the provided methods in the files to write the program that would translate the rhythm into a MIDI file. After hours tinkering and wishing that I had just looked up documentation earlier, both the makefile and the methods were completed.

Creating Euclidean Rhythms:

For example, we have inputs of 5, and 3, one way to evenly space the objects is encoded above. Repeatedly, add the second input, 3, to a box with a capacity of 5. When the number of objects in the box is greater than the capacity, mark a beat and modulo then number of objects by the first input, 5. Then continue to add the second input for 5 rounds.(same number as the first input) Then the end result will look like the following: [. x . x x].

Step by step example

0 + 3 = 3. 3 <5 = T then [.]

3 + 3 = 6. 6 <5 = F then [. x] and 6 % 5 = 1

1 + 3 = 4. 4 <5 = T then [. x .]

4 + 3 = 7. 7 <5 = F then [. x . x] and 7 % 5= 2

2+ 3 = 5. 5<5 = F then [. x . x x] and 5 % 5 = 0

The Euclidean rhythm generated is [. x . x x]

The final project can be found on my Github page:

https://github.com/jmesich/euclideanRhythmGenerator/

Credits:

  1. The original idea of this project was found in Godfried Toussaint’s original paper.
  2. RtMidi is a library to allow MIDI messages to be sent as output. It was created by Professor Gary Scavone
  3. WriteMidi is a library to allow MIDI files to be saved on the disk. It was created by Github user craigsapp.

--

--