@waveform-playlist/browser 11.1.0 → 11.2.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,6 +65,7 @@ import {
65
65
  } from "react";
66
66
  import { ThemeProvider } from "styled-components";
67
67
  import {
68
+ configureGlobalContext,
68
69
  createToneAdapter,
69
70
  getGlobalAudioContext as getGlobalAudioContext4
70
71
  } from "@waveform-playlist/playout";
@@ -78,11 +79,13 @@ import { getContext as getContext2 } from "tone";
78
79
  import WaveformData from "waveform-data";
79
80
  function loadWaveformData(src) {
80
81
  return __async(this, null, function* () {
82
+ var _a, _b;
81
83
  const response = yield fetch(src);
82
84
  if (!response.ok) {
83
85
  throw new Error(`Failed to fetch waveform data: ${response.statusText}`);
84
86
  }
85
- const isBinary = src.endsWith(".dat");
87
+ const { pathname } = new URL(src, (_b = (_a = globalThis.location) == null ? void 0 : _a.href) != null ? _b : "http://localhost");
88
+ const isBinary = pathname.toLowerCase().endsWith(".dat");
86
89
  if (isBinary) {
87
90
  const arrayBuffer = yield response.arrayBuffer();
88
91
  return WaveformData.create(arrayBuffer);
@@ -3700,6 +3703,7 @@ var WaveformPlaylistProvider = ({
3700
3703
  soundFontCache,
3701
3704
  deferEngineRebuild = false,
3702
3705
  indefinitePlayback = false,
3706
+ sampleRate: sampleRateProp,
3703
3707
  children
3704
3708
  }) => {
3705
3709
  var _a, _b, _c, _d;
@@ -3763,9 +3767,21 @@ var WaveformPlaylistProvider = ({
3763
3767
  const isDraggingRef = useRef15(false);
3764
3768
  const prevTracksRef = useRef15([]);
3765
3769
  const samplesPerPixelRef = useRef15(initialSamplesPerPixel);
3766
- const sampleRateRef = useRef15(
3767
- typeof AudioContext !== "undefined" ? getGlobalAudioContext4().sampleRate : 48e3
3768
- );
3770
+ const [initialSampleRate] = useState15(() => {
3771
+ if (typeof AudioContext === "undefined") return sampleRateProp != null ? sampleRateProp : 48e3;
3772
+ try {
3773
+ if (sampleRateProp !== void 0) {
3774
+ return configureGlobalContext({ sampleRate: sampleRateProp });
3775
+ }
3776
+ return getGlobalAudioContext4().sampleRate;
3777
+ } catch (err) {
3778
+ console.warn(
3779
+ "[waveform-playlist] Failed to configure AudioContext: " + String(err) + " \u2014 falling back to " + (sampleRateProp != null ? sampleRateProp : 48e3) + " Hz"
3780
+ );
3781
+ return sampleRateProp != null ? sampleRateProp : 48e3;
3782
+ }
3783
+ });
3784
+ const sampleRateRef = useRef15(initialSampleRate);
3769
3785
  const { timeFormat, setTimeFormat, formatTime: formatTime2 } = useTimeFormat();
3770
3786
  const zoom = useZoomControls({ engineRef, initialSamplesPerPixel });
3771
3787
  const { samplesPerPixel, onEngineState: onZoomEngineState } = zoom;
@@ -4115,15 +4131,28 @@ var WaveformPlaylistProvider = ({
4115
4131
  let peaks;
4116
4132
  if (clip.waveformData) {
4117
4133
  try {
4134
+ const wdRate = clip.waveformData.sample_rate;
4135
+ const clipRate = clip.sampleRate;
4136
+ let peakOffset = clip.offsetSamples;
4137
+ let peakDuration = clip.durationSamples;
4138
+ let peakSpp = samplesPerPixel;
4139
+ if (wdRate !== clipRate && clipRate > 0 && wdRate > 0) {
4140
+ const ratio = wdRate / clipRate;
4141
+ peakOffset = Math.round(clip.offsetSamples * ratio);
4142
+ peakDuration = Math.round(clip.durationSamples * ratio);
4143
+ peakSpp = Math.max(1, Math.round(samplesPerPixel * ratio));
4144
+ }
4118
4145
  peaks = extractPeaksFromWaveformDataFull(
4119
4146
  clip.waveformData,
4120
- samplesPerPixel,
4147
+ peakSpp,
4121
4148
  mono,
4122
- clip.offsetSamples,
4123
- clip.durationSamples
4149
+ peakOffset,
4150
+ peakDuration
4124
4151
  );
4125
4152
  } catch (err) {
4126
- console.warn("[waveform-playlist] Failed to extract peaks from waveformData:", err);
4153
+ console.warn(
4154
+ "[waveform-playlist] Failed to extract peaks from waveformData: " + String(err)
4155
+ );
4127
4156
  }
4128
4157
  }
4129
4158
  if (!peaks) {
@@ -4138,7 +4167,9 @@ var WaveformPlaylistProvider = ({
4138
4167
  clip.durationSamples
4139
4168
  );
4140
4169
  } catch (err) {
4141
- console.warn("[waveform-playlist] Failed to extract peaks from cache:", err);
4170
+ console.warn(
4171
+ "[waveform-playlist] Failed to extract peaks from cache: " + String(err)
4172
+ );
4142
4173
  }
4143
4174
  }
4144
4175
  }