@waveform-playlist/core
The core package provides foundational types, interfaces, and utilities used throughout the Waveform Playlist library. It has zero dependencies and can be used independently for type-safe audio editing data structures.Installation
Main Exports
Types
Audio Clip Model
Represents a single audio clip on the timeline with sample-accurate positioning
Represents a track containing multiple audio clips with volume, pan, and effects
Represents the complete project with all tracks, sample rate, and duration
Interface for waveform-data.js library objects (BBC audiowaveform format)
Configuration Types
Fade configuration with duration and type (linear, logarithmic, sCurve, exponential)
Union type:
'logarithmic' | 'linear' | 'sCurve' | 'exponential'Waveform visualization configuration (sample rate, samples per pixel, colors)
Complete playlist configuration (zoom levels, colors, controls, timescale)
Time selection with start and end times
Peak Data Types
Union type for peak arrays:
Int8Array | Int16ArrayUnion type for bit depth:
8 | 16Result of peak extraction with interleaved min/max data for each channel
Spectrogram Types
Visualization mode:
'waveform' | 'spectrogram'FFT configuration (size, window type, frequency scale, mel bands, etc.)
Predefined color map name or custom color array
Annotation Types
Annotation with start/end times, label, and optional ID
Export format:
'json' | 'aeneas'Configuration for annotation list (annotations array, editable, linkEndpoints, etc.)
State Enums
User interaction modes: Cursor, Select, Shift, FadeIn, FadeOut
Playback state with isPlaying, isPaused, cursor position, and duration
Factory Functions
Create a new AudioClip with sample-based positioning. Supports peaks-first rendering when audioBuffer is omitted.
Create a new AudioClip using time-based values (seconds). Automatically converts to samples.
Create a new ClipTrack with sensible defaults (volume: 1.0, pan: 0, muted: false, etc.)
Create a new Timeline and calculate total duration from all clips
Utility Functions
Clip Queries
Get all clips that overlap with a sample range
Get all clips at a specific sample position
Check if two clips overlap in time
Sort clips by start time (returns new array)
Find silent regions (gaps) between clips on a track
Time Conversion
Convert sample count to seconds
Convert seconds to sample count (rounded)
Convert samples to pixel position
Convert pixel position to samples
Clip Time Helpers
Get clip start time in seconds
Get clip end time in seconds
Get clip trim offset in seconds
Get clip duration in seconds
Constants
Maximum width for canvas chunks (1000px) for horizontal virtual scrolling
Usage Examples
Creating a Clip-Based Timeline
Peaks-First Rendering
Create clips with pre-computed waveform data but no audio buffer for instant visual rendering:Querying Clips
Time Conversions
Key Concepts
Sample-Accurate Positioning
All clip positions, durations, and offsets are stored as integer sample counts, not floating-point seconds. This eliminates floating-point precision errors in audio editing:seconds = samples / sampleRate
Peaks-First Rendering
Clips can be created withwaveformData but without audioBuffer. This enables:
- Instant visual rendering - Load pre-computed peaks (1-2 KB) instead of full audio (MB)
- Progressive loading - Show waveforms immediately, load audio in background
- Bandwidth optimization - Only load audio when user needs playback
audioBuffer property is optional - add it later when audio loads.
Multi-Clip Tracks
Unlike traditional DAWs with single-file-per-track, Waveform Playlist uses a clip-based model:- Each track contains an array of clips
- Clips can be positioned anywhere on the timeline
- Gaps between clips are silent
- Clips can overlap for crossfades
- Each clip has independent trim points and gain
Type Safety
This package provides complete TypeScript definitions for all data structures. Import types for full IDE autocomplete and compile-time checking:Related Packages
- Browser - Complete React solution using these types
- UI Components - React components for visualization
- Playout - Audio playback using these data structures