Preview: Audio, Lock and Shy keep the cache; playback with audio waits for frames (#103)
Toggling a layer's Audio, Lock or Shy switch (or Hide Shy Layers) threw away every cached frame: the RAM preview identity hashes each comp's address, which any edit replaces, and the layer and disk cache keys hashed every switch. None of these change pixels. - Switches::pixels, Layer::same_pixels and Comp::same_pixels (exhaustive field lists, so a new field must be considered) and Comp::pixel_form. - Layer cache keys hash Switches::pixels; the disk cache's comp content key hashes Comp::pixel_form. - Frames::identity: when a new revision's comps draw the same pixels as those of the comp's last new identity, that identity (and the project holding its comps' addresses) is kept, so the frames stay, also when the switch is toggled back. With audio on, playback skipped frames that weren't rendered yet. Now the sound waits: until the frames ahead (to the end of the preview, or what fits in the RAM preview) are cached, every frame shows as it renders, silently, like a preview without audio; then the sound starts in sync. Reaching an uncached frame stops the sound instead of skipping frames. Tests: audio_lock_and_shy_switches_keep_the_frames (frames.rs, nested comps and toggling back), audio_lock_and_shy_keep_cached_layers (engine), the disk key in tests_disk_cache, and preview_with_audio_shows_every_frame_and_sounds_once_cached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4a401a4785
commit
93856382e7
@@ -613,6 +613,139 @@ 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).
|
||||
|
||||
impl Switches {
|
||||
/// These switches with Audio, Lock and Shy at their defaults.
|
||||
pub fn pixels(&self) -> Switches {
|
||||
Switches { audio: true, locked: false, shy: false, ..self.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Layer {
|
||||
/// Draws the same pixels as `o`: equal but for the Audio, Lock and Shy switches.
|
||||
pub fn same_pixels(&self, o: &Layer) -> bool {
|
||||
// Every field (no `..`: a new field must be considered here); the property tree last.
|
||||
let Layer {
|
||||
id,
|
||||
name,
|
||||
source,
|
||||
label,
|
||||
comment,
|
||||
start_time,
|
||||
in_point,
|
||||
out_point,
|
||||
stretch,
|
||||
switches,
|
||||
blend_mode,
|
||||
preserve_transparency,
|
||||
track_matte,
|
||||
parent,
|
||||
markers,
|
||||
markers_locked,
|
||||
auto_orient,
|
||||
environment,
|
||||
environment_background,
|
||||
props,
|
||||
} = self;
|
||||
*id == o.id
|
||||
&& *name == o.name
|
||||
&& *source == o.source
|
||||
&& *label == o.label
|
||||
&& *comment == o.comment
|
||||
&& *start_time == o.start_time
|
||||
&& *in_point == o.in_point
|
||||
&& *out_point == o.out_point
|
||||
&& *stretch == o.stretch
|
||||
&& switches.pixels() == o.switches.pixels()
|
||||
&& *blend_mode == o.blend_mode
|
||||
&& *preserve_transparency == o.preserve_transparency
|
||||
&& *track_matte == o.track_matte
|
||||
&& *parent == o.parent
|
||||
&& *markers == o.markers
|
||||
&& *markers_locked == o.markers_locked
|
||||
&& *auto_orient == o.auto_orient
|
||||
&& *environment == o.environment
|
||||
&& *environment_background == o.environment_background
|
||||
&& *props == o.props
|
||||
}
|
||||
}
|
||||
|
||||
impl Comp {
|
||||
/// Draws the same pixels as `o`: equal but for its layers' Audio, Lock and Shy switches and
|
||||
/// Hide Shy Layers.
|
||||
pub fn same_pixels(&self, o: &Comp) -> bool {
|
||||
// Every field (no `..`: a new field must be considered here); the layers last.
|
||||
let Comp {
|
||||
width,
|
||||
height,
|
||||
pixel_aspect,
|
||||
frame_rate,
|
||||
duration,
|
||||
display_start,
|
||||
background,
|
||||
work_area,
|
||||
layers,
|
||||
markers,
|
||||
shutter_angle,
|
||||
shutter_phase,
|
||||
motion_blur_samples,
|
||||
motion_blur_adaptive_limit,
|
||||
renderer,
|
||||
hide_shy: _,
|
||||
enable_motion_blur,
|
||||
enable_frame_blending,
|
||||
draft_3d,
|
||||
preserve_frame_rate,
|
||||
preserve_resolution,
|
||||
poster_time,
|
||||
global_light,
|
||||
guides,
|
||||
essential,
|
||||
} = self;
|
||||
*width == o.width
|
||||
&& *height == o.height
|
||||
&& *pixel_aspect == o.pixel_aspect
|
||||
&& *frame_rate == o.frame_rate
|
||||
&& *duration == o.duration
|
||||
&& *display_start == o.display_start
|
||||
&& *background == o.background
|
||||
&& *work_area == o.work_area
|
||||
&& *markers == o.markers
|
||||
&& *shutter_angle == o.shutter_angle
|
||||
&& *shutter_phase == o.shutter_phase
|
||||
&& *motion_blur_samples == o.motion_blur_samples
|
||||
&& *motion_blur_adaptive_limit == o.motion_blur_adaptive_limit
|
||||
&& *renderer == o.renderer
|
||||
&& *enable_motion_blur == o.enable_motion_blur
|
||||
&& *enable_frame_blending == o.enable_frame_blending
|
||||
&& *draft_3d == o.draft_3d
|
||||
&& *preserve_frame_rate == o.preserve_frame_rate
|
||||
&& *preserve_resolution == o.preserve_resolution
|
||||
&& *poster_time == o.poster_time
|
||||
&& *global_light == o.global_light
|
||||
&& *guides == o.guides
|
||||
&& *essential == o.essential
|
||||
&& layers.len() == o.layers.len()
|
||||
&& layers.iter().zip(&o.layers).all(|(a, b)| a.same_pixels(b))
|
||||
}
|
||||
|
||||
/// The comp with those switches 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.layers.iter().all(|l| l.switches == l.switches.pixels()) {
|
||||
return std::borrow::Cow::Borrowed(self);
|
||||
}
|
||||
let mut c = self.clone();
|
||||
c.hide_shy = false;
|
||||
for l in &mut c.layers {
|
||||
l.switches = l.switches.pixels();
|
||||
}
|
||||
std::borrow::Cow::Owned(c)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum MatteKind {
|
||||
#[default]
|
||||
|
||||
Reference in New Issue
Block a user