Skip to main content

Components

Pre-built React components for building audio applications.

Import​

import {
Waveform,
PlayButton,
PauseButton,
StopButton,
// ... other components
} from '@waveform-playlist/browser';

Which Provider Each Control Needs​

The controls on this page read the nearest playlist provider. They are exports of @waveform-playlist/browser (ExportWavButton of @waveform-playlist/browser/tone), except the three annotation checkboxes and DownloadAnnotationsButton, which are exports of @waveform-playlist/annotations.

Works underComponents
Either providerPlayButton, PauseButton, StopButton, RewindButton, FastForwardButton, SkipBackwardButton, SkipForwardButton, ClearAllButton, AudioPosition, TimeFormatSelect, SelectionTimeInputs, AutomaticScrollCheckbox, AnnotationList (it draws nothing without <AnnotationProvider>), and, from @waveform-playlist/annotations, ContinuousPlayCheckbox, LinkEndpointsCheckbox, EditableCheckbox and DownloadAnnotationsButton
MediaElementProvider onlyPlaybackRateSelect
WebAudioProvider onlyLoopButton, SetLoopRegionButton, ZoomInButton, ZoomOutButton, MasterVolumeControl, KeyboardShortcuts, ExportWavButton, and, among the children of <WaveformTrackControls>, DefaultTrackControls and the track control pieces

A control under a provider that does not serve it throws when it renders, also when a provider of the right kind is further out. The message names the hook and both providers, for example: "useLoop needs WebAudioProvider, and the nearest playlist provider here is MediaElementProvider, which does not provide it".

The View: Roots, Parts and Ready-Made Compositions​

The waveform view is composed. Each thing it draws is a component, a part, and it is drawn because it is rendered inside a root. Three ready-made compositions cover the common cases. The guide is Composing the View.

import {
Waveform,
WaveformEditor,
MediaElementWaveform,
WaveformRoot,
MediaElementWaveformRoot,
WaveformTimescale,
WaveformLoopRegion,
WaveformTrackControls,
WaveformTracks,
WaveformClipHeaders,
WaveformFades,
WaveformRecordingPreview,
WaveformAnnotationBoxes,
WaveformSelection,
WaveformPlayhead,
WaveformViewOptions,
AnnotationList,
} from '@waveform-playlist/browser';

The roots, the parts and the three ready-made compositions take no option for row height or bar style. Those are set with <WaveformViewOptions>.

Waveform​

The multitrack view, ready-made: the timescale, the loop region, the track controls (a 200 px column), the tracks, the annotation boxes, the selection and the playhead, with the annotation text list below when there are annotations.

<WebAudioProvider arrangement={arrangement}>
<Waveform />
</WebAudioProvider>

arrangement comes from useCreateArrangement (see Loading Audio).

It renders this composition:

<WaveformRoot className={className}>
<WaveformTimescale />
<WaveformLoopRegion />
<WaveformTrackControls />
<WaveformTracks />
<WaveformAnnotationBoxes />
<WaveformSelection />
<WaveformPlayhead />
</WaveformRoot>
<AnnotationList />

The two annotation components draw nothing while the playlist has no annotations.

PropTypeDefaultDescription
classNamestring-Class of the view's outermost element

What the view is made of is not an option of Waveform. To leave a part out, give a part an option (a label for the annotation boxes, a height or action buttons for the annotation list), set the width of the controls column or add your own element, write the composition yourself with WaveformRoot.

Whether clips can be dragged and trimmed, and whether their trim handles are widened for touch, is not a prop either. Wrap the view in ClipInteractionProvider, or, with your own DragDropProvider, in ClipInteractionOptions:

ClipInteractionOptions propTypeDefaultDescription
enabledbooleaninherited, false at the topClips below can be dragged and trimmed
touchOptimizedbooleaninherited, false at the topClips below get 24px trim handles instead of 8px

See Custom Drag Setup.

WaveformEditor​

Waveform with clip headers and fade curves: its tracks part holds <WaveformClipHeaders /> and <WaveformFades />. Same props as Waveform (WaveformEditorProps). Inside a ClipInteractionProvider the header is what a clip is dragged by, and the trim handles come with it.

<ClipInteractionProvider>
<WaveformEditor />
</ClipInteractionProvider>

MediaElementWaveform​

The view of MediaElementProvider, ready-made: the timescale, the one track, the annotation boxes, the selection and the playhead, with the annotation text list below when there are annotations.

<MediaElementProvider track={track}>
<MediaElementWaveform />
</MediaElementProvider>

It renders this composition:

<MediaElementWaveformRoot className={className}>
<WaveformTimescale />
<WaveformTracks />
<WaveformAnnotationBoxes />
<WaveformSelection />
<WaveformPlayhead />
</MediaElementWaveformRoot>
<AnnotationList />
PropTypeDefaultDescription
classNamestring-Class of the view's outermost element

Whether annotations can be edited and whether a dragged edge takes its neighbour along are options of the provider (annotationList, useAnnotationOptions()), not props of the view.

