@dawcore/spectrogram 0.0.2 → 0.0.3
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.d.mts +34 -26
- package/dist/index.d.ts +34 -26
- package/dist/index.js +150 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -34
- package/dist/index.mjs.map +1 -1
- package/dist/orchestrator/index.d.mts +34 -26
- package/dist/orchestrator/index.mjs +150 -34
- package/dist/orchestrator/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -135,10 +135,10 @@ interface CanvasMeta {
|
|
|
135
135
|
widthPx: number;
|
|
136
136
|
}
|
|
137
137
|
interface ViewportBounds {
|
|
138
|
-
visibleStartPx: number;
|
|
139
|
-
visibleEndPx: number;
|
|
140
|
-
bufferStartPx: number;
|
|
141
|
-
bufferEndPx: number;
|
|
138
|
+
readonly visibleStartPx: number;
|
|
139
|
+
readonly visibleEndPx: number;
|
|
140
|
+
readonly bufferStartPx: number;
|
|
141
|
+
readonly bufferEndPx: number;
|
|
142
142
|
}
|
|
143
143
|
interface ClassifiedTiers<T extends CanvasMeta> {
|
|
144
144
|
viewport: T[];
|
|
@@ -148,33 +148,33 @@ interface ClassifiedTiers<T extends CanvasMeta> {
|
|
|
148
148
|
declare function classifyViewport<T extends CanvasMeta>(canvases: T[], bounds: ViewportBounds): ClassifiedTiers<T>;
|
|
149
149
|
|
|
150
150
|
interface SpectrogramOrchestratorOptions {
|
|
151
|
-
workerFactory: () => Worker;
|
|
152
|
-
workerPoolSize?: number;
|
|
153
|
-
config: SpectrogramConfig;
|
|
154
|
-
colorMap?: ColorMapValue;
|
|
155
|
-
devicePixelRatio?: number;
|
|
151
|
+
readonly workerFactory: () => Worker;
|
|
152
|
+
readonly workerPoolSize?: number;
|
|
153
|
+
readonly config: SpectrogramConfig;
|
|
154
|
+
readonly colorMap?: ColorMapValue;
|
|
155
|
+
readonly devicePixelRatio?: number;
|
|
156
156
|
}
|
|
157
157
|
interface ClipRegistration {
|
|
158
|
-
clipId: string;
|
|
159
|
-
trackId: string;
|
|
160
|
-
channelData: Float32Array
|
|
161
|
-
sampleRate: number;
|
|
162
|
-
durationSamples: number;
|
|
163
|
-
offsetSamples: number;
|
|
158
|
+
readonly clipId: string;
|
|
159
|
+
readonly trackId: string;
|
|
160
|
+
readonly channelData: ReadonlyArray<Float32Array>;
|
|
161
|
+
readonly sampleRate: number;
|
|
162
|
+
readonly durationSamples: number;
|
|
163
|
+
readonly offsetSamples: number;
|
|
164
164
|
}
|
|
165
165
|
interface CanvasRegistration {
|
|
166
|
-
canvasId: string;
|
|
167
|
-
canvas: OffscreenCanvas;
|
|
168
|
-
clipId: string;
|
|
169
|
-
trackId: string;
|
|
170
|
-
channelIndex: number;
|
|
171
|
-
chunkIndex: number;
|
|
172
|
-
globalPixelOffset: number;
|
|
173
|
-
widthPx: number;
|
|
174
|
-
heightPx: number;
|
|
166
|
+
readonly canvasId: string;
|
|
167
|
+
readonly canvas: OffscreenCanvas;
|
|
168
|
+
readonly clipId: string;
|
|
169
|
+
readonly trackId: string;
|
|
170
|
+
readonly channelIndex: number;
|
|
171
|
+
readonly chunkIndex: number;
|
|
172
|
+
readonly globalPixelOffset: number;
|
|
173
|
+
readonly widthPx: number;
|
|
174
|
+
readonly heightPx: number;
|
|
175
175
|
}
|
|
176
176
|
interface ViewportState extends ViewportBounds {
|
|
177
|
-
samplesPerPixel: number;
|
|
177
|
+
readonly samplesPerPixel: number;
|
|
178
178
|
}
|
|
179
179
|
interface ClipEntry {
|
|
180
180
|
trackId: string;
|
|
@@ -221,8 +221,16 @@ declare class SpectrogramOrchestrator extends EventTarget {
|
|
|
221
221
|
protected yieldUntilIdle(): Promise<void>;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
/**
|
|
225
|
+
* `viewport-ready` fires at most once per `(generation, trackId)` pair after
|
|
226
|
+
* the viewport-tier FFT completes. Generation bumps (setViewport with a real
|
|
227
|
+
* change, setConfig, setColorMap, setDevicePixelRatio) reset the dispatched-set
|
|
228
|
+
* so the event re-fires on the next render. The `generation` field lets
|
|
229
|
+
* consumers correlate ready events to their own state.
|
|
230
|
+
*/
|
|
224
231
|
interface ViewportReadyDetail {
|
|
225
|
-
trackId: string;
|
|
232
|
+
readonly trackId: string;
|
|
233
|
+
readonly generation: number;
|
|
226
234
|
}
|
|
227
235
|
|
|
228
236
|
interface ChunkLike {
|
package/dist/index.d.ts
CHANGED
|
@@ -135,10 +135,10 @@ interface CanvasMeta {
|
|
|
135
135
|
widthPx: number;
|
|
136
136
|
}
|
|
137
137
|
interface ViewportBounds {
|
|
138
|
-
visibleStartPx: number;
|
|
139
|
-
visibleEndPx: number;
|
|
140
|
-
bufferStartPx: number;
|
|
141
|
-
bufferEndPx: number;
|
|
138
|
+
readonly visibleStartPx: number;
|
|
139
|
+
readonly visibleEndPx: number;
|
|
140
|
+
readonly bufferStartPx: number;
|
|
141
|
+
readonly bufferEndPx: number;
|
|
142
142
|
}
|
|
143
143
|
interface ClassifiedTiers<T extends CanvasMeta> {
|
|
144
144
|
viewport: T[];
|
|
@@ -148,33 +148,33 @@ interface ClassifiedTiers<T extends CanvasMeta> {
|
|
|
148
148
|
declare function classifyViewport<T extends CanvasMeta>(canvases: T[], bounds: ViewportBounds): ClassifiedTiers<T>;
|
|
149
149
|
|
|
150
150
|
interface SpectrogramOrchestratorOptions {
|
|
151
|
-
workerFactory: () => Worker;
|
|
152
|
-
workerPoolSize?: number;
|
|
153
|
-
config: SpectrogramConfig;
|
|
154
|
-
colorMap?: ColorMapValue;
|
|
155
|
-
devicePixelRatio?: number;
|
|
151
|
+
readonly workerFactory: () => Worker;
|
|
152
|
+
readonly workerPoolSize?: number;
|
|
153
|
+
readonly config: SpectrogramConfig;
|
|
154
|
+
readonly colorMap?: ColorMapValue;
|
|
155
|
+
readonly devicePixelRatio?: number;
|
|
156
156
|
}
|
|
157
157
|
interface ClipRegistration {
|
|
158
|
-
clipId: string;
|
|
159
|
-
trackId: string;
|
|
160
|
-
channelData: Float32Array
|
|
161
|
-
sampleRate: number;
|
|
162
|
-
durationSamples: number;
|
|
163
|
-
offsetSamples: number;
|
|
158
|
+
readonly clipId: string;
|
|
159
|
+
readonly trackId: string;
|
|
160
|
+
readonly channelData: ReadonlyArray<Float32Array>;
|
|
161
|
+
readonly sampleRate: number;
|
|
162
|
+
readonly durationSamples: number;
|
|
163
|
+
readonly offsetSamples: number;
|
|
164
164
|
}
|
|
165
165
|
interface CanvasRegistration {
|
|
166
|
-
canvasId: string;
|
|
167
|
-
canvas: OffscreenCanvas;
|
|
168
|
-
clipId: string;
|
|
169
|
-
trackId: string;
|
|
170
|
-
channelIndex: number;
|
|
171
|
-
chunkIndex: number;
|
|
172
|
-
globalPixelOffset: number;
|
|
173
|
-
widthPx: number;
|
|
174
|
-
heightPx: number;
|
|
166
|
+
readonly canvasId: string;
|
|
167
|
+
readonly canvas: OffscreenCanvas;
|
|
168
|
+
readonly clipId: string;
|
|
169
|
+
readonly trackId: string;
|
|
170
|
+
readonly channelIndex: number;
|
|
171
|
+
readonly chunkIndex: number;
|
|
172
|
+
readonly globalPixelOffset: number;
|
|
173
|
+
readonly widthPx: number;
|
|
174
|
+
readonly heightPx: number;
|
|
175
175
|
}
|
|
176
176
|
interface ViewportState extends ViewportBounds {
|
|
177
|
-
samplesPerPixel: number;
|
|
177
|
+
readonly samplesPerPixel: number;
|
|
178
178
|
}
|
|
179
179
|
interface ClipEntry {
|
|
180
180
|
trackId: string;
|
|
@@ -221,8 +221,16 @@ declare class SpectrogramOrchestrator extends EventTarget {
|
|
|
221
221
|
protected yieldUntilIdle(): Promise<void>;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
/**
|
|
225
|
+
* `viewport-ready` fires at most once per `(generation, trackId)` pair after
|
|
226
|
+
* the viewport-tier FFT completes. Generation bumps (setViewport with a real
|
|
227
|
+
* change, setConfig, setColorMap, setDevicePixelRatio) reset the dispatched-set
|
|
228
|
+
* so the event re-fires on the next render. The `generation` field lets
|
|
229
|
+
* consumers correlate ready events to their own state.
|
|
230
|
+
*/
|
|
224
231
|
interface ViewportReadyDetail {
|
|
225
|
-
trackId: string;
|
|
232
|
+
readonly trackId: string;
|
|
233
|
+
readonly generation: number;
|
|
226
234
|
}
|
|
227
235
|
|
|
228
236
|
interface ChunkLike {
|
package/dist/index.js
CHANGED
|
@@ -3473,11 +3473,19 @@ function createSpectrogramWorker(worker) {
|
|
|
3473
3473
|
};
|
|
3474
3474
|
worker.onerror = (e) => {
|
|
3475
3475
|
terminated = true;
|
|
3476
|
-
|
|
3477
|
-
|
|
3476
|
+
console.error(
|
|
3477
|
+
"[dawcore-spectrogram] worker crashed with " + pending.size + " pending operations: " + (e.message || "unknown error")
|
|
3478
|
+
);
|
|
3479
|
+
for (const [id, entry] of pending) {
|
|
3480
|
+
entry.reject(new Error("Worker crashed (id=" + id + "): " + (e.message || "unknown error")));
|
|
3478
3481
|
}
|
|
3479
3482
|
pending.clear();
|
|
3480
3483
|
};
|
|
3484
|
+
worker.onmessageerror = (e) => {
|
|
3485
|
+
console.warn(
|
|
3486
|
+
"[dawcore-spectrogram] worker postMessage clone failure: " + (e.data ? JSON.stringify(e.data) : "no data")
|
|
3487
|
+
);
|
|
3488
|
+
};
|
|
3481
3489
|
return {
|
|
3482
3490
|
computeFFT(params, generation = 0) {
|
|
3483
3491
|
if (terminated) return Promise.reject(new Error("Worker terminated"));
|
|
@@ -3569,28 +3577,45 @@ function createSpectrogramWorker(worker) {
|
|
|
3569
3577
|
// src/worker/createSpectrogramWorkerPool.ts
|
|
3570
3578
|
function parseChannelFromCanvasId(canvasId) {
|
|
3571
3579
|
const match = canvasId.match(/-ch(\d+)-/);
|
|
3572
|
-
|
|
3580
|
+
if (!match) {
|
|
3581
|
+
console.warn(
|
|
3582
|
+
"[dawcore-spectrogram] canvas ID missing -ch{N}- segment, routing to worker 0: " + canvasId
|
|
3583
|
+
);
|
|
3584
|
+
return 0;
|
|
3585
|
+
}
|
|
3586
|
+
return parseInt(match[1], 10);
|
|
3573
3587
|
}
|
|
3574
3588
|
function defaultPoolSize() {
|
|
3575
3589
|
return 2;
|
|
3576
3590
|
}
|
|
3577
3591
|
function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize()) {
|
|
3578
3592
|
const workers = [];
|
|
3593
|
+
let failedAt = -1;
|
|
3579
3594
|
try {
|
|
3580
3595
|
for (let i = 0; i < poolSize; i++) {
|
|
3596
|
+
failedAt = i;
|
|
3581
3597
|
workers.push(createSpectrogramWorker(createWorker()));
|
|
3582
3598
|
}
|
|
3599
|
+
failedAt = -1;
|
|
3583
3600
|
} catch (err) {
|
|
3584
3601
|
for (const w of workers) {
|
|
3585
|
-
|
|
3602
|
+
try {
|
|
3603
|
+
w.terminate();
|
|
3604
|
+
} catch (terminateErr) {
|
|
3605
|
+
console.warn(
|
|
3606
|
+
"[dawcore-spectrogram] pool constructor cleanup: terminate failed for worker \u2014 " + String(terminateErr)
|
|
3607
|
+
);
|
|
3608
|
+
}
|
|
3586
3609
|
}
|
|
3587
|
-
throw
|
|
3610
|
+
throw new Error(
|
|
3611
|
+
"Failed to create spectrogram worker pool (size=" + poolSize + ") at worker " + failedAt + ": " + (err instanceof Error ? err.message : String(err))
|
|
3612
|
+
);
|
|
3588
3613
|
}
|
|
3589
3614
|
function getWorkerForChannel(channelIndex) {
|
|
3590
3615
|
return workers[channelIndex % workers.length];
|
|
3591
3616
|
}
|
|
3592
3617
|
return {
|
|
3593
|
-
computeFFT(params, generation = 0) {
|
|
3618
|
+
async computeFFT(params, generation = 0) {
|
|
3594
3619
|
if (params.mono) {
|
|
3595
3620
|
return workers[0].computeFFT(params, generation);
|
|
3596
3621
|
}
|
|
@@ -3599,7 +3624,17 @@ function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize())
|
|
|
3599
3624
|
const promises = activeWorkers.map(
|
|
3600
3625
|
(w, i) => w.computeFFT({ ...params, channelFilter: i }, generation)
|
|
3601
3626
|
);
|
|
3602
|
-
|
|
3627
|
+
const settled = await Promise.allSettled(promises);
|
|
3628
|
+
const failures = settled.filter((s) => s.status === "rejected");
|
|
3629
|
+
if (failures.length > 0) {
|
|
3630
|
+
for (let i = 1; i < failures.length; i++) {
|
|
3631
|
+
console.warn(
|
|
3632
|
+
"[dawcore-spectrogram] additional channel FFT failure (" + i + "): " + (failures[i].reason instanceof Error ? failures[i].reason.message : String(failures[i].reason))
|
|
3633
|
+
);
|
|
3634
|
+
}
|
|
3635
|
+
throw failures[0].reason;
|
|
3636
|
+
}
|
|
3637
|
+
return settled[0].value;
|
|
3603
3638
|
},
|
|
3604
3639
|
renderChunks(params, generation = 0) {
|
|
3605
3640
|
const worker = getWorkerForChannel(params.channelIndex);
|
|
@@ -3636,6 +3671,9 @@ function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize())
|
|
|
3636
3671
|
};
|
|
3637
3672
|
}
|
|
3638
3673
|
|
|
3674
|
+
// src/orchestrator/SpectrogramOrchestrator.ts
|
|
3675
|
+
var import_core = require("@waveform-playlist/core");
|
|
3676
|
+
|
|
3639
3677
|
// src/orchestrator/color-lut-cache.ts
|
|
3640
3678
|
var ColorLUTCache = class {
|
|
3641
3679
|
constructor() {
|
|
@@ -3712,36 +3750,55 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3712
3750
|
this.disposed = false;
|
|
3713
3751
|
this.renderInFlight = false;
|
|
3714
3752
|
// Tracks which trackIds have already emitted `viewport-ready` for the
|
|
3715
|
-
// current generation. Cleared on every generation bump (setViewport
|
|
3716
|
-
// setConfig
|
|
3717
|
-
//
|
|
3718
|
-
// loading — would re-fire the
|
|
3753
|
+
// current generation. Cleared on every generation bump (setViewport with a
|
|
3754
|
+
// real change, setConfig, setColorMap, setDevicePixelRatio) AND in dispose().
|
|
3755
|
+
// Without this, every render — including those triggered by late
|
|
3756
|
+
// `registerCanvas` calls during track-by-track loading — would re-fire the
|
|
3757
|
+
// event for every track in the canvas map (N×N-ish ascending fan-in:
|
|
3758
|
+
// 3 tracks → 4+3+2+1 = 10 events; the dedup reduces this to 3).
|
|
3719
3759
|
this.readyDispatched = /* @__PURE__ */ new Set();
|
|
3720
3760
|
const poolSize = opts.workerPoolSize ?? 2;
|
|
3721
3761
|
this.pool = createSpectrogramWorkerPool(opts.workerFactory, poolSize);
|
|
3722
3762
|
this.config = opts.config;
|
|
3723
|
-
this.colorMap = opts.colorMap ??
|
|
3763
|
+
this.colorMap = opts.colorMap ?? import_core.DEFAULT_SPECTROGRAM_COLOR_MAP;
|
|
3724
3764
|
this.devicePixelRatio = opts.devicePixelRatio ?? (typeof window !== "undefined" ? window.devicePixelRatio : 1);
|
|
3725
3765
|
}
|
|
3726
3766
|
registerClip(reg) {
|
|
3727
3767
|
if (this.disposed) return;
|
|
3768
|
+
const channelData = [...reg.channelData];
|
|
3728
3769
|
this.clips.set(reg.clipId, {
|
|
3729
3770
|
trackId: reg.trackId,
|
|
3730
|
-
channelData
|
|
3771
|
+
channelData,
|
|
3731
3772
|
sampleRate: reg.sampleRate,
|
|
3732
3773
|
durationSamples: reg.durationSamples,
|
|
3733
3774
|
offsetSamples: reg.offsetSamples
|
|
3734
3775
|
});
|
|
3735
|
-
this.pool.registerAudioData(reg.clipId,
|
|
3776
|
+
this.pool.registerAudioData(reg.clipId, channelData, reg.sampleRate);
|
|
3777
|
+
if (this.viewport) {
|
|
3778
|
+
for (const canvas of this.canvases.values()) {
|
|
3779
|
+
if (canvas.clipId === reg.clipId) {
|
|
3780
|
+
this.scheduleRender();
|
|
3781
|
+
break;
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
3736
3785
|
}
|
|
3737
3786
|
unregisterClip(clipId) {
|
|
3738
3787
|
if (this.disposed) return;
|
|
3739
|
-
if (!this.clips.has(clipId))
|
|
3788
|
+
if (!this.clips.has(clipId)) {
|
|
3789
|
+
console.warn("[dawcore-spectrogram] unregisterClip: unknown clip " + clipId);
|
|
3790
|
+
return;
|
|
3791
|
+
}
|
|
3740
3792
|
this.clips.delete(clipId);
|
|
3741
3793
|
this.pool.unregisterAudioData(clipId);
|
|
3742
3794
|
}
|
|
3743
3795
|
registerCanvas(reg) {
|
|
3744
|
-
if (this.disposed)
|
|
3796
|
+
if (this.disposed) {
|
|
3797
|
+
console.warn(
|
|
3798
|
+
"[dawcore-spectrogram] registerCanvas after dispose \u2014 canvas " + reg.canvasId + " will not render (OffscreenCanvas is now dead)"
|
|
3799
|
+
);
|
|
3800
|
+
return;
|
|
3801
|
+
}
|
|
3745
3802
|
this.canvases.set(reg.canvasId, {
|
|
3746
3803
|
canvasId: reg.canvasId,
|
|
3747
3804
|
globalPixelOffset: reg.globalPixelOffset,
|
|
@@ -3757,12 +3814,21 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3757
3814
|
}
|
|
3758
3815
|
unregisterCanvas(canvasId) {
|
|
3759
3816
|
if (this.disposed) return;
|
|
3760
|
-
if (!this.canvases.has(canvasId))
|
|
3817
|
+
if (!this.canvases.has(canvasId)) {
|
|
3818
|
+
console.warn("[dawcore-spectrogram] unregisterCanvas: unknown canvas " + canvasId);
|
|
3819
|
+
return;
|
|
3820
|
+
}
|
|
3761
3821
|
this.canvases.delete(canvasId);
|
|
3762
3822
|
this.pool.unregisterCanvas(canvasId);
|
|
3763
3823
|
}
|
|
3764
3824
|
setViewport(state) {
|
|
3765
3825
|
if (this.disposed) return;
|
|
3826
|
+
if (!Number.isFinite(state.visibleStartPx) || !Number.isFinite(state.visibleEndPx) || !Number.isFinite(state.bufferStartPx) || !Number.isFinite(state.bufferEndPx) || !Number.isFinite(state.samplesPerPixel) || state.samplesPerPixel <= 0 || state.visibleStartPx > state.visibleEndPx || state.bufferStartPx > state.bufferEndPx) {
|
|
3827
|
+
console.warn(
|
|
3828
|
+
"[dawcore-spectrogram] setViewport: invalid state \u2014 ignored (" + JSON.stringify(state) + ")"
|
|
3829
|
+
);
|
|
3830
|
+
return;
|
|
3831
|
+
}
|
|
3766
3832
|
if (this.viewport && viewportsEqual(this.viewport, state)) return;
|
|
3767
3833
|
const prevGeneration = this.generation;
|
|
3768
3834
|
this.generation += 1;
|
|
@@ -3791,7 +3857,20 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3791
3857
|
this.scheduleRender();
|
|
3792
3858
|
}
|
|
3793
3859
|
setDevicePixelRatio(dpr) {
|
|
3860
|
+
if (this.disposed) return;
|
|
3861
|
+
if (!Number.isFinite(dpr) || dpr <= 0) {
|
|
3862
|
+
console.warn(
|
|
3863
|
+
"[dawcore-spectrogram] setDevicePixelRatio: invalid value " + dpr + " \u2014 ignored"
|
|
3864
|
+
);
|
|
3865
|
+
return;
|
|
3866
|
+
}
|
|
3867
|
+
if (this.devicePixelRatio === dpr) return;
|
|
3794
3868
|
this.devicePixelRatio = dpr;
|
|
3869
|
+
const prevGeneration = this.generation;
|
|
3870
|
+
this.generation += 1;
|
|
3871
|
+
this.readyDispatched.clear();
|
|
3872
|
+
this.pool.abortGeneration(prevGeneration);
|
|
3873
|
+
this.scheduleRender();
|
|
3795
3874
|
}
|
|
3796
3875
|
dispose() {
|
|
3797
3876
|
if (this.disposed) return;
|
|
@@ -3809,7 +3888,12 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3809
3888
|
this.renderInFlight = true;
|
|
3810
3889
|
queueMicrotask(() => {
|
|
3811
3890
|
this.renderInFlight = false;
|
|
3812
|
-
|
|
3891
|
+
this.runRender(this.generation).catch((err) => {
|
|
3892
|
+
if (err instanceof SpectrogramAbortError) return;
|
|
3893
|
+
console.warn(
|
|
3894
|
+
"[dawcore-spectrogram] runRender unhandled rejection (generation " + this.generation + "): " + (err instanceof Error ? err.message : String(err))
|
|
3895
|
+
);
|
|
3896
|
+
});
|
|
3813
3897
|
});
|
|
3814
3898
|
}
|
|
3815
3899
|
async runRender(generation) {
|
|
@@ -3823,16 +3907,34 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3823
3907
|
canvasesByTrack.set(c.trackId, list);
|
|
3824
3908
|
}
|
|
3825
3909
|
for (const [trackId, trackCanvases] of canvasesByTrack) {
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
this.readyDispatched.
|
|
3831
|
-
|
|
3910
|
+
try {
|
|
3911
|
+
const tiers = classifyViewport(trackCanvases, viewport);
|
|
3912
|
+
await this.renderTier(tiers.viewport, generation, viewport);
|
|
3913
|
+
if (this.generation !== generation || this.disposed) return;
|
|
3914
|
+
if (!this.readyDispatched.has(trackId)) {
|
|
3915
|
+
this.readyDispatched.add(trackId);
|
|
3916
|
+
this.dispatchEvent(
|
|
3917
|
+
new CustomEvent("viewport-ready", { detail: { trackId, generation } })
|
|
3918
|
+
);
|
|
3919
|
+
}
|
|
3920
|
+
await this.renderTier(tiers.buffer, generation, viewport);
|
|
3921
|
+
if (this.generation !== generation || this.disposed) return;
|
|
3922
|
+
await this.renderRemainingViaIdle(tiers.remaining, generation, viewport);
|
|
3923
|
+
} catch (err) {
|
|
3924
|
+
if (this.generation !== generation || this.disposed) return;
|
|
3925
|
+
if (err instanceof SpectrogramAbortError) {
|
|
3926
|
+
return;
|
|
3927
|
+
}
|
|
3928
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
3929
|
+
console.warn(
|
|
3930
|
+
"[dawcore-spectrogram] render failed for track " + trackId + " (generation " + generation + "): " + error.message
|
|
3931
|
+
);
|
|
3932
|
+
this.dispatchEvent(
|
|
3933
|
+
new CustomEvent("viewport-error", {
|
|
3934
|
+
detail: { trackId, generation, error }
|
|
3935
|
+
})
|
|
3936
|
+
);
|
|
3832
3937
|
}
|
|
3833
|
-
await this.renderTier(tiers.buffer, generation, viewport);
|
|
3834
|
-
if (this.generation !== generation || this.disposed) return;
|
|
3835
|
-
await this.renderRemainingViaIdle(tiers.remaining, generation, viewport);
|
|
3836
3938
|
}
|
|
3837
3939
|
}
|
|
3838
3940
|
async renderTier(canvases, generation, viewport) {
|
|
@@ -3847,8 +3949,13 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3847
3949
|
if (group.length === 0) return;
|
|
3848
3950
|
const first = group[0];
|
|
3849
3951
|
const clip = this.clips.get(first.clipId);
|
|
3850
|
-
if (!clip)
|
|
3851
|
-
|
|
3952
|
+
if (!clip) {
|
|
3953
|
+
console.warn(
|
|
3954
|
+
"[dawcore-spectrogram] renderGroup: no clip audio for " + first.clipId + " (canvas " + first.canvasId + ") \u2014 canvas will stay black until registerClip is called"
|
|
3955
|
+
);
|
|
3956
|
+
return;
|
|
3957
|
+
}
|
|
3958
|
+
const fftSize = this.config.fftSize ?? import_core.SPECTROGRAM_DEFAULTS.fftSize;
|
|
3852
3959
|
const startPx = Math.min(...group.map((c) => c.globalPixelOffset));
|
|
3853
3960
|
const endPx = Math.max(...group.map((c) => c.globalPixelOffset + c.widthPx));
|
|
3854
3961
|
const startSample = clip.offsetSamples + Math.floor(startPx * viewport.samplesPerPixel);
|
|
@@ -3883,11 +3990,11 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3883
3990
|
devicePixelRatio: this.devicePixelRatio,
|
|
3884
3991
|
samplesPerPixel: viewport.samplesPerPixel,
|
|
3885
3992
|
colorLUT,
|
|
3886
|
-
frequencyScale: String(this.config.frequencyScale ??
|
|
3887
|
-
minFrequency: this.config.minFrequency ??
|
|
3993
|
+
frequencyScale: String(this.config.frequencyScale ?? import_core.SPECTROGRAM_DEFAULTS.frequencyScale),
|
|
3994
|
+
minFrequency: this.config.minFrequency ?? import_core.SPECTROGRAM_DEFAULTS.minFrequency,
|
|
3888
3995
|
maxFrequency: this.config.maxFrequency ?? clip.sampleRate / 2,
|
|
3889
|
-
gainDb: this.config.gainDb ??
|
|
3890
|
-
rangeDb: this.config.rangeDb ??
|
|
3996
|
+
gainDb: this.config.gainDb ?? import_core.SPECTROGRAM_DEFAULTS.gainDb,
|
|
3997
|
+
rangeDb: this.config.rangeDb ?? import_core.SPECTROGRAM_DEFAULTS.rangeDb,
|
|
3891
3998
|
channelIndex: first.channelIndex
|
|
3892
3999
|
},
|
|
3893
4000
|
generation
|
|
@@ -3900,7 +4007,16 @@ var SpectrogramOrchestrator = class extends EventTarget {
|
|
|
3900
4007
|
if (this.generation !== generation || this.disposed) return;
|
|
3901
4008
|
await this.yieldUntilIdle();
|
|
3902
4009
|
if (this.generation !== generation || this.disposed) return;
|
|
3903
|
-
|
|
4010
|
+
try {
|
|
4011
|
+
await this.renderGroup(group, generation, viewport);
|
|
4012
|
+
} catch (err) {
|
|
4013
|
+
if (this.generation !== generation || this.disposed) return;
|
|
4014
|
+
if (err instanceof SpectrogramAbortError) return;
|
|
4015
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
4016
|
+
console.warn(
|
|
4017
|
+
"[dawcore-spectrogram] remaining-tier render failed for canvas group: " + error.message
|
|
4018
|
+
);
|
|
4019
|
+
}
|
|
3904
4020
|
}
|
|
3905
4021
|
}
|
|
3906
4022
|
yieldUntilIdle() {
|