Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge upstream/main into fix-1083-beat-marker-audio-pause

vangel7646aa69482db0
diff --cc crates/project/src/lib.rs
index 57824de8c,16d782165..9ab402d9d
--- a/crates/project/src/lib.rs
+++ b/crates/project/src/lib.rs
@@@ -749,6 -779,6 +779,16 @@@ impl Default for Switches
// What a frame's pixels depend on. Caches key on it: the Audio, Lock and Shy switches and Hide
// Shy Layers don't change pixels, so toggling them keeps cached frames (#103).
++/// A protected time marker with a duration sets the comp's timing (Responsive Design), so it is
++/// part of the pixels even where plain markers are not.
++fn is_timing_marker(m: &Marker) -> bool {
++ m.protected && m.duration > Tick::ZERO
++}
++
++fn timing_markers(m: &[Marker]) -> impl Iterator<Item = (Tick, Tick)> + '_ {
++ m.iter().filter(|m| is_timing_marker(m)).map(|m| (m.time, m.duration))
++}
++
impl Switches {
/// These switches with Audio, Lock and Shy at their defaults.
pub fn pixels(&self) -> Switches {
@@@ -815,13 -839,6 +855,14 @@@ impl Comp
/// Draws the same pixels as `o`: equal but for its layers' Audio, Lock and Shy switches, Hide
/// Shy Layers and the viewer's Resolution.
pub fn same_pixels(&self, o: &Comp) -> bool {
+ self.same_pixels_with(o, true)
+ }
+
+ /// [`Self::same_pixels`], with the comp's and its layers' markers counting only when
+ /// `with_markers`: only expressions read them, so while none does, adding or moving a marker
- /// (even during playback) leaves every rendered frame valid.
++ /// (even during playback) leaves every rendered frame valid. Protected time markers with a
++ /// duration set the timing (Responsive Design), so those always count.
+ pub fn same_pixels_with(&self, o: &Comp, with_markers: bool) -> bool {
// Every field (no `..`: a new field must be considered here); the layers last.
let Comp {
width,
@@@ -859,7 -876,7 +900,7 @@@
&& *display_start == o.display_start
&& *background == o.background
&& *work_area == o.work_area
- && (!with_markers || *markers == o.markers)
- && *markers == o.markers
++ && (if with_markers { *markers == o.markers } else { timing_markers(markers).eq(timing_markers(&o.markers)) })
&& *shutter_angle == o.shutter_angle
&& *shutter_phase == o.shutter_phase
&& *motion_blur_samples == o.motion_blur_samples
@@@ -881,30 -915,14 +922,30 @@@
/// The comp with those switches and the Resolution at their defaults (borrowed when they
/// already are), for keys that hash the whole comp.
pub fn pixel_form(&self) -> std::borrow::Cow<'_, Comp> {
- if !self.hide_shy && self.resolution.is_auto() && self.layers.iter().all(|l| l.switches == l.switches.pixels()) {
+ self.pixel_form_with(true)
+ }
+
- /// [`Self::pixel_form`], also without the comp's and its layers' markers when not
++ /// [`Self::pixel_form`], also without the comp's plain markers and its layers' markers when not
+ /// `with_markers` (see [`Self::same_pixels_with`] and [`Project::reads_markers`]).
+ pub fn pixel_form_with(&self, with_markers: bool) -> std::borrow::Cow<'_, Comp> {
+ if !self.hide_shy
+ && self.resolution.is_auto()
+ && self.layers.iter().all(|l| l.switches == l.switches.pixels())
- && (with_markers || (self.markers.is_empty() && self.layers.iter().all(|l| l.markers.is_empty())))
++ && (with_markers || (self.markers.iter().all(|m| !is_timing_marker(m)) && self.layers.iter().all(|l| l.markers.is_empty())))
+ {
return std::borrow::Cow::Borrowed(self);
}
let mut c = self.clone();
c.hide_shy = false;
c.resolution = Resolution::Auto;
+ if !with_markers {
- c.markers.clear();
++ c.markers.retain(is_timing_marker);
+ }
for l in &mut c.layers {
l.switches = l.switches.pixels();
+ if !with_markers {
+ l.markers.clear();
+ }
}
std::borrow::Cow::Owned(c)
}
@@@ -1355,21 -1378,6 +1401,21 @@@ impl Default for Project
}
impl Project {
- /// Some expression mentions markers (`marker.key(1)`, `numKeys`, `nearestKey`...). Only then
- /// do the markers of comps and layers affect what is rendered, so frame caches ignore them
- /// otherwise.
++ /// Some layer has an expression, which can read markers (`marker.key(1)`, `numKeys`,
++ /// `nearestKey`...). Only then do the markers of comps and layers affect what is rendered, so
++ /// frame caches ignore them otherwise.
+ pub fn reads_markers(&self) -> bool {
+ let mut found = false;
+ for (_, c) in self.comps() {
+ for l in &c.layers {
+ if !found {
- l.props.walk("", &mut |_, p| found |= p.expr.as_ref().is_some_and(|e| e.text.to_ascii_lowercase().contains("marker")));
++ l.props.walk("", &mut |_, p| found |= p.expr.is_some());
+ }
+ }
+ }
+ found
+ }
+
/// Allocate an id (items, layers and property uids share one counter).
pub fn alloc(&mut self) -> u64 {
let id = self.next_id;
diff --cc crates/ui-egui/src/frames.rs
index e41a06f7e,059bc3a03..a8675e49c
--- a/crates/ui-egui/src/frames.rs
+++ b/crates/ui-egui/src/frames.rs
@@@ -1982,26 -1996,28 +1982,52 @@@ mod tests
use serde_json::json;
let mut s = Session::default();
let id = |v: serde_json::Value, k: &str| v[k].as_u64().unwrap();
- let outer = ItemId(id(s.execute("comp.new", json!({"name": "Outer", "width": 8, "height": 8, "duration": 1})).unwrap(), "comp"));
- let solid = id(s.execute("layer.newSolid", json!({"comp": outer.0, "color": "#ff0000"})).unwrap(), "layer");
+ let inner = ItemId(id(s.execute("comp.new", json!({"name": "Inner", "width": 8, "height": 8, "duration": 2})).unwrap(), "comp"));
+ let solid = id(s.execute("layer.newSolid", json!({"comp": inner.0, "color": "#ff0000"})).unwrap(), "layer");
+ let outer = ItemId(id(s.execute("comp.new", json!({"name": "Outer", "width": 8, "height": 8, "duration": 2})).unwrap(), "comp"));
+ id(s.execute("layer.addItem", json!({"comp": outer.0, "item": inner.0})).unwrap(), "layer");
let f = Frames::default();
- let at = |s: &Session| f.content_of(&s.project, s.revision, outer);
- let o0 = at(&s);
- s.execute("layer.addMarker", json!({"comp": outer.0, "layers": [solid], "time": 0.5, "comment": "beat"})).unwrap();
- assert_eq!(at(&s), o0, "a marker changes no pixels, so it keeps the frames");
- }
-
+ let at = |s: &Session, c: ItemId| f.content_of(&s.project, s.revision, c);
+ let (o0, i0) = (at(&s, outer), at(&s, inner));
+ s.execute("comp.addMarker", json!({"comp": inner.0, "time": 0.5, "comment": "beat"})).unwrap();
+ s.execute("comp.addMarker", json!({"comp": outer.0, "time": 1.0})).unwrap();
+ s.execute("comp.addMarker", json!({"comp": outer.0, "time": 1.5})).unwrap();
+ assert_eq!((at(&s, outer), at(&s, inner)), (o0, i0), "comp markers");
+ s.execute("markers.set", json!({"comp": inner.0, "layer": solid, "new": true, "time": 0.25})).unwrap();
+ assert_eq!((at(&s, outer), at(&s, inner)), (o0, i0), "layer marker");
+ // An expression reading markers makes them count again.
+ s.execute("prop.setExpression", json!({"comp": inner.0, "layer": solid, "path": "transform/opacity", "expression": "thisComp.marker.numKeys"}))
+ .unwrap();
+ let (o1, i1) = (at(&s, outer), at(&s, inner));
+ assert_ne!(o1, o0);
+ s.execute("comp.addMarker", json!({"comp": inner.0, "time": 1.0})).unwrap();
+ assert_ne!(at(&s, inner), i1, "marker read by an expression");
+ assert_ne!(at(&s, outer), o1, "marker read by an expression in a nested comp");
+ }
++
++ /// A protected time marker with a duration sets the comp's timing (Responsive Design), so it
++ /// changes the frames even though plain markers do not; and any expression, which can read
++ /// markers, makes every marker count.
+ #[test]
- fn markers_count_when_an_expression_can_read_them() {
++ fn timing_markers_and_expressions_still_change_the_frames() {
+ use effectcraft_engine::Session;
+ use serde_json::json;
+ let mut s = Session::default();
+ let id = |v: serde_json::Value, k: &str| v[k].as_u64().unwrap();
+ let outer = ItemId(id(s.execute("comp.new", json!({"name": "Outer", "width": 8, "height": 8, "duration": 1})).unwrap(), "comp"));
+ let solid = id(s.execute("layer.newSolid", json!({"comp": outer.0, "color": "#ff0000"})).unwrap(), "layer");
- s.execute("prop.setExpression", json!({"comp": outer.0, "layer": solid, "path": "transform/opacity", "expression": "1"})).unwrap();
+ let f = Frames::default();
+ let at = |s: &Session| f.content_of(&s.project, s.revision, outer);
+ let o0 = at(&s);
+ s.execute("layer.addMarker", json!({"comp": outer.0, "layers": [solid], "time": 0.5, "comment": "beat"})).unwrap();
- assert_ne!(at(&s), o0, "an expression can read the marker, so the frames change");
++ assert_eq!(at(&s), o0, "a plain marker changes no pixels, so it keeps the frames");
++ s.execute("comp.addMarker", json!({"comp": outer.0, "time": 0.25})).unwrap();
++ s.execute("markers.set", json!({"comp": outer.0, "index": 0, "duration": 0.25, "protected": true})).unwrap();
++ let o1 = at(&s);
++ assert_ne!(o1, o0, "a protected time marker with a duration sets the timing");
++ s.execute("prop.setExpression", json!({"comp": outer.0, "layer": solid, "path": "transform/opacity", "expression": "1"})).unwrap();
++ let o2 = at(&s);
++ s.execute("layer.addMarker", json!({"comp": outer.0, "layers": [solid], "time": 0.75})).unwrap();
++ assert_ne!(at(&s), o2, "an expression can read the marker, so the frames change");
+ }
}