@waveform-playlist/core 12.6.2 → 13.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
@@ -62,6 +62,7 @@ parseSpectrogramCanvasId(id);
62
62
  | `clipTimeHelpers` | `clipStartTime`, `clipEndTime`, `clipOffsetTime`, `clipDurationTime`, `clipPixelWidth`, `trackChannelCount` |
63
63
  | clip constructors (`types/clip`) | `createClip`, `createClipFromSeconds`, `createClipFromTicks`, `createTrack`, `createTimeline`, `getClipsInRange`, `getClipsAtSample`, `clipsOverlap`, `sortClipsByTime`, `findGaps` |
64
64
  | `fades` | `applyFadeIn`, `applyFadeOut`, `generateCurve`, `linearCurve`, `exponentialCurve`, `logarithmicCurve`, `sCurveCurve` |
65
+ | `panStage` | `createPanStage`, `panMatrix`, `PanStage`, `PanMatrix`, `PanStageContext` |
65
66
  | `utils/dBUtils` | `gainToDb`, `dBToNormalized`, `normalizedToDb`, `gainToNormalized` |
66
67
  | `utils/conversions` | `samplesToSeconds`, `secondsToSamples`, `samplesToPixels`, `pixelsToSamples`, `pixelsToSeconds`, `secondsToPixels` |
67
68
  | `utils/beatsAndBars` | `PPQN`, `ticksPerBeat`, `ticksPerBar`, `ticksToSamples`, `samplesToTicks`, `snapToGrid` |
@@ -71,8 +72,8 @@ parseSpectrogramCanvasId(id);
71
72
  | `utils/audioBufferUtils` | `concatenateAudioData`, `createAudioBuffer`, `appendToAudioBuffer`, `calculateDuration` |
72
73
  | `utils/latency` | `resolveRecordingOffsetSamples` — override-vs-auto recording latency compensation (shared by React + dawcore) |
73
74
  | `utils/carveClipRange` | `carveClipRange` — punch-in replace: carve a sample range out of a clip list (trim/remove/split) |
74
- | `keyboard` | `KeyboardShortcut`, `handleKeyboardEvent`, `getShortcutLabel` |
75
- | `spectrogramCanvasId` | `buildSpectrogramCanvasId`, `parseSpectrogramCanvasId`, `SpectrogramCanvasIdParts` |
75
+ | `keyboard` | `KeyboardShortcut`, `handleKeyboardEvent` |
76
+ | `spectrogramCanvasId` | `buildSpectrogramCanvasId`, `parseSpectrogramCanvasId`, `SpectrogramCanvasIdParts`, `SpectrogramCanvasRegistration` |
76
77
  | `probeRangeSupport` | `probeRangeSupport`, `RangeSupport` |
77
78
  | `enumerateMicrophones` | `enumerateMicrophones`, `watchMicrophoneDevices`, `MicrophoneEnumeration` — permission-free device listing with `supported`/`hasLabels` flags (labels are browser-redacted pre-permission) |
78
79
  | `constants` | `MAX_CANVAS_WIDTH` |
@@ -84,3 +85,76 @@ parseSpectrogramCanvasId(id);
84
85
  ## License
85
86
 
86
87
  MIT
