@waveform-playlist/playout 13.0.0-next.0 → 13.0.0-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/dist/index.mjs CHANGED
@@ -42,7 +42,7 @@ var ToneTrack = class {
42
42
  this.panStage = createPanStage(
43
43
  getContext().rawContext,
44
44
  options.track.stereoPan,
45
- options.channelCount ?? 1
45
+ options.panLaw ?? "mono"
46
46
  );
47
47
  this.muteGain = new Gain(options.track.muted ? 0 : 1);
48
48
  this.volumeNode.connect(this.panStage.input);
@@ -188,13 +188,11 @@ var ToneTrack = class {
188
188
  this.scheduledClips.splice(index, 1);
189
189
  }
190
190
  /**
191
- * Select the pan law from the track's source material: 1 = mono law,
192
- * 2+ = stereo law. Call when the track's clips change — a stereo clip
193
- * joining a mono track moves it to the stereo law (same rule as the
194
- * native transport and the offline export).
191
+ * Switch the track's pan law (the gains ramp). The law is the track's own
192
+ * (#684): its clips do not change it, on any renderer.
195
193
  */
196
- setSourceChannelCount(sourceChannelCount) {
197
- this.panStage.setSourceChannelCount(sourceChannelCount);
194
+ setPanLaw(panLaw) {
195
+ this.panStage.setPanLaw(panLaw);
198
196
  }
199
197
  /**
200
198
  * Replace clips on this track. Diffs old vs new by buffer + timing —
@@ -560,6 +558,16 @@ import {
560
558
  gainToDb as gainToDb2,
561
559
  createPanStage as createPanStage2
562
560
  } from "@waveform-playlist/core";
561
+
562
+ // src/midiWindow.ts
563
+ function noteInWindow(note, window) {
564
+ const start2 = Math.max(note.time, window.offset);
565
+ const end = Math.min(note.time + note.duration, window.offset + window.duration);
566
+ if (!(end > start2)) return null;
567
+ return { start: start2 - window.offset, duration: end - start2 };
568
+ }
569
+
570
+ // src/MidiToneTrack.ts
563
571
  function getDrumCategory(midiNote) {
564
572
  if (midiNote === 35 || midiNote === 36) return "kick";
565
573
  if (midiNote >= 37 && midiNote <= 40) return "snare";
@@ -575,7 +583,7 @@ var MidiToneTrack = class {
575
583
  this.panStage = createPanStage2(
576
584
  getContext2().rawContext,
577
585
  options.track.stereoPan,
578
- 1
586
+ "mono"
579
587
  );
580
588
  this.muteGain = new Gain2(options.track.muted ? 0 : 1);
581
589
  this.volumeNode.connect(this.panStage.input);
@@ -725,9 +733,10 @@ var MidiToneTrack = class {
725
733
  const absClipEnd = absClipStart + clipInfo.duration;
726
734
  if (absClipStart < transportOffset && absClipEnd > transportOffset) {
727
735
  for (const note of clipInfo.notes) {
728
- const adjustedTime = note.time - clipInfo.offset;
729
- const noteAbsStart = absClipStart + Math.max(0, adjustedTime);
730
- const noteAbsEnd = noteAbsStart + note.duration;
736
+ const sounding = noteInWindow(note, clipInfo);
737
+ if (!sounding) continue;
738
+ const noteAbsStart = absClipStart + sounding.start;
739
+ const noteAbsEnd = noteAbsStart + sounding.duration;
731
740
  if (noteAbsStart < transportOffset && noteAbsEnd > transportOffset) {
732
741
  const remainingDuration = noteAbsEnd - transportOffset;
733
742
  try {
@@ -911,7 +920,7 @@ var SoundFontToneTrack = class {
911
920
  this.panStage = createPanStage3(
912
921
  getContext3().rawContext,
913
922
  options.track.stereoPan,
914
- 1
923
+ "mono"
915
924
  );
916
925
  this.muteGain = new Gain3(options.track.muted ? 0 : 1);
917
926
  this.volumeNode.connect(this.panStage.input);
@@ -1052,9 +1061,10 @@ var SoundFontToneTrack = class {
1052
1061
  const absClipEnd = absClipStart + clipInfo.duration;
1053
1062
  if (absClipStart < transportOffset && absClipEnd > transportOffset) {
1054
1063
  for (const note of clipInfo.notes) {
1055
- const adjustedTime = note.time - clipInfo.offset;
1056
- const noteAbsStart = absClipStart + Math.max(0, adjustedTime);
1057
- const noteAbsEnd = noteAbsStart + note.duration;
1064
+ const sounding = noteInWindow(note, clipInfo);
1065
+ if (!sounding) continue;
1066
+ const noteAbsStart = absClipStart + sounding.start;
1067
+ const noteAbsEnd = noteAbsStart + sounding.duration;
1058
1068
  if (noteAbsStart < transportOffset && noteAbsEnd > transportOffset) {
1059
1069
  const remainingDuration = noteAbsEnd - transportOffset;
1060
1070
  try {
@@ -1293,16 +1303,16 @@ var TonePlayout = class {
1293
1303
  /**
1294
1304
  * Replace clips on a track, preserving the track's audio graph.
1295
1305
  * Only works for ToneTrack (audio clips), not MidiToneTrack.
1296
- * `sourceChannelCount` (max channel count across the new clips) re-selects
1297
- * the track's pan law; omit to leave it unchanged.
1306
+ * `panLaw` is the track's pan law (core's trackPanLaw); omit to leave it
1307
+ * unchanged.
1298
1308
  */
1299
- replaceTrackClips(trackId, newClips, newStartTime, sourceChannelCount) {
1309
+ replaceTrackClips(trackId, newClips, newStartTime, panLaw) {
1300
1310
  const track = this.tracks.get(trackId);
1301
1311
  if (!track || !("replaceClips" in track)) return false;
1302
1312
  const toneTrack = track;
1303
1313
  toneTrack.replaceClips(newClips, newStartTime);
1304
- if (sourceChannelCount !== void 0) {
1305
- toneTrack.setSourceChannelCount(sourceChannelCount);
1314
+ if (panLaw !== void 0) {
1315
+ toneTrack.setPanLaw(panLaw);
1306
1316
  }
1307
1317
  return true;
1308
1318
  }
@@ -1922,7 +1932,7 @@ import {
1922
1932
  clipEndTime,
1923
1933
  clipOffsetTime,
1924
1934
  clipDurationTime,
1925
- trackChannelCount,
1935
+ trackPanLaw,
1926
1936
  trackKind
1927
1937
  } from "@waveform-playlist/core";
1928
1938
  import { now as now2 } from "tone";
@@ -1961,7 +1971,9 @@ function createToneAdapter(options) {
1961
1971
  const endTime = Math.max(...audioClips.map(clipEndTime));
1962
1972
  const trackObj = {
1963
1973
  id: track.id,
1964
- name: track.name,
1974
+ // The adapter is not given the track's name (a view field, core's
1975
+ // TRACK_VIEW_FIELDS); nothing in TonePlayout reads this one.
1976
+ name: track.id,
1965
1977
  gain: track.volume,
1966
1978
  muted: track.muted,
1967
1979
  soloed: track.soloed,
@@ -1982,7 +1994,7 @@ function createToneAdapter(options) {
1982
1994
  clips: clipInfos,
1983
1995
  track: trackObj,
1984
1996
  effects: options?.trackEffects?.(track.id),
1985
- channelCount: trackChannelCount(track)
1997
+ panLaw: trackPanLaw(track)
1986
1998
  });
1987
1999
  }
1988
2000
  function addMidiTrackToPlayout(p, track) {
@@ -1993,7 +2005,9 @@ function createToneAdapter(options) {
1993
2005
  const trackId = track.id;
1994
2006
  const trackObj = {
1995
2007
  id: trackId,
1996
- name: track.name,
2008
+ // The adapter is not given the track's name (a view field, core's
2009
+ // TRACK_VIEW_FIELDS); nothing in TonePlayout reads this one.
2010
+ name: track.id,
1997
2011
  gain: track.volume,
1998
2012
  muted: track.muted,
1999
2013
  soloed: track.soloed,
@@ -2025,7 +2039,7 @@ function createToneAdapter(options) {
2025
2039
  } else {
2026
2040
  if (_soundFontCache) {
2027
2041
  console.warn(
2028
- `[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
2042
+ `[waveform-playlist] SoundFont not loaded for track "${track.id}" \u2014 falling back to PolySynth.`
2029
2043
  );
2030
2044
  }
2031
2045
  p.addMidiTrack({
@@ -2158,7 +2172,7 @@ function createToneAdapter(options) {
2158
2172
  trackId,
2159
2173
  clipInfos,
2160
2174
  startTime,
2161
- trackChannelCount(track)
2175
+ trackPanLaw(track)
2162
2176
  );
2163
2177
  if (audioUpdated) {
2164
2178
  playout.applyInitialSoloState();
@@ -2245,6 +2259,15 @@ function createToneAdapter(options) {
2245
2259
  if (existing) _currentTracks.set(trackId, { ...existing, pan });
2246
2260
  playout?.getTrack(trackId)?.setPan(pan);
2247
2261
  },
2262
+ // A track's pan law changed (#684). 'auto': from the clips of the track
2263
+ // last sent. The clips are not replaced; the pan stage ramps. A MIDI or
2264
+ // SoundFont track has no law to set.
2265
+ setTrackPanLaw(trackId, panLaw) {
2266
+ const existing = _currentTracks.get(trackId);
2267
+ const track = playout?.getTrack(trackId);
2268
+ if (!existing || !track || !("setPanLaw" in track)) return;
2269
+ track.setPanLaw(trackPanLaw({ ...existing, panLaw }));
2270
+ },
2248
2271
  setLoop(enabled, start2, end) {
2249
2272
  _loopEnabled = enabled;
2250
2273
  _loopStart = start2;
@@ -2335,7 +2358,7 @@ function createToneAdapter(options) {
2335
2358
  changed = true;
2336
2359
  } catch (err) {
2337
2360
  console.warn(
2338
- `[waveform-playlist] SoundFont swap failed for track "${track.name}": ` + String(err)
2361
+ `[waveform-playlist] SoundFont swap failed for track "${track.id}": ` + String(err)
2339
2362
  );
2340
2363
  }
2341
2364
  }