The VS Code of video editing, built for agents.
TypeScript
Add keyboard shortcuts for seeking playhead to selection and timeline edges
konstantin-paulus4acfb3e4472f
diff --git a/apps/web/src/engine/input/shortcuts.ts b/apps/web/src/engine/input/shortcuts.tsindex eb8da1c9..dbf45985 100644--- a/apps/web/src/engine/input/shortcuts.ts+++ b/apps/web/src/engine/input/shortcuts.ts@@ -16,6 +16,7 @@ import {Time,Tool,ToolType,+ Workarea,getActiveEntity,getCameraMatrix,getEntityChildren,@@ -257,6 +258,50 @@ const seekFrames = (frames: number) => (world: World): void => seekBy(world, fraconst seekSeconds = (seconds: number) => (world: World): void =>seekBy(world, Math.round(seconds * (world.get(FrameRate)?.value ?? 30)));+/**+ * Parks the playhead on the selection's outer edge: the earliest frame any of+ * it starts on, or the frame just past the last of it to end. `end` is+ * exclusive everywhere else — the frame a following clip begins on, and the+ * one a cut at the boundary leaves the playhead on — so it is here too.+ *+ * The scene is the context the clips are edited in rather than a clip on it,+ * so having it selected is not an edge to jump to.+ */+export function seekToSelectionEdge(world: World, edge: 'start' | 'end'): void {+ const scene = getActiveEntity(world);+ if (!scene) return;++ const computed = store(world, Computed);+ const clips = [...world.query(Selected, NODES)].filter(entity => entity !== scene);+ if (!clips.length) return;++ const frames = clips.map(entity => computed[edge][entity.id()] ?? 0);+ setPlayhead(world, scene, edge === 'start' ? Math.min(...frames) : Math.max(...frames));+}++const seekSelectionEdge = (edge: 'start' | 'end') => (world: World): void =>+ seekToSelectionEdge(world, edge);++/**+ * Parks the playhead at one end of the active scene. A work area is the+ * stretch that plays and exports, so while there is one its edges are the+ * ends: seeking past them would leave the playhead where playback cannot+ * pick up, and the next play would snap back in anyway.+ */+export function seekToTimelineEdge(world: World, edge: 'start' | 'end'): void {+ const scene = getActiveEntity(world);+ if (!scene) return;++ const workarea = scene.has(Workarea) ? scene.get(Workarea) : undefined;++ setPlayhead(world, scene, edge === 'start'+ ? workarea?.start ?? 0+ : workarea?.end ?? store(world, Computed).duration[scene.id()] ?? 0);+}++const seekTimelineEdge = (edge: 'start' | 'end') => (world: World): void =>+ seekToTimelineEdge(world, edge);+/** How much of the zoom a step takes, in or out. */const ZOOM_STEP = 1.25;@@ -413,6 +458,11 @@ const PRESSED_SHORTCUTS: readonly Shortcut[] = [{ keys: ['d', '!mod'], action: seekFrames(1) },{ keys: ['w', '!mod'], action: seekSeconds(1) },{ keys: ['s', '!mod'], action: seekSeconds(-1) },+ { keys: [';', '!mod'], action: seekSelectionEdge('start') },+ { keys: ["'", '!mod'], action: seekSelectionEdge('end') },+ // fn ←/→ on macOS, Home/End elsewhere.+ { keys: ['home'], action: seekTimelineEdge('start') },+ { keys: ['end'], action: seekTimelineEdge('end') },{ keys: [']', '!mod'], action: restack('front') },{ keys: ['[', '!mod'], action: restack('back') },{ keys: ['\\', '!mod'], action: selectParents },diff --git a/packages/encoder/src/image-encoder.ts b/packages/encoder/src/image-encoder.tsindex 03919812..36eab056 100644--- a/packages/encoder/src/image-encoder.ts+++ b/packages/encoder/src/image-encoder.ts@@ -3,9 +3,9 @@* file, You can obtain one at http://mozilla.org/MPL/2.0/. */import {- setActive, framesToSeconds, formatTimecode, assert, store, getEntityTree,+ setActive, framesToSeconds, formatTimecode, assert, store,assetSystem, playbackSystem, motionSystem, transformSystem, renderSystem,- Muted, Workarea, Playback, Computed,+ Silent, Workarea, Playback, Computed,Time, FrameRate, RenderSurface, AudioEngine,} from '@diffusionstudio/runtime';@@ -51,10 +51,11 @@ export async function createImageEncoder(world: World, config: ImageEncoderConfi// for the lazy audio-bus wiring to have something to bind to.world.set(AudioEngine, { context: new OfflineAudioContext(2, 1, 48000) });- // Mute everything so the playback system never initializes audio decoders.- for (const entity of getEntityTree(world, scene)) {- entity.add(Muted);- }+ // Silence the world so the playback system never initializes audio+ // decoders. On the world rather than as a `Muted` on every node: what the+ // scene holds is still audio, and a `<captions>` that has to transcribe+ // its scene during the warmup below asks exactly that question.+ world.add(Silent);await warmupAssets(world);diff --git a/packages/runtime/src/systems/playback.ts b/packages/runtime/src/systems/playback.tsindex 09b0c3c6..830de7b5 100644--- a/packages/runtime/src/systems/playback.ts+++ b/packages/runtime/src/systems/playback.ts@@ -17,7 +17,7 @@ import {Sequential, Transition, Playback, Workarea,AudioPlayback, Computed,AudioDecoderHandle, AudioBusHandle, Host,- Mode, FrameRate, Time, AudioEngine, FramePromises, Tickers,+ Mode, Silent, FrameRate, Time, AudioEngine, FramePromises, Tickers,Root,} from '../traits';import { getParentNode } from '../queries/hierarchy';@@ -153,7 +153,7 @@ function forwardCaptionDecoder(world: World, _scene: Entity, entity: Entity): vo* timing still comes from the clip entity itself.*/function forwardAudioDecoder(world: World, scene: Entity, entity: Entity, audioSource?: Entity): void {- if (entity.has(Muted)) return;+ if (world.has(Silent) || entity.has(Muted)) return;const resolvedDecoder = resolveAudioDecoder(world, audioSource ?? entity);if (!resolvedDecoder) return;diff --git a/packages/runtime/src/traits/world.ts b/packages/runtime/src/traits/world.tsindex 356f5269..46705bc7 100644--- a/packages/runtime/src/traits/world.ts+++ b/packages/runtime/src/traits/world.ts@@ -36,6 +36,12 @@ export type RuntimeMode = 'realtime' | 'offline-video' | 'offline-audio';export const Mode = trait({ value: 'realtime' as RuntimeMode });+// On the world: nothing in this render is to be heard, so no audio decoder is+// ever opened (a frame capture draws pictures and never mixes). A rendering+// concern, kept apart from `Muted`, which is the composition's own — a clip+// the project muted. What is silenced here is still audio the scene has.+export const Silent = trait();+// Frame clock (was timestamp).export const Time = trait({ now: 0, delta: 0 });