@dawcore/transport 0.0.16-next.0 → 0.0.16-next.10

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
@@ -183,7 +183,7 @@ transport.disconnectMasterOutput();
183
183
  - A mono clip reaches the chain as mono, at full level (not as two channels at −3 dB from a centred panner).
184
184
  - Do **not** connect the chain's output to `masterOutputNode` yourself — the transport returns it into the track. Routing it to the master would bypass the fader, pan, mute and solo.
185
185
  - Mute and solo silence a track including its effect tails.
186
- - Pan is unaffected by what the chain outputs: the pan law follows the track's clips, not the chain. A stereo reverb on a mono track stays stereo and sits at the same centre level as the dry track (see [Panning](#panning)).
186
+ - Pan is unaffected by what the chain outputs: the pan law is the track's own, not the chain's. A stereo reverb on a mono track stays stereo and sits at the same centre level as the dry track (see [Panning](#panning)).
187
187
 
188
188
  `setTracks()` rebuilds every track node and drops these hookups — reconnect afterwards. (Before 0.0.16 the hook was `connectTrackOutput(trackId, node)`, post-fader, with the caller wiring the chain to the master.)
189
189
 
@@ -193,11 +193,18 @@ A track is panned by a small gain matrix (`createPanStage` from `@waveform-playl
193
193
 
194
194
  Why: a `StereoPannerNode` chooses its pan law from the signal it _receives_ — the equal-power law for mono input (−3 dB per side at centre), the stereo law for stereo input (unity at centre). With pre-fader effects the panner is fed by the effects chain, so the law would follow the chain's output instead of the track: a mono track with a stereo reverb or a typical WAM plugin would jump about 3 dB at centre and get a different pan curve the moment the effect was added.
195
195
 
196
- The pan stage implements the same two laws — its output matches a `StereoPannerNode` fed the raw clip to within float rounding — but takes the law from the track's **source material**: the highest channel count among the track's clips (`trackChannelCount(track)`), re-evaluated on `setTracks`, `addTrack` and `updateTrack`.
196
+ The pan stage implements the same two laws — its output matches a `StereoPannerNode` fed the raw clip to within float rounding — but takes the law from the **track**: `trackPanLaw(track)` from `@waveform-playlist/core`, read on `setTracks`, `addTrack` and `updateTrack`, and changed with `setTrackPanLaw`.
197
197
 
198
- - Mono track: equal-power pan. The stage never mixes the two channels, so a stereo effect stays stereo.
199
- - Stereo track: the stereo law — centre passes both channels at unity; panning left folds the right channel into the left, and vice versa.
200
- - A track with both mono and stereo clips uses the stereo law for all of them, so its mono clips play 3 dB louder at centre than they would on a mono-only track. Adding the first stereo clip to a mono track (or removing the last one) therefore shifts the track's mono clips by 3 dB at centre. (Before 0.0.16 the law depended on which clips happened to be sounding.)
198
+ - `'mono'`: equal-power pan. The stage never mixes the two channels, so a stereo effect stays stereo.
199
+ - `'stereo'`: centre passes both channels at unity; panning left folds the right channel into the left, and vice versa.
200
+
201
+ **Which law a track has.** `trackPanLaw(track)` is the track's own `panLaw` when that is `'mono'` or `'stereo'`. A track that carries none (or `'auto'`) gets the law of its clips: `'stereo'` if any clip's buffer has two or more channels, else `'mono'`.
202
+
203
+ - **Under a `PlaylistEngine`** (the React provider, `<daw-editor>`), the arrangement decides each track's law from the first decoded audio the track holds, keeps it, and sends it in `track.panLaw`. Adding or removing clips then never moves the level of the audio already on the track.
204
+ - **Used on its own**, the transport holds no such memory: a track you pass without `panLaw` follows its clips each time you pass it. Adding the first stereo clip to a track of mono clips, or removing the last one, then moves the mono clips by 3 dB at centre (on `updateTrack` the gains ramp over 10 ms, so the step does not click; `setTracks` rebuilds every track node at its law, with no ramp). Put `panLaw: 'mono'` or `'stereo'` on the tracks you pass in to keep the level where it is.
205
+
206
+ `setTrackPanLaw(trackId, panLaw)` switches a track's law without touching its clips: playing sources go on playing. `'auto'` there means "from the clips of the track the transport holds".
207
+ - A clip of the other kind plays under the track's law: a stereo clip on a `'mono'` track stays stereo, 3 dB lower at centre, and a hard pan mutes one side; a mono clip on a `'stereo'` track plays 3 dB louder at centre than on a `'mono'` track. (Before 0.0.16 the law depended on which clips happened to be sounding.)
201
208
 
202
209
  The Tone.js adapter (`@waveform-playlist/playout`) and both offline renderers use the same stage, so pan positions and levels match across backends and between playback and export.
203
210
 
@@ -243,6 +250,7 @@ new Transport(audioContext: AudioContext, options?: TransportOptions)
243
250
  **Track Controls:**
244
251
  - `setTrackVolume(trackId, volume)`
245
252
  - `setTrackPan(trackId, pan)`
253
+ - `setTrackPanLaw(trackId, panLaw)` — `'mono'`, `'stereo'`, or `'auto'` (from the track's clips); see [Panning](#panning)
246
254
  - `setTrackMute(trackId, muted)`
247
255
  - `setTrackSolo(trackId, soloed)`
248
256
  - `setMasterVolume(volume)`
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { ClipTrack } from '@waveform-playlist/core';
1
+ import { DecidedPanLaw, PlayoutTrack, PanLaw } from '@waveform-playlist/core';
2
2
  import { PlayoutAdapter } from '@waveform-playlist/engine';
3
3
 
4
4
  /** Branded type for tick positions — prevents accidentally passing seconds where ticks are expected. */
@@ -656,8 +656,8 @@ declare class MasterNode {
656
656
  * Pan is core's gain-matrix stage, not a `StereoPannerNode` (#669): a
657
657
  * panner picks its law from the layout it RECEIVES, which pre-fader is the
658
658
  * effects chain's output — a stereo reverb on a mono track would sit ~3 dB
659
- * louder at centre. The stage takes its law from `sourceChannelCount`, the
660
- * max channel count of the track's clips, whatever the chain outputs.
659
+ * louder at centre. The stage takes its law from `panLaw` (the track's own,
660
+ * core's `trackPanLaw`), whatever the chain outputs.
661
661
  */
662
662
  declare class TrackNode {
663
663
  readonly id: string;
@@ -666,16 +666,16 @@ declare class TrackNode {
666
666
  private _panStage;
667
667
  private _muteNode;
668
668
  private _effects;
669
- constructor(id: string, audioContext: AudioContext, sourceChannelCount?: number);
669
+ constructor(id: string, audioContext: AudioContext, panLaw?: DecidedPanLaw);
670
670
  /** Where clip sources connect (pre-fader, pre-effects). */
671
671
  get input(): GainNode;
672
672
  /** Connect this track's output to a destination (master node) */
673
673
  connectOutput(destination: AudioNode): void;
674
674
  setVolume(value: number): void;
675
675
  setPan(value: number): void;
676
- /** Select the pan law from the track's source material: 1 = mono law
677
- * (−3 dB per side at centre), 2+ = stereo law (unity at centre). */
678
- setSourceChannelCount(sourceChannelCount: number): void;
676
+ /** Switch the pan law: 'mono' (−3 dB per side at centre) or 'stereo'
677
+ * (unity at centre). The gains ramp; the law it already has does nothing. */
678
+ setPanLaw(panLaw: DecidedPanLaw): void;
679
679
  setMute(muted: boolean): void;
680
680
  /**
681
681
  * Insert an effects chain between the track input and the fader:
@@ -724,13 +724,13 @@ declare class ClipPlayer implements SchedulerListener<ClipEvent> {
724
724
  constructor(audioContext: AudioContext, sampleTimeline: SampleTimeline, tempoMap: TempoMap, toAudioTime: (transportTime: number) => number);
725
725
  /** Swap in a new (immutable) TempoMap (Transport does this on every tempo edit). */
726
726
  setTempoMap(tempoMap: TempoMap): void;
727
- setTracks(tracks: ClipTrack[], trackNodes: Map<string, TrackNode>): void;
727
+ setTracks(tracks: readonly PlayoutTrack[], trackNodes: Map<string, TrackNode>): void;
728
728
  /** Set loop region using ticks. startTick is unused — loop clamping only needs
729
729
  * the end boundary; mid-clip restart at loopStart is handled by onPositionJump. */
730
730
  setLoop(enabled: boolean, _startTick: Tick, endTick: Tick): void;
731
731
  /** Set loop region using samples directly */
732
732
  setLoopSamples(enabled: boolean, _startSample: Sample, endSample: Sample): void;
733
- updateTrack(trackId: string, track: ClipTrack): void;
733
+ updateTrack(trackId: string, track: PlayoutTrack): void;
734
734
  generate(fromTick: Tick, toTick: Tick): ClipEvent[];
735
735
  consume(event: ClipEvent): void;
736
736
  onPositionJump(newTick: Tick): void;
@@ -914,12 +914,20 @@ declare class Transport {
914
914
  * (see the `discontinuity` event). Diagnostics. */
915
915
  get rebaseCount(): number;
916
916
  isPlaying(): boolean;
917
- setTracks(tracks: ClipTrack[]): void;
918
- addTrack(track: ClipTrack): void;
917
+ setTracks(tracks: readonly PlayoutTrack[]): void;
918
+ addTrack(track: PlayoutTrack): void;
919
919
  removeTrack(trackId: string): void;
920
- updateTrack(trackId: string, track: ClipTrack): void;
920
+ updateTrack(trackId: string, track: PlayoutTrack): void;
921
921
  setTrackVolume(trackId: string, volume: number): void;
922
922
  setTrackPan(trackId: string, pan: number): void;
923
+ /**
924
+ * Set a track's pan law (#684): `'mono'`, `'stereo'`, or `'auto'` for
925
+ * "from the clips of the track the transport holds". The clips are not
926
+ * touched: playing sources go on playing, and the pan stage ramps to the
927
+ * new law. A later `updateTrack` or `setTracks` takes the law from the
928
+ * track it is given (its `panLaw`, else its clips).
929
+ */
930
+ setTrackPanLaw(trackId: string, panLaw: PanLaw): void;
923
931
  setTrackMute(trackId: string, muted: boolean): void;
924
932
  setTrackSolo(trackId: string, soloed: boolean): void;
925
933
  setMasterVolume(volume: number): void;
@@ -1038,10 +1046,10 @@ declare class NativePlayoutAdapter implements PlayoutAdapter {
1038
1046
  get ppqn(): number;
1039
1047
  get transport(): Transport;
1040
1048
  init(): Promise<void>;
1041
- setTracks(tracks: ClipTrack[]): void;
1042
- addTrack(track: ClipTrack): void;
1049
+ setTracks(tracks: readonly PlayoutTrack[]): void;
1050
+ addTrack(track: PlayoutTrack): void;
1043
1051
  removeTrack(trackId: string): void;
1044
- updateTrack(trackId: string, track: ClipTrack): void;
1052
+ updateTrack(trackId: string, track: PlayoutTrack): void;
1045
1053
  play(startTime: number, endTime?: number): void;
1046
1054
  pause(): void;
1047
1055
  stop(): void;
@@ -1058,6 +1066,7 @@ declare class NativePlayoutAdapter implements PlayoutAdapter {
1058
1066
  setTrackMute(trackId: string, muted: boolean): void;
1059
1067
  setTrackSolo(trackId: string, soloed: boolean): void;
1060
1068
  setTrackPan(trackId: string, pan: number): void;
1069
+ setTrackPanLaw(trackId: string, panLaw: PanLaw): void;
1061
1070
  setLoop(enabled: boolean, start: number, end: number): void;
1062
1071
  setCountIn(enabled: boolean): void;
1063
1072
  setCountInBars(bars: number): void;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ClipTrack } from '@waveform-playlist/core';
1
+ import { DecidedPanLaw, PlayoutTrack, PanLaw } from '@waveform-playlist/core';
2
2
  import { PlayoutAdapter } from '@waveform-playlist/engine';
3
3
 
4
4
  /** Branded type for tick positions — prevents accidentally passing seconds where ticks are expected. */
@@ -656,8 +656,8 @@ declare class MasterNode {
656
656
  * Pan is core's gain-matrix stage, not a `StereoPannerNode` (#669): a
657
657
  * panner picks its law from the layout it RECEIVES, which pre-fader is the
658
658
  * effects chain's output — a stereo reverb on a mono track would sit ~3 dB
659
- * louder at centre. The stage takes its law from `sourceChannelCount`, the
660
- * max channel count of the track's clips, whatever the chain outputs.
659
+ * louder at centre. The stage takes its law from `panLaw` (the track's own,
660
+ * core's `trackPanLaw`), whatever the chain outputs.
661
661
  */
662
662
  declare class TrackNode {
663
663
  readonly id: string;
@@ -666,16 +666,16 @@ declare class TrackNode {
666
666
  private _panStage;
667
667
  private _muteNode;
668
668
  private _effects;
669
- constructor(id: string, audioContext: AudioContext, sourceChannelCount?: number);
669
+ constructor(id: string, audioContext: AudioContext, panLaw?: DecidedPanLaw);
670
670
  /** Where clip sources connect (pre-fader, pre-effects). */
671
671
  get input(): GainNode;
672
672
  /** Connect this track's output to a destination (master node) */
673
673
  connectOutput(destination: AudioNode): void;
674
674
  setVolume(value: number): void;
675
675
  setPan(value: number): void;
676
- /** Select the pan law from the track's source material: 1 = mono law
677
- * (−3 dB per side at centre), 2+ = stereo law (unity at centre). */
678
- setSourceChannelCount(sourceChannelCount: number): void;
676
+ /** Switch the pan law: 'mono' (−3 dB per side at centre) or 'stereo'
677
+ * (unity at centre). The gains ramp; the law it already has does nothing. */
678
+ setPanLaw(panLaw: DecidedPanLaw): void;
679
679
  setMute(muted: boolean): void;
680
680
  /**
681
681
  * Insert an effects chain between the track input and the fader:
@@ -724,13 +724,13 @@ declare class ClipPlayer implements SchedulerListener<ClipEvent> {
724
724
  constructor(audioContext: AudioContext, sampleTimeline: SampleTimeline, tempoMap: TempoMap, toAudioTime: (transportTime: number) => number);
725
725
  /** Swap in a new (immutable) TempoMap (Transport does this on every tempo edit). */
726
726
  setTempoMap(tempoMap: TempoMap): void;
727
- setTracks(tracks: ClipTrack[], trackNodes: Map<string, TrackNode>): void;
727
+ setTracks(tracks: readonly PlayoutTrack[], trackNodes: Map<string, TrackNode>): void;
728
728
  /** Set loop region using ticks. startTick is unused — loop clamping only needs
729
729
  * the end boundary; mid-clip restart at loopStart is handled by onPositionJump. */
730
730
  setLoop(enabled: boolean, _startTick: Tick, endTick: Tick): void;
731
731
  /** Set loop region using samples directly */
732
732
  setLoopSamples(enabled: boolean, _startSample: Sample, endSample: Sample): void;
733
- updateTrack(trackId: string, track: ClipTrack): void;
733
+ updateTrack(trackId: string, track: PlayoutTrack): void;
734
734
  generate(fromTick: Tick, toTick: Tick): ClipEvent[];
735
735
  consume(event: ClipEvent): void;
736
736
  onPositionJump(newTick: Tick): void;
@@ -914,12 +914,20 @@ declare class Transport {
914
914
  * (see the `discontinuity` event). Diagnostics. */
915
915
  get rebaseCount(): number;
916
916
  isPlaying(): boolean;
917
- setTracks(tracks: ClipTrack[]): void;
918
- addTrack(track: ClipTrack): void;
917
+ setTracks(tracks: readonly PlayoutTrack[]): void;
918
+ addTrack(track: PlayoutTrack): void;
919
919
  removeTrack(trackId: string): void;
920
- updateTrack(trackId: string, track: ClipTrack): void;
920
+ updateTrack(trackId: string, track: PlayoutTrack): void;
921
921
  setTrackVolume(trackId: string, volume: number): void;
922
922
  setTrackPan(trackId: string, pan: number): void;
923
+ /**
924
+ * Set a track's pan law (#684): `'mono'`, `'stereo'`, or `'auto'` for
925
+ * "from the clips of the track the transport holds". The clips are not
926
+ * touched: playing sources go on playing, and the pan stage ramps to the
927
+ * new law. A later `updateTrack` or `setTracks` takes the law from the
928
+ * track it is given (its `panLaw`, else its clips).
929
+ */
930
+ setTrackPanLaw(trackId: string, panLaw: PanLaw): void;
923
931
  setTrackMute(trackId: string, muted: boolean): void;
924
932
  setTrackSolo(trackId: string, soloed: boolean): void;
925
933
  setMasterVolume(volume: number): void;
@@ -1038,10 +1046,10 @@ declare class NativePlayoutAdapter implements PlayoutAdapter {
1038
1046
  get ppqn(): number;
1039
1047
  get transport(): Transport;
1040
1048
  init(): Promise<void>;
1041
- setTracks(tracks: ClipTrack[]): void;
1042
- addTrack(track: ClipTrack): void;
1049
+ setTracks(tracks: readonly PlayoutTrack[]): void;
1050
+ addTrack(track: PlayoutTrack): void;
1043
1051
  removeTrack(trackId: string): void;
1044
- updateTrack(trackId: string, track: ClipTrack): void;
1052
+ updateTrack(trackId: string, track: PlayoutTrack): void;
1045
1053
  play(startTime: number, endTime?: number): void;
1046
1054
  pause(): void;
1047
1055
  stop(): void;
@@ -1058,6 +1066,7 @@ declare class NativePlayoutAdapter implements PlayoutAdapter {
1058
1066
  setTrackMute(trackId: string, muted: boolean): void;
1059
1067
  setTrackSolo(trackId: string, soloed: boolean): void;
1060
1068
  setTrackPan(trackId: string, pan: number): void;
1069
+ setTrackPanLaw(trackId: string, panLaw: PanLaw): void;
1061
1070
  setLoop(enabled: boolean, start: number, end: number): void;
1062
1071
  setCountIn(enabled: boolean): void;
1063
1072
  setCountInBars(bars: number): void;
package/dist/index.js CHANGED
@@ -1331,12 +1331,12 @@ var MasterNode = class {
1331
1331
  var import_core = require("@waveform-playlist/core");
1332
1332
  var PREFIX = "[waveform-playlist] ";
1333
1333
  var TrackNode = class {
1334
- constructor(id, audioContext, sourceChannelCount = 1) {
1334
+ constructor(id, audioContext, panLaw = "mono") {
1335
1335
  this._effects = null;
1336
1336
  this.id = id;
1337
1337
  this._inputNode = audioContext.createGain();
1338
1338
  this._volumeNode = audioContext.createGain();
1339
- this._panStage = (0, import_core.createPanStage)(audioContext, 0, sourceChannelCount);
1339
+ this._panStage = (0, import_core.createPanStage)(audioContext, 0, panLaw);
1340
1340
  this._muteNode = audioContext.createGain();
1341
1341
  this._inputNode.connect(this._volumeNode);
1342
1342
  this._volumeNode.connect(this._panStage.input);
@@ -1356,10 +1356,10 @@ var TrackNode = class {
1356
1356
  setPan(value) {
1357
1357
  this._panStage.setPan(value);
1358
1358
  }
1359
- /** Select the pan law from the track's source material: 1 = mono law
1360
- * (−3 dB per side at centre), 2+ = stereo law (unity at centre). */
1361
- setSourceChannelCount(sourceChannelCount) {
1362
- this._panStage.setSourceChannelCount(sourceChannelCount);
1359
+ /** Switch the pan law: 'mono' (−3 dB per side at centre) or 'stereo'
1360
+ * (unity at centre). The gains ramp; the law it already has does nothing. */
1361
+ setPanLaw(panLaw) {
1362
+ this._panStage.setPanLaw(panLaw);
1363
1363
  }
1364
1364
  setMute(muted) {
1365
1365
  this._muteNode.gain.value = muted ? 0 : 1;
@@ -2175,7 +2175,7 @@ var _Transport = class _Transport {
2175
2175
  this._mutedTrackIds.clear();
2176
2176
  this._tracks = tracks;
2177
2177
  for (const track of tracks) {
2178
- const trackNode = new TrackNode(track.id, this._audioContext, (0, import_core2.trackChannelCount)(track));
2178
+ const trackNode = new TrackNode(track.id, this._audioContext, (0, import_core2.trackPanLaw)(track));
2179
2179
  trackNode.setVolume(track.volume);
2180
2180
  trackNode.setPan(track.pan);
2181
2181
  trackNode.connectOutput(this._masterNode.input);
@@ -2191,7 +2191,7 @@ var _Transport = class _Transport {
2191
2191
  this._clipPlayer.setTracks(tracks, this._trackNodes);
2192
2192
  }
2193
2193
  addTrack(track) {
2194
- const trackNode = new TrackNode(track.id, this._audioContext, (0, import_core2.trackChannelCount)(track));
2194
+ const trackNode = new TrackNode(track.id, this._audioContext, (0, import_core2.trackPanLaw)(track));
2195
2195
  trackNode.setVolume(track.volume);
2196
2196
  trackNode.setPan(track.pan);
2197
2197
  trackNode.connectOutput(this._masterNode.input);
@@ -2224,7 +2224,7 @@ var _Transport = class _Transport {
2224
2224
  if (node) {
2225
2225
  node.setVolume(track.volume);
2226
2226
  node.setPan(track.pan);
2227
- node.setSourceChannelCount((0, import_core2.trackChannelCount)(track));
2227
+ node.setPanLaw((0, import_core2.trackPanLaw)(track));
2228
2228
  }
2229
2229
  if (track.muted) {
2230
2230
  this._mutedTrackIds.add(trackId);
@@ -2256,6 +2256,22 @@ var _Transport = class _Transport {
2256
2256
  }
2257
2257
  node.setPan(pan);
2258
2258
  }
2259
+ /**
2260
+ * Set a track's pan law (#684): `'mono'`, `'stereo'`, or `'auto'` for
2261
+ * "from the clips of the track the transport holds". The clips are not
2262
+ * touched: playing sources go on playing, and the pan stage ramps to the
2263
+ * new law. A later `updateTrack` or `setTracks` takes the law from the
2264
+ * track it is given (its `panLaw`, else its clips).
2265
+ */
2266
+ setTrackPanLaw(trackId, panLaw) {
2267
+ const node = this._trackNodes.get(trackId);
2268
+ const track = this._tracks.find((t) => t.id === trackId);
2269
+ if (!node || !track) {
2270
+ console.warn('[waveform-playlist] setTrackPanLaw: unknown trackId "' + trackId + '"');
2271
+ return;
2272
+ }
2273
+ node.setPanLaw((0, import_core2.trackPanLaw)({ ...track, panLaw }));
2274
+ }
2259
2275
  setTrackMute(trackId, muted) {
2260
2276
  if (muted) {
2261
2277
  this._mutedTrackIds.add(trackId);
@@ -2857,6 +2873,9 @@ var NativePlayoutAdapter = class {
2857
2873
  setTrackPan(trackId, pan) {
2858
2874
  this._transport.setTrackPan(trackId, pan);
2859
2875
  }
2876
+ setTrackPanLaw(trackId, panLaw) {
2877
+ this._transport.setTrackPanLaw(trackId, panLaw);
2878
+ }
2860
2879
  setLoop(enabled, start, end) {
2861
2880
  const finite = Number.isFinite(start) && Number.isFinite(end);
2862
2881
  const degenerate = enabled && finite && this._transport.timeToTick(start) >= this._transport.timeToTick(end);