> ## Documentation Index
> Fetch the complete documentation index at: https://pkhambat.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Patterns

> The pattern type: lines that play together and repeat, how long a pattern lasts, groups, bar and every.

A `pattern` value holds lines that start together and repeat. A `block` holds lines that play once. Both require an explicit type before the name: `pattern groove = { ... }` or `block myBlock = { ... }`. An untyped `myBlock = { ... }` is an error and defines nothing. Declaring either plays nothing. [`play`](https://pkhambat.mintlify.site/language/play) renders it.

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
set time 5 over 4

pattern groove = {
  kick: x---
  snare: x----
  tom.floor: x--
}

play groove
```

## Duration

Each line repeats at its own length, and the pattern lasts until they end together: the least common multiple of their lengths. Above, the floor tom repeats every 3 steps, the kick every 4 and the snare every 5, so they meet after 60 steps: three bars of `5 over 4`. A line that ends in [`...`](https://pkhambat.mintlify.site/language/overview#lengths) has no length of its own and doesn't count.

A length in front sets the duration instead: `pattern groove = 4 bars { ... }`. Everything inside must then fit it a whole number of times, and the error names the shortest length that would. A pattern whose lines don't meet within 64 bars needs a length.

## Groups

A named `block` plays its instrument lines once, even when a repeating pattern beside or around it runs longer. A longer play leaves silence after the block rather than repeating it. Use a `pattern` when the material should loop.

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
block accent = { crash: 1 }
pattern beat = {
  kick: 1 3
  snare: 2 4
  hat: x-
}

play {
  accent
  beat
} for 2 bars
```

`( )` holds what plays in order: names, blocks, other groups, and lines of their own, one after another, separated by spaces or new lines. It is the one way to put things in order. On lines of their own, things play together, and two things on one line without brackets are an error. See [Blocks](https://pkhambat.mintlify.site/language/overview.md#blocks). A length in front of a name or a group repeats it for that long; in front of braces it is the block's own length, which comes to the same thing, and is what a block of lines ending in `...` needs.

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
pattern intro = { crash: 1 }
pattern verse = { kick: x--- ---- x-x- ---- }
pattern chorus = {
  kick: x-
  snare: ---- x--- ---- x-x-
}

play (intro 4 bars (verse chorus) intro)
```

A group can run over several lines, and a line of its own in it plays as a block of one line.

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
set octave 4

play (
  piano: notes i---ii---iii---iv---
  piano: notes v---vi---vii---i'---
  { piano: notes 1 bars i' }
)
```

A pattern can hold another by name, on a line of its own, and its value can be a group.

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
pattern beat = {
  kick: x---
  hat: x-
}

pattern verse = {
  piano: chords Am F|C G
  beat
}

pattern chorus = {
  piano: chords F G|C -
  beat
}

pattern song = (verse chorus)

play song
```

## bar

`bar <n> { ... }` adds lines to bar `n` of the pattern or play it is in, every time through. `bar 3 to 4 { ... }` covers a range. It adds to what plays and silences nothing. Where it hits the same kit piece or instrument at the same moment as a line above, it wins.

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
set time 7 over 8
set tempo 90

pattern groove = {
  kick: x--x---
  snare: 2e 4
  snare.ghost: --x----
  hat: ^-x-
  bar 2 {
    snare.ghost: d3 d3e
    hat.open: ^3&
    hat.pedal: 4
  }
}

play {
  crash: 1
  groove
}
```

This is *The Sound of Muzak* by Porcupine Tree. The lines of `groove` meet after two bars, so the pattern is two bars long and the fill closes every pass.

## every

`every <length>` in front of a line or block sets how long one step lasts inside it.

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
set time 3 over 4
set tempo 100

steps pa = ^---
steps radiddle = -xxx

pattern hands = {
  snare: pa
  snare.ghost: radiddle
}

pattern feet = every 3 steps {
  kick: ^-^^-^--
  hat.pedal: -x--x-xx
}

play {
  hands
  feet
}
```

This is Gavin Harrison's paradiddle challenge. `every 3 steps` makes each of the feet's steps three sixteenth notes long, so the feet play the paradiddle three times slower than the hands.

| On the score | Write |
| - | - |
| Eighth notes | `every 2 steps` |
| Eighth-note triplets | `every 1/3 beats` |
| Sixteenth-note triplets | `every 1/6 beats` |
| Thirty-second notes | `every 1/2 steps` |

`every` changes the steps of kit pieces and instruments alike. Beats and chords keep their timing, and lines outside it keep their own step.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.