Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
496 changes: 466 additions & 30 deletions crates/compositor/src/cursor.rs

Large diffs are not rendered by default.

65 changes: 54 additions & 11 deletions crates/compositor/src/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ fn reload_cursor_if_changed(
screen_path: &str,
turned: bool,
smoothing: f32,
shape: &CursorShape,
) -> bool {
let key = cursor_key(screen_path, turned);
if key == *loaded_cursor_path {
Expand All @@ -929,12 +930,30 @@ fn reload_cursor_if_changed(
// curseur (`Compositor::resized`), et le relisser parcourt tout
// l'enregistrement à chaque bascule d'un scrub.
match raw_cursor {
Some(track) => comp.set_cursor(track.smoothed(smoothing)),
Some(track) => comp.set_cursor(track.shaped(smoothing, &shape.0, &shape.1)),
None => comp.clear_cursor(),
}
true
}

/// What reshapes a cursor track besides the smoothing slider (`CursorTrack::shaped`): where its
/// spring restarts and the editor's cursor-motion sections, both for the playing clip's chain.
type CursorShape = (Vec<f32>, Vec<crate::cursor::MotionRegion>);

/// Both belong to the chain of clip `clip_index` (`Scene::cursor_chain`): the clips of a chain
/// share one shaped track, and the track is shaped again when playback moves to another chain,
/// even on the same file. One spring pass over the recording.
fn cursor_shape_inputs(scene: Option<&Scene>, clip_index: usize) -> CursorShape {
scene
.map(|s| {
(
s.cursor_break_for_clip(clip_index).into_iter().collect(),
s.cursor_motion_for_clip(clip_index),
)
})
.unwrap_or_default()
}

fn scene_for_clip(scene: &Scene, clip_index: usize) -> Scene {
match scene.clips.get(clip_index) {
Some(clip) => scene.for_clip_window(
Expand Down Expand Up @@ -1518,7 +1537,9 @@ unsafe fn advance_to_next_scene_clip(
active_clip_index: &mut usize,
raw_cursor: &mut Option<CursorTrack>,
loaded_cursor_path: &mut String,
smoothing: f32,
last_smoothing: &mut f32,
last_shape: &mut CursorShape,
) -> Option<f64> {
let Some(next_index) = next_clip_index(scene, *active_clip_index) else {
return None;
Expand Down Expand Up @@ -1592,11 +1613,16 @@ unsafe fn advance_to_next_scene_clip(
// fichier d'avant le croit encore chargé, ne relit rien, et dessine sur ce clip la
// télémétrie de celui qu'on vient de quitter.
*loaded_cursor_path = cursor_key(active_screen_path, turned);
// Shaped for the clip it lands on before its first frame is composed: installing
// the raw track and correcting it on the next loop turn showed one frame elsewhere
// (a clip that opens inside a Freeze showed the recorded position first).
let shape = cursor_shape_inputs(Some(scene), next_index);
match raw_cursor {
Some(track) => comp.set_cursor(track.smoothed(0.0)),
Some(track) => comp.set_cursor(track.shaped(smoothing, &shape.0, &shape.1)),
None => comp.clear_cursor(),
}
*last_smoothing = -1.0;
*last_smoothing = smoothing;
*last_shape = shape;
Some(next_clip.source_start_sec)
}
Err(e) => {
Expand Down Expand Up @@ -1699,6 +1725,8 @@ unsafe fn render_thread(
let mut last_preview_size: (u32, u32) = (0, 0);
let mut last_ip: Option<InspectorParams> = None;
let mut last_smoothing: f32 = -1.0; // force la 1re application (0.0 est une valeur valide)
// The breaks and motion sections the current track was shaped with (`cursor_shape_inputs`).
let mut last_shape: CursorShape = Default::default();
// Fenêtre de stabilisation après un changement EN PAUSE. Un seul recompose ne suffit pas
// quand l'effet demandé est asynchrone : la segmentation webcam (détourage / flou / fond
// personnalisé) démarre son worker au 1er compose, ne SOUMET la frame qu'au 2e et ne
Expand Down Expand Up @@ -1812,15 +1840,18 @@ unsafe fn render_thread(
// construction identique. Mesuré : 66 bascules sur un scrub de deux clips,
// donc 66 relectures du même fichier.
// The key also carries the clip's turn: the same file turned is another track.
let shape = cursor_shape_inputs(full_scene.as_ref(), active_clip_index);
if reload_cursor_if_changed(
&comp,
&mut raw_cursor,
&mut loaded_cursor_path,
&active_screen_path,
turned,
ip.cursor_smoothing,
&shape,
) {
last_smoothing = ip.cursor_smoothing;
last_shape = shape;
}
clip_changed = true;
}
Expand Down Expand Up @@ -1856,14 +1887,6 @@ unsafe fn render_thread(
cursor_auto_hide: ip.cursor_auto_hide,
has_webcam: has_real_webcam,
});
// Lissage ressort-amortisseur : re-génère la piste (240 Hz) uniquement quand la valeur
// change (pas à chaque frame — le resample+ressort parcourt tout l'enregistrement).
if let Some(raw) = &raw_cursor {
if ip.cursor_smoothing != last_smoothing {
comp.set_cursor(raw.smoothed(ip.cursor_smoothing));
last_smoothing = ip.cursor_smoothing;
}
}
// un changement de param doit se voir même en pause (édition live des sliders) :
// on recompose la frame courante dans la branche pause ci-dessous.
let ip_changed = last_ip != Some(ip);
Expand Down Expand Up @@ -1894,15 +1917,31 @@ unsafe fn render_thread(
// here, mirrored the new way.
let turned = scene.as_ref().is_some_and(Scene::screen_turned);
comp.set_scene(scene);
let shape = cursor_shape_inputs(full_scene.as_ref(), active_clip_index);
if reload_cursor_if_changed(
&comp,
&mut raw_cursor,
&mut loaded_cursor_path,
&active_screen_path,
turned,
ip.cursor_smoothing,
&shape,
) {
last_smoothing = ip.cursor_smoothing;
last_shape = shape;
}
}
// Lissage ressort-amortisseur : re-génère la piste (240 Hz) uniquement quand la valeur
// change (pas à chaque frame — le resample+ressort parcourt tout l'enregistrement).
// The cursor-motion sections and clip breaks reshape it the same way, when the scene
// changes them: read here, after the scene update above, so the frame composed below
// already uses the new ones.
if let Some(raw) = &raw_cursor {
let shape = cursor_shape_inputs(full_scene.as_ref(), active_clip_index);
if ip.cursor_smoothing != last_smoothing || shape != last_shape {
comp.set_cursor(raw.shaped(ip.cursor_smoothing, &shape.0, &shape.1));
last_smoothing = ip.cursor_smoothing;
last_shape = shape;
}
}
// Le temps programme dépend du clip actif ET de la scène entière (durées des clips
Expand Down Expand Up @@ -2041,7 +2080,9 @@ unsafe fn render_thread(
&mut active_clip_index,
&mut raw_cursor,
&mut loaded_cursor_path,
ip.cursor_smoothing,
&mut last_smoothing,
&mut last_shape,
) {
acc = anchor_acc(start, player.screen_time_sec());
}
Expand Down Expand Up @@ -2072,7 +2113,9 @@ unsafe fn render_thread(
&mut active_clip_index,
&mut raw_cursor,
&mut loaded_cursor_path,
ip.cursor_smoothing,
&mut last_smoothing,
&mut last_shape,
)
.map(|start| anchor_acc(start, player.screen_time_sec()));
}
Expand Down
Loading
Loading