@waveform-playlist/browser 16.0.1 → 17.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,27 +4,28 @@ React components, hooks, and context providers for building a multitrack Web Aud
4
4
 
5
5
  ## Features
6
6
 
7
- - **Multitrack editor** — `<Waveform />` renders canvas waveforms, per-track controls (mute/solo/volume/pan), a time ruler, and a playhead for any number of tracks
7
+ - **Multitrack editor** — `<Waveform />` renders canvas waveforms, per-track controls (mute/solo/volume/pan), a time ruler, and a playhead for any number of tracks. It is a ready-made composition of exported parts (`WaveformRoot`, `WaveformTimescale`, `WaveformTrackControls`, `WaveformTracks`, `WaveformClipHeaders`, `WaveformFades`, `WaveformPlayhead` and more): compose them yourself to choose what is drawn. The control panel of a track is composed too: the children of `<WaveformTrackControls>` are rendered once per track, from the default panel (`DefaultTrackControls`), its pieces (`TrackName`, `TrackMuteButton`, `TrackSoloButton`, `TrackVolumeSlider`, `TrackPanSlider`, `TrackMenuButton`, `TrackRemoveButton`, `TrackReorderGrip`) or your own component, which reads its track with `useTrack()`
8
+ - **An arrangement owns the tracks** — `WaveformPlaylistProvider` takes an `arrangement` (from `useCreateArrangement`): the tracks, their mix, the undo history and the loading of the audio the clips name. A track names its audio with `audioTrack({ src })` from `@waveform-playlist/core`; the arrangement fetches and decodes it, and the view draws a placeholder for a clip still loading when its length is known
8
9
  - **Clip-based editing** — drag-to-move, boundary trimming with collision detection, splitting at the playhead, snap-to-grid (beats/bars or timescale), undo/redo
9
10
  - **Split context providers** — `WaveformPlaylistProvider` (multitrack, Tone.js-backed) and `MediaElementPlaylistProvider` (single-track, `<audio>`-backed with pitch-preserving playback rate)
10
- - **Four focused context hooks** — `usePlaybackAnimation`, `usePlaylistState`, `usePlaylistControls`, `usePlaylistData` isolate 60fps playhead updates from low-frequency state so unrelated components don't re-render on every animation frame
11
+ - **Focused context hooks** — one hook per group of fields that change together (`useIsPlaying`, `useCurrentTime`, `useSelection`, `useAnnotations`, `usePlaybackControls`, `usePlaybackRefs`, `usePlaylistView`, `usePlaylistTimeline`, `usePlaylistMixer`, `useLoop`, `useEditorControls` and more), so a component re-renders only for the group it reads, not on every pointer move, slider step or annotation boundary
11
12
  - **Audio effects** — 20 Tone.js effects (reverb, delay, modulation, filter, distortion, dynamics, spatial) with runtime parameter control, master and per-track chains, plus WAM 2.0 plugin hosting
12
- - **Recording** — pairs with `@waveform-playlist/recording` for mic input, overdubbing, and live waveform preview; punch-in takes replace overlapped content, and `setRecordingActive(active, armedTrackId)` suppresses the end-of-timeline auto-stop and transiently mutes the recorded-over track for the session
13
- - **Annotations & spectrogram** — optional integration contexts for `@waveform-playlist/annotations` and `@waveform-playlist/spectrogram`
13
+ - **Recording** — pairs with `@waveform-playlist/recording` for mic input, overdubbing, and live waveform preview; punch-in takes replace overlapped content, and `useRecordingSession({ isRecording, trackId })` (or `setRecordingActive(active, armedTrackId)` directly) suppresses the end-of-timeline auto-stop and mutes the recorded-over track in the mix for the take (its Mute button shows it and is disabled; the mute from before is written back when the take ends)
14
+ - **Annotations & spectrogram** — optional integration contexts for `@waveform-playlist/annotations` and `@waveform-playlist/spectrogram`. Under either provider, `<WaveformAnnotationBoxes>` (a part of the view; it wires the drag of the box edges itself) and `<AnnotationList>` (the text list, anywhere under the provider) draw the annotations
14
15
  - **WAV export** — render the full mix (including effects) offline to a downloadable WAV file
15
16
  - **MediaElement player mode** — a lightweight single-track player with pitch-preserving speed control, for podcast/audiobook-style use cases that don't need multitrack mixing
