Music Modeling
A surprising fact is that state machines have the ability to represent and follow the patterns and rules that are common in music. In other words, state machines can generate music by themselves.
State Machines and Music​
A state machine can assign musical elements, such as notes, chords or modulation values, to different states. For example, one state could represent a C Major
chord, and another state could represent a G Major
chord. The state machine could switch between these states and execute them based on a musical time unit, like every bar or every quarter note. This way, the state machine can generate musical patterns and sequences.
- Diagram
- Matrix
C Major | G Major | |
---|---|---|
C Major | ✔ | |
G Major | ✔ |
This idea gives you a lot of control over the musical elements, but also lets you introduce some unpredictability and variation, allowing you to create music that is both structured and unpredictable, both familiar and surprising, both simple and complex.
Let's explore further how state machines can capture the structure and logic of music.
Drum Patterns​
Let's see how a state machine can model a drum beat with the following elements:
- Kick and snare: the main drums that set the foundation of the beat, usually played on quarter or eighth notes;
- Hi-hats: small cymbals that add dynamics and variation to the beat, usually played on sixteenth or eighth notes;
- Ghost notes: soft off-beat notes played on the kick or snare, they add some groove and syncopation to the beat;
- Cymbals: large cymbals that can add accents and transitions to the beat, usually played every few bars.
To model a drum pattern like this, we can use a parallel state machine that has multiple parts, one part for each element of the beat. Each part has a set of states that represent the notes or rests that make up the drum pattern. We can add some variation and complexity to the pattern by using probabilistic transitions between the states. The transitions between the states can be triggered by a clock signal, which determines the tempo of the beat.
The following state machine diagram illustrates this pattern:
- Diagram
- Matrix
Kick | Snare | |
---|---|---|
Kick | 100% | |
Snare | 100% |
Closed hi-hat (loud) | Closed hi-hat (soft) | Open hi-hat | |
---|---|---|---|
Closed hi-hat (loud) | 80% | 20% | |
Closed hi-hat (soft) | 100% | ||
Open hi-hat | 90% | 10% |
Rest | Soft Kick | Soft Snare | |
---|---|---|---|
Rest | 40% | 30% | 30% |
Soft Kick | 80% | 20% | |
Soft Snare | 80% | 20% |
Crash | Ride | |
---|---|---|
Crash | 50% | 50% |
Ride | 50% | 50% |
This is how it works:
- Part 1 plays either
Kick
orSnare
on every quarter note. It alternates between them with a 100% chance; - Part 2 plays one of these sounds on every sixteenth note:
Closed hi-hat (loud)
,Closed hi-hat (soft)
and anOpen hi-hat
. It favors the closed hi-hats over the open one; - Part 3 plays either
Rest
,Soft kick
andSoft snare
on every dotted sixteenth note. It picks them with various chances and sometimes repeats the rest; - Part 4 plays either
Ride
andCrash
every four whole notes. It has a 50% chance to change the sound or repeat it.
And this is how the state machine sounds when it plays at 92 beats per minute:
In the Getting Started section, you will learn how to recreate the examples that you see on this page using Flow. We will guide you through the steps and demonstrate how to apply state machine concepts along the way.
Did you notice that this state machine does not use one of the features we learned before? All the states are just notes and there are no high-level states represented with nested state machines: there is no hierarchy.
Let's look at another state machine that can generate some harmonic and melodic variations, and how we can use hierarchical structures to represent high-level musical ideas that have smaller patterns inside them.
Harmonies, Arpeggios and Melodies​
Let's see how a state machine can model a musical piece that has the following elements:
- The harmony: a sequence of chords that defines the tonality and mood;
- The arpeggios: a pattern of notes that plays on top of the chord progression and adds rhythm. Different arpeggios can be used for variety;
- The melody: a series of notes that creates a tune.
The following diagram shows how a hierarchical state machine with three parallel parts can model behavior like this:
- Diagram
- Matrix
F Major 7 | G Major | A minor | |
---|---|---|---|
F Major 7 | 80% | 20% | |
G Major | 20% | 80% | |
A minor | 100% |
Arp 1 | Arp 2 | |
---|---|---|
Arp 1 | 100% | |
Arp 2 | 100% |
B | C | D | E | C | B | A | C | |
---|---|---|---|---|---|---|---|---|
B | 50% | 50% | ||||||
C | 50% | 50% | ||||||
D | 50% | 50% | ||||||
E | 20% | 40% | 40% | |||||
C | 40% | 40% | 20% | |||||
B | 50% | 50% | ||||||
A | 50% | 50% | ||||||
C |
M1 | M2 | M3 | M4 | |
---|---|---|---|---|
M1 | 50% | 50% | ||
M2 | 50% | 50% | ||
M3 | 50% | 50% | ||
M4 | 50% | 50% |
A | E | Rest | A | E | Rest | |
---|---|---|---|---|---|---|
A | 100% | |||||
E | 100% | |||||
Rest | 100% | |||||
A | 100% | |||||
E | 100% | |||||
Rest |
This is how this state machine works:
- Part 1 plays one of these chords on every dotted whole note:
F Major 7
,G Major
orA minor
. It transitions between them to create a pleasant harmony; - Part 2 alternates between two different high-level arpeggio states, played with sixteenth notes. Each arpeggio is composed of 8 states, and it transitions to the other arpeggio when it reaches its last state;
- Part 3 plays a melody on quarter notes; it has four high-level states, and each state represents a short segment of the melody.
Listen to how beautiful this state machine can sound along with the generative drums from the previous section:
Drum Breaks​
Another creative technique is to use a state machine to create endless variations of a sliced sample.
For example, imagine slicing a drum sample into sixteenth notes, and assigning each slice to a different pitch. Then you can design a state machine that plays these slices in mostly sequential order, but sometimes jumps to a different slice, or repeats the current slice instead of moving on.
This way, you can generate interesting and unexpected patterns from the same sample.
- Diagram
- Matrix
S1 | S2 | S3 | S4 | S5 | S6 | S7 | S8 | |
---|---|---|---|---|---|---|---|---|
S1 | 80% | 10% | 10% | |||||
S2 | 100% | |||||||
S3 | 100% | |||||||
S4 | 10% | 90% | ||||||
S5 | 10% | 90% | ||||||
S6 | 10% | 90% | ||||||
S7 | 10% | 90% | ||||||
S8 | 100% |
N1 | N2 | |
---|---|---|
N1 | 100% | |
N2 |
N1 | N2 | |
---|---|---|
N1 | 10% | 90% |
N2 |
The state machine above has 8 high-level states, each with 2 notes, for a total of 16 notes ranging from C1
to D#2
. The high-level states usually follow each other in sequence, but sometimes they can skip ahead or go back with lower probability. Within each high-level state, the notes are played one after another, except for a few states where the snare note can repeat with a small chance.
Listen to this example of slicing and rearranging the famous Amen Break to hear how this technique sounds in action:
Summary​
As you can see (and hear!), state machines and their features are very helpful for expressing musical elements:
- Probabilistic nature allows a state machine to choose one state transition over another, adding some variability and producing a unique pattern every time;
- Hierarchical structures allow for more complex and structured musical patterns to be modeled;
- Parallelism allows the modeling of musical sequences that contain multiple parts playing together.
Flow is the result of applying all these concepts to music making. We've also added some unique features that are specific to the music making domain, giving you the power to create generative patterns that go beyond the limits of traditional linear sequencing approaches.
This algorithmic composition approach Flow offers has a great advantage: you only need to define the rules once, and then you can let the algorithm generate music for you forever. This frees you to focus on other aspects of your music, such as sound design or live performance. You can also record the music that the algorithm produces and select the best parts for your compositions.
Now it's time to see Flow in action and learn how you can use it to make your own music!