Source: MIT License
POP File (v1.0)
Uses FMSynth from @jpfli
I’ve been experimenting with a procedural music generator using a basic formula for creating a more relaxing piano music. Thought I’d post the process the generator uses to create each note.
First off on the screen there’s a 4x4 grid of boxes (green box is the current parameters and the smaller red box is the cursor). The rows of the grid represent the chaos level of the tune (Methodical, Semi-Methodical, Semi-Chaotic, and Semi-Chaotic) while the columns represent the pacing (Slowest, Slow, Fast, and Fastest). To the right of that you can see the parameters the generator is using. This shows the tempo, whether the chords are played on the Bass Clef or the Treble Clef, the percent chances of each type of note (1=whole, 2=half, 4=quarter, and 8=eigth) and the percent chance the generator will take a single step up/down from the previous note, skip and take two steps up/down, or leap between three and six notes up/down. The main part of the screen shows the current measure as it’s being played out.
Before I explain how the generator works it would be good to share one of the primary tutorial videos on basic music composition theory that I used to tell the generator how to decide what note/duration to play next.
The tune is pretty simple in that it plays a chord (3 notes either on the bass clef, or the treble clef) along with a melody (opposite clef as the chord). To start I define the notes available for each clef (so that the generator knows which note is a +/-1 from the previous note):
Treble Clef Notes (12 total)
Bass Clef Notes (12 total)
Chords
So the way the generator works is it starts by generating the melody for the measure based on the last note of the previous measure and either stepping (move one note up/down), skipping (move two notes up/down), or leaping (move three to six notes up/down) and a note duration. Since the fastest note is an eighth note that means there’s 8 slots per measure so if it decides to generate a whole note (uses 8 slots) but there aren’t enough available slots remaining then it drops down to a half note and so on filling in all remaining slots in the measure. Once the melody is generated it looks at the first note and picks a random chord that has at least one matching note on the opposite clef and the chords are always whole notes.
Faster pacing increases the tempo as well as the percent chance of playing shorter notes while an increase in tone increases the percent chance of doing more skips/leaps and fewer steps (creating a more chaotic melody that jumps around a lot).
Here’s an example of 64 measures (~2min):