WaveformRoot and MediaElementWaveformRoot​

The frame of the view: the scrolling area, the timescale strip above it and the controls column beside it. A root sorts its children into those places by the type of the element; a child that is not a part is drawn in the scrolling tracks area, in the order written.

WaveformRoot needs WebAudioProvider; MediaElementWaveformRoot needs MediaElementProvider. Each throws under the other provider.

PropTypeDescription
classNamestringClass of the view's outermost element
childrenReactNodeThe parts, and anything else to draw over the tracks

A press on the tracks area starts the selection drag; under WaveformRoot it also selects the track under the pointer.

Parts​

PartDrawsPropsProvider
WaveformTimescalethe time ruler, in a strip above the tracksrenderTick, heighteither
WaveformLoopRegionthe draggable loop region, in the same strip; nothing while looping is offnoneWebAudioProvider
WaveformTrackControlsthe column of track controls, left of the scrolling areawidth; children: the control panel of one trackWebAudioProvider
WaveformTracksthe track rows with their clipsgainScaled; children: the three parts beloweither
WaveformClipHeadersa header on every clipnoneeither
WaveformFadeseach clip's fade-in and fade-out curvesnoneeither
WaveformRecordingPreviewthe take being recorded, in its trackrecordingStateWebAudioProvider
WaveformAnnotationBoxesthe row of annotation boxes, with the drag of their edgesgetLabel, heighteither
WaveformSelectionthe highlighted selection; nothing for a collapsed selectionnoneeither
WaveformPlayheadthe playheadrenderPlayheadeither

WaveformTimescale​

PropTypeDefaultDescription
renderTick(label: string, pixelPosition: number) => ReactNode-Custom tick label. label is already formatted for the scale mode
heightnumber30Height in pixels of the timescale strip. The root reads it from the element, as it reads the width of the controls part, so it must be on the part itself

The strip exists when a root has a WaveformTimescale or a WaveformLoopRegion. The first WaveformTimescale among the root's children decides its height; a strip that holds only a WaveformLoopRegion is 30 px tall. A height that is not a positive number is replaced by 30, with one warning in development; to have no timescale, leave the part out.

WaveformTrackControls​

PropTypeDefaultDescription
widthnumber200Width of the controls column in pixels. The root reads it from the element, so it must be on the part itself
childrenReactNode<DefaultTrackControls />The control panel of ONE track. The part renders it once per track, each copy inside that track's context, which useTrack() and the pieces read
<WaveformTrackControls width={180}>
<DefaultTrackControls />
<TrackRemoveButton onRemove={removeTrack} />
<TrackReorderGrip />
</WaveformTrackControls>

Each track has a slot in the column: as wide as the column and as tall as the track's row, with overflow: hidden. A click anywhere in a slot selects the track. Inside the slot, the element that holds the panel has data-track-controls="<track id>".

The part compares its children with the ones of the previous render (element types, keys and props; children recursively, style one level deep) and keeps the previous ones while they are equal. Children written inline therefore do not render the panels when the composing component renders, as long as their props keep their identity. A function or an object written inline as a prop (other than style) makes every panel render each time.

Under MediaElementWaveformRoot it draws nothing.

WaveformTracks​

PropTypeDefaultDescription
gainScaledbooleanfalseDraw each clip's waveform scaled by its gain (clamped to the channel height), so clips levelled with clip gain look the way they sound. Draw-time only: peaks are not regenerated
childrenReactNode-WaveformClipHeaders, WaveformFades, WaveformRecordingPreview. Nothing else is rendered from here

WaveformClipHeaders, WaveformFades and WaveformRecordingPreview are markers: WaveformTracks and the root read them from its children, and they draw nothing anywhere else. With clip interaction enabled, the header is what a clip is dragged by, and the trim handles come with it. Under MediaElementProvider the header shows the track's name ("Track" without one), and nothing supports dragging the clip: leave clip interaction off above that provider.

<WaveformTracks gainScaled>
<WaveformClipHeaders />
{showFades ? <WaveformFades /> : null}
</WaveformTracks>

WaveformRecordingPreview​

PropTypeDescription
recordingStateWaveformRecordingStateThe take: isRecording, trackId, startSample, progress (from useIntegratedRecording / useRecording), bits, optional latencyOffset

It only draws the take. Call useRecordingSession so the provider mutes the take's track for the take (the mixer shows it muted and its <TrackMuteButton /> is disabled until the take ends). See the Recording guide.

WaveformAnnotationBoxes​

The row of annotation boxes, under either root. It needs the AnnotationProvider of @waveform-playlist/annotations and draws nothing without it or without annotations.

PropTypeDefaultDescription
getLabelGetAnnotationBoxLabelFnthe annotation's idLabel of a box, from the annotation and its index. Pass a function that keeps its identity (defined outside the component, or memoized): a new one renders every box
heightnumber30Height of the row in pixels

