State Machines
To start making music with Flow, you need to grasp the core idea behind it: a state machine. It's a simple but very powerful concept that you will love.
Flow uses an advanced state machine kind that has three special features: it's probabilistic, it has hierarchical structure, and it is parallel. These features make Flow versatile and expressive for creating generative music.
Don't worry if this sounds complicated. We will explain everything in detail below.
What is a State Machine?
Widely used in many fields such as philosophy, biology, computer science, engineering, linguistics and more, a state machine is a way of modeling various objects and systems that can be in different states and transition between these states.
A simple example of a system that can be represented with a state machine is a toaster. A toaster has two main states: Idle
and Toasting
. When a user presses the lever, the toaster transitions from Idle
to Toasting
. When the timer expires, the toaster transitions back to Idle
. The diagram below shows how this process can be modeled with a state machine:
A state machine can be represented with two different ways:
-
A graphical diagram that shows the states and the transitions between them. Each rectangle represents a state, and each arrow represents a transition from one state to another. The arrow can have a label that indicates the input or event that triggers the transition.
-
A matrix in which each row and column represent a state, and each cell represents a transition from the row state to the column state. The cell can have a value that indicates a transition from one state to another, or it can be empty if there is no transition.
You can switch between these views by clicking the Diagram or Matrix tabs.
- Diagram
- Matrix
Idle | Toasting | |
---|---|---|
Idle | ✔ | |
Toasting | ✔ |
This state machine is pretty simple: it has only two states, and each state has exactly one possible transition. Its next state is uniquely determined by its current state and input, which makes a state machine completely predictable, or deterministic.
Deterministic state machines can have more than one possible transition for each state, and follow one of them depending on the events or inputs.
For example, an alarm clock with the snooze function has three states: Idle
, Ringing
, and Snooze
. The transitions between these states depend on the input signals from the clock, the buttons, or the buzzer. A single state can have multiple transitions leading to or from it, depending on the input signals and the conditions. The following state machine captures the possible transitions for different alarm clock scenarios:
- Diagram
- Matrix
Idle | Ringing | Snooze | |
---|---|---|---|
Idle | ✔ | ||
Ringing |