Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Studio: the viewer plays at 3× and 4×, and its playback menu is laid out again (#292)

riverisbuilding6c7d599c2c7e
diff --git a/.changeset/playback-speed-4x.md b/.changeset/playback-speed-4x.md
new file mode 100644
index 0000000..766e7ef
--- /dev/null
+++ b/.changeset/playback-speed-4x.md
@@ -0,0 +1,5 @@
+---
+"openfilm": patch
+---
+
+Studio: the viewer plays at 3× and 4× too, its sound’s pitch kept. Its playback menu is laid out again: loop and speed as the layout menu’s rows, and the speed two rows, 0.25× to 1× and 1.5× to 4×. J/K/L’s 4× plays with sound, and the full-screen player offers the same speeds.
diff --git a/packages/openfilm/studio/ui/src/components/PlaybackMenu.tsx b/packages/openfilm/studio/ui/src/components/PlaybackMenu.tsx
index 2ceb6c1..34e107e 100644
--- a/packages/openfilm/studio/ui/src/components/PlaybackMenu.tsx
+++ b/packages/openfilm/studio/ui/src/components/PlaybackMenu.tsx
@@ -3,11 +3,9 @@ import { createPortal } from 'react-dom';
import { Gauge, Repeat } from 'lucide-react';
import { useT } from '@/i18n';
import { useKeyHint } from '@/lib/keymap-store';
+import { PLAYBACK_SPEEDS, speedStep, speedText } from '@/lib/playback-speed';
import { Tooltip } from './Tooltip';
-/** The speeds the viewer plays at (the player plays forward only, from 0.25× to 2×). */
-export const PLAYBACK_SPEEDS = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2] as const;
-
export type PlaybackSettings = {
/** Loop playback (⇧L): of the range marked (`ranged`), else of the whole film. */
loop: boolean;
@@ -19,8 +17,9 @@ export type PlaybackSettings = {
/**
* The viewer's playback settings: loop and the speed (subtitles are the timeline's CC button). What is not the default shows on the
- * button itself (the loop icon, "1.5×"), so it is seen without opening the menu. Nothing here takes focus on click:
- * the next Space still plays.
+ * button itself (the loop icon, "1.5×"), so it is seen without opening the menu. Laid out as the layout menu beside
+ * it is (a row each, its icon in a tile); the speed is one segmented control. Nothing here takes focus on click: the next
+ * Space still plays.
*/
export function PlaybackMenu({ className, disabled, settings }: {
className?: string;
@@ -58,19 +57,9 @@ export function PlaybackMenu({ className, disabled, settings }: {
const { loop, ranged, onLoop, speed, onSpeed } = settings;
const loopLabel = t(ranged ? 'viewer.loopRange' : 'viewer.loopFilm');
- const speedText = (s: number) => `${s}×`;
const keep = (e: React.MouseEvent) => e.preventDefault();
- const toggle = (key: string, label: string, checked: boolean, change: () => void, Icon: typeof Repeat, hint?: string) => (
- <button key={key} type="button" role="switch" aria-checked={checked} onClick={change} onMouseDown={keep}
- data-playback={key}
- className="flex w-full items-center gap-2.5 rounded-[7px] px-2 py-1.5 text-[12px] text-[var(--text)] hover:bg-[var(--bg-hover)] focus-visible:outline focus-visible:outline-[var(--border-strong)]">
- <Icon size={14} aria-hidden className="shrink-0 text-[var(--text-muted)]" />
- <span className="flex-1 text-left">{label}</span>
- {hint ? <span className="text-[11px] text-[var(--text-faint)]">{hint}</span> : null}
- <span aria-hidden className={`relative h-[18px] w-[30px] shrink-0 rounded-full transition-colors ${checked ? 'bg-[var(--text)]' : 'bg-[var(--surface-2)] ring-1 ring-inset ring-[var(--border)]'}`}>
- <span className={`absolute top-[3px] h-3 w-3 rounded-full transition-all ${checked ? 'left-[15px] bg-[var(--bg)]' : 'left-[3px] bg-[var(--text-faint)]'}`} />
- </span>
- </button>
+ const tile = (Icon: typeof Repeat) => (
+ <span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-[var(--surface-2)] text-[var(--text-muted)]"><Icon size={13} aria-hidden /></span>
);
return <>
@@ -90,21 +79,60 @@ export function PlaybackMenu({ className, disabled, settings }: {
</button>
</Tooltip>
{anchor && createPortal(<div ref={panel} id={id} role="dialog" aria-label={t('viewer.playback')}
- style={anchor} className="fixed z-[110] w-56 rounded-[14px] border border-[var(--border)] bg-[var(--surface)] p-1.5 shadow-[0_18px_48px_-12px_rgba(0,0,0,0.45),0_2px_8px_rgba(0,0,0,0.12)]">
+ style={anchor} className="fixed z-[110] w-60 rounded-[14px] border border-[var(--border)] bg-[var(--surface)] p-1.5 shadow-[0_18px_48px_-12px_rgba(0,0,0,0.45),0_2px_8px_rgba(0,0,0,0.12)]">
<div className="px-2 pb-1 pt-1 text-[11px] font-medium text-[var(--text-faint)]">{t('viewer.playback')}</div>
- {toggle('loop', loopLabel, loop, onLoop, Repeat, keyHint('loop'))}
- <div className="mx-1 my-1 h-px bg-[var(--border)]" />
- <div className="px-2 pb-1.5 pt-1 text-[11px] font-medium text-[var(--text-faint)]">{t('viewer.speed')}</div>
- <div role="radiogroup" aria-label={t('viewer.speed')} className="grid grid-cols-4 gap-1 px-1 pb-1">
- {PLAYBACK_SPEEDS.map((s) => (
- <button key={s} type="button" role="radio" aria-checked={s === speed} onClick={() => onSpeed(s)} onMouseDown={keep}
- className={`h-7 rounded-[6px] text-[12px] tabular-nums transition focus-visible:outline focus-visible:outline-[var(--border-strong)] ${
- s === speed ? 'bg-[var(--text)] font-medium text-[var(--bg)]' : 'text-[var(--text)] hover:bg-[var(--bg-hover)]'
- }`}>
- {speedText(s)}
- </button>
- ))}
+ <button type="button" role="switch" aria-checked={loop} onClick={onLoop} onMouseDown={keep} data-playback="loop"
+ className="flex w-full items-center gap-2.5 rounded-[7px] px-2 py-1.5 text-[13px] text-[var(--text)] hover:bg-[var(--bg-hover)] focus-visible:outline focus-visible:outline-[var(--border-strong)]">
+ {tile(Repeat)}
+ <span className="flex-1 text-left">{loopLabel}</span>
+ {keyHint('loop') ? <span className="text-[11px] text-[var(--text-faint)]">{keyHint('loop')}</span> : null}
+ {/* a switch, ink-colored, as the layout menu's */}
+ <span aria-hidden className={`relative h-[18px] w-[30px] shrink-0 rounded-full transition-colors ${loop ? 'bg-[var(--text)]' : 'bg-[var(--surface-2)] ring-1 ring-inset ring-[var(--border)]'}`}>
+ <span className={`absolute top-[3px] h-3 w-3 rounded-full transition-all ${loop ? 'left-[15px] bg-[var(--bg)]' : 'left-[3px] bg-[var(--text-faint)]'}`} />
+ </span>
+ </button>
+ <div className="flex items-center gap-2.5 px-2 pb-1.5 pt-1.5 text-[13px] text-[var(--text)]">
+ {tile(Gauge)}
+ <span className="flex-1">{t('viewer.speed')}</span>
</div>
+ <SpeedRow label={t('viewer.speed')} speed={speed} onSpeed={onSpeed} keep={keep} />
</div>, document.body)}
</>;
}
+
+/** Speeds a row: PLAYBACK_SPEEDS in two rows, the slower ones up to 1×, then the faster. */
+const PER_ROW = 4;
+
+/**
+ * The speed: PLAYBACK_SPEEDS as one segmented control in two rows, as the inspector's choices are, the one playing
+ * raised on a mark that slides to the next one picked. A speed between them (the shuttle's) marks the nearest.
+ */
+function SpeedRow({ label, speed, onSpeed, keep }: {
+ label: string;
+ speed: number;
+ onSpeed: (speed: number) => void;
+ keep: (e: React.MouseEvent) => void;
+}) {
+ const at = speedStep(speed);
+ const rows = Math.ceil(PLAYBACK_SPEEDS.length / PER_ROW);
+ return (
+ <div role="radiogroup" aria-label={label} data-playback="speed"
+ className="relative mx-2 mb-1.5 grid rounded-[8px] bg-[var(--fill-tsp)] p-[2px]"
+ style={{ gridTemplateColumns: `repeat(${PER_ROW}, minmax(0, 1fr))` }}>
+ <span aria-hidden className="absolute left-[2px] top-[2px] rounded-[6px] bg-[var(--bg)] shadow-[0_0_0_0.5px_var(--border-strong),0_1px_2px_rgba(0,0,0,0.12)] transition-transform duration-200 ease-out"
+ style={{
+ width: `calc((100% - 4px) / ${PER_ROW})`,
+ height: `calc((100% - 4px) / ${rows})`,
+ transform: `translate(${(at % PER_ROW) * 100}%, ${Math.floor(at / PER_ROW) * 100}%)`,
+ }} />
+ {PLAYBACK_SPEEDS.map((s, i) => (
+ <button key={s} type="button" role="radio" aria-checked={i === at} onClick={() => onSpeed(s)} onMouseDown={keep}
+ className={`relative h-[28px] rounded-[6px] text-[12px] tabular-nums transition-colors focus-visible:outline focus-visible:outline-[var(--border-strong)] ${
+ i === at ? 'font-medium text-[var(--text)]' : 'text-[var(--text-muted)] hover:text-[var(--text)]'
+ }`}>
+ {speedText(s)}
+ </button>
+ ))}
+ </div>
+ );
+}
diff --git a/packages/openfilm/studio/ui/src/components/ProjectView.tsx b/packages/openfilm/studio/ui/src/components/ProjectView.tsx
index 35c23a2..2fbe53a 100644
--- a/packages/openfilm/studio/ui/src/components/ProjectView.tsx
+++ b/packages/openfilm/studio/ui/src/components/ProjectView.tsx
@@ -17,6 +17,7 @@ import { Preview, type FilmInfo, type PlayedReport, type PreviewHandle } from '@
import { usePreviewRenders } from '@/editor/use-preview-renders';
import { filmShape, type MediaFacts } from '@/lib/film-shape';
import { changesPicture } from '@/lib/picture-files';
+import { SPEED_MAX } from '@/lib/playback-speed';
import type { ReplaceFamily } from '@/lib/clip-replace';
import { layoutTracks, type TimelineBlock, type TimelineTrack } from '@/lib/timeline-layout';
import { filmClipKind, filmSrcIsPage, filmSrcKind, filmTrackBadges, parseFilmDocLoc, type FilmBox, type FilmDoc, type FilmOverride } from '@/lib/film';
@@ -461,8 +462,8 @@ export function ProjectView({ projectId, onProject, onLeave }: {
if (!player.current.playing) preview.current?.seek(pictureAt(t));
for (const fn of listeners.current) fn();
}, []);
- /* ── J / K / L: the shuttle. 1× and 2× forward are the player's own (with sound); faster, or backwards, the picture
- alone is sought along at that rate, silent, as a scrub is (the player plays forward only, at most 2×) ── */
+ /* ── J / K / L: the shuttle. 1×, 2× and 4× forward are the player's own (with sound); backwards, the picture alone
+ is sought along at that rate, silent, as a scrub is (the player plays forward only, at most 4×) ── */
const shuttleRateRef = React.useRef(0);
const shuttleFrame = React.useRef(0);
/** The shuttle let go: the player back at the speed picked if the shuttle changed its rate. */
@@ -507,7 +508,7 @@ export function ProjectView({ projectId, onProject, onLeave }: {
const rate = shuttleRate(was, key);
if (rate === 0) { stopShuttle(); pause(); return; }
if (!(player.current.duration > 0)) return;
- if (rate > 0 && rate <= 2) {
+ if (rate > 0 && rate <= SPEED_MAX) {
if (shuttleFrame.current) { cancelAnimationFrame(shuttleFrame.current); shuttleFrame.current = 0; }
shuttleRateRef.current = rate;
player.current.setRate(rate);
diff --git a/packages/openfilm/studio/ui/src/components/player-controls/controls-bar.tsx b/packages/openfilm/studio/ui/src/components/player-controls/controls-bar.tsx
index a38b876..a52c2dd 100644
--- a/packages/openfilm/studio/ui/src/components/player-controls/controls-bar.tsx
+++ b/packages/openfilm/studio/ui/src/components/player-controls/controls-bar.tsx
@@ -13,6 +13,7 @@ import {
TransportSeekBar,
transportTimeText,
} from './transport';
+import { PLAYBACK_SPEEDS } from '@/lib/playback-speed';
/* YouTube-style icons, 24×24, currentColor */
function Icon({ d, size = 24 }: { d: string; size?: number }) {
@@ -45,8 +46,6 @@ export function CaptionsIcon({ size = 24 }: { size?: number }) {
);
}
-const SPEED_OPTIONS = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
-
export interface PlayerControlsBarProps {
timeMs: number;
totalMs: number;
@@ -350,7 +349,7 @@ function SettingsMenu({
<Icon d={PATH_CHEVRON_BACK} size={20} />
<span>{t('player.speed')}</span>
</button>
- {SPEED_OPTIONS.map((s) => (
+ {PLAYBACK_SPEEDS.map((s) => (
<MenuOption
key={s}
style={row}
diff --git a/packages/openfilm/studio/ui/src/editor/player.ts b/packages/openfilm/studio/ui/src/editor/player.ts
index 0dc73e7..033116c 100644
--- a/packages/openfilm/studio/ui/src/editor/player.ts
+++ b/packages/openfilm/studio/ui/src/editor/player.ts
@@ -22,6 +22,8 @@
* only: the film and its exports are as they are.
*/
+import { SPEED_MAX, SPEED_MIN } from '../lib/playback-speed.ts';
+
/** Sounds fetched at once; the others wait, the ones nearest to where the film is first. */
const FETCHES = 3;
/** How far ahead of the film sounds are started (film seconds); the rest are started as the film gets near them. */
@@ -322,7 +324,7 @@ export class Player {
/** Play faster or slower, the pitch kept (see stretchRate); playing goes on from where it is, heard at once. */
setRate(rate: number) {
const t = this.time();
- const next = Math.max(0.25, Math.min(2, rate));
+ const next = Math.max(SPEED_MIN, Math.min(SPEED_MAX, rate));
if (next === this.rate) return;
this.rate = next;
if (this.playing) this.restart(t);
diff --git a/packages/openfilm/studio/ui/src/lib/playback-speed.test.ts b/packages/openfilm/studio/ui/src/lib/playback-speed.test.ts
new file mode 100644
index 0000000..058b5ba
--- /dev/null
+++ b/packages/openfilm/studio/ui/src/lib/playback-speed.test.ts
@@ -0,0 +1,19 @@
+import assert from 'node:assert/strict';
+import { test } from 'node:test';
+
+import { PLAYBACK_SPEEDS, SPEED_MAX, SPEED_MIN, speedStep } from './playback-speed.ts';
+
+test('the player plays from 0.25× to 4×, 3× and 4× the fastest', () => {
+ assert.equal(SPEED_MIN, 0.25);
+ assert.equal(SPEED_MAX, 4);
+ assert.deepEqual(PLAYBACK_SPEEDS.slice(-3), [2, 3, 4]);
+});
+
+test('a speed is on the step nearest to it', () => {
+ assert.equal(PLAYBACK_SPEEDS[speedStep(1)], 1);
+ assert.equal(PLAYBACK_SPEEDS[speedStep(4)], 4);
+ assert.equal(PLAYBACK_SPEEDS[speedStep(2.4)], 2);
+ assert.equal(PLAYBACK_SPEEDS[speedStep(8)], 4);
+ assert.equal(PLAYBACK_SPEEDS[speedStep(0.1)], 0.25);
+ assert.equal(PLAYBACK_SPEEDS[speedStep(1.25)], 1);
+});
diff --git a/packages/openfilm/studio/ui/src/lib/playback-speed.ts b/packages/openfilm/studio/ui/src/lib/playback-speed.ts
new file mode 100644
index 0000000..6f92bab
--- /dev/null
+++ b/packages/openfilm/studio/ui/src/lib/playback-speed.ts
@@ -0,0 +1,20 @@
+/**
+ * The speeds the player plays at, forward only, the pitch kept: the viewer's menu (two rows of four: slower, then
+ * faster), the full-screen player's.
+ */
+export const PLAYBACK_SPEEDS = [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4] as const;
+
+export const SPEED_MIN = PLAYBACK_SPEEDS[0];
+export const SPEED_MAX = PLAYBACK_SPEEDS[PLAYBACK_SPEEDS.length - 1];
+
+/** The speed as it is shown: `1.5×`. */
+export const speedText = (speed: number) => `${speed}×`;
+
+/** The step of PLAYBACK_SPEEDS nearest to a speed (a speed set some other way, the shuttle's, falls between them). */
+export function speedStep(speed: number): number {
+ let best = 0;
+ for (let i = 1; i < PLAYBACK_SPEEDS.length; i++) {
+ if (Math.abs(PLAYBACK_SPEEDS[i] - speed) < Math.abs(PLAYBACK_SPEEDS[best] - speed)) best = i;
+ }
+ return best;
+}