A click on a box selects its annotation (activeAnnotationId) and plays it from its start; with continuous play off, playback ends where the annotation ends. The selected box has the active look. The box the playhead is in while playing (playingAnnotationId) has aria-current="true" and, when it is not the selected one, a lighter background (theme key annotationBoxPlayingBackground, optional).

The part has its own DragDropProvider around the row and wires the drag of the edges itself. An edge can be dragged while the provider's editable option is on; whether it takes the edge it touches along is the provider's linkEndpoints option. The moves are shown as they happen and the provider's annotation store is written once, on release: the start and end of the annotations the drag touched, found by id in the store's list as it is then. A drag whose annotation is removed from the store meanwhile ends and writes nothing. An edge can be dragged as far as the timeline is drawn, which can be past the end of the audio. A DragDropProvider of your own above the view, ClipInteractionProvider included, does not receive the drag of an annotation edge.

The drag starts after 1 px of pointer travel. With touchOptimized on a ClipInteractionOptions or ClipInteractionProvider above, a touch must be held 250 ms first.

The border of a box that is not active is the theme's annotationBoxBorder. See the Annotations guide.

WaveformPlayhead​

PropTypeDescription
renderPlayheadRenderPlayheadFunctionCustom playhead. See Custom Playhead

The playhead is shown while playing, and at rest when no range is selected.

WaveformViewOptions​

Sets the options that only affect how a view draws, for every root below it, under either provider. It draws nothing itself. It may sit below the provider, above it, or above several providers; the roots, the parts and the ready-made compositions take none of these options.

It goes above a root, not inside one. A root reads the options above itself: a <WaveformViewOptions> among a root's children does nothing for that root, the parts inside it are not recognised (they count as wrapped in a component), and a development build warns once.

import { WebAudioProvider, Waveform, WaveformViewOptions } from '@waveform-playlist/browser';

<WaveformViewOptions waveHeight={100} barWidth={3} barGap={1} roundedBars>
<WebAudioProvider arrangement={arrangement}>
<Waveform />
</WebAudioProvider>
</WaveformViewOptions>
PropTypeDefaultDescription
waveHeightnumber80Height in pixels of one channel of a track
barWidthnumber1Width in pixels of a waveform bar
barGapnumber0Space in pixels between two bars
roundedBarsbooleanfalseDraw bars with rounded caps (radius barWidth / 2). Most visible with barWidth of 3 or more and a barGap above 0
progressBarWidthnumberbarWidth + barGapWidth in pixels of the playhead line
fillViewportbooleanfalseDraw the timeline at least as wide as its scroll container when the audio is shorter. WaveformRoot only: MediaElementWaveformRoot ignores it, because a MediaElement timeline is as long as its audio
childrenReactNode-The tree the options apply to

The type is WaveformViewOptionsProps.

Inheritance. A prop that is left out is taken from the <WaveformViewOptions> above, and from the defaults when there is none. 0 and false are values, not "left out". Nest one to change a single option for part of the tree. A nested one cannot return an option to its default or to its derived value, because a prop left out inherits: with progressBarWidth={7} outside and barWidth={4} inside, the playhead stays 7 px wide. Write the value you want.

<WaveformViewOptions waveHeight={100} barWidth={2} barGap={1}>
<MediaElementProvider track={first}>
<MediaElementWaveform />
</MediaElementProvider>
{/* this player: 60 px rows, the bar style from above */}
<WaveformViewOptions waveHeight={60}>
<MediaElementProvider track={second}>
<MediaElementWaveform />
</MediaElementProvider>
</WaveformViewOptions>
</WaveformViewOptions>

Values that cannot be drawn are corrected by the root, with one warning per message in development:

  • a waveHeight or a barWidth that is not above 0 (0, a negative number, NaN) is replaced by the default (80, 1);
  • a barGap that is NaN is replaced by 0;
  • a barGap that, with the bar width as corrected, makes barWidth + barGap less than 1 is raised until the next bar is one pixel on (the gap becomes 1 - barWidth);
  • a progressBarWidth that is not above 0 is replaced by barWidth + barGap (as corrected). To draw no playhead, leave <WaveformPlayhead> out.

null for an option means "left out".

Reading the values. A component drawn inside a root reads the resolved waveHeight, barWidth, barGap, roundedBars and progressBarWidth with useWaveformViewInfo() from @waveform-playlist/ui-components. useAudioSettings() does not have them, and fillViewport has no reader.

mono, indefinitePlayback and theme stay on the provider: the provider computes the peaks with mono, its animation loop and seekTo follow indefinitePlayback, and the theme is also read by controls drawn outside a view. With indefinitePlayback on, WaveformRoot draws the timeline as wide as its container, as fillViewport does.

