Music 220a Final Project: Random Music Generator in ChucK

About

For my final project, I decided to create a random music generator in chuck. I am attracted to the concepts of randomness and indeterminacy in music, and I figured this would be a great way to utilize these ideas while expanding my programming abilities in chuck. Thus, this project is part program and part artistic piece. I wanted to make random music, but in a recognizable sense, so the structure of the music is largely predetermined, but the actual execution is completely random. The end result is a program that will generate a short song based on user inputs, but will never generate the same song twice. The following diagram and sections describe how the program works.

Diagram

“Diagram”

Inputs

The program accepts five inputs, which must be entered in the code itself. These inputs are key, mode, style, tempo, and time signature. Any of the 12 keys may be used, the mode can be either major or minor, and one of three styles may be chosen. These styles are classical, pop/rock, and blues. Any tempo can be used, although exceeding 200 or so bpm may cause issues. Any time signature can be used; however, the time signature really just refers to the beats in a measure, and not the division of notes. For example, 3/4 and 3/8 would both just be entered as 3.

Get Functions and Global Variables

The input variables are used by a number of Get Functions to get a unique set of global variables which are used by the rest of the program. Global variables include chords, progressions, scales, melodies, rhythms, instruments, and durations of beats, measures, and song sections. Particularly important are the progression and scale variables, as these are what differentiates styles. These global variables are passed on to the player functions for actually creating sound.

Player Functions

There are four player functions used by the program, corresponding to four parts or voices of the piece. All pieces will have drums, bass, and a harmony part. In addition, pieces in the styles of pop/rock and blues will have a lead part, while classical pieces will have a second harmony part in lieu of a lead part. These functions take in the global variables as inputs, which communicate to the players which chords, progressions, rhythms, scales, etc. to play for the song. Each of these functions contains a number of potential instruments that may be played. The instruments are randomly chosen at beginning of the program and act as global variables, so the player functions will only play those instruments for the entire song. In addition, the player functions will play the instruments differently depending on whether the section being played is a chorus, verse, or cadence.

Section Players

The four part players are controlled by three section players: PlayChorus(), PlayVerse(), and PlayCadence(), which take in as an input the number of times the section should be played. Each function sporks the player functions and lets them run for the amount of time necessary for the number of repetitions of the section. At the end of the section, each spork is removed, otherwise they would continue running when the next section player is called. The PlayChorus() function will always play the same chord progression, melody, and drum patterns each time it is called in a song, while the PlayVerse() will be different every time. The verses can really almost be thought of as solos or bridges as opposed to verses in the traditional sense. The PlayCadence() function always plays a V-I cadence regardless of style or mode.

Main Loop

The main loop controls the calling of the section player functions. PlayChorus() will always be called once before the main loop, and then PlayVerse() and PlayChorus() will alternate within the loop based on the number of iterations determined by the song structure array. The loop will always end on a PlayChorus, and the PlayCadence() function is called at the conclusion of every song.

Example Recordings

  • F Major Pop/Rock Tempo=160 Time =4
  • D Minor Classical Tempo=170 Time =3
  • Bb Minor Blues Tempo=200 Time =4
  • ChucK Program

  • RandomMusicGenerator.ck
  • Note: If you want to use the random music generator, you must load in your own drum samples, as this code will only work on my personal computer. In the GetDrums() function (line 1032), change the names of directories and sample files to match your own.