Skip to main content

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.

State machine representing a simple chord change

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:

Parallel state machine with four parts representing a complex and dynamic drum beat

This is how it works:

  • Part 1 plays either Kick or Snare 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 an Open hi-hat. It favors the closed hi-hats over the open one;
  • Part 3 plays either Rest, Soft kick and Soft snare on every dotted sixteenth note. It picks them with various chances and sometimes repeats the rest;
  • Part 4 plays either Ride and Crash 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:

Examples

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.

The drum pattern example

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:

Parallel state machine with three parts representing harmony, arpeggio and melody playing simultaneously

This is how this state machine works:

  • Part 1 plays one of these chords on every dotted whole note: F Major 7, G Major or A 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:

The drum beat, along with the harmony, arpeggio and melody

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.

Probabilistic state machine representing a sequential rhythmic pattern with some irregularities

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:

Slicing and rearranging the Amen Break

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!