Where a Part Must Be​

  • A part is a child of its root, or of a fragment in it. A part wrapped in your own component is not recognised: a wrapped WaveformTimescale or WaveformTrackControls is drawn in the tracks area, a wrapped WaveformClipHeaders does nothing.
  • One WaveformTracks per root, as the root's own child.
  • WaveformTimescale, WaveformLoopRegion, WaveformTrackControls, WaveformTracks and WaveformAnnotationBoxes throw outside a root ("The timescale must be rendered inside the waveform root").
  • In development a part that is not where it can work says so once in the console. It does not throw.

The full list is in Composing the View.

AnnotationList​

The annotation text list, under either provider. It is not a part of a root: render it anywhere under the provider (below the view, in a sidebar, more than once). It reads the annotations, the selected annotation, the playing one and the three annotation options from the provider, and writes its text, id and action-button edits to the provider's annotation store (annotationStore), each to its annotation found by id. Without a store the provider has no annotations, and the list draws nothing.

<AnnotationList height={300} actions={annotationActions} scrollActivePosition="start" />
PropTypeDefaultDescription
heightnumber-Height of the list in pixels. Without it the list is at most 200 px high
actionsAnnotationAction[]-Buttons shown on each row while the provider's editable option is on. An action is called with the annotation, its index, the annotations and { linkEndpoints, continuousPlay } as the provider has them. Pass an array that keeps its identity: a new one renders every row
scrollActivePositionScrollLogicalPosition | 'none''center'Where a row is put when the list scrolls to it: the selected row when the selection changes, the playing row when playback moves to it. 'none': the list follows neither
scrollActiveContainer'nearest' | 'all''nearest'Which containers scroll: only the list, or the page too
children(item: RenderAnnotationItemProps) => ReactNode-Draws a row in place of the default one. Called with { annotation, index, isActive, isPlaying, onClick, formatTime } (isActive: selected; isPlaying: the playhead is in it while playing). Define it outside the component or memoize it: a new function renders every row
  • It draws nothing while there are no annotations.
  • It needs the AnnotationProvider of @waveform-playlist/annotations. Without it the list draws nothing, and a development build warns once in the console.
  • A click on a row selects the annotation and plays it from its start, as a click on its box does. In the default row a click in a field that is being edited, or on an action button, does not.
  • The row of the playing annotation has aria-current="true" (with a custom row, the <div> around it has) and, when it is not the selected row, a lighter look (theme key annotationTextItemPlayingBackground, optional).
  • While editable is on, the text and the id of a default row can be edited in place. An empty id and an id another annotation has are not accepted: the field shows the stored id again.

See the Annotations guide.


Custom Playhead​

Replace the default playhead with a custom component: pass renderPlayhead to <WaveformPlayhead> in your composition.

PlayheadProps​

The render function receives these props, under either provider:

interface PlayheadProps {
/** Position in pixels from left edge (valid while not playing) */
position: number;
/** Playhead color from theme (default: #ff0000) */
color?: string;
/** Whether audio is currently playing */
isPlaying: boolean;
/**
* The time to draw the playhead at, in seconds. The provider keeps it current
* on every frame of playback, and on a seek, a stop and the end of playback
* (after a pause under MediaElementProvider it is not rewritten: it
* holds the last time the loop or the element's `timeupdate` reported,
* normally within a frame of the paused position). Under
* WebAudioProvider it is the audible time while playing (raw minus
* output latency and look-ahead); under MediaElementProvider it is
* the same ref as usePlaybackRefs().currentTimeRef.
*/
visualTimeRef: React.RefObject<number>;
/** For converting time to pixels: (time * sampleRate) / samplesPerPixel */
samplesPerPixel: number;
sampleRate: number;
}

position is enough for a playhead that only needs to be right while stopped. To move during playback, read visualTimeRef.current in your own animation frame while isPlaying is true, as PlayheadWithMarker does.

<WaveformPlayhead> renders nothing (and renderPlayhead is not called) while a range is highlighted and playback is stopped or paused.

The raw playback position is not a prop: a playhead that needs it reads currentTimeRef from usePlaybackRefs(), under either provider. Engine values are not props either. A playhead for WebAudioProvider that needs one calls useEngineRefs(); the function passed as renderPlayhead may call hooks, the same ones on every render (or return your own component: (props) => <MyPlayhead {...props} />). A custom playhead is unmounted while it is hidden, so state it holds starts again.

Built-in Playhead Components​

Import pre-built playhead variants:

import { Playhead, PlayheadWithMarker } from '@waveform-playlist/ui-components';

Default Playhead​

A simple vertical line (used by default):

<WaveformPlayhead />
// or explicitly:
<WaveformPlayhead renderPlayhead={(props) => <Playhead {...props} />} />

PlayheadWithMarker​

A playhead with a triangle marker at the top, positioned to sit in the timescale area:

<WaveformRoot>
<WaveformTimescale />
<WaveformLoopRegion />
<WaveformTrackControls />
<WaveformTracks />
<WaveformSelection />
<WaveformPlayhead renderPlayhead={(props) => <PlayheadWithMarker {...props} />} />
</WaveformRoot>

Custom Playhead Example​

