Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/rustmotion-cli/src/commands/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,7 @@ pub fn validate_geometry_animated(scenario: &ResolvedScenario) -> Vec<GeometryVi
let root_css = render::root_style(scene.layout.as_ref(), view.view_type.clone());
let anim = Some(BuildAnimationCtx {
time,
scenario_time: time,
scene_duration,
fps,
});
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmotion-components/src/audio_spectrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Painter for AudioSpectrum {
let w = layout.width;
let h = layout.height;
let n = self.bars.max(1) as usize;
let values = self.get_band_values(ctx.time);
let values = self.get_band_values(ctx.scenario_time);
let (r, g, b, a) = parse_hex_color(&self.color);
let color = Color::from_argb(a, r, g, b);

Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
20 changes: 18 additions & 2 deletions crates/rustmotion-components/src/box_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ use crate::{ChildComponent, Component};
#[derive(Debug, Clone, Copy)]
pub struct BuildAnimationCtx {
pub time: f64,
/// Seconds since the scenario started, as opposed to `time`, which
/// restarts at every scene. Only the `audio-reactive` binding reads it:
/// the audio analysis is indexed on the scenario's timeline, so using
/// `time` gave a scene starting at t=73 s the analysis at 73 s *into that
/// scene*. Every animation stays on `time`, which is what a delay, a
/// stagger or a preset is written against.
pub scenario_time: f64,
pub scene_duration: f64,
/// Frames per second of the output video. Required to convert the
/// `shutter` fraction (in `MotionBlurConfig`) into an absolute temporal
Expand Down Expand Up @@ -305,6 +312,7 @@ fn build_ghosts<'a>(
// Resolve animation props at the *ghost* time.
let ghost_actx = BuildAnimationCtx {
time: ghost_time,
scenario_time: actx.scenario_time,
scene_duration: actx.scene_duration,
fps: actx.fps,
};
Expand Down Expand Up @@ -428,6 +436,11 @@ fn build_child<'a>(
let (scale, shift) = time_remap;
BuildAnimationCtx {
time: a.time * scale + shift,
// A container's `time_scale`/`time_offset` remaps the *animation*
// clock of its subtree. The audio is not part of that subtree —
// it plays at wall-clock speed regardless — so the scenario clock
// passes through unremapped.
scenario_time: a.scenario_time,
scene_duration: a.scene_duration,
fps: a.fps,
}
Expand Down Expand Up @@ -545,10 +558,10 @@ fn build_child<'a>(
let raw = if let Some(analysis) = analysis_opt {
match &ar.source {
AudioSource::Amplitude(AudioSourceTag::Amplitude) => {
analysis.amplitude_smoothed(actx.time, ar.smoothing_frames)
analysis.amplitude_smoothed(actx.scenario_time, ar.smoothing_frames)
}
AudioSource::Band { band } => {
analysis.band_smoothed(actx.time, *band, ar.smoothing_frames)
analysis.band_smoothed(actx.scenario_time, *band, ar.smoothing_frames)
}
}
} else {
Expand Down Expand Up @@ -2657,6 +2670,7 @@ mod tests {
}
let anim = BuildAnimationCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
fps: 30,
};
Expand Down Expand Up @@ -2709,6 +2723,7 @@ mod tests {
}
let anim = BuildAnimationCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
fps: 30,
};
Expand Down Expand Up @@ -2737,6 +2752,7 @@ mod tests {
let shape = make_shape(100.0, 100.0);
let anim = BuildAnimationCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
fps: 30,
};
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/callout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/caption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ mod tests {
fn test_ctx(time: f64) -> PaintCtx {
PaintCtx {
time,
scenario_time: time,
scene_duration: 2.0,
frame_index: (time * 30.0) as u32,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ mod tests {
let mut surface = skia_safe::surfaces::raster_n32_premul((W, H)).expect("raster surface");
let ctx = PaintCtx {
time: 1.0,
scenario_time: 1.0,
scene_duration: 2.0,
frame_index: 30,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/gradient_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ mod tests {
fn base_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/kbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
7 changes: 7 additions & 0 deletions crates/rustmotion-components/src/legacy_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl<'a> PaintDispatcher for LegacyPaintDispatcher<'a> {

let paint_ctx = PaintCtx {
time: local_time,
scenario_time: frame.scenario_time,
scene_duration: frame.scene_duration,
frame_index: frame.frame_index,
fps: frame.fps,
Expand Down Expand Up @@ -246,6 +247,7 @@ mod tests {
let dispatcher = LegacyPaintDispatcher::new(&built.components);
let frame = PaintFrame {
time: 0.0,
scenario_time: 0.0,
frame_index: 0,
fps: 30,
video_width: 200,
Expand Down Expand Up @@ -314,6 +316,7 @@ mod tests {
let dispatcher = LegacyPaintDispatcher::new(&built.components);
let frame = PaintFrame {
time: 0.0,
scenario_time: 0.0,
frame_index: 0,
fps: 30,
video_width: 200,
Expand Down Expand Up @@ -415,6 +418,7 @@ mod tests {
let dispatcher = LegacyPaintDispatcher::new(&built.components);
let frame = PaintFrame {
time: 0.0,
scenario_time: 0.0,
frame_index: 0,
fps: 30,
video_width: 200,
Expand Down Expand Up @@ -511,6 +515,7 @@ mod tests {
(200.0, 200.0),
crate::box_builder::BuildAnimationCtx {
time,
scenario_time: time,
scene_duration: 1.0,
fps: 30,
},
Expand All @@ -523,6 +528,7 @@ mod tests {
let dispatcher = LegacyPaintDispatcher::new(&built.components);
let frame = PaintFrame {
time,
scenario_time: time,
frame_index: 0,
fps: 30,
video_width: 200,
Expand Down Expand Up @@ -591,6 +597,7 @@ mod tests {
};
let frame = PaintFrame {
time: 0.0,
scenario_time: 0.0,
frame_index: 0,
fps: 30,
video_width: 10,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/marquee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 1.0,
scenario_time: 1.0,
scene_duration: 2.0,
frame_index: 30,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/pill_nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ mod tests {
fn base_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 2.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ mod tests {
let mut surface = skia_safe::surfaces::raster_n32_premul((W, H)).expect("raster surface");
let ctx = PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ mod tests {
let mut surface = skia_safe::surfaces::raster_n32_premul((W, H)).expect("raster surface");
let ctx = PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ mod tests {
fn test_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
1 change: 1 addition & 0 deletions crates/rustmotion-components/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ mod tests {
fn base_ctx() -> PaintCtx {
PaintCtx {
time: 0.0,
scenario_time: 0.0,
scene_duration: 1.0,
frame_index: 0,
fps: 30,
Expand Down
6 changes: 3 additions & 3 deletions crates/rustmotion-components/src/waveform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct Waveform {
/// Visual style: line or filled.
#[serde(default)]
pub draw_style: DrawStyle,
/// Time window in seconds, centered on ctx.time.
/// Time window in seconds, centered on ctx.scenario_time.
#[serde(default = "default_window")]
pub window: f32,
#[serde(flatten)]
Expand Down Expand Up @@ -91,8 +91,8 @@ impl Painter for Waveform {
};

let half_window = self.window as f64 / 2.0;
let t_start = (ctx.time - half_window).max(0.0);
let t_end = ctx.time + half_window;
let t_start = (ctx.scenario_time - half_window).max(0.0);
let t_end = ctx.scenario_time + half_window;

// Sample N points along the window
let n_points = w as usize;
Expand Down
2 changes: 2 additions & 0 deletions crates/rustmotion-components/tests/caption_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn render_caption_at(json: serde_json::Value, time: f64, y: f32) -> Vec<u8> {
(W as f32, H as f32),
BuildAnimationCtx {
time,
scenario_time: time,
scene_duration: 2.0,
fps: 30,
},
Expand All @@ -58,6 +59,7 @@ fn render_caption_at(json: serde_json::Value, time: f64, y: f32) -> Vec<u8> {
let dispatcher = LegacyPaintDispatcher::for_scene(&built);
let frame = PaintFrame {
time,
scenario_time: time,
frame_index: (time * 30.0) as u32,
fps: 30,
video_width: W,
Expand Down
2 changes: 2 additions & 0 deletions crates/rustmotion-components/tests/codeblock_auto_scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fn render_codeblock_at(time: f64) -> Vec<u8> {
(W as f32, H as f32),
BuildAnimationCtx {
time,
scenario_time: time,
scene_duration: SCENE_DURATION,
fps: 30,
},
Expand All @@ -84,6 +85,7 @@ fn render_codeblock_at(time: f64) -> Vec<u8> {
let dispatcher = LegacyPaintDispatcher::for_scene(&built);
let frame = PaintFrame {
time,
scenario_time: time,
frame_index: (time * 30.0) as u32,
fps: 30,
video_width: W,
Expand Down
2 changes: 2 additions & 0 deletions crates/rustmotion-components/tests/degenerate_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn paint(json: serde_json::Value, time: f64) {
(W as f32, H as f32),
BuildAnimationCtx {
time,
scenario_time: time,
scene_duration: 2.0,
fps: 30,
},
Expand All @@ -57,6 +58,7 @@ fn paint(json: serde_json::Value, time: f64) {
let dispatcher = LegacyPaintDispatcher::for_scene(&built);
let frame = PaintFrame {
time,
scenario_time: time,
frame_index: (time * 30.0) as u32,
fps: 30,
video_width: W,
Expand Down
2 changes: 2 additions & 0 deletions crates/rustmotion-components/tests/relative_font_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn render(json: serde_json::Value) -> Vec<u8> {
(W as f32, H as f32),
BuildAnimationCtx {
time: 0.5,
scenario_time: 0.5,
scene_duration: 2.0,
fps: 30,
},
Expand All @@ -53,6 +54,7 @@ fn render(json: serde_json::Value) -> Vec<u8> {
let dispatcher = LegacyPaintDispatcher::for_scene(&built);
let frame = PaintFrame {
time: 0.5,
scenario_time: 0.5,
frame_index: 15,
fps: 30,
video_width: W,
Expand Down
2 changes: 2 additions & 0 deletions crates/rustmotion-components/tests/text_autofit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn render_at(content: &str, autofit: bool, time: f64) -> Vec<u8> {
(W as f32, H as f32),
BuildAnimationCtx {
time,
scenario_time: time,
scene_duration: SCENE_DURATION,
fps: 30,
},
Expand All @@ -76,6 +77,7 @@ fn render_at(content: &str, autofit: bool, time: f64) -> Vec<u8> {
let dispatcher = LegacyPaintDispatcher::for_scene(&built);
let frame = PaintFrame {
time,
scenario_time: time,
frame_index: (time * 30.0) as u32,
fps: 30,
video_width: W,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn css_at(json: serde_json::Value, time: f64) -> CssStyle {
CssStyle::default(),
BuildAnimationCtx {
time,
scenario_time: time,
scene_duration: SCENE_DURATION,
fps: 30,
},
Expand Down
Loading
Loading