88
+
89
+ ## Pan stage
90
+
91
+ `createPanStage(audioContext, pan, sourceChannelCount)` builds a track's pan stage from plain gain, splitter and merger nodes. Every renderer in this project pans with it — the native transport, the Tone.js adapter and both offline exports — instead of a Web Audio `StereoPannerNode` or a Tone.js `Panner`.
92
+
93
+ ```typescript
94
+ import { createPanStage, trackChannelCount } from '@waveform-playlist/core';
95
+
96
+ const stage = createPanStage(audioContext, track.pan, trackChannelCount(track));
97
+ faderNode.connect(stage.input);
98
+ stage.output.connect(muteNode);
99
+
100
+ stage.setPan(-0.5);
101
+ stage.setSourceChannelCount(2); // the track gained a stereo clip
102
+ stage.dispose();
103
+ ```
104
+
105
+ Why not the built-in nodes:
106
+
107
+ - **`StereoPannerNode`** chooses its pan law from the signal it receives: equal-power for mono input (−3 dB per side at centre), the stereo law for stereo input (unity at centre). Track effects are pre-fader inserts, so the panner would be fed by the effects chain and the law would follow the chain's output: a mono track would jump about 3 dB at centre as soon as a stereo effect was added.
108
+ - **Tone.js `Panner`** wraps a `StereoPannerNode` with a fixed channel count. On Tone's default context (standardized-audio-context) that setting cannot be changed, so a mono track's panner is locked to one channel and a stereo effect on the track is summed to mono before it is panned.
109
+
110
+ The stage implements the same two laws as `StereoPannerNode` (`panMatrix(pan, sourceChannelCount)` is the pure math) but takes the law from the caller — the channel count of the track's source material — and always passes stereo through. It works on any `AudioContext` or `OfflineAudioContext`, and on the raw context behind Tone.js.
111
+
112
+ ## Effect registry
113
+
114
+ `registerEffect(type, definition)` makes a custom effect (an `AudioWorkletNode`, or any chain of native nodes) available by id to both hosts in this project: `<daw-editor>` (`editor.addEffect(type)`) and the React effects hooks (`addEffect(type)` from `useDynamicEffects()`). Both render it in their offline exports.
115
+
116
+ ```typescript
117
+ import { registerEffect } from '@waveform-playlist/core';
118
+
119
+ registerEffect('my-tremolo', {
120
+ label: 'Tremolo',
121
+ category: 'modulation',
122
+ defaults: { rate: 6, depth: 0.8 },
123
+ params: {
124
+ rate: { min: 0.1, max: 20, step: 0.1, unit: 'Hz' },
125
+ depth: { min: 0, max: 1, step: 0.01 },
126
+ },
127
+ // Optional. Runs once per audio context, the offline one of an export included.
128
+ prepare: (audioContext) => audioContext.audioWorklet.addModule('/worklets/tremolo.js'),
129
+ create: (audioContext) => {
130
+ const node = new AudioWorkletNode(audioContext, 'my-tremolo');
131
+ return {
132
+ input: node,
133
+ output: node,
134
+ applyParams: (params) => {
135
+ for (const name of ['rate', 'depth']) {
136
+ const param = node.parameters.get(name); // AudioParam | undefined
137
+ const value = params[name];
138
+ if (param && value !== undefined) param.value = value;
139
+ }
140
+ },
141
+ // Tell the processor to stop (it returns false from process() once it
142
+ // has received this message), then disconnect.
143
+ dispose: () => {
144
+ node.port.postMessage('dispose');
145
+ node.disconnect();
146
+ },
147
+ };
148
+ },
149
+ });
150
+ ```
151
+
152
+ The two hosts await `prepare` differently. The React `addEffect(type)` is async and awaits it itself. `<daw-editor>`'s `addEffect(type)` is synchronous, so for a definition with `prepare` call `await editor.prepareEffect(type)` first. Both await it for their offline exports.
153
+
154
+ The host owns every connection out of the instance's `output` and disconnects all of them when it rewires the chain, so do not connect `output` to anything inside the effect (take a feedback tap from a node before it).
155
+
156
+ For an AudioWorklet effect, let `dispose` stop the processor with a port message, as above; a processor that always returns `true` from `process()` runs until the page closes. Do not have the processor return `false` whenever it is idle: in Chrome, a processor that returned `false` while nothing was connected to it (the effect bypassed by disconnection) did not run again when reconnected.
157
+
158
+ A definition with a `wetParam` is bypassed by setting that parameter to 0; one without is disconnected while bypassed. Also exported: `unregisterEffect`, `getEffectDefinitions`, `prepareEffect`, `ensureEffectPrepared`, `needsPrepare`, `createEffectInstance`, and the types `NativeEffectDefinition`, `NativeEffectInstance` and `EffectParamDef`.
159
+
160
+ The registry is stored on `globalThis`, so an effect registered through one installed copy of this package is visible to a host that uses another copy.