Create your own playhead component:

import styled from 'styled-components';

const CustomPlayheadLine = styled.div<{ $position: number; $color: string }>`
position: absolute;
top: 0;
left: 0;
width: 3px;
height: 100%;
background: ${(props) => props.$color};
transform: translate3d(${(props) => props.$position}px, 0, 0);
z-index: 150;
pointer-events: none;
will-change: transform;
border-radius: 2px;
box-shadow: 0 0 4px ${(props) => props.$color};
`;

const GlowingPlayhead = ({ position, color = '#ff0000' }) => (
<CustomPlayheadLine $position={position} $color={color} />
);

// Usage
<WaveformPlayhead renderPlayhead={(props) => <GlowingPlayhead {...props} />} />

Performance Tips​

  • Use transform: translate3d() for GPU-accelerated positioning
  • Add will-change: transform for smooth animation
  • Set pointer-events: none to prevent interference with track interactions

Playback Buttons​

PlayButton​

Starts playback from the current cursor position, or plays the highlighted selection.

<PlayButton />

Behavior:

  • Disabled during playback
  • With a selection highlighted (and, under WebAudioProvider, looping off) it plays the selection and stops at its end. If the cursor is inside the selection, it resumes from the cursor
  • Otherwise it plays from the cursor
  • Works the same way under MediaElementProvider, which has no loop

PauseButton​

Pauses playback, maintaining cursor position.

<PauseButton />

Behavior:

  • Disabled when not playing

StopButton​

Stops playback and returns the cursor to where playback started.

<StopButton />

Behavior:

  • Disabled when not playing, under both providers. After Pause it is disabled and the cursor stays at the pause point

RewindButton​

Moves the cursor to the start: seekTo(0). During playback, playback restarts there.

<RewindButton />

FastForwardButton​

Moves the cursor to the end of the audio: seekTo(Infinity), which the provider clamps. Disabled under a WebAudioProvider with indefinitePlayback, where the transport has no end.

<FastForwardButton />

SkipBackwardButton and SkipForwardButton​

Move the cursor back or forward by skipAmount seconds from the current playback position, clamped to the audio. Under a WebAudioProvider with indefinitePlayback, and during a recording session, the position is not clamped at the end of the audio: Skip Forward keeps going. During playback, playback restarts at the new position.

<SkipBackwardButton />
<SkipForwardButton skipAmount={10} />

Props:

  • skipAmount (optional): seconds to skip. Default 5

SetLoopRegionButton​

Creates a loop region from the current selection, or clears an existing loop region.

<SetLoopRegionButton />

Behavior:

  • Disabled when no selection exists and no loop region is set
  • Shows "Set Loop" when no loop region exists
  • Shows "Clear Loop" when a loop region is set
  • Click to toggle between setting and clearing the loop region

LoopButton​

Toggles loop mode for the loop region.

<LoopButton />

Behavior:

  • Shows "Loop Off" when disabled, "Loop On" when enabled
  • If no loop region exists when enabling, creates a default loop region (first 10s or 25% of duration)
  • When enabled, playback loops when the cursor enters and reaches the end of the loop region
  • Loop region is displayed in the timescale area and can be dragged to adjust

Workflow:

  1. Create a selection by clicking and dragging on the waveform
  2. Click SetLoopRegionButton to create a loop region from the selection (or drag in the timescale)
  3. Click LoopButton to enable looping
  4. Play - when the cursor reaches the loop region, it will loop

Zoom Controls​

ZoomInButton​

Decreases samplesPerPixel for more detail.

<ZoomInButton />

Behavior:

  • Disabled at minimum zoom (128 spp)

ZoomOutButton​

Increases samplesPerPixel for wider view.

<ZoomOutButton />

Behavior:

  • Disabled at maximum zoom (8192 spp)

Volume Controls​

MasterVolumeControl​

Slider for overall output volume.

<MasterVolumeControl />

The control sets the master volume from 0 (silent) to 1 (full), and that is what it passes to setMasterVolume and shows from useMixer().masterVolume. setMasterVolume itself takes any finite number of 0 or more (above 1 boosts); anything else throws. The <input type="range"> it draws runs from 0 to 100, and the control divides by 100; a master volume above 1 set another way shows at the slider's end.

Track volume​

<TrackVolumeSlider />, among the children of <WaveformTrackControls>: see Track Controls. For a slider outside the controls column, read the value from useMixer().trackStates[i].volume (the entry of tracks[i]; every track has one, also while its audio loads) and set it with useEditorControls().setTrackVolume(tracks[i].id, volume, { gesture: gesture.id }), with one createMixerGesture() (from @waveform-playlist/core) per slider so that a drag is one undo step (see Undo of Mixer Moves).


Position Display​

AudioPosition​

Shows the current playback position. It follows playback through the provider's animation loop, and shows the resting cursor position while stopped.

<AudioPosition />

The format is the provider's current time format (TimeFormatSelect, or setTimeFormat from usePlaybackControls()); the default is hh:mm:ss.uuu. Works under either provider.


