useZoomControls hook manages zoom state and controls via PlaylistEngine delegation. It uses the engine state subscription pattern to mirror zoom state from the engine.
useZoomControls
Manage zoom level and controls for waveform visualization.Import
Usage
Integrated with Playlist Context
The hook is automatically integrated inWaveformPlaylistProvider. Access zoom controls via usePlaylistControls and zoom state via usePlaylistData:
Parameters
Ref to the PlaylistEngine instance. The engine owns the canonical zoom state.
Initial zoom level in samples per pixel. Higher values = more zoomed out.Typical values:
2048- Zoomed in (more detail)4096- Default zoom8192- Zoomed out (overview)
Return Value
Current zoom level in samples per pixel. Mirrored from engine state.
Zoom in (decrease samples per pixel). Delegates to
engine.zoomIn().Zoom out (increase samples per pixel). Delegates to
engine.zoomOut().Whether zooming in is currently available.
false when at maximum zoom.Whether zooming out is currently available.
false when at minimum zoom.Internal callback for mirroring engine state. Called by the provider’s
statechange handler.Engine State Subscription Pattern
The hook uses the engine state subscription pattern:- Engine owns state -
samplesPerPixel,canZoomIn,canZoomOutare stored in the engine - Emits events - Engine emits
statechangeevent on state changes - Hook mirrors state -
onEngineState()callback updates React state
startTransition for Zoom Updates
Zoom updates use React’sstartTransition to mark them as non-urgent:
Ref Guards
The hook uses refs to prevent redundantsetState calls:
Zoom Levels
The engine manages zoom level constraints:- Minimum zoom (max detail) - Typically 100 samples/pixel
- Maximum zoom (full overview) - Calculated to fit entire duration in viewport
Web Worker Peak Resampling
Waveform Playlist uses a two-stage peak generation strategy:- Load time - Generate high-resolution peaks in web worker
- Zoom time - Resample peaks using
WaveformData.resample()(instant)
Related
- Playback Hooks - Access zoom via
usePlaylistData - PlaylistEngine - Engine implementation
- WaveformData - Peak resampling