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

Back and Next shot buttons in the music video preview (#11208)

[._.]/ef71dc9601ce
diff --git a/client/src/components/musicVideo/CompositionPreviewPlayer.jsx b/client/src/components/musicVideo/CompositionPreviewPlayer.jsx
index e832516c7c..5810418bc8 100644
--- a/client/src/components/musicVideo/CompositionPreviewPlayer.jsx
+++ b/client/src/components/musicVideo/CompositionPreviewPlayer.jsx
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Pause, Play } from 'lucide-react';
import { normalizeTitleCard } from '../../../../server/lib/musicVideoTitleCard.js';
import useGeneratedPreview from '../../hooks/useGeneratedPreview.js';
+import ShotStepper from './ShotStepper.jsx';
const buttonCls = 'flex items-center gap-1 bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm min-h-[44px] sm:min-h-0 disabled:opacity-50';
@@ -33,9 +34,10 @@ const startsDeferred = (collapsed) => collapsed && window.matchMedia?.(DESKTOP_Q
* `seekRequest` (`{ t, n }`) moves the player from outside. `collapsed` hides
* the picture below `lg` until the dock is expanded or the viewport is desktop.
* `lyrics` previews timed lyrics instead of the document. `draft` previews the
- * candidate document.
+ * candidate document. `shotNav` adds Back and Next shot buttons (and the arrow
+ * keys) for the docked player.
*/
-export default function CompositionPreviewPlayer({ project, audioUrl, seekRequest = null, collapsed = false, draft = false, lyrics = false, scrubId: givenScrubId = null }) {
+export default function CompositionPreviewPlayer({ project, audioUrl, seekRequest = null, collapsed = false, draft = false, lyrics = false, shotNav = false, scrubId: givenScrubId = null }) {
const doc = lyrics ? { playthrough: true } : (draft ? project.composition?.documentDraft : project.composition?.document) || null;
const scrubId = givenScrubId || (lyrics ? 'mv-lyrics-scrub' : draft ? 'mv-doc-draft-scrub' : 'mv-doc-scrub');
const [wanted, setWanted] = useState(() => !startsDeferred(collapsed));
@@ -133,6 +135,7 @@ export default function CompositionPreviewPlayer({ project, audioUrl, seekReques
className="min-w-0 flex-1" />
<span className="text-xs text-port-text-muted tabular-nums">{timeLabel}</span>
</div>
+ {shotNav && <ShotStepper scenes={project.scenes} time={t} onSeek={seek} disabled={!preview.ready || failed} keys />}
{lyric && !lyrics && <p className="text-xs italic break-words" aria-live="off" data-testid="preview-lyric">♪ {lyric}</p>}
{audioUrl && <audio ref={audioRef} src={audioUrl} preload="none" className="hidden" onEnded={() => setPlaying(false)} />}
</div>
diff --git a/client/src/components/musicVideo/PreviewDock.jsx b/client/src/components/musicVideo/PreviewDock.jsx
index bc7516e7f8..a7d087b2c6 100644
--- a/client/src/components/musicVideo/PreviewDock.jsx
+++ b/client/src/components/musicVideo/PreviewDock.jsx
@@ -1,14 +1,16 @@
-import { useEffect, useRef } from 'react';
+import { useEffect, useRef, useState } from 'react';
import { useSearchParams } from 'react-router';
import { ChevronDown, ChevronUp, MonitorPlay } from 'lucide-react';
import CompositionPreviewPlayer from './CompositionPreviewPlayer.jsx';
import StoryboardAnimatic from './StoryboardAnimatic.jsx';
+import ShotStepper from './ShotStepper.jsx';
// A rendered file (the final render or a draft excerpt). Its clock starts at
// the clip's own start, so a seek to song time `t` lands at `t - startSec` and
-// is ignored outside it.
-function VideoPreview({ source, seekRequest, collapsed }) {
+// is ignored outside it. Back and Next step through the shots inside it.
+function VideoPreview({ source, scenes, seekRequest, collapsed }) {
const videoRef = useRef(null);
+ const [time, setTime] = useState(0);
const pending = useRef(null);
const applied = useRef(null);
const seekTo = (t, play = false) => {
@@ -24,17 +26,29 @@ function VideoPreview({ source, seekRequest, collapsed }) {
const t = seekRequest.t - source.startSec;
if (t >= 0 && (source.endSec == null || t <= source.endSec - source.startSec)) seekTo(t, !!seekRequest.play);
}, [seekRequest, source.startSec, source.endSec]);
+ const startSec = source.startSec || 0;
return (
- <video
- ref={videoRef}
- src={source.src}
- controls
- playsInline
- preload="metadata"
- onLoadedMetadata={() => { if (pending.current != null) { seekTo(pending.current); pending.current = null; } }}
- aria-label={source.id === 'final' ? 'Final render preview' : 'Draft excerpt preview'}
- className={`aspect-video max-h-[50vh] w-full rounded border border-port-border bg-black object-contain ${collapsed ? 'max-xl:hidden' : ''}`}
- />
+ <div className={`space-y-2 ${collapsed ? 'max-xl:hidden' : ''}`}>
+ <video
+ ref={videoRef}
+ src={source.src}
+ controls
+ playsInline
+ preload="metadata"
+ onLoadedMetadata={() => { if (pending.current != null) { seekTo(pending.current); pending.current = null; } }}
+ onTimeUpdate={(e) => setTime(e.currentTarget.currentTime)}
+ onSeeked={(e) => setTime(e.currentTarget.currentTime)}
+ aria-label={source.id === 'final' ? 'Final render preview' : 'Draft excerpt preview'}
+ className="aspect-video max-h-[50vh] w-full rounded border border-port-border bg-black object-contain"
+ />
+ <ShotStepper
+ scenes={scenes}
+ time={startSec + time}
+ onSeek={(t) => { seekTo(t - startSec); setTime(t - startSec); }}
+ range={{ startSec, endSec: source.endSec ?? null }}
+ keys
+ />
+ </div>
);
}
@@ -100,10 +114,10 @@ export default function PreviewDock({ project, sources, audioUrl, seekRequest, c
</p>
)}
{/* Folded below xl, the dock is one row: the player and its controls wait for the expand. */}
- {source?.kind === 'document' && <div className={collapsed ? 'max-xl:hidden' : ''}><CompositionPreviewPlayer project={project} audioUrl={audioUrl} seekRequest={seekRequest} collapsed={collapsed} /></div>}
- {source?.kind === 'lyrics' && <div className={collapsed ? 'max-xl:hidden' : ''}><CompositionPreviewPlayer project={project} audioUrl={audioUrl} seekRequest={seekRequest} collapsed={collapsed} lyrics /></div>}
+ {source?.kind === 'document' && <div className={collapsed ? 'max-xl:hidden' : ''}><CompositionPreviewPlayer project={project} audioUrl={audioUrl} seekRequest={seekRequest} collapsed={collapsed} shotNav /></div>}
+ {source?.kind === 'lyrics' && <div className={collapsed ? 'max-xl:hidden' : ''}><CompositionPreviewPlayer project={project} audioUrl={audioUrl} seekRequest={seekRequest} collapsed={collapsed} lyrics shotNav /></div>}
{source?.kind === 'animatic' && <StoryboardAnimatic project={project} audioUrl={audioUrl} seekRequest={seekRequest} collapsed={collapsed} />}
- {source?.kind === 'video' && <VideoPreview key={source.id} source={source} seekRequest={seekRequest} collapsed={collapsed} />}
+ {source?.kind === 'video' && <VideoPreview key={source.id} source={source} scenes={project.scenes} seekRequest={seekRequest} collapsed={collapsed} />}
</aside>
);
}
diff --git a/client/src/components/musicVideo/PreviewDock.test.jsx b/client/src/components/musicVideo/PreviewDock.test.jsx
new file mode 100644
index 0000000000..b4ee667ff1
--- /dev/null
+++ b/client/src/components/musicVideo/PreviewDock.test.jsx
@@ -0,0 +1,21 @@
+import { describe, expect, it } from 'vitest';
+import { fireEvent, render, screen } from '@testing-library/react';
+import { MemoryRouter } from 'react-router';
+import PreviewDock from './PreviewDock.jsx';
+
+describe('PreviewDock video shot steps', () => {
+ it('steps a draft excerpt through its own shots in song time', () => {
+ const project = { id: 'p', scenes: [{ startSec: 18 }, { startSec: 22 }, { startSec: 26 }, { startSec: 31 }] };
+ const sources = [{ id: 'draft-1', kind: 'video', label: 'Draft', src: '/data/videos/draft.mp4', startSec: 20, endSec: 30 }];
+ render(<MemoryRouter><PreviewDock project={project} sources={sources} audioUrl="/song.mp3" /></MemoryRouter>);
+ const video = screen.getByLabelText('Draft excerpt preview');
+ Object.defineProperty(video, 'readyState', { value: 4, configurable: true });
+ expect(screen.getByText('Shot – / 2')).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Next shot' }));
+ expect(video.currentTime).toBe(2);
+ fireEvent.click(screen.getByRole('button', { name: 'Next shot' }));
+ expect(video.currentTime).toBe(6);
+ expect(screen.getByText('Shot 2 / 2')).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Next shot' }).disabled).toBe(true);
+ });
+});
diff --git a/client/src/components/musicVideo/ShotStepper.jsx b/client/src/components/musicVideo/ShotStepper.jsx
new file mode 100644
index 0000000000..ec0b23996a
--- /dev/null
+++ b/client/src/components/musicVideo/ShotStepper.jsx
@@ -0,0 +1,71 @@
+import { useEffect, useRef } from 'react';
+import { SkipBack, SkipForward } from 'lucide-react';
+import { shouldIgnoreGlobalKey } from '../../lib/a11yKeyboard.js';
+
+// Back within this far into a shot goes to the shot before it; further in, to its own start.
+const RESTART_SEC = 1;
+// A seek lands a hair off the start it aimed at; this much counts as being on it.
+const ON_START_SEC = 0.05;
+
+const startsIn = (scenes, range) => (scenes || [])
+ .map((scene) => scene?.startSec)
+ .filter((start) => Number.isFinite(start)
+ && (!range || (start >= range.startSec - ON_START_SEC && (range.endSec == null || start < range.endSec))))
+ .sort((a, b) => a - b);
+
+/**
+ * Where Back and Next go from song time `t`: Back to the current shot's start
+ * when more than a second into it, else to the shot before; Next to the next
+ * shot's start. `range` (`{ startSec, endSec }`) keeps both inside a rendered
+ * excerpt. `index`/`count` name the shot on screen (1-based; 0 before the first).
+ */
+export function shotSteps(scenes, t, range = null) {
+ const starts = startsIn(scenes, range);
+ let current = -1;
+ starts.forEach((start, i) => { if (start <= t + ON_START_SEC) current = i; });
+ const back = current < 0
+ ? null
+ : t - starts[current] > RESTART_SEC || current === 0 ? starts[current] : starts[current - 1];
+ const next = starts[current + 1] ?? null;
+ return { back, next, index: current + 1, count: starts.length };
+}
+
+const buttonCls = 'flex min-h-[44px] min-w-[44px] shrink-0 items-center justify-center rounded border border-port-border bg-port-bg text-port-text disabled:opacity-40 sm:min-h-[28px] sm:min-w-[28px]';
+
+/**
+ * Back and Next buttons that jump the player to a shot's start, with the shot
+ * number between them. `onSeek(songSec)` moves the player and leaves it playing
+ * or paused as it was. `keys` also binds the left and right arrows on the page.
+ */
+export default function ShotStepper({ scenes, time, onSeek, range = null, disabled = false, keys = false, className = '' }) {
+ const { back, next, index, count } = shotSteps(scenes, time, range);
+ const latest = useRef({ back, next, onSeek, disabled });
+ latest.current = { back, next, onSeek, disabled };
+ useEffect(() => {
+ if (!keys) return undefined;
+ const onKey = (event) => {
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return;
+ // A focused player or slider already moves by itself on the arrows.
+ if (shouldIgnoreGlobalKey(event) || event.target?.closest?.('audio, video, input')) return;
+ const { back: to, next: forward, onSeek: seek, disabled: off } = latest.current;
+ const target = event.key === 'ArrowLeft' ? to : forward;
+ if (off || target == null) return;
+ event.preventDefault();
+ seek(target);
+ };
+ window.addEventListener('keydown', onKey);
+ return () => window.removeEventListener('keydown', onKey);
+ }, [keys]);
+ if (!count) return null;
+ return (
+ <div className={`flex min-w-0 items-center gap-1.5 text-[11px] text-port-text-muted ${className}`}>
+ <button type="button" onClick={() => onSeek(back)} disabled={disabled || back == null} aria-label="Previous shot" title="Previous shot" className={buttonCls}>
+ <SkipBack size={14} aria-hidden="true" />
+ </button>
+ <span className="whitespace-nowrap tabular-nums" aria-live="off">Shot {index || '–'} / {count}</span>
+ <button type="button" onClick={() => onSeek(next)} disabled={disabled || next == null} aria-label="Next shot" title="Next shot" className={buttonCls}>
+ <SkipForward size={14} aria-hidden="true" />
+ </button>
+ </div>
+ );
+}
diff --git a/client/src/components/musicVideo/ShotStepper.test.jsx b/client/src/components/musicVideo/ShotStepper.test.jsx
new file mode 100644
index 0000000000..05612eeec6
--- /dev/null
+++ b/client/src/components/musicVideo/ShotStepper.test.jsx
@@ -0,0 +1,34 @@
+import { describe, expect, it, vi } from 'vitest';
+import { fireEvent, render, screen } from '@testing-library/react';
+import ShotStepper, { shotSteps } from './ShotStepper.jsx';
+
+const scenes = [{ startSec: 4 }, { startSec: 0 }, { startSec: 8.5 }, { startSec: null }];
+
+describe('shotSteps', () => {
+ it('backs up to the shot start, or the shot before when at its start, and steps forward', () => {
+ expect(shotSteps(scenes, 6)).toEqual({ back: 4, next: 8.5, index: 2, count: 3 });
+ expect(shotSteps(scenes, 4.5)).toMatchObject({ back: 0, next: 8.5 });
+ expect(shotSteps(scenes, 3.98)).toMatchObject({ back: 0, next: 8.5, index: 2 });
+ expect(shotSteps(scenes, 0.2)).toMatchObject({ back: 0, next: 4, index: 1 });
+ expect(shotSteps(scenes, 9)).toMatchObject({ back: 4, next: null, index: 3 });
+ });
+
+ it('keeps a rendered excerpt to the shots inside it', () => {
+ expect(shotSteps(scenes, 5, { startSec: 4, endSec: 8 })).toEqual({ back: 4, next: null, index: 1, count: 1 });
+ });
+});
+
+describe('ShotStepper', () => {
+ it('jumps with the buttons and the arrow keys, leaving a focused slider its own arrows', () => {
+ const onSeek = vi.fn();
+ render(<><ShotStepper scenes={scenes} time={6} onSeek={onSeek} keys /><input type="range" aria-label="Scrub" /></>);
+ expect(screen.getByText('Shot 2 / 3')).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Next shot' }));
+ expect(onSeek).toHaveBeenLastCalledWith(8.5);
+ fireEvent.keyDown(window, { key: 'ArrowLeft' });
+ expect(onSeek).toHaveBeenLastCalledWith(4);
+ onSeek.mockClear();
+ fireEvent.keyDown(screen.getByLabelText('Scrub'), { key: 'ArrowRight' });
+ expect(onSeek).not.toHaveBeenCalled();
+ });
+});
diff --git a/client/src/components/musicVideo/StoryboardAnimatic.jsx b/client/src/components/musicVideo/StoryboardAnimatic.jsx
index 8e44dd5e5c..bb7a0f39c3 100644
--- a/client/src/components/musicVideo/StoryboardAnimatic.jsx
+++ b/client/src/components/musicVideo/StoryboardAnimatic.jsx
@@ -6,6 +6,7 @@ import { playthroughVersion } from './CompositionPreviewPlayer.jsx';
import { useVideoFileSrc } from '../../hooks/useVideoFileSrc.js';
import { selectedPerformanceInstruction } from '../../lib/musicVideoShotTiming.js';
import { normalizeTitleCard } from '../../../../server/lib/musicVideoTitleCard.js';
+import ShotStepper from './ShotStepper.jsx';
const timedShots = (scenes) => scenes.filter((scene) => Number.isFinite(scene?.startSec)).sort((a, b) => a.startSec - b.startSec);
@@ -240,6 +241,12 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
setTime(seekRequest.t);
if (seekRequest.play) audioRef.current.play?.()?.catch?.(() => {});
}, [seekRequest]);
+ // Back and Next move the song; it keeps playing or stays paused as it was.
+ const seekTo = useCallback((t) => {
+ if (!audioRef.current) return;
+ audioRef.current.currentTime = t;
+ setTime(t);
+ }, []);
const shot = shotAt(scenes, time);
const timed = timedShots(scenes);
const index = shot ? timed.indexOf(shot) : -1;
@@ -268,7 +275,12 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
</figure>
<div className="flex min-w-0 items-start gap-2">
<div className="min-w-0 flex-1 text-[11px] text-port-text-muted">
- {shot && <p>Shot {index + 1} of {timed.length} · {formatDurationSec(shot.startSec)}</p>}
+ {shot && (
+ <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
+ <ShotStepper scenes={timed} time={time} onSeek={seekTo} keys />
+ <span className="tabular-nums">{formatDurationSec(shot.startSec)}</span>
+ </div>
+ )}
{!cardInFrame && shot && !shot.referenceImageId && !shot.videoHistoryId && (
<p className="line-clamp-2 break-words">
<span className="font-medium text-port-text">{label}</span>{shot.visualIntent ? ` · ${shot.visualIntent}` : ''}
diff --git a/client/src/components/musicVideo/StoryboardAnimatic.test.jsx b/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
index b252760d62..632fc5541f 100644
--- a/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
+++ b/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
@@ -20,12 +20,12 @@ describe('StoryboardAnimatic', () => {
const { container } = render(<StoryboardAnimatic project={{ id: 'p', scenes }} audioUrl="/song.mp3" />);
expect(screen.getByText('Opening')).toBeTruthy();
expect(screen.getByText('Lights come up')).toBeTruthy();
- expect(screen.getByText('Shot 1 of 2 · 0:00')).toBeTruthy();
+ expect(screen.getByText('Shot 1 / 2')).toBeTruthy();
const audio = screen.getByLabelText('Song for the storyboard animatic');
Object.defineProperty(audio, 'currentTime', { value: 12, configurable: true });
fireEvent.timeUpdate(audio);
expect(container.querySelector('img').getAttribute('src')).toBe('/data/images/frame-b.png');
- expect(screen.getByText('Shot 2 of 2 · 0:10')).toBeTruthy();
+ expect(screen.getByText('Shot 2 / 2')).toBeTruthy();
});
});
@@ -121,6 +121,18 @@ describe('StoryboardAnimatic clips', () => {
expect(await screen.findByLabelText('Clip for Four')).toBeTruthy();
});
+ it('steps the song to the next and previous shot starts', () => {
+ const stills = clipScenes.map(({ videoHistoryId, ...scene }) => scene);
+ render(<StoryboardAnimatic project={{ id: 'p', scenes: stills }} audioUrl="/song.mp3" />);
+ const audio = screen.getByLabelText('Song for the storyboard animatic');
+ expect(screen.getByText('Shot 1 / 2')).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Next shot' }));
+ expect(audio.currentTime).toBe(10);
+ expect(screen.getByText('Shot 2 / 2')).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Previous shot' }));
+ expect(audio.currentTime).toBe(0);
+ });
+
it('maps song time into the clip: trimmed in-point, then loop or hold past its end', () => {
const performance = {
sceneId: 'p', startSec: 10, endSec: 20, shotMode: 'performance', videoHistoryId: 'v1',