LabDAW

Sequencer

A step grid: press a step, or drag across several, to draw a pattern.

A step grid for a drum pattern or any row of on and off steps, with a velocity bar under each. The registry component is written on the sequencer primitive, which installs with it.

Installation

The primitives are built on the UI SDK kernel, in beta. Nothing of ours comes from npm: the primitive and its adapter are files you copy into your project and own, and the only packages are the kernel's. The commands name its version, @ui-sdk/*@0.1.0-beta.14.

The styled component, with sizes and themed steps, is one command:

The styled component, with size variants and theme styles:

pnpm dlx shadcn@latest add @audio-ui/sequencer

Or the primitive alone, to style yourself:

pnpm dlx shadcn@latest add @audio-ui/sequencer-react

It writes the primitive, its adapter and primitive.ts into components/audio-ui/ and installs the kernel's packages and what each file imports. The optional styles are one more command:

pnpm dlx shadcn@latest add @audio-ui/primitives-css

Usage

import { Sequencer } from "@/components/audio-ui/sequencer";

<Sequencer
  aria-label="Drum pattern"
  onValueChange={setPattern}
  rowLabels={["Kick", "Snare", "Hihat"]}
  source={step}
  value={pattern}
/>;

value is a row per sound, each a list of steps: boolean[][]. velocities is how loud each step plays, from 0 to 1, in the same shape; a step it does not list plays at full. Add showVelocity for a bar under each row to draw them. source is the step being played, a live { getSnapshot, subscribe } such as one made with createSource: a clock ticking every step never re-renders React.

The primitive alone, part by part:

A Root groups the rows. A Row is one sound, a Cell one of its steps, a <button> pressed when the step is on, and a Velocity a bar under a step. You write a Row for each row and a Cell for each step, with their row and step: the Root's content can read the state, { rows, steps }, so the grid follows the pattern. That is a function in React, the default slot in Vue and a snippet in Svelte.

import { Sequencer } from "@/components/audio-ui/sequencer/react";

const KIT = ["Kick", "Snare", "Hat"];

export function Beat({ pattern, onChange }: { pattern: boolean[][]; onChange: (pattern: boolean[][]) => void }) {
  return (
    <Sequencer.Root onValueChange={onChange} value={pattern}>
      {({ rows, steps }) =>
        Array.from({ length: rows }, (_, row) => (
          <Sequencer.Row aria-label={KIT[row]} className="flex gap-1" index={row} key={row}>
            {Array.from({ length: steps }, (_, step) => (
              <Sequencer.Cell
                aria-label={`${KIT[row]}, step ${step + 1}`}
                className="size-8 rounded bg-muted data-on:bg-primary data-current:ring-2"
                key={step}
                row={row}
                step={step}
              />
            ))}
          </Sequencer.Row>
        ))
      }
    </Sequencer.Root>
  );
}

In the web adapter the sequencer makes the rows, the cells and the velocity bars itself, one for each step of its pattern. Add the velocity-bars attribute to get the bars.

Velocity bars. Write a Velocity for each step, in the Row, under the cells. Its height is the --sequencer-velocity CSS variable, from 0 to 1, which you read in your styles. It holds a native <input type="range"> that carries its name and takes the keys.

The step being played

Give the Root a source, a live value of the step being played, in the shape of an external store: getSnapshot() returns the step and subscribe(listener) is called on each tick. The step's cells get data-current straight in the DOM, so a clock ticking every step renders nothing. Any object with those two methods works, with nothing to install, and useTransportClock from the registry gives you one on the audio clock.

In the web adapter, source is a property, not an attribute.

Interaction

Gestures · 7

Press a step
Flips it.
Drag on
Paints the new state across every step the pointer crosses.
Arrow keys, Home, End
Move between steps; with Ctrl or Cmd, Home and End go to the corners.
Space, Enter
Flip the focused step.
Press or drag on a velocity bar
Sets the velocity where the pointer is, and draws across the steps of the row.
Alt + click, Delete on a velocity bar
Bring the step back to full.
Arrow keys, Page Up/Down, Home/End on a velocity bar
Change the velocity by 5%, by 25%, or to silent or full.

The steps share one tab stop, and each is a toggle button (aria-pressed) named after its row and step.

API reference

Registry component

Sequencer takes the Root props, plus:

Props · 7

Options

Set on the Root, as props (an attribute in kebab case in the web adapter, the grids as JSON).

OptionTypeDefault
value, defaultValueboolean[][]The pattern: a row for each sound, each a list of steps. Controlled, or the starting one.
velocities, defaultVelocitiesnumber[][]How loud each step plays, from 0 to 1, a row for each sound like the pattern. A step it does not list plays at full.
source{ getSnapshot, subscribe }The step being played, followed with no render.
disabledbooleanfalseTakes no gesture.
onValueChange(pattern, details) => voidA step is flipped. details.cancel() keeps the pattern as it was.
onValueCommitted(pattern, details) => voidA press, a paint or a key that changed the pattern ends.
onVelocityChange(velocities, details) => voidA velocity is drawn or nudged.
onVelocityCommitted(velocities, details) => voidA drag, a key or a reset that changed a velocity ends.

What a change reports

  • Pattern: reason is "press", "paint" or "keyboard".
  • Velocities: reason is "drag", "keyboard", "input-change" or "reset".
  • Both carry a source ("mouse", "touch", "pen", "keyboard") and the event.
  • In the web adapter, the pattern is the input and change events, and the velocities the velocitychange and velocitycommit events, with detail: { value, reason, source }.

States to style from

  • data-on and aria-pressed on a cell while its step is on, data-current while it is the step being played, data-row and data-step for its place.
  • data-painting on the Root and the cells while a pointer paints.
  • data-disabled on every part.

Parts

Parts · 4

Events

Events · 4

Built by Ouest Labs, the source code is available on GitHub.
RSS