forge
Explore
Log in

Don't you dare go Hollow

Group reaches the sound before a video layer over it

Browse files at this commit

ccd1ffa4a3da664a28a9656d4a887764c137efb2Ahmet Kaan GümüşParent: 7cce619
  • fix
    • Group reaches the sound before a video layer over it
Show full message
🐛 fix(timeline): Group reaches the sound before a video layer over it

`span_partner` walked the lanes in storage order, and a project file may hold
them in any order: with the audio lane stored after a second video one, Group on
a detached picture paired it with the layer above it and left the sound out. The
walk now takes the lanes of the *other* kind first -- "group this" means the
other half of the take -- and keeps a same-kind lane as the fallback, so two
video lanes are still groupable where no sound covers the span.

The test builds exactly that order, which only a saved project can hold: the
project is written, its audio lines moved to the end, and loaded back.
crates/app/src/main.rsmodified+72 -6
@@ -4885,17 +4885,24 @@ fn whole_take(session: &PlaybackSession, lane: Lane, idx: usize) -> bool {
4885 /// notice says so.4885 /// notice says so.
4886 fn span_partner(session: &PlaybackSession, lane: Lane, idx: usize) -> Option<(Lane, usize)> {4886 fn span_partner(session: &PlaybackSession, lane: Lane, idx: usize) -> Option<(Lane, usize)> {
4887 let clip = *session.lane_clips(lane).get(idx)?;4887 let clip = *session.lane_clips(lane).get(idx)?;
4888- session4888+ let matches = |other: Lane| {
4889- .lanes()
4890- .into_iter()
4891- .filter(|&other| other != lane)
4892- .find_map(|other| {
4893 let i = session.lane_clips(other).iter().position(|c| {4889 let i = session.lane_clips(other).iter().position(|c| {
4894 (c.start, c.end()) == (clip.start, clip.end())4890 (c.start, c.end()) == (clip.start, clip.end())
4895 && !(c.link.is_some() && c.link == clip.link)4891 && !(c.link.is_some() && c.link == clip.link)
4896 })?;4892 })?;
4897 Some((other, i))4893 Some((other, i))
4898- })4894+ };
4895+ // Sound before picture (and picture before sound): "group this" means the
4896+ // other half of the take, and a project whose audio lane was added after a
4897+ // second video one has that half *after* the layer in storage order -- which
4898+ // is the order the lanes come in. A same-kind lane is still groupable (V1
4899+ // and V2 may be one take), but only where no opposite one covers the span.
4900+ let (opposite, same): (Vec<Lane>, Vec<Lane>) = session
4901+ .lanes()
4902+ .into_iter()
4903+ .filter(|&other| other != lane)
4904+ .partition(|other| other.kind != lane.kind);
4905+ opposite.into_iter().chain(same).find_map(matches)
4899 }4906 }
4900 4907
4901 /// Whether a click marks this clip: the clip that was clicked always, and the4908 /// Whether a click marks this clip: the clip that was clicked always, and the
@@ -5652,6 +5659,65 @@ mod tests {
5652 );5659 );
5653 }5660 }
5654 5661
5662+ /// Which clip Group reaches when more than one covers the span: the sound,
5663+ /// whatever order the lanes are stored in. A project file may hold them in
5664+ /// any order -- a video layer *before* the audio lane among them -- and
5665+ /// "group this" means the other half of the take, never the layer above it.
5666+ #[test]
5667+ fn group_reaches_the_sound_before_a_video_layer_over_it() {
5668+ use engine::project::LaneKind;
5669+
5670+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
5671+ session.set_gain(0.0);
5672+ let v2 = session.add_lane(LaneKind::Video);
5673+ let path = session.sources()[0].path.clone();
5674+ let frames = source_frames(lane_clips(&session), session.sources(), &path);
5675+ assert!(
5676+ session
5677+ .place_stream_at(0.0, &path, 0, frames, Some(v2))
5678+ .expect("its own file is on this timeline"),
5679+ "a layer covering the same frames as the take"
5680+ );
5681+
5682+ // Saved and loaded back with the lanes in the order a hand-written
5683+ // project may hold them: the sound last, behind the layer.
5684+ let dir = std::env::temp_dir().join(format!("ve_group_{}", std::process::id()));
5685+ std::fs::create_dir_all(&dir).expect("a scratch directory");
5686+ let file = dir.join("lanes.edith");
5687+ session.save_project(&file).expect("save the project");
5688+ let text = std::fs::read_to_string(&file).expect("read it back");
5689+ let (sound, rest): (Vec<&str>, Vec<&str>) =
5690+ text.lines().partition(|l| l.starts_with("audio "));
5691+ std::fs::write(
5692+ &file,
5693+ format!("{}\n{}\n", rest.join("\n"), sound.join("\n")),
5694+ )
5695+ .expect("write the reordered project");
5696+ let mut session = PlaybackSession::open_project(&file).expect("it loads as it stands");
5697+ std::fs::remove_dir_all(&dir).ok();
5698+ assert_eq!(
5699+ session.lanes(),
5700+ vec![Lane::V1, v2, Lane::A1],
5701+ "the sound is the last lane there"
5702+ );
5703+
5704+ // Detached, so Group has a choice to get wrong: the layer covers these
5705+ // frames too, and it is the lane the walk meets first.
5706+ assert!(session.ungroup(Lane::V1, 0));
5707+ // Group on the picture reaches the sound, not that layer.
5708+ assert_eq!(span_partner(&session, Lane::V1, 0), Some((Lane::A1, 0)));
5709+ session
5710+ .group(Lane::V1, 0, Lane::A1, 0)
5711+ .expect("the two halves cover the same frames");
5712+ // ...and a lane of its own kind is still groupable, once the sound is
5713+ // spoken for: two video lanes may be one take.
5714+ assert_eq!(
5715+ span_partner(&session, Lane::V1, 0),
5716+ Some((v2, 0)),
5717+ "the layer is what is left to group with"
5718+ );
5719+ }
5720+
5655 /// The refusal path, end to end against the real files: an incompatible5721 /// The refusal path, end to end against the real files: an incompatible
5656 /// import changes nothing, and the library mirrors `sources()` 1:1, so a5722 /// import changes nothing, and the library mirrors `sources()` 1:1, so a
5657 /// refused file cannot leave a row behind.5723 /// refused file cannot leave a row behind.