Group reaches the sound before a video layer over it
Browse files at this commitccd1ffa4a3da664a28a9656d4a887764c137efb2Parent: 7cce619- fix
- Group reaches the sound before a video layer over it
1 changed file +74 -8
- crates/app/src/main.rs +74 -8
crates/app/src/main.rsmodified+74 -8
| @@ -4885,17 +4885,24 @@ fn whole_take(session: &PlaybackSession, lane: Lane, idx: usize) -> bool { | ||
| 4885 | 4885 | /// notice says so. |
| 4886 | 4886 | fn span_partner(session: &PlaybackSession, lane: Lane, idx: usize) -> Option<(Lane, usize)> { |
| 4887 | 4887 | let clip = *session.lane_clips(lane).get(idx)?; |
| 4888 | - session | |
| 4888 | + let matches = |other: Lane| { | |
| 4889 | + let i = session.lane_clips(other).iter().position(|c| { | |
| 4890 | + (c.start, c.end()) == (clip.start, clip.end()) | |
| 4891 | + && !(c.link.is_some() && c.link == clip.link) | |
| 4892 | + })?; | |
| 4893 | + Some((other, i)) | |
| 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 | |
| 4889 | 4901 | .lanes() |
| 4890 | 4902 | .into_iter() |
| 4891 | 4903 | .filter(|&other| other != lane) |
| 4892 | - .find_map(|other| { | |
| 4893 | - let i = session.lane_clips(other).iter().position(|c| { | |
| 4894 | - (c.start, c.end()) == (clip.start, clip.end()) | |
| 4895 | - && !(c.link.is_some() && c.link == clip.link) | |
| 4896 | - })?; | |
| 4897 | - Some((other, i)) | |
| 4898 | - }) | |
| 4904 | + .partition(|other| other.kind != lane.kind); | |
| 4905 | + opposite.into_iter().chain(same).find_map(matches) | |
| 4899 | 4906 | } |
| 4900 | 4907 | |
| 4901 | 4908 | /// 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 | 5721 | /// The refusal path, end to end against the real files: an incompatible |
| 5656 | 5722 | /// import changes nothing, and the library mirrors `sources()` 1:1, so a |
| 5657 | 5723 | /// refused file cannot leave a row behind. |