Lab

drum-steps

A drum clip's notes as steps: a row per pad, a step per stretch of the grid, with each step's velocity, chance and shift, and the edits a step sequencer makes on the notes (switch a step, set its level, fill a row every n steps).

pnpm dlx shadcn@latest add @audio-ui/drum-steps
import { MAX_SHIFT, STEP_VELOCITY, stepsOf, withStep, withStepLevel, /* … */ } from "@/lib/drum-steps";
Fileslib/drum-steps.ts
Depends onNothing
npm@audio-ui/core
Used bydrum-step-editor
ExportKindWhat it is
StepCellinterfaceA row and a step of a grid.
StepGridinterfaceThe steps a clip is seen on: a row per pad, by its note, top to bottom, steps steps step long from start, such as its loop's start.
StepsinterfaceWhat each step of each row plays: a row per pad, a value per step.
StepLeveltypeWhat the lane under the steps sets on a step's notes.
MAX_SHIFTconstThe latest a step's note can be shifted, as a share of the step.
STEP_VELOCITYconstHow hard a step switched on plays.
stepsOffunctionThe steps the notes play on grid.
withStepfunctionThe notes with the step cell switched on, a note a step long added on its pad, or off, every note in it taken away; the same notes when it already is so.
withStepLevelfunctionThe notes with what the lane sets on the step cell: its notes' velocity or chance, 0 to 1, or how late they start, as a share of a step up to MAX_SHIFT.
filledEveryfunctionThe notes with the row row playing every every steps from the first, and nothing else.
MAX_REPEATSconstThe most a step can repeat in a roll.
withStepRepeatsfunctionThe notes with the step cell played count times, a roll: as many hits as even across the step, each as loud as its first note was, or one hit again with count 1.

Usage

A drum clip's notes as steps, a row per pad, as a step sequencer shows them, and the edits a step sequencer makes, back onto the notes.

import { stepsOf, withStep } from "@/lib/drum-steps";

const steps = stepsOf(notes, grid); // each step's velocity, chance, shift and repeats, by row
const next = withStep(notes, grid, { row: 0, step: 4 }, true); // a hit on the kick, fifth step

withStepLevel sets a step's velocity or chance, withStepRepeats rolls it, and filledEvery fills a row every 2, 4 or 8 steps. The notes stay the clip's own: the drum step editor draws them as steps and edits them through these.

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