@waveform-playlist/browser 13.0.0 → 13.1.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/dist/index.mjs CHANGED
@@ -238,6 +238,13 @@ function extractPeaksFromWaveformDataFull(waveformData, samplesPerPixel, isMono,
238
238
  };
239
239
  }
240
240
 
241
+ // src/soundFontSync.ts
242
+ import { isToneAdapter } from "@waveform-playlist/playout";
243
+ function syncSoundFontCacheToAdapter(adapter, cache) {
244
+ if (!isToneAdapter(adapter)) return;
245
+ adapter.setSoundFontCache(cache);
246
+ }
247
+
241
248
  // src/hooks/useTimeFormat.ts
242
249
  import { useState } from "react";
243
250
  import {
@@ -3629,6 +3636,7 @@ var WaveformPlaylistProvider = ({
3629
3636
  const [annotationsEditable, setAnnotationsEditable] = useState15((_c = annotationList == null ? void 0 : annotationList.editable) != null ? _c : false);
3630
3637
  const [isReady, setIsReady] = useState15(false);
3631
3638
  const engineRef = useRef15(null);
3639
+ const adapterRef = useRef15(null);
3632
3640
  const audioInitializedRef = useRef15(false);
3633
3641
  const isPlayingRef = useRef15(false);
3634
3642
  isPlayingRef.current = isPlaying;
@@ -3857,6 +3865,7 @@ var WaveformPlaylistProvider = ({
3857
3865
  if (engineRef.current) {
3858
3866
  engineRef.current.dispose();
3859
3867
  engineRef.current = null;
3868
+ adapterRef.current = null;
3860
3869
  }
3861
3870
  prevTracksRef.current = tracks;
3862
3871
  return;
@@ -3911,6 +3920,7 @@ var WaveformPlaylistProvider = ({
3911
3920
  engineTracksRef.current = null;
3912
3921
  audioInitializedRef.current = false;
3913
3922
  const adapter = createToneAdapter({ effects, soundFontCache: soundFontCacheRef.current });
3923
+ adapterRef.current = adapter;
3914
3924
  const engine = new PlaylistEngine({
3915
3925
  adapter,
3916
3926
  samplesPerPixel: samplesPerPixelRef.current,
@@ -3979,6 +3989,7 @@ var WaveformPlaylistProvider = ({
3979
3989
  stopAnimationFrameLoop();
3980
3990
  if (engineRef.current) {
3981
3991
  engineRef.current.dispose();
3992
+ adapterRef.current = null;
3982
3993
  }
3983
3994
  };
3984
3995
  }, [
@@ -3989,6 +4000,9 @@ var WaveformPlaylistProvider = ({
3989
4000
  // isPlaying is intentionally excluded — read from isPlayingRef inside the
3990
4001
  // effect body. Including it causes a full engine+playout rebuild on every
3991
4002
  // play/pause/stop, destroying and recreating all audio Players.
4003
+ // soundFontCache is deliberately excluded — late cache changes are forwarded
4004
+ // to the live adapter by the sync effect below; only adapter creation reads it
4005
+ // (via soundFontCacheRef).
3992
4006
  onReady,
3993
4007
  effects,
3994
4008
  stopAnimationFrameLoop,
@@ -4006,9 +4020,11 @@ var WaveformPlaylistProvider = ({
4006
4020
  loopEndRef,
4007
4021
  isLoopEnabledRef,
4008
4022
  stableZoomLevels,
4009
- soundFontCache,
4010
4023
  deferEngineRebuild
4011
4024
  ]);
4025
+ useEffect10(() => {
4026
+ syncSoundFontCacheToAdapter(adapterRef.current, soundFontCache);
4027
+ }, [soundFontCache]);
4012
4028
  useEffect10(() => {
4013
4029
  if (tracks.length === 0) return;
4014
4030
  const allTrackPeaks = tracks.map((track) => {
@@ -4106,12 +4122,7 @@ var WaveformPlaylistProvider = ({
4106
4122
  return ((_b2 = audioStartPositionRef.current) != null ? _b2 : 0) + elapsed;
4107
4123
  }, []);
4108
4124
  const toVisualTime = useCallback19((rawTime) => {
4109
- var _a2, _b2;
4110
- const audioCtx = getGlobalAudioContext4();
4111
- const latency = "outputLatency" in audioCtx ? audioCtx.outputLatency : 0;
4112
- const lookAhead = (_b2 = (_a2 = engineRef.current) == null ? void 0 : _a2.lookAhead) != null ? _b2 : 0;
4113
- const visual = rawTime - latency - lookAhead;
4114
- return Number.isFinite(visual) ? Math.max(0, visual) : 0;
4125
+ return Number.isFinite(rawTime) ? Math.max(0, rawTime) : 0;
4115
4126
  }, []);
4116
4127
  const setCurrentTimeRefs = useCallback19(
4117
4128
  (rawTime) => {
@@ -4131,14 +4142,10 @@ var WaveformPlaylistProvider = ({
4131
4142
  frameCallbacksRef.current.delete(id);
4132
4143
  }, []);
4133
4144
  const startAnimationLoop = useCallback19(() => {
4134
- const audioCtx = getGlobalAudioContext4();
4135
4145
  const updateTime = () => {
4136
- var _a2, _b2;
4137
4146
  const time = getPlaybackTime();
4138
4147
  currentTimeRef.current = time;
4139
- const latency = "outputLatency" in audioCtx ? audioCtx.outputLatency : 0;
4140
- const lookAhead = (_b2 = (_a2 = engineRef.current) == null ? void 0 : _a2.lookAhead) != null ? _b2 : 0;
4141
- const visualRaw = time - latency - lookAhead;
4148
+ const visualRaw = engineRef.current ? engineRef.current.getAudibleTime() : time;
4142
4149
  const visualTime = Number.isFinite(visualRaw) ? Math.max(0, visualRaw) : 0;
4143
4150
  visualTimeRef.current = visualTime;
4144
4151
  const sr = sampleRateRef.current;