diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs index 4384095c7..e0f53fb12 100644 --- a/crates/ui-egui/src/panels/drag_preview.rs +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -4,43 +4,49 @@ use std::sync::Arc; -use effectcraft_engine::project::{Comp, ItemId}; +use effectcraft_engine::project::{ItemId, Project}; use crate::EffectcraftApp; -/// The active comp and its current frame index when a panel starts its pass. [`DragWatch::end`] -/// compares them with the comp and frame after the panel ran its gestures, so every drag the -/// panel handles is covered without a flag per gesture. +/// The project, the active comp and its current frame index when a panel starts its pass. +/// [`DragWatch::end`] compares them with the comp and frame after the panel ran its gestures, so +/// every drag the panel handles is covered without a flag per gesture. pub(crate) struct DragWatch { - before: Option<(ItemId, Arc, i64)>, + before: Option<(ItemId, Arc, i64)>, } impl DragWatch { pub(crate) fn begin(app: &EffectcraftApp) -> Self { + let project = app.session.project.clone(); let before = app.session.active_comp_id().and_then(|id| { - let comp = app.session.project.comp_arc(id)?; - let frame = comp.frame_rate.frame_at(app.session.time()); - Some((id, comp, frame)) + let frame = project.comp_arc(id)?.frame_rate.frame_at(app.session.time()); + Some((id, project, frame)) }); Self { before } } /// While the primary button drags (moved past a click, or held past one), a change of the /// current frame or of the active comp's pixels since [`Self::begin`] sets - /// `property_interacting`, which stays set until the button is up (`App::frame`). A click, - /// or a drag that draws the same pixels (scrolling, zooming, the work area, selecting, markers - /// no expression reads, as for the frame cache) keeps Full. + /// `property_interacting`, which stays set until the button is up (`App::frame`). Pixels are + /// compared as the frame cache does: markers count when an expression reads them, a layer's + /// audio when something draws it, before or after the edit. A click, or a drag that draws + /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { - let Some((id, comp, frame)) = self.before else { return }; + let Some((id, project, frame)) = self.before else { return }; if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { return; } if app.session.active_comp_id() != Some(id) { return; } - let Some(now) = app.session.project.comp_arc(id) else { return }; - let moved = comp.frame_rate.frame_at(app.session.time()) != frame; - if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels_with(&comp, app.session.project.reads_markers(), &|_| false)) { + let (Some(was), Some(now)) = (project.comp_arc(id), app.session.project.comp_arc(id)) else { return }; + let moved = was.frame_rate.frame_at(app.session.time()) != frame; + let edited = || { + let current = &app.session.project; + let heard = current.heard_layers().union(&project.heard_layers()); + !now.same_pixels_with(&was, current.reads_markers(), &|l| heard.contains(id, l)) + }; + if moved || (!Arc::ptr_eq(&was, &now) && edited()) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index e2cb2112a..5cf11ad0e 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -158,6 +158,36 @@ fn work_area_drag_keeps_full_resolution() { release(&mut f.h, from); } +/// Scrubs the precomp's Audio Levels in the Timeline; `reads_audio` adds an expression that +/// reads audio. Returns whether the viewer drew a draft while held. +fn audio_levels_scrub(reads_audio: bool) -> bool { + let mut f = fixture("adaptive"); + if reads_audio { + let rotation = json!({"layer": f.solid, "path": "transform/rotation", "expression": "thisComp.layer(1).audioLevels; value"}); + f.h.state_mut().session.execute("prop.setExpression", rotation).unwrap(); + } + let uid = f.h.state().session.active_comp().unwrap().layers.iter().find(|l| l.id.0 == f.pre).unwrap().props.prop("audio/levels").unwrap().uid; + let tl = &mut f.h.state_mut().ui.timeline; + tl.open_layers.insert(f.pre); + tl.layer_reveal.insert(f.pre, vec!["props".into()]); + tl.reveal_props.insert(uid); + f.h.run_steps(3); + let from = rect(&f.h, &format!("timeline.prop.{uid}.value.0")).center(); + let before = on_screen(&f.h); + hold(&mut f.h, from, from + vec2(40.0, 0.0)); + assert_ne!(on_screen(&f.h), before, "the scrub changed the levels"); + let draft = draft(&f.h); + release(&mut f.h, from); + draft +} + +/// A layer's audio is pixels only when something draws it (an expression reading audio here). +#[test] +fn audio_levels_scrub_draws_a_draft_only_when_audio_is_drawn() { + assert!(audio_levels_scrub(true), "an expression reads the audio"); + assert!(!audio_levels_scrub(false), "nothing draws the audio"); +} + /// Markers are pixels only to the expressions that read them (#1083): moving one keeps Full. #[test] fn marker_drag_keeps_full_resolution() {