diff --git a/crates/engine/src/editkeys.rs b/crates/engine/src/editkeys.rs index 132378e..6aaf679 100644 --- a/crates/engine/src/editkeys.rs +++ b/crates/engine/src/editkeys.rs @@ -274,7 +274,7 @@ pub fn matched_source( true => clip.out_frame.saturating_sub(1).saturating_sub(from_in), false => clip.in_frame + from_in, }; - let secs = if crate::is_image(&src.path) { 0. } else { f64::from(at) / fps }; + let secs = if crate::is_still(&src.path) { 0. } else { f64::from(at) / fps }; Some((src.path.clone(), src.audio_stream, secs)) } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 67a1bb9..3069ffe 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -169,6 +169,10 @@ pub fn is_image(path: &std::path::Path) -> bool { }) } +pub fn is_still(path: &std::path::Path) -> bool { + is_image(path) && sequence::Run::parse(path).is_none() +} + /// Whether a source's file is there to read: a real file, or a generator, which has none to miss. pub fn source_present(path: &std::path::Path) -> bool { generate::is_generated(path) diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 2a70a4f..a59ac1d 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -5918,6 +5918,7 @@ impl PlaybackSession { start: 0, in_frame: 0, out_frame: match image { + true if !crate::is_still(path) => frames, true => place_frames(frames, self.meta.frame_rate, self.project.still_secs()), false => sound_held_frames(path, stream, frames, self.meta.frame_rate), }, diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 802a33b..0a84af8 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -9686,7 +9686,7 @@ impl Project { fn is_still(&self, clip: &Clip) -> bool { self.sources .get(clip.source) - .is_some_and(|s| crate::is_image(&s.path)) + .is_some_and(|s| crate::is_still(&s.path)) } /// The placements that move as one with the one at `idx` of `lane` -- diff --git a/crates/mcp/src/tools/edit.rs b/crates/mcp/src/tools/edit.rs index cf38528..557b175 100644 --- a/crates/mcp/src/tools/edit.rs +++ b/crates/mcp/src/tools/edit.rs @@ -1310,9 +1310,13 @@ fn place_op( } // `length` sets how long the still shows; omitted, it is the project's still length. let asked = length(op, "length", fps)?; + let run = (!engine::is_still(&path)).then(|| s.file_frames(&path)); let len = match asked { - None => (still * fps).ceil().max(1.0) as u32, + None => run.unwrap_or_else(|| (still * fps).ceil().max(1.0) as u32), Some(0) => return Err(format!("place src:{n}: a still's length must be more than 0")), + Some(l) if run.is_some_and(|r| l > r) => { + return Err(format!("place src:{n}: length {} is past the sequence's {}", secs_text(l, fps), secs_text(run.unwrap_or(0), fps))) + } Some(l) if f64::from(l) > STILL_MAX_SECS * fps => { return Err(format!( "place src:{n}: length {} is past the {STILL_MAX_SECS:.0} s a still may run", @@ -1358,7 +1362,8 @@ fn place_op( } } let touched = clips_of_source_at(s, n, at); - let mut text = format!("{verb} src:{n} (still) @{at}f"); + let kind = if run.is_some() { "sequence" } else { "still" }; + let mut text = format!("{verb} src:{n} ({kind}) @{at}f"); if asked.is_some() { text.push_str(&format!(" for {}", secs_text(len, fps))); } @@ -1646,7 +1651,11 @@ fn op_three_point(s: &mut PlaybackSession, kind: SourceEdit, op: &Value, fps: f6 "src:{n} is a still image, which takes no in/out: give `to` or `length` for how long it shows (default {still:.1} s, the project's still length, up to {STILL_MAX_SECS:.0} s)" )); } - let len = dur.unwrap_or_else(|| (still * fps).ceil().max(1.0) as u32); + let run = (!engine::is_still(&path)).then(|| s.file_frames(&path)); + let len = dur.or(run).unwrap_or_else(|| (still * fps).ceil().max(1.0) as u32); + if run.is_some_and(|r| len > r) { + return Err(format!("{verb} src:{n}: {} is past the sequence's {}", secs_text(len, fps), secs_text(run.unwrap_or(0), fps))); + } if f64::from(len) > STILL_MAX_SECS * fps { return Err(format!("{verb} src:{n}: {} is past the {STILL_MAX_SECS:.0} s a still may run", secs_text(len, fps))); } @@ -1698,7 +1707,11 @@ fn op_three_point(s: &mut PlaybackSession, kind: SourceEdit, op: &Value, fps: f6 let (l_in, l_out) = landed_span(s, &touched, n).unwrap_or((in_f, out_f)); let len = s.lane_clips(touched[0].0).iter().find(|c| c.start == at && c.source == n).map_or(out_f - in_f, |c| c.frames()); let names: Vec = lanes.iter().map(|&l| parse::lane_name(l)).collect(); - let shown = if still { "(still)".to_string() } else { Base::of(s, &path).span(l_in, l_out) }; + let shown = match (still, engine::is_still(&path)) { + (true, true) => "(still)".to_string(), + (true, false) => "(sequence)".to_string(), + _ => Base::of(s, &path).span(l_in, l_out), + }; let mut text = format!( "{verb} src:{n} {shown} at timeline {at}f ({}) on {} for {}{note}", secs_text(at, fps), @@ -6382,9 +6395,9 @@ fn op_replace(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result>())?; let path: PathBuf = s.sources()[n].path.clone(); - let still = engine::is_image(&path); - let picture = still || engine::probe_media(&path).video.is_some(); - let sound = !still + let still = engine::is_still(&path); + let picture = engine::is_image(&path) || engine::probe_media(&path).video.is_some(); + let sound = !engine::is_image(&path) && !AudioSession::probe_streams(&path).map_err(|e| format!("src:{n}: cannot read its sound: {e}"))?.is_empty(); let total = source_frames(s, n, Some(lane), fps); let (in_f, note) = if still { diff --git a/crates/mcp/src/tools/media.rs b/crates/mcp/src/tools/media.rs index d593b0a..8506883 100644 --- a/crates/mcp/src/tools/media.rs +++ b/crates/mcp/src/tools/media.rs @@ -2573,7 +2573,7 @@ mod agreement_tests { quiet(); let td = TestDir::new("png-run-import"); let still = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/../engine/tests/fixtures/fuzz/still.png")).expect("read the still"); - for k in 1..=10 { + for k in 1..=200 { std::fs::write(td.path().join(format!("frame_{k:04}.png")), &still).expect("write a frame"); } let mut server = Server::new(); @@ -2581,8 +2581,11 @@ mod agreement_tests { let one = td.path().join("frame_0004.png"); let r = import(&mut server, &json!({"paths": [one.display().to_string()]})); assert!(!r.is_error, "{}", r.text); - assert!(r.text.contains("image sequence, 10 frames"), "{}", r.text); - assert!(r.text.contains("frame_[0001-0010].png"), "{}", r.text); + assert!(r.text.contains("image sequence, 200 frames"), "{}", r.text); + assert!(r.text.contains("frame_[0001-0200].png"), "{}", r.text); + let r = super::super::edit::run_edit(&mut server, &json!({"ops": [{"op": "append", "source": "src:0"}]})); + assert!(!r.is_error && r.text.contains("(sequence)"), "{}", r.text); + assert_eq!(server.session.as_ref().unwrap().lane_clips(engine::project::Lane::V1)[0].frames(), 200, "{}", r.text); } #[test]