@waveform-playlist/playout 12.5.5 → 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
@@ -10,6 +10,19 @@ npm install @waveform-playlist/playout
10
10
 
11
11
  Requires `tone` (`^15.0.0`) as a peer dependency — this package doesn't bundle Tone.js, so the version in your app is the one that runs. `@waveform-playlist/engine` is an optional peer; most consumers pull in both automatically via `@waveform-playlist/browser` rather than installing this package directly.
12
12
 
13
+ ### Tone.js versions
14
+
15
+ Two Tone.js lines satisfy the `^15.0.0` peer range, and both are tested on every pull request (build, type-check and unit tests, including a contract test for the Tone.js internals this package depends on):
16
+
17
+ | | Install | Notes |
18
+ |---|---|---|
19
+ | Stable (default) | `npm install tone` — 15.1.x | What the examples and documentation site run. |
20
+ | Prerelease | `npm install tone@next` — 15.5.x | Where upstream fixes land; Tone's stable line rarely releases. |
21
+
22
+ What you gain on `tone@next`: `configureGlobalContext({ sampleRate })` is honoured on the default audio context. On 15.1.x Tone.js ignores the option there, the context runs at the hardware rate, and a warning is logged (use `nativeAudioContext: true` to set the rate on 15.1.x). The function returns the rate actually in use on both.
23
+
24
+ `next` is a moving prerelease tag. Pin an exact version in your app if you adopt it.
25
+
13
26
  ## Usage
14
27
 
