perf: tighten director tag and segment helpers
This commit is contained in:
@@ -53,7 +53,15 @@ function stripAudioSegmentTransient(s) {
|
||||
}
|
||||
|
||||
function dedupeById(items = []) {
|
||||
return items.filter((seg, index, self) => index === self.findIndex((s) => s.id === seg.id));
|
||||
const seen = new Set();
|
||||
const deduped = [];
|
||||
for (const seg of items || []) {
|
||||
const id = seg?.id;
|
||||
if (!id || seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
deduped.push(seg);
|
||||
}
|
||||
return deduped;
|
||||
}
|
||||
|
||||
function findActiveSegmentAtFrame(segments = [], targetFrame, type) {
|
||||
@@ -61,6 +69,10 @@ function findActiveSegmentAtFrame(segments = [], targetFrame, type) {
|
||||
(seg) => seg?.type === type && targetFrame >= seg.start && targetFrame < seg.start + seg.length
|
||||
);
|
||||
}
|
||||
|
||||
function segmentMatchesAudioSource(seg, audioFile, blobUrl) {
|
||||
return !!seg && (seg.audioFile === audioFile || seg._blobUrl === blobUrl);
|
||||
}
|
||||
|
||||
function hideWidget(w) {
|
||||
if (!w) return;
|
||||
@@ -2004,6 +2016,14 @@ class TimelineEditor {
|
||||
return found;
|
||||
}
|
||||
|
||||
_forEachMatchingAudioSegment(audioFile, blobUrl, visitor) {
|
||||
for (const seg of this.timeline.audioSegments || []) {
|
||||
if (segmentMatchesAudioSource(seg, audioFile, blobUrl)) {
|
||||
visitor(seg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_getSegmentsByFileKey(fileKey) {
|
||||
const matches = [];
|
||||
this._forEachMatchingSegment(fileKey, (seg) => {
|
||||
@@ -2231,11 +2251,10 @@ class TimelineEditor {
|
||||
|
||||
const audioBuffer = await this._loadAudioBuffer(seg);
|
||||
|
||||
const matchingSegs = this.timeline.audioSegments.filter(s => s.audioFile === seg.audioFile || s._blobUrl === seg._blobUrl);
|
||||
for (const s of matchingSegs) {
|
||||
s._audioBuffer = audioBuffer;
|
||||
s._decoding = false;
|
||||
}
|
||||
this._forEachMatchingAudioSegment(seg.audioFile, seg._blobUrl, (s) => {
|
||||
s._audioBuffer = audioBuffer;
|
||||
s._decoding = false;
|
||||
});
|
||||
} catch (err) {
|
||||
console.warn("Failed to preload audio segment:", err);
|
||||
seg._decoding = false;
|
||||
|
||||
Reference in New Issue
Block a user