Merge remote-tracking branch 'upstream/main' into cache-defaults-3298

This commit is contained in:
vangel76 committed 2026-11-12 00:05:19 +01:00
commit 9924ebb1e0
171 files changed
+6309 -720

No files matched your search

+22 -14
View File
@@ -1,8 +1,11 @@
use super::{Comp, CompSelection, Event, ItemId, LayerId, Result, Session, Tick, Value, commands};
/// `t` as a current time of `comp`: a frame within its duration.
/// `t` as a current time of `comp`: a frame within its duration. The last frame is the last one
/// that starts before the end, so a final partial frame (a duration off the frame grid after a
/// frame-rate change) stays reachable; on the grid it is `duration - frame_duration`.
fn comp_frame_at(comp: &Comp, t: Tick) -> Tick {
comp.frame_rate.snap_nearest(t.min(comp.duration - comp.frame_duration()).max(Tick::ZERO))
let last = comp.frame_rate.snap(comp.duration - Tick(1)).max(Tick::ZERO);
comp.frame_rate.snap_nearest(t.max(Tick::ZERO)).min(last)
}
impl Session {
@@ -114,18 +117,23 @@ impl Session {
/// editor is open, so playback with no text editor does no text copying.
pub fn set_time(&mut self, t: Tick) {
if let Some(c) = self.state.active_comp {
let t = self.project.comp(c).map_or(t, |comp| comp_frame_at(comp, t));
let edited = commands::text_edit::active_editor_snapshot(self);
self.state.times.insert(c, t);
if self.prefs.general.sync_time_related_items {
// Direct call: this `set_time` owns the editor snapshot for both time changes,
// so a synced move does not take a second snapshot or start a second epoch.
self.sync_related_times_inner(c, t);
}
commands::text_edit::after_external_change(self, edited.as_ref());
self.set_time_of(c, t);
}
}
/// Move `comp`'s current time, as [`Session::set_time`] does for the active comp.
pub fn set_time_of(&mut self, c: ItemId, t: Tick) {
let t = self.project.comp(c).map_or(t, |comp| comp_frame_at(comp, t));
let edited = commands::text_edit::active_editor_snapshot(self);
self.state.times.insert(c, t);
if self.prefs.general.sync_time_related_items {
// Direct call: this `set_time_of` owns the editor snapshot for both time changes,
// so a synced move does not take a second snapshot or start a second epoch.
self.sync_related_times_inner(c, t);
}
commands::text_edit::after_external_change(self, edited.as_ref());
}
/// Settings ▸ General ▸ Synchronize Time of All Related Items: moving the current time of
/// `comp` moves the current time of the comps nested in it (through their precomp layers'
/// timing) and of the comps it is nested in, so every related viewer shows the same moment.
@@ -139,8 +147,8 @@ impl Session {
/// Sets the time of every comp related to `comp` through precomp layers: down into the comps
/// it nests (through each layer's timing) and up into the comps nesting it. A seen-set keeps
/// cycles and diamonds finite; each found time is clamped to its comp's last frame, snapped to
/// the nearest frame and stored in `state.times`. The caller owns the text-editor boundary.
/// cycles and diamonds finite; each found time goes through [`comp_frame_at`] (as a direct move
/// does) and is stored in `state.times`. The caller owns the text-editor boundary.
fn sync_related_times_inner(&mut self, comp: ItemId, t: Tick) {
let mut seen = std::collections::BTreeSet::from([comp]);
let mut todo = vec![(comp, t)];
@@ -170,7 +178,7 @@ impl Session {
}
for (cid, ct) in found {
if let Some(c) = self.project.comp(cid) {
let ct = c.frame_rate.snap_nearest(ct.clamp(Tick::ZERO, (c.duration - c.frame_duration()).max(Tick::ZERO)));
let ct = comp_frame_at(c, ct);
self.state.times.insert(cid, ct);
}
}
+12 -5
View File
@@ -103,15 +103,22 @@ impl Session {
effectcraft_project::ItemKind::Footage(f) if f.has_video => {
let f = f.clone();
Some(Box::new(move || {
let img = effectcraft_render::cineon_frame(footage.frame(item, &f, Tick(0))?, &f);
// Point-sample down to at most `max_side` on the long side.
let step = (img.width.max(img.height) as f32 / max_side.max(1) as f32).ceil().max(1.0) as u32;
let (w, h) = (img.width.div_ceil(step), img.height.div_ceil(step));
// Vector footage is drawn at the thumbnail's size: its declared size can be a
// 16384² canvas, gigabytes of pixels to point-sample down to a few dozen.
let scale = (max_side.max(1) as f64 / f.width.max(f.height).max(1) as f64).min(1.0);
let src = footage.vector_frame(item, &f, scale).or_else(|| footage.frame(item, &f, Tick(0)))?;
let img = effectcraft_render::cineon_frame(src, &f);
// Point-sample down to at most `max_side` on the long side (a drawn size one
// pixel over it, from rounding, is shrunk by that pixel, not halved).
let (long, max) = (u64::from(img.width.max(img.height)), u64::from(max_side.max(1)));
let fit = |side: u32| if long <= max { side } else { ((u64::from(side) * max + long / 2) / long).max(1) as u32 };
let (w, h) = (fit(img.width), fit(img.height));
let full = img.to_rgba8();
let mut px = Vec::with_capacity((w * h * 4) as usize);
for y in 0..h {
for x in 0..w {
let i = (((y * step) * img.width + x * step) * 4) as usize;
let (sx, sy) = (u64::from(x) * u64::from(img.width) / u64::from(w), u64::from(y) * u64::from(img.height) / u64::from(h));
let i = ((sy * u64::from(img.width) + sx) * 4) as usize;
px.extend_from_slice(&full[i..i + 4]);
}
}