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: preserve planned music-video timing when sparse beats cannot align cuts
[._.]/ Adam Eivy255aa7fc240b
diff --git a/server/services/musicVideo/projectsLogic.js b/server/services/musicVideo/projectsLogic.jsindex d3fc31b682..fb54a4e800 100644--- a/server/services/musicVideo/projectsLogic.js+++ b/server/services/musicVideo/projectsLogic.js@@ -287,7 +287,10 @@ export function applyProjectPatch(project, patch) {const trackChanged = ('trackId' in patch && patch.trackId !== project.trackId)|| ('uploadedAudioFilename' in patch && patch.uploadedAudioFilename !== project.uploadedAudioFilename);if (!trackChanged) return touch(project, mergedPatch);- const scenes = (project.scenes || []).map((s) => (s.beatAligned ? { ...s, beatAligned: false } : s));+ // A planned section belongs to the old audio too; clear its provenance so+ // the renderer does not preserve that plan's timing on the replacement song.+ const scenes = (project.scenes || []).map((s) => (s.beatAligned || s.sectionIndex != null+ ? { ...s, beatAligned: false, sectionIndex: null } : s));// Clearing audioAnalysis means the project must be re-analyzed before it can be// planned/arranged/rendered, so a status that implies analysis existed// (`analyzed`/`ready`/`rendering`/`complete`) is now stale. Regress it to `draft` —diff --git a/server/services/musicVideo/projectsLogic.test.js b/server/services/musicVideo/projectsLogic.test.jsindex ca361bf8f3..48562fbcbf 100644--- a/server/services/musicVideo/projectsLogic.test.js+++ b/server/services/musicVideo/projectsLogic.test.js@@ -216,12 +216,12 @@ describe('applyProjectPatch', () => {trackId: 't1',scenes: [{ sceneId: 's1', order: 0, startSec: 1, endSec: 2, beatAligned: true },- { sceneId: 's2', order: 1, startSec: 3, endSec: 4, beatAligned: false },+ { sceneId: 's2', order: 1, startSec: 3, endSec: 4, beatAligned: false, sectionIndex: 0 },],};const next = applyProjectPatch(withScenes, { trackId: 't2' });expect(next.scenes[0]).toMatchObject({ beatAligned: false, startSec: 1, endSec: 2 });- expect(next.scenes[1]).toMatchObject({ beatAligned: false, startSec: 3, endSec: 4 });+ expect(next.scenes[1]).toMatchObject({ beatAligned: false, sectionIndex: null, startSec: 3, endSec: 4 });});it('regresses status to draft on track change since the cleared analysis must be redone', () => {diff --git a/server/services/musicVideo/render.js b/server/services/musicVideo/render.jsindex 93e14ba1a9..d732639bc7 100644--- a/server/services/musicVideo/render.js+++ b/server/services/musicVideo/render.js@@ -282,7 +282,8 @@ export async function resolveSceneClips(project, { layered = false } = {}) {// returned unchanged.//// `scenes` (optional) is the project's scene list — when a clip's matching-// scene has `beatAligned: true` and a valid `startSec`/`endSec` (persisted by+// scene has planner section provenance or `beatAligned: true` and valid+// `startSec`/`endSec` (persisted by// the BeatTimeline drag-snap arranger, #1854), that scene's saved duration is// honored EXACTLY instead of being re-derived from the live beat grid: the// director already snapped and saved it, so the render shouldn't silently@@ -303,7 +304,11 @@ export function beatSnapClips(clips, beats, { toleranceSec = 0.12, minClipSec =return { ...clip };}const scene = scenesById?.get(clip.sceneId);- if (scene?.beatAligned && typeof scene.startSec === 'number' && typeof scene.endSec === 'number' && scene.endSec > scene.startSec) {+ // A planned shot keeps its bounded span even when a sparse grid cannot+ // supply an on-beat cut. Beat alignment describes the cut, not ownership+ // of its timing. Section provenance is cleared when the audio changes.+ const planned = Number.isInteger(scene?.sectionIndex) && scene.sectionIndex >= 0;+ if ((scene?.beatAligned || planned) && sceneHasAuthoredSpan(scene)) {// inSec stays 0 here deliberately: this only ever trims how much of the// clip plays, never which frames — there is no in-point/out-point// distinction. A legacy planned scene commonly spans much longer thandiff --git a/server/services/musicVideo/render.test.js b/server/services/musicVideo/render.test.jsindex f2820c2cf1..edaebbda0c 100644--- a/server/services/musicVideo/render.test.js+++ b/server/services/musicVideo/render.test.js@@ -27,6 +27,7 @@ import { findFfmpeg, probeVideoGeometry } from '../../lib/ffmpeg.js';import { loadHistory } from '../videoGen/local.js';import { getTrack } from '../tracks/index.js';import { getProject } from './projects.js';+import { planShots } from './shotPlan.js';const clip = (over = {}) => ({ videoPath: '/v/a.mp4', width: 768, height: 512, fps: 24, duration: 2, inSec: 0, outSec: 2, ...over });@@ -166,6 +167,20 @@ describe('excerptBoundaryTimes (#8986)', () => {});describe('beatSnapClips', () => {+ it('keeps a sparse-grid shot plan on its authored timeline when source clips are longer', async () => {+ const beats = [0, 12];+ const { shots } = planShots([{ label: 'Verse', startSec: 0, endSec: 12 }], { beats });+ expect(shots.some((shot) => !shot.beatAligned)).toBe(true);+ const scenes = shots.map((shot, order) => ({ ...shot, sceneId: `s${order}`, order, videoHistoryId: `v${order}`, loop: false }));+ loadHistory.mockResolvedValue(scenes.map((scene) => ({ id: scene.videoHistoryId, filename: `${scene.videoHistoryId}.mp4`, numFrames: 240, fps: 24, width: 768, height: 512 })));+ const clips = beatSnapClips(await resolveSceneClips({ scenes }), beats, { scenes });+ expect(clips.map((c) => c.duration)).toEqual(shots.map((shot) => shot.endSec - shot.startSec));+ const { totalDuration, args } = buildMusicVideoFfmpegArgs(clips, '/music/example.wav', '/out.mp4', { audioDurationSec: 20 });+ expect(totalDuration).toBe(12);+ const filters = args[args.indexOf('-filter_complex') + 1];+ for (const shot of shots) expect(filters).toContain(`trim=start=0:end=${shot.endSec - shot.startSec}`);+ });+it('returns clips unchanged when there is no beat grid', () => {const out = beatSnapClips([clip({ duration: 2, outSec: 2 })], null);expect(out[0].outSec).toBe(2);