LabDAW

Waveform Lane

The waveforms of a lane's clips on one canvas and one WebGL context, drawn on the GPU by gl-waveform: exact peaks and the RMS inside, a line through the samples zoomed in, plain or as the three bands of the sound.

Installation

pnpm dlx shadcn@latest add @audio-ui/waveform-lane

Usage

WaveformLane draws the waveforms of all of a lane's clips on one canvas, each in its own part of it, placed as the clips are on the lane. Drawn by gl-waveform on the GPU, every pixel column shows the exact lowest and highest of its samples with the RMS inside, and zoomed in it is a line through the samples, with a dot on each: at any zoom, over recordings of any length. It is a thin React wrapper over @/lib/webgl/waveform, which does the drawing and has no React in it: a custom element or a script starts the same lane. All the clips share one WebGL context, and clips of one recording share what is on the GPU for it. The audio editor switches its lane between this, the spectrogram and the waveform by band from its View menu.

import { WaveformLane } from "@/components/audio-ui/waveform-lane";

<WaveformLane
  className="h-full text-foreground"
  clips={clips} // { id, source, start, length, gain, peak, sampleRate, samples, segments, bands? }[]
  look="plain" // or "bands"
  zoom={pixelsPerSecond}
/>;
PropType
clipsWaveformClip[]The clips to draw: id, the source recording they read, where each starts and how length it is on the lane in seconds, its gain, the recording's peak (its loudest sample, 0 to 1, drawn as tall as the lane), sampleRate and samples ({ frames, read }, mixed to one), segments (how it reads its recording, see below) and bands for the band look.
zoomnumberThe lane's pixels a second. Leave it out for a clip's own lane: its clips fit its box.
sharedbooleanDraw on the page's one WebGL context and copy the picture onto this canvas, for a lane a clip: a page then draws as many as it has clips, past the sixteen contexts a browser keeps, and clips of one recording share what is on the GPU for it. Read once, as the lane starts. Default false.
layout"auto" | "mix" | "split"How a recording's channels are laid out: one waveform, a row each, or a row each once the rows are tall enough to read, as a DAW does. A clip gives its channels, one reader each, for the rows. Default "auto".
look"plain" | "bands"One waveform, or the three bands of the sound one over the other. Default "plain".

With look="bands" a clip is drawn as its sound split in three by a Linkwitz-Riley crossover, at 250 Hz and 2.5 kHz (splitBands of @/lib/engine/analysis): the lows warm, the mids in the ink's own colour and the highs cool, the lows tall behind the highs, as DJ software colours a sound. Each band is drawn as tall as its own loudest sample reaches (peaks), so a band that is quiet in the mix still shows. bands is called once a recording and may split it lazily: the split holds three copies of the mix.

A clip says how it reads its recording as segments(from, to): the stretches of the clip between two times of it, each a straight read, as a DAW paints a region. clipSegments of the arrangement library gives them for a clip that plays on from its offset, one for each turn of its loop and each stretch between its warp markers. A stretch read backwards is not drawn, so a reversed clip is ClipWaveform's, which draws a clip as it plays, as it is where hasWebGL2 of @/lib/webgl/lane says WebGL 2 is missing. The color is the text color.

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