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

Add Merge over previous to the shot card (#11617)

[._.]/d9f7b52baea9
diff --git a/client/src/components/musicVideo/SceneCard.jsx b/client/src/components/musicVideo/SceneCard.jsx
index ad2892f61b..c35c54f337 100644
--- a/client/src/components/musicVideo/SceneCard.jsx
+++ b/client/src/components/musicVideo/SceneCard.jsx
@@ -85,8 +85,9 @@ const frameSpan = (scene) => `fr ${frameAt(scene.startSec)}–${frameAt(scene.en
* A shot longer than that lane renders in one take (the lip-sync audio window,
* or Grok's longest clip) offers `onSplit(sceneId, backend)`, which cuts it
* into contiguous scenes at lyric pauses / phrase boundaries server-side.
- * Any scene but the last offers `onMergeNext(sceneId, backend)` (with `nextEndSec`, the next scene's end), the inverse;
- * it is hidden when the joined span would exceed that lane's longest take.
+ * Any scene but the last offers `onMergeNext(sceneId, backend)` (with `nextEndSec`, the next scene's end), the inverse,
+ * and any but the first `onMergePrevious(sceneId, backend)` (with `prevStartSec`), which keeps this shot and removes the
+ * one before; each is hidden when the joined span would exceed that lane's longest take.
*
* The card is a disclosure: collapsed it is one row — frame thumbnail, title,
* timing, lyric line and status — and it opens on tap to the full editor:
@@ -121,7 +122,7 @@ export default function SceneCard({
onMove, onDelete, onEditLocal, onSave,
project = null, onGenerateFrame, onGenerateVideo, onContinueVideo, onGenerateEndFrame, generatingEndFrame = false, onContinueFromPrevious, previousHasClip = false,
onOpenPreview, onSelectTake, onReviewTake, onRejectUnusedTakes = null, onSwapFrames = null, onMarkTake = null, onPoolMarked = null, onImportTake, onImportClipTake, onPlacePoolItem, onTrimClip, projectId = null, aspect = '16:9', videoModels = [], defaultVideoModel = '', shotNumbers = undefined, takeBusy = false, layered = false, documentComposition = false,
- lipSyncBackend = '', songDurationSec = null, onSplit, onMergeNext, onMoveStart = null, nextEndSec = null, falVideoSettings = null, onSeek, performanceReview = null, onRepairPerformance, repairBusy = false,
+ lipSyncBackend = '', songDurationSec = null, onSplit, onMergeNext, onMergePrevious = null, prevStartSec = null, onMoveStart = null, nextEndSec = null, falVideoSettings = null, onSeek, performanceReview = null, onRepairPerformance, repairBusy = false,
expanded, onToggleExpand, stepShot = null, footageOptional = false, failedScenes = null, songReview = null,
}) {
const detailsRef = useRef(null);
@@ -159,6 +160,7 @@ export default function SceneCard({
const timing = buildSceneTimingPresentation({
scene, layer, lipSyncBackend: renderLane, songDurationSec, falVideoSettings: renderSettings,
nextEndSec, isLast, documentComposition, hasMergeNext: !!onMergeNext,
+ prevStartSec, isFirst: index === 0, hasMergePrevious: !!onMergePrevious,
lineCues: isPerformanceScene(scene) && renderInputs.wholeLine === true ? project?.lyricCues || [] : null,
});
const { performance, capability, performanceBlocked, performanceCost } = timing;
@@ -233,7 +235,7 @@ export default function SceneCard({
disabled={shotLock?.clip === 'locked'} disabledReason={shotLock?.clip === 'locked' ? 'Video locked. Unlock the video to retime it.' : null} />
)}
{/* What this shot's render covers and costs, and what blocks it, stays in view. */}
- <SceneTimingPlan timing={timing} sceneId={scene.sceneId} lipSyncBackend={renderLane} onSplit={onSplit} onMergeNext={onMergeNext}
+ <SceneTimingPlan timing={timing} sceneId={scene.sceneId} lipSyncBackend={renderLane} onSplit={onSplit} onMergeNext={onMergeNext} onMergePrevious={onMergePrevious}
span={sceneHasAuthoredSpan(scene) ? { startSec: scene.startSec, endSec: scene.endSec } : null} />
{/* A VHS glitch riding on the cut into or out of this shot; never moves the cut. */}
<SceneTransitions fieldId={fieldId} scene={scene} onChange={applyPatch} />
diff --git a/client/src/components/musicVideo/SceneCard.test.jsx b/client/src/components/musicVideo/SceneCard.test.jsx
index 9e70d38a05..87fe7e82ce 100644
--- a/client/src/components/musicVideo/SceneCard.test.jsx
+++ b/client/src/components/musicVideo/SceneCard.test.jsx
@@ -268,6 +268,25 @@ describe('Merge with next (#10810)', () => {
});
});
+// Uniquely catches Merge over previous showing on the first shot, past the backend limit, or calling with the wrong shot.
+describe('Merge over previous', () => {
+ const scene = { sceneId: 's2', startSec: 4, endSec: 8, takes: [] };
+ const props = { index: 1, expanded: true, onEditLocal: vi.fn(), onSave: vi.fn() };
+
+ it('merges this shot over the previous one, and hides when first, in a document composition, or past the backend limit', () => {
+ const onMergePrevious = vi.fn();
+ const { rerender } = render(<SceneCard scene={scene} {...props} onMergePrevious={onMergePrevious} prevStartSec={0} lipSyncBackend="grok" />);
+ fireEvent.click(screen.getByRole('button', { name: 'Merge over previous' }));
+ expect(onMergePrevious).toHaveBeenCalledWith('s2', 'grok');
+ rerender(<SceneCard scene={{ ...scene, endSec: 19 }} {...props} onMergePrevious={onMergePrevious} prevStartSec={0} lipSyncBackend="grok" />);
+ expect(screen.queryByRole('button', { name: 'Merge over previous' })).toBeNull();
+ rerender(<SceneCard scene={scene} {...props} index={0} onMergePrevious={onMergePrevious} prevStartSec={0} />);
+ expect(screen.queryByRole('button', { name: 'Merge over previous' })).toBeNull();
+ rerender(<SceneCard scene={scene} {...props} onMergePrevious={onMergePrevious} prevStartSec={0} documentComposition />);
+ expect(screen.queryByRole('button', { name: 'Merge over previous' })).toBeNull();
+ });
+});
+
describe('scene timing and provider presentation (#11046)', () => {
const scene = { sceneId: 'timing', startSec: 10, endSec: 12, referenceImageId: 'frame.png', takes: [] };
const props = { index: 0, expanded: true, onEditLocal: vi.fn(), onSave: vi.fn() };
diff --git a/client/src/components/musicVideo/SceneTimingPlan.jsx b/client/src/components/musicVideo/SceneTimingPlan.jsx
index 6351d5ef99..5d02d18fba 100644
--- a/client/src/components/musicVideo/SceneTimingPlan.jsx
+++ b/client/src/components/musicVideo/SceneTimingPlan.jsx
@@ -37,10 +37,10 @@ function SplitAt({ sceneId, startSec, endSec, onSplit }) {
}
/** Stateless provider plan and scene split/merge controls, without wrapper DOM. `span` (the shot's start and end) offers a manual split. */
-export default function SceneTimingPlan({ timing, sceneId, lipSyncBackend, onSplit, onMergeNext, span = null }) {
+export default function SceneTimingPlan({ timing, sceneId, lipSyncBackend, onSplit, onMergeNext, onMergePrevious = null, span = null }) {
const {
performance, performanceBlocked, capability, plan, performanceCost,
- falTake, falCost, grokPlan, timedSpan, canSplit, splitLimit, canMerge,
+ falTake, falCost, grokPlan, timedSpan, canSplit, splitLimit, canMerge, canMergePrevious,
} = timing;
return (
<>
@@ -78,6 +78,13 @@ export default function SceneTimingPlan({ timing, sceneId, lipSyncBackend, onSpl
{onSplit && span && span.endSec - span.startSec >= 2 * MIN_PIECE_SEC + 0.1 && (
<SplitAt key={`${span.startSec}-${span.endSec}`} sceneId={sceneId} startSec={span.startSec} endSec={span.endSec} onSplit={onSplit} />
)}
+ {canMergePrevious && onMergePrevious && (
+ <button type="button" onClick={() => onMergePrevious(sceneId, lipSyncBackend || null)}
+ className="inline-flex items-center gap-1 rounded bg-port-bg border border-port-border hover:bg-port-border/40 px-2 py-1 text-xs min-h-[44px] sm:min-h-0"
+ title="Remove the previous shot and start this one where it started">
+ <Merge size={13} /> Merge over previous
+ </button>
+ )}
{canMerge && (
<button type="button" onClick={() => onMergeNext(sceneId, lipSyncBackend || null)}
className="inline-flex items-center gap-1 rounded bg-port-bg border border-port-border hover:bg-port-border/40 px-2 py-1 text-xs min-h-[44px] sm:min-h-0"
diff --git a/client/src/components/musicVideo/stages/BoardStage.jsx b/client/src/components/musicVideo/stages/BoardStage.jsx
index 61cd42aff8..9dcd2014c1 100644
--- a/client/src/components/musicVideo/stages/BoardStage.jsx
+++ b/client/src/components/musicVideo/stages/BoardStage.jsx
@@ -267,6 +267,8 @@ export default function BoardStage({ board }) {
onDelete={board.onDeleteScene}
onSplit={board.onSplitScene}
onMergeNext={board.onMergeNextScene}
+ onMergePrevious={board.onMergePreviousScene}
+ prevStartSec={scenes[idx - 1]?.startSec ?? null}
onMoveStart={board.onMoveSceneStart}
nextEndSec={scenes[idx + 1]?.endSec ?? null}
onRepairPerformance={['code', 'document'].includes(project.composition?.mode) ? null : board.onRepairPerformance}
diff --git a/client/src/lib/musicVideoSceneTiming.js b/client/src/lib/musicVideoSceneTiming.js
index a54834f39b..8a8658a2da 100644
--- a/client/src/lib/musicVideoSceneTiming.js
+++ b/client/src/lib/musicVideoSceneTiming.js
@@ -14,6 +14,7 @@ const falEstimate = (take) => (take?.costUsd == null ? null
export function buildSceneTimingPresentation({
scene, layer, lipSyncBackend, songDurationSec, falVideoSettings,
nextEndSec, isLast, documentComposition, hasMergeNext, lineCues = null,
+ prevStartSec = null, isFirst = true, hasMergePrevious = false,
}) {
const performance = isPerformanceScene(scene);
const capability = performance ? performanceCapability(lipSyncBackend, { scene, videoSettings: falVideoSettings }) : null;
@@ -37,8 +38,12 @@ export function buildSceneTimingPresentation({
const mergedSpan = typeof scene.startSec === 'number' && typeof nextEndSec === 'number' ? nextEndSec - scene.startSec : null;
const canMerge = hasMergeNext && !isLast && !documentComposition
&& (splitLimit == null || (mergedSpan != null && mergedSpan <= splitLimit + 1e-6));
+ // Merge over previous keeps this shot and starts it where the previous one did.
+ const mergedPreviousSpan = typeof prevStartSec === 'number' && typeof scene.endSec === 'number' ? scene.endSec - prevStartSec : null;
+ const canMergePrevious = hasMergePrevious && !isFirst && !documentComposition
+ && (splitLimit == null || (mergedPreviousSpan != null && mergedPreviousSpan <= splitLimit + 1e-6));
return {
performance, capability, timedSpan, plan, performanceBlocked, grokPlan,
- falTake, falCost, performanceCost, splitLimit, canSplit, mergedSpan, canMerge,
+ falTake, falCost, performanceCost, splitLimit, canSplit, mergedSpan, canMerge, canMergePrevious,
};
}
diff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsx
index 678a692e58..025d49d4a0 100644
--- a/client/src/pages/MusicVideo.jsx
+++ b/client/src/pages/MusicVideo.jsx
@@ -24,7 +24,7 @@ import {
updateMusicVideoScene,
deleteMusicVideoScene,
splitMusicVideoScene,
- mergeMusicVideoNextScene,
+ mergeMusicVideoNextScene, mergeMusicVideoPreviousScene,
moveMusicVideoSceneStart,
reorderMusicVideoScenes,
importMusicVideoLyrics,
@@ -1002,6 +1002,16 @@ export default function MusicVideo() {
.catch((err) => toast.error(err?.message || 'Failed to merge scenes'));
};
+ // Extend a scene back over the previous one, which is removed (the mirror of the merge above).
+ const handleMergePreviousScene = (sceneId, backend) => {
+ mergeMusicVideoPreviousScene(selected.id, sceneId, backend, { silent: true })
+ .then(({ project }) => {
+ replaceProject(project);
+ toast.success('Merged over the previous shot');
+ })
+ .catch((err) => toast.error(err?.message || 'Failed to merge scenes'));
+ };
+
// Move the cut before a shot: it starts at `startSec` and the shot before it ends there.
const handleMoveSceneStart = (sceneId, startSec) => moveMusicVideoSceneStart(selected.id, sceneId, startSec, { silent: true })
.then(({ project }) => replaceProject(project))
@@ -1361,6 +1371,7 @@ export default function MusicVideo() {
onDeleteScene: handleDeleteScene,
onSplitScene: handleSplitScene,
onMergeNextScene: handleMergeNextScene,
+ onMergePreviousScene: handleMergePreviousScene,
onMoveSceneStart: handleMoveSceneStart,
onRepairPerformance: revisions.repairPerformance,
repairBusy: revisions.busy,
diff --git a/client/src/services/apiMusicVideo.js b/client/src/services/apiMusicVideo.js
index f1263c83a9..8963cfe624 100644
--- a/client/src/services/apiMusicVideo.js
+++ b/client/src/services/apiMusicVideo.js
@@ -141,6 +141,11 @@ export const mergeMusicVideoNextScene = (id, sceneId, backend, options = {}) =>
request(`/music-video/${encodeURIComponent(id)}/scenes/${encodeURIComponent(sceneId)}/merge-next`, {
method: 'POST', body: JSON.stringify(backend ? { backend } : {}), ...options,
});
+// Merge a scene over the previous one: it starts where that one did, which is removed → { project, scene }.
+export const mergeMusicVideoPreviousScene = (id, sceneId, backend, options = {}) =>
+ request(`/music-video/${encodeURIComponent(id)}/scenes/${encodeURIComponent(sceneId)}/merge-previous`, {
+ method: 'POST', body: JSON.stringify(backend ? { backend } : {}), ...options,
+ });
// Move a shot's start; the shot before ends there too → { project, scene, previous }.
export const moveMusicVideoSceneStart = (id, sceneId, startSec, options = {}) =>
request(`/music-video/${encodeURIComponent(id)}/scenes/${encodeURIComponent(sceneId)}/start`, {
diff --git a/server/routes/musicVideo.js b/server/routes/musicVideo.js
index 6e83e85b0b..8125cda4f6 100644
--- a/server/routes/musicVideo.js
+++ b/server/routes/musicVideo.js
@@ -112,6 +112,7 @@ import {
reorderProjectScenes,
splitProjectScene,
mergeProjectNextScene,
+ mergeProjectPreviousScene,
moveProjectSceneStart,
setProjectMidiTranscription,
appendSceneTakes,
@@ -1550,6 +1551,12 @@ router.post('/:id/scenes/:sceneId/merge-next', asyncHandler(async (req, res) =>
res.json(await mergeProjectNextScene(req.params.id, req.params.sceneId, { backend }));
}));
+// Merge a scene over the previous one: it starts where the previous one did, which is removed.
+router.post('/:id/scenes/:sceneId/merge-previous', asyncHandler(async (req, res) => {
+ const { backend } = validateRequest(musicVideoSceneSplitSchema, req.body ?? {});
+ res.json(await mergeProjectPreviousScene(req.params.id, req.params.sceneId, { backend }));
+}));
+
// Move a shot's start; the shot before it ends at the same time, so the cut between them moves.
router.post('/:id/scenes/:sceneId/start', asyncHandler(async (req, res) => {
const { startSec } = validateRequest(musicVideoSceneStartSchema, req.body ?? {});
diff --git a/server/routes/musicVideo.test.js b/server/routes/musicVideo.test.js
index 5e335f8648..cfc3318fec 100644
--- a/server/routes/musicVideo.test.js
+++ b/server/routes/musicVideo.test.js
@@ -29,6 +29,7 @@ vi.mock('../services/musicVideo/projects.js', () => ({
// Scene split (#8977) — exercised against the real store in musicVideoSceneSplit.test.js.
splitProjectScene: vi.fn(),
mergeProjectNextScene: vi.fn(),
+ mergeProjectPreviousScene: vi.fn(),
setProjectMidiTranscription: vi.fn(async (id, midi) => ({ id, midiTranscription: midi })),
// Scene takes (#8965) — exercised against the real store in musicVideoTakes.test.js.
appendSceneTakes: vi.fn(),
diff --git a/server/services/musicVideo/projects.js b/server/services/musicVideo/projects.js
index f5039e4422..76b3d0e5fa 100644
--- a/server/services/musicVideo/projects.js
+++ b/server/services/musicVideo/projects.js
@@ -329,6 +329,22 @@ export async function mergeProjectNextScene(id, sceneId, options = {}) {
});
}
+/**
+ * Merge a scene over the one before it (projectsLogic.mergePreviousScene): this
+ * scene starts where the previous one did and the previous one is removed.
+ * Returns `{ project, scene }`.
+ */
+export async function mergeProjectPreviousScene(id, sceneId, options = {}) {
+ const [{ mergePreviousScene }, { assertClipUnlocked }] = await Promise.all([import('./projectsLogic.js'), import('./productionReview.js')]);
+ return mutateProjectRecord(id, (current) => {
+ const scenes = current.scenes || [];
+ const index = scenes.findIndex(scene => scene.sceneId === sceneId);
+ assertClipUnlocked(current, sceneId);
+ if (index > 0) assertClipUnlocked(current, scenes[index - 1].sceneId);
+ return mergePreviousScene(current, sceneId, options);
+ });
+}
+
/**
* Move the cut before a shot: the shot starts at `startSec` and the shot
* before it ends there, so the two stay joined. Either shot's locked video
diff --git a/server/services/musicVideo/projects.test.js b/server/services/musicVideo/projects.test.js
index bf1d51b732..ef1e0f03a3 100644
--- a/server/services/musicVideo/projects.test.js
+++ b/server/services/musicVideo/projects.test.js
@@ -307,7 +307,7 @@ describe('automation respects persisted shot locks (#11218)', () => {
});
describe('a locked shot video', () => {
- // Uniquely catches a video lock that only labels the shot: edits, split, merge, take choice and a run must all be refused.
+ // Uniquely catches a video lock that only labels the shot: edits, split, merges either way, take choice and a run must all be refused.
it('freezes the shot for the director and for automation until its video is unlocked', async () => {
const { setShotLocks, clipLocks } = await import('./productionReview.js');
const p = await projects.createProject({ name: 'Video lock' });
@@ -322,8 +322,9 @@ describe('a locked shot video', () => {
await expect(projects.deleteScene(p.id, scene.sceneId)).rejects.toMatchObject({ code: 'MUSIC_VIDEO_SHOT_LOCKED' });
await expect(projects.splitProjectScene(p.id, scene.sceneId, { atSec: 1 })).rejects.toMatchObject({ code: 'MUSIC_VIDEO_SHOT_LOCKED' });
await expect(projects.selectSceneTake(p.id, scene.sceneId, 'take-1')).rejects.toMatchObject({ code: 'MUSIC_VIDEO_SHOT_LOCKED' });
- await projects.addProjectScene(p.id, { startSec: 2, endSec: 3, prompt: 'After' });
+ const after = await projects.addProjectScene(p.id, { startSec: 2, endSec: 3, prompt: 'After' });
await expect(projects.mergeProjectNextScene(p.id, scene.sceneId)).rejects.toMatchObject({ code: 'MUSIC_VIDEO_SHOT_LOCKED' });
+ await expect(projects.mergeProjectPreviousScene(p.id, after.sceneId)).rejects.toMatchObject({ code: 'MUSIC_VIDEO_SHOT_LOCKED' });
// A field that doesn't change what the shot shows stays editable.
await projects.updateScene(p.id, scene.sceneId, { prompt: 'Approved', textZone: 'upper' });
const run = await projects.mutateProjectRecord(p.id, current => ({ project: { ...current, scenes: current.scenes.map(s => ({ ...s, videoHistoryId: 'run-clip' })) } }), { source: 'production-run' });
diff --git a/server/services/musicVideo/projectsLogic.js b/server/services/musicVideo/projectsLogic.js
index 6b49d0ff59..e25b99a1b3 100644
--- a/server/services/musicVideo/projectsLogic.js
+++ b/server/services/musicVideo/projectsLogic.js
@@ -912,19 +912,39 @@ export function mergeNextScene(project, sceneId, { backend = null } = {}) {
const scenes = project.scenes || [];
const idx = scenes.findIndex((s) => s.sceneId === sceneId);
if (idx < 0) throw new ServerError('Scene not found', { status: 404, code: 'NOT_FOUND' });
- const scene = scenes[idx];
- const following = scenes[idx + 1];
- if (!following) throw new ServerError('This is the last scene — there is no next scene to merge.', { status: 400, code: 'MUSIC_VIDEO_MERGE_NO_NEXT' });
+ if (!scenes[idx + 1]) throw new ServerError('This is the last scene — there is no next scene to merge.', { status: 400, code: 'MUSIC_VIDEO_MERGE_NO_NEXT' });
+ return joinScenes(project, idx, { keep: 'first', backend });
+}
+
+/**
+ * Merge a scene over the one before it, the mirror of `mergeNextScene`: this
+ * scene keeps its id, takes and selections and starts where the previous scene
+ * started, and the previous scene is removed. Same refusals and clip rules.
+ * Returns `{ project, scene }`.
+ */
+export function mergePreviousScene(project, sceneId, { backend = null } = {}) {
+ const scenes = project.scenes || [];
+ const idx = scenes.findIndex((s) => s.sceneId === sceneId);
+ if (idx < 0) throw new ServerError('Scene not found', { status: 404, code: 'NOT_FOUND' });
+ if (idx === 0) throw new ServerError('This is the first scene — there is no previous scene to merge over.', { status: 400, code: 'MUSIC_VIDEO_MERGE_NO_PREVIOUS' });
+ return joinScenes(project, idx - 1, { keep: 'second', backend });
+}
+
+/** Join scenes `idx` and `idx + 1` into one spanning both, keeping the `first` or `second` scene's id and media. */
+function joinScenes(project, idx, { keep, backend }) {
+ const scenes = project.scenes || [];
+ const [first, second] = [scenes[idx], scenes[idx + 1]];
+ const [kept, removed] = keep === 'first' ? [first, second] : [second, first];
if (project.composition?.mode === 'document') {
throw new ServerError("This video's shot order comes from its composition document — merge the shots in the shot manifest instead.", { status: 400, code: 'MUSIC_VIDEO_MERGE_DOCUMENT' });
}
const lane = backend || project.videoSettings?.backend || null;
- const startSec = scene.startSec;
- const endSec = timedSec(following.endSec) ? following.endSec : scene.endSec;
- if (timedSec(startSec) && timedSec(endSec) && (endSec <= startSec || (timedSec(scene.endSec) && endSec < scene.endSec))) {
+ const startSec = first.startSec;
+ const endSec = timedSec(second.endSec) ? second.endSec : first.endSec;
+ if (timedSec(startSec) && timedSec(endSec) && (endSec <= startSec || (timedSec(first.endSec) && endSec < first.endSec))) {
throw new ServerError('The next scene ends before this one does — put the scenes in song order before merging them.', { status: 400, code: 'MUSIC_VIDEO_MERGE_OUT_OF_ORDER' });
}
- const maxSec = shotSplitLimit(scene, lane, project.videoSettings);
+ const maxSec = shotSplitLimit(kept, lane, project.videoSettings);
if (maxSec != null) {
if (!timedSec(startSec) || !timedSec(endSec)) {
throw new ServerError('Both scenes need a start and end time before they can be merged on this backend.', { status: 400, code: 'MUSIC_VIDEO_MERGE_UNTIMED' });
@@ -935,34 +955,38 @@ export function mergeNextScene(project, sceneId, { backend = null } = {}) {
}
const now = new Date().toISOString();
- let takes = ensureSceneTakes(scene, now);
- const sharedClip = scene.videoHistoryId && scene.videoHistoryId === following.videoHistoryId;
- if (sharedClip && !takes.some((t) => t.kind === 'video' && t.assetId === scene.videoHistoryId)) {
- const kept = ensureSceneTakes(following, now).find((t) => t.kind === 'video' && t.assetId === scene.videoHistoryId);
- if (kept) takes = [...takes, kept];
+ let takes = ensureSceneTakes(kept, now);
+ const sharedClip = kept.videoHistoryId && kept.videoHistoryId === removed.videoHistoryId;
+ if (sharedClip && !takes.some((t) => t.kind === 'video' && t.assetId === kept.videoHistoryId)) {
+ const shared = ensureSceneTakes(removed, now).find((t) => t.kind === 'video' && t.assetId === kept.videoHistoryId);
+ if (shared) takes = [...takes, shared];
}
- const lyricText = [scene.lyricText, following.lyricText].filter((t) => typeof t === 'string' && t.trim()).join(' / ').slice(0, 2000) || null;
+ const lyricText = [first.lyricText, second.lyricText].filter((t) => typeof t === 'string' && t.trim()).join(' / ').slice(0, 2000) || null;
const merged = {
- ...scene, endSec, lyricText, takes,
- ...(isPerformanceScene(scene) ? { videoHistoryId: null } : {}),
+ ...kept, startSec, endSec, lyricText, takes,
+ ...(isPerformanceScene(kept) ? { videoHistoryId: null } : {}),
};
const nextScenes = [...scenes.slice(0, idx), merged, ...scenes.slice(idx + 2)].map((s, i) => ({ ...s, order: i }));
const extra = { scenes: nextScenes };
const sceneReview = project.songRevision?.sceneReview;
- if (sceneReview && typeof sceneReview === 'object' && following.sceneId in sceneReview) {
+ if (sceneReview && typeof sceneReview === 'object' && removed.sceneId in sceneReview) {
extra.songRevision = { ...project.songRevision,
- sceneReview: Object.fromEntries(Object.entries(sceneReview).filter(([id]) => id !== following.sceneId)) };
+ sceneReview: Object.fromEntries(Object.entries(sceneReview).filter(([id]) => id !== removed.sceneId)) };
}
const draft = project.productionReview?.draft;
if (Array.isArray(draft?.storyboard) && draft.storyboardSource !== 'document') {
- const second = draft.storyboard.find((shot) => shot?.sceneId === following.sceneId);
+ const rowOf = (scene) => draft.storyboard.find((shot) => shot?.sceneId === scene.sceneId);
+ const [firstRow, secondRow] = [rowOf(first), rowOf(second)];
+ const gone = rowOf(removed);
const storyboard = draft.storyboard
- .filter((shot) => shot?.sceneId !== following.sceneId)
+ .filter((shot) => shot?.sceneId !== removed.sceneId)
.map((shot) => {
- if (shot?.sceneId !== scene.sceneId) return shot;
- const cueIds = [...new Set([...(shot.lyricCueIds || []), ...(second?.lyricCueIds || [])])];
- return { ...shot, endSec: timedSec(second?.endSec) ? second.endSec : endSec ?? shot.endSec, lyricCueIds: cueIds };
+ if (shot?.sceneId !== kept.sceneId) return shot;
+ const cueIds = [...new Set([...(firstRow?.lyricCueIds || []), ...(secondRow?.lyricCueIds || [])])];
+ return { ...shot,
+ ...(keep === 'second' ? { startSec: timedSec(gone?.startSec) ? gone.startSec : startSec ?? shot.startSec } : {}),
+ endSec: timedSec(secondRow?.endSec) ? secondRow.endSec : endSec ?? shot.endSec, lyricCueIds: cueIds };
});
extra.productionReview = { ...project.productionReview, draft: { ...draft, storyboard } };
}
diff --git a/server/services/musicVideo/projectsLogic.test.js b/server/services/musicVideo/projectsLogic.test.js
index 335484b820..e294818d17 100644
--- a/server/services/musicVideo/projectsLogic.test.js
+++ b/server/services/musicVideo/projectsLogic.test.js
@@ -11,6 +11,7 @@ import {
removeScene,
reorderScenes,
mergeNextScene,
+ mergePreviousScene,
mirrorStatus,
sanitizeProjectForSync,
mergeProjectRecord,
@@ -664,6 +665,33 @@ describe('mergeNextScene', () => {
});
});
+// Uniquely catches merge-over-previous keeping the wrong shot's id/clip or leaving the removed shot's span behind.
+describe('mergePreviousScene', () => {
+ it('extends a shot back over the previous one, which is removed', () => {
+ let project = baseProject();
+ const ids = [];
+ for (const [startSec, endSec, lyricText] of [[0, 4, 'line one'], [4, 9, 'line two'], [9, 12, 'line three']]) {
+ const r = addScene(project, { startSec, endSec, lyricText, sectionLabel: 'Verse' });
+ project = r.project; ids.push(r.scene.sceneId);
+ }
+ project = applySceneUpdate(project, ids[1], { videoHistoryId: 'clip-a' }).project;
+ project = applySceneUpdate(project, ids[2], { videoHistoryId: 'clip-b' }).project;
+ const withDraft = { ...project, productionReview: { draft: { storyboard: [
+ { sceneId: ids[0], startSec: 0, endSec: 4, lyricCueIds: ['c1'] },
+ { sceneId: ids[1], startSec: 4, endSec: 9, lyricCueIds: ['c2'] },
+ { sceneId: ids[2], startSec: 9, endSec: 12, lyricCueIds: ['c3'] },
+ ] } } };
+ const { project: next, scene } = mergePreviousScene(withDraft, ids[2]);
+ expect(next.scenes.map((s) => [s.sceneId, s.order])).toEqual([[ids[0], 0], [ids[2], 1]]);
+ expect(scene).toMatchObject({ sceneId: ids[2], startSec: 4, endSec: 12, lyricText: 'line two / line three', videoHistoryId: 'clip-b' });
+ expect(next.productionReview.draft.storyboard).toEqual([
+ { sceneId: ids[0], startSec: 0, endSec: 4, lyricCueIds: ['c1'] },
+ { sceneId: ids[2], startSec: 4, endSec: 12, lyricCueIds: ['c2', 'c3'] },
+ ]);
+ expect(() => mergePreviousScene(withDraft, ids[0])).toThrow(/no previous scene/);
+ });
+});
+
describe('mirrorStatus', () => {
it('bounds and defaults the status column value', () => {
expect(mirrorStatus('rendering')).toBe('rendering');