15
28
  ```typescript
package/dist/index.d.mts CHANGED
@@ -3,7 +3,22 @@ import { Fade, Track, MidiNoteData } from '@waveform-playlist/core';
3
3
  import { ZoneMap, Generator, GeneratorType } from 'soundfont2';
4
4
  import { PlayoutAdapter } from '@waveform-playlist/engine';
5
5
 
6
- type TrackEffectsFunction = (graphEnd: Gain, masterGainNode: ToneAudioNode, isOffline: boolean) => void | (() => void);
6
+ /**
7
+ * Wires a track's effects, PRE-FADER (#660): connect `trackInput` through
8
+ * your effects and into `faderInput`. The track's volume, pan and mute come
9
+ * after, so the fader never changes how hard a compressor or distortion
10
+ * works.
11
+ *
12
+ * The chain MUST end at `faderInput`. Anything connected elsewhere (the
13
+ * master bus, `toDestination()`) bypasses the track's volume, pan, mute and
14
+ * solo.
15
+ *
16
+ * @param trackInput - Where the track's clips/notes arrive (unity gain)
17
+ * @param faderInput - The track's volume stage; connect the chain's end here
18
+ * @param isOffline - Whether rendering offline (for export)
19
+ * @returns Optional cleanup function called when the track is disposed
20
+ */
21
+ type TrackEffectsFunction = (trackInput: Gain, faderInput: ToneAudioNode, isOffline: boolean) => void | (() => void);
7
22
  interface ClipInfo {
8
23
  buffer: AudioBuffer;
9
24
  startTime: number;
@@ -19,7 +34,7 @@ interface ToneTrackOptions {
19
34
  track: Track;
20
35
  effects?: TrackEffectsFunction;
21
36
  destination?: ToneAudioNode;
22
- /** Max channel count across clips — sets Panner channelCount. Default: 1 */
37
+ /** Max channel count across clips — selects the pan law (core's createPanStage). Default: 1 */
23
38
  channelCount?: number;
24
39
  }
25
40
  /** Per-clip scheduling info and audio nodes */
@@ -31,14 +46,15 @@ interface ScheduledClip {
31
46
  declare class ToneTrack {
32
47
  private scheduledClips;
33
48
  private activeSources;
49
+ /** Pre-fader summing point: clip sources → inputGain → [effects] → volume. */
50
+ private inputGain;
34
51
  private volumeNode;
35
- private panNode;
52
+ private panStage;
36
53
  private muteGain;
37
54
  private track;
38
55
  private effectsCleanup?;
39
- private _destination;
40
56
  private _hasClosureEffects;
41
- private _effectsChainNode;
57
+ private _effectsChain;
42
58
  private _scheduleGuardOffset;
43
59
  constructor(options: ToneTrackOptions);
44
60
  /**
@@ -71,6 +87,13 @@ declare class ToneTrack {
71
87
  * disconnects the fadeGainNode.
72
88
  */
73
89
  removeScheduledClip(index: number): void;
90
+ /**
91
+ * Select the pan law from the track's source material: 1 = mono law,
92
+ * 2+ = stereo law. Call when the track's clips change — a stereo clip
93
+ * joining a mono track moves it to the stereo law (same rule as the
94
+ * native transport and the offline export).
95
+ */
96
+ setSourceChannelCount(sourceChannelCount: number): void;
74
97
  /**
75
98
  * Replace clips on this track. Diffs old vs new by buffer + timing —
76
99
  * unchanged clips keep their active sources playing (no audible interruption).
@@ -106,15 +129,21 @@ declare class ToneTrack {
106
129
  setPan(pan: number): void;
107
130
  setMute(muted: boolean): void;
108
131
  setSolo(soloed: boolean): void;
132
+ /** Native node behind the Volume stage — where an external chain returns. */
133
+ private get _faderNativeInput();
109
134
  /**
110
- * Insert an external effects chain: reroute muteGain → node instead of
111
- * muteGain → destination. The caller wires the chain's output onward
112
- * (dawcore's EffectsManager connects it to the master bus input).
113
- * Mutually exclusive with the TrackEffectsFunction closure model.
135
+ * Insert an external effects chain PRE-FADER (#660):
136
+ * `inputGain → input … output → volume → pan → mute`. The track owns both
137
+ * edges; the caller only builds what lies between the two nodes (pass the
138
+ * same node twice for a single-node effect). Replaces any chain connected
139
+ * earlier. Mutually exclusive with the TrackEffectsFunction closure model.
114
140
  */
115
- connectEffects(node: AudioNode): void;
116
- /** Restore the direct muteGain → destination connection. Safe when nothing is connected. */
141
+ connectEffects(input: AudioNode, output: AudioNode): void;
142
+ /** Restore the direct inputGain → volume connection. Safe when nothing is connected. */
117
143
  disconnectEffects(): void;
144
+ /** Targeted disconnect of the chain's return edge (output → volume); a
145
+ * consumer may have disposed its chain first, so failures only warn. */
146
+ private _releaseEffectsChain;
118
147
  dispose(): void;
119
148
  get id(): string;
120
149
  get duration(): number;
@@ -170,8 +199,10 @@ declare class MidiToneTrack implements PlayableTrack {
170
199
  private snareSynth;
171
200
  private cymbalSynth;
172
201
  private tomSynth;
202
+ /** Pre-fader summing point: voices → inputGain → [effects] → volume. */
203
+ private inputGain;
173
204
  private volumeNode;
174
- private panNode;
205
+ private panStage;
175
206
  private muteGain;
176
207
  private track;
177
208
  private effectsCleanup?;
@@ -401,8 +432,10 @@ declare class SoundFontToneTrack implements PlayableTrack {
401
432
  private soundFontCache;
402
433
  private programNumber;
403
434
  private bankNumber;
435
+ /** Pre-fader summing point: voices → inputGain → [effects] → volume. */
436
+ private inputGain;
404
437
  private volumeNode;
405
- private panNode;
438
+ private panStage;
406
439
  private muteGain;
407
440
  private track;
408
441
  private effectsCleanup?;
@@ -478,8 +511,10 @@ declare class TonePlayout {
478
511
  /**
479
512
  * Replace clips on a track, preserving the track's audio graph.
480
513
  * Only works for ToneTrack (audio clips), not MidiToneTrack.
514
+ * `sourceChannelCount` (max channel count across the new clips) re-selects
515
+ * the track's pan law; omit to leave it unchanged.
481
516
  */
482
- replaceTrackClips(trackId: string, newClips: ClipInfo[], newStartTime?: number): boolean;
517
+ replaceTrackClips(trackId: string, newClips: ClipInfo[], newStartTime?: number, sourceChannelCount?: number): boolean;
483
518
  /**
484
519
  * Start mid-clip sources for a specific track at the current Transport position.
485
520
  * Call after adding/updating a track during active playback so clips that span
@@ -500,10 +535,13 @@ declare class TonePlayout {
500
535
  * masterOutputNode (the post-volume tap for analyzers).
501
536
  */
502
537
  get masterBusInputNode(): GainNode;
503
- /** Insert an external chain on a track: muteGain → node (caller wires node onward). */
504
- connectTrackOutput(trackId: string, node: AudioNode): void;
538
+ /**
539
+ * Insert an external chain on a track, PRE-FADER (#660): clips → input …
540
+ * output → volume → pan → mute. The track wires both edges.
541
+ */
542
+ connectTrackEffects(trackId: string, input: AudioNode, output: AudioNode): void;
505
543
  /** Restore a track's direct connection. No-op for unknown or MIDI tracks. */
506
- disconnectTrackOutput(trackId: string): void;
544
+ disconnectTrackEffects(trackId: string): void;
507
545
  /**
508
546
  * Insert an external master chain after the tap: masterVolume → [closure
509
547
  * effects] → tap → node (caller wires node.output → ctx.destination).
@@ -544,8 +582,10 @@ interface AudioContextOptions {
544
582
  * (Firefox), where Tone.js Listener initialization would throw.
545
583
  */
546
584
  nativeAudioContext?: boolean;
547
- /** Desired sample rate. Creates a standardized-audio-context AudioContext
548
- * at this rate, bypassing Tone.js 15.1.22's limitation. Cross-browser safe. */
585
+ /** Desired sample rate. Honoured in native mode, and in the default mode
586
+ * with Tone.js 15.5.x (`tone@next`). Tone.js 15.1.22 ignores it in the
587
+ * default mode: the context runs at the hardware rate and a warning is
588
+ * logged. The return value is always the rate actually in use. */
549
589
  sampleRate?: number;
550
590
  /** Latency hint passed to the AudioContext constructor. */
551
591
  latencyHint?: AudioContextLatencyCategory | number;
@@ -663,7 +703,17 @@ declare function hasMediaStreamSource(stream: MediaStream): boolean;
663
703
  declare function getUnderlyingAudioParam(signal: unknown): AudioParam | undefined;
664
704
 
665
705
  interface ToneAdapterOptions {
706
+ /** Master effects chain. */
666
707
  effects?: EffectsFunction;
708
+ /**
709
+ * Returns the effects function of a track, or `undefined` for none. Called
710
+ * with the track's id each time the adapter builds that track's audio graph:
711
+ * `setTracks`, `addTrack`, a SoundFont swap, and an `updateTrack` that
712
+ * builds rather than edits in place (a MIDI track, or an audio track that
713
+ * had no clips before). An `updateTrack` that only changes the clips of an
714
+ * existing audio track keeps its graph and does not ask.
715
+ */
716
+ trackEffects?: (trackId: string) => TrackEffectsFunction | undefined;
667
717
  /** When provided, MIDI clips use SoundFont sample playback instead of PolySynth */
668
718
  soundFontCache?: SoundFontCache;
669
719
  /** Pulses per quarter note. Defaults to 192 (Tone.js native). */
@@ -676,8 +726,9 @@ interface ToneAdapterOptions {
676
726
  * a standardized-audio-context graph.
677
727
  */
678
728
  interface ToneEffectsTransport {
679
- connectTrackOutput(trackId: string, node: AudioNode): void;
680
- disconnectTrackOutput(trackId: string): void;
729
+ /** Pre-fader track insert: clips → input … output → volume → pan → mute. */
730
+ connectTrackEffects(trackId: string, input: AudioNode, output: AudioNode): void;
731
+ disconnectTrackEffects(trackId: string): void;
681
732
  connectMasterOutput(node: AudioNode): void;
682
733
  disconnectMasterOutput(): void;
683
734
  readonly masterOutputNode: AudioNode;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,22 @@ import { Fade, Track, MidiNoteData } from '@waveform-playlist/core';
3
3
  import { ZoneMap, Generator, GeneratorType } from 'soundfont2';
4
4
  import { PlayoutAdapter } from '@waveform-playlist/engine';
5
5
 
6
- type TrackEffectsFunction = (graphEnd: Gain, masterGainNode: ToneAudioNode, isOffline: boolean) => void | (() => void);
6
+ /**
7
+ * Wires a track's effects, PRE-FADER (#660): connect `trackInput` through
8
+ * your effects and into `faderInput`. The track's volume, pan and mute come
9
+ * after, so the fader never changes how hard a compressor or distortion
10
+ * works.
11
+ *
12
+ * The chain MUST end at `faderInput`. Anything connected elsewhere (the
13
+ * master bus, `toDestination()`) bypasses the track's volume, pan, mute and
14
+ * solo.
15
+ *
16
+ * @param trackInput - Where the track's clips/notes arrive (unity gain)
17
+ * @param faderInput - The track's volume stage; connect the chain's end here
18
+ * @param isOffline - Whether rendering offline (for export)
19
+ * @returns Optional cleanup function called when the track is disposed
20
+ */
21
+ type TrackEffectsFunction = (trackInput: Gain, faderInput: ToneAudioNode, isOffline: boolean) => void | (() => void);
7
22
  interface ClipInfo {
8
23
  buffer: AudioBuffer;
9
24
  startTime: number;
@@ -19,7 +34,7 @@ interface ToneTrackOptions {
19
34
  track: Track;
20
35
  effects?: TrackEffectsFunction;
21
36
  destination?: ToneAudioNode;
22
- /** Max channel count across clips — sets Panner channelCount. Default: 1 */
37
+ /** Max channel count across clips — selects the pan law (core's createPanStage). Default: 1 */
23
38
  channelCount?: number;
24
39
  }
25
40
  /** Per-clip scheduling info and audio nodes */
@@ -31,14 +46,15 @@ interface ScheduledClip {
31
46
  declare class ToneTrack {
32
47
  private scheduledClips;
33
48
  private activeSources;
49
+ /** Pre-fader summing point: clip sources → inputGain → [effects] → volume. */
50
+ private inputGain;
34
51
  private volumeNode;
35
- private panNode;
52
+ private panStage;
36
53
  private muteGain;
37
54
  private track;
38
55
  private effectsCleanup?;
39
- private _destination;
40
56
  private _hasClosureEffects;
41
- private _effectsChainNode;
57
+ private _effectsChain;
42
58
  private _scheduleGuardOffset;
43
59
  constructor(options: ToneTrackOptions);
44
60
  /**
@@ -71,6 +87,13 @@ declare class ToneTrack {
71
87
  * disconnects the fadeGainNode.
72
88
  */
73
89
  removeScheduledClip(index: number): void;
90
+ /**
91
+ * Select the pan law from the track's source material: 1 = mono law,
92
+ * 2+ = stereo law. Call when the track's clips change — a stereo clip
93
+ * joining a mono track moves it to the stereo law (same rule as the
94
+ * native transport and the offline export).
95
+ */
96
+ setSourceChannelCount(sourceChannelCount: number): void;
74
97
  /**
75
98
  * Replace clips on this track. Diffs old vs new by buffer + timing —
76
99
  * unchanged clips keep their active sources playing (no audible interruption).
@@ -106,15 +129,21 @@ declare class ToneTrack {
106
129
  setPan(pan: number): void;
107
130
  setMute(muted: boolean): void;
108
131
  setSolo(soloed: boolean): void;
132
+ /** Native node behind the Volume stage — where an external chain returns. */
133
+ private get _faderNativeInput();
109
134
  /**
110
- * Insert an external effects chain: reroute muteGain → node instead of
111
- * muteGain → destination. The caller wires the chain's output onward
112
- * (dawcore's EffectsManager connects it to the master bus input).
113
- * Mutually exclusive with the TrackEffectsFunction closure model.
135
+ * Insert an external effects chain PRE-FADER (#660):
136
+ * `inputGain → input … output → volume → pan → mute`. The track owns both
137
+ * edges; the caller only builds what lies between the two nodes (pass the
138
+ * same node twice for a single-node effect). Replaces any chain connected
139
+ * earlier. Mutually exclusive with the TrackEffectsFunction closure model.
114
140
  */
115
- connectEffects(node: AudioNode): void;
116
- /** Restore the direct muteGain → destination connection. Safe when nothing is connected. */
141
+ connectEffects(input: AudioNode, output: AudioNode): void;
142
+ /** Restore the direct inputGain → volume connection. Safe when nothing is connected. */
117
143
  disconnectEffects(): void;
144
+ /** Targeted disconnect of the chain's return edge (output → volume); a
145
+ * consumer may have disposed its chain first, so failures only warn. */
146
+ private _releaseEffectsChain;
118
147
  dispose(): void;
119
148
  get id(): string;
120
149
  get duration(): number;
@@ -170,8 +199,10 @@ declare class MidiToneTrack implements PlayableTrack {
170
199
  private snareSynth;
171
200
  private cymbalSynth;
172
201
  private tomSynth;
202
+ /** Pre-fader summing point: voices → inputGain → [effects] → volume. */
203
+ private inputGain;
173
204
  private volumeNode;
174
- private panNode;
205
+ private panStage;
175
206
  private muteGain;
176
207
  private track;
177
208
  private effectsCleanup?;
@@ -401,8 +432,10 @@ declare class SoundFontToneTrack implements PlayableTrack {
401
432
  private soundFontCache;
402
433
  private programNumber;
403
434
  private bankNumber;
435
+ /** Pre-fader summing point: voices → inputGain → [effects] → volume. */
436
+ private inputGain;
404
437
  private volumeNode;
405
- private panNode;
438
+ private panStage;
406
439
  private muteGain;
407
440
  private track;
408
441
  private effectsCleanup?;
@@ -478,8 +511,10 @@ declare class TonePlayout {
478
511
  /**
479
512
  * Replace clips on a track, preserving the track's audio graph.
480
513
  * Only works for ToneTrack (audio clips), not MidiToneTrack.
514
+ * `sourceChannelCount` (max channel count across the new clips) re-selects
515
+ * the track's pan law; omit to leave it unchanged.
481
516
  */
482
- replaceTrackClips(trackId: string, newClips: ClipInfo[], newStartTime?: number): boolean;
517
+ replaceTrackClips(trackId: string, newClips: ClipInfo[], newStartTime?: number, sourceChannelCount?: number): boolean;
483
518
  /**
484
519
  * Start mid-clip sources for a specific track at the current Transport position.
485
520
  * Call after adding/updating a track during active playback so clips that span
@@ -500,10 +535,13 @@ declare class TonePlayout {
500
535
  * masterOutputNode (the post-volume tap for analyzers).
501
536
  */
502
537
  get masterBusInputNode(): GainNode;
503
- /** Insert an external chain on a track: muteGain → node (caller wires node onward). */
504
- connectTrackOutput(trackId: string, node: AudioNode): void;
538
+ /**
539
+ * Insert an external chain on a track, PRE-FADER (#660): clips → input …
540
+ * output → volume → pan → mute. The track wires both edges.
541
+ */
542
+ connectTrackEffects(trackId: string, input: AudioNode, output: AudioNode): void;
505
543
  /** Restore a track's direct connection. No-op for unknown or MIDI tracks. */
506
- disconnectTrackOutput(trackId: string): void;
544
+ disconnectTrackEffects(trackId: string): void;
507
545
  /**
508
546
  * Insert an external master chain after the tap: masterVolume → [closure
509
547
  * effects] → tap → node (caller wires node.output → ctx.destination).
@@ -544,8 +582,10 @@ interface AudioContextOptions {
544
582
  * (Firefox), where Tone.js Listener initialization would throw.
545
583
  */
546
584
  nativeAudioContext?: boolean;
547
- /** Desired sample rate. Creates a standardized-audio-context AudioContext
548
- * at this rate, bypassing Tone.js 15.1.22's limitation. Cross-browser safe. */
585
+ /** Desired sample rate. Honoured in native mode, and in the default mode
586
+ * with Tone.js 15.5.x (`tone@next`). Tone.js 15.1.22 ignores it in the
587
+ * default mode: the context runs at the hardware rate and a warning is
588
+ * logged. The return value is always the rate actually in use. */
549
589
  sampleRate?: number;
550
590
  /** Latency hint passed to the AudioContext constructor. */
551
591
  latencyHint?: AudioContextLatencyCategory | number;
@@ -663,7 +703,17 @@ declare function hasMediaStreamSource(stream: MediaStream): boolean;
663
703
  declare function getUnderlyingAudioParam(signal: unknown): AudioParam | undefined;
664
704
 
665
705
  interface ToneAdapterOptions {
706
+ /** Master effects chain. */
666
707
  effects?: EffectsFunction;
708
+ /**
709
+ * Returns the effects function of a track, or `undefined` for none. Called
710
+ * with the track's id each time the adapter builds that track's audio graph:
711
+ * `setTracks`, `addTrack`, a SoundFont swap, and an `updateTrack` that
712
+ * builds rather than edits in place (a MIDI track, or an audio track that
713
+ * had no clips before). An `updateTrack` that only changes the clips of an
714
+ * existing audio track keeps its graph and does not ask.
715
+ */
716
+ trackEffects?: (trackId: string) => TrackEffectsFunction | undefined;
667
717
  /** When provided, MIDI clips use SoundFont sample playback instead of PolySynth */
668
718
  soundFontCache?: SoundFontCache;
669
719
  /** Pulses per quarter note. Defaults to 192 (Tone.js native). */
@@ -676,8 +726,9 @@ interface ToneAdapterOptions {
676
726
  * a standardized-audio-context graph.
677
727
  */
678
728
  interface ToneEffectsTransport {
679
- connectTrackOutput(trackId: string, node: AudioNode): void;
680
- disconnectTrackOutput(trackId: string): void;
729
+ /** Pre-fader track insert: clips → input … output → volume → pan → mute. */
730
+ connectTrackEffects(trackId: string, input: AudioNode, output: AudioNode): void;
731
+ disconnectTrackEffects(trackId: string): void;
681
732
  connectMasterOutput(node: AudioNode): void;
682
733
  disconnectMasterOutput(): void;
683
734
  readonly masterOutputNode: AudioNode;