---
title: "Recipe: a step sequencer"
description: "Lanes are Tracks in a derive; one sequence plays them on the runner's clock, with no action per step."
modificationDate: "2026-11-09"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a step sequencer

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/sequencer: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

Lanes are `Track`s in a `derive`; one `sequence` plays them on the runner's clock, with
no action per step. Each loops at its own length (polymeter). MIDI and the rest: ["Sound, MIDI and media"](https://exact.expo.dev/learn/contract-for-agents/views-layout-and-interaction.md#sound-midi-and-media).

```prompt Add a step sequencer
Add a step sequencer to the Exact app in this folder: lanes of steps that play sounds in a loop, with Play and Pause. Use https://github.com/expo/exact/blob/main/docs/recipes/sequencer.md as the source for each step. The Exact checkout has the same page at docs/recipes/sequencer.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not give the lanes (their sounds, steps, beats a step and hits) and the tempo, propose them and ask me before you write code. Use only sound files that are in the app's folder; if there are none, ask me for them.
3. In app.contract, declare each file a lane can name with a `sound` line; an undeclared file is silent. Add the recipe's `Step`, `Track` and `Transport` shapes with their fields in the same order, and a `lane` function.
4. Put the tracks in a `derive` and play them with one `sequence ... when playing`, `play(tracks, bpm=..., from=at)`. Pause saves the beat in `at` from the `exactTransport()` resource. Use a key for a mode, not a second `sequence`.
5. If the app runs on iOS and does not play in the background, add a task on `transport.reason == "background"` that sets `playing` to false.
6. Add a test in app.test.contract that taps Play, moves the clock, and uses `expect sound has "<file>" at <ms>` for each lane, then changes a lane and expects the new sound.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me the lanes, the tempo and the sound files, what the tests and verify reported, and the launch command for each target platform.
```

```contract
sound "assets/kits/808/kick.wav"
sound "assets/kits/808/hat.wav"
sound "assets/kits/909/kick.wav"
sound "assets/kits/909/hat.wav"

shape Step
  beat: number
  src: string
  gain: number
  group: string
  note: number
  velocity: number
  channel: number
  duration: number
  haptic: string

shape Track
  beats: number
  loops: number
  offset: number
  output: string
  steps: Step[]

shape Transport
  bpm: number
  anchorAt: number
  anchorBeat: number

// `n` steps of `every` beats, sounding at `hits`.
fn lane(kit: string, slot: string, n: number, every: number, hits: number[]): Track = Track(beats=n * every, loops=0, offset=0, output="", steps=hits.map(i => Step(beat=i * every, src=`assets/kits/${kit}/${slot}.wav`, gain=1, group=slot, note=-1, velocity=100, channel=9, duration=every, haptic="")))

component Drums
  state playing = false
  state at = 0
  state kit = "808"
  resource transport = exactTransport() as shape Transport
  derive tracks = [lane(kit, "kick", 16, 0.25, [0, 4, 8, 12]), lane(kit, "hat", 12, 0.25, [0, 3, 6, 9])]
  sequence groove when playing
    play(tracks, bpm=120, from=at)
  action start
    playing = true
  action pause
    at = transport.anchorBeat + (performanceNow() - transport.anchorAt) * transport.bpm / 60000
    playing = false
  action setKit(name: string)
    kit = name
  view
    row gap=8
      if playing
        button "Pause" press=pause testId="pause"
      else
        button "Play" press=start testId="play"
      button "909" press=setKit("909") aria-pressed=(kit == "909") testId="kit-909"
```

```contract-test
test "lanes loop at their own lengths; an edit plays at once"
  tap "play"
  clock +2000
  expect sound has "assets/kits/808/hat.wav" at 1500
  tap "kit-909"
  clock +1000
  expect sound has "assets/kits/909/kick.wav" at 2500
```

- **Declare every file a built path can name**, a `sound` line each: a step whose `src`
  none declares is silent (`logs`: `… is not a declared sound`).
- **The shapes are positional:** keep their fields in this order.
- **Resolution is beats a step:** `0.25` is a sixteenth, `1/3` a triplet eighth.
- **Edits are live:** a changed step, lane, kit or `bpm` plays from its commit, in phase.
  `pause` keeps the beat in `at` for the next start. A new `key=` starts again at `from`:
  one sequence plays at a time, so a mode is a key, not a second `sequence`.
- **A playhead** is an animation: the guide's "Following the transport".
- **MIDI:** a track's `output` is an output's `id`, its `offset` a delay in ms;
  `clock=` an input's `id` follows that device (`waiting` until Start).
- **iOS stops it when hidden** unless the app plays in the background (LLP 1125 D4); a
  task on `transport.reason == "background"` (add `reason: string` to `Transport`) sets
  `playing` false.
