Skip to content

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

fix: snap code sections to aligned lyric words (#9076)

[._.]/ Adam Eivydb1ae1b2c196
diff --git a/server/services/musicVideo/codeTimeline.js b/server/services/musicVideo/codeTimeline.js
index c4d49b0141..ef5f0f035b 100644
--- a/server/services/musicVideo/codeTimeline.js
+++ b/server/services/musicVideo/codeTimeline.js
@@ -6,8 +6,8 @@
* starts at song time 0 — the same timebase as a footage render. Each later
* boundary snaps to the beat at or before the first word of that section's
* first lyric line, or to the nearest downbeat when the section has no lyric.
- * Word timings are used when a line carries them; otherwise the line start is
- * the only cue (#9074 may add words later).
+ * Word timings are used when a line carries them (`w` from alignment, or
+ * `text` on an already-normalized cue); otherwise the line start is the only cue.
*/
import { CODE_FPS } from './codeFrame.js';
@@ -101,15 +101,21 @@ function lyricLines(project) {
.sort((a, b) => a.startSec - b.startSec);
}
+function wordLabel(word) {
+ if (typeof word?.text === 'string' && word.text.trim()) return word.text.trim();
+ if (typeof word?.w === 'string' && word.w.trim()) return word.w.trim();
+ return null;
+}
+
function wordsOf(line) {
- const words = Array.isArray(line.words) ? line.words.filter((word) => word && typeof word.text === 'string' && word.text.trim() && finite(word.startSec) != null) : [];
- if (words.length) {
- return words.map((word) => ({
- text: word.text.trim(),
- startSec: word.startSec,
- endSec: finite(word.endSec) != null && word.endSec > word.startSec ? word.endSec : null,
- }));
- }
+ const words = Array.isArray(line.words) ? line.words.flatMap((word) => {
+ const text = wordLabel(word);
+ const startSec = finite(word?.startSec);
+ if (!text || startSec == null) return [];
+ const endSec = finite(word.endSec) != null && word.endSec > startSec ? word.endSec : null;
+ return [{ text, startSec, endSec }];
+ }) : [];
+ if (words.length) return words;
const startSec = line.startSec;
const endSec = finite(line.endSec) != null && line.endSec > startSec ? line.endSec : null;
return [{ text: line.text, startSec, endSec }];
diff --git a/server/services/musicVideo/codeTimeline.test.js b/server/services/musicVideo/codeTimeline.test.js
index 0a803e5a27..a198befb5b 100644
--- a/server/services/musicVideo/codeTimeline.test.js
+++ b/server/services/musicVideo/codeTimeline.test.js
@@ -46,6 +46,32 @@ describe('buildCodeTimeline (#9076)', () => {
]);
});
+ it('snaps to the aligned word, which is stored as w', () => {
+ const aligned = {
+ ...project,
+ audioAnalysis: {
+ ...project.audioAnalysis,
+ sections: [
+ { label: 'Verse', startSec: 0, endSec: 1.2 },
+ { label: 'Chorus', startSec: 1.2, endSec: 4 },
+ ],
+ },
+ lyricCues: [{
+ id: 'l2', text: 'second line', startSec: 1.25, endSec: 3.2,
+ words: [
+ { w: 'second', startSec: 1.8, endSec: 2.1, conf: 'matched' },
+ { w: 'line', startSec: 2.2, endSec: 2.8, conf: 'matched' },
+ ],
+ }],
+ };
+ const timeline = buildCodeTimeline(aligned);
+ // The line starts at 1.25 (beat 1). The first sung word is at 1.8, so the
+ // cut is the beat at or before that word.
+ expect(timeline.sections[1].startSec).toBe(1.5);
+ const song = buildSongDocument(aligned, timeline);
+ expect(song.lyrics[0].words.map((word) => word.text)).toEqual(['second', 'line']);
+ });
+
it('uses the nearest downbeat when a section has no lyric', () => {
const instrumental = {
...project,