From e46313785799dc711a755aade3e6d22bb566fe92 Mon Sep 17 00:00:00 2001 From: Yoav Levavi Date: Tue, 29 Sep 2026 09:46:18 +0300 Subject: [PATCH 1/3] feat: J/K/L playback speed shuttle and V for select mode L starts playback and steps it up through 1.5x/2x/3x/4x, J steps it down to 0.5x, and K stops and resets to 1x; a badge shows the current speed. Space and the play button always play at 1x. V returns the timeline to select mode (S still toggles split). The playback clock runs at the chosen rate and the audio output consumes source audio at the same rate through a streaming WSOLA time-stretcher, so shuttling keeps the original pitch. Audio the stretcher has pulled ahead is counted in the video-sync latency. Non-f32 output devices fall back to frame decimation. Co-Authored-By: Claude Opus 5.5 --- .../desktop-display-transport-benchmark.rs | 1 + apps/desktop/src-tauri/src/lib.rs | 9 + apps/desktop/src/routes/editor/Player.tsx | 71 +++++++ apps/desktop/src/utils/tauri.ts | 3 + .../examples/editor-playback-benchmark.rs | 1 + crates/editor/src/audio_output.rs | 116 ++++++++++- .../editor/src/audio_output/native_tests.rs | 1 + crates/editor/src/editor_instance.rs | 20 ++ crates/editor/src/lib.rs | 1 + crates/editor/src/playback.rs | 25 ++- crates/editor/src/time_stretch.rs | 194 ++++++++++++++++++ 11 files changed, 434 insertions(+), 8 deletions(-) create mode 100644 crates/editor/src/time_stretch.rs diff --git a/apps/desktop/src-tauri/examples/desktop-display-transport-benchmark.rs b/apps/desktop/src-tauri/examples/desktop-display-transport-benchmark.rs index f7449e2f940..abe07708d38 100644 --- a/apps/desktop/src-tauri/examples/desktop-display-transport-benchmark.rs +++ b/apps/desktop/src-tauri/examples/desktop-display-transport-benchmark.rs @@ -338,6 +338,7 @@ async fn main() { music: cap_editor::MusicTracks::new(), audio_output, telemetry: Some(telemetry), + playback_rate: 1.0, }; let playback_handle = match playback.start(fps, resolution_base).await { diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index a78c370641e..f36dd096678 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -4710,6 +4710,14 @@ async fn start_playback( Ok(()) } +#[tauri::command] +#[specta::specta] +#[instrument(skip(editor_instance))] +async fn set_playback_rate(editor_instance: WindowEditorInstance, rate: f64) -> Result<(), String> { + editor_instance.set_playback_rate(rate); + Ok(()) +} + #[tauri::command] #[specta::specta] #[instrument(skip(editor_instance))] @@ -6824,6 +6832,7 @@ fn specta_builder() -> tauri_specta::Builder { audio_library::add_audio_library_track, audio_library::import_audio_track_file, start_playback, + set_playback_rate, stop_playback, commit_editor_preparing_frame, start_editor_handoff_playback, diff --git a/apps/desktop/src/routes/editor/Player.tsx b/apps/desktop/src/routes/editor/Player.tsx index 3ef4105cf0f..65d075d2c86 100644 --- a/apps/desktop/src/routes/editor/Player.tsx +++ b/apps/desktop/src/routes/editor/Player.tsx @@ -44,6 +44,8 @@ import { EditorButton, Slider } from "./ui"; import { useEditorShortcuts } from "./useEditorShortcuts"; import { formatTime } from "./utils"; +const SHUTTLE_RATES = [0.5, 1, 1.5, 2, 3, 4]; + export function PlayerContent(props: { compactness?: number }) { const { previewStyle, @@ -263,7 +265,64 @@ export function PlayerContent(props: { compactness?: number }) { } }); + const [playbackRate, setPlaybackRate] = createSignal(1); + + const applyPlaybackRate = async (rate: number) => { + if (rate === playbackRate()) return; + setPlaybackRate(rate); + await commands.setPlaybackRate(rate); + }; + + const shuttle = async (rate: number) => { + if (isAtEnd()) return; + const pending = requestHandoffPlayback(true); + if (pending) { + await pending; + return; + } + const time = editorState.previewTime ?? editorState.playbackTime; + const frame = Math.max(Math.floor(time * FPS), 0); + try { + await applyPlaybackRate(rate); + if (playbackIntent()) { + await commands.stopPlayback(); + setEditorState("playing", false); + } + setEditorState("playbackTime", time); + await commands.seekTo(frame); + await commands.startPlayback(FPS, previewResolutionBase()); + setEditorState("playing", true); + setEditorState("previewTime", null); + } catch (error) { + console.error("Error changing playback speed:", error); + setEditorState("playing", false); + } + }; + + const shuttleFaster = () => { + const current = playbackIntent() ? playbackRate() : 0; + const next = SHUTTLE_RATES.find((rate) => rate > current && rate >= 1); + return shuttle(next ?? SHUTTLE_RATES[SHUTTLE_RATES.length - 1]); + }; + + const shuttleSlower = () => { + const current = playbackIntent() ? playbackRate() : 1; + const next = [...SHUTTLE_RATES].reverse().find((rate) => rate < current); + return shuttle(next ?? SHUTTLE_RATES[0]); + }; + + const shuttleStop = async () => { + const pending = requestHandoffPlayback(false); + if (pending) await pending; + else if (playbackIntent()) { + await commands.stopPlayback(); + setEditorState("playing", false); + } + await applyPlaybackRate(1); + }; + const handlePlayPauseClick = async () => { + await applyPlaybackRate(1); const pending = requestHandoffPlayback( isAtEnd() || !playbackIntent(), isAtEnd() ? 0 : undefined, @@ -330,6 +389,13 @@ export function PlayerContent(props: { compactness?: number }) { editorState.timeline.interactMode === "split" ? "seek" : "split", ), }, + { + combo: "V", + handler: () => setEditorState("timeline", "interactMode", "seek"), + }, + { combo: "L", handler: shuttleFaster }, + { combo: "J", handler: shuttleSlower }, + { combo: "K", handler: shuttleStop }, { combo: "Mod+=", handler: () => @@ -463,6 +529,11 @@ export function PlayerContent(props: { compactness?: number }) { > + + + {playbackRate()}× + +