16
17
 
17
18
  ## Installation
18
19
 
19
20
  ```bash
20
- npm install @waveform-playlist/browser tone @dnd-kit/react
21
+ npm install @waveform-playlist/browser @waveform-playlist/playout @waveform-playlist/core tone @dnd-kit/react
21
22
  ```
22
23
 
23
24
  `@waveform-playlist/browser` requires these peer dependencies:
24
25
 
25
26
  | Package | Purpose |
26
27
  |---------|---------|
27
- | `react` / `react-dom` | ^18.0.0 or ^19.0.0 |
28
+ | `react` / `react-dom` | ^19.0.0 |
28
29
  | `styled-components` | ^6.0.0 — CSS-in-JS styling |
29
30
  | `tone` | ^15.0.0 — Web Audio engine (optional if you supply your own `PlayoutAdapter`) |
30
31
  | `@dnd-kit/react` | ^0.5.0 — drag-and-drop (includes `@dnd-kit/dom` and `@dnd-kit/abstract`) |
@@ -32,10 +33,10 @@ npm install @waveform-playlist/browser tone @dnd-kit/react
32
33
  | `@waveform-playlist/media-element-playout` | engine for `MediaElementPlaylistProvider` (optional peer) |
33
34
  | `@waveform-playlist/annotations` / `@waveform-playlist/recording` / `@dawcore/wam` | optional, install only if you use those features |
34
35
 
35
- **Engine-free core:** the package's main entry has no static dependency on `tone` or `@waveform-playlist/playout` — a `MediaElementPlaylistProvider`-only consumer, or one supplying a custom `createAdapter`, never resolves either. Tone-coupled exports (`useAudioTracks`, `useDynamicTracks`, effects hooks, `useExportWav`, `useOutputMeter`, `useMasterAnalyser`) live at the **`@waveform-playlist/browser/tone`** subpath:
36
+ **Engine-free core:** the package's main entry has no static dependency on `tone` or `@waveform-playlist/playout` — a `MediaElementPlaylistProvider`-only consumer, or one supplying a custom `createAdapter`, never resolves either. Tone-coupled exports (effects hooks, `useExportWav`, `useOutputMeter`, `useMasterAnalyser`) live at the **`@waveform-playlist/browser/tone`** subpath:
36
37
 
37
38
  ```typescript
38
- import { useAudioTracks, useDynamicEffects, useExportWav } from '@waveform-playlist/browser/tone';
39
+ import { useDynamicEffects, useExportWav } from '@waveform-playlist/browser/tone';
39
40
  ```
40
41
 
41
42
  ## Quick Start
@@ -44,54 +45,89 @@ import { useAudioTracks, useDynamicEffects, useExportWav } from '@waveform-playl
44
45
  import {
45
46
  WaveformPlaylistProvider,
46
47
  Waveform,
48
+ WaveformViewOptions,
47
49
  PlayButton,
48
50
  PauseButton,
49
51
  StopButton,
52
+ useCreateArrangement,
50
53
  } from '@waveform-playlist/browser';
51
- import { useAudioTracks } from '@waveform-playlist/browser/tone';
54
+ import { audioTrack } from '@waveform-playlist/core';
52
55
 
