Tidal Cycles Draft Book
Tidal Cycles Draft Book
Tidal Cycles Draft Book
Learning TidalCycles
Patterns I Have Known and Loved
BY
ALEX Mc LEAN
SLAB LABORATORY
SHEFFIELD
ROYAUME UNI
MMXIX
Chapter 1
Introduction
TidalCycles, or just Tidal for short, is a language environment for exploring pattern.
It’s known as a live coding environment (see below), and often used in dance music
contexts, but really can be applied to anything pattern-related, whether repetitive
dance music, abstract minimalist music, weird electroacoustic music, or outside the
world of music completely - people have used Tidal to make video art, choreograph
dance, and even pattern textiles.
Pattern is central to Tidal, so lets have a go at defining it. In music, any sequence is
often called a ‘pattern’, if it gets repeated. But there’s a lot more to pattern than repe-
tition. Think about patterns in textiles - you get a lot of repeating patterns, but also
patterns of reflection or rotation creating symmetry, fractal patterns playing with sim-
ilarity at different scales, interference patterns between different elements. You also
get glitches in patterns, where expectations set up by other kinds of pattern are con-
founded through ‘errors’, often introduced on purpose. All these kinds of patternings
can be explored with Tidal, and more.
2
1.2. LIVE CODING AND EMBRACING ERROR 3
1.3 Installation
To install TidalCycles, you will need a laptop or desktop computer, running Linux,
MacOS X or Windows. Your computer doesn’t need to be particularly powerful, but
you might well need full admin rights to it. All components of the TidalCycles sys-
tem are free/open source. For the latest installation information, please refer to the
instructions on https://tidalcycles.org/Installation.
https://github.com/toplap/awesome-livecoding
4 CHAPTER 1. INTRODUCTION
When you’re writing Tidal patterns, you’re writing Haskell code, using the Tidal li-
brary. Tidal is a bit more than an add-on for Haskell though, it provides its own oper-
ators and a computational model for dealing with Patterns, so is really a language in
its own right. In computer science terms, it’s a domain specific language, embedded
in Haskell. In turn, the mini-notation for describing sequences is embedded in Tidal.
Tidal does all the pattern generation itself - it turns the code you write into messages
that are sent to a sound synthesiser, most often SuperDirt.
Just as Tidal is written in Haskell, SuperDirt is written in SuperCollider. SuperCollider
is a programming environment for audio synthesis and digital signal processing (DSP)
in general. SuperCollider is amazing - you’ll find SuperCollider under the hood of a
lot of audio live coding environments. In fact, many people use it as a great live coding
system in its own right. If you like, and are a superhero, you can live code synthesisers
and effects in SuperCollider while live coding patterns to trigger them in Tidal.
With Tidal making patterns, and SuperDirt making sound, the only thing left is a text
editor to work in. There are a few editors that have plugins for talking with Tidal
- atom, vscode, emacs or vim. Whichever you choose, the plugin will take care of
starting ghci for you, loading the Tidal library, and setting up the connections with
SuperDirt.
Starting tidal should just be a case of typing some code into a tidal file, and running
it. A default Tidal installation will be configured to use the atom editor, but it’s much
the same deal whatever editor you’re using.
1.6. STRUCTURE OF A TIDAL PATTERN 5
1. Start atom
2. Open (or create and save) a file with the .tidal extension (e.g. mylovelycode.tidal).
3. Type or paste in some code (e.g. d1 $ sound "bd sn")
4. Running the code, by making sure the cursor is on it, and pressing shift-enter
or control-enter
shift-enter runs a single line of code, and ctrl- (or on a mac, cmd-) enter will run a
pattern that runs over multiple lines.
When you want to stop the sound, you can replace the pattern with silence by running
this: d1 $ silence, or just hush by itself.
Note 1
If you’re running multiple lines of code (with ‘ctrl-enter‘), you can still only run one
pattern at a time. Make sure there’s a blank line above and below the pattern you
want to run.
Now you know how to start and stop a pattern, lets jump ahead and look at a more
complicated example. The aim here isn’t to understand everything, but to start to get
an idea about what a pattern looks like, and what tidal is capable of. Here we go:
d1 $ chunk 4 (hurry 2) $ sound "bd [~ rs] mt [lt ht]" # crush 5
Running the above, you should start hearing a shifting drum pattern. Again, to stop
it, run this:
d1 $ silence
or this:
hush
What just happened? There’s already quite a lot to take in here, but lets have a look
at the different bits, working from right to left.
crush 5
This is a control pattern. Here it sets SuperDirt’s bit crusher audio effect on, using
the constant value 5. This adds some fairly subtle distortion to the sound output (try
lower values for more distortion). You can pattern these effects too, we’ll come to that
in chapter xxx.
Reading back some more, we find another control pattern, setting the sound that’s
played.
sound "bd [~ rs] mt [lt ht]"
This time the value is in speech marks, which means that it’s specified using Tidal’s
flexible mini-notation for sequences. The words inside - bd, rs, mt etc, are all names
of sample banks (bd is short for bass drum, rs for rimshot, and lt, mt and ht for low,
6 CHAPTER 1. INTRODUCTION
mid and high toms). We’ll start looking at mini-notation syntax including [] and ~
in the next chapter, but for now lets just say that it’s all about rhythm.
Lets think about what the sound function actually does. It takes
"bd [~ rs] mt [lt ht]", which is a pattern of words, and turns it into a
pattern of sounds. That is, it takes one kind of pattern as input, and returns another
kind of pattern as output. In Tidal, everything either tends to be a pattern, or a
function for working on patterns. It’s patterns all the way down.
You might have noticed that between the sound and crush control patterns, there’s
a # character:
sound "bd [~ rs] mt [lt ht]" # crush 5
The job of # is to join the two control patterns together. Super simple to use, but
underneath there are some complexities about how patterns are combined. We’ll look
into those in chapter xxx.
Reading further back, we see this construction:
chunk 4 (hurry 2)
This is a funky bit of code, which adds a lot of rhythmic variety by shifting along,
progressively ‘speeding up’ a quarter of a pattern per cycle. Again, we’ll look at these
patterning functions in detail later, but for now think of this as a machine that takes
a pattern as input, and returns a mangled version of that pattern as output.
d1 $
Reading right back to the start, we get to d1. d1 is another function, which takes a
pattern of controls as input (in this case sound and crush control patterns combined),
and sends it to the synthesiser to be turned into the actual sounds you can hear. The
$ operator is there to divide up the line; whatever is on the right of the $ is calculated
before being passed to the function on the left. Looking at the whole pattern again,
you can see there’s actually two $s in it. One makes sure the sound and crush con-
trols are combined before being mangled by the chunk function, and the other makes
sure everything gets worked out before finally being passed to d1.
d1 $ chunk 4 (hurry 2) $ sound "bd [~ rs] mt [lt ht]" # crush 5
That completes our tour of this particular pattern. It’ll take a while to really get your
head around all of this, but don’t worry, we’ll cover it all again properly later. Next,
we go back to basics to have a proper look at that mini-notation.
Chapter 2
Mini notation
We’ve already seen that Tidal can be broken down into two parts: a mini-notation
for quickly describing sequences, and a library of functions for transforming pattern.
In this chapter, we focus on the mini-notation. Built on Tidal’s flexible approach to
musical time, the mini-notation is a quick way to express rhythms, whether you’re
making canonical techno or far-out polyrhythmic minimalism.
The mini-notation is all about sequencing, describing how one event follows another,
in repeating, looping structures. Whenever you see something in speech marks (""),
that will almost always be a mini-notation sequence. Here’s a simple example:
d1 $ sound "kick snare"
The above plays kick after snare after kick, one after the other, forever. The
"kick snare" represents the repeating mini-notation sequence, the sound specifies
that it’s a pattern of sounds, and the d1 $ sends the pattern to be turned into sound.
Note 2
A note for experienced programmers - mini-notation sequences are immediately
parsed into tidal patterns, so although they look like strings, you can’t treat them
as such.
Most examples in this chapter will be visual, rather than musical, so you can have a
good look at the pattern next to its code. Some examples will visualise patterns of
words from left to right, like this:
"kick snare"
7
8 CHAPTER 2. MINI NOTATION
Sometimes, I’ll show colour patterns as a circle, clockwise from the top:
Patterns will most often be visualised as words, as they’re unambiguous, and accessi-
ble to colourblind people. I will use colour patternings from time to time though, and
give at least one solid musical example for each concept.
This will depend on your cultural background, but in most music software, musical
time is based on the beat. Whether you’re using a software sequencer or writing sheet
music, you’ll generally express things relative to a tempo (musical speed) measured in
beats per minute. In Tidal, things tend to be measured in cycles, not beats. In musical
terms, a cycle is equivalent to a measure or bar. What does this mean in practice?
First of all, you’ll notice that the more events you add to a mini-notation sequence,
the faster it is played. Compare these two:
d1 $ sound "kick snare clap clap"
The latter goes 1.5 times faster than the former, to fit all the events into a single cycle.
In other software, you might define a number of beats per bar, and set the tempo
in beats per minute (BPM). In Tidal though, you set cycles (bars) per second, and
the temporal structure within a cycle is fluid - beats can fall all over the place, with
structure coming from complex and compound ratios rather than a strict metrical
grid.
So in Tidal, the cycle is the reference point for patterning, and not the event. That
doesn’t mean that things have to fit inside a cycle, or that one cycle has to be the
same as the next.
You can change the current tempo with the setcps function, for example, to play at
a rate of 0.4 cycles per second:
setcps 0.45
If you had four events in a cycle, that would feel like (0.45 * 4 =) 1.8 beats per second,
or (0.45 * 4 * 60 =) 108 beats per minute.
2.1. SEQUENCES AND SUB-SEQUENCES 9
The ‘tilde’ token ~ leaves a step empty, creating a musical rest (gap):
"a b ~ c"
The above pattern still has four ‘steps’ of equal length, but the third step is left empty.
Here’s an audio equivalent:
sound "kick snare ~ clap"
Events don’t have to be of equal, though. The following still has four steps, but the
second step contains a subsequence, denoted with square brackets:
d1 $ sound "kick [snare bd] ~ clap"
So now kick and clap each take up a quarter of a cycle, and snare and bd each take
up an eigth of a cycle. If we draw out the cycle from left to right, the structure looks
like this:
"kick [snare bd] ~ clap"
The following illustrates what this structure looks like as a colour cycle, clockwise
from the top:
The subsequences can be subdivided however you like. The following has two steps
of half a cycle each, the first one having a subsequence of three steps, and the second
of four steps:
You can also have subsequences inside subsequences, to any level of depth.
If you want a step within a sequence to play faster, you can use * followed by a speed
factor. For example:
d1 $ sound "bd rs*3 mt lt"
The above is still a four step sequence, but the second one is played three times as
fast, so that the rimshot sound is heard three times in the space of one. The following
sounds exactly the same:
d1 $ sound "bd [rs rs rs] mt lt"
From the following visual representation, we can clearly the division into four steps,
with the second step ‘sped up’:
"bd rs*3 mt lt"
Just as * speeds up a step, the symbol for divide, /, slows a step down:
d1 $ sound "bd rs/3 mt lt"
As a result, you now only hear the rimshot every third step. Lets have a look at a
diagram of this pattern, but sped up by a factor of three with []*3, so that we see
three cycles’ worth of the pattern as a subsequence:
"[bd rs/3 mt lt]*3"
You can see that we get a different third of the rs event each time around; the shaded
part of each event is the ‘active’ part. We only hear a sound when the first third of it
plays, because a sound is only triggered at the start of an event.
Note 3
When events get cut into parts like this, the whole sound is triggered when (and only
when) the first part of the event plays. This is a little counter-intuitive, but will start
to make more sense when we look at combining patterns together in chapter xxx.
We’ll also look at fun ways of properly chopping up sounds into bits in chapter xxx.
These modifiers can be applied to a subsequence too. If you slow down a subsequence
with three elements in it, by a factor of three, you will hear one of them per cycle:
d1 $ sound "bd [rs cp ht]/3 mt lt"
In other words, you hear one third of the subsequence each time, and the next time
around, it carries on where it left off. Lets have a look at three cycles worth of that
(this time making use of a function, fast):
fast 3 "bd [rs cp ht]/3 mt lt"
2.1. SEQUENCES AND SUB-SEQUENCES 11
Spreading three events over three cycles is straightforward, but what if the numbers
aren’t so easily divisible? The answer is, things start sounding funky. Here’s an ex-
ample with those three events spread over four cycles:
d1 $ sound "bd [rs cp ht]/4 mt lt"
You can see that Tidal does a good job of splitting the sequence in four, so that you
end up with fragments of events. Remember that a sound is only triggered by the
start of an event, so the first time around we hear a rimshot at the start of the second
step in the subsequence, the second time a clap one third of the way into the step,
the third time a high tom two thirds into the step, and the fourth time we don’t hear
anything during that step - we only get the tail end of the high tom, which doesn’t
trigger anything.
2.1.5 Polyphony
In music, polyphony simply means that two or more sounds can happen at the same
time. There are a lot of ways to layer things up in Tidal, but in the mini-notation there
is really just one way - separating sequences with commas. There are a few different
ways to match up events in the different subsequences, though.
If we stick with the square brackets used above, then the sequences get layered, so
that their cycles match up perfectly.
So if we have a simple pattern of tom patterns …
d1 $ sound "lt ht mt"
… we can play them at the same time by putting a comma between them, and wrapping
the lot in square brackets:
d1 $ sound "[lt ht mt, [rs rs] [rs rs rs]]"
You can see that the two subsequences are squashed to fit the cycle.
So far we have seen (and heard) that when there are multiple subsequences inside
square brackets, they are layered on top of each other, with cycles aligned. Lets start
with a simple visual example:
"[a b c, d e]"
When you have two rhythms on top of each other, such as three against two above,
it’s known as a polyrhythm.
If we replace the square brackets with curly brackets {}, then instead the steps align:
"{a b c, d e}"
The first subsequence has remained the same, but the steps in the second subsequences
now line up with the steps in the first. Because there aren’t enough steps in the second
sequence, it loops round. It is clearer what is going on if we speed up the whole thing
by a factor of three, in order to see three cycles of the mini-notation sequence:
fast 3 "{pink red purple, lightblue darkblue}"
This kind of construction, where you layer up sequences with the same step duration
but with differing number of steps, is known as polymetre.
Here’s what happen if we change that pattern from curly to square brackets:
fast 3 "[pink red purple, lightblue darkblue]"
However you can manually set the number of steps per cycle, by adding % and a
number after the closing curly bracket. For example to take twelve steps per cycle:
"{pink red purple, lightblue blue darkblue orange}%12"
The . (full stop/period) character provides an alternative to grouping with []. For
example this …
"[a b c] [d e f g] [h i]"
There is one more pair of symbols for denoting subsequences: <>, also known as angle
brackets. These simply slow a subsequence down to one step per cycle.
d1 $ sound "<lt ht mt>"
The angle brackets slow down a subsequence by the number of steps in it, for example
the following does the same as the above.
d1 $ sound "[lt ht mt]/3"
14 CHAPTER 2. MINI NOTATION
We’ve seen that * speeds up time inside a step, effectively causing a step to repeat
itself, but squashed in the same space. ! instead duplicates steps.
"a*3" repeats a within the step, and "b!3" repeats b as additional steps.
If you write a ! without a number, it’ll simply repeat the previous step. So, these
three examples all produce exactly the same result:
"[a b]!2 c!3"
"[a b] ! c ! !"
"[a b] [a b] c c c"
The @ symbol is similar to !, but instead of repeating a step, is stretches it out over
the given number of steps.
"a b@2"
In the above, the first subsequence is stretched to take up the space of two steps, and
the second the space of three steps. That makes five in total, so the two subsequences
take up two fifths and three fifths of a cycle respectively.
Randomness provides a quick way to introduce variety into a sequence. We’ll cover
randomness in detail in chapter xxx, but lets have a quick look at making random
choices within the mini-notation, right now.
2.6. RANDOM CHOICES WITH ? AND | 15
A way to randomly skip playing a step is by using the question mark (?). By default,
there will be a 50% chance of an event playing or not. In the following, the second
and fourth steps will be silent, roughly half the time:
d1 $ sound "bd sd? bd cp?"
It also works with ‘sped up’ events, for example the eight repetitions of bd in the
second step here will be silenced at random:
d1 $ sound "cp bd*8?"
You can make an event more, or less likely to play by adding a decimal number be-
tween 0 (never play) and 1 (always play). For example, the orange segments in the
following will be removed at random, around 90% of the time:
"orange*100?0.9"
The | character is used in a similar way to the comma (,) in that it separates subse-
quences. However, instead of layering them up, it picks one of them to play at random,
each cycle.
d1 $ sound "bd [mt|ht lt ht]"
Sometimes the above will play the equivalent of bd mt, and others it will play
bd [ht lt ht]. Here’s a visual example:
So far, we’ve seen a lot of sound patterns. We learned that the word sound is the name
of a function that turns a pattern of words (like "bd sd") into a pattern of controls (like
sound "bd sd"). A sound control is one that defines what kind of sound to play, in
particular which set of samples or synthesiser notes to choose from. There are many
more functions allowing you to pattern other aspects of sound, such as loudness, pitch,
distortion, panning, filtering. This chapter will introduce them, and how to combine
them together.
The crush function creates a control pattern, just like sound, however its input is a
pattern of numbers rather than words. Also, if you run this code, it doesn’t actually
make any sound! crush is for applying a ‘bitcrushing’ distortion effect, but you won’t
hear anything until you also give a sound to be crushed:
d1 $ sound "bd cp sd mt" |+ crush "16 3"
Now we hear something! Here the sound and crush controls have been combined
together with the |+ operator. Lets have a look at what we end up with:
d1 $ sound "bd cp sd mt" |+ crush "16 3"
There are four events in the result, even though we only gave two values to the crush
control. This is because when combine patterns with the |+ operator, Tidal will start
with events on the left hand side, and match them up with values on the right hand
16
3.1. COMBINING CONTROL PATTERNS 17
side. Note that the first two events have a crush value of 16, and the second two have
a value of 3, in line with the values that are active .
There’s also a +| operator, which instead starts with events from the right-hand side,
and matches them up with values on the left. Lets change our previous example to
use that:
d1 $ sound "bd cp sd mt" +| crush "16 3"
This will take a bit more explaining! Comparing both examples above, the shaded
parts are the same, but the second example has ‘remembered’ the the original events
on the right. Whereas the bd in the first example was a simple event taking up the
first quarter of the cycle, in the second example, it’s a fragment of an event. It still
takes up a quarter of a cycle, but it remembers that it is originally from an event that
took up half a cycle.
In the second example above, the crush value of 16 has been split in half, the first half
matching with bd, and the second matching with cp. Again, the shaded part shows
the half you are left with, in both cases. The 3 event has also been cut in half, between
the sd and mt.
When it comes to listening to the above pattern though, you only hear the first (bd)
and third (sd) sounds, and not the second (cp) and fourth (mt). This is because sounds
are only triggered at the start of events. The first half of both cp and mt have been cut
off, and so they are never triggered.
This combining of events works even when they don’t line up. Here’s a pattern where
three events are combined with two:
d1 $ sound "bd cp sd" |+ crush "16 3"
With the |+ operator, we keep the structure of the three events from the left hand
side. The middle one gets split in half, between the two events on the right hand side.
In the end, three events are triggered; the cp has lost its start, so doesn’t play.
The below shows that if we instead use the +| operator, the event structure comes the
pattern on the right, and is split between events on the left. This time there are only
two events with their ‘starts’ intact (bd and cp, and that therefore result in a sound
being triggered.
d1 $ sound "bd cp sd" +| crush "16 3"
There is one more operator in this family, |+|. Whereas |+ starts with events on the
left, and +| starts with events on the right, |+| results in events which ‘forget’ where
18 CHAPTER 3. EFFECTING SOUND WITH CONTROL PATTERNS
In this final example, all four are ‘whole’ events, and so you hear all four.
3.2 Summary
You might be wondering why events are kept at all, if they have lost their trigger
point, and so can’t be heard. The answer is that these event fragments become useful
when it comes to using patterns in different ways, such as combining with yet another
control pattern, or feeding it into a function that transforms the resulting pattern so
fragmentary event onsets once more come into play.