Playback Speed​

PlaybackRateSelect​

MediaElementProvider only. A dropdown (a native <select> with the accessible name "Playback speed") that shows and sets the provider's playback rate.

<PlaybackRateSelect />
<PlaybackRateSelect rates={[0.75, 1, 1.5]} />
PropTypeDefaultDescription
ratesreadonly number[][0.5, 0.75, 1, 1.25, 1.5, 2]The speeds to offer, in the order to list them
classNamestring-Class for the wrapper element

A current speed that is not among rates (set from code with setPlaybackRate) is listed as an extra option. The base component of the same name in @waveform-playlist/ui-components takes value, onChange, rates, disabled and className, for use without the provider.


Time Format​

TimeFormatSelect​

Dropdown for selecting time display format.

<TimeFormatSelect />

Options:

  • seconds - whole seconds: 3726
  • thousandths - seconds with three decimals: 3725.500
  • hh:mm:ss - 01:02:06
  • hh:mm:ss.u - 01:02:05.5
  • hh:mm:ss.uu - 01:02:05.50
  • hh:mm:ss.uuu - 01:02:05.500

SelectionTimeInputs​

Either provider. Two text inputs for the start and the end of the selection; an edit sets the selection when the input loses focus (or on Enter). In the clock formats an edit may also be typed as 1.5 (seconds) or 1:30 (minutes and seconds); text that is not a time changes nothing, and the input shows the selection again. A start typed after the end (or an end before the start) makes the two times change places: the smaller is the start, and the cursor goes there.

<SelectionTimeInputs />

The times are shown and parsed in the provider's time format: the one TimeFormatSelect shows and usePlaybackControls().setTimeFormat() sets. No select has to be on the page. The controlled component of the same name in @waveform-playlist/ui-components takes the format as a prop: selectionStart, selectionEnd, onSelectionChange, format (default hh:mm:ss.uuu), className.

Checkboxes​

ContinuousPlayCheckbox​

Toggle for continuous play, which governs annotation playback:

  • Off: playing an annotation stops at that annotation's end.
  • On: playback continues through the following annotations.

Switching it on while an annotation is playing lets playback continue past that annotation. Playing the selection (the Play button or Space with a selection highlighted) is not affected by the toggle: the selection plays from its start to its end either way. An annotation you click follows the toggle even while a selection is highlighted elsewhere, and the selection stays highlighted. It is not the loop control; see LoopButton.

import { ContinuousPlayCheckbox } from '@waveform-playlist/annotations';

<ContinuousPlayCheckbox />

It is an export of @waveform-playlist/annotations, as LinkEndpointsCheckbox, EditableCheckbox and DownloadAnnotationsButton are. The four need a playlist provider above them (either one) and throw without one; they do not need <AnnotationProvider>. It shows the provider's continuousPlay option (useAnnotationOptions()) and sets it with setContinuousPlay of usePlaybackControls().

LinkEndpointsCheckbox and EditableCheckbox​

Either provider. LinkEndpointsCheckbox shows and sets the provider's linkEndpoints option: whether a dragged annotation edge takes the edge it touches along. EditableCheckbox shows and sets the editable option: whether the edges of the annotation boxes can be dragged, and whether the text and ids in the annotation list can be edited and its action buttons are shown.

import { LinkEndpointsCheckbox, EditableCheckbox } from '@waveform-playlist/annotations';

<LinkEndpointsCheckbox />
<EditableCheckbox>Allow editing</EditableCheckbox>

The three annotation checkboxes take disabled, children, the label (default "Continuous Play", "Link Endpoints" and "Editable Annotations"), and a className, set on the element that wraps the input and its label. The id of each input is generated, so the same checkbox can be rendered twice on a page.

DownloadAnnotationsButton (also @waveform-playlist/annotations, either provider) downloads the provider's annotations as an array of Aeneas fragments. Props: filename (default annotations.json), children (the label, default "Download JSON"), title (the tooltip), disabled, className. It is also disabled while there are no annotations.

AutomaticScrollCheckbox​

Toggle for auto-scrolling during playback. While it is on, a drag on the waveform during playback does not select a range: the press and its release seek to where the press landed.

<AutomaticScrollCheckbox />

Track Controls​

The control panel of a track is composed from pieces. Each piece is bound to the track whose panel it is rendered in: it takes no prop for the track and works only among the children of <WaveformTrackControls>, which renders them once per track. Elsewhere a piece throws the message of useTrack(). The guide is Track Management.

import {
DefaultTrackControls,
TrackName,
TrackMuteButton,
TrackSoloButton,
TrackVolumeSlider,
TrackPanSlider,
TrackMenuButton,
TrackRemoveButton,
TrackReorderGrip,
} from '@waveform-playlist/browser';

