A layer takes the sound down with it
Browse files at this commitcd0df099d6c4a182c2482d0f0a5456b9041830b3Parent: 9ba8e0a- fix
- a layer takes the sound down with it
3 changed files +149 -22
- crates/app/src/main.rs +36 -16
- crates/engine/src/playback.rs +15 -4
- crates/engine/src/project.rs +98 -2
crates/app/src/main.rsmodified+36 -16
| @@ -11243,11 +11243,11 @@ mod tests { | |||
| 11243 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | 11243 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 11244 | session.set_gain(0.0); | 11244 | session.set_gain(0.0); |
| 11245 | let v2 = session.add_lane(LaneKind::Video); | 11245 | let v2 = session.add_lane(LaneKind::Video); |
| 11246 | - let path = session.sources()[0].path.clone(); | 11246 | + // A bare layer, through the one-lane door: a *drop* on V2 brings the |
| 11247 | + // file's sound down with it and would put a third clip over this span. | ||
| 11248 | + let whole = session.lane_clips(Lane::V1)[0]; | ||
| 11247 | assert!( | 11249 | assert!( |
| 11248 | - session | 11250 | + session.place_at(v2, 0.0, whole), |
| 11249 | - .place_stream_at(0.0, &path, 0, Some(v2)) | ||
| 11250 | - .expect("its own file is on this timeline"), | ||
| 11251 | "a layer covering the same frames as the take" | 11251 | "a layer covering the same frames as the take" |
| 11252 | ); | 11252 | ); |
| 11253 | 11253 | ||
| @@ -11679,30 +11679,50 @@ mod tests { | |||
| 11679 | ); | 11679 | ); |
| 11680 | assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2"); | 11680 | assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2"); |
| 11681 | assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead"); | 11681 | assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead"); |
| 11682 | + // ...with the sound it came with, on the row of its own the drop added: | ||
| 11683 | + // a file with audio dropped on a layer used to land silent. | ||
| 11684 | + let a2 = Lane::new(LaneKind::Audio, 1); | ||
| 11685 | + assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1, v2, a2]); | ||
| 11686 | + assert_eq!(session.lane_clips(a2), session.lane_clips(v2), "same take"); | ||
| 11687 | + assert_eq!( | ||
| 11688 | + session.lane_clips(v2)[0].link, | ||
| 11689 | + session.lane_clips(a2)[0].link, | ||
| 11690 | + "grouped, so a drag moves both" | ||
| 11691 | + ); | ||
| 11682 | // And nowhere else: the first pair is exactly as it was, one take each. | 11692 | // And nowhere else: the first pair is exactly as it was, one take each. |
| 11683 | assert_eq!(session.lane_clips(Lane::V1).len(), 1); | 11693 | assert_eq!(session.lane_clips(Lane::V1).len(), 1); |
| 11684 | assert_eq!(session.lane_clips(Lane::A1).len(), 1); | 11694 | assert_eq!(session.lane_clips(Lane::A1).len(), 1); |
| 11695 | + // ...and it is a project that saves and opens again as it stands: a | ||
| 11696 | + // grouped pair on a further row is what the file has to carry. | ||
| 11697 | + let dir = engine::scratch::Scratch::dir("ve_layer"); | ||
| 11698 | + let file = dir.join("layer.edith"); | ||
| 11699 | + session.save_project(&file).expect("save the project"); | ||
| 11700 | + let back = PlaybackSession::open_project(&file).expect("it loads as it stands"); | ||
| 11701 | + std::fs::remove_dir_all(&dir).ok(); | ||
| 11702 | + assert_eq!(back.lanes(), session.lanes()); | ||
| 11703 | + for lane in back.lanes() { | ||
| 11704 | + assert_eq!(back.lane_clips(lane), session.lane_clips(lane), "{lane:?}"); | ||
| 11705 | + } | ||
| 11685 | // Delete on the layer is a lift: it is laid over the timeline, so | 11706 | // Delete on the layer is a lift: it is laid over the timeline, so |
| 11686 | // closing a hole under it would drag the take beneath out of step with | 11707 | // closing a hole under it would drag the take beneath out of step with |
| 11687 | // it. The take on the first pair is still a take, and still ripples. | 11708 | // it. The take on the first pair is still a take, and still ripples. |
| 11688 | assert!(!whole_take(&session, v2, 0)); | 11709 | assert!(!whole_take(&session, v2, 0)); |
| 11689 | assert!(whole_take(&session, Lane::V1, 0)); | 11710 | assert!(whole_take(&session, Lane::V1, 0)); |
| 11690 | assert!(whole_take(&session, Lane::A1, 0)); | 11711 | assert!(whole_take(&session, Lane::A1, 0)); |
| 11712 | + assert_eq!(a2.label(), "A2"); | ||
| 11691 | assert!(session.lift_clip(v2, 0)); | 11713 | assert!(session.lift_clip(v2, 0)); |
| 11692 | assert!(session.lane_clips(v2).is_empty()); | 11714 | assert!(session.lane_clips(v2).is_empty()); |
| 11693 | assert_eq!(session.lane_clips(Lane::V1).len(), 1, "V1 stayed put"); | 11715 | assert_eq!(session.lane_clips(Lane::V1).len(), 1, "V1 stayed put"); |
| 11716 | + assert_eq!( | ||
| 11717 | + session.lane_clips(a2).len(), | ||
| 11718 | + 1, | ||
| 11719 | + "a lift takes the half it names: the sound is still there to lift" | ||
| 11720 | + ); | ||
| 11721 | + assert!(session.lift_clip(a2, 0)); | ||
| 11694 | 11722 | ||
| 11695 | // A second audio lane used to be what an mp4 export could not write -- | 11723 | // A second audio lane used to be what an mp4 export could not write -- |
| 11696 | // it copied one AAC track and a mix is not a copy. It mixes now | 11724 | // it copied one AAC track and a mix is not a copy. It mixes now |
| 11697 | // (`export::copy_audio`), so no row is greyed by a count of lanes. | 11725 | // (`export::copy_audio`), so no row is greyed by a count of lanes. |
| 11698 | - assert_eq!(format_refusal(&session, Format::Mp4), None); | ||
| 11699 | - let a2 = session.add_lane(LaneKind::Audio); | ||
| 11700 | - assert_eq!(a2.label(), "A2"); | ||
| 11701 | - assert!( | ||
| 11702 | - session | ||
| 11703 | - .place_stream_at(0.0, &path, 0, Some(a2)) | ||
| 11704 | - .expect("its own file is on this timeline") | ||
| 11705 | - ); | ||
| 11706 | for format in [Format::Mp4, Format::Av1, Format::Av1Mp4] { | 11726 | for format in [Format::Mp4, Format::Av1, Format::Av1Mp4] { |
| 11707 | assert_eq!( | 11727 | assert_eq!( |
| 11708 | format_refusal(&session, format), | 11728 | format_refusal(&session, format), |
| @@ -11711,10 +11731,10 @@ mod tests { | |||
| 11711 | ); | 11731 | ); |
| 11712 | } | 11732 | } |
| 11713 | 11733 | ||
| 11714 | - // Undo, one edit at a time and backwards: the drop on A2, the lane A2 | 11734 | + // Undo, one edit at a time and backwards: the lift of the sound, the |
| 11715 | - // itself, the lift, the drop on V2, and last the lane V2 -- an added | 11735 | + // lift of the picture, the drop on V2 with the lane A2 it added, and |
| 11716 | - // track is one step like every other edit. | 11736 | + // last the lane V2 -- an added track is one step like every other edit. |
| 11717 | - for lanes in [4, 3, 3, 3, 2] { | 11737 | + for lanes in [4, 4, 3, 2] { |
| 11718 | assert!(session.undo()); | 11738 | assert!(session.undo()); |
| 11719 | assert_eq!(session.lanes().len(), lanes); | 11739 | assert_eq!(session.lanes().len(), lanes); |
| 11720 | } | 11740 | } |
crates/engine/src/playback.rsmodified+15 -4
| @@ -1944,9 +1944,11 @@ impl PlaybackSession { | |||
| 1944 | /// Which lane it lands on is decided here, from the file and from `onto` -- | 1944 | /// Which lane it lands on is decided here, from the file and from `onto` -- |
| 1945 | /// the lane it was let go over, if it was let go over one at all: a file | 1945 | /// the lane it was let go over, if it was let go over one at all: a file |
| 1946 | /// with a picture asked for by no lane, or for one of the first pair, is | 1946 | /// with a picture asked for by no lane, or for one of the first pair, is |
| 1947 | - /// pasted across `V1` and `A1` as a grouped take; asked for by any further | 1947 | + /// pasted across `V1` and `A1` as a grouped take; asked for by a further |
| 1948 | - /// lane it is *placed* there alone, overwriting what it lands on and | 1948 | + /// *video* lane it is *placed* there with its sound on that lane's own audio |
| 1949 | - /// rippling nothing. A file with no picture ([`crate::is_audio`]) is placed | 1949 | + /// row (`V2` -> `A2`, added if it is not there yet), overwriting what the two |
| 1950 | + /// halves land on and rippling nothing; asked for by a further audio lane it | ||
| 1951 | + /// is that file's sound alone. A file with no picture ([`crate::is_audio`]) is placed | ||
| 1950 | /// on the audio lane it was asked for, or on `A1`, and never on a video | 1952 | /// on the audio lane it was asked for, or on `A1`, and never on a video |
| 1951 | /// lane. A still image ([`crate::is_image`]) is its mirror: the video lane | 1953 | /// lane. A still image ([`crate::is_image`]) is its mirror: the video lane |
| 1952 | /// it was asked for or `V1`, never an audio one, and it goes down | 1954 | /// it was asked for or `V1`, never an audio one, and it goes down |
| @@ -2019,11 +2021,20 @@ impl PlaybackSession { | |||
| 2019 | // A picture: the lane it was let go over, unless that is one of the | 2021 | // A picture: the lane it was let go over, unless that is one of the |
| 2020 | // first pair. Those two are the grouped take a paste spans, and a | 2022 | // first pair. Those two are the grouped take a paste spans, and a |
| 2021 | // further lane is a layer of its own -- its picture on `V2`, its | 2023 | // further lane is a layer of its own -- its picture on `V2`, its |
| 2022 | - // sound on `A2`. | 2024 | + // sound on `A2` (below). |
| 2023 | (false, Some(lane)) if lane.ord > 0 => Some(lane), | 2025 | (false, Some(lane)) if lane.ord > 0 => Some(lane), |
| 2024 | (false, _) => None, | 2026 | (false, _) => None, |
| 2025 | }; | 2027 | }; |
| 2026 | Ok(match onto { | 2028 | Ok(match onto { |
| 2029 | + // A picture let go over a further *video* track lands there with the | ||
| 2030 | + // sound it came with -- `V2`'s picture, `A2`'s sound, one take and | ||
| 2031 | + // one undo step ([`Project::place_take`]). Dropped on a further | ||
| 2032 | + // audio lane it is the sound alone, which is what asking an audio | ||
| 2033 | + // row for an mp4 means. | ||
| 2034 | + Some(lane) if lane.kind == LaneKind::Video => { | ||
| 2035 | + let at = secs_to_frame(timeline_secs, self.meta.frame_rate); | ||
| 2036 | + self.edit(Dirty::Both, |p| p.place_take(lane, at, clip)) | ||
| 2037 | + } | ||
| 2027 | Some(lane) => self.place_at(lane, timeline_secs, clip), | 2038 | Some(lane) => self.place_at(lane, timeline_secs, clip), |
| 2028 | // The grouped take, at the frame it was let go on -- past the last | 2039 | // The grouped take, at the frame it was let go on -- past the last |
| 2029 | // clip included, where the bed is black and the ghost was drawn. | 2040 | // clip included, where the bed is black and the ghost was drawn. |
crates/engine/src/project.rsmodified+98 -2
| @@ -1995,12 +1995,61 @@ impl Project { | |||
| 1995 | link: None, | 1995 | link: None, |
| 1996 | ..clip | 1996 | ..clip |
| 1997 | }; | 1997 | }; |
| 1998 | - let clips = self.lane_mut(lane).expect("checked above"); | 1998 | + self.insert_over(lane, clip); |
| 1999 | + true | ||
| 2000 | + } | ||
| 2001 | + | ||
| 2002 | + /// Place `clip` on `lane` **and its sound on that lane's own audio row** as | ||
| 2003 | + /// one grouped take -- what a picture let go over a further video track | ||
| 2004 | + /// means: `V2`'s picture plays on `V2` and its sound on `A2`, which is added | ||
| 2005 | + /// if it is not there yet (the `+ V` button adds a video row alone). Without | ||
| 2006 | + /// this half a file with sound landed on a layer silent, and the only way to | ||
| 2007 | + /// hear it was to drop it a second time on an audio lane. | ||
| 2008 | + /// | ||
| 2009 | + /// Both halves overwrite what they land on and neither ripples, exactly as | ||
| 2010 | + /// [`place`](Project::place) does -- a layer is laid *over* the timeline, so | ||
| 2011 | + /// nothing under it moves. One history snapshot for the pair, the added lane | ||
| 2012 | + /// included, so one [`Project::undo`] takes the whole placement back. The two | ||
| 2013 | + /// carry one link, which is what makes them one take to a drag, a trim and a | ||
| 2014 | + /// save. | ||
| 2015 | + /// | ||
| 2016 | + /// Refused, changing nothing, for an empty `clip` and for a lane that is not | ||
| 2017 | + /// there or is not a video lane: sound placed alone is | ||
| 2018 | + /// [`place`](Project::place)'s door, and a still has no sound to pair. | ||
| 2019 | + pub fn place_take(&mut self, lane: Lane, timeline_frame: u32, clip: Clip) -> bool { | ||
| 2020 | + if clip.out_frame <= clip.in_frame | ||
| 2021 | + || lane.kind != LaneKind::Video | ||
| 2022 | + || self.index(lane).is_none() | ||
| 2023 | + { | ||
| 2024 | + return false; | ||
| 2025 | + } | ||
| 2026 | + self.snapshot(); | ||
| 2027 | + // `A2` for `V2` -- and the rows between it and the last audio lane, since | ||
| 2028 | + // an ord names a lane only while every ord below it does. | ||
| 2029 | + while self.lane_count(LaneKind::Audio) <= lane.ord { | ||
| 2030 | + self.lanes.push(LaneData::new(LaneKind::Audio, Vec::new())); | ||
| 2031 | + } | ||
| 2032 | + let clip = Clip { | ||
| 2033 | + start: timeline_frame, | ||
| 2034 | + link: Some(self.new_link()), | ||
| 2035 | + ..clip | ||
| 2036 | + }; | ||
| 2037 | + for half in [lane, Lane::new(LaneKind::Audio, lane.ord)] { | ||
| 2038 | + self.insert_over(half, clip); | ||
| 2039 | + } | ||
| 2040 | + debug_assert!(links_are_consistent(&self.lanes).is_ok()); | ||
| 2041 | + true | ||
| 2042 | + } | ||
| 2043 | + | ||
| 2044 | + /// `clip` into `lane` at its own start, over whatever it lands on: the | ||
| 2045 | + /// insert both placement doors make, which is what keeps a lane sorted and | ||
| 2046 | + /// disjoint. The caller has checked that the lane is there. | ||
| 2047 | + fn insert_over(&mut self, lane: Lane, clip: Clip) { | ||
| 2048 | + let clips = self.lane_mut(lane).expect("the caller checked the lane"); | ||
| 1999 | clear(clips, clip.start, clip.end()); | 2049 | clear(clips, clip.start, clip.end()); |
| 2000 | let idx = clips.partition_point(|c| c.start < clip.start); | 2050 | let idx = clips.partition_point(|c| c.start < clip.start); |
| 2001 | clips.insert(idx, clip); | 2051 | clips.insert(idx, clip); |
| 2002 | debug_assert!(sorted_disjoint(clips)); | 2052 | debug_assert!(sorted_disjoint(clips)); |
| 2003 | - true | ||
| 2004 | } | 2053 | } |
| 2005 | 2054 | ||
| 2006 | /// Move the clip at `idx` of `from` onto `to` with its head at timeline | 2055 | /// Move the clip at `idx` of `from` onto `to` with its head at timeline |
| @@ -3884,6 +3933,53 @@ mod tests { | |||
| 3884 | assert!(!p.place(Lane::V1, 0, clip(0, 7, 7, 0)), "empty clip"); | 3933 | assert!(!p.place(Lane::V1, 0, clip(0, 7, 7, 0)), "empty clip"); |
| 3885 | } | 3934 | } |
| 3886 | 3935 | ||
| 3936 | + /// A file with sound let go over a further video track: both halves go down, | ||
| 3937 | + /// on the same frames, and the audio row is added when the `+ V` button left | ||
| 3938 | + /// the project without one. One undo takes the lane and both clips back. | ||
| 3939 | + #[test] | ||
| 3940 | + fn a_take_placed_on_a_layer_lands_with_its_sound() { | ||
| 3941 | + let mut p = three(); | ||
| 3942 | + let v2 = p.add_lane(LaneKind::Video); | ||
| 3943 | + assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2], "no A2 yet"); | ||
| 3944 | + | ||
| 3945 | + assert!(p.place_take(v2, 4, clip(0, 100, 102, 0))); | ||
| 3946 | + let a2 = Lane::new(LaneKind::Audio, 1); | ||
| 3947 | + assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2, a2], "A2 was added"); | ||
| 3948 | + assert_eq!(p.lane(v2), p.lane(a2), "same frames, same source"); | ||
| 3949 | + assert_eq!(p.lane(v2)[0].start, 4); | ||
| 3950 | + assert_eq!(p.lane(v2)[0].end(), 6); | ||
| 3951 | + assert_eq!( | ||
| 3952 | + p.lane(v2)[0].link, | ||
| 3953 | + p.lane(a2)[0].link, | ||
| 3954 | + "one take, not two placements" | ||
| 3955 | + ); | ||
| 3956 | + assert!(p.lane(v2)[0].link.is_some()); | ||
| 3957 | + assert_eq!(shape(&p)[0], shape(&three())[0], "V1 untouched"); | ||
| 3958 | + assert_eq!(shape(&p)[1], shape(&three())[1], "and A1 with it"); | ||
| 3959 | + | ||
| 3960 | + // The pair overwrites its own two lanes and nothing else, exactly as a | ||
| 3961 | + // one-lane place does. | ||
| 3962 | + assert!(p.place_take(v2, 5, clip(0, 200, 203, 0))); | ||
| 3963 | + assert_eq!(p.lane(v2), p.lane(a2)); | ||
| 3964 | + assert_eq!(p.lane(v2).len(), 2, "the tail of the first is still there"); | ||
| 3965 | + assert_eq!(shape(&p)[0], shape(&three())[0], "V1 still untouched"); | ||
| 3966 | + | ||
| 3967 | + assert!(p.undo(), "one step for the second pair"); | ||
| 3968 | + assert_eq!(p.lane(v2).len(), 1); | ||
| 3969 | + assert!(p.undo(), "one step for the first pair *and* its lane"); | ||
| 3970 | + assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2]); | ||
| 3971 | + assert!(p.lane(v2).is_empty()); | ||
| 3972 | + | ||
| 3973 | + // Refusals cost nothing: sound placed alone is `place`'s door. | ||
| 3974 | + assert!(!p.place_take(Lane::A1, 0, clip(0, 100, 102, 0)), "audio lane"); | ||
| 3975 | + assert!(!p.place_take(v2, 0, clip(0, 7, 7, 0)), "empty clip"); | ||
| 3976 | + assert!( | ||
| 3977 | + !p.place_take(Lane::new(LaneKind::Video, 9), 0, clip(0, 1, 2, 0)), | ||
| 3978 | + "a lane that is not there" | ||
| 3979 | + ); | ||
| 3980 | + assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2]); | ||
| 3981 | + } | ||
| 3982 | + | ||
| 3887 | /// The drag between tracks: let go at the frames it already covers the clip | 3983 | /// The drag between tracks: let go at the frames it already covers the clip |
| 3888 | /// keeps them, one undo takes it back, and every way it can be refused | 3984 | /// keeps them, one undo takes it back, and every way it can be refused |
| 3889 | /// leaves the project untouched. | 3985 | /// leaves the project untouched. |