@waveform-playlist/browser 10.1.2 → 10.3.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
@@ -65,7 +65,8 @@ import {
65
65
  } from "react";
66
66
  import { ThemeProvider } from "styled-components";
67
67
  import {
68
- createToneAdapter
68
+ createToneAdapter,
69
+ getGlobalAudioContext as getGlobalAudioContext3
69
70
  } from "@waveform-playlist/playout";
70
71
  import { PlaylistEngine } from "@waveform-playlist/engine";
71
72
  import {
@@ -2645,7 +2646,10 @@ function useTrackDynamicEffects() {
2645
2646
 
2646
2647
  // src/hooks/useExportWav.ts
2647
2648
  import { useState as useState10, useCallback as useCallback13 } from "react";
2648
- import { getUnderlyingAudioParam } from "@waveform-playlist/playout";
2649
+ import {
2650
+ getUnderlyingAudioParam,
2651
+ getGlobalAudioContext
2652
+ } from "@waveform-playlist/playout";
2649
2653
 
2650
2654
  // src/utils/wavEncoder.ts
2651
2655
  function encodeWav(audioBuffer, options = {}) {
@@ -2723,7 +2727,6 @@ function useExportWav() {
2723
2727
  const [error, setError] = useState10(null);
2724
2728
  const exportWav = useCallback13(
2725
2729
  (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (tracks, trackStates, options = {}) {
2726
- var _a;
2727
2730
  const {
2728
2731
  filename = "export",
2729
2732
  mode = "master",
@@ -2745,7 +2748,7 @@ function useExportWav() {
2745
2748
  if (mode === "individual" && (trackIndex === void 0 || trackIndex < 0 || trackIndex >= tracks.length)) {
2746
2749
  throw new Error("Invalid track index for individual export");
2747
2750
  }
2748
- const sampleRate = ((_a = tracks[0].clips[0]) == null ? void 0 : _a.sampleRate) || 44100;
2751
+ const sampleRate = getGlobalAudioContext().sampleRate;
2749
2752
  let totalDurationSamples = 0;
2750
2753
  for (const track of tracks) {
2751
2754
  for (const clip of track.clips) {
@@ -3426,7 +3429,7 @@ function useWaveformDataCache(tracks, baseScale) {
3426
3429
  // src/hooks/useDynamicTracks.ts
3427
3430
  import { useState as useState12, useCallback as useCallback16, useRef as useRef12, useEffect as useEffect8 } from "react";
3428
3431
  import { createTrack as createTrack2, createClipFromSeconds as createClipFromSeconds2 } from "@waveform-playlist/core";
3429
- import { getGlobalAudioContext } from "@waveform-playlist/playout";
3432
+ import { getGlobalAudioContext as getGlobalAudioContext2 } from "@waveform-playlist/playout";
3430
3433
  function getSourceName(source) {
3431
3434
  var _a, _b, _c, _d, _e;
3432
3435
  if (source instanceof File) {
@@ -3477,7 +3480,7 @@ function useDynamicTracks() {
3477
3480
  }, []);
3478
3481
  const addTracks = useCallback16((sources) => {
3479
3482
  if (sources.length === 0) return;
3480
- const audioContext = getGlobalAudioContext();
3483
+ const audioContext = getGlobalAudioContext2();
3481
3484
  const placeholders = sources.map((source) => ({
3482
3485
  track: createTrack2({ name: `${getSourceName(source)} (loading...)`, clips: [] }),
3483
3486
  source
@@ -3673,7 +3676,7 @@ var WaveformPlaylistProvider = ({
3673
3676
  indefinitePlayback = false,
3674
3677
  children
3675
3678
  }) => {
3676
- var _a, _b, _c, _d, _e, _f, _g;
3679
+ var _a, _b, _c, _d;
3677
3680
  const progressBarWidth = progressBarWidthProp != null ? progressBarWidthProp : barWidth + barGap;
3678
3681
  const indefinitePlaybackRef = useRef14(indefinitePlayback);
3679
3682
  indefinitePlaybackRef.current = indefinitePlayback;
@@ -3734,7 +3737,9 @@ var WaveformPlaylistProvider = ({
3734
3737
  const isDraggingRef = useRef14(false);
3735
3738
  const prevTracksRef = useRef14([]);
3736
3739
  const samplesPerPixelRef = useRef14(initialSamplesPerPixel);
3737
- const sampleRateRef = useRef14(44100);
3740
+ const sampleRateRef = useRef14(
3741
+ typeof AudioContext !== "undefined" ? getGlobalAudioContext3().sampleRate : 48e3
3742
+ );
3738
3743
  const { timeFormat, setTimeFormat, formatTime: formatTime2 } = useTimeFormat();
3739
3744
  const zoom = useZoomControls({ engineRef, initialSamplesPerPixel });
3740
3745
  const { samplesPerPixel, onEngineState: onZoomEngineState } = zoom;
@@ -3929,7 +3934,7 @@ var WaveformPlaylistProvider = ({
3929
3934
  pendingResumeRef.current = { position: resumePosition };
3930
3935
  }
3931
3936
  const loadAudio = () => __async(null, null, function* () {
3932
- var _a3, _b3, _c3, _d3, _e2;
3937
+ var _a3, _b3, _c3, _d3, _e;
3933
3938
  try {
3934
3939
  const buffers = [];
3935
3940
  tracks.forEach((track) => {
@@ -3979,7 +3984,7 @@ var WaveformPlaylistProvider = ({
3979
3984
  engine.setSelection((_a3 = selectionStartRef.current) != null ? _a3 : 0, (_b3 = selectionEndRef.current) != null ? _b3 : 0);
3980
3985
  engine.setLoopRegion((_c3 = loopStartRef.current) != null ? _c3 : 0, (_d3 = loopEndRef.current) != null ? _d3 : 0);
3981
3986
  if (isLoopEnabledRef.current) engine.setLoopEnabled(true);
3982
- engine.setMasterVolume((_e2 = masterVolumeRef.current) != null ? _e2 : 1);
3987
+ engine.setMasterVolume((_e = masterVolumeRef.current) != null ? _e : 1);
3983
3988
  if (selectedTrackIdRef.current) engine.selectTrack(selectedTrackIdRef.current);
3984
3989
  const currentTrackStates = trackStatesRef.current;
3985
3990
  const tracksWithState = tracks.map((track, index) => {
@@ -4268,7 +4273,7 @@ var WaveformPlaylistProvider = ({
4268
4273
  }, [tracks, startAnimationLoop, stopAnimationLoop]);
4269
4274
  const play = useCallback18(
4270
4275
  (startTime, playDuration) => __async(null, null, function* () {
4271
- if (!engineRef.current || duration === 0) return;
4276
+ if (!engineRef.current) return;
4272
4277
  const actualStartTime = startTime != null ? startTime : currentTimeRef.current;
4273
4278
  playStartPositionRef.current = actualStartTime;
4274
4279
  currentTimeRef.current = actualStartTime;
@@ -4295,7 +4300,7 @@ var WaveformPlaylistProvider = ({
4295
4300
  setIsPlaying(true);
4296
4301
  startAnimationLoop();
4297
4302
  }),
4298
- [duration, startAnimationLoop, stopAnimationLoop]
4303
+ [startAnimationLoop, stopAnimationLoop]
4299
4304
  );
4300
4305
  const pause = useCallback18(() => {
4301
4306
  if (!engineRef.current) return;
@@ -4415,8 +4420,7 @@ var WaveformPlaylistProvider = ({
4415
4420
  },
4416
4421
  []
4417
4422
  );
4418
- const sampleRate = ((_e = audioBuffers[0]) == null ? void 0 : _e.sampleRate) || ((_g = (_f = tracks[0]) == null ? void 0 : _f.clips[0]) == null ? void 0 : _g.sampleRate) || 44100;
4419
- sampleRateRef.current = sampleRate;
4423
+ const sampleRate = sampleRateRef.current;
4420
4424
  const timeScaleHeight = timescale ? 30 : 0;
4421
4425
  const minimumPlaylistHeight = tracks.length * waveHeight + timeScaleHeight;
4422
4426
  const animationValue = useMemo4(
@@ -4658,6 +4662,7 @@ var MediaElementPlaylistProvider = ({
4658
4662
  waveHeight = 100,
4659
4663
  timescale = false,
4660
4664
  playbackRate: initialPlaybackRate = 1,
4665
+ preservesPitch = true,
4661
4666
  automaticScroll = false,
4662
4667
  theme: userTheme,
4663
4668
  controls = { show: false, width: 0 },
@@ -4727,7 +4732,8 @@ var MediaElementPlaylistProvider = ({
4727
4732
  useEffect11(() => {
4728
4733
  var _a2, _b;
4729
4734
  const playout = new MediaElementPlayout({
4730
- playbackRate: initialPlaybackRate
4735
+ playbackRate: initialPlaybackRate,
4736
+ preservesPitch
4731
4737
  });
4732
4738
  playout.addTrack({
4733
4739
  source: track.source,
@@ -4765,6 +4771,7 @@ var MediaElementPlaylistProvider = ({
4765
4771
  track.fadeOut,
4766
4772
  audioContext,
4767
4773
  initialPlaybackRate,
4774
+ preservesPitch,
4768
4775
  onReady,
4769
4776
  stopAnimationFrameLoop,
4770
4777
  setActiveAnnotationId