@waveform-playlist/playout 9.5.1 → 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.js CHANGED
@@ -164,7 +164,7 @@ var ToneTrack = class {
164
164
  this._scheduleGuardOffset = 0;
165
165
  this.track = options.track;
166
166
  this.volumeNode = new import_tone.Volume(this.gainToDb(options.track.gain));
167
- this.panNode = new import_tone.Panner(options.track.stereoPan);
167
+ this.panNode = new import_tone.Panner({ pan: options.track.stereoPan, channelCount: 2 });
168
168
  this.muteGain = new import_tone.Gain(options.track.muted ? 0 : 1);
169
169
  this.volumeNode.chain(this.panNode, this.muteGain);
170
170
  const destination = options.destination || (0, import_tone.getDestination)();
@@ -1553,6 +1553,84 @@ function createToneAdapter(options) {
1553
1553
  let _loopStart = 0;
1554
1554
  let _loopEnd = 0;
1555
1555
  let _audioInitialized = false;
1556
+ function addTrackToPlayout(p, track) {
1557
+ const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
1558
+ const midiClips = track.clips.filter((c) => c.midiNotes && c.midiNotes.length > 0);
1559
+ if (audioClips.length > 0) {
1560
+ const startTime = Math.min(...audioClips.map(import_core.clipStartTime));
1561
+ const endTime = Math.max(...audioClips.map(import_core.clipEndTime));
1562
+ const trackObj = {
1563
+ id: track.id,
1564
+ name: track.name,
1565
+ gain: track.volume,
1566
+ muted: track.muted,
1567
+ soloed: track.soloed,
1568
+ stereoPan: track.pan,
1569
+ startTime,
1570
+ endTime
1571
+ };
1572
+ const clipInfos = audioClips.map((clip) => ({
1573
+ buffer: clip.audioBuffer,
1574
+ startTime: (0, import_core.clipStartTime)(clip) - startTime,
1575
+ duration: (0, import_core.clipDurationTime)(clip),
1576
+ offset: (0, import_core.clipOffsetTime)(clip),
1577
+ fadeIn: clip.fadeIn,
1578
+ fadeOut: clip.fadeOut,
1579
+ gain: clip.gain
1580
+ }));
1581
+ p.addTrack({
1582
+ clips: clipInfos,
1583
+ track: trackObj,
1584
+ effects: track.effects
1585
+ });
1586
+ }
1587
+ if (midiClips.length > 0) {
1588
+ const startTime = Math.min(...midiClips.map(import_core.clipStartTime));
1589
+ const endTime = Math.max(...midiClips.map(import_core.clipEndTime));
1590
+ const trackId = audioClips.length > 0 ? `${track.id}:midi` : track.id;
1591
+ const trackObj = {
1592
+ id: trackId,
1593
+ name: track.name,
1594
+ gain: track.volume,
1595
+ muted: track.muted,
1596
+ soloed: track.soloed,
1597
+ stereoPan: track.pan,
1598
+ startTime,
1599
+ endTime
1600
+ };
1601
+ const midiClipInfos = midiClips.map((clip) => ({
1602
+ notes: clip.midiNotes,
1603
+ startTime: (0, import_core.clipStartTime)(clip) - startTime,
1604
+ duration: (0, import_core.clipDurationTime)(clip),
1605
+ offset: (0, import_core.clipOffsetTime)(clip)
1606
+ }));
1607
+ if (options?.soundFontCache?.isLoaded) {
1608
+ const firstClip = midiClips[0];
1609
+ const midiChannel = firstClip.midiChannel;
1610
+ const isPercussion = midiChannel === 9;
1611
+ const programNumber = firstClip.midiProgram ?? 0;
1612
+ p.addSoundFontTrack({
1613
+ clips: midiClipInfos,
1614
+ track: trackObj,
1615
+ soundFontCache: options.soundFontCache,
1616
+ programNumber,
1617
+ isPercussion,
1618
+ effects: track.effects
1619
+ });
1620
+ } else {
1621
+ if (options?.soundFontCache) {
1622
+ console.warn(
1623
+ `[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
1624
+ );
1625
+ }
1626
+ p.addMidiTrack({
1627
+ clips: midiClipInfos,
1628
+ track: trackObj,
1629
+ effects: track.effects
1630
+ });
1631
+ }
1632
+ }
1633
+ }
1556
1634
  function buildPlayout(tracks) {
1557
1635
  if (playout) {
1558
1636
  try {
@@ -1577,82 +1655,7 @@ function createToneAdapter(options) {
1577
1655
  });
1578
1656
  }
1579
1657
  for (const track of tracks) {
1580
- const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
1581
- const midiClips = track.clips.filter((c) => c.midiNotes && c.midiNotes.length > 0);
1582
- if (audioClips.length > 0) {
1583
- const startTime = Math.min(...audioClips.map(import_core.clipStartTime));
1584
- const endTime = Math.max(...audioClips.map(import_core.clipEndTime));
1585
- const trackObj = {
1586
- id: track.id,
1587
- name: track.name,
1588
- gain: track.volume,
1589
- muted: track.muted,
1590
- soloed: track.soloed,
1591
- stereoPan: track.pan,
1592
- startTime,
1593
- endTime
1594
- };
1595
- const clipInfos = audioClips.map((clip) => ({
1596
- buffer: clip.audioBuffer,
1597
- startTime: (0, import_core.clipStartTime)(clip) - startTime,
1598
- duration: (0, import_core.clipDurationTime)(clip),
1599
- offset: (0, import_core.clipOffsetTime)(clip),
1600
- fadeIn: clip.fadeIn,
1601
- fadeOut: clip.fadeOut,
1602
- gain: clip.gain
1603
- }));
1604
- playout.addTrack({
1605
- clips: clipInfos,
1606
- track: trackObj,
1607
- effects: track.effects
1608
- });
1609
- }
1610
- if (midiClips.length > 0) {
1611
- const startTime = Math.min(...midiClips.map(import_core.clipStartTime));
1612
- const endTime = Math.max(...midiClips.map(import_core.clipEndTime));
1613
- const trackId = audioClips.length > 0 ? `${track.id}:midi` : track.id;
1614
- const trackObj = {
1615
- id: trackId,
1616
- name: track.name,
1617
- gain: track.volume,
1618
- muted: track.muted,
1619
- soloed: track.soloed,
1620
- stereoPan: track.pan,
1621
- startTime,
1622
- endTime
1623
- };
1624
- const midiClipInfos = midiClips.map((clip) => ({
1625
- notes: clip.midiNotes,
1626
- startTime: (0, import_core.clipStartTime)(clip) - startTime,
1627
- duration: (0, import_core.clipDurationTime)(clip),
1628
- offset: (0, import_core.clipOffsetTime)(clip)
1629
- }));
1630
- if (options?.soundFontCache?.isLoaded) {
1631
- const firstClip = midiClips[0];
1632
- const midiChannel = firstClip.midiChannel;
1633
- const isPercussion = midiChannel === 9;
1634
- const programNumber = firstClip.midiProgram ?? 0;
1635
- playout.addSoundFontTrack({
1636
- clips: midiClipInfos,
1637
- track: trackObj,
1638
- soundFontCache: options.soundFontCache,
1639
- programNumber,
1640
- isPercussion,
1641
- effects: track.effects
1642
- });
1643
- } else {
1644
- if (options?.soundFontCache) {
1645
- console.warn(
1646
- `[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
1647
- );
1648
- }
1649
- playout.addMidiTrack({
1650
- clips: midiClipInfos,
1651
- track: trackObj,
1652
- effects: track.effects
1653
- });
1654
- }
1655
- }
1658
+ addTrackToPlayout(playout, track);
1656
1659
  }
1657
1660
  playout.applyInitialSoloState();
1658
1661
  playout.setLoop(_loopEnabled, _loopStart, _loopEnd);
@@ -1672,6 +1675,15 @@ function createToneAdapter(options) {
1672
1675
  setTracks(tracks) {
1673
1676
  buildPlayout(tracks);
1674
1677
  },
1678
+ addTrack(track) {
1679
+ if (!playout) {
1680
+ throw new Error(
1681
+ "[waveform-playlist] adapter.addTrack() called but no playout exists. Call setTracks() first to initialize the playout."
1682
+ );
1683
+ }
1684
+ addTrackToPlayout(playout, track);
1685
+ playout.applyInitialSoloState();
1686
+ },
1675
1687
  play(startTime, endTime) {
1676
1688
  if (!playout) {
1677
1689
  console.warn(