Skip to content

Pattern Basics

On this page you write a drum beat and a bass line, one pattern at a time. You learn how a pattern divides time, and you hear each change as you make it.

Work in a project, as in Your First Sound. Write each step into src/main.non, select it, and press Cmd+Enter. Every step adds to what the previous one built.

Finish Language for a Reusable Piece, and open your project’s src/main.non. Evaluate RESET; on its own, then remove that line. The session should be silent. This page starts a new beat with bundled kits and no earlier tracks.

use "std/instruments" { Sampler, SamplerMelodic, Kit };
let drums = AudioTrack("drums");
drums.set_instrument(Sampler(Kit("TR-808")));
drums << [bd sd bd sd];
PLAY;

You hear a kick and a snare, in turn. [bd sd bd sd] is a pattern: four steps in square brackets. It fills one cycle — think of one bar — and repeats.

Give the same cycle eight steps:

drums << [bd ch sd ch bd ch sd ch];

The pattern is not longer: the cycle is as long as before, and each step takes half the time. The number of steps sets their length. Three steps divide the cycle into exact thirds:

drums << [bd bd sd];

_ is a step with no sound:

drums << [bd _ _ bd _ _ sd _];

A rest takes a step, the same as a sound. Here it leaves space between the hits.

set_bpm(140);

The beat is faster, and every pattern keeps its shape. By default a cycle is four beats, so at 120 BPM it lasts two seconds; at 140 it is shorter. Go back:

set_bpm(120);

Notes need an instrument that plays pitches. Make a bass track with the keys kit, and send it note names:

let bass = AudioTrack("bass");
bass.set_instrument(SamplerMelodic(Kit("keys")));
bass << [C2 _ Eb2 _ G2 _ Bb2 _];

A note name is a letter, an optional # or b, and an octave: C2, F#3, Bb2. A number is a MIDI note: [36 _ 39 _ 43 _ 46 _] plays the same line.

A comma in a pattern plays what is on both sides at the same time:

bass << [[C2, G2] _ [Eb2, Bb2] _];

Two notes sound together on each hit. The same comma layers drums:

drums << [bd _ sd _, ch ch ch ch];

The kick and snare play in one layer, the hi-hats in another, both in the same cycle.

Angle brackets play one of their elements in each cycle, in turn:

bass << [<C2 Ab1> _ Eb2 _ G2 _ Bb2 _];

The first note is C2 in one cycle and Ab1 in the next. The rest of the line stays the same.

STOP;