Step 05 of 11
Song structure
The finished arrangement of Night Bus, and longer songs built from blocks.
5.1Arrangement: the finished track
.mask() switches a layer on or off per cycle. "<0!4 1!12>" means "off for 4 cycles, then on for 12", so it's one 16-cycle loop. Each layer gets its own mask, and the result is the arrangement from the top of the page. This is the complete Night Bus.
// Night Bus · A minor · 124 BPM · 16 cycles
setcpm(124/4)
// drums
$: s("bd*4").bank("RolandTR909")
$: s("~ cp ~ cp").bank("RolandTR909")
.mask("<0!2 1!14>")
$: s("[~ oh]*4").bank("RolandTR909").gain(.4)
.mask("<0!2 1!14>")
$: s("hh*16").bank("RolandTR909")
.gain("[.25 .5]*8")
.sometimesBy(.2, x => x.ply(2))
.mask("<0!2 1!14>")
// bass
$: note("<a1 f1 c2 g1>")
.struct("x ~ x x ~ x x ~")
.s("sawtooth")
.lpf(sine.range(300, 1800).slow(8))
.decay(.15).sustain(0)
.mask("<0!4 1!12>")
// chords
$: chord("<Am7 F^7 C^7 G7>")
.struct("[~ x]*2")
.voicing()
.s("gm_epiano1")
.room(.5).gain(.6)
.mask("<0!8 1!8>")
// melody
$: n("0 [~ 2] 4 [3 2]".add("<0 -2 2 -1>"))
.scale("A4:minor")
.s("triangle")
.jux(rev)
.delay(.4).gain(.5)
.mask("<0!12 1!4>")
Playing it live
- Edit while it plays, then press Ctrl+Enter. The change lands on the next cycle without stopping the music.
- Write
_$:instead of$:to mute a layer. Remove the underscore to bring it back. - Delete the
.mask(…)lines when you want to "drop" every layer at once. - Add
.pianoroll()to the end of the melody to see its notes scroll by.
5.2A song from blocks
In lesson 5.1, layers switched on one after another inside a single 16-bar loop. Real songs work differently: they're made of blocks (sections) that replace each other. First an intro, then a verse, a build-up, the chorus, a quiet breakdown, the chorus again, and an outro. Each block is a fixed group of layers, played for a set number of bars.
| Block | Job in the song | Typical length |
|---|---|---|
| Intro | Sets the tempo and mood with only a few layers. DJs mix in over it. | 8–16 bars |
| Verse | The main groove, without the strongest hook | 8–16 bars |
| Build | Tension before the chorus: rolls, risers, the kick drops out | 4–8 bars |
| Chorus / drop | The peak: every layer plus the melody | 8–16 bars |
| Breakdown | A rest: drums stop, pads and melody stay | 4–8 bars |
| Outro | Layers leave and the track winds down | 8–16 bars |
Keep every block a multiple of 4 bars, the length of the chord progression, so each block starts on the first chord.
The plan for Night Bus
| Layer | Intro | Verse | Build | Chorus | Break | Outro |
|---|---|---|---|---|---|---|
kick | ● | ● | · | ● | · | ● |
clap | · | ● | · | ● | · | · |
hats | ● | ● | · | ● | · | · |
ohats | · | · | · | ● | · | · |
fill (toms, bar 8) | · | ● | · | · | · | · |
roll (snare roll) | · | · | ● | · | · | · |
bass | · | ● | ● | ● | · | · |
chords | · | ● | · | ● | · | · |
pad | ● | · | ● | · | ● | ● |
melody | · | · | · | ● | ● | · |
Three steps in code
- Layers: define every instrument part once, with
constand a name. - Blocks: combine layers with
stack(…). One block is a list of layers that play together. - Song: put the blocks in order with
arrange([bars, block], …). Each block starts from its own first bar, so a fill written for "bar 8" lands on the last bar of an 8-bar block.
// Night Bus · full song · A minor · 124 BPM
setcpm(124/4)
// ---------- 1. layers: every instrument part, defined once ----------
const kick = s("bd*4").bank("RolandTR909")
const clap = s("~ cp ~ cp").bank("RolandTR909")
const hats = s("hh*16").bank("RolandTR909").gain("[.25 .5]*8")
const ohats = s("[~ oh]*4").bank("RolandTR909").gain(.4)
const fill = s("<~!7 [~ ~ [ht mt] [lt lt]]>").bank("RolandTR909") // tom fill in bar 8
const roll = s("sd*16").bank("RolandTR909")
.ply("<1 1 2 2>").gain(saw.range(.1, .7).slow(4)) // snare roll, louder and faster
const bass = note("<a1 f1 c2 g1>").struct("x ~ x x ~ x x ~")
.s("sawtooth").lpf(sine.range(300, 1800).slow(8)).decay(.15).sustain(0)
const chords = chord("<Am7 F^7 C^7 G7>").struct("[~ x]*2").voicing()
.s("gm_epiano1").room(.5).gain(.6)
const pad = chord("<Am7 F^7 C^7 G7>").voicing().s("gm_pad_warm").gain(.35)
const melody = n("0 [~ 2] 4 [3 2]".add("<0 -2 2 -1>")).scale("A4:minor")
.s("triangle").jux(rev).delay(.4).gain(.5)
// ---------- 2. blocks: which layers play together ----------
const intro = stack(kick, hats, pad)
const verse = stack(kick, clap, hats, bass, chords, fill)
const build = stack(roll, pad, bass)
const chorus = stack(kick, clap, hats, ohats, bass, chords, melody)
const breakdown = stack(pad, melody)
const outro = stack(kick, pad)
// ---------- 3. the song: [number of bars, block] ----------
$: arrange(
[8, intro],
[8, verse],
[4, build],
[8, chorus],
[4, breakdown],
[8, chorus],
[8, outro]
)
The song loops after the outro. To stop at the end, press Ctrl+.. To get a file, export cycles 0–48 as a WAV (lesson 7.1).
Transitions between blocks
A plain cut from one block to the next can sound abrupt. These tricks tell the listener that something new is coming:
| Trick | Code | Where it's used above |
|---|---|---|
| Fill in the last bar | s("<~!7 [~ ~ [ht mt] [lt lt]]>") | fill in the verse |
| Roll that speeds up and gets louder | s("sd*16").ply("<1 1 2 2>").gain(saw.range(.1, .7).slow(4)) | roll in the build |
| Drop the kick before the chorus | Leave kick out of the build block | build |
| Kick stops for the last bar of a block | kick.mask("<1!7 0>") | Try it in the verse |
| Filter opens across a block | .lpf(saw.range(300, 4000).slow(8)) | Try it on chords |
Another way: the song as one line
Replace the arrange(…) part with a "score line". !8 means "for 8 bars", and .pick() looks up each block by name. Keep the three steps above and change only step 3:
// 3. the song as a score line: name!bars
$: "<intro!8 verse!8 build!4 chorus!8 breakdown!4 chorus!8 outro!8>"
.pick({intro, verse, build, chorus, breakdown, outro})
Unlike arrange, pick plays each block by the song's global clock. A block that starts at bar 17 plays its own bar 17, not bar 1. That's fine as long as every block starts on a multiple of its pattern lengths (4 or 8 bars here). The full song above follows this rule.
Playing the blocks live
When you perform, you choose the next block by hand instead of writing out the order. Keep steps 1 and 2, and replace step 3 with a single line. Then change the word and press Ctrl+Enter: the new block starts right away, in time.
// change the word (intro, verse, build, chorus, breakdown, outro) and press Ctrl+Enter
$: verse
Tested with Strudel 1.3. Course text: CC BY-SA 4.0, code: CC0 1.0 (licences).