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

Render one shot from its card; new shots land at their time; split a shot at a chosen time (#11240)

[._.]/f66e8ee8623c
diff --git a/client/src/components/musicVideo/SceneCard.jsx b/client/src/components/musicVideo/SceneCard.jsx
index 69297bf535..92bdfa60d7 100644
--- a/client/src/components/musicVideo/SceneCard.jsx
+++ b/client/src/components/musicVideo/SceneCard.jsx
@@ -24,6 +24,7 @@ import SceneRenderProgress from './SceneRenderProgress.jsx';
import { COVERAGE_TOLERANCE_SEC, SCENE_ATTENTION_LABELS, sceneAttention } from '../../lib/musicVideoSceneAttention.js';
import { ShotLockButton, useShotLock } from './ShotLock.jsx';
import ScenePoster from './ScenePoster.jsx';
+import SceneRenderTarget, { renderTargetOverrides } from './SceneRenderTarget.jsx';
// The two timeline-bound scene fields rendered as identical number inputs.
const SCENE_TIME_FIELDS = [['Start', 'startSec'], ['End', 'endSec']];
@@ -75,7 +76,8 @@ const MOVE_DOCUMENT_TITLE = "This video's shot order comes from its composition
// the persisted scene (and its speaker), so an unsaved or failed speaker edit
// must hold back every video entry point — Generate video and the failure Retry.
// Returns the refusal reason, or null when the render may go ahead.
-function videoGenerationRefusal({ settingsSaving, speakerUnsaved, referenceImageId, generatingVideo, videoBlockedReason, performanceBlocked }) {
+function videoGenerationRefusal({ settingsSaving, speakerUnsaved, referenceImageId, generatingVideo, videoBlockedReason, performanceBlocked, lockBlocked }) {
+ if (lockBlocked) return lockBlocked;
if (videoBlockedReason) return videoBlockedReason;
if (performanceBlocked) return performanceBlocked;
if (speakerUnsaved) return 'Save the speaker / singer edit first';
@@ -87,7 +89,7 @@ function videoGenerationRefusal({ settingsSaving, speakerUnsaved, referenceImage
export default function SceneCard({
scene, index, shotNumber = null, isLast, generatingFrame, generatingVideo, frameProgress = null, videoProgress = null,
- settingsSaving, videoBlockedReason, canContinueShot,
+ settingsSaving, videoBlockedReason, videoBlockedReasonFor = null, canContinueShot,
onMove, onDelete, onEditLocal, onSave,
onGenerateFrame, onGenerateVideo, onContinueVideo, onGenerateEndFrame, generatingEndFrame = false, onContinueFromPrevious, previousHasClip = false,
onOpenPreview, onSelectTake, onReviewTake, onImportTake, onImportClipTake, takeBusy = false, layered = false, documentComposition = false,
@@ -134,8 +136,15 @@ export default function SceneCard({
const fieldId = (name) => `mv-scene-${scene.sceneId}-${name}`;
// #10297: a code shot is drawn by the composition, so it has no frame or clip to make.
const codeShot = layered && layer === 'code';
+ // Where this shot's clip renders: the project's saved renderer unless the card picks another for this shot.
+ const [renderPick, setRenderPick] = useState('');
+ const renderOverrides = renderTargetOverrides(renderPick, falVideoSettings || {});
+ const renderSettings = renderOverrides ? { ...falVideoSettings, ...renderOverrides } : falVideoSettings;
+ const renderLane = renderOverrides
+ ? (renderSettings.backend === 'local' && renderSettings.generationMode === 'audioReactive' ? 'local' : renderSettings.backend)
+ : lipSyncBackend;
const timing = buildSceneTimingPresentation({
- scene, layer, lipSyncBackend, songDurationSec, falVideoSettings,
+ scene, layer, lipSyncBackend: renderLane, songDurationSec, falVideoSettings: renderSettings,
nextEndSec, isLast, documentComposition, hasMergeNext: !!onMergeNext,
});
const { performance, capability, performanceBlocked, performanceCost } = timing;
@@ -144,7 +153,12 @@ export default function SceneCard({
excerptStartSec: performanceReview?.excerptStartSec, backend: lipSyncBackend, videoSettings: falVideoSettings || {} });
const shotModeId = `mv-shot-mode-${scene.sceneId}`;
// #10152: what needs the director's attention, visible without opening the card.
- const locked = useShotLock(scene.sceneId)?.state === 'locked';
+ const shotLock = useShotLock(scene.sceneId);
+ const locked = shotLock?.state === 'locked';
+ // A clip needs its still locked, and a locked video stays as it is until unlocked.
+ const lockBlocked = !shotLock ? null
+ : shotLock.clip === 'locked' ? 'Video locked. Unlock the video to render it again.'
+ : shotLock.still !== 'locked' ? 'Lock the still first' : null;
const attention = sceneAttention(scene, { layered, footageOptional, lipSyncBackend, songDurationSec, clipSec, failed: failedScenes || {}, songReview, videoSettings: falVideoSettings, locked });
const songChange = songReview?.[scene.sceneId];
const generatingLane = generatingFrame && generatingVideo ? 'Frame + clip' : generatingFrame ? 'Frame' : generatingVideo ? 'Clip' : null;
@@ -154,9 +168,25 @@ export default function SceneCard({
? scene.lastFailure : null;
const videoRefusal = videoGenerationRefusal({
settingsSaving, speakerUnsaved: performance && (speakerDirty || speakerSaving),
- referenceImageId: scene.referenceImageId, generatingVideo, videoBlockedReason, performanceBlocked,
+ referenceImageId: scene.referenceImageId, generatingVideo, performanceBlocked, lockBlocked,
+ videoBlockedReason: renderOverrides && videoBlockedReasonFor ? videoBlockedReasonFor(renderSettings) : videoBlockedReason,
});
- const generateVideo = () => { if (!videoRefusal) onGenerateVideo?.(scene); };
+ const generateVideo = () => {
+ if (videoRefusal) return;
+ if (renderOverrides) onGenerateVideo?.(scene, { target: renderOverrides });
+ else onGenerateVideo?.(scene);
+ };
+ const renderCost = performance ? performanceCost : timing.falCost;
+ const promptField = (
+ <textarea
+ aria-label="Shot prompt"
+ value={scene.prompt || ''} rows={2}
+ onChange={(e) => onEditLocal(scene.sceneId, { prompt: e.target.value })}
+ onBlur={(e) => onSave(scene.sceneId, { prompt: e.target.value })}
+ placeholder={layer === 'footage' ? 'Motion prompt: what happens in this shot' : "Shot prompt — what this scene's video should show"}
+ className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm"
+ />
+ );
return (
<div className="min-w-0">
<details
@@ -223,14 +253,8 @@ export default function SceneCard({
</button>
<button onClick={() => onDelete(scene.sceneId)} aria-label="Delete scene" className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1 text-port-error" title="Delete scene"><Trash2 size={14} /></button>
</div>
- <textarea
- aria-label="Shot prompt"
- value={scene.prompt || ''} rows={2}
- onChange={(e) => onEditLocal(scene.sceneId, { prompt: e.target.value })}
- onBlur={(e) => onSave(scene.sceneId, { prompt: e.target.value })}
- placeholder="Shot prompt — what this scene's video should show"
- className="w-full bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm"
- />
+ {/* A footage shot's prompt is its motion, edited beside its Render button below. */}
+ {(layer !== 'footage' || codeShot) && promptField}
{(scene.lyricText || scene.visualIntent || scene.direction) && (
<div className="text-[11px] text-port-text-muted space-y-0.5">
{scene.lyricText && <p className="italic break-words">♪ {scene.lyricText}</p>}
@@ -363,7 +387,7 @@ export default function SceneCard({
Set a start and end — a {{ card: 'title card', code: 'code-drawn shot' }[layer] || 'still'} runs for exactly its span.
</p>
)}
- <SceneTimingPlan timing={timing} sceneId={scene.sceneId} lipSyncBackend={lipSyncBackend} onSplit={onSplit} onMergeNext={onMergeNext} />
+ <SceneTimingPlan timing={timing} sceneId={scene.sceneId} lipSyncBackend={renderLane} onSplit={onSplit} onMergeNext={onMergeNext} />
{underCovered && (
<div role="alert" className="flex flex-wrap items-center gap-2 rounded border border-port-warning/40 bg-port-warning/10 px-2 py-1.5 text-xs text-port-warning">
<AlertTriangle size={13} className="shrink-0" />
@@ -455,7 +479,15 @@ export default function SceneCard({
onEditLocal={onEditLocal} onSave={onSave} onOpenPreview={onOpenPreview} takeBusy={takeBusy}
onSelectTake={onSelectTake} onReviewTake={onReviewTake} videoSettings={falVideoSettings} />
)}
- {/* Scene clip — i2v video generated from the reference frame (Phase 1) */}
+ {/* Render: the motion prompt, where this shot renders and what it costs, then its clip (Phase 1). */}
+ <section aria-label="Render" className="space-y-2 rounded border border-port-border p-2">
+ <h4 className="text-xs font-medium">Render</h4>
+ {layer === 'footage' && promptField}
+ <div className="flex flex-wrap items-center gap-2">
+ <SceneRenderTarget id={fieldId('render-on')} value={renderPick} onChange={setRenderPick} performance={performance}
+ saved={falVideoSettings || {}} disabled={!!generatingVideo} />
+ {renderCost && <span className="text-[11px] text-port-text-muted">{renderCost}</span>}
+ </div>
<div className="flex items-center gap-2 flex-wrap">
{scene.videoHistoryId && performance && (
<PerformanceEvidence key={scene.videoHistoryId} clipSrc={clipSrc} instruction={instruction}
@@ -503,9 +535,9 @@ export default function SceneCard({
className="flex items-center gap-1 bg-port-border hover:bg-port-border/70 disabled:opacity-50 rounded px-2 py-1.5 text-xs min-h-[44px] sm:min-h-0 whitespace-nowrap"
title={videoRefusal
|| (performance ? `${capability.style === 'music' ? "Animate this scene's frame to the song" : "Lip-sync this scene's frame to the song"} via ${capability.label} — ${performanceCost}`
- : "Generate this scene's video from its reference frame (i2v)")}>
+ : "Render this shot's clip from its still")}>
{generatingVideo ? <Activity size={14} className="animate-spin" /> : <Video size={14} />}
- {generatingVideo ? 'Generating video…' : (scene.videoHistoryId ? 'New video take' : 'Generate video')}
+ {generatingVideo ? 'Rendering…' : (scene.videoHistoryId ? 'Render again' : 'Render')}
</button>
{scene.videoHistoryId && canContinueShot && (
<button
@@ -529,6 +561,7 @@ export default function SceneCard({
onSelect={(take) => onSelectTake?.(scene, take)}
onReview={(take, review) => onReviewTake?.(scene, take, review)}
onOpenPreview={onOpenPreview} />
+ </section>
</>)}
</div>
</details>
diff --git a/client/src/components/musicVideo/SceneCard.test.jsx b/client/src/components/musicVideo/SceneCard.test.jsx
index 2c99944d4c..72ccf23a5a 100644
--- a/client/src/components/musicVideo/SceneCard.test.jsx
+++ b/client/src/components/musicVideo/SceneCard.test.jsx
@@ -12,7 +12,7 @@ describe('code shot (#10297)', () => {
// A composed render has no code to run, so it says the shot will be black there.
expect(screen.getByTestId('code-shot-note').textContent).toMatch(/composed render shows it as a black frame/);
expect(screen.queryByRole('button', { name: 'Generate frame' })).toBeNull();
- expect(screen.queryByRole('button', { name: 'Generate video' })).toBeNull();
+ expect(screen.queryByRole('button', { name: 'Render' })).toBeNull();
rerender(<SceneCard scene={scene} index={0} layered documentComposition onEditLocal={() => {}} onSave={() => {}} />);
expect(screen.getByTestId('code-shot-note').textContent).not.toMatch(/black frame/);
// A plain render plays footage, so the generation controls come back.
@@ -33,7 +33,7 @@ describe('performance speaker save boundary', () => {
}
render(<Harness />);
const input = screen.getByLabelText('Speaker / singer');
- const generate = screen.getByRole('button', { name: 'Generate video' });
+ const generate = screen.getByRole('button', { name: 'Render' });
expect(generate.disabled).toBe(false);
fireEvent.change(input, { target: { value: 'Example Singer' } });
expect(generate.disabled).toBe(true);
@@ -87,7 +87,7 @@ describe('failed video retry behind the speaker save gate (#11040)', () => {
render(<Harness onSave={onSave} onGenerateVideo={onGenerateVideo} lastFailure={videoFailure} />);
const input = screen.getByLabelText('Speaker / singer');
const retry = screen.getByRole('button', { name: 'Retry' });
- const generate = screen.getByRole('button', { name: 'Generate video' });
+ const generate = screen.getByRole('button', { name: 'Render' });
expect(retry.disabled).toBe(false);
fireEvent.change(input, { target: { value: 'Example Singer' } });
expect([generate.disabled, retry.disabled]).toEqual([true, true]);
@@ -246,18 +246,18 @@ describe('scene timing and provider presentation (#11046)', () => {
expect(plan()).toContain('song 0:08–0:13');
expect(plan()).toContain('shot starts 1.52s into the take');
expect(plan()).toContain('est. $0.81 (5.05s at 1080P)');
- expect(screen.getByRole('button', { name: 'Generate video' }).title).toContain('est. $0.81');
+ expect(screen.getByRole('button', { name: 'Render' }).title).toContain('est. $0.81');
rerender(<SceneCard {...props} scene={{ ...performance, startSec: 0, endSec: 6 }} lipSyncBackend="fal"
falVideoSettings={{ falLipSyncResolution: '768P' }} songDurationSec={null} />);
expect(plan()).toContain('song 0:00–0:06');
expect(plan()).not.toContain('shot starts');
expect(plan()).toContain('est. $0.48 (6s at 768P)');
- expect(screen.getByRole('button', { name: 'Generate video' }).disabled).toBe(false);
+ expect(screen.getByRole('button', { name: 'Render' }).disabled).toBe(false);
rerender(<SceneCard {...props} scene={{ ...performance, startSec: 0, endSec: 6 }} lipSyncBackend="fal" />);
- expect(screen.getByRole('button', { name: 'Generate video' }).disabled).toBe(false);
+ expect(screen.getByRole('button', { name: 'Render' }).disabled).toBe(false);
rerender(<SceneCard {...props} scene={performance} lipSyncBackend="fal" songDurationSec={11} />);
expect(screen.getByText('The performance shot runs past the end of the song.')).toBeTruthy();
- expect(screen.getByRole('button', { name: 'Generate video' }).disabled).toBe(true);
+ expect(screen.getByRole('button', { name: 'Render' }).disabled).toBe(true);
});
it('blocks unsupported performance generation and keeps the blocker on the generation control', () => {
@@ -265,7 +265,7 @@ describe('scene timing and provider presentation (#11046)', () => {
const blocker = screen.getByText(/Grok video is cutaway-only/);
expect(blocker.closest('[role="alert"]')).toBeTruthy();
expect(screen.queryByTestId('performance-plan')).toBeNull();
- const generate = screen.getByRole('button', { name: 'Generate video' });
+ const generate = screen.getByRole('button', { name: 'Render' });
expect(generate.disabled).toBe(true);
expect(generate.title).toBe(blocker.textContent);
});
@@ -282,7 +282,7 @@ describe('scene timing and provider presentation (#11046)', () => {
expect(screen.queryByTestId('performance-plan')).toBeNull();
rerender(<SceneCard {...props} scene={{ ...scene, visualLayer: 'still', shotMode: 'performance' }} lipSyncBackend="fal" />);
expect(screen.queryByTestId('fal-cutaway-plan')).toBeNull();
- expect(screen.getByRole('button', { name: 'Generate video' }).disabled).toBe(false);
+ expect(screen.getByRole('button', { name: 'Render' }).disabled).toBe(false);
});
it('warns about uncovered Grok time and splits with the original scene/backend arguments only beyond the epsilon', () => {
@@ -315,3 +315,25 @@ describe('scene timing and provider presentation (#11046)', () => {
expect(onMergeNext).toHaveBeenLastCalledWith('timing', null);
});
});
+
+describe('Render follows the shot locks', () => {
+ // Uniquely catches Render staying live on a shot whose still is unlocked, or whose video is locked.
+ it('needs the still locked to render, and refuses a locked video until it is unlocked', async () => {
+ const { ShotLockContext } = await import('./ShotLock.jsx');
+ const scene = { sceneId: 's1', prompt: 'She spins the reel', referenceImageId: 'still.png', videoHistoryId: 'clip-1', startSec: 0, endSec: 4, takes: [] };
+ const onGenerateVideo = vi.fn();
+ const card = (still, clip) => (
+ <ShotLockContext.Provider value={{ locks: { s1: still }, clips: { s1: clip }, toggle: () => {}, busy: false }}>
+ <SceneCard scene={scene} index={0} expanded onEditLocal={() => {}} onSave={() => {}} onGenerateVideo={onGenerateVideo} falVideoSettings={{ backend: 'local' }} />
+ </ShotLockContext.Provider>
+ );
+ const { rerender } = render(card('open', 'open'));
+ expect(screen.getByRole('button', { name: 'Render again' })).toHaveProperty('title', 'Lock the still first');
+ rerender(card('locked', 'locked'));
+ expect(screen.getByRole('button', { name: 'Render again' }).disabled).toBe(true);
+ expect(screen.getByRole('button', { name: 'Render again' }).title).toMatch(/^Video locked/);
+ rerender(card('locked', 'open'));
+ fireEvent.click(screen.getByRole('button', { name: 'Render again' }));
+ expect(onGenerateVideo).toHaveBeenCalledWith(scene);
+ });
+});
diff --git a/client/src/components/musicVideo/SceneRenderTarget.jsx b/client/src/components/musicVideo/SceneRenderTarget.jsx
new file mode 100644
index 0000000000..705624596e
--- /dev/null
+++ b/client/src/components/musicVideo/SceneRenderTarget.jsx
@@ -0,0 +1,57 @@
+import { FAL_DEFAULT_IMAGE_VIDEO_MODEL, FAL_IMAGE_VIDEO_MODELS, describeFalVideoRate, getFalVideoModel } from '../../lib/falVideoModels.js';
+
+/**
+ * Where one shot's clip renders, picked on its card: the project's saved
+ * renderer, local LTX, Grok, or a fal.ai model. LTX is local only, so fal
+ * offers only its curated start-frame models; a lip-synced or music-driven
+ * shot renders on fal's source-audio route, so fal is one choice there, and
+ * Grok (no audio) renders cutaways only.
+ * The pick is a value string: '' (saved), 'local', 'grok', 'fal' or 'fal:<modelId>'.
+ */
+const BACKEND_LABELS = { local: 'Local LTX', grok: 'Grok', fal: 'fal.ai' };
+
+function savedLabel(saved) {
+ if (saved.backend === 'fal') return `fal.ai · ${getFalVideoModel(saved.falModelId || FAL_DEFAULT_IMAGE_VIDEO_MODEL)?.label || 'video'}`;
+ return BACKEND_LABELS[saved.backend] || 'install default';
+}
+
+export function renderTargetOptions({ performance, saved }) {
+ return [
+ { value: '', label: `Project setting · ${savedLabel(saved)}` },
+ { value: 'local', label: 'Local LTX' },
+ { value: 'grok', label: performance ? 'Grok (cutaways only)' : 'Grok', disabled: performance },
+ ...(performance
+ ? [{ value: 'fal', label: 'fal.ai (song-driven)' }]
+ : FAL_IMAGE_VIDEO_MODELS.map((model) => {
+ const rate = describeFalVideoRate(model.id);
+ return { value: `fal:${model.id}`, label: `fal.ai · ${model.label}${rate ? ` · ${rate}` : ''}` };
+ })),
+ ];
+}
+
+/** The settings overrides a pick makes for this render, or null for the project's saved renderer. */
+export function renderTargetOverrides(value, saved) {
+ if (!value) return null;
+ if (!value.startsWith('fal')) return { backend: value };
+ const falModelId = value.slice(4) || null;
+ if (!falModelId) return { backend: 'fal' };
+ // Each model has its own resolutions, so the saved one only carries over to the saved model.
+ const sameModel = falModelId === (saved.falModelId || FAL_DEFAULT_IMAGE_VIDEO_MODEL);
+ // A picked model is the one this render uses, end frame or not.
+ return { backend: 'fal', falModelId, falEndFrameModelId: falModelId, ...(sameModel ? {} : { falResolution: null, falDuration: null }) };
+}
+
+export default function SceneRenderTarget({ id, value, onChange, performance, saved, disabled = false }) {
+ return (
+ <>
+ <label htmlFor={id} className="text-xs">Render on</label>
+ <select id={id} value={value} onChange={(e) => onChange(e.target.value)} disabled={disabled}
+ title="Where this shot's clip renders. Only this shot; the project setting stays as it is."
+ className="min-w-0 max-w-full flex-1 basis-48 bg-port-bg border border-port-border rounded px-1 py-1 text-xs min-h-[44px] sm:min-h-0 sm:flex-none disabled:opacity-50">
+ {renderTargetOptions({ performance, saved }).map((option) => (
+ <option key={option.value} value={option.value} disabled={option.disabled}>{option.label}</option>
+ ))}
+ </select>
+ </>
+ );
+}
diff --git a/client/src/components/musicVideo/stages/BoardStage.jsx b/client/src/components/musicVideo/stages/BoardStage.jsx
index b7aee91459..cebdf5905c 100644
--- a/client/src/components/musicVideo/stages/BoardStage.jsx
+++ b/client/src/components/musicVideo/stages/BoardStage.jsx
@@ -193,6 +193,7 @@ export default function BoardStage({ board }) {
videoProgress={sceneMedia.videoSceneProgress?.[scene.sceneId]}
settingsSaving={videoSettings.saving}
videoBlockedReason={videoSettings.videoBlockedReason}
+ videoBlockedReasonFor={videoSettings.blockedReasonFor}
lipSyncBackend={lipSyncBackend}
songDurationSec={songDurationSec}
footageOptional={attentionCtx.footageOptional}
diff --git a/client/src/hooks/useMusicVideoModelSettings.js b/client/src/hooks/useMusicVideoModelSettings.js
index f56de184fb..b656d7d2ae 100644
--- a/client/src/hooks/useMusicVideoModelSettings.js
+++ b/client/src/hooks/useMusicVideoModelSettings.js
@@ -105,11 +105,13 @@ export default function useMusicVideoModelSettings({ project, onProjectPatch } =
// mirrors the general Video Gen page: an unconfigured backend is a clear
// preflight reason rather than a request that reaches the server only to
// fail with FAL_NOT_CONFIGURED (#8968) — no silent fallback to local/Grok.
- const videoBlockedReason = audioReactiveSelected && !audioReactiveReady
+ // `blockedReasonFor` answers the same for a one-shot render with other settings (a scene card's Render on pick).
+ const blockedReasonFor = (pick) => (pick.backend === 'local' && pick.generationMode === 'audioReactive' && !audioReactiveReady
? 'Audio-reactive generation requires an installed LTX-2.3 audio-reactive LoRA and an LTX-2.3 local model'
- : settings.backend === 'fal' && !falEnabled
+ : pick.backend === 'fal' && !falEnabled
? 'No fal.ai API key configured — set it in Settings → Video Gen (or the FAL_KEY env var) first'
- : null;
+ : null);
+ const videoBlockedReason = blockedReasonFor(settings);
const change = (patch) => {
if (!project || saving) return;
@@ -175,6 +177,7 @@ export default function useMusicVideoModelSettings({ project, onProjectPatch } =
audioReactiveReady,
audioReactiveSelected,
videoBlockedReason,
+ blockedReasonFor,
change,
changeFramePin,
};
diff --git a/client/src/hooks/useMusicVideoSceneMedia.js b/client/src/hooks/useMusicVideoSceneMedia.js
index c4cbccd721..200c8c1475 100644
--- a/client/src/hooks/useMusicVideoSceneMedia.js
+++ b/client/src/hooks/useMusicVideoSceneMedia.js
@@ -345,13 +345,17 @@ export default function useMusicVideoSceneMedia({ project, videoSettings, applyS
* Returns a promise that always resolves to `{ ok }` — see generateFrame's
* doc comment. `revisionId` (optional) is the revision hook's kickoff tag (#9011).
*/
- const generateSceneVideo = (scene, { revisionId, onJob } = {}) => {
+ const generateSceneVideo = (scene, { revisionId, onJob, target = null } = {}) => {
if (!scene.referenceImageId) { toast.error('Generate a reference frame first'); return Promise.resolve({ ok: false }); }
const problem = shotActionContractProblem(scene.direction?.actionContract, scene);
if (problem) { toast.error(problem); return Promise.resolve({ ok: false }); }
const basePrompt = buildShotPrompt(scene);
if (!basePrompt) { toast.error('Add a shot prompt first'); return Promise.resolve({ ok: false }); }
- const { settings, audioReactiveSelected, detectedAudioReactiveLora, videoBlockedReason } = videoSettings;
+ // `target` renders this one shot elsewhere (a scene card's Render on pick) without changing the saved setting.
+ const settings = target ? { ...videoSettings.settings, ...target } : videoSettings.settings;
+ const { detectedAudioReactiveLora } = videoSettings;
+ const audioReactiveSelected = target ? settings.backend === 'local' && settings.generationMode === 'audioReactive' : videoSettings.audioReactiveSelected;
+ const videoBlockedReason = target && videoSettings.blockedReasonFor ? videoSettings.blockedReasonFor(settings) : videoSettings.videoBlockedReason;
if (videoBlockedReason) { toast.error(videoBlockedReason); return Promise.resolve({ ok: false }); }
// #8977: a performance shot lip-syncs to the master recording, which only a
// verified source-audio provider can do — never a cutaway lane with an
diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsx
index 9dc71b97d1..f5a24e4866 100644
--- a/client/src/pages/MusicVideo.test.jsx
+++ b/client/src/pages/MusicVideo.test.jsx
@@ -1037,7 +1037,7 @@ describe('MusicVideo project video renderer', () => {
expect(await screen.findByLabelText('Scene video renderer')).toHaveProperty('value', '');
closeSettings();
await openStage('produce');
- fireEvent.click(screen.getByRole('button', { name: /^Generate video$/ }));
+ fireEvent.click(screen.getByRole('button', { name: /^Render$/ }));
await waitFor(() => expect(generateVideo).toHaveBeenCalled());
expect(generateVideo.mock.calls.at(-1)[0]).not.toHaveProperty('backend');
expect(generateVideo.mock.calls.at(-1)[0]).not.toHaveProperty('modelId');
@@ -1073,7 +1073,7 @@ describe('MusicVideo project video renderer', () => {
closeSettings();
await openStage('produce');
- fireEvent.click(screen.getByRole('button', { name: /^Generate video$/ }));
+ fireEvent.click(screen.getByRole('button', { name: /^Render$/ }));
await waitFor(() => expect(generateVideo).toHaveBeenCalledWith(expect.objectContaining({
backend: 'local',
modelId: 'ltx23_distilled_q4',
@@ -1120,7 +1120,7 @@ describe('MusicVideo project video renderer', () => {
closeSettings();
await openStage('produce');
- fireEvent.click(screen.getByRole('button', { name: /^Generate video$/ }));
+ fireEvent.click(screen.getByRole('button', { name: /^Render$/ }));
await waitFor(() => expect(generateVideo).toHaveBeenCalledWith(expect.objectContaining({
backend: 'local',
modelId: 'ltx23_distilled_q4',
@@ -1187,7 +1187,7 @@ describe('MusicVideo project video renderer', () => {
reactions: [{ startSec: 1, endSec: 2, subject: 'Listener', description: 'Turns back' }] };
await openProject({ ...PROJECT_NO_CLIP, videoSettings: { backend: 'fal', falDuration: 6 },
scenes: [{ ...PROJECT_NO_CLIP.scenes[0], startSec: 0, endSec: 4, direction: { actionContract } }] }, 'produce');
- fireEvent.click(await findEnabledByRole('button', { name: /^Generate video$/ }));
+ fireEvent.click(await findEnabledByRole('button', { name: /^Render$/ }));
await waitFor(() => expect(generateVideo).toHaveBeenCalled());
const prompt = generateVideo.mock.calls.at(-1)[0].prompt;
expect(prompt).toContain('Action 0.000s–1.000s: Singer');
@@ -1213,7 +1213,7 @@ describe('MusicVideo project video renderer', () => {
await openStage('produce');
// No model pin: the default Hailuo-02 image-to-video take, priced before it is paid for.
expect((await screen.findByTestId('fal-cutaway-plan')).textContent).toContain('est. $0.27 (6s at 768P)');
- fireEvent.click(await findEnabledByRole('button', { name: /^Generate video$/ }));
+ fireEvent.click(await findEnabledByRole('button', { name: /^Render$/ }));
await waitFor(() => expect(generateVideo).toHaveBeenCalledWith(expect.objectContaining({
backend: 'fal',
falDuration: 6,
@@ -1226,6 +1226,28 @@ describe('MusicVideo project video renderer', () => {
expect(generateVideo.mock.calls.at(-1)[0]).not.toHaveProperty('disableAudio');
});
+ // Uniquely catches the card's Render on pick being ignored, or rewriting the project's saved renderer.
+ it('renders one shot on the fal.ai model picked on its card, priced there, without changing the project renderer', async () => {
+ getVideoGenStatus.mockResolvedValueOnce({ connected: true, defaultModel: 'ltx23_distilled_q4', falEnabled: true,
+ models: [{ id: 'ltx23_distilled_q4', name: 'LTX-2.3 Distilled Q4', runtime: 'ltx2' }] });
+ generateVideo.mockResolvedValue({ jobId: 'fal-pick-job' });
+ await openProject({ ...PROJECT_NO_CLIP, videoSettings: { backend: 'local' } });
+ await openStage('produce');
+ const render = within(await screen.findByRole('region', { name: 'Render' }));
+ const pick = render.getByLabelText('Render on');
+ expect(pick.value).toBe('');
+ expect(within(pick).getByRole('option', { name: /^fal\.ai · .*Kling/ })).toBeTruthy();
+ expect(within(pick).queryByRole('option', { name: /LTX.*fal|fal.*LTX/ })).toBeNull();
+ fireEvent.change(pick, { target: { value: 'fal:fal-ai/minimax/hailuo-02/standard/image-to-video' } });
+ expect(render.getByText(/^est\. \$/)).toBeTruthy();
+ fireEvent.click(render.getByRole('button', { name: /^Render$/ }));
+ await waitFor(() => expect(generateVideo).toHaveBeenCalledWith(expect.objectContaining({
+ backend: 'fal', falModelId: 'fal-ai/minimax/hailuo-02/standard/image-to-video', mode: 'image', sourceImageFile: 'img1',
+ })));
+ expect(generateVideo.mock.calls.at(-1)[0]).not.toHaveProperty('modelId');
+ expect(updateMusicVideoProject.mock.calls.some(([, patch]) => patch?.videoSettings)).toBe(false);
+ });
+
it('renders a cutaway on the picked fal.ai model at the shot-covering length, sending exactly the take it prices', async () => {
getVideoGenStatus.mockResolvedValueOnce({ connected: true, defaultModel: '', falEnabled: true, models: [] });
generateVideo.mockResolvedValue({ jobId: 'fal-h3-job' });
@@ -1237,7 +1259,7 @@ describe('MusicVideo project video renderer', () => {
// A 7.2s shot on H3 Max (5–15s whole seconds) renders 8s at $0.16/s.
expect((await screen.findByTestId('fal-cutaway-plan')).textContent).toContain('est. $1.28 (8s at 1080P)');
- fireEvent.click(await findEnabledByRole('button', { name: /^Generate video$/ }));
+ fireEvent.click(await findEnabledByRole('button', { name: /^Render$/ }));
await waitFor(() => expect(generateVideo).toHaveBeenCalledWith(expect.objectContaining({
backend: 'fal', falModelId: 'minimax/h3-max/image-to-video', falDuration: 8, falResolution: '1080P',
})));
@@ -1259,7 +1281,7 @@ describe('MusicVideo project video renderer', () => {
// exactly the "no fal.ai API key configured" install this covers.
await openProject({ ...PROJECT_NO_CLIP, videoSettings: { backend: 'fal' } }, 'produce');
- const generate = await screen.findByRole('button', { name: /^Generate video$/ });
+ const generate = await screen.findByRole('button', { name: /^Render$/ });
expect(generate).toBeDisabled();
expect(generate).toHaveProperty('title', expect.stringContaining('No fal.ai API key configured'));
fireEvent.click(generate);
@@ -1286,7 +1308,7 @@ describe('MusicVideo project video renderer', () => {
closeSettings();
await openStage('produce');
expect(await screen.findByText(/Grok video is cutaway-only/)).toBeTruthy();
- const generate = await screen.findByRole('button', { name: /^Generate video$/ });
+ const generate = await screen.findByRole('button', { name: /^Render$/ });
expect(generate).toBeDisabled();
fireEvent.click(generate);
expect(generateVideo).not.toHaveBeenCalled();
@@ -1305,7 +1327,7 @@ describe('MusicVideo project video renderer', () => {
expect(plan.textContent).toMatch(/shot starts 1\.7[78]s into the take/);
// The padded 5.05s window at the 1080P lip-sync default ($0.16/s).
expect(plan.textContent).toContain('est. $0.81 (5.05s at 1080P)');
- fireEvent.click(await findEnabledByRole('button', { name: /^Generate video$/ }));
+ fireEvent.click(await findEnabledByRole('button', { name: /^Render$/ }));
await waitFor(() => expect(generateVideo).toHaveBeenCalledWith(expect.objectContaining({
backend: 'fal', mode: 'image', sourceImageFile: 'img1', falResolution: '1080P',
})));
@@ -1354,7 +1376,7 @@ describe('MusicVideo project video renderer', () => {
}, 'produce');
expect(await screen.findByText(/Grok renders a 10s clip for this 7\.2s cutaway/)).toBeTruthy();
- fireEvent.click(await findEnabledByRole('button', { name: /^Generate video$/ }));
+ fireEvent.click(await findEnabledByRole('button', { name: /^Render$/ }));
await waitFor(() => expect(generateVideo).toHaveBeenCalledWith(expect.objectContaining({
backend: 'grok', grokDuration: 10,
prompt: expect.stringContaining('around 2.0s: camera pushes in'),
@@ -1396,7 +1418,7 @@ describe('MusicVideo restricted-model license gate', () => {
generateVideo.mockResolvedValue({ jobId: 'gated-job' });
await openProject(PROJECT_NO_CLIP, 'produce');
- const generate = await findEnabledByRole('button', { name: /^Generate video$/ });
+ const generate = await findEnabledByRole('button', { name: /^Render$/ });
expect(screen.queryByRole('checkbox', { name: /I am eligible/ })).toBeNull();
fireEvent.click(generate);
await waitFor(() => expect(generateVideo).toHaveBeenCalled());
diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.js
index 5577db4ac4..a248872186 100644
--- a/server/lib/musicVideoValidation.js
+++ b/server/lib/musicVideoValidation.js
@@ -1472,6 +1472,8 @@ export const musicVideoSceneReorderSchema = z.object({
// the lane the director will render with; omitted/null = the project's pin.
export const musicVideoSceneSplitSchema = z.object({
backend: z.enum(['local', 'grok', 'fal']).nullable().optional(),
+ // Split the shot in two at this song time instead of by the backend's longest take.
+ atSec: z.number().finite().nonnegative().optional(),
}).strict();
// Autonomous shot planner (#1855): propose a scene per analyzed audio section.
diff --git a/server/routes/musicVideo.js b/server/routes/musicVideo.js
index a8a90701d3..73d7a06075 100644
--- a/server/routes/musicVideo.js
+++ b/server/routes/musicVideo.js
@@ -1489,9 +1489,10 @@ router.post('/:id/scenes/reorder', asyncHandler(async (req, res) => {
// Split a shot its backend cannot render in one take (#8977): a performance
// longer than the lip-sync window, a Grok cutaway longer than its longest clip.
+// With `atSec`, cut it in two at that song time instead.
router.post('/:id/scenes/:sceneId/split', asyncHandler(async (req, res) => {
- const { backend } = validateRequest(musicVideoSceneSplitSchema, req.body ?? {});
- res.json(await splitProjectScene(req.params.id, req.params.sceneId, { backend }));
+ const { backend, atSec } = validateRequest(musicVideoSceneSplitSchema, req.body ?? {});
+ res.json(await splitProjectScene(req.params.id, req.params.sceneId, { backend, atSec }));
}));
// Merge a scene with the next one — the inverse of split.
diff --git a/server/routes/musicVideoSceneSplit.test.js b/server/routes/musicVideoSceneSplit.test.js
index c7b54e0d73..672c0abecf 100644
--- a/server/routes/musicVideoSceneSplit.test.js
+++ b/server/routes/musicVideoSceneSplit.test.js
@@ -109,4 +109,32 @@ describe('POST /:id/scenes/:sceneId/split', () => {
expect((await split('mvs-missing')).status).toBe(404);
expect((await projects.getProject(project.id)).scenes).toHaveLength(2);
});
+
+ // Uniquely catches a cut at a chosen time losing the director's still locks, or a new mid-song shot landing at the end of the board.
+ it('cuts a shot in two at a chosen time, keeping its still locked on both pieces and the board in song order', async () => {
+ const { setShotLocks, shotLocks } = await import('../services/musicVideo/productionReview.js');
+ const intro = await projects.addProjectScene(project.id, { label: 'Intro', startSec: 0, endSec: 10, prompt: 'Wide room' });
+ const outro = await projects.addProjectScene(project.id, { label: 'Outro', startSec: 20, endSec: 30, prompt: 'Door' });
+ // Added after the outro but timed between the two: it goes in between.
+ const middle = await projects.addProjectScene(project.id, { label: 'Middle', startSec: 10, endSec: 20, prompt: 'Close-up' });
+ expect((await projects.getProject(project.id)).scenes.map((s) => [s.sceneId, s.order])).toEqual([[intro.sceneId, 0], [middle.sceneId, 1], [outro.sceneId, 2]]);
+ await projects.updateScene(project.id, middle.sceneId, { referenceImageId: 'singer.png' });
+ await projects.mutateProjectRecord(project.id, (current) => ({ project: setShotLocks(current, { sceneIds: [intro.sceneId, middle.sceneId], locked: true }) }));
+
+ expect((await split(middle.sceneId, { atSec: 25 })).body.code).toBe('MUSIC_VIDEO_SPLIT_OUT_OF_RANGE');
+ const res = await split(middle.sceneId, { atSec: 13.5 });
+ expect(res.status).toBe(200);
+ const [first, second] = res.body.scenes;
+ expect([first.sceneId, first.startSec, first.endSec, second.startSec, second.endSec]).toEqual([middle.sceneId, 10, 13.5, 13.5, 20]);
+ expect(second).toMatchObject({ prompt: 'Close-up', referenceImageId: 'singer.png', videoHistoryId: null });
+
+ // A shot added after the split, mid-song, keeps every lock in place.
+ const insert = await projects.addProjectScene(project.id, { label: 'Insert', startSec: 5, endSec: 6 });
+ const stored = await projects.getProject(project.id);
+ expect(stored.scenes.map((s) => s.sceneId)).toEqual([intro.sceneId, insert.sceneId, middle.sceneId, second.sceneId, outro.sceneId]);
+ expect(stored.scenes.map((s) => s.order)).toEqual([0, 1, 2, 3, 4]);
+ const locks = shotLocks(stored);
+ expect([locks[intro.sceneId], locks[middle.sceneId], locks[second.sceneId], locks[outro.sceneId], locks[insert.sceneId]])
+ .toEqual(['locked', 'locked', 'locked', 'open', 'open']);
+ });
});
diff --git a/server/services/musicVideo/productionReview.js b/server/services/musicVideo/productionReview.js
index dd9adb5aad..5aa5e55f48 100644
--- a/server/services/musicVideo/productionReview.js
+++ b/server/services/musicVideo/productionReview.js
@@ -247,6 +247,39 @@ export function preserveAutomatedShotLocks(before, after, source) {
return { project: next, rejected: true };
}
+/**
+ * Keep the director's still locks through a change that adds shots or reshapes
+ * the board (a new shot, a split). Every shot locked before stays locked by its
+ * own timing-free lock, even one covered only by a whole-board approval the
+ * change stales; `from` maps a new shot to the shot it was cut from, and a new
+ * piece of a locked still is locked too. Clip locks are not copied: a new piece
+ * has no clip of its own.
+ */
+export function carryShotLocks(before, after, { from = {} } = {}) {
+ const locks = shotLocks(before);
+ if (!locks) return after;
+ const held = before.productionReview?.shotApprovals || {};
+ const board = before.productionReview?.approvals?.storyboard;
+ const lockOf = scene => held[scene.sceneId] || { ...board, fromBoardApproval: true };
+ const shotApprovals = { ...after.productionReview?.shotApprovals };
+ let carried = false;
+ for (const scene of before.scenes || []) {
+ if (locks[scene.sceneId] !== 'locked' || !after.scenes?.some(s => s.sceneId === scene.sceneId)) continue;
+ const own = held[scene.sceneId];
+ if (own?.v === STILL_LOCK_VERSION) continue;
+ shotApprovals[scene.sceneId] = stillLock(before, scene, lockOf(scene));
+ carried = true;
+ }
+ for (const [pieceId, sourceId] of Object.entries(from)) {
+ const source = before.scenes?.find(s => s.sceneId === sourceId);
+ const piece = after.scenes?.find(s => s.sceneId === pieceId);
+ if (!source || !piece || locks[sourceId] !== 'locked') continue;
+ shotApprovals[pieceId] = stillLock(after, piece, lockOf(source));
+ carried = true;
+ }
+ return carried ? { ...after, productionReview: { ...after.productionReview, shotApprovals } } : after;
+}
+
/**
* Lock or unlock Board shots for the director. A lock binds to the shot as it is now.
* `stage: 'video'` locks or unlocks a video shot's selected clip, which needs its
diff --git a/server/services/musicVideo/productionReview.storyboard.test.js b/server/services/musicVideo/productionReview.storyboard.test.js
index 4403a312f5..742ce3ccd6 100644
--- a/server/services/musicVideo/productionReview.storyboard.test.js
+++ b/server/services/musicVideo/productionReview.storyboard.test.js
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
-import { productionReadiness, productionAlignmentBasis, approveProductionStage, carryProductionApprovals, assertShotApproval, assertClipUnlocked, setShotLocks } from './productionReview.js';
-import { applySceneUpdate, mergeNextScene, removeScene } from './projectsLogic.js';
+import { productionReadiness, productionAlignmentBasis, approveProductionStage, carryProductionApprovals, carryShotLocks, assertShotApproval, assertClipUnlocked, setShotLocks } from './productionReview.js';
+import { addScenes, applySceneUpdate, mergeNextScene, removeScene } from './projectsLogic.js';
const WORD_PROBLEM = /bounded, positive-duration word timings/;
const SHOT_PROBLEM = /^Complete timing, action, staging, camera and transition/;
@@ -108,6 +108,14 @@ describe('the director trimming an approved storyboard', () => {
expect(productionReadiness(merged).storyboard.shotLocks).toEqual({ s1: 'locked', s3: 'locked' });
});
+ // Uniquely catches new shots staling the whole-board approval that was all that locked the old ones.
+ it('keeps the approved shots locked when the planner adds shots, and leaves the new ones open', () => {
+ const board = approvedBoard();
+ const { project: added, scenes: [fresh] } = addScenes(board, [{ label: 'Tag', startSec: 8, endSec: 9, visualIntent: 'Lights out', framePrompt: 'Black' }]);
+ expect(productionReadiness(carryShotLocks(board, added)).storyboard.shotLocks)
+ .toEqual({ s1: 'locked', s2: 'locked', s3: 'locked', [fresh.sceneId]: 'open' });
+ });
+
// Uniquely catches a lyric anchor dropped from a row slipping past the board check.
it('still blocks the board on a storyboard row that drops its lyric anchor', () => {
const board = approvedBoard();
diff --git a/server/services/musicVideo/projects.js b/server/services/musicVideo/projects.js
index 02b54ab321..04f8431bb2 100644
--- a/server/services/musicVideo/projects.js
+++ b/server/services/musicVideo/projects.js
@@ -227,9 +227,13 @@ export async function setProjectMidiTranscription(id, midi) {
return next;
}
+/** Add a director's shot at its time; shots locked before stay locked. */
export async function addProjectScene(id, sceneInput) {
- const scene = await (await selectBackend()).addProjectScene(id, sceneInput);
- emitRecordUpdated('musicVideoProject', id);
+ const [{ addScene }, { carryShotLocks }] = await Promise.all([import('./projectsLogic.js'), import('./productionReview.js')]);
+ const { scene } = await mutateProjectRecord(id, (current) => {
+ const outcome = addScene(current, sceneInput);
+ return { ...outcome, project: carryShotLocks(current, outcome.project) };
+ });
return scene;
}
@@ -240,13 +244,11 @@ export async function addProjectScene(id, sceneInput) {
* concurrent edit with stale state.
*/
export async function addProjectScenes(id, sceneInputs, { source = null } = {}) {
- if (source) {
- const { addScenes } = await import('./projectsLogic.js');
- return mutateProjectRecord(id, current => addScenes(current, sceneInputs), { source });
- }
- const { project, scenes } = await (await selectBackend()).addProjectScenes(id, sceneInputs);
- emitRecordUpdated('musicVideoProject', id);
- return { project, scenes };
+ const [{ addScenes }, { carryShotLocks }] = await Promise.all([import('./projectsLogic.js'), import('./productionReview.js')]);
+ return mutateProjectRecord(id, (current) => {
+ const outcome = addScenes(current, sceneInputs);
+ return { ...outcome, project: carryShotLocks(current, outcome.project) };
+ }, { source });
}
/**
@@ -282,13 +284,17 @@ export async function reorderProjectScenes(id, orderedIds) {
/**
* Split a shot longer than its backend renders in one take into contiguous
- * scenes on lyric/phrase boundaries (#8977, projectsLogic.splitScene).
- * Returns `{ project, scenes }` — the persisted project and the pieces.
+ * scenes on lyric/phrase boundaries (#8977, projectsLogic.splitScene), or in
+ * two at `options.atSec`. A locked still stays locked on every piece. Returns `{ project, scenes }` — the persisted project and the pieces.
*/
export async function splitProjectScene(id, sceneId, options = {}) {
await assertClipsUnlocked(id, [sceneId]);
- const { splitScene } = await import('./projectsLogic.js');
- return mutateProjectRecord(id, (current) => splitScene(current, sceneId, options));
+ const [{ splitScene }, { carryShotLocks }] = await Promise.all([import('./projectsLogic.js'), import('./productionReview.js')]);
+ return mutateProjectRecord(id, (current) => {
+ const outcome = splitScene(current, sceneId, options);
+ const from = Object.fromEntries(outcome.scenes.slice(1).map((piece) => [piece.sceneId, sceneId]));
+ return { ...outcome, project: carryShotLocks(current, outcome.project, { from }) };
+ });
}
/**
diff --git a/server/services/musicVideo/projectsLogic.js b/server/services/musicVideo/projectsLogic.js
index f98d40a932..94caebda94 100644
--- a/server/services/musicVideo/projectsLogic.js
+++ b/server/services/musicVideo/projectsLogic.js
@@ -526,9 +526,16 @@ function buildScene(input, { order }) {
};
}
+/** Where a new scene goes: before the first timed scene that starts after it; untimed scenes go last. */
+function insertByTime(scenes, scene) {
+ const at = scene.startSec;
+ const idx = typeof at === 'number' ? scenes.findIndex((s) => typeof s.startSec === 'number' && s.startSec > at) : -1;
+ return idx < 0 ? [...scenes, scene] : [...scenes.slice(0, idx), scene, ...scenes.slice(idx)];
+}
+
/**
- * Append a scene to the board. Validates the input, assigns a sceneId and the
- * next order index. Returns `{ project, scene }`. A thin single-item wrapper
+ * Add a scene to the board at its time. Validates the input, assigns a sceneId and
+ * renumbers order. Returns `{ project, scene }`. A thin single-item wrapper
* over `addScenes` so the validate/build/order logic lives in exactly one
* place.
*/
@@ -538,23 +545,26 @@ export function addScene(project, sceneInput) {
}
/**
- * Append several scenes to the board in one pass (the autonomous planner,
+ * Add several scenes to the board in one pass (the autonomous planner,
* #1855) — a single `touch`/persist instead of N sequential addScene calls, so
* a 10-section plan is one write (and one peer-sync emit) instead of ten.
- * Returns `{ project, scenes }` (the newly-created scenes, in input order).
+ * A timed scene goes in at its time, so the board stays in song order; an
+ * untimed one is appended. Returns `{ project, scenes }` (the newly-created
+ * scenes, in input order).
*/
export function addScenes(project, sceneInputs) {
const list = Array.isArray(sceneInputs) ? sceneInputs : [];
- const existing = project.scenes || [];
- const added = [];
- let order = existing.length;
+ let scenes = project.scenes || [];
+ const ids = [];
for (const input of list) {
const data = parseSceneOrThrow(musicVideoSceneCreateSchema, input);
- added.push(buildScene(data, { order }));
- order += 1;
+ const scene = buildScene(data, { order: 0 });
+ ids.push(scene.sceneId);
+ scenes = insertByTime(scenes, scene);
}
- const next = touch(project, { scenes: [...existing, ...added] });
- return { project: next, scenes: added };
+ scenes = scenes.map((s, i) => (s.order === i ? s : { ...s, order: i }));
+ const next = touch(project, { scenes });
+ return { project: next, scenes: ids.map((id) => scenes.find((s) => s.sceneId === id)) };
}
/**
@@ -727,23 +737,19 @@ function lyricTextWithin(cues, startSec, endSec) {
* piece is a new scene placed right after it, carrying the shot's direction
* and the selected reference frame (as a take, so the frame is ready to
* animate) but no clip — the old clip was generated for the whole span. Each
- * piece's `lyricText` is the timed lines sung inside it. Returns `{ project, scenes }` (all pieces, in
- * order); throws 400 when the shot is untimed or already fits one take.
+ * piece's `lyricText` is the timed lines sung inside it. `atSec` instead cuts
+ * the shot in two at that song time, whatever the backend. Returns `{ project, scenes }` (all pieces, in
+ * order); throws 400 when the shot is untimed, already fits one take, or `atSec` falls outside it.
*/
-export function splitScene(project, sceneId, { backend = null } = {}) {
+export function splitScene(project, sceneId, { backend = null, atSec = 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 lane = backend || project.videoSettings?.backend || null;
- const maxSec = shotSplitLimit(scene, lane, project.videoSettings);
- if (maxSec == null) {
- throw new ServerError('This backend renders the shot at any length — there is nothing to split.', { status: 400, code: 'MUSIC_VIDEO_SPLIT_NOT_NEEDED' });
- }
- const plan = planShotSplit({
+ const plan = atSec != null ? splitAtTime(scene, atSec) : planShotSplit({
startSec: scene.startSec,
endSec: scene.endSec,
- maxSec,
+ maxSec: splitLimitOrThrow(project, scene, backend),
lyricCues: project.lyricCues,
phrases: project.phrases,
beats: project.audioAnalysis?.beats,
@@ -806,6 +812,29 @@ export function splitScene(project, sceneId, { backend = null } = {}) {
const timedSec = (v) => typeof v === 'number' && Number.isFinite(v);
+function splitLimitOrThrow(project, scene, backend) {
+ const maxSec = shotSplitLimit(scene, backend || project.videoSettings?.backend || null, project.videoSettings);
+ if (maxSec == null) {
+ throw new ServerError('This backend renders the shot at any length — there is nothing to split.', { status: 400, code: 'MUSIC_VIDEO_SPLIT_NOT_NEEDED' });
+ }
+ return maxSec;
+}
+
+/** Shortest piece a split at a chosen time may leave. */
+const MIN_SPLIT_PIECE_SEC = 0.1;
+
+/** Two pieces cut at `atSec`, which must fall inside the timed shot. */
+function splitAtTime(scene, atSec) {
+ const { startSec, endSec } = scene;
+ if (!timedSec(startSec) || !timedSec(endSec)) {
+ return { ok: false, code: 'MUSIC_VIDEO_SPLIT_UNTIMED', message: 'Give this shot a start and end time before splitting it.' };
+ }
+ if (atSec < startSec + MIN_SPLIT_PIECE_SEC || atSec > endSec - MIN_SPLIT_PIECE_SEC) {
+ return { ok: false, code: 'MUSIC_VIDEO_SPLIT_OUT_OF_RANGE', message: `Split inside the shot, between ${startSec + MIN_SPLIT_PIECE_SEC}s and ${endSec - MIN_SPLIT_PIECE_SEC}s.` };
+ }
+ return { ok: true, pieces: [{ startSec, endSec: atSec }, { startSec: atSec, endSec }] };
+}
+
/**
* Join a scene with the one after it — the inverse of `splitScene`. The first
* scene keeps its id, takes and selections and stretches to the next scene's