Hi everybody! Today I would like to share my Random Inspiration Generator with you, a simple program I have written in the C# programming language to help give some inspiration for composing. We all know that with composing, getting started is one of the main hurdles and without direction, writing music and finding inspiration can seem like a challenge. Looking at art, getting out into nature, watching movies or reading (comic) books can help with sparking creativity, but for those of you who would like a quick fix to the illusive inspiration issue, the Random Inspiration Generator is here to help!
The term C# (C-sharp) would probably make you think of music theory and because this blog’s focus is on composition and audio, I’d better clarify that in this post the term refers to the programming language. For my elective at SAE QANTM, I have chosen the “Introduction to Scripting” unit, which focuses on gaining a basic understanding of programming and using Unity’s scripting tool, MonoDevelop. Trying to make sense of code for a beginner is similar to learning music theory, the concepts are all intertwined and is literally another language, with perseverance though, it is a process that can be learnt just like music. It is a gratifying feeling, learning something new and bringing my passion of music into the programming domain helps to inspire me to get better at it.

Put it together!
In the picture above, you will notice that the RIG (Random Inspiration Generator) has given me three inspiration triggers, the Mode, the Key and the Tempo. Mode, Key and Tempo are assigned values and are called variables. To begin with, you make a class, in this case the class is called “modes” and within this class, the variables are declared. A simple message is then written which will be output by Unity in the console window.

This seems simple enough but the computer needs to be told what values to assign to the variables and because this is a random inspiration generator, a system for applying random values must be implemented. A wise man once said “The generation of random numbers is too important to be left to chance” (Robert R. Coveyou, Oak Ridge National Laboratory, 1969) and with programming, this is definitely true. Another point is that some of my variables are not numbers, they are words, known as “strings”. For my RIG, I chose to generate the 7 Modes of Diatonic Harmony, which are classified as strings and are as follows:
- Ionian
- Dorian
- Phyrgian
- Lydian
- Mixolydian
- Aeolian
- Locrian
To randomly generate these modes, a function was used, within this function more variables were created as well as a random number generator, which selects the series of possibilities (switch statement), in this case the different Modes.

From the example above, we see that if the random number generator returns the number 4, then “Lydian” (case 4) will be selected as the mode. The process for generating the Key was the same as the modes.

If you enjoy music theory, then you may be asking “I thought we were talking modes and not key”, in the RIG the Key refers to the Tonic or Root-Note of the Mode. If you would like to give the Random Inspiration Generator a go, then just copy and paste the code below into Monodevelop (Unity and Monodevelop are free to download). Happy Composing!
using UnityEngine;
using System.Collections;
public class Modes : MonoBehaviour
{
public class modes
{
public int id;
public string modeName;
public string key;
public int tempo;
public void modeData()
{
Debug.Log(“Hello Sam, your mode is “ + modeName + “ in the key of “ + key + “ with a tempo of “ + tempo + “ BPM. Happy composing man!“);
}
}
// Use this for initialization
void Start ()
{
float tempoValue;
float theTempo;
//Array
modes[] whatMode = new modes[8];
// for loop generates the muscial info
for(int i = 1; i <= 7; i++)
{
// Assign random value to the tempo
tempoValue = Random.value;
// return random value and assign it to the tempo
theTempo = Mathf.RoundToInt(250 * tempoValue + 1);
// Instantiate game objects
whatMode[i] = new modes();
whatMode[i].id = i;
// Call the mode and key functions
whatMode[i].modeName = getMode();
whatMode[i].key = getKey();
//cast the tempo to an integer
whatMode[i].tempo = (int)theTempo;
}
//get data for the musical information
for(int i = 1; i <= 7; i++)
{
whatMode[i].modeData();
}
}
// Generate random modes
string getMode()
{
string myMode;
float rNumber;
int mySelection;
rNumber = Random.value;
mySelection = (int)Mathf.RoundToInt(7 * rNumber + 1);
// possible modes to choose from
switch(mySelection)
{
case 1 : myMode = “Ionian“;
break;
case 2 : myMode = “Dorian“;
break;
case 3 : myMode = “Phrygian“;
break;
case 4 : myMode = “Lydian“;
break;
case 5 : myMode = “Mixolydian“;
break;
case 6 : myMode = “Aeolian“;
break;
case 7 : myMode = “Locrian“;
break;
default: myMode = “Ionian“;
break;
}
// return the selection
return myMode;
}
// generate key of mode
string getKey()
{
string myKey;
float rNumber;
int mySelection;
rNumber = Random.value;
mySelection = (int)Mathf.RoundToInt(11 * rNumber + 1);
switch(mySelection)
{
case 1: myKey = “C“;
break;
case 2: myKey = “D Flat“;
break;
case 3: myKey = “D“;
break;
case 4: myKey = “E Flat“;
break;
case 5: myKey = “E“;
break;
case 6: myKey = “F“;
break;
case 7: myKey = “G Flat“;
break;
case 8: myKey = “G“;
break;
case 9: myKey = “A Flat“;
break;
case 10: myKey = “A“;
break;
case 11: myKey = “B Flat“;
break;
default: myKey = “B“;
break;
}
return myKey;
}
}
absolutely amazing
LikeLiked by 1 person