@waveform-playlist/playout 9.5.2 → 10.0.0

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
@@ -130,7 +130,7 @@ var ToneTrack = class {
130
130
  this._scheduleGuardOffset = 0;
131
131
  this.track = options.track;
132
132
  this.volumeNode = new Volume(this.gainToDb(options.track.gain));
133
- this.panNode = new Panner(options.track.stereoPan);
133
+ this.panNode = new Panner({ pan: options.track.stereoPan, channelCount: 2 });
134
134
  this.muteGain = new Gain(options.track.muted ? 0 : 1);
135
135
  this.volumeNode.chain(this.panNode, this.muteGain);
136
136
  const destination = options.destination || getDestination();
@@ -1536,6 +1536,84 @@ function createToneAdapter(options) {
1536
1536
  let _loopStart = 0;
1537
1537
  let _loopEnd = 0;
1538
1538
  let _audioInitialized = false;
1539
+ function addTrackToPlayout(p, track) {
1540
+ const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
1541
+ const midiClips = track.clips.filter((c) => c.midiNotes && c.midiNotes.length > 0);
1542
+ if (audioClips.length > 0) {
1543
+ const startTime = Math.min(...audioClips.map(clipStartTime));
1544
+ const endTime = Math.max(...audioClips.map(clipEndTime));
1545
+ const trackObj = {
1546
+ id: track.id,
1547
+ name: track.name,
1548
+ gain: track.volume,
1549
+ muted: track.muted,
1550
+ soloed: track.soloed,
1551
+ stereoPan: track.pan,
1552
+ startTime,
1553
+ endTime
1554
+ };
1555
+ const clipInfos = audioClips.map((clip) => ({
1556
+ buffer: clip.audioBuffer,
1557
+ startTime: clipStartTime(clip) - startTime,
1558
+ duration: clipDurationTime(clip),
1559
+ offset: clipOffsetTime(clip),
1560
+ fadeIn: clip.fadeIn,
1561
+ fadeOut: clip.fadeOut,
1562
+ gain: clip.gain
1563
+ }));
1564
+ p.addTrack({
1565
+ clips: clipInfos,
1566
+ track: trackObj,
1567
+ effects: track.effects
1568
+ });
1569
+ }
1570
+ if (midiClips.length > 0) {
1571
+ const startTime = Math.min(...midiClips.map(clipStartTime));
1572
+ const endTime = Math.max(...midiClips.map(clipEndTime));
1573
+ const trackId = audioClips.length > 0 ? `${track.id}:midi` : track.id;
1574
+ const trackObj = {
1575
+ id: trackId,
1576
+ name: track.name,
1577
+ gain: track.volume,
1578
+ muted: track.muted,
1579
+ soloed: track.soloed,
1580
+ stereoPan: track.pan,
1581
+ startTime,
1582
+ endTime
1583
+ };
1584
+ const midiClipInfos = midiClips.map((clip) => ({
1585
+ notes: clip.midiNotes,
1586
+ startTime: clipStartTime(clip) - startTime,
1587
+ duration: clipDurationTime(clip),
1588
+ offset: clipOffsetTime(clip)
1589
+ }));
1590
+ if (options?.soundFontCache?.isLoaded) {
1591
+ const firstClip = midiClips[0];
1592
+ const midiChannel = firstClip.midiChannel;
1593
+ const isPercussion = midiChannel === 9;
1594
+ const programNumber = firstClip.midiProgram ?? 0;
1595
+ p.addSoundFontTrack({
1596
+ clips: midiClipInfos,
1597
+ track: trackObj,
1598
+ soundFontCache: options.soundFontCache,
1599
+ programNumber,
1600
+ isPercussion,
1601
+ effects: track.effects
1602
+ });
1603
+ } else {
1604
+ if (options?.soundFontCache) {
1605
+ console.warn(
1606
+ `[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
1607
+ );
1608
+ }
1609
+ p.addMidiTrack({
1610
+ clips: midiClipInfos,
1611
+ track: trackObj,
1612
+ effects: track.effects
1613
+ });
1614
+ }
1615
+ }
1616
+ }
1539
1617
  function buildPlayout(tracks) {
1540
1618
  if (playout) {
1541
1619
  try {
@@ -1560,82 +1638,7 @@ function createToneAdapter(options) {
1560
1638
  });
1561
1639
  }
1562
1640
  for (const track of tracks) {
1563
- const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
1564
- const midiClips = track.clips.filter((c) => c.midiNotes && c.midiNotes.length > 0);
1565
- if (audioClips.length > 0) {
1566
- const startTime = Math.min(...audioClips.map(clipStartTime));
1567
- const endTime = Math.max(...audioClips.map(clipEndTime));
1568
- const trackObj = {
1569
- id: track.id,
1570
- name: track.name,
1571
- gain: track.volume,
1572
- muted: track.muted,
1573
- soloed: track.soloed,
1574
- stereoPan: track.pan,
1575
- startTime,
1576
- endTime
1577
- };
1578
- const clipInfos = audioClips.map((clip) => ({
1579
- buffer: clip.audioBuffer,
1580
- startTime: clipStartTime(clip) - startTime,
1581
- duration: clipDurationTime(clip),
1582
- offset: clipOffsetTime(clip),
1583
- fadeIn: clip.fadeIn,
1584
- fadeOut: clip.fadeOut,
1585
- gain: clip.gain
1586
- }));
1587
- playout.addTrack({
1588
- clips: clipInfos,
1589
- track: trackObj,
1590
- effects: track.effects
1591
- });
1592
- }
1593
- if (midiClips.length > 0) {
1594
- const startTime = Math.min(...midiClips.map(clipStartTime));
1595
- const endTime = Math.max(...midiClips.map(clipEndTime));
1596
- const trackId = audioClips.length > 0 ? `${track.id}:midi` : track.id;
1597
- const trackObj = {
1598
- id: trackId,
1599
- name: track.name,
1600
- gain: track.volume,
1601
- muted: track.muted,
1602
- soloed: track.soloed,
1603
- stereoPan: track.pan,
1604
- startTime,
1605
- endTime
1606
- };
1607
- const midiClipInfos = midiClips.map((clip) => ({
1608
- notes: clip.midiNotes,
1609
- startTime: clipStartTime(clip) - startTime,
1610
- duration: clipDurationTime(clip),
1611
- offset: clipOffsetTime(clip)
1612
- }));
1613
- if (options?.soundFontCache?.isLoaded) {
1614
- const firstClip = midiClips[0];
1615
- const midiChannel = firstClip.midiChannel;
1616
- const isPercussion = midiChannel === 9;
1617
- const programNumber = firstClip.midiProgram ?? 0;
1618
- playout.addSoundFontTrack({
1619
- clips: midiClipInfos,
1620
- track: trackObj,
1621
- soundFontCache: options.soundFontCache,
1622
- programNumber,
1623
- isPercussion,
1624
- effects: track.effects
1625
- });
1626
- } else {
1627
- if (options?.soundFontCache) {
1628
- console.warn(
1629
- `[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
1630
- );
1631
- }
1632
- playout.addMidiTrack({
1633
- clips: midiClipInfos,
1634
- track: trackObj,
1635
- effects: track.effects
1636
- });
1637
- }
1638
- }
1641
+ addTrackToPlayout(playout, track);
1639
1642
  }
1640
1643
  playout.applyInitialSoloState();
1641
1644
  playout.setLoop(_loopEnabled, _loopStart, _loopEnd);
@@ -1655,6 +1658,15 @@ function createToneAdapter(options) {
1655
1658
  setTracks(tracks) {
1656
1659
  buildPlayout(tracks);
1657
1660
  },
1661
+ addTrack(track) {
1662
+ if (!playout) {
1663
+ throw new Error(
1664
+ "[waveform-playlist] adapter.addTrack() called but no playout exists. Call setTracks() first to initialize the playout."
1665
+ );
1666
+ }
1667
+ addTrackToPlayout(playout, track);
1668
+ playout.applyInitialSoloState();
1669
+ },
1658
1670
  play(startTime, endTime) {
1659
1671
  if (!playout) {
1660
1672
  console.warn(