Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: finish lyric fades before the next caption (#10682)
Adam Eivyd058b50ffa3c
diff --git a/server/services/musicVideo/documentTemplates/shared/lyricType.js b/server/services/musicVideo/documentTemplates/shared/lyricType.jsindex 6246691967..86dc24c32d 100644--- a/server/services/musicVideo/documentTemplates/shared/lyricType.js+++ b/server/services/musicVideo/documentTemplates/shared/lyricType.js@@ -147,9 +147,10 @@ function wordsForLine(line, songWords = []) {/*** When a line leaves the screen. A line never shows before its first onset and- * stays at least LYRIC_TIMING.minOnScreenSec. `line`/`stamp`/`data` start exiting- * 0.3s after the last word ends (capped at the next line's onset); a `hook`- * exits on the first beat at or after its last word, with no fade.+ * stays at least LYRIC_TIMING.minOnScreenSec unless another cue takes its zone.+ * `line`/`data` fade 0.3s after the last word ends, finishing by the next cue in+ * their zone (or cutting at its onset when a full fade cannot fit). A `stamp`+ * cuts after its hold; a `hook` cuts on the next beat, with no fade.*/function lineWindow(words, role, { beats = [], nextOnset = null, fps = 24, endSec = null } = {}) {const T = LYRIC_TIMING;@@ -168,6 +169,12 @@ function lineWindow(words, role, { beats = [], nextOnset = null, fps = 24, endSeif (finite(nextOnset) && nextOnset < exitSec) exitSec = nextOnset;exitSec = Math.max(exitSec, minExit);const fade = role === 'stamp' ? 0 : T.lineExitFrames / fps;+ if (role !== 'stamp' && finite(nextOnset)) {+ // Zone turnover outranks the minimum hold: never crossfade two captions.+ if (nextOnset - fade < minExit) return { startSec: onset, exitSec: nextOnset, endSec: nextOnset };+ exitSec = Math.min(exitSec, nextOnset - fade);+ return { startSec: onset, exitSec, endSec: Math.min(exitSec + fade, nextOnset) };+ }return { startSec: onset, exitSec, endSec: exitSec + fade };}@@ -268,7 +275,8 @@ export function createLyricType(mv = globalThis.PORTOS_MV, options = {}) {if (!line.role && !options.overrides?.[line.id] && !options.overrides?.[index] && LYRIC_ROLES.includes(sectionRoles[kind])) role = sectionRoles[kind];const shot = sceneAt(words[0].startSec);if (!line.role && !options.overrides?.[line.id] && !options.overrides?.[index] && LYRIC_ROLES.includes(shot?.lyricRole)) role = shot.lyricRole;- return { index, id: line.id ?? null, text: String(line.text).trim(), role, words, zone: line.zone || null, strike: !!line.strike, endSec: line.endSec, shot };+ const zone = line.zone || shot?.textZone || (role === 'hook' ? 'center' : options.defaultZone || 'lower-left');+ return { index, id: line.id ?? null, text: String(line.text).trim(), role, words, zone: TEXT_ZONES.includes(zone) ? zone : 'lower-left', strike: !!line.strike, endSec: line.endSec, shot };}).filter(Boolean).sort((a, b) => a.words[0].startSec - b.words[0].startSec);// At most one data caption per shot: later ones in the same shot fall back to `line`.@@ -279,10 +287,11 @@ export function createLyricType(mv = globalThis.PORTOS_MV, options = {}) {if (dataShots.has(key)) line.role = 'line'; else dataShots.add(key);}const lines = timed.map((line, i) => {- const next = timed.slice(i + 1).find((other) => other.role === line.role);+ const next = timed.slice(i + 1).find((other) => line.role === 'line' || line.role === 'data'+ ? other.zone === line.zone+ : other.role === line.role);const window = lineWindow(line.words, line.role, { beats, nextOnset: next?.words[0].startSec ?? null, fps, endSec: line.role === 'hook' ? line.endSec : null });- const zone = line.zone || line.shot?.textZone || (line.role === 'hook' ? 'center' : options.defaultZone || 'lower-left');- return { ...line, ...window, zone: TEXT_ZONES.includes(zone) ? zone : 'lower-left', accent: line.role === 'hook' ? accentIndexOf(line.words) : -1 };+ return { ...line, ...window, accent: line.role === 'hook' ? accentIndexOf(line.words) : -1 };});const exclusive = options.exclusive !== false;diff --git a/server/services/musicVideo/documentTemplates/shared/lyricType.test.js b/server/services/musicVideo/documentTemplates/shared/lyricType.test.jsindex 6542e54bdf..2cf961233c 100644--- a/server/services/musicVideo/documentTemplates/shared/lyricType.test.js+++ b/server/services/musicVideo/documentTemplates/shared/lyricType.test.js@@ -76,6 +76,52 @@ describe('lyricType timing', () => {const quick = createLyricType({ ...MV, lyricMarkers: [], lyrics: [{ text: 'no', startSec: 2, endSec: 2.1, words: [{ text: 'no', startSec: 2, endSec: 2.1 }] }] });expect(quick.lines[0].exitSec).toBeCloseTo(2.8, 6);});++ it.each([+ { role: 'line', nextRole: 'line', gap: 0.1, cut: true },+ { role: 'line', nextRole: 'data', gap: 1, cut: true },+ { role: 'data', nextRole: 'line', gap: 1.2, cut: false },+ ])('never overlaps a $role cue with the next $nextRole cue in its zone (gap $gap)', ({ role, nextRole, gap, cut }) => {+ const onset = 2;+ const nextOnset = onset + gap;+ const type = createLyricType({ render: { fps: 24 } }, { lines: [+ { text: 'Example first', role, zone: 'lower-left', words: words('Example first', onset, 0.4) },+ { text: 'Example next', role: nextRole, zone: 'lower-left', words: words('Example next', nextOnset, 0.02) },+ ] });+ const [first, next] = type.lines;+ expect(first.endSec).toBeLessThanOrEqual(nextOnset);+ if (cut) expect(first.exitSec).toBe(nextOnset);+ else {+ expect(first.endSec).toBe(nextOnset);+ expect(first.endSec - first.exitSec).toBeCloseTo(8 / 24, 6);+ }+ for (let frame = onset * 24; frame <= (nextOnset + 1) * 24; frame++) {+ expect(type.linesAt(frame / 24).length).toBeLessThanOrEqual(1);+ }+ expect(type.linesAt(nextOnset)).toEqual([next]);+ });++ it('keeps cues in different zones independent', () => {+ const type = createLyricType({}, { lines: [+ { text: 'Example first', role: 'line', zone: 'upper-right', words: words('Example first', 2, 0.02) },+ { text: 'Example next', role: 'line', zone: 'lower-left', words: words('Example next', 2.1, 0.02) },+ ] });+ expect(type.linesAt(2.3)).toEqual(type.lines);+ expect(type.lines[0].exitSec).toBeCloseTo(2.8, 6);+ expect(type.lines[0].endSec - type.lines[0].exitSec).toBeCloseTo(8 / 24, 6);+ });++ it('preserves hook beat cuts and stamp minimum holds for crowded cues', () => {+ const type = createLyricType({ song: { beats: [3, 4] } }, { exclusive: false, lines: [+ { text: 'Example hook', role: 'hook', words: words('Example hook', 2, 0.02) },+ { text: 'Example hook next', role: 'hook', words: words('Example hook next', 2.1, 0.02) },+ { text: 'Example stamp', role: 'stamp', words: words('Example stamp', 5, 0.02) },+ { text: 'Example stamp next', role: 'stamp', words: words('Example stamp next', 5.1, 0.02) },+ ] });+ expect(type.lines[0]).toMatchObject({ exitSec: 3, endSec: 3 });+ expect(type.lines[2].exitSec).toBeCloseTo(5.8, 6);+ expect(type.lines[2].endSec).toBe(type.lines[2].exitSec);+ });});describe('lyricType text zones', () => {