Lab

piano-roll-tools

AI-native tool surface for a piano roll, createPianoRollTools builds typed, agent-agnostic tools (setNotes/addNotes/removeNotes/transpose/clear/setTempo) an LLM calls to compose melodies and basslines from natural language, parameterized by the roll's pitch range and grid

pnpm dlx shadcn@latest add @audio-ui/piano-roll-tools
import { clampNoteToDomain, createPianoRollTools } from "@/lib/piano-roll-tools";
Fileslib/piano-roll-tools.ts
Depends onNothing
npmzod
Used byNothing
ExportKindWhat it is
PianoRollNoteinterfaceA grid-snapped, pitched note.
NoteInputinterfaceA note as the model supplies it, no id (the tools assign one), length/velocity optional.
PianoRollStateinterfaceWhat the tools read and write, the notes plus the tempo.
clampNoteToDomainfunctionNormalizes a model-supplied note into the roll's domain, the same clamping the primitive does on its controlled value.
PianoRollToolsConfiginterface
createPianoRollToolsfunctionBuilds the tool set for a specific roll.
PianoRollToolstype

Usage

Typed tools an AI model uses to edit a piano roll, through tool calls: adding, moving and deleting notes, each call checked against a schema (zod) and clamped into the roll's range, the notes coming in as values and going out as new ones.

import { createPianoRollTools } from "@/lib/piano-roll-tools";

const tools = createPianoRollTools({ maxPitch: 84, minPitch: 36 });
// Give tools to your model, then apply what it calls to the notes you hold.

The tools change the notes you hold, never the roll directly, so an undo, a playback and the roll follow them as they would a person's edit. See Piano roll.

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