@waveform-playlist/spectrogram 15.0.0-next.4 → 15.0.0-next.5
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 +106 -235
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -459,7 +459,7 @@ var SpectrogramSettingsModal = ({
|
|
|
459
459
|
};
|
|
460
460
|
|
|
461
461
|
// src/SpectrogramProvider.tsx
|
|
462
|
-
var
|
|
462
|
+
var import_react3 = require("react");
|
|
463
463
|
var import_core2 = require("@waveform-playlist/core");
|
|
464
464
|
var import_spectrogram2 = require("@dawcore/spectrogram");
|
|
465
465
|
|
|
@@ -550,23 +550,10 @@ function computeChunkSampleRange({
|
|
|
550
550
|
function resolveRenderMode(override, trackRenderMode) {
|
|
551
551
|
return override?.renderMode ?? trackRenderMode ?? "waveform";
|
|
552
552
|
}
|
|
553
|
-
function toComputeConfig(cfg) {
|
|
554
|
-
return {
|
|
555
|
-
fftSize: cfg?.fftSize,
|
|
556
|
-
hopSize: cfg?.hopSize,
|
|
557
|
-
windowFunction: cfg?.windowFunction,
|
|
558
|
-
alpha: cfg?.alpha,
|
|
559
|
-
zeroPaddingFactor: cfg?.zeroPaddingFactor
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
553
|
function buildConfigKey(params) {
|
|
563
554
|
const { mode, cfg, cm, mono } = params;
|
|
564
555
|
return JSON.stringify({ mode, cfg, cm, mono });
|
|
565
556
|
}
|
|
566
|
-
function buildFFTKey(params) {
|
|
567
|
-
const { mode, mono, computeConfig } = params;
|
|
568
|
-
return JSON.stringify({ mode, mono, ...computeConfig });
|
|
569
|
-
}
|
|
570
557
|
function mapsDiffer(prev, current) {
|
|
571
558
|
if (current.size !== prev.size) return true;
|
|
572
559
|
for (const [key, value] of current) {
|
|
@@ -591,85 +578,107 @@ function resolveClipRange(clip, registered) {
|
|
|
591
578
|
};
|
|
592
579
|
}
|
|
593
580
|
|
|
581
|
+
// src/audioRegistration.ts
|
|
582
|
+
function createAudioKeyOf() {
|
|
583
|
+
const keys = /* @__PURE__ */ new WeakMap();
|
|
584
|
+
let next = 0;
|
|
585
|
+
return (buffer) => {
|
|
586
|
+
const existing = keys.get(buffer);
|
|
587
|
+
if (existing !== void 0) return existing;
|
|
588
|
+
next += 1;
|
|
589
|
+
const key = `audio-${next}`;
|
|
590
|
+
keys.set(buffer, key);
|
|
591
|
+
return key;
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
function spectrogramAudio(tracks, overrides, audioKeyOf) {
|
|
595
|
+
const wanted = /* @__PURE__ */ new Map();
|
|
596
|
+
for (const track of tracks) {
|
|
597
|
+
if (resolveRenderMode(overrides.get(track.id), track.renderMode) === "waveform") continue;
|
|
598
|
+
for (const clip of track.clips) {
|
|
599
|
+
if (clip.audioBuffer) wanted.set(audioKeyOf(clip.audioBuffer), clip.audioBuffer);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return wanted;
|
|
603
|
+
}
|
|
604
|
+
function channelData(buffer) {
|
|
605
|
+
return Array.from({ length: buffer.numberOfChannels }, (_, ch) => buffer.getChannelData(ch));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// src/useStableByContent.ts
|
|
609
|
+
var import_react2 = require("react");
|
|
610
|
+
function useStableByContent(value) {
|
|
611
|
+
const content = JSON.stringify(value);
|
|
612
|
+
return (0, import_react2.useMemo)(() => value, [content]);
|
|
613
|
+
}
|
|
614
|
+
|
|
594
615
|
// src/SpectrogramProvider.tsx
|
|
595
616
|
var import_browser = require("@waveform-playlist/browser");
|
|
596
617
|
var import_browser2 = require("@waveform-playlist/browser");
|
|
597
618
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
598
619
|
var import_meta = {};
|
|
599
620
|
var SpectrogramProvider = ({
|
|
600
|
-
config
|
|
601
|
-
colorMap
|
|
621
|
+
config,
|
|
622
|
+
colorMap,
|
|
602
623
|
workerPoolSize,
|
|
603
624
|
children
|
|
604
625
|
}) => {
|
|
626
|
+
const spectrogramConfig = useStableByContent(config);
|
|
627
|
+
const spectrogramColorMap = useStableByContent(colorMap);
|
|
605
628
|
const { mono } = (0, import_browser2.usePlaylistView)();
|
|
606
629
|
const { samplesPerPixel } = (0, import_browser2.usePlaylistZoom)();
|
|
607
|
-
const { tracks
|
|
630
|
+
const { tracks } = (0, import_browser2.usePlaylistTimeline)();
|
|
608
631
|
const { scrollContainerRef } = (0, import_browser2.usePlaybackControls)();
|
|
609
|
-
const [trackSpectrogramOverrides, setTrackSpectrogramOverrides] = (0,
|
|
610
|
-
const spectrogramCanvasRegistryRef = (0,
|
|
611
|
-
const canvasHeightsRef = (0,
|
|
612
|
-
const canvasRangesRef = (0,
|
|
613
|
-
const [spectrogramCanvasVersion, setSpectrogramCanvasVersion] = (0,
|
|
614
|
-
const prevSpectrogramConfigRef = (0,
|
|
615
|
-
const
|
|
616
|
-
const
|
|
617
|
-
const
|
|
618
|
-
const
|
|
619
|
-
const
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
632
|
+
const [trackSpectrogramOverrides, setTrackSpectrogramOverrides] = (0, import_react3.useState)(() => /* @__PURE__ */ new Map());
|
|
633
|
+
const spectrogramCanvasRegistryRef = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
|
|
634
|
+
const canvasHeightsRef = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
|
|
635
|
+
const canvasRangesRef = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
|
|
636
|
+
const [spectrogramCanvasVersion, setSpectrogramCanvasVersion] = (0, import_react3.useState)(0);
|
|
637
|
+
const prevSpectrogramConfigRef = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
|
|
638
|
+
const spectrogramWorkerRef = (0, import_react3.useRef)(null);
|
|
639
|
+
const spectrogramGenerationRef = (0, import_react3.useRef)(0);
|
|
640
|
+
const prevCanvasVersionRef = (0, import_react3.useRef)(0);
|
|
641
|
+
const backgroundRenderAbortRef = (0, import_react3.useRef)(null);
|
|
642
|
+
const [audioKeyOf] = (0, import_react3.useState)(createAudioKeyOf);
|
|
643
|
+
const ensureWorkerPool = (0, import_react3.useCallback)(() => {
|
|
644
|
+
if (spectrogramWorkerRef.current) return spectrogramWorkerRef.current;
|
|
645
|
+
try {
|
|
646
|
+
const pool = (0, import_spectrogram2.createSpectrogramWorkerPool)(
|
|
647
|
+
() => new Worker(new URL("@dawcore/spectrogram/worker/spectrogram.worker", import_meta.url), {
|
|
648
|
+
type: "module"
|
|
649
|
+
}),
|
|
650
|
+
workerPoolSize
|
|
651
|
+
);
|
|
652
|
+
spectrogramWorkerRef.current = pool;
|
|
653
|
+
return pool;
|
|
654
|
+
} catch (err) {
|
|
655
|
+
console.warn(
|
|
656
|
+
`[waveform-playlist] Spectrogram Web Worker unavailable: ${err instanceof Error ? err.message : String(err)}`
|
|
657
|
+
);
|
|
658
|
+
return null;
|
|
659
|
+
}
|
|
660
|
+
}, [workerPoolSize]);
|
|
661
|
+
(0, import_react3.useEffect)(() => {
|
|
623
662
|
return () => {
|
|
624
663
|
spectrogramWorkerRef.current?.terminate();
|
|
625
664
|
spectrogramWorkerRef.current = null;
|
|
626
665
|
};
|
|
627
666
|
}, []);
|
|
628
|
-
(0,
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
if (!
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
type: "module"
|
|
636
|
-
}),
|
|
637
|
-
workerPoolSize
|
|
638
|
-
);
|
|
639
|
-
spectrogramWorkerRef.current = workerApi;
|
|
640
|
-
} catch (err) {
|
|
641
|
-
console.warn(
|
|
642
|
-
`[waveform-playlist] Spectrogram Web Worker unavailable for pre-transfer: ${err instanceof Error ? err.message : String(err)}`
|
|
643
|
-
);
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
667
|
+
(0, import_react3.useEffect)(() => {
|
|
668
|
+
const wanted = spectrogramAudio(tracks, trackSpectrogramOverrides, audioKeyOf);
|
|
669
|
+
const pool = wanted.size > 0 ? ensureWorkerPool() : spectrogramWorkerRef.current;
|
|
670
|
+
if (!pool) return;
|
|
671
|
+
const held = new Set(pool.registeredAudioClipIds());
|
|
672
|
+
for (const [key, buffer] of wanted) {
|
|
673
|
+
if (!held.has(key)) pool.registerAudioData(key, channelData(buffer), buffer.sampleRate);
|
|
646
674
|
}
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
for (const clip of track.clips) {
|
|
650
|
-
if (!clip.audioBuffer) continue;
|
|
651
|
-
currentClipIds.add(clip.id);
|
|
652
|
-
if (!registeredAudioClipIdsRef.current.has(clip.id)) {
|
|
653
|
-
const channelDataArrays = [];
|
|
654
|
-
for (let ch = 0; ch < clip.audioBuffer.numberOfChannels; ch++) {
|
|
655
|
-
channelDataArrays.push(clip.audioBuffer.getChannelData(ch));
|
|
656
|
-
}
|
|
657
|
-
workerApi.registerAudioData(clip.id, channelDataArrays, clip.audioBuffer.sampleRate);
|
|
658
|
-
registeredAudioClipIdsRef.current.add(clip.id);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
for (const clipId of registeredAudioClipIdsRef.current) {
|
|
663
|
-
if (!currentClipIds.has(clipId)) {
|
|
664
|
-
workerApi.unregisterAudioData(clipId);
|
|
665
|
-
registeredAudioClipIdsRef.current.delete(clipId);
|
|
666
|
-
}
|
|
675
|
+
for (const key of held) {
|
|
676
|
+
if (!wanted.has(key)) pool.unregisterAudioData(key);
|
|
667
677
|
}
|
|
668
|
-
}, [
|
|
669
|
-
(0,
|
|
678
|
+
}, [tracks, trackSpectrogramOverrides, audioKeyOf, ensureWorkerPool]);
|
|
679
|
+
(0, import_react3.useEffect)(() => {
|
|
670
680
|
if (tracks.length === 0) return;
|
|
671
681
|
const currentKeys = /* @__PURE__ */ new Map();
|
|
672
|
-
const currentFFTKeys = /* @__PURE__ */ new Map();
|
|
673
682
|
tracks.forEach((track) => {
|
|
674
683
|
const override = trackSpectrogramOverrides.get(track.id);
|
|
675
684
|
const mode = resolveRenderMode(override, track.renderMode);
|
|
@@ -677,54 +686,28 @@ var SpectrogramProvider = ({
|
|
|
677
686
|
const cfg = override?.config ?? track.spectrogramConfig ?? spectrogramConfig;
|
|
678
687
|
const cm = override?.colorMap ?? track.spectrogramColorMap ?? spectrogramColorMap;
|
|
679
688
|
currentKeys.set(track.id, buildConfigKey({ mode, cfg, cm, mono }));
|
|
680
|
-
currentFFTKeys.set(
|
|
681
|
-
track.id,
|
|
682
|
-
buildFFTKey({ mode, mono, computeConfig: toComputeConfig(cfg) })
|
|
683
|
-
);
|
|
684
689
|
});
|
|
685
690
|
const prevKeys = prevSpectrogramConfigRef.current;
|
|
686
|
-
const prevFFTKeys = prevSpectrogramFFTKeyRef.current;
|
|
687
691
|
const configChanged = mapsDiffer(prevKeys, currentKeys);
|
|
688
|
-
const fftKeyChanged = mapsDiffer(prevFFTKeys, currentFFTKeys);
|
|
689
692
|
const canvasVersionChanged = spectrogramCanvasVersion !== prevCanvasVersionRef.current;
|
|
690
693
|
prevCanvasVersionRef.current = spectrogramCanvasVersion;
|
|
691
694
|
if (!configChanged && !canvasVersionChanged) return;
|
|
692
695
|
if (configChanged) {
|
|
693
696
|
prevSpectrogramConfigRef.current = currentKeys;
|
|
694
|
-
prevSpectrogramFFTKeyRef.current = currentFFTKeys;
|
|
695
697
|
}
|
|
696
698
|
if (backgroundRenderAbortRef.current) {
|
|
697
699
|
backgroundRenderAbortRef.current.aborted = true;
|
|
698
700
|
}
|
|
699
701
|
const generation = ++spectrogramGenerationRef.current;
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
try {
|
|
706
|
-
workerApi = (0, import_spectrogram2.createSpectrogramWorkerPool)(
|
|
707
|
-
() => new Worker(new URL("@dawcore/spectrogram/worker/spectrogram.worker", import_meta.url), {
|
|
708
|
-
type: "module"
|
|
709
|
-
}),
|
|
710
|
-
workerPoolSize
|
|
711
|
-
);
|
|
712
|
-
spectrogramWorkerRef.current = workerApi;
|
|
713
|
-
} catch (err) {
|
|
714
|
-
console.error(
|
|
715
|
-
`[waveform-playlist] Spectrogram Web Worker required but unavailable: ${err instanceof Error ? err.message : String(err)}`
|
|
716
|
-
);
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
const clipsNeedingFFT = [];
|
|
721
|
-
const clipsNeedingDisplayOnly = [];
|
|
722
|
-
tracks.forEach((track, i) => {
|
|
702
|
+
const workerApi = ensureWorkerPool();
|
|
703
|
+
if (!workerApi) return;
|
|
704
|
+
workerApi.abortGeneration(generation);
|
|
705
|
+
const clipsToRender = [];
|
|
706
|
+
tracks.forEach((track) => {
|
|
723
707
|
const override = trackSpectrogramOverrides.get(track.id);
|
|
724
708
|
const mode = resolveRenderMode(override, track.renderMode);
|
|
725
709
|
if (mode === "waveform") return;
|
|
726
710
|
const trackConfigChanged = configChanged && currentKeys.get(track.id) !== prevKeys.get(track.id);
|
|
727
|
-
const trackFFTChanged = fftKeyChanged && currentFFTKeys.get(track.id) !== prevFFTKeys.get(track.id);
|
|
728
711
|
const hasRegisteredCanvases = canvasVersionChanged && track.clips.some((clip) => spectrogramCanvasRegistryRef.current.has(clip.id));
|
|
729
712
|
if (!trackConfigChanged && !hasRegisteredCanvases) return;
|
|
730
713
|
const cfg = override?.config ?? track.spectrogramConfig ?? spectrogramConfig ?? {};
|
|
@@ -739,34 +722,10 @@ var SpectrogramProvider = ({
|
|
|
739
722
|
canvasRangesRef.current
|
|
740
723
|
)
|
|
741
724
|
);
|
|
742
|
-
|
|
743
|
-
const channelDataArrays2 = [];
|
|
744
|
-
for (let ch = 0; ch < clip.audioBuffer.numberOfChannels; ch++) {
|
|
745
|
-
channelDataArrays2.push(clip.audioBuffer.getChannelData(ch));
|
|
746
|
-
}
|
|
747
|
-
clipsNeedingDisplayOnly.push({
|
|
748
|
-
clipId: clip.id,
|
|
749
|
-
trackIndex: i,
|
|
750
|
-
channelDataArrays: channelDataArrays2,
|
|
751
|
-
config: cfg,
|
|
752
|
-
sampleRate: clip.audioBuffer.sampleRate,
|
|
753
|
-
offsetSamples,
|
|
754
|
-
durationSamples,
|
|
755
|
-
clipStartSample: clip.startSample,
|
|
756
|
-
monoFlag,
|
|
757
|
-
colorMap: cm,
|
|
758
|
-
numChannels: monoFlag ? 1 : clip.audioBuffer.numberOfChannels
|
|
759
|
-
});
|
|
760
|
-
continue;
|
|
761
|
-
}
|
|
762
|
-
const channelDataArrays = [];
|
|
763
|
-
for (let ch = 0; ch < clip.audioBuffer.numberOfChannels; ch++) {
|
|
764
|
-
channelDataArrays.push(clip.audioBuffer.getChannelData(ch));
|
|
765
|
-
}
|
|
766
|
-
clipsNeedingFFT.push({
|
|
725
|
+
clipsToRender.push({
|
|
767
726
|
clipId: clip.id,
|
|
768
|
-
|
|
769
|
-
channelDataArrays,
|
|
727
|
+
audioKey: audioKeyOf(clip.audioBuffer),
|
|
728
|
+
channelDataArrays: channelData(clip.audioBuffer),
|
|
770
729
|
config: cfg,
|
|
771
730
|
sampleRate: clip.audioBuffer.sampleRate,
|
|
772
731
|
offsetSamples,
|
|
@@ -777,7 +736,7 @@ var SpectrogramProvider = ({
|
|
|
777
736
|
});
|
|
778
737
|
}
|
|
779
738
|
});
|
|
780
|
-
if (
|
|
739
|
+
if (clipsToRender.length === 0) return;
|
|
781
740
|
const getVisibleChunkRange = (channelInfo, clipPixelOffset = 0) => {
|
|
782
741
|
const container = scrollContainerRef.current;
|
|
783
742
|
return classifyChunkTiers(
|
|
@@ -830,7 +789,8 @@ var SpectrogramProvider = ({
|
|
|
830
789
|
});
|
|
831
790
|
const { cacheKey } = await api.computeFFT(
|
|
832
791
|
{
|
|
833
|
-
|
|
792
|
+
// The pool's "clip id" names the registered audio: the buffer's key.
|
|
793
|
+
clipId: item.audioKey,
|
|
834
794
|
channelDataArrays: item.channelDataArrays,
|
|
835
795
|
config: item.config,
|
|
836
796
|
sampleRate: item.sampleRate,
|
|
@@ -886,7 +846,7 @@ var SpectrogramProvider = ({
|
|
|
886
846
|
}
|
|
887
847
|
return false;
|
|
888
848
|
};
|
|
889
|
-
for (const item of
|
|
849
|
+
for (const item of clipsToRender) {
|
|
890
850
|
if (spectrogramGenerationRef.current !== generation || abortToken.aborted) return;
|
|
891
851
|
try {
|
|
892
852
|
const clipCanvasInfo = spectrogramCanvasRegistryRef.current.get(item.clipId);
|
|
@@ -950,7 +910,6 @@ var SpectrogramProvider = ({
|
|
|
950
910
|
}
|
|
951
911
|
}
|
|
952
912
|
}
|
|
953
|
-
renderedClipIdsRef.current.add(item.clipId);
|
|
954
913
|
if (spectrogramGenerationRef.current !== generation || abortToken.aborted) return;
|
|
955
914
|
if (await renderBackgroundBatches(channelRanges, item)) return;
|
|
956
915
|
}
|
|
@@ -961,78 +920,6 @@ var SpectrogramProvider = ({
|
|
|
961
920
|
);
|
|
962
921
|
}
|
|
963
922
|
}
|
|
964
|
-
for (const item of clipsNeedingDisplayOnly) {
|
|
965
|
-
if (spectrogramGenerationRef.current !== generation || abortToken.aborted) return;
|
|
966
|
-
const clipCanvasInfo = spectrogramCanvasRegistryRef.current.get(item.clipId);
|
|
967
|
-
if (!clipCanvasInfo || clipCanvasInfo.size === 0) continue;
|
|
968
|
-
try {
|
|
969
|
-
const clipPixelOffset = Math.floor(item.clipStartSample / samplesPerPixel);
|
|
970
|
-
const channelRanges = [];
|
|
971
|
-
for (let ch = 0; ch < item.numChannels; ch++) {
|
|
972
|
-
const channelInfo = clipCanvasInfo.get(ch);
|
|
973
|
-
if (!channelInfo) continue;
|
|
974
|
-
const range = getVisibleChunkRange(channelInfo, clipPixelOffset);
|
|
975
|
-
channelRanges.push({ ch, channelInfo, ...range });
|
|
976
|
-
}
|
|
977
|
-
if (channelRanges.length > 0 && channelRanges[0].viewportIndices.length > 0) {
|
|
978
|
-
const cacheKey = await computeFFTForChunks(
|
|
979
|
-
workerApi,
|
|
980
|
-
channelRanges[0].channelInfo,
|
|
981
|
-
channelRanges[0].viewportIndices,
|
|
982
|
-
item,
|
|
983
|
-
generation
|
|
984
|
-
);
|
|
985
|
-
if (spectrogramGenerationRef.current !== generation || abortToken.aborted) return;
|
|
986
|
-
for (const { ch, channelInfo, viewportIndices } of channelRanges) {
|
|
987
|
-
await renderChunkSubset(
|
|
988
|
-
workerApi,
|
|
989
|
-
cacheKey,
|
|
990
|
-
channelInfo,
|
|
991
|
-
viewportIndices,
|
|
992
|
-
item,
|
|
993
|
-
ch,
|
|
994
|
-
generation
|
|
995
|
-
);
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
if (spectrogramGenerationRef.current !== generation || abortToken.aborted) return;
|
|
999
|
-
if (channelRanges.length > 0 && channelRanges[0].bufferIndices.length > 0) {
|
|
1000
|
-
const bufferGroups = groupContiguousIndices(
|
|
1001
|
-
channelRanges[0].channelInfo,
|
|
1002
|
-
channelRanges[0].bufferIndices
|
|
1003
|
-
);
|
|
1004
|
-
for (const group of bufferGroups) {
|
|
1005
|
-
if (spectrogramGenerationRef.current !== generation || abortToken.aborted) return;
|
|
1006
|
-
const cacheKey = await computeFFTForChunks(
|
|
1007
|
-
workerApi,
|
|
1008
|
-
channelRanges[0].channelInfo,
|
|
1009
|
-
group,
|
|
1010
|
-
item,
|
|
1011
|
-
generation
|
|
1012
|
-
);
|
|
1013
|
-
if (spectrogramGenerationRef.current !== generation || abortToken.aborted) return;
|
|
1014
|
-
for (const { ch, channelInfo } of channelRanges) {
|
|
1015
|
-
await renderChunkSubset(
|
|
1016
|
-
workerApi,
|
|
1017
|
-
cacheKey,
|
|
1018
|
-
channelInfo,
|
|
1019
|
-
group,
|
|
1020
|
-
item,
|
|
1021
|
-
ch,
|
|
1022
|
-
generation
|
|
1023
|
-
);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
if (spectrogramGenerationRef.current !== generation || abortToken.aborted) return;
|
|
1028
|
-
if (await renderBackgroundBatches(channelRanges, item)) return;
|
|
1029
|
-
} catch (err) {
|
|
1030
|
-
if (err instanceof import_spectrogram2.SpectrogramAbortError) return;
|
|
1031
|
-
console.warn(
|
|
1032
|
-
`[waveform-playlist] Spectrogram display re-render error for clip ${item.clipId}: ${err instanceof Error ? err.message : String(err)}`
|
|
1033
|
-
);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
923
|
};
|
|
1037
924
|
computeAsync().catch((err) => {
|
|
1038
925
|
console.error(
|
|
@@ -1047,9 +934,11 @@ var SpectrogramProvider = ({
|
|
|
1047
934
|
trackSpectrogramOverrides,
|
|
1048
935
|
samplesPerPixel,
|
|
1049
936
|
spectrogramCanvasVersion,
|
|
1050
|
-
scrollContainerRef
|
|
937
|
+
scrollContainerRef,
|
|
938
|
+
audioKeyOf,
|
|
939
|
+
ensureWorkerPool
|
|
1051
940
|
]);
|
|
1052
|
-
const setTrackRenderMode = (0,
|
|
941
|
+
const setTrackRenderMode = (0, import_react3.useCallback)((trackId, mode) => {
|
|
1053
942
|
setTrackSpectrogramOverrides((prev) => {
|
|
1054
943
|
const next = new Map(prev);
|
|
1055
944
|
const existing = next.get(trackId);
|
|
@@ -1057,40 +946,22 @@ var SpectrogramProvider = ({
|
|
|
1057
946
|
return next;
|
|
1058
947
|
});
|
|
1059
948
|
}, []);
|
|
1060
|
-
const setTrackSpectrogramConfig = (0,
|
|
1061
|
-
(trackId,
|
|
949
|
+
const setTrackSpectrogramConfig = (0, import_react3.useCallback)(
|
|
950
|
+
(trackId, config2, colorMap2) => {
|
|
1062
951
|
setTrackSpectrogramOverrides((prev) => {
|
|
1063
952
|
const next = new Map(prev);
|
|
1064
953
|
const existing = next.get(trackId);
|
|
1065
954
|
next.set(trackId, {
|
|
1066
|
-
|
|
1067
|
-
config,
|
|
1068
|
-
|
|
955
|
+
...existing,
|
|
956
|
+
config: config2,
|
|
957
|
+
colorMap: colorMap2 ?? existing?.colorMap
|
|
1069
958
|
});
|
|
1070
959
|
return next;
|
|
1071
960
|
});
|
|
1072
961
|
},
|
|
1073
962
|
[]
|
|
1074
963
|
);
|
|
1075
|
-
const
|
|
1076
|
-
if (spectrogramWorkerRef.current) return spectrogramWorkerRef.current;
|
|
1077
|
-
try {
|
|
1078
|
-
const pool = (0, import_spectrogram2.createSpectrogramWorkerPool)(
|
|
1079
|
-
() => new Worker(new URL("@dawcore/spectrogram/worker/spectrogram.worker", import_meta.url), {
|
|
1080
|
-
type: "module"
|
|
1081
|
-
}),
|
|
1082
|
-
workerPoolSize
|
|
1083
|
-
);
|
|
1084
|
-
spectrogramWorkerRef.current = pool;
|
|
1085
|
-
return pool;
|
|
1086
|
-
} catch (err) {
|
|
1087
|
-
console.warn(
|
|
1088
|
-
`[waveform-playlist] Spectrogram Web Worker unavailable: ${err instanceof Error ? err.message : String(err)}`
|
|
1089
|
-
);
|
|
1090
|
-
return null;
|
|
1091
|
-
}
|
|
1092
|
-
}, [workerPoolSize]);
|
|
1093
|
-
const registerSpectrogramCanvas = (0, import_react2.useCallback)(
|
|
964
|
+
const registerSpectrogramCanvas = (0, import_react3.useCallback)(
|
|
1094
965
|
(reg) => {
|
|
1095
966
|
const pool = ensureWorkerPool();
|
|
1096
967
|
if (!pool) return;
|
|
@@ -1129,7 +1000,7 @@ var SpectrogramProvider = ({
|
|
|
1129
1000
|
},
|
|
1130
1001
|
[ensureWorkerPool]
|
|
1131
1002
|
);
|
|
1132
|
-
const unregisterSpectrogramCanvas = (0,
|
|
1003
|
+
const unregisterSpectrogramCanvas = (0, import_react3.useCallback)((canvasId) => {
|
|
1133
1004
|
canvasHeightsRef.current.delete(canvasId);
|
|
1134
1005
|
canvasRangesRef.current.delete(canvasId);
|
|
1135
1006
|
const pool = spectrogramWorkerRef.current;
|
|
@@ -1163,7 +1034,7 @@ var SpectrogramProvider = ({
|
|
|
1163
1034
|
}
|
|
1164
1035
|
setSpectrogramCanvasVersion((v) => v + 1);
|
|
1165
1036
|
}, []);
|
|
1166
|
-
const renderMenuItems = (0,
|
|
1037
|
+
const renderMenuItems = (0, import_react3.useCallback)(
|
|
1167
1038
|
(props) => {
|
|
1168
1039
|
return SpectrogramMenuItems({
|
|
1169
1040
|
renderMode: props.renderMode,
|
|
@@ -1174,7 +1045,7 @@ var SpectrogramProvider = ({
|
|
|
1174
1045
|
},
|
|
1175
1046
|
[]
|
|
1176
1047
|
);
|
|
1177
|
-
const value = (0,
|
|
1048
|
+
const value = (0, import_react3.useMemo)(
|
|
1178
1049
|
() => ({
|
|
1179
1050
|
trackSpectrogramOverrides,
|
|
1180
1051
|
spectrogramConfig,
|