mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-16 15:22:43 +00:00
#2047: a layer's audio counts when something draws it
Compare the comp exactly as the frame cache does: a layer's Audio switch, Audio group and audio effects are pixels when a layer picks its audio or an expression reads audio, before or after the edit. Scrubbing Audio Levels read by an expression now draws a draft; with nothing drawing the audio it keeps Full.
This commit is contained in:
1 parent
9ed7954a97
commit
8b481f3811
2 files changed
+51
-15
No files matched your search
@@ -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<Comp>, i64)>,
|
||||
before: Option<(ItemId, Arc<Project>, 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();
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user