The pieces work while a track's audio is still loading: the values are the arrangement's mix, and a change made then is kept. While a take is recorded onto a track (useTrack().isRecording), its mute button is disabled and shown pressed: the take plays the track muted, while its own mute is left as it is. Every change the pieces make is an undo step: a click on mute or solo is one, and a drag of <TrackVolumeSlider /> or <TrackPanSlider />, or a held arrow key on it, is one.

DefaultTrackControls​

The default panel: the name, the track menu, mute, solo, volume and pan. It is what <WaveformTrackControls /> draws when it has no children. It has no remove button and no reorder grip: render <TrackRemoveButton> or <TrackReorderGrip /> beside it.

PropTypeDescription
childrenReactNodeDrawn inside the panel, below the pan slider
<WaveformTrackControls>
<DefaultTrackControls>
<MyTrackColorPicker />
</DefaultTrackControls>
<TrackRemoveButton onRemove={removeTrack} />
</WaveformTrackControls>

The panel fills the slot. An element rendered beside it in the normal flow is therefore outside the visible slot; a control of your own goes inside, as a child, unless it positions itself as the remove button and the grip do.

TrackName​

The track's name on one line, cut off with an ellipsis; "Track N" (N is the position, from 1) for a track without a name. No props. The element has the attribute data-track-name.

TrackMuteButton and TrackSoloButton​

Toggle buttons labelled "Mute" and "Solo", with aria-pressed. No props. Each click is an undo step. The mute button is disabled, and pressed, while a take is recorded onto the track.

TrackVolumeSlider​

The track's volume, 0 to 1 in steps of 0.01, between two speaker icons. The input is labelled "Volume". No props. A drag, or a held arrow, Page, Home or End key, is one undo step.

TrackPanSlider​

The track's pan, -1 (left) to 1 (right) in steps of 0.01, between "L" and "R". The input is labelled "Pan". No props. A drag, or a held key, is one undo step, as for the volume slider.

TrackMenuButton​

The track's menu: how the track is drawn (waveform, spectrogram, both) and its spectrogram settings. No props. It draws nothing without a SpectrogramProvider above the view, and nothing for a MIDI track. A click on the button does not select the track.

TrackRemoveButton​

A close button at the top left corner of the track's slot (it positions itself; put it anywhere among the children). A click calls onRemove and does not select the track.

PropTypeDescription
onRemove(trackId: string) => voidCalled with the track's id. Removing the track from your tracks is yours to do

