@waveform-playlist/spectrogram 14.0.1 → 15.0.0-next.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/README.md +6 -8
- package/dist/index.d.mts +8 -9
- package/dist/index.d.ts +8 -9
- package/dist/index.js +141 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Wraps [`@dawcore/spectrogram`](https://www.npmjs.com/package/@dawcore/spectrogra
|
|
|
10
10
|
- **Render-mode switching** per track — `'waveform'`, `'spectrogram'`, or `'both'` (waveform on top, spectrogram below)
|
|
11
11
|
- **Six built-in color maps** (`viridis`, `magma`, `inferno`, `grayscale`, `igray`, `roseus`) plus custom `[r, g, b]` palettes
|
|
12
12
|
- **Five frequency scales** — linear, logarithmic, mel, bark, erb
|
|
13
|
-
- **Drop-in settings UI** — `<SpectrogramSettingsModal>` (FFT size, hop size, window function, gain/range, frequency bounds) and
|
|
13
|
+
- **Drop-in settings UI** — `<SpectrogramSettingsModal>` (FFT size, hop size, window function, gain/range, frequency bounds) and `SpectrogramMenuItems()`, a function that returns the render-mode and settings items for a `TrackMenu` (`@waveform-playlist/ui-components`). Under the provider, the default track controls of `@waveform-playlist/browser` show that menu already (`<TrackMenuButton />` in a panel you compose; `useTrack().setRenderMode()` and `.openSpectrogramSettings()` in your own)
|
|
14
14
|
- **Viewport-aware rendering** — a Web Worker pool computes the visible chunks first, then a scroll buffer, then the rest in the background, so long timelines stay responsive
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
@@ -26,19 +26,17 @@ Requires `@waveform-playlist/browser`, `react`, and `styled-components` as peer
|
|
|
26
26
|
Wrap your editor with `<SpectrogramProvider>` and set a track's `renderMode`:
|
|
27
27
|
|
|
28
28
|
```tsx
|
|
29
|
-
import { WaveformPlaylistProvider, Waveform } from '@waveform-playlist/browser';
|
|
30
|
-
import {
|
|
29
|
+
import { WaveformPlaylistProvider, Waveform, useCreateArrangement } from '@waveform-playlist/browser';
|
|
30
|
+
import { audioTrack } from '@waveform-playlist/core';
|
|
31
31
|
import { SpectrogramProvider } from '@waveform-playlist/spectrogram';
|
|
32
32
|
|
|
33
33
|
function MyEditor() {
|
|
34
|
-
const
|
|
35
|
-
{ src: '/audio/vocals.opus', name: 'Vocals', renderMode: 'spectrogram' },
|
|
34
|
+
const arrangement = useCreateArrangement(() => [
|
|
35
|
+
audioTrack({ src: '/audio/vocals.opus', name: 'Vocals', renderMode: 'spectrogram' }),
|
|
36
36
|
]);
|
|
37
37
|
|
|
38
|
-
if (loading) return <div>Loading...</div>;
|
|
39
|
-
|
|
40
38
|
return (
|
|
41
|
-
<WaveformPlaylistProvider
|
|
39
|
+
<WaveformPlaylistProvider arrangement={arrangement}>
|
|
42
40
|
<SpectrogramProvider config={{ fftSize: 2048, frequencyScale: 'mel' }} colorMap="viridis">
|
|
43
41
|
<Waveform />
|
|
44
42
|
</SpectrogramProvider>
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { RenderMode, SpectrogramConfig, ColorMapValue } from '@waveform-playlist/core';
|
|
2
|
+
import { SpectrogramIntegration } from '@waveform-playlist/browser';
|
|
2
3
|
import React, { ReactNode } from 'react';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
content: ReactNode;
|
|
8
|
-
}
|
|
9
|
-
|
|
5
|
+
/** The items browser's track menu asks the spectrogram integration for:
|
|
6
|
+
* ui-components' `TrackMenuItem[]`, named through the type that carries it. */
|
|
7
|
+
type MenuItems = ReturnType<NonNullable<SpectrogramIntegration['renderMenuItems']>>;
|
|
10
8
|
interface SpectrogramMenuItemsProps {
|
|
11
9
|
renderMode: RenderMode;
|
|
12
10
|
onRenderModeChange: (mode: RenderMode) => void;
|
|
@@ -14,9 +12,10 @@ interface SpectrogramMenuItemsProps {
|
|
|
14
12
|
onClose?: () => void;
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
17
|
-
* Returns
|
|
15
|
+
* Returns the track menu items (`TrackMenuItem[]` of ui-components) for the
|
|
16
|
+
* spectrogram display mode radios and settings button.
|
|
18
17
|
*/
|
|
19
|
-
declare function SpectrogramMenuItems({ renderMode, onRenderModeChange, onOpenSettings, onClose, }: SpectrogramMenuItemsProps):
|
|
18
|
+
declare function SpectrogramMenuItems({ renderMode, onRenderModeChange, onOpenSettings, onClose, }: SpectrogramMenuItemsProps): MenuItems;
|
|
20
19
|
|
|
21
20
|
interface SpectrogramSettingsModalProps {
|
|
22
21
|
open: boolean;
|
|
@@ -36,4 +35,4 @@ interface SpectrogramProviderProps {
|
|
|
36
35
|
}
|
|
37
36
|
declare const SpectrogramProvider: React.FC<SpectrogramProviderProps>;
|
|
38
37
|
|
|
39
|
-
export { SpectrogramMenuItems, type SpectrogramMenuItemsProps, SpectrogramProvider, type SpectrogramProviderProps, SpectrogramSettingsModal, type SpectrogramSettingsModalProps
|
|
38
|
+
export { SpectrogramMenuItems, type SpectrogramMenuItemsProps, SpectrogramProvider, type SpectrogramProviderProps, SpectrogramSettingsModal, type SpectrogramSettingsModalProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { RenderMode, SpectrogramConfig, ColorMapValue } from '@waveform-playlist/core';
|
|
2
|
+
import { SpectrogramIntegration } from '@waveform-playlist/browser';
|
|
2
3
|
import React, { ReactNode } from 'react';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
content: ReactNode;
|
|
8
|
-
}
|
|
9
|
-
|
|
5
|
+
/** The items browser's track menu asks the spectrogram integration for:
|
|
6
|
+
* ui-components' `TrackMenuItem[]`, named through the type that carries it. */
|
|
7
|
+
type MenuItems = ReturnType<NonNullable<SpectrogramIntegration['renderMenuItems']>>;
|
|
10
8
|
interface SpectrogramMenuItemsProps {
|
|
11
9
|
renderMode: RenderMode;
|
|
12
10
|
onRenderModeChange: (mode: RenderMode) => void;
|
|
@@ -14,9 +12,10 @@ interface SpectrogramMenuItemsProps {
|
|
|
14
12
|
onClose?: () => void;
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
17
|
-
* Returns
|
|
15
|
+
* Returns the track menu items (`TrackMenuItem[]` of ui-components) for the
|
|
16
|
+
* spectrogram display mode radios and settings button.
|
|
18
17
|
*/
|
|
19
|
-
declare function SpectrogramMenuItems({ renderMode, onRenderModeChange, onOpenSettings, onClose, }: SpectrogramMenuItemsProps):
|
|
18
|
+
declare function SpectrogramMenuItems({ renderMode, onRenderModeChange, onOpenSettings, onClose, }: SpectrogramMenuItemsProps): MenuItems;
|
|
20
19
|
|
|
21
20
|
interface SpectrogramSettingsModalProps {
|
|
22
21
|
open: boolean;
|
|
@@ -36,4 +35,4 @@ interface SpectrogramProviderProps {
|
|
|
36
35
|
}
|
|
37
36
|
declare const SpectrogramProvider: React.FC<SpectrogramProviderProps>;
|
|
38
37
|
|
|
39
|
-
export { SpectrogramMenuItems, type SpectrogramMenuItemsProps, SpectrogramProvider, type SpectrogramProviderProps, SpectrogramSettingsModal, type SpectrogramSettingsModalProps
|
|
38
|
+
export { SpectrogramMenuItems, type SpectrogramMenuItemsProps, SpectrogramProvider, type SpectrogramProviderProps, SpectrogramSettingsModal, type SpectrogramSettingsModalProps };
|
package/dist/index.js
CHANGED
|
@@ -140,6 +140,7 @@ var StyledDialog = import_styled_components2.default.dialog`
|
|
|
140
140
|
color: ${(p) => p.theme.textColor ?? "inherit"};
|
|
141
141
|
min-width: 380px;
|
|
142
142
|
max-width: 500px;
|
|
143
|
+
overscroll-behavior: contain;
|
|
143
144
|
|
|
144
145
|
&::backdrop {
|
|
145
146
|
background: rgba(0, 0, 0, 0.5);
|
|
@@ -222,14 +223,8 @@ var WINDOW_FUNCTIONS = [
|
|
|
222
223
|
];
|
|
223
224
|
var FREQ_SCALES = ["linear", "logarithmic", "mel", "bark", "erb"];
|
|
224
225
|
var COLOR_MAPS = ["viridis", "magma", "inferno", "grayscale", "igray", "roseus"];
|
|
225
|
-
var
|
|
226
|
-
|
|
227
|
-
onClose,
|
|
228
|
-
config,
|
|
229
|
-
colorMap,
|
|
230
|
-
onApply
|
|
231
|
-
}) => {
|
|
232
|
-
const dialogRef = (0, import_react.useRef)(null);
|
|
226
|
+
var SettingsForm = ({ onClose, config, colorMap, onApply }) => {
|
|
227
|
+
const id = (0, import_react.useId)();
|
|
233
228
|
const [fftSize, setFftSize] = (0, import_react.useState)(config.fftSize ?? 2048);
|
|
234
229
|
const [windowFn, setWindowFn] = (0, import_react.useState)(config.windowFunction ?? "hann");
|
|
235
230
|
const [freqScale, setFreqScale] = (0, import_react.useState)(config.frequencyScale ?? "mel");
|
|
@@ -245,35 +240,6 @@ var SpectrogramSettingsModal = ({
|
|
|
245
240
|
config.hopSize ?? Math.floor((config.fftSize ?? 2048) / 4)
|
|
246
241
|
);
|
|
247
242
|
const [showLabels, setShowLabels] = (0, import_react.useState)(config.labels ?? false);
|
|
248
|
-
(0, import_react.useEffect)(() => {
|
|
249
|
-
setFftSize(config.fftSize ?? 2048);
|
|
250
|
-
setWindowFn(config.windowFunction ?? "hann");
|
|
251
|
-
setFreqScale(config.frequencyScale ?? "mel");
|
|
252
|
-
setLocalColorMap(typeof colorMap === "string" ? colorMap : "viridis");
|
|
253
|
-
setMinFreq(config.minFrequency ?? 0);
|
|
254
|
-
setMaxFreq(config.maxFrequency ?? 2e4);
|
|
255
|
-
setGainDb(config.gainDb ?? 20);
|
|
256
|
-
setRangeDb(config.rangeDb ?? 80);
|
|
257
|
-
setZeroPadding(config.zeroPaddingFactor ?? 2);
|
|
258
|
-
setHopSize(config.hopSize ?? Math.floor((config.fftSize ?? 2048) / 4));
|
|
259
|
-
setShowLabels(config.labels ?? false);
|
|
260
|
-
}, [config, colorMap]);
|
|
261
|
-
(0, import_react.useEffect)(() => {
|
|
262
|
-
const dialog = dialogRef.current;
|
|
263
|
-
if (!dialog) return;
|
|
264
|
-
if (open && !dialog.open) {
|
|
265
|
-
dialog.showModal();
|
|
266
|
-
} else if (!open && dialog.open) {
|
|
267
|
-
dialog.close();
|
|
268
|
-
}
|
|
269
|
-
const handleClose = () => {
|
|
270
|
-
if (open) {
|
|
271
|
-
onClose();
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
dialog.addEventListener("close", handleClose);
|
|
275
|
-
return () => dialog.removeEventListener("close", handleClose);
|
|
276
|
-
}, [open, onClose]);
|
|
277
243
|
const handleApply = () => {
|
|
278
244
|
onApply(
|
|
279
245
|
{
|
|
@@ -292,14 +258,14 @@ var SpectrogramSettingsModal = ({
|
|
|
292
258
|
);
|
|
293
259
|
onClose();
|
|
294
260
|
};
|
|
295
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
296
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Title, { children: "Spectrogram Settings" }),
|
|
261
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
297
262
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(FormGrid, { children: [
|
|
298
263
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
299
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "FFT Size" }),
|
|
264
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-fft-size`, children: "FFT Size" }),
|
|
300
265
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
301
266
|
Select,
|
|
302
267
|
{
|
|
268
|
+
id: `${id}-fft-size`,
|
|
303
269
|
value: fftSize,
|
|
304
270
|
onChange: (e) => {
|
|
305
271
|
const v = Number(e.target.value);
|
|
@@ -311,27 +277,52 @@ var SpectrogramSettingsModal = ({
|
|
|
311
277
|
)
|
|
312
278
|
] }),
|
|
313
279
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
314
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Hop Size" }),
|
|
315
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
316
|
-
|
|
317
|
-
{
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
280
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-hop-size`, children: "Hop Size" }),
|
|
281
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
282
|
+
Select,
|
|
283
|
+
{
|
|
284
|
+
id: `${id}-hop-size`,
|
|
285
|
+
value: hopSize,
|
|
286
|
+
onChange: (e) => setHopSize(Number(e.target.value)),
|
|
287
|
+
children: [
|
|
288
|
+
{ label: `${fftSize} (no overlap)`, value: fftSize },
|
|
289
|
+
{ label: `${Math.floor(fftSize / 2)} (50%)`, value: Math.floor(fftSize / 2) },
|
|
290
|
+
{ label: `${Math.floor(fftSize / 4)} (75%)`, value: Math.floor(fftSize / 4) },
|
|
291
|
+
{ label: `${Math.floor(fftSize / 8)} (87.5%)`, value: Math.floor(fftSize / 8) }
|
|
292
|
+
].map((o) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: o.value, children: o.label }, o.value))
|
|
293
|
+
}
|
|
294
|
+
)
|
|
321
295
|
] }),
|
|
322
296
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
323
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Zero Padding" }),
|
|
324
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
297
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-zero-padding`, children: "Zero Padding" }),
|
|
298
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
299
|
+
Select,
|
|
300
|
+
{
|
|
301
|
+
id: `${id}-zero-padding`,
|
|
302
|
+
value: zeroPadding,
|
|
303
|
+
onChange: (e) => setZeroPadding(Number(e.target.value)),
|
|
304
|
+
children: [1, 2, 4, 8, 16].map((v) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: v, children: v }, v))
|
|
305
|
+
}
|
|
306
|
+
)
|
|
325
307
|
] }),
|
|
326
308
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
327
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Window Function" }),
|
|
328
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
309
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-window-function`, children: "Window Function" }),
|
|
310
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
311
|
+
Select,
|
|
312
|
+
{
|
|
313
|
+
id: `${id}-window-function`,
|
|
314
|
+
value: windowFn,
|
|
315
|
+
onChange: (e) => setWindowFn(e.target.value),
|
|
316
|
+
children: WINDOW_FUNCTIONS.map((w) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: w, children: w }, w))
|
|
317
|
+
}
|
|
318
|
+
)
|
|
329
319
|
] }),
|
|
330
320
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
331
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Frequency Scale" }),
|
|
321
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-frequency-scale`, children: "Frequency Scale" }),
|
|
332
322
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
333
323
|
Select,
|
|
334
324
|
{
|
|
325
|
+
id: `${id}-frequency-scale`,
|
|
335
326
|
value: freqScale,
|
|
336
327
|
onChange: (e) => setFreqScale(e.target.value),
|
|
337
328
|
children: FREQ_SCALES.map((s) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: s, children: s }, s))
|
|
@@ -339,10 +330,11 @@ var SpectrogramSettingsModal = ({
|
|
|
339
330
|
)
|
|
340
331
|
] }),
|
|
341
332
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
342
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Color Map" }),
|
|
333
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-color-map`, children: "Color Map" }),
|
|
343
334
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
344
335
|
Select,
|
|
345
336
|
{
|
|
337
|
+
id: `${id}-color-map`,
|
|
346
338
|
value: localColorMap,
|
|
347
339
|
onChange: (e) => setLocalColorMap(e.target.value),
|
|
348
340
|
children: COLOR_MAPS.map((c) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: c, children: c }, c))
|
|
@@ -350,10 +342,11 @@ var SpectrogramSettingsModal = ({
|
|
|
350
342
|
)
|
|
351
343
|
] }),
|
|
352
344
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
353
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Min Frequency (Hz)" }),
|
|
345
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-min-frequency`, children: "Min Frequency (Hz)" }),
|
|
354
346
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
355
347
|
NumberInput,
|
|
356
348
|
{
|
|
349
|
+
id: `${id}-min-frequency`,
|
|
357
350
|
type: "number",
|
|
358
351
|
min: 0,
|
|
359
352
|
max: 5e3,
|
|
@@ -364,10 +357,11 @@ var SpectrogramSettingsModal = ({
|
|
|
364
357
|
)
|
|
365
358
|
] }),
|
|
366
359
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
367
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Max Frequency (Hz)" }),
|
|
360
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-max-frequency`, children: "Max Frequency (Hz)" }),
|
|
368
361
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
369
362
|
NumberInput,
|
|
370
363
|
{
|
|
364
|
+
id: `${id}-max-frequency`,
|
|
371
365
|
type: "number",
|
|
372
366
|
min: 1e3,
|
|
373
367
|
max: 22050,
|
|
@@ -378,10 +372,11 @@ var SpectrogramSettingsModal = ({
|
|
|
378
372
|
)
|
|
379
373
|
] }),
|
|
380
374
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
381
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Range (dB)" }),
|
|
375
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-range-db`, children: "Range (dB)" }),
|
|
382
376
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
383
377
|
NumberInput,
|
|
384
378
|
{
|
|
379
|
+
id: `${id}-range-db`,
|
|
385
380
|
type: "number",
|
|
386
381
|
min: 1,
|
|
387
382
|
max: 120,
|
|
@@ -392,10 +387,11 @@ var SpectrogramSettingsModal = ({
|
|
|
392
387
|
)
|
|
393
388
|
] }),
|
|
394
389
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Field, { children: [
|
|
395
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: "Gain (dB)" }),
|
|
390
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { htmlFor: `${id}-gain-db`, children: "Gain (dB)" }),
|
|
396
391
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
397
392
|
NumberInput,
|
|
398
393
|
{
|
|
394
|
+
id: `${id}-gain-db`,
|
|
399
395
|
type: "number",
|
|
400
396
|
min: -20,
|
|
401
397
|
max: 60,
|
|
@@ -418,11 +414,49 @@ var SpectrogramSettingsModal = ({
|
|
|
418
414
|
] }) })
|
|
419
415
|
] }),
|
|
420
416
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ButtonRow, { children: [
|
|
421
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ModalButton, { onClick: onClose, children: "Cancel" }),
|
|
422
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ModalButton, { $primary: true, onClick: handleApply, children: "Apply" })
|
|
417
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ModalButton, { type: "button", onClick: onClose, children: "Cancel" }),
|
|
418
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ModalButton, { type: "button", $primary: true, onClick: handleApply, children: "Apply" })
|
|
423
419
|
] })
|
|
424
420
|
] });
|
|
425
421
|
};
|
|
422
|
+
var SpectrogramSettingsModal = ({
|
|
423
|
+
open,
|
|
424
|
+
onClose,
|
|
425
|
+
config,
|
|
426
|
+
colorMap,
|
|
427
|
+
onApply
|
|
428
|
+
}) => {
|
|
429
|
+
const dialogRef = (0, import_react.useRef)(null);
|
|
430
|
+
const titleId = (0, import_react.useId)();
|
|
431
|
+
const latestRef = (0, import_react.useRef)({ open, onClose });
|
|
432
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
433
|
+
latestRef.current = { open, onClose };
|
|
434
|
+
});
|
|
435
|
+
(0, import_react.useEffect)(() => {
|
|
436
|
+
const dialog = dialogRef.current;
|
|
437
|
+
if (!dialog) return;
|
|
438
|
+
const handleClose = () => {
|
|
439
|
+
if (latestRef.current.open) {
|
|
440
|
+
latestRef.current.onClose();
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
dialog.addEventListener("close", handleClose);
|
|
444
|
+
return () => dialog.removeEventListener("close", handleClose);
|
|
445
|
+
}, []);
|
|
446
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
447
|
+
const dialog = dialogRef.current;
|
|
448
|
+
if (!dialog) return;
|
|
449
|
+
if (open && !dialog.open) {
|
|
450
|
+
dialog.showModal();
|
|
451
|
+
} else if (!open && dialog.open) {
|
|
452
|
+
dialog.close();
|
|
453
|
+
}
|
|
454
|
+
}, [open]);
|
|
455
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(StyledDialog, { ref: dialogRef, "aria-labelledby": titleId, children: [
|
|
456
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Title, { id: titleId, children: "Spectrogram Settings" }),
|
|
457
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SettingsForm, { onClose, config, colorMap, onApply })
|
|
458
|
+
] });
|
|
459
|
+
};
|
|
426
460
|
|
|
427
461
|
// src/SpectrogramProvider.tsx
|
|
428
462
|
var import_react2 = require("react");
|
|
@@ -540,6 +574,22 @@ function mapsDiffer(prev, current) {
|
|
|
540
574
|
}
|
|
541
575
|
return false;
|
|
542
576
|
}
|
|
577
|
+
function registeredClipRange(perClip, rangeByCanvasId) {
|
|
578
|
+
if (!perClip) return void 0;
|
|
579
|
+
for (const channelInfo of perClip.values()) {
|
|
580
|
+
for (const canvasId of channelInfo.canvasIds) {
|
|
581
|
+
const range = rangeByCanvasId.get(canvasId);
|
|
582
|
+
if (range) return range;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return void 0;
|
|
586
|
+
}
|
|
587
|
+
function resolveClipRange(clip, registered) {
|
|
588
|
+
return {
|
|
589
|
+
offsetSamples: registered?.offsetSamples ?? clip.offsetSamples,
|
|
590
|
+
durationSamples: registered?.durationSamples ?? clip.durationSamples
|
|
591
|
+
};
|
|
592
|
+
}
|
|
543
593
|
|
|
544
594
|
// src/SpectrogramProvider.tsx
|
|
545
595
|
var import_browser = require("@waveform-playlist/browser");
|
|
@@ -552,10 +602,14 @@ var SpectrogramProvider = ({
|
|
|
552
602
|
workerPoolSize,
|
|
553
603
|
children
|
|
554
604
|
}) => {
|
|
555
|
-
const {
|
|
556
|
-
const {
|
|
557
|
-
const
|
|
605
|
+
const { mono } = (0, import_browser2.usePlaylistView)();
|
|
606
|
+
const { samplesPerPixel } = (0, import_browser2.usePlaylistZoom)();
|
|
607
|
+
const { tracks, isReady } = (0, import_browser2.usePlaylistTimeline)();
|
|
608
|
+
const { scrollContainerRef } = (0, import_browser2.usePlaybackControls)();
|
|
609
|
+
const [trackSpectrogramOverrides, setTrackSpectrogramOverrides] = (0, import_react2.useState)(() => /* @__PURE__ */ new Map());
|
|
558
610
|
const spectrogramCanvasRegistryRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
611
|
+
const canvasHeightsRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
612
|
+
const canvasRangesRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
559
613
|
const [spectrogramCanvasVersion, setSpectrogramCanvasVersion] = (0, import_react2.useState)(0);
|
|
560
614
|
const prevSpectrogramConfigRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
561
615
|
const prevSpectrogramFFTKeyRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
@@ -678,6 +732,13 @@ var SpectrogramProvider = ({
|
|
|
678
732
|
for (const clip of track.clips) {
|
|
679
733
|
if (!clip.audioBuffer) continue;
|
|
680
734
|
const monoFlag = mono || clip.audioBuffer.numberOfChannels === 1;
|
|
735
|
+
const { offsetSamples, durationSamples } = resolveClipRange(
|
|
736
|
+
clip,
|
|
737
|
+
registeredClipRange(
|
|
738
|
+
spectrogramCanvasRegistryRef.current.get(clip.id),
|
|
739
|
+
canvasRangesRef.current
|
|
740
|
+
)
|
|
741
|
+
);
|
|
681
742
|
if (!trackFFTChanged && !hasRegisteredCanvases && renderedClipIdsRef.current.has(clip.id)) {
|
|
682
743
|
const channelDataArrays2 = [];
|
|
683
744
|
for (let ch = 0; ch < clip.audioBuffer.numberOfChannels; ch++) {
|
|
@@ -689,8 +750,8 @@ var SpectrogramProvider = ({
|
|
|
689
750
|
channelDataArrays: channelDataArrays2,
|
|
690
751
|
config: cfg,
|
|
691
752
|
sampleRate: clip.audioBuffer.sampleRate,
|
|
692
|
-
offsetSamples
|
|
693
|
-
durationSamples
|
|
753
|
+
offsetSamples,
|
|
754
|
+
durationSamples,
|
|
694
755
|
clipStartSample: clip.startSample,
|
|
695
756
|
monoFlag,
|
|
696
757
|
colorMap: cm,
|
|
@@ -708,8 +769,8 @@ var SpectrogramProvider = ({
|
|
|
708
769
|
channelDataArrays,
|
|
709
770
|
config: cfg,
|
|
710
771
|
sampleRate: clip.audioBuffer.sampleRate,
|
|
711
|
-
offsetSamples
|
|
712
|
-
durationSamples
|
|
772
|
+
offsetSamples,
|
|
773
|
+
durationSamples,
|
|
713
774
|
clipStartSample: clip.startSample,
|
|
714
775
|
monoFlag,
|
|
715
776
|
colorMap: cm
|
|
@@ -730,6 +791,8 @@ var SpectrogramProvider = ({
|
|
|
730
791
|
if (indices.length === 0) return;
|
|
731
792
|
const canvasIds = indices.map((i) => channelInfo.canvasIds[i]);
|
|
732
793
|
const canvasWidths = indices.map((i) => channelInfo.canvasWidths[i]);
|
|
794
|
+
const canvasHeight = canvasHeightsRef.current.get(canvasIds[0]);
|
|
795
|
+
if (canvasHeight === void 0) return;
|
|
733
796
|
const globalPixelOffsets = [];
|
|
734
797
|
for (const idx of indices) {
|
|
735
798
|
const chunkNumber = extractChunkNumber(channelInfo.canvasIds[idx]);
|
|
@@ -742,7 +805,7 @@ var SpectrogramProvider = ({
|
|
|
742
805
|
canvasIds,
|
|
743
806
|
canvasWidths,
|
|
744
807
|
globalPixelOffsets,
|
|
745
|
-
canvasHeight
|
|
808
|
+
canvasHeight,
|
|
746
809
|
devicePixelRatio: typeof window !== "undefined" ? window.devicePixelRatio : 1,
|
|
747
810
|
samplesPerPixel,
|
|
748
811
|
colorLUT,
|
|
@@ -982,7 +1045,6 @@ var SpectrogramProvider = ({
|
|
|
982
1045
|
spectrogramConfig,
|
|
983
1046
|
spectrogramColorMap,
|
|
984
1047
|
trackSpectrogramOverrides,
|
|
985
|
-
waveHeight,
|
|
986
1048
|
samplesPerPixel,
|
|
987
1049
|
spectrogramCanvasVersion,
|
|
988
1050
|
scrollContainerRef
|
|
@@ -1040,6 +1102,15 @@ var SpectrogramProvider = ({
|
|
|
1040
1102
|
);
|
|
1041
1103
|
return;
|
|
1042
1104
|
}
|
|
1105
|
+
canvasHeightsRef.current.set(reg.canvasId, reg.heightPx);
|
|
1106
|
+
if (reg.offsetSamples !== void 0 || reg.durationSamples !== void 0) {
|
|
1107
|
+
canvasRangesRef.current.set(reg.canvasId, {
|
|
1108
|
+
offsetSamples: reg.offsetSamples,
|
|
1109
|
+
durationSamples: reg.durationSamples
|
|
1110
|
+
});
|
|
1111
|
+
} else {
|
|
1112
|
+
canvasRangesRef.current.delete(reg.canvasId);
|
|
1113
|
+
}
|
|
1043
1114
|
const registry = spectrogramCanvasRegistryRef.current;
|
|
1044
1115
|
if (!registry.has(reg.clipId)) {
|
|
1045
1116
|
registry.set(reg.clipId, /* @__PURE__ */ new Map());
|
|
@@ -1059,6 +1130,8 @@ var SpectrogramProvider = ({
|
|
|
1059
1130
|
[ensureWorkerPool]
|
|
1060
1131
|
);
|
|
1061
1132
|
const unregisterSpectrogramCanvas = (0, import_react2.useCallback)((canvasId) => {
|
|
1133
|
+
canvasHeightsRef.current.delete(canvasId);
|
|
1134
|
+
canvasRangesRef.current.delete(canvasId);
|
|
1062
1135
|
const pool = spectrogramWorkerRef.current;
|
|
1063
1136
|
if (pool) {
|
|
1064
1137
|
try {
|