🐛 An image sequence places at its own frame count, not the project's still length, and edit replies name it (sequence)
Browse files at this commitf150749ea02bbc940e3d6d02094dc20d11765e6cParent: a888db96 changed files +33 -12
- crates/engine/src/editkeys.rs +1 -1
- crates/engine/src/lib.rs +4 -0
- crates/engine/src/playback.rs +1 -0
- crates/engine/src/project.rs +1 -1
- crates/mcp/src/tools/edit.rs +20 -7
- crates/mcp/src/tools/media.rs +6 -3
crates/engine/src/editkeys.rsmodified+1 -1
| @@ -274,7 +274,7 @@ pub fn matched_source( | |||
| 274 | true => clip.out_frame.saturating_sub(1).saturating_sub(from_in), | 274 | true => clip.out_frame.saturating_sub(1).saturating_sub(from_in), |
| 275 | false => clip.in_frame + from_in, | 275 | false => clip.in_frame + from_in, |
| 276 | }; | 276 | }; |
| 277 | - let secs = if crate::is_image(&src.path) { 0. } else { f64::from(at) / fps }; | 277 | + let secs = if crate::is_still(&src.path) { 0. } else { f64::from(at) / fps }; |
| 278 | Some((src.path.clone(), src.audio_stream, secs)) | 278 | Some((src.path.clone(), src.audio_stream, secs)) |
| 279 | } | 279 | } |
| 280 | 280 | ||
crates/engine/src/lib.rsmodified+4 -0
| @@ -169,6 +169,10 @@ pub fn is_image(path: &std::path::Path) -> bool { | |||
| 169 | }) | 169 | }) |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | +pub fn is_still(path: &std::path::Path) -> bool { | ||
| 173 | + is_image(path) && sequence::Run::parse(path).is_none() | ||
| 174 | +} | ||
| 175 | + | ||
| 172 | /// Whether a source's file is there to read: a real file, or a generator, which has none to miss. | 176 | /// Whether a source's file is there to read: a real file, or a generator, which has none to miss. |
| 173 | pub fn source_present(path: &std::path::Path) -> bool { | 177 | pub fn source_present(path: &std::path::Path) -> bool { |
| 174 | generate::is_generated(path) | 178 | generate::is_generated(path) |
crates/engine/src/playback.rsmodified+1 -0
| @@ -5918,6 +5918,7 @@ impl PlaybackSession { | |||
| 5918 | start: 0, | 5918 | start: 0, |
| 5919 | in_frame: 0, | 5919 | in_frame: 0, |
| 5920 | out_frame: match image { | 5920 | out_frame: match image { |
| 5921 | + true if !crate::is_still(path) => frames, | ||
| 5921 | true => place_frames(frames, self.meta.frame_rate, self.project.still_secs()), | 5922 | true => place_frames(frames, self.meta.frame_rate, self.project.still_secs()), |
| 5922 | false => sound_held_frames(path, stream, frames, self.meta.frame_rate), | 5923 | false => sound_held_frames(path, stream, frames, self.meta.frame_rate), |
| 5923 | }, | 5924 | }, |
crates/engine/src/project.rsmodified+1 -1
| @@ -9686,7 +9686,7 @@ impl Project { | |||
| 9686 | fn is_still(&self, clip: &Clip) -> bool { | 9686 | fn is_still(&self, clip: &Clip) -> bool { |
| 9687 | self.sources | 9687 | self.sources |
| 9688 | .get(clip.source) | 9688 | .get(clip.source) |
| 9689 | - .is_some_and(|s| crate::is_image(&s.path)) | 9689 | + .is_some_and(|s| crate::is_still(&s.path)) |
| 9690 | } | 9690 | } |
| 9691 | 9691 | ||
| 9692 | /// The placements that move as one with the one at `idx` of `lane` -- | 9692 | /// The placements that move as one with the one at `idx` of `lane` -- |
crates/mcp/src/tools/edit.rsmodified+20 -7
| @@ -1310,9 +1310,13 @@ fn place_op( | |||
| 1310 | } | 1310 | } |
| 1311 | // `length` sets how long the still shows; omitted, it is the project's still length. | 1311 | // `length` sets how long the still shows; omitted, it is the project's still length. |
| 1312 | let asked = length(op, "length", fps)?; | 1312 | let asked = length(op, "length", fps)?; |
| 1313 | + let run = (!engine::is_still(&path)).then(|| s.file_frames(&path)); | ||
| 1313 | let len = match asked { | 1314 | let len = match asked { |
| 1314 | - None => (still * fps).ceil().max(1.0) as u32, | 1315 | + None => run.unwrap_or_else(|| (still * fps).ceil().max(1.0) as u32), |
| 1315 | Some(0) => return Err(format!("place src:{n}: a still's length must be more than 0")), | 1316 | Some(0) => return Err(format!("place src:{n}: a still's length must be more than 0")), |
| 1317 | + Some(l) if run.is_some_and(|r| l > r) => { | ||
| 1318 | + return Err(format!("place src:{n}: length {} is past the sequence's {}", secs_text(l, fps), secs_text(run.unwrap_or(0), fps))) | ||
| 1319 | + } | ||
| 1316 | Some(l) if f64::from(l) > STILL_MAX_SECS * fps => { | 1320 | Some(l) if f64::from(l) > STILL_MAX_SECS * fps => { |
| 1317 | return Err(format!( | 1321 | return Err(format!( |
| 1318 | "place src:{n}: length {} is past the {STILL_MAX_SECS:.0} s a still may run", | 1322 | "place src:{n}: length {} is past the {STILL_MAX_SECS:.0} s a still may run", |
| @@ -1358,7 +1362,8 @@ fn place_op( | |||
| 1358 | } | 1362 | } |
| 1359 | } | 1363 | } |
| 1360 | let touched = clips_of_source_at(s, n, at); | 1364 | let touched = clips_of_source_at(s, n, at); |
| 1361 | - let mut text = format!("{verb} src:{n} (still) @{at}f"); | 1365 | + let kind = if run.is_some() { "sequence" } else { "still" }; |
| 1366 | + let mut text = format!("{verb} src:{n} ({kind}) @{at}f"); | ||
| 1362 | if asked.is_some() { | 1367 | if asked.is_some() { |
| 1363 | text.push_str(&format!(" for {}", secs_text(len, fps))); | 1368 | text.push_str(&format!(" for {}", secs_text(len, fps))); |
| 1364 | } | 1369 | } |
| @@ -1646,7 +1651,11 @@ fn op_three_point(s: &mut PlaybackSession, kind: SourceEdit, op: &Value, fps: f6 | |||
| 1646 | "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)" | 1651 | "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)" |
| 1647 | )); | 1652 | )); |
| 1648 | } | 1653 | } |
| 1649 | - let len = dur.unwrap_or_else(|| (still * fps).ceil().max(1.0) as u32); | 1654 | + let run = (!engine::is_still(&path)).then(|| s.file_frames(&path)); |
| 1655 | + let len = dur.or(run).unwrap_or_else(|| (still * fps).ceil().max(1.0) as u32); | ||
| 1656 | + if run.is_some_and(|r| len > r) { | ||
| 1657 | + return Err(format!("{verb} src:{n}: {} is past the sequence's {}", secs_text(len, fps), secs_text(run.unwrap_or(0), fps))); | ||
| 1658 | + } | ||
| 1650 | if f64::from(len) > STILL_MAX_SECS * fps { | 1659 | if f64::from(len) > STILL_MAX_SECS * fps { |
| 1651 | return Err(format!("{verb} src:{n}: {} is past the {STILL_MAX_SECS:.0} s a still may run", secs_text(len, fps))); | 1660 | return Err(format!("{verb} src:{n}: {} is past the {STILL_MAX_SECS:.0} s a still may run", secs_text(len, fps))); |
| 1652 | } | 1661 | } |
| @@ -1698,7 +1707,11 @@ fn op_three_point(s: &mut PlaybackSession, kind: SourceEdit, op: &Value, fps: f6 | |||
| 1698 | let (l_in, l_out) = landed_span(s, &touched, n).unwrap_or((in_f, out_f)); | 1707 | let (l_in, l_out) = landed_span(s, &touched, n).unwrap_or((in_f, out_f)); |
| 1699 | 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()); | 1708 | 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()); |
| 1700 | let names: Vec<String> = lanes.iter().map(|&l| parse::lane_name(l)).collect(); | 1709 | let names: Vec<String> = lanes.iter().map(|&l| parse::lane_name(l)).collect(); |
| 1701 | - let shown = if still { "(still)".to_string() } else { Base::of(s, &path).span(l_in, l_out) }; | 1710 | + let shown = match (still, engine::is_still(&path)) { |
| 1711 | + (true, true) => "(still)".to_string(), | ||
| 1712 | + (true, false) => "(sequence)".to_string(), | ||
| 1713 | + _ => Base::of(s, &path).span(l_in, l_out), | ||
| 1714 | + }; | ||
| 1702 | let mut text = format!( | 1715 | let mut text = format!( |
| 1703 | "{verb} src:{n} {shown} at timeline {at}f ({}) on {} for {}{note}", | 1716 | "{verb} src:{n} {shown} at timeline {at}f ({}) on {} for {}{note}", |
| 1704 | secs_text(at, fps), | 1717 | secs_text(at, fps), |
| @@ -6382,9 +6395,9 @@ fn op_replace(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Done, Str | |||
| 6382 | let n = source_arg(s, op)?; | 6395 | let n = source_arg(s, op)?; |
| 6383 | check_unlocked(s, &take_of(s, lane, idx).iter().map(|&(l, _)| l).collect::<Vec<_>>())?; | 6396 | check_unlocked(s, &take_of(s, lane, idx).iter().map(|&(l, _)| l).collect::<Vec<_>>())?; |
| 6384 | let path: PathBuf = s.sources()[n].path.clone(); | 6397 | let path: PathBuf = s.sources()[n].path.clone(); |
| 6385 | - let still = engine::is_image(&path); | 6398 | + let still = engine::is_still(&path); |
| 6386 | - let picture = still || engine::probe_media(&path).video.is_some(); | 6399 | + let picture = engine::is_image(&path) || engine::probe_media(&path).video.is_some(); |
| 6387 | - let sound = !still | 6400 | + let sound = !engine::is_image(&path) |
| 6388 | && !AudioSession::probe_streams(&path).map_err(|e| format!("src:{n}: cannot read its sound: {e}"))?.is_empty(); | 6401 | && !AudioSession::probe_streams(&path).map_err(|e| format!("src:{n}: cannot read its sound: {e}"))?.is_empty(); |
| 6389 | let total = source_frames(s, n, Some(lane), fps); | 6402 | let total = source_frames(s, n, Some(lane), fps); |
| 6390 | let (in_f, note) = if still { | 6403 | let (in_f, note) = if still { |
crates/mcp/src/tools/media.rsmodified+6 -3
| @@ -2573,7 +2573,7 @@ mod agreement_tests { | |||
| 2573 | quiet(); | 2573 | quiet(); |
| 2574 | let td = TestDir::new("png-run-import"); | 2574 | let td = TestDir::new("png-run-import"); |
| 2575 | let still = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/../engine/tests/fixtures/fuzz/still.png")).expect("read the still"); | 2575 | let still = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/../engine/tests/fixtures/fuzz/still.png")).expect("read the still"); |
| 2576 | - for k in 1..=10 { | 2576 | + for k in 1..=200 { |
| 2577 | std::fs::write(td.path().join(format!("frame_{k:04}.png")), &still).expect("write a frame"); | 2577 | std::fs::write(td.path().join(format!("frame_{k:04}.png")), &still).expect("write a frame"); |
| 2578 | } | 2578 | } |
| 2579 | let mut server = Server::new(); | 2579 | let mut server = Server::new(); |
| @@ -2581,8 +2581,11 @@ mod agreement_tests { | |||
| 2581 | let one = td.path().join("frame_0004.png"); | 2581 | let one = td.path().join("frame_0004.png"); |
| 2582 | let r = import(&mut server, &json!({"paths": [one.display().to_string()]})); | 2582 | let r = import(&mut server, &json!({"paths": [one.display().to_string()]})); |
| 2583 | assert!(!r.is_error, "{}", r.text); | 2583 | assert!(!r.is_error, "{}", r.text); |
| 2584 | - assert!(r.text.contains("image sequence, 10 frames"), "{}", r.text); | 2584 | + assert!(r.text.contains("image sequence, 200 frames"), "{}", r.text); |
| 2585 | - assert!(r.text.contains("frame_[0001-0010].png"), "{}", r.text); | 2585 | + assert!(r.text.contains("frame_[0001-0200].png"), "{}", r.text); |
| 2586 | + let r = super::super::edit::run_edit(&mut server, &json!({"ops": [{"op": "append", "source": "src:0"}]})); | ||
| 2587 | + assert!(!r.is_error && r.text.contains("(sequence)"), "{}", r.text); | ||
| 2588 | + assert_eq!(server.session.as_ref().unwrap().lane_clips(engine::project::Lane::V1)[0].frames(), 200, "{}", r.text); | ||
| 2586 | } | 2589 | } |
| 2587 | 2590 | ||
| 2588 | #[test] | 2591 | #[test] |