53
56
  function MyPlaylist() {
54
- const { tracks, loading, error } = useAudioTracks([
55
- { src: '/audio/vocals.mp3', name: 'Vocals' },
56
- { src: '/audio/guitar.mp3', name: 'Guitar' },
57
+ // One arrangement for the life of the component: it owns the tracks and loads their audio
58
+ const arrangement = useCreateArrangement(() => [
59
+ audioTrack({ src: '/audio/vocals.mp3', name: 'Vocals' }),
60
+ audioTrack({ src: '/audio/guitar.mp3', name: 'Guitar' }),
57
61
  ]);
58
62
 
59
- if (loading) return <div>Loading audio...</div>;
60
- if (error) return <div>Error: {error}</div>;
61
-
62
63
  return (
63
- <WaveformPlaylistProvider
64
- tracks={tracks}
65
- samplesPerPixel={1024}
66
- waveHeight={128}
67
- timescale
68
- controls={{ show: true, width: 200 }}
69
- >
64
+ <WaveformPlaylistProvider arrangement={arrangement} samplesPerPixel={1024}>
70
65
  <div style={{ display: 'flex', gap: '0.5rem', marginBottom: '1rem' }}>
71
66
  <PlayButton />
72
67
  <PauseButton />
73
68
  <StopButton />
74
69
  </div>
75
- <Waveform />
70
+ <WaveformViewOptions waveHeight={128}>
71
+ <Waveform />
72
+ </WaveformViewOptions>
76
73
  </WaveformPlaylistProvider>
77
74
  );
78
75
  }
79
76
  ```
80
77
 
78
+ `<WaveformViewOptions>` sets the options that only affect how a view draws (`waveHeight`, `barWidth`, `barGap`, `roundedBars`, `progressBarWidth`, `fillViewport`) for every view below it. They are not provider props. It works under either provider and may sit above the provider, also above several.
79
+
81
80
  Prefer a lightweight single-track player instead? Use `MediaElementPlaylistProvider` with `@waveform-playlist/media-element-playout` — no Tone.js, no AudioBuffer decoding, and pitch-preserving playback rate out of the box.
82
81
 
83
82
  ## Context Hooks
84
83
 
85
- `WaveformPlaylistProvider` splits its context into four hooks so components only re-render for the data they actually read:
86
-
87
- | Hook | Exposes |
88
- |------|---------|
89
- | `usePlaybackAnimation` | `isPlaying`, `currentTime`, animation refs, `getPlaybackTime()`, `registerFrameCallback()` for 60fps-driven UI (playhead, progress bars) |
90
- | `usePlaylistState` | Low-frequency state — selection, loop region, annotations, `selectedTrackId`, `canUndo`/`canRedo` |
91
- | `usePlaylistControls` | Actions — `play`, `pause`, `stop`, `seekTo`, track mute/solo/volume/pan, zoom, undo/redo, `setRecordingActive` (recording-session suppression + armed-track mute) |
92
- | `usePlaylistData` | Derived/config data — `tracks`, `duration`, `sampleRate`, `peaksDataArray`, `trackStates`, `isReady` |
93
-
94
- `usePlaylistDataOptional` is the same as `usePlaylistData` but returns `null` outside a provider (for components that render both inside and outside one). `MediaElementPlaylistProvider` has the equivalent `useMediaElementAnimation`, `useMediaElementState`, `useMediaElementControls`, `useMediaElementData`.
84
+ Each provider splits its context into one hook per group of fields that change together, so components only re-render for the data they actually read. The two providers serve what they share through the same hooks, so a component written against the first table works under either; a hook reads the nearest provider.
85
+
86
+ Under either provider:
87
+
88
+ | Hook | Exposes | Re-renders on |
89
+ |------|---------|---------------|
90
+ | `useIsPlaying` | `isPlaying` | play, pause, stop |
91
+ | `useCurrentTime` | `currentTime` — where the cursor rests; does not advance during playback | a seek, a pause, a stop and a leftward selection drag |
92
+ | `useSelection` | `selectionStart`, `selectionEnd` | every pointer move of a selection drag, so only components that show the selection should call it |
93
+ | `useActiveAnnotation` | `activeAnnotationId` | every annotation boundary during playback, so only components that show the active annotation should call it |
94
+ | `useAnnotations` | `annotations` | an annotation edit |
95
+ | `useAnnotationOptions` | `editable`, `linkEndpoints`, `continuousPlay`: the three annotation options. They start from the provider's `annotationList` prop and follow it | one of the three being toggled |
96
+ | `usePlaybackControls` | Actions — `play`, `pause`, `stop`, `seekTo`, `setSelection`, and the annotation, scroll and time-format setters | never |
97
+ | `usePlaybackRefs` | `currentTimeRef` (the live position), `visualTimeRef` (the position to draw), `registerFrameCallback()` / `unregisterFrameCallback()` for 60fps-driven UI (playhead, progress bars) | never |
98
+ | `usePlaylistView` | What the provider was configured with that a view also reads: `sampleRate`, `mono`, `indefinitePlayback`. The view options are not here: inside a view, `usePlaylistInfo()` from `@waveform-playlist/ui-components` has the resolved `waveHeight`, `barWidth`, `barGap`, `roundedBars` and `progressBarWidth` | a provider prop change |
99
+ | `usePlaylistSettings` | `timeFormat`, `isAutomaticScroll` | the user changing either setting |
100
+ | `usePlaylistZoom` | `samplesPerPixel`, `canZoomIn`, `canZoomOut` | a zoom |
101
+
102
+ `WaveformPlaylistProvider` only:
103
+
104
+ | Hook | Exposes | Re-renders on |
105
+ |------|---------|---------------|
106
+ | `useArrangement` | The provider's `Arrangement`: change the tracks through it | never |
107
+ | `useEditorControls` | Actions — track mute/solo/volume/pan (by track id), track order, zoom, loop, undo/redo (on the arrangement, engine or not), `setRecordingActive` (recording-session suppression + armed-track mute) | never |
108
+ | `useEngineRefs` | `playoutRef` (the engine), `getPlaybackTime()`, `getAudioContextTime()`, `getLookAhead()`, `getOutputLatency()`, `playbackStartTimeRef`, `audioStartPositionRef` | never |
109
+ | `usePlaylistTimeline` | `tracks` (loaded clips only, read-only), `peaksDataArray` (with placeholder records for clips still loading), `duration` (loaded audio), `isReady` | every clip operation (a trim once, on release), a zoom (`peaksDataArray` is computed per zoom level), audio or peaks arriving, `isReady` changing |
110
+ | `usePlaylistMixer` | `trackStates` (one entry per track in the order of `tracks`, also while a track loads), `masterVolume` | every mute, solo, volume or pan change (each step of a slider drag); tracks added, removed, renamed or reordered |
111
+ | `useTrack` | Among the children of `<WaveformTrackControls>` only: the track whose panel is being drawn (id, name, mixer state, `isSelected`, `isRecordingArmed`) and actions bound to it (`setMuted`, `setVolume`, `moveUp`, …) | a change of that track's state, position or selection |
112
+ | `useTrackReorderPreview` | `trackDragPreview`, `trackReorderEpoch` | every drag-over of a track reorder |
113
+ | `useLoop` | `isLoopEnabled`, `loopStart`, `loopEnd` | a loop change |
114
+ | `useSelectedTrackId` | `selectedTrackId` | another track being selected |
115
+ | `useUndoRedo` | `canUndo`, `canRedo` | after an edit |
116
+
117
+ `MediaElementPlaylistProvider` only:
118
+
119
+ | Hook | Exposes | Re-renders on |
120
+ |------|---------|---------------|
121
+ | `usePlaybackRate` | `playbackRate`, `setPlaybackRate` | the speed changing |
122
+ | `useMediaElementTrack` | `duration`, `isReady`, `peaksDataArray`, `fadeIn`, `fadeOut`, `playoutRef` (the player) | the track or the zoom level changing, the player becoming ready |
123
+
124
+ `usePlaylistTimeline` and `usePlaylistMixer` change during an interaction; call them in the smallest component that needs them. `usePlaybackRefs` and `useEngineRefs` never re-render the component that calls them: read a ref's `.current` in a handler, an effect or a frame callback.
125
+
126
+ The transport buttons (`PlayButton`, `PauseButton`, `StopButton`, `RewindButton`, `FastForwardButton`, `SkipBackwardButton`, `SkipForwardButton`), `AudioPosition`, `TimeFormatSelect`, `SelectionTimeInputs` and `AutomaticScrollCheckbox` work under either provider. `PlaybackRateSelect` works under `MediaElementPlaylistProvider` only.
127
+
128
+ ## Arrangement Hooks
129
+
130
+ `useCreateArrangement(init?, options?)` makes the `Arrangement` (from `@waveform-playlist/engine`) that owns a multitrack editor's tracks, one per component instance: pass it to `<WaveformPlaylistProvider arrangement>`. `useArrangementTracks(arrangement)` returns its tracks, loading clips included, and re-renders when they change, not on a mix change; `useArrangementSources(arrangement)` returns where each source is (`pending`, `loaded` or `failed`) with `pendingCount`, `failedCount` and `isLoading`. They are in the core entry. See the [hooks reference](https://naomiaro.github.io/waveform-playlist/docs/react/api/hooks#arrangement-hooks) and the [Loading Audio guide](https://naomiaro.github.io/waveform-playlist/docs/react/guides/loading-audio).
95
131
 
96
132
  ## Examples & Documentation
97
133