Pass a function that keeps its identity (useCallback, or a hook's stable function): a new function on every render of your component renders every panel each time.

TrackReorderGrip​

A drag grip with a move-up and a move-down button, at the right edge of the track's slot (it positions itself). No props. The default panel makes room for it on both sides when the grip is rendered beside the panel, as a sibling (CSS :has()). The buttons work with no other setup; dragging needs a ClipInteractionProvider above the view. The up button is disabled for the first track, the down button for the last. Neither the grip nor the buttons select the track. The element around them has the attribute data-track-reorder-grip.

A reorder is committed with useEditorControls().reorderTrack(trackId, toIndex): an undo step of the arrangement, which the view and the engine follow.

For a grip element of your own, see useTrackReorderHandle().

A panel of your own​

Any component among the children can read its track with useTrack():

function TrackGainReadout() {
const { volume } = useTrack();
return <span>{Math.round(volume * 100)}%</span>;
}

<WaveformTrackControls>
<DefaultTrackControls>
<TrackGainReadout />
</DefaultTrackControls>
</WaveformTrackControls>

Export Controls​

ExportWavButton​

Export the playlist to a WAV file.

<ExportWavButton />

Props:

PropTypeDefaultDescription
labelstring'Export WAV'Button label
exportingLabelstring'Exporting WAV…'Button label while an export is running
filenamestring'export'Downloaded file name (without extension). A single track's file is <filename>_<track name>.wav, with control characters and / \ : * ? " < > | in the track name replaced by _
trackIdstring-The one track to export. Left out, the mix is exported
bitDepth16 | 3216WAV bit depth (16-bit PCM or 32-bit float)
effectsFunctionOfflineEffectsFunction-Master effects chain for the offline render, e.g. createOfflineEffectsFunction() of useDynamicEffects()
createOfflineTrackEffects(trackId: string) => OfflineTrackEffectsFunction | undefined-Each track's effects chain for the offline render, e.g. createOfflineTrackEffectsFunction of useTrackDynamicEffects()
classNamestring-CSS class name
onExportComplete(blob: Blob) => void-Callback when export succeeds
onExportError(error: Error) => void-Callback when export fails. Without it, the failure is written to the console (console.error, the error as the second argument). A throw from onExportComplete is not passed here

Behavior:

  • Shows exportingLabel while it exports, without a percentage: useExportWav().progress moves in milestones and does not follow the render
  • Disabled while it exports, and when the playlist has no tracks. A track whose audio is still loading counts as a track: the export then renders the clips that have loaded
  • Automatically triggers download when complete
  • Clip fades are always exported. Effects are exported when their functions are given: leave out effectsFunction and createOfflineTrackEffects for an export without effects.
  • The mix is every audible track: a muted track is left out, soloed or not, and when a track is soloed only soloed tracks are heard. It has two channels when any audible track is stereo (a stereo clip or the stereo pan law), else one.
  • The button keeps its export state to itself. To show isExporting or progress elsewhere on the page, call useExportWav() and draw your own button.

Example:

import { useState } from 'react';
import { ExportWavButton } from '@waveform-playlist/browser/tone';

function ExportMix() {
const [exportError, setExportError] = useState<string | null>(null);
return (
<>
<ExportWavButton
filename="my-mix"
bitDepth={16}
onExportComplete={(blob) => console.log('Exported:', blob.size, 'bytes')}
onExportError={(error) => setExportError(error.message)}
/>
{exportError && <p role="alert">{exportError}</p>}
</>
);
}

Single Track Export:

The track named by trackId is exported as it sounds on its own: with its volume, pan and track effects, and through the master chain when effectsFunction is given; its mute and the other tracks' solo are ignored. The file lasts as long as the mix, so stems exported one by one line up when each is exported after loading has finished.

import { useTimeline } from '@waveform-playlist/browser';
import { ExportWavButton } from '@waveform-playlist/browser/tone';

function ExportFirstTrack() {
const { tracks } = useTimeline();
return <ExportWavButton label="Export Stem" filename="stem" trackId={tracks[0]?.id} />;
}

Export With Tone.js Effects:

import { Reverb } from 'tone';

// Define effects chain
const createEffectsChain = (masterVolume, destination, isOffline) => {
const reverb = new Reverb({ decay: 2.5, wet: 0.3 });
masterVolume.connect(reverb);
reverb.connect(destination);

// Return cleanup function
return () => {
reverb.dispose();
};
};

// Use in export button
<ExportWavButton
label="Export with Reverb"
filename="mix-with-effects"
effectsFunction={createEffectsChain}
/>

Complete Example​

import {
WebAudioProvider,
WaveformRoot,
WaveformTimescale,
WaveformLoopRegion,
WaveformTrackControls,
WaveformTracks,
WaveformSelection,
WaveformPlayhead,
WaveformViewOptions,
PlayButton,
PauseButton,
StopButton,
RewindButton,
FastForwardButton,
SetLoopRegionButton,
LoopButton,
ZoomInButton,
ZoomOutButton,
MasterVolumeControl,
AudioPosition,
TimeFormatSelect,
AutomaticScrollCheckbox,
useCreateArrangement,
} from '@waveform-playlist/browser';
import { ExportWavButton } from '@waveform-playlist/browser/tone';
import { audioTrack } from '@waveform-playlist/core';

function FullFeaturedPlaylist() {
// The rows are there at once; each clip is drawn when its file has loaded. Play works once the playlist is ready
const arrangement = useCreateArrangement(() => [
audioTrack({ src: '/audio/track1.mp3', name: 'Track 1' }),
audioTrack({ src: '/audio/track2.mp3', name: 'Track 2' }),
]);

return (
<WebAudioProvider arrangement={arrangement} samplesPerPixel={1024}>
{/* Transport Controls */}
<div style={{ display: 'flex', gap: '0.5rem', marginBottom: '1rem' }}>
<RewindButton />
<PlayButton />
<PauseButton />
<StopButton />
<FastForwardButton />
<SetLoopRegionButton />
<LoopButton />
</div>

{/* Zoom Controls */}
<div style={{ display: 'flex', gap: '0.5rem', marginBottom: '1rem' }}>
<ZoomInButton />
<ZoomOutButton />
</div>

{/* Volume and Position */}
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center', marginBottom: '1rem' }}>
<MasterVolumeControl />
<AudioPosition />
<TimeFormatSelect />
</div>

{/* Options */}
<div style={{ display: 'flex', gap: '1rem', marginBottom: '1rem' }}>
<AutomaticScrollCheckbox />
</div>

{/* Export */}
<div style={{ marginBottom: '1rem' }}>
<ExportWavButton filename="my-mix" />
</div>

{/* The view: the parts of <Waveform /> without the annotation row, with a 180 px controls column
and 100 px rows */}
<WaveformViewOptions waveHeight={100}>
<WaveformRoot>
<WaveformTimescale />
<WaveformLoopRegion />
<WaveformTrackControls width={180} />
<WaveformTracks />
<WaveformSelection />
<WaveformPlayhead />
</WaveformRoot>
</WaveformViewOptions>
</WebAudioProvider>
);
}

Styling Components​

All components accept standard React props including className and style:

<PlayButton className="my-play-button" />
<PlayButton style={{ backgroundColor: 'green' }} />

For consistent styling, use the theme system or wrap components:

const StyledPlayButton = styled(PlayButton)`
background: #0066cc;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;

&:hover {
background: #0055aa;
}

&:disabled {
background: #cccccc;
cursor: not-allowed;
}
`;

See Also​