Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/lint/src/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,28 @@ describe("audio-aware project rules", () => {
expect(codes).not.toContain("duplicate_audio_track");
});

it("names the clip without data-duration in the fix hint when it is counted to the end", async () => {
const line = (id: string, start: number) =>
`<audio id="${id}" src="${id}.wav" data-start="${start}" data-track-index="2"></audio>`;
const project = makeProject(composition(line("vo1", 0) + line("vo2", 4)));
const { results } = await lintProject(project);
const finding = results
.flatMap((result) => result.result.findings)
.find((f) => f.code === "duplicate_audio_track");
expect(finding?.fixHint).toContain("vo1.wav and vo2.wav have no data-duration");
});

it("keeps the plain fix hint when both overlapping clips set data-duration", async () => {
const project = makeProject(
composition(video('data-has-audio="true"', 0) + video('data-has-audio="true"', 2)),
);
const { results } = await lintProject(project);
const finding = results
.flatMap((result) => result.result.findings)
.find((f) => f.code === "duplicate_audio_track");
expect(finding?.fixHint).toBe("Use non-overlapping time windows or different track indices.");
});

it("stays quiet for back-to-back clips whose start plus duration only rounds past the next start", async () => {
// 21.03 + 0.1 is 21.130000000000003 in floating point.
const clip = (id: string, start: string, duration: string) =>
Expand Down
16 changes: 14 additions & 2 deletions packages/lint/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ interface AudioSpan {
start: number;
end: number;
src: string;
runsToWindowEnd: boolean;
}

/** One parsed file: reference starts resolve within it, memoised. */
Expand Down Expand Up @@ -893,7 +894,12 @@ function audioSpanOf(
const duration = parseNumeric(el.getAttribute("data-duration")) ?? localDuration(file, el);
const kept = cutToHostSlots({ start, end: start + (duration ?? Infinity) }, slots);
if (kept.end <= kept.start) return null;
return { trackIndex: parseInt(trackStr, 10), ...kept, src: el.getAttribute("src") || "unknown" };
return {
trackIndex: parseInt(trackStr, 10),
...kept,
src: el.getAttribute("src") || "unknown",
runsToWindowEnd: duration === null,
};
}

const formatSeconds = (t: number) => (Number.isFinite(t) ? String(Number(t.toFixed(2))) : "end");
Expand All @@ -907,11 +913,17 @@ function lintDuplicateAudioTracks(projectDir: string, rootHtml: string): Hyperfr
const b = tracks[j]!;
if (a.trackIndex !== b.trackIndex) continue;
if (spansOverlap(a.start, a.end, b.start, b.end)) {
const withoutDuration = [a, b]
.filter((span) => span.runsToWindowEnd)
.map((span) => span.src);
findings.push({
code: "duplicate_audio_track",
severity: "warning",
message: `Multiple audible <audio>/<video> elements on track ${a.trackIndex} overlap (${a.src} at ${formatSeconds(a.start)}-${formatSeconds(a.end)}s, ${b.src} at ${formatSeconds(b.start)}-${formatSeconds(b.end)}s). This causes layered audio playback.`,
fixHint: "Use non-overlapping time windows or different track indices.",
fixHint:
withoutDuration.length > 0
? `${withoutDuration.join(" and ")} ${withoutDuration.length > 1 ? "have no data-duration, so lint counts them" : "has no data-duration, so lint counts it"} until the composition ends. Set data-duration to the file's length, or use different track indices.`
: "Use non-overlapping time windows or different track indices.",
});
}
}
Expand Down
Loading