forge
Explore
Log in

Don't you dare go Hollow

Per-clip audio fades and adjacency crossfade (edith 18)

Browse files at this commit

4e4ec1632a1925d41966afc4b6e4795230ce94c3Ahmet Kaan GümüşParent: a80334d6d0747c
  • feat
    • per-clip audio fades and adjacency crossfade (edith 18)
Show full message
✨ feat(engine): per-clip audio fades and adjacency crossfade (edith 18)

# Conflicts:
#	crates/engine/src/export.rs
crates/app/src/tests/editing.rsmodified+10 -0
@@ -615,6 +615,8 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
615 use keymap::{ActionId, Keymap};615 use keymap::{ActionId, Keymap};
616 // Frames 30..90 of the timeline, taken from the head of its source.616 // Frames 30..90 of the timeline, taken from the head of its source.
617 let clip = Clip {617 let clip = Clip {
618+ fade_in: 0,
619+ fade_out: 0,
618 start: 30,620 start: 30,
619 in_frame: 0,621 in_frame: 0,
620 out_frame: 60,622 out_frame: 60,
@@ -655,6 +657,8 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
655 // clip by any reading of the playhead, so "only from inside a clip"657 // clip by any reading of the playhead, so "only from inside a clip"
656 // there is a refusal claiming something the screen contradicts.658 // there is a refusal claiming something the screen contradicts.
657 let slow = Clip {659 let slow = Clip {
660+ fade_in: 0,
661+ fade_out: 0,
658 speed: Speed::MIN,662 speed: Speed::MIN,
659 ..clip663 ..clip
660 };664 };
@@ -679,6 +683,8 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
679 // engine's question. Group is offered on every clip, for that reason.683 // engine's question. Group is offered on every clip, for that reason.
680 assert!(!offered(&clip, v1, ActionId::Detach, 0));684 assert!(!offered(&clip, v1, ActionId::Detach, 0));
681 let grouped = Clip {685 let grouped = Clip {
686+ fade_in: 0,
687+ fade_out: 0,
682 link: Some(3),688 link: Some(3),
683 ..clip689 ..clip
684 };690 };
@@ -981,6 +987,8 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
981 fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() {987 fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() {
982 use keymap::ActionId;988 use keymap::ActionId;
983 let clip = Clip {989 let clip = Clip {
990+ fade_in: 0,
991+ fade_out: 0,
984 start: 30,992 start: 30,
985 in_frame: 0,993 in_frame: 0,
986 out_frame: 60,994 out_frame: 60,
@@ -1611,6 +1619,8 @@ fn removing_a_row_is_refused_while_it_plays_and_takes_the_row_away() {
1611 #[test]1619 #[test]
1612 fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() {1620 fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() {
1613 let clip = |source: usize| Clip {1621 let clip = |source: usize| Clip {
1622+ fade_in: 0,
1623+ fade_out: 0,
1614 start: 0,1624 start: 0,
1615 in_frame: 0,1625 in_frame: 0,
1616 out_frame: 30,1626 out_frame: 30,
crates/app/src/tests/layout.rsmodified+2 -0
@@ -801,6 +801,8 @@ fn a_stills_trim_preview_grows_forward_like_the_commit() {
801 #[test]801 #[test]
802 fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() {802 fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() {
803 let at = |start: u32| Clip {803 let at = |start: u32| Clip {
804+ fade_in: 0,
805+ fade_out: 0,
804 start,806 start,
805 in_frame: 0,807 in_frame: 0,
806 out_frame: 30,808 out_frame: 30,
crates/app/src/tests/view.rsmodified+2 -0
@@ -147,6 +147,8 @@ fn a_lane_refuses_the_files_it_cannot_hold_before_the_release_says_so() {
147 #[test]147 #[test]
148 fn the_marks_are_every_lane_the_playhead_and_the_start() {148 fn the_marks_are_every_lane_the_playhead_and_the_start() {
149 let clip = |start: u32, frames: u32, link| Clip {149 let clip = |start: u32, frames: u32, link| Clip {
150+ fade_in: 0,
151+ fade_out: 0,
150 start,152 start,
151 in_frame: 0,153 in_frame: 0,
152 out_frame: frames,154 out_frame: frames,
crates/app/src/timeline_math.rsmodified+6 -0
@@ -303,12 +303,16 @@ pub(crate) fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip
303 };303 };
304 match still {304 match still {
305 true => Clip {305 true => Clip {
306+ fade_in: 0,
307+ fade_out: 0,
306 in_frame: 0,308 in_frame: 0,
307 out_frame: keep,309 out_frame: keep,
308 start: to,310 start: to,
309 ..clip311 ..clip
310 },312 },
311 false => Clip {313 false => Clip {
314+ fade_in: 0,
315+ fade_out: 0,
312 in_frame: clip.out_frame - keep.min(clip.out_frame),316 in_frame: clip.out_frame - keep.min(clip.out_frame),
313 start: to,317 start: to,
314 ..clip318 ..clip
@@ -317,6 +321,8 @@ pub(crate) fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip
317 }321 }
318 Edge::End => match clip.speed.fit(to.saturating_sub(clip.start)) {322 Edge::End => match clip.speed.fit(to.saturating_sub(clip.start)) {
319 Some(keep) => Clip {323 Some(keep) => Clip {
324+ fade_in: 0,
325+ fade_out: 0,
320 out_frame: clip.in_frame + keep,326 out_frame: clip.in_frame + keep,
321 ..clip327 ..clip
322 },328 },
crates/engine/examples/bench.rsmodified+2 -0
@@ -860,6 +860,8 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) {
860 .min(meta.frame_count.max(1));860 .min(meta.frame_count.max(1));
861 let in_frame = (meta.frame_count / 10).min(meta.frame_count.saturating_sub(span));861 let in_frame = (meta.frame_count / 10).min(meta.frame_count.saturating_sub(span));
862 let clip = Clip {862 let clip = Clip {
863+ fade_in: 0,
864+ fade_out: 0,
863 start: 0,865 start: 0,
864 in_frame,866 in_frame,
865 out_frame: in_frame + span,867 out_frame: in_frame + span,
crates/engine/src/audio.rsmodified+109 -4
@@ -392,6 +392,22 @@ impl AudioSession {
392 eqs: &[Option<EqParams>],392 eqs: &[Option<EqParams>],
393 speeds: &[Option<crate::project::Stretch>],393 speeds: &[Option<crate::project::Stretch>],
394 sample_rate: Option<u32>,394 sample_rate: Option<u32>,
395+ ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
396+ Self::open_multi_streams_speed_at_fade(sources, segs, eqs, speeds, &[], sample_rate)
397+ }
398+
399+ /// [`open_multi_streams_speed_at`](Self::open_multi_streams_speed_at) with a
400+ /// fade envelope per segment: `fades[i]` is what segment `i` plays through
401+ /// ([`emit`]'s last effect, after the rate and the equalizer), built the
402+ /// same way `eqs` and `speeds` are -- one entry per `segs`, a short list
403+ /// meaning flat from there on.
404+ pub fn open_multi_streams_speed_at_fade(
405+ sources: &[(PathBuf, usize)],
406+ segs: &[(Option<usize>, f64, f64)],
407+ eqs: &[Option<EqParams>],
408+ speeds: &[Option<crate::project::Stretch>],
409+ fades: &[Option<crate::project::Fade>],
410+ sample_rate: Option<u32>,
395 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {411 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
396 // The first source that could have a track, which is not always index 0:412 // The first source that could have a track, which is not always index 0:
397 // a still image has none, and one at the front of the list (a save413 // a still image has none, and one at the front of the list (a save
@@ -571,6 +587,17 @@ impl AudioSession {
571 })587 })
572 .collect();588 .collect();
573 589
590+ // One [`crate::project::Fade`] per segment, exactly the eq and speed
591+ // lists' rule: a short `fades` (the empty one every plain caller
592+ // passes) means the rest play flat, and it is cloned rather than
593+ // built here because [`Project::audio_fades_from`] already resolved
594+ // each clip's own frame count against where this segment lands.
595+ let fades: Vec<Option<crate::project::Fade>> = segments
596+ .iter()
597+ .enumerate()
598+ .map(|(i, _)| fades.get(i).copied().flatten())
599+ .collect();
600+
574 let (tx, rx) = sync_channel(32);601 let (tx, rx) = sync_channel(32);
575 thread::Builder::new()602 thread::Builder::new()
576 .name("audio-decode".into())603 .name("audio-decode".into())
@@ -581,6 +608,7 @@ impl AudioSession {
581 segments,608 segments,
582 eqs,609 eqs,
583 speeds,610 speeds,
611+ fades,
584 timeline,612 timeline,
585 tx,613 tx,
586 })614 })
@@ -690,7 +718,27 @@ impl AudioSession {
690 limiter: Limiter,718 limiter: Limiter,
691 sample_rate: Option<u32>,719 sample_rate: Option<u32>,
692 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {720 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
693- Self::open_mixed_streams_live(sources, lanes, eqs, speeds, gains, limiter, None, sample_rate)721+ Self::open_mixed_streams_master_at_fade(
722+ sources, lanes, eqs, speeds, &[], gains, limiter, sample_rate,
723+ )
724+ }
725+
726+ /// [`open_mixed_streams_master_at`](Self::open_mixed_streams_master_at)
727+ /// with a fade envelope per segment; see
728+ /// [`open_mixed_streams_live_fade`](Self::open_mixed_streams_live_fade).
729+ pub fn open_mixed_streams_master_at_fade(
730+ sources: &[(PathBuf, usize)],
731+ lanes: &[Vec<(Option<usize>, f64, f64)>],
732+ eqs: &[Vec<Option<EqParams>>],
733+ speeds: &[Vec<Option<crate::project::Stretch>>],
734+ fades: &[Vec<Option<crate::project::Fade>>],
735+ gains: &[f32],
736+ limiter: Limiter,
737+ sample_rate: Option<u32>,
738+ ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
739+ Self::open_mixed_streams_live_fade(
740+ sources, lanes, eqs, speeds, fades, gains, limiter, None, sample_rate,
741+ )
694 }742 }
695 743
696 /// [`open_mixed_streams_master`](Self::open_mixed_streams_master) with the744 /// [`open_mixed_streams_master`](Self::open_mixed_streams_master) with the
@@ -710,6 +758,27 @@ impl AudioSession {
710 limiter: Limiter,758 limiter: Limiter,
711 live: Option<&Arc<MixControls>>,759 live: Option<&Arc<MixControls>>,
712 sample_rate: Option<u32>,760 sample_rate: Option<u32>,
761+ ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
762+ Self::open_mixed_streams_live_fade(
763+ sources, lanes, eqs, speeds, &[], gains, limiter, live, sample_rate,
764+ )
765+ }
766+
767+ /// [`open_mixed_streams_live`](Self::open_mixed_streams_live) with a fade
768+ /// envelope per segment as well: `fades[i]` is what segment `i` plays
769+ /// through -- [`crate::Project::audio_fades_from`] is what builds it, off
770+ /// the same walk the segments come from. A short or missing list means
771+ /// the rest play flat, the eq list's rule.
772+ pub fn open_mixed_streams_live_fade(
773+ sources: &[(PathBuf, usize)],
774+ lanes: &[Vec<(Option<usize>, f64, f64)>],
775+ eqs: &[Vec<Option<EqParams>>],
776+ speeds: &[Vec<Option<crate::project::Stretch>>],
777+ fades: &[Vec<Option<crate::project::Fade>>],
778+ gains: &[f32],
779+ limiter: Limiter,
780+ live: Option<&Arc<MixControls>>,
781+ sample_rate: Option<u32>,
713 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {782 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
714 let [first, ..] = lanes else {783 let [first, ..] = lanes else {
715 return Ok(None);784 return Ok(None);
@@ -717,11 +786,13 @@ impl AudioSession {
717 if !Self::is_mixed(lanes.len(), gains, limiter) {786 if !Self::is_mixed(lanes.len(), gains, limiter) {
718 let flat = Vec::new();787 let flat = Vec::new();
719 let plain = Vec::new();788 let plain = Vec::new();
720- return Self::open_multi_streams_speed_at(789+ let flat_fade = Vec::new();
790+ return Self::open_multi_streams_speed_at_fade(
721 sources,791 sources,
722 first,792 first,
723 eqs.first().unwrap_or(&flat),793 eqs.first().unwrap_or(&flat),
724 speeds.first().unwrap_or(&plain),794 speeds.first().unwrap_or(&plain),
795+ fades.first().unwrap_or(&flat_fade),
725 sample_rate,796 sample_rate,
726 );797 );
727 }798 }
@@ -732,12 +803,14 @@ impl AudioSession {
732 // agree by construction; `None` from any of them is a silent803 // agree by construction; `None` from any of them is a silent
733 // timeline.804 // timeline.
734 let flat = Vec::new();805 let flat = Vec::new();
806+ let flat_fade = Vec::new();
735 let plain = Vec::new();807 let plain = Vec::new();
736- let Some((lane_meta, rx)) = Self::open_multi_streams_speed_at(808+ let Some((lane_meta, rx)) = Self::open_multi_streams_speed_at_fade(
737 sources,809 sources,
738 segs,810 segs,
739 eqs.get(i).unwrap_or(&flat),811 eqs.get(i).unwrap_or(&flat),
740 speeds.get(i).unwrap_or(&plain),812 speeds.get(i).unwrap_or(&plain),
813+ fades.get(i).unwrap_or(&flat_fade),
741 sample_rate,814 sample_rate,
742 )?815 )?
743 else {816 else {
@@ -2820,6 +2893,10 @@ struct Worker {
2820 /// every segment of a project nobody has speeded or rate-mismatched, and2893 /// every segment of a project nobody has speeded or rate-mismatched, and
2821 /// the path that emits the decoder's own samples untouched.2894 /// the path that emits the decoder's own samples untouched.
2822 speeds: Vec<Option<Rate>>,2895 speeds: Vec<Option<Rate>>,
2896+ /// One per entry of `segments` again: that segment's gain envelope, or
2897+ /// `None` for one that plays flat -- [`emit`]'s last effect, run after
2898+ /// the rate and the equalizer.
2899+ fades: Vec<Option<crate::project::Fade>>,
2823 /// `start_sample` of the first chunk.2900 /// `start_sample` of the first chunk.
2824 timeline: u64,2901 timeline: u64,
2825 tx: SyncSender<AudioChunk>,2902 tx: SyncSender<AudioChunk>,
@@ -2953,8 +3030,16 @@ fn run(mut w: Worker) {
2953 let mut speeds = std::mem::take(&mut w.speeds);3030 let mut speeds = std::mem::take(&mut w.speeds);
2954 // ...and a short rate list is "real time from here on", for the same reason.3031 // ...and a short rate list is "real time from here on", for the same reason.
2955 speeds.resize_with(segments.len(), || None);3032 speeds.resize_with(segments.len(), || None);
3033+ let mut fades = std::mem::take(&mut w.fades);
3034+ // ...and a short fade list is "flat from here on", the same rule again.
3035+ fades.resize_with(segments.len(), || None);
2956 3036
2957- for ((seg, eq), speed) in segments.iter().zip(eqs.iter_mut()).zip(speeds.iter_mut()) {3037+ for (((seg, eq), speed), fade) in segments
3038+ .iter()
3039+ .zip(eqs.iter_mut())
3040+ .zip(speeds.iter_mut())
3041+ .zip(fades.iter_mut())
3042+ {
2958 let Some(source) = seg.source else {3043 let Some(source) = seg.source else {
2959 // A gap: hand the device real silence rather than nothing at all,3044 // A gap: hand the device real silence rather than nothing at all,
2960 // in the same packet-sized chunks decoding produces, so `fed` and3045 // in the same packet-sized chunks decoding produces, so `fed` and
@@ -2984,6 +3069,7 @@ fn run(mut w: Worker) {
2984 seg,3069 seg,
2985 eq.as_mut(),3070 eq.as_mut(),
2986 speed,3071 speed,
3072+ fade,
2987 channels,3073 channels,
2988 &mut timeline,3074 &mut timeline,
2989 &w.tx,3075 &w.tx,
@@ -2999,6 +3085,7 @@ fn run(mut w: Worker) {
2999 seg,3085 seg,
3000 eq.as_mut(),3086 eq.as_mut(),
3001 speed,3087 speed,
3088+ fade,
3002 channels,3089 channels,
3003 &mut timeline,3090 &mut timeline,
3004 &w.tx,3091 &w.tx,
@@ -3014,6 +3101,7 @@ fn run(mut w: Worker) {
3014 seg,3101 seg,
3015 eq.as_mut(),3102 eq.as_mut(),
3016 speed,3103 speed,
3104+ fade,
3017 channels,3105 channels,
3018 &mut timeline,3106 &mut timeline,
3019 &w.tx,3107 &w.tx,
@@ -3063,6 +3151,7 @@ fn run(mut w: Worker) {
3063 seg,3151 seg,
3064 eq.as_mut(),3152 eq.as_mut(),
3065 speed.as_mut(),3153 speed.as_mut(),
3154+ fade.as_mut(),
3066 pos,3155 pos,
3067 next,3156 next,
3068 &mut timeline,3157 &mut timeline,
@@ -3115,6 +3204,7 @@ fn emit(
3115 seg: &Segment,3204 seg: &Segment,
3116 eq: Option<&mut EqState>,3205 eq: Option<&mut EqState>,
3117 speed: Option<&mut Rate>,3206 speed: Option<&mut Rate>,
3207+ fade: Option<&mut crate::project::Fade>,
3118 pos: u64,3208 pos: u64,
3119 next: u64,3209 next: u64,
3120 timeline: &mut u64,3210 timeline: &mut u64,
@@ -3147,6 +3237,15 @@ fn emit(
3147 if let Some(eq) = eq {3237 if let Some(eq) = eq {
3148 eq.process(interleaved);3238 eq.process(interleaved);
3149 }3239 }
3240+ // The fade last, on the same output-rate samples the mix will hear: its
3241+ // frame counts are timeline frames ([`crate::project::Clip::fade_in`]),
3242+ // which is what a resample has already turned these into. The state
3243+ // walks forward with the segment across as many buffers as decoding
3244+ // takes, exactly as the equalizer's does.
3245+ if let Some(fade) = fade {
3246+ fade.apply(interleaved, channels);
3247+ fade.elapsed = fade.elapsed.saturating_add((interleaved.len() / channels) as u32);
3248+ }
3150 let chunk = AudioChunk {3249 let chunk = AudioChunk {
3151 start_sample: *timeline,3250 start_sample: *timeline,
3152 samples: std::mem::take(interleaved),3251 samples: std::mem::take(interleaved),
@@ -3164,6 +3263,7 @@ fn run_ac3(
3164 seg: &Segment,3263 seg: &Segment,
3165 mut eq: Option<&mut EqState>,3264 mut eq: Option<&mut EqState>,
3166 speed: &mut Option<Rate>,3265 speed: &mut Option<Rate>,
3266+ fade: &mut Option<crate::project::Fade>,
3167 channels: usize,3267 channels: usize,
3168 timeline: &mut u64,3268 timeline: &mut u64,
3169 tx: &SyncSender<AudioChunk>,3269 tx: &SyncSender<AudioChunk>,
@@ -3206,6 +3306,7 @@ fn run_ac3(
3206 seg,3306 seg,
3207 eq.as_deref_mut(),3307 eq.as_deref_mut(),
3208 speed.as_mut(),3308 speed.as_mut(),
3309+ fade.as_mut(),
3209 pos,3310 pos,
3210 next,3311 next,
3211 timeline,3312 timeline,
@@ -3227,6 +3328,7 @@ fn run_mkv_ac3(
3227 seg: &Segment,3328 seg: &Segment,
3228 mut eq: Option<&mut EqState>,3329 mut eq: Option<&mut EqState>,
3229 speed: &mut Option<Rate>,3330 speed: &mut Option<Rate>,
3331+ fade: &mut Option<crate::project::Fade>,
3230 channels: usize,3332 channels: usize,
3231 timeline: &mut u64,3333 timeline: &mut u64,
3232 tx: &SyncSender<AudioChunk>,3334 tx: &SyncSender<AudioChunk>,
@@ -3268,6 +3370,7 @@ fn run_mkv_ac3(
3268 seg,3370 seg,
3269 eq.as_deref_mut(),3371 eq.as_deref_mut(),
3270 speed.as_mut(),3372 speed.as_mut(),
3373+ fade.as_mut(),
3271 pos,3374 pos,
3272 next,3375 next,
3273 timeline,3376 timeline,
@@ -3294,6 +3397,7 @@ fn run_sym(
3294 seg: &Segment,3397 seg: &Segment,
3295 mut eq: Option<&mut EqState>,3398 mut eq: Option<&mut EqState>,
3296 speed: &mut Option<Rate>,3399 speed: &mut Option<Rate>,
3400+ fade: &mut Option<crate::project::Fade>,
3297 channels: usize,3401 channels: usize,
3298 timeline: &mut u64,3402 timeline: &mut u64,
3299 tx: &SyncSender<AudioChunk>,3403 tx: &SyncSender<AudioChunk>,
@@ -3342,6 +3446,7 @@ fn run_sym(
3342 seg,3446 seg,
3343 eq.as_deref_mut(),3447 eq.as_deref_mut(),
3344 speed.as_mut(),3448 speed.as_mut(),
3449+ fade.as_mut(),
3345 pos,3450 pos,
3346 next,3451 next,
3347 timeline,3452 timeline,
crates/engine/src/edith.rsmodified+147 -56
@@ -16,9 +16,9 @@
16 //! subtitle 3 test_av.mp416 //! subtitle 3 test_av.mp4
17 //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk17 //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk
18 //! color 0.1:1.2:0.9:-0.318 //! color 0.1:1.2:0.9:-0.3
19-//! video 1 0 0 120 0 0 0 0 fit 100019+//! video 1 0 0 120 0 0 0 0 fit 1000 0 0
20-//! audio 1 0 0 120 0 0 0 - fit 100020+//! audio 1 0 0 120 0 0 0 - fit 1000 30 30
21-//! video 2 120 0 120 1 - - - fill 200021+//! video 2 120 0 120 1 - - - fill 2000 0 0
22 //! audio 222 //! audio 2
23 //! sub 1 0 60 0 500000 150000023 //! sub 1 0 60 0 500000 1500000
24 //! sub 224 //! sub 2
@@ -110,15 +110,18 @@
110 //! -- the first colour line is color 0 -- printed and refused by the same rules.110 //! -- the first colour line is color 0 -- printed and refused by the same rules.
111 //!111 //!
112 //! A lane line is `<kind> <lane> <start> <in> <out> <source> <link> <eq>112 //! A lane line is `<kind> <lane> <start> <in> <out> <source> <link> <eq>
113-//! <color> <fit> <speed>`: which lane the clip is on -- its kind and its 1-based number113+//! <color> <fit> <speed> <fade_in> <fade_out>`: which lane the clip is on -- its kind and its 1-based number
114 //! among the lanes of that kind, the [`crate::project::Lane::label`] a header114 //! among the lanes of that kind, the [`crate::project::Lane::label`] a header
115 //! column shows -- then where the clip sits on the timeline, the half-open115 //! column shows -- then where the clip sits on the timeline, the half-open
116 //! source range it plays, the file it plays from, its group id, the eq line it116 //! source range it plays, the file it plays from, its group id, the eq line it
117 //! plays through, the colour line it is graded by (`-` for none of those three)117 //! plays through, the colour line it is graded by (`-` for none of those three)
118 //! and how it meets a project canvas of another shape, spelled `fit`, `fill`,118 //! and how it meets a project canvas of another shape, spelled `fit`, `fill`,
119-//! `stretch` or `center` ([`crate::scale::FitPolicy`]), and how fast it plays,119+//! `stretch` or `center` ([`crate::scale::FitPolicy`]), how fast it plays,
120 //! in thousandths of real time ([`crate::project::Speed`], `1000` for a clip120 //! in thousandths of real time ([`crate::project::Speed`], `1000` for a clip
121-//! nobody has speeded). Timeline placement is121+//! nobody has speeded), and finally its ramp up from silence and ramp down to
122+//! it, in timeline frames ([`crate::project::Clip::fade_in`],
123+//! [`crate::project::Clip::fade_out`], `0 0` for a clip nobody has faded).
124+//! Timeline placement is
122 //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing125 //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing
123 //! to write for one, and nothing that can disagree about its length. The `<in>`126 //! to write for one, and nothing that can disagree about its length. The `<in>`
124 //! and `<out>` are *source* frames whatever the speed says: how long the clip is127 //! and `<out>` are *source* frames whatever the speed says: how long the clip is
@@ -143,6 +146,8 @@
143 //! track 3 of a two-track palette is refused here, as a clip naming a source146 //! track 3 of a two-track palette is refused here, as a clip naming a source
144 //! that is not there is.147 //! that is not there is.
145 //!148 //!
149+//! **Version 17** was this without the clip's two fade fields: such a project
150+//! holds no clip anyone has faded, which is what a `0 0` pair still means.
146 //! **Version 15** was this without the caption's group field: such a project151 //! **Version 15** was this without the caption's group field: such a project
147 //! holds captions no hand ever grouped, which is every caption there could be.152 //! holds captions no hand ever grouped, which is every caption there could be.
148 //! **Version 14** was that without the `sub` lines: such a project holds no153 //! **Version 14** was that without the `sub` lines: such a project holds no
@@ -180,7 +185,7 @@
180 //! nothing, and an older one plays everything at real time, and an older one185 //! nothing, and an older one plays everything at real time, and an older one
181 //! mixes flat, and an older one shows no subtitles, and an older one is shown186 //! mixes flat, and an older one shows no subtitles, and an older one is shown
182 //! in the reference rendition, and an older one places none of the words it187 //! in the reference rendition, and an older one places none of the words it
183-//! names -- and saving any of them writes v16. An older188+//! names -- and saving any of them writes v18. An older
184 //! reader refuses a newer file by name.189 //! reader refuses a newer file by name.
185 //!190 //!
186 //! Text because an edit list is a few integers and a path, and a path is191 //! Text because an edit list is a few integers and a path, and a path is
@@ -216,7 +221,8 @@ use crate::subtitle::SubtitleTrack;
216 221
217 /// What [`save`] writes. Read support goes back to `edith 1`; see the module222 /// What [`save`] writes. Read support goes back to `edith 1`; see the module
218 /// docs for what those dialects looked like.223 /// docs for what those dialects looked like.
219-const MAGIC: &[u8] = b"edith 17";224+const MAGIC: &[u8] = b"edith 18";
225+const MAGIC_V17: &[u8] = b"edith 17";
220 const MAGIC_V16: &[u8] = b"edith 16";226 const MAGIC_V16: &[u8] = b"edith 16";
221 const MAGIC_V15: &[u8] = b"edith 15";227 const MAGIC_V15: &[u8] = b"edith 15";
222 const MAGIC_V14: &[u8] = b"edith 14";228 const MAGIC_V14: &[u8] = b"edith 14";
@@ -549,13 +555,15 @@ fn emit(
549 let color = c.color.map_or("-".to_string(), |e| e.to_string());555 let color = c.color.map_or("-".to_string(), |e| e.to_string());
550 out.extend_from_slice(556 out.extend_from_slice(
551 format!(557 format!(
552- "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {}\n",558+ "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {}\n",
553 c.start,559 c.start,
554 c.in_frame,560 c.in_frame,
555 c.out_frame,561 c.out_frame,
556 c.source,562 c.source,
557 fit_name(c.fit),563 fit_name(c.fit),
558- c.speed.permille()564+ c.speed.permille(),
565+ c.fade_in,
566+ c.fade_out,
559 )567 )
560 .as_bytes(),568 .as_bytes(),
561 );569 );
@@ -598,8 +606,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
598 // The dialects that wrote a source line without its stream field. Reading606 // The dialects that wrote a source line without its stream field. Reading
599 // one is the whole of what "an old project still opens" means here.607 // one is the whole of what "an old project still opens" means here.
600 let streamless = v1 || first == MAGIC_V2;608 let streamless = v1 || first == MAGIC_V2;
601- // The one that carries an explicit sound rate...609+ // The one that carries a per-clip fade envelope...
602- let v17 = first == MAGIC;610+ let v18 = first == MAGIC;
611+ // ...the one that carries an explicit sound rate...
612+ let v17 = v18 || first == MAGIC_V17;
603 // ...the one whose captions may carry a group id...613 // ...the one whose captions may carry a group id...
604 let v16 = v17 || first == MAGIC_V16;614 let v16 = v17 || first == MAGIC_V16;
605 // ...the one that places the words it names...615 // ...the one that places the words it names...
@@ -963,6 +973,8 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
963 let f = fields(rest, 3, "clip", n)?;973 let f = fields(rest, 3, "clip", n)?;
964 let clip = check(974 let clip = check(
965 Clip {975 Clip {
976+ fade_in: 0,
977+ fade_out: 0,
966 start: queued,978 start: queued,
967 in_frame: number(f[0], n)?,979 in_frame: number(f[0], n)?,
968 out_frame: number(f[1], n)?,980 out_frame: number(f[1], n)?,
@@ -1081,16 +1093,31 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
1081 if numbered && rest.is_empty() {1093 if numbered && rest.is_empty() {
1082 continue;1094 continue;
1083 }1095 }
1084- // v8 grew the speed field, v7 the fit one, v6 the colour one and1096+ // v18 grew the two fade fields, v8 the speed one, v7 the fit
1085- // v5 the eq one; every older dialect ends at the link.1097+ // one, v6 the colour one and v5 the eq one; every older
1086- let want =1098+ // dialect ends at the link.
1087- 5 + usize::from(v5) + usize::from(v6) + usize::from(v7) + usize::from(v8);1099+ let want = 5
1100+ + usize::from(v5)
1101+ + usize::from(v6)
1102+ + usize::from(v7)
1103+ + usize::from(v8)
1104+ + 2 * usize::from(v18);
1088 let f = fields(rest, want, "clip", n)?;1105 let f = fields(rest, want, "clip", n)?;
1106+ let in_frame = number(f[1], n)?;
1107+ let out_frame = number(f[2], n)?;
1108+ let speed = speed_of(f.get(8).copied(), n)?;
1109+ // Clamped to the clip's own timeline length,
1110+ // [`Project::set_fade_in`]'s rule: a crafted or hand-edited
1111+ // file asking for more ramp than the clip has frames gets the
1112+ // clip's whole length rather than a refusal.
1113+ let frames = speed.frames(out_frame.saturating_sub(in_frame));
1089 let clip = check(1114 let clip = check(
1090 Clip {1115 Clip {
1116+ fade_in: number(f.get(9).copied().unwrap_or(b"0"), n)?.min(frames),
1117+ fade_out: number(f.get(10).copied().unwrap_or(b"0"), n)?.min(frames),
1091 start: number(f[0], n)?,1118 start: number(f[0], n)?,
1092- in_frame: number(f[1], n)?,1119+ in_frame,
1093- out_frame: number(f[2], n)?,1120+ out_frame,
1094 source: number(f[3], n)? as usize,1121 source: number(f[3], n)? as usize,
1095 link: match f[4] {1122 link: match f[4] {
1096 b"-" => None,1123 b"-" => None,
@@ -1099,7 +1126,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
1099 eq: table_index(f.get(5).copied(), doc.eq.len(), "eq", n)?,1126 eq: table_index(f.get(5).copied(), doc.eq.len(), "eq", n)?,
1100 color: table_index(f.get(6).copied(), doc.color.len(), "color", n)?,1127 color: table_index(f.get(6).copied(), doc.color.len(), "color", n)?,
1101 fit: fit_policy(f.get(7).copied(), n)?,1128 fit: fit_policy(f.get(7).copied(), n)?,
1102- speed: speed_of(f.get(8).copied(), n)?,1129+ speed,
1103 },1130 },
1104 &doc,1131 &doc,
1105 n,1132 n,
@@ -1509,7 +1536,7 @@ mod tests {
1509 video 1 0 0 30 0 - - - fit 1000\n";1536 video 1 0 0 30 0 - - - fit 1000\n";
1510 let old = parse(v9, &dir).expect("v9 still loads");1537 let old = parse(v9, &dir).expect("v9 still loads");
1511 assert_eq!(old.subtitles, Vec::new());1538 assert_eq!(old.subtitles, Vec::new());
1512- assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 17\n"));1539+ assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 18\n"));
1513 // ...and the line itself is not a v9 line: a dialect may not be mixed.1540 // ...and the line itself is not a v9 line: a dialect may not be mixed.
1514 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)1541 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)
1515 .unwrap_err()1542 .unwrap_err()
@@ -1851,7 +1878,7 @@ mod tests {
1851 assert_eq!(mixed, "line 3: unknown keyword \"samplerate\"");1878 assert_eq!(mixed, "line 3: unknown keyword \"samplerate\"");
1852 // A number out of a sound rate's range is a corrupt line, by name.1879 // A number out of a sound rate's range is a corrupt line, by name.
1853 for line in ["samplerate 0\n", "samplerate 500000\n", "samplerate nope\n"] {1880 for line in ["samplerate 0\n", "samplerate 500000\n", "samplerate nope\n"] {
1854- let file = format!("edith 17\nsource 0 a.mp4\n{line}");1881+ let file = format!("edith 18\nsource 0 a.mp4\n{line}");
1855 assert!(1882 assert!(
1856 parse(file.as_bytes(), &dir).is_err(),1883 parse(file.as_bytes(), &dir).is_err(),
1857 "{line:?} is not a sound rate line"1884 "{line:?} is not a sound rate line"
@@ -1919,6 +1946,8 @@ mod tests {
1919 1946
1920 fn clip(start: u32, in_frame: u32, out_frame: u32, source: usize, link: Option<u32>) -> Clip {1947 fn clip(start: u32, in_frame: u32, out_frame: u32, source: usize, link: Option<u32>) -> Clip {
1921 Clip {1948 Clip {
1949+ fade_in: 0,
1950+ fade_out: 0,
1922 start,1951 start,
1923 in_frame,1952 in_frame,
1924 out_frame,1953 out_frame,
@@ -1977,10 +2006,10 @@ mod tests {
1977 let bytes = flat(&dir, &sources, &lanes, 12);2006 let bytes = flat(&dir, &sources, &lanes, 12);
1978 assert_eq!(2007 assert_eq!(
1979 String::from_utf8_lossy(&bytes),2008 String::from_utf8_lossy(&bytes),
1980- "edith 17\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\2009+ "edith 18\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
1981 source 2 /elsewhere/b.mp4\n\2010 source 2 /elsewhere/b.mp4\n\
1982- video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\2011+ video 1 0 0 30 0 0 - - fit 1000 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0\n\
1983- audio 1 0 0 30 0 0 - - fit 1000\n",2012+ audio 1 0 0 30 0 0 - - fit 1000 0 0\n",
1984 "the file under the project directory is written relative to it, \2013 "the file under the project directory is written relative to it, \
1985 each with the audio stream it plays"2014 each with the audio stream it plays"
1986 );2015 );
@@ -2014,9 +2043,9 @@ mod tests {
2014 let bytes = flat(&dir, &sources, &lanes, 7);2043 let bytes = flat(&dir, &sources, &lanes, 7);
2015 assert_eq!(2044 assert_eq!(
2016 String::from_utf8_lossy(&bytes),2045 String::from_utf8_lossy(&bytes),
2017- "edith 17\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\2046+ "edith 18\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
2018- video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\2047+ video 1 0 0 30 0 4 - - fit 1000 0 0\naudio 1\n\
2019- video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n",2048+ video 2 40 0 10 0 - - - fit 1000 0 0\naudio 2 0 0 30 0 4 - - fit 1000 0 0\n",
2020 "an empty lane is a line of its own; everything else is its clips"2049 "an empty lane is a line of its own; everything else is its clips"
2021 );2050 );
2022 let back = parse(&bytes, &dir).expect("parse");2051 let back = parse(&bytes, &dir).expect("parse");
@@ -2100,20 +2129,28 @@ mod tests {
2100 let lanes = two(2129 let lanes = two(
2101 vec![2130 vec![
2102 Clip {2131 Clip {
2132+ fade_in: 0,
2133+ fade_out: 0,
2103 eq: Some(0),2134 eq: Some(0),
2104 ..clip(0, 0, 30, 0, Some(0))2135 ..clip(0, 0, 30, 0, Some(0))
2105 },2136 },
2106 Clip {2137 Clip {
2138+ fade_in: 0,
2139+ fade_out: 0,
2107 eq: Some(1),2140 eq: Some(1),
2108 ..clip(30, 10, 20, 0, None)2141 ..clip(30, 10, 20, 0, None)
2109 },2142 },
2110 ],2143 ],
2111 vec![2144 vec![
2112 Clip {2145 Clip {
2146+ fade_in: 0,
2147+ fade_out: 0,
2113 eq: Some(0),2148 eq: Some(0),
2114 ..clip(0, 0, 30, 0, Some(0))2149 ..clip(0, 0, 30, 0, Some(0))
2115 },2150 },
2116 Clip {2151 Clip {
2152+ fade_in: 0,
2153+ fade_out: 0,
2117 eq: Some(2),2154 eq: Some(2),
2118 ..clip(30, 0, 10, 0, None)2155 ..clip(30, 0, 10, 0, None)
2119 },2156 },
@@ -2122,12 +2159,12 @@ mod tests {
2122 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);2159 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);
2123 assert_eq!(2160 assert_eq!(
2124 String::from_utf8_lossy(&bytes),2161 String::from_utf8_lossy(&bytes),
2125- "edith 17\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2162+ "edith 18\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2126 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\2163 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
2127 eq 16777215.0:-0.1:3.918315e-39:hs\n\2164 eq 16777215.0:-0.1:3.918315e-39:hs\n\
2128 eq\n\2165 eq\n\
2129- video 1 0 0 30 0 0 0 - fit 1000\nvideo 1 30 10 20 0 - 1 - fit 1000\n\2166+ video 1 0 0 30 0 0 0 - fit 1000 0 0\nvideo 1 30 10 20 0 - 1 - fit 1000 0 0\n\
2130- audio 1 0 0 30 0 0 0 - fit 1000\naudio 1 30 0 10 0 - 2 - fit 1000\n",2167+ audio 1 0 0 30 0 0 0 - fit 1000 0 0\naudio 1 30 0 10 0 - 2 - fit 1000 0 0\n",
2131 "the table comes before the clips, and a clip names a line of it"2168 "the table comes before the clips, and a clip names a line of it"
2132 );2169 );
2133 2170
@@ -2196,12 +2233,16 @@ mod tests {
2196 let lanes = two(2233 let lanes = two(
2197 vec![2234 vec![
2198 Clip {2235 Clip {
2236+ fade_in: 0,
2237+ fade_out: 0,
2199 color: Some(0),2238 color: Some(0),
2200 fit: FitPolicy::default(),2239 fit: FitPolicy::default(),
2201 speed: Speed::NORMAL,2240 speed: Speed::NORMAL,
2202 ..clip(0, 0, 30, 0, Some(0))2241 ..clip(0, 0, 30, 0, Some(0))
2203 },2242 },
2204 Clip {2243 Clip {
2244+ fade_in: 0,
2245+ fade_out: 0,
2205 color: Some(1),2246 color: Some(1),
2206 fit: FitPolicy::default(),2247 fit: FitPolicy::default(),
2207 speed: Speed::NORMAL,2248 speed: Speed::NORMAL,
@@ -2210,12 +2251,16 @@ mod tests {
2210 ],2251 ],
2211 vec![2252 vec![
2212 Clip {2253 Clip {
2254+ fade_in: 0,
2255+ fade_out: 0,
2213 color: Some(0),2256 color: Some(0),
2214 fit: FitPolicy::default(),2257 fit: FitPolicy::default(),
2215 speed: Speed::NORMAL,2258 speed: Speed::NORMAL,
2216 ..clip(0, 0, 30, 0, Some(0))2259 ..clip(0, 0, 30, 0, Some(0))
2217 },2260 },
2218 Clip {2261 Clip {
2262+ fade_in: 0,
2263+ fade_out: 0,
2219 color: Some(2),2264 color: Some(2),
2220 fit: FitPolicy::default(),2265 fit: FitPolicy::default(),
2221 speed: Speed::NORMAL,2266 speed: Speed::NORMAL,
@@ -2226,12 +2271,12 @@ mod tests {
2226 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);2271 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);
2227 assert_eq!(2272 assert_eq!(
2228 String::from_utf8_lossy(&bytes),2273 String::from_utf8_lossy(&bytes),
2229- "edith 17\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2274+ "edith 18\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2230 color 0.1:1.2:0.9:-0.3\n\2275 color 0.1:1.2:0.9:-0.3\n\
2231 color -1e-7:16777215.0:3.918315e-39:-0.0\n\2276 color -1e-7:16777215.0:3.918315e-39:-0.0\n\
2232 color 0.0:1.0:1.0:0.0\n\2277 color 0.0:1.0:1.0:0.0\n\
2233- video 1 0 0 30 0 0 - 0 fit 1000\nvideo 1 30 10 20 0 - - 1 fit 1000\n\2278+ video 1 0 0 30 0 0 - 0 fit 1000 0 0\nvideo 1 30 10 20 0 - - 1 fit 1000 0 0\n\
2234- audio 1 0 0 30 0 0 - 0 fit 1000\naudio 1 30 0 10 0 - - 2 fit 1000\n",2279+ audio 1 0 0 30 0 0 - 0 fit 1000 0 0\naudio 1 30 0 10 0 - - 2 fit 1000 0 0\n",
2235 "the table comes before the clips, and a clip names a line of it"2280 "the table comes before the clips, and a clip names a line of it"
2236 );2281 );
2237 2282
@@ -2291,9 +2336,9 @@ mod tests {
2291 (1280, 720),2336 (1280, 720),
2292 old.playhead2337 old.playhead
2293 )),2338 )),
2294- "edith 17\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2339+ "edith 18\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2295 eq 80.0:-3.0:0.707:ls\n\2340 eq 80.0:-3.0:0.707:ls\n\
2296- video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"2341+ video 1 0 0 30 0 0 0 - fit 1000 0 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0\n"
2297 );2342 );
2298 }2343 }
2299 2344
@@ -2306,6 +2351,8 @@ mod tests {
2306 let dir = PathBuf::from("/proj");2351 let dir = PathBuf::from("/proj");
2307 let sources = vec![Source::new("/proj/a.mp4", 0)];2352 let sources = vec![Source::new("/proj/a.mp4", 0)];
2308 let speeded = |start, in_frame, out_frame, permille| Clip {2353 let speeded = |start, in_frame, out_frame, permille| Clip {
2354+ fade_in: 0,
2355+ fade_out: 0,
2309 start,2356 start,
2310 in_frame,2357 in_frame,
2311 out_frame,2358 out_frame,
@@ -2329,9 +2376,9 @@ mod tests {
2329 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);2376 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
2330 assert_eq!(2377 assert_eq!(
2331 String::from_utf8_lossy(&bytes),2378 String::from_utf8_lossy(&bytes),
2332- "edith 17\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2379+ "edith 18\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2333- video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\2380+ video 1 0 0 30 0 - - - fit 2000 0 0\nvideo 1 15 30 40 0 - - - fit 250 0 0\n\
2334- audio 1 0 0 30 0 - - - fit 2000\n",2381+ audio 1 0 0 30 0 - - - fit 2000 0 0\n",
2335 "the rate is the clip line's last field, in thousandths"2382 "the rate is the clip line's last field, in thousandths"
2336 );2383 );
2337 let back = parse(&bytes, &dir).expect("parse");2384 let back = parse(&bytes, &dir).expect("parse");
@@ -2358,8 +2405,8 @@ mod tests {
2358 (1280, 720),2405 (1280, 720),
2359 old.playhead2406 old.playhead
2360 )),2407 )),
2361- "edith 17\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2408+ "edith 18\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2362- video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"2409+ video 1 0 0 30 0 0 - - fit 1000 0 0\naudio 1 0 0 30 0 0 - - fit 1000 0 0\n"
2363 );2410 );
2364 // A rate outside what the editor can set is a corrupt line, by name.2411 // A rate outside what the editor can set is a corrupt line, by name.
2365 let bad = b"edith 8\nsource 0 a.mp4\nvideo 1 0 0 30 0 - - - fit 9000\n";2412 let bad = b"edith 8\nsource 0 a.mp4\nvideo 1 0 0 30 0 - - - fit 9000\n";
@@ -2369,6 +2416,50 @@ mod tests {
2369 );2416 );
2370 }2417 }
2371 2418
2419+ #[test]
2420+ fn a_v17_file_loads_with_zero_fades_and_fades_round_trip_bit_exactly() {
2421+ let dir = PathBuf::from("/proj");
2422+ // The v17 dialect: nine clip fields, the last the speed -- no fade
2423+ // pair after it at all, not even zeroes.
2424+ let v17 = b"edith 17\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2425+ video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n";
2426+ let old = parse(v17, &dir).expect("v17 parses");
2427+ assert!(
2428+ old.lanes
2429+ .iter()
2430+ .flat_map(|(_, clips)| clips)
2431+ .all(|c| c.fade_in == 0 && c.fade_out == 0),
2432+ "nothing before v18 had a fade to name"
2433+ );
2434+
2435+ // ...and the dialect that does: nonzero fades on both edges, written
2436+ // and read back as the very numbers.
2437+ let sources = vec![Source::new("/proj/a.mp4", 0)];
2438+ let faded = Clip {
2439+ fade_in: 5,
2440+ fade_out: 7,
2441+ start: 0,
2442+ in_frame: 0,
2443+ out_frame: 30,
2444+ source: 0,
2445+ link: None,
2446+ eq: None,
2447+ color: None,
2448+ fit: FitPolicy::default(),
2449+ speed: Speed::NORMAL,
2450+ };
2451+ let lanes = vec![(LaneKind::Video, vec![faded])];
2452+ let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
2453+ assert_eq!(
2454+ String::from_utf8_lossy(&bytes),
2455+ "edith 18\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2456+ video 1 0 0 30 0 - - - fit 1000 5 7\n",
2457+ "the fades are the clip line's last two fields"
2458+ );
2459+ let back = parse(&bytes, &dir).expect("parse");
2460+ assert_eq!(back.lanes, lanes, "the fades round trip as the very numbers");
2461+ }
2462+
2372 /// The whole of the v9 bump, the speed test's twin: the mix a project was2463 /// The whole of the v9 bump, the speed test's twin: the mix a project was
2373 /// left at -- every track's own volume and the master limiter -- plus the2464 /// left at -- every track's own volume and the master limiter -- plus the
2374 /// rate it was cut at, all written, all read back as the very numbers, and2465 /// rate it was cut at, all written, all read back as the very numbers, and
@@ -2409,10 +2500,10 @@ mod tests {
2409 );2500 );
2410 assert_eq!(2501 assert_eq!(
2411 String::from_utf8_lossy(&bytes),2502 String::from_utf8_lossy(&bytes),
2412- "edith 17\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\2503+ "edith 18\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\
2413 limiter -1.5 on\nsource 0 a.mp4\n\2504 limiter -1.5 on\nsource 0 a.mp4\n\
2414- video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\2505+ video 1 0 0 30 0 - - - fit 1000 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0\n\
2415- audio 2 0 0 30 0 - - - fit 1000\n\2506+ audio 2 0 0 30 0 - - - fit 1000 0 0\n\
2416 gain audio 1 3.0\ngain audio 2 -6.5\n",2507 gain audio 1 3.0\ngain audio 2 -6.5\n",
2417 "the mix is lines of its own, the gains after the lanes they name"2508 "the mix is lines of its own, the gains after the lanes they name"
2418 );2509 );
@@ -2441,8 +2532,8 @@ mod tests {
2441 (1280, 720),2532 (1280, 720),
2442 old.playhead2533 old.playhead
2443 )),2534 )),
2444- "edith 17\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2535+ "edith 18\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2445- video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"2536+ video 1 0 0 30 0 - - - fit 1000 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0\n"
2446 );2537 );
2447 2538
2448 // Each of the three refuses by name, on its own line.2539 // Each of the three refuses by name, on its own line.
@@ -2605,10 +2696,10 @@ mod tests {
2605 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");2696 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");
2606 assert_eq!(2697 assert_eq!(
2607 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),2698 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),
2608- "edith 17\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\2699+ "edith 18\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2609 source 2 /elsewhere/b.mp4\n\2700 source 2 /elsewhere/b.mp4\n\
2610- video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\2701+ video 1 0 0 30 0 0 - - fit 1000 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0\n\
2611- audio 1 0 0 30 0 0 - - fit 1000\n"2702+ audio 1 0 0 30 0 0 - - fit 1000 0 0\n"
2612 );2703 );
2613 // An empty lane's line is still the whole of that lane, eq or no eq.2704 // An empty lane's line is still the whole of that lane, eq or no eq.
2614 let empty = parse(2705 let empty = parse(
@@ -2658,10 +2749,10 @@ mod tests {
2658 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);2749 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
2659 assert_eq!(2750 assert_eq!(
2660 String::from_utf8_lossy(&v5),2751 String::from_utf8_lossy(&v5),
2661- "edith 17\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\2752+ "edith 18\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2662 source 0 /elsewhere/b.mp4\n\2753 source 0 /elsewhere/b.mp4\n\
2663- video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\2754+ video 1 0 0 30 0 0 - - fit 1000 0 0\nvideo 1 30 10 20 1 1 - - fit 1000 0 0\n\
2664- audio 1 0 0 30 0 0 - - fit 1000\n",2755+ audio 1 0 0 30 0 0 - - fit 1000 0 0\n",
2665 "a re-saved v2 project differs only by its version, the lane \2756 "a re-saved v2 project differs only by its version, the lane \
2666 numbers, the streams it always meant and an equalizer it has none of"2757 numbers, the streams it always meant and an equalizer it has none of"
2667 );2758 );
@@ -2690,7 +2781,7 @@ mod tests {
2690 // Saved again it is the current version, which round-trips to the2781 // Saved again it is the current version, which round-trips to the
2691 // same document.2782 // same document.
2692 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);2783 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
2693- assert!(v5.starts_with(b"edith 17\n"));2784+ assert!(v5.starts_with(b"edith 18\n"));
2694 let again = parse(&v5, &dir).expect("v5 parses");2785 let again = parse(&v5, &dir).expect("v5 parses");
2695 assert_eq!(again.lanes, back.lanes);2786 assert_eq!(again.lanes, back.lanes);
2696 // A dialect may not be mixed: lane lines under v1, `clip` under v2.2787 // A dialect may not be mixed: lane lines under v1, `clip` under v2.
@@ -2800,8 +2891,8 @@ mod tests {
2800 let bytes = std::fs::read(&path).expect("read back");2891 let bytes = std::fs::read(&path).expect("read back");
2801 assert_eq!(2892 assert_eq!(
2802 String::from_utf8_lossy(&bytes),2893 String::from_utf8_lossy(&bytes),
2803- "edith 17\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\2894+ "edith 18\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
2804- video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"2895+ video 1 0 0 30 0 - - - fit 1000 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0\n"
2805 );2896 );
2806 // Loading rejoins the *given* directory, so the file is reached by the2897 // Loading rejoins the *given* directory, so the file is reached by the
2807 // way the project was opened -- the same file, through the link, still2898 // way the project was opened -- the same file, through the link, still
@@ -2845,10 +2936,10 @@ mod tests {
2845 #[test]2936 #[test]
2846 fn a_wrong_first_line_is_refused_by_name() {2937 fn a_wrong_first_line_is_refused_by_name() {
2847 let dir = PathBuf::from("/proj");2938 let dir = PathBuf::from("/proj");
2848- let err = parse(b"edith 18\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)2939+ let err = parse(b"edith 19\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)
2849 .unwrap_err()2940 .unwrap_err()
2850 .to_string();2941 .to_string();
2851- assert_eq!(err, "line 1: unsupported version 18");2942+ assert_eq!(err, "line 1: unsupported version 19");
2852 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {2943 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {
2853 assert_eq!(2944 assert_eq!(
2854 parse(junk, &dir).unwrap_err().to_string(),2945 parse(junk, &dir).unwrap_err().to_string(),
crates/engine/src/export.rsmodified+8 -2
@@ -1717,16 +1717,18 @@ fn encode_audio(
1717 let segs = project.audio_segments_from(offset, meta.frame_rate);1717 let segs = project.audio_segments_from(offset, meta.frame_rate);
1718 let eqs = project.audio_eqs_from(offset, meta.frame_rate);1718 let eqs = project.audio_eqs_from(offset, meta.frame_rate);
1719 let speeds = project.audio_speeds_from(offset, meta.frame_rate);1719 let speeds = project.audio_speeds_from(offset, meta.frame_rate);
1720+ let fades = project.audio_fades_from(offset, meta.frame_rate);
1720 // Coarse stage timers, in the same voice as `export video: copy` below: an1721 // Coarse stage timers, in the same voice as `export video: copy` below: an
1721 // export of a feature film spends minutes in here before a byte of picture1722 // export of a feature film spends minutes in here before a byte of picture
1722 // is written, and which minutes went where is the first question asked of a1723 // is written, and which minutes went where is the first question asked of a
1723 // slow export. Three lines an export, so they stay on.1724 // slow export. Three lines an export, so they stay on.
1724 let mixed = std::time::Instant::now();1725 let mixed = std::time::Instant::now();
1725- let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at(1726+ let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at_fade(
1726 &sources,1727 &sources,
1727 &segs,1728 &segs,
1728 &eqs,1729 &eqs,
1729 &speeds,1730 &speeds,
1731+ &fades,
1730 &project.audio_gains(),1732 &project.audio_gains(),
1731 project.limiter(),1733 project.limiter(),
1732 sample_rate,1734 sample_rate,
@@ -2820,15 +2822,19 @@ fn run_audio(
2820 // 2x is half as long and holds the samples that were heard -- not a2822 // 2x is half as long and holds the samples that were heard -- not a
2821 // second pass here that could disagree with what the ear got.2823 // second pass here that could disagree with what the ear got.
2822 let speeds = project.audio_speeds_from(offset, meta.frame_rate);2824 let speeds = project.audio_speeds_from(offset, meta.frame_rate);
2825+ // ...and the fades with them, the same choke-point reason again: a clip's
2826+ // envelope runs inside the worker playback feeds from too.
2827+ let fades = project.audio_fades_from(offset, meta.frame_rate);
2823 // ...and the mix over both: each lane's volume into the sum, the master2828 // ...and the mix over both: each lane's volume into the sum, the master
2824 // limiter out of it. The same opener playback's feeder reads from, so a2829 // limiter out of it. The same opener playback's feeder reads from, so a
2825 // file is written at the levels it was heard at -- there is no second2830 // file is written at the levels it was heard at -- there is no second
2826 // place here that could mix it differently.2831 // place here that could mix it differently.
2827- let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at(2832+ let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at_fade(
2828 &sources,2833 &sources,
2829 &segs,2834 &segs,
2830 &eqs,2835 &eqs,
2831 &speeds,2836 &speeds,
2837+ &fades,
2832 &project.audio_gains(),2838 &project.audio_gains(),
2833 project.limiter(),2839 project.limiter(),
2834 sample_rate,2840 sample_rate,
crates/engine/src/playback.rsmodified+12 -1
@@ -618,6 +618,8 @@ impl PlaybackSession {
618 // *video* open's pair of grouped clips: here there is no picture to618 // *video* open's pair of grouped clips: here there is no picture to
619 // group the sound with, so the video lane starts empty.619 // group the sound with, so the video lane starts empty.
620 let clip = Clip {620 let clip = Clip {
621+ fade_in: 0,
622+ fade_out: 0,
621 start: 0,623 start: 0,
622 in_frame: 0,624 in_frame: 0,
623 out_frame: meta.frame_count,625 out_frame: meta.frame_count,
@@ -701,6 +703,8 @@ impl PlaybackSession {
701 color: ColorDescription::default(),703 color: ColorDescription::default(),
702 };704 };
703 let clip = Clip {705 let clip = Clip {
706+ fade_in: 0,
707+ fade_out: 0,
704 start: 0,708 start: 0,
705 in_frame: 0,709 in_frame: 0,
706 out_frame: place_frames(meta.frame_count, IMAGE_ONLY_RATE),710 out_frame: place_frames(meta.frame_count, IMAGE_ONLY_RATE),
@@ -2625,6 +2629,8 @@ impl PlaybackSession {
2625 let source = self.project.import(path, stream);2629 let source = self.project.import(path, stream);
2626 self.note_frames(source, frames, rate);2630 self.note_frames(source, frames, rate);
2627 let clip = Clip {2631 let clip = Clip {
2632+ fade_in: 0,
2633+ fade_out: 0,
2628 start: 0,2634 start: 0,
2629 in_frame: 0,2635 in_frame: 0,
2630 out_frame: match image {2636 out_frame: match image {
@@ -3254,6 +3260,10 @@ impl PlaybackSession {
3254 // speeded, which is the path that decodes the same samples it always3260 // speeded, which is the path that decodes the same samples it always
3255 // did.3261 // did.
3256 let speeds = self.project.audio_speeds_from(target, fps);3262 let speeds = self.project.audio_speeds_from(target, fps);
3263+ // ...and the fades, the same way again: a clip's own envelope runs
3264+ // inside its worker, after the rate and the equalizer, so a fade
3265+ // edit is audible at once exactly as an EQ edit is.
3266+ let fades = self.project.audio_fades_from(target, fps);
3257 // Each source on the stream it was placed with: what plays is what3267 // Each source on the stream it was placed with: what plays is what
3258 // the library row said, and what an export copies (`export::run`).3268 // the library row said, and what an export copies (`export::run`).
3259 let sources = self.project.audio_sources();3269 let sources = self.project.audio_sources();
@@ -3283,11 +3293,12 @@ impl PlaybackSession {
3283 // one `pread` on a cold 25 GB film is seconds, and this is called3293 // one `pread` on a cold 25 GB film is seconds, and this is called
3284 // from a ruler drag ([`Audio::spawn_feeder_deferred`]).3294 // from a ruler drag ([`Audio::spawn_feeder_deferred`]).
3285 audio_running = audio.spawn_feeder_deferred(move || {3295 audio_running = audio.spawn_feeder_deferred(move || {
3286- match AudioSession::open_mixed_streams_live(3296+ match AudioSession::open_mixed_streams_live_fade(
3287 &sources,3297 &sources,
3288 &segs,3298 &segs,
3289 &eqs,3299 &eqs,
3290 &speeds,3300 &speeds,
3301+ &fades,
3291 &gains,3302 &gains,
3292 limiter,3303 limiter,
3293 Some(&worker_controls),3304 Some(&worker_controls),
crates/engine/src/project.rsmodified+299 -6
@@ -430,6 +430,15 @@ pub struct Clip {
430 /// changes is how many *timeline* frames that range is spread over430 /// changes is how many *timeline* frames that range is spread over
431 /// ([`Clip::frames`]).431 /// ([`Clip::frames`]).
432 pub speed: Speed,432 pub speed: Speed,
433+ /// Timeline frames of ramp-up from silence at the clip's own start, inline
434+ /// like [`Clip::fit`] and [`Clip::speed`] for the same reason: one small
435+ /// number with nothing to share, and every consumer (mixer, exporter) wants
436+ /// it sitting right next to the frame range it shapes. Clamped to the
437+ /// clip's own length by the setter -- never wider than the clip is long.
438+ pub fade_in: u32,
439+ /// Timeline frames of ramp-down to silence at the clip's own end. Same
440+ /// promises as [`Clip::fade_in`].
441+ pub fade_out: u32,
433 }442 }
434 443
435 impl Clip {444 impl Clip {
@@ -748,6 +757,62 @@ pub struct Stretch {
748 pub timeline_secs: f64,757 pub timeline_secs: f64,
749 }758 }
750 759
760+/// What one audio segment's gain envelope is: [`Project::audio_fades_from`]
761+/// builds it off the clip's own [`Clip::fade_in`]/[`Clip::fade_out`], resolved
762+/// against where in the *clip* -- not the segment, which may start mid-clip
763+/// on a seek -- this segment's first frame lands.
764+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
765+pub struct Fade {
766+ /// How many of the clip's own frames already played before this
767+ /// segment's first frame: `0` unless playback started mid-clip.
768+ pub elapsed: u32,
769+ /// The clip's [`Clip::fade_in`].
770+ pub fade_in: u32,
771+ /// The clip's [`Clip::fade_out`].
772+ pub fade_out: u32,
773+ /// The clip's own [`Clip::frames`] -- the envelope's whole width, of
774+ /// which this segment may only cover the tail.
775+ pub total: u32,
776+}
777+
778+impl Fade {
779+ /// The gain at clip-relative frame `pos`, an equal-power curve on each
780+ /// edge that plays through unchanged (gain `1.0`) wherever neither ramp
781+ /// reaches: `sin(t * pi/2)` for `t` the fraction of the way through the
782+ /// ramp, so a fade lands on silence at its very first (or very last)
783+ /// frame and reaches unity smoothly rather than at a constant slope --
784+ /// the same curve [`Project::crossfade`] relies on to keep two clips'
785+ /// sum around one level through the join. Both ramps multiply where a
786+ /// clip is short enough for them to overlap.
787+ fn gain_at(self, pos: u32) -> f32 {
788+ let mut g = 1.0f32;
789+ if self.fade_in > 0 && pos < self.fade_in {
790+ let t = pos as f32 / self.fade_in as f32;
791+ g *= (t * std::f32::consts::FRAC_PI_2).sin();
792+ }
793+ if self.fade_out > 0 {
794+ let out_start = self.total.saturating_sub(self.fade_out);
795+ if pos >= out_start {
796+ let remaining = self.total.saturating_sub(pos);
797+ let t = remaining as f32 / self.fade_out as f32;
798+ g *= (t.clamp(0.0, 1.0) * std::f32::consts::FRAC_PI_2).sin();
799+ }
800+ }
801+ g
802+ }
803+
804+ /// Multiplies `frames` in place -- `channels`-wide interleaved samples,
805+ /// starting at this segment's own frame `0` -- by [`Self::gain_at`].
806+ pub fn apply(self, frames: &mut [f32], channels: usize) {
807+ for (i, block) in frames.chunks_mut(channels).enumerate() {
808+ let g = self.gain_at(self.elapsed.saturating_add(i as u32));
809+ for s in block {
810+ *s *= g;
811+ }
812+ }
813+ }
814+}
815+
751 /// What a save writes and a load takes back: the sources, every lane in816 /// What a save writes and a load takes back: the sources, every lane in
752 /// display order with its kind, and the equalizer and colour tables their clips817 /// display order with its kind, and the equalizer and colour tables their clips
753 /// index into -- [`Project::without_orphan_sources`] out,818 /// index into -- [`Project::without_orphan_sources`] out,
@@ -814,6 +879,8 @@ impl Project {
814 /// is clamped to one frame.879 /// is clamped to one frame.
815 pub fn single(path: impl AsRef<Path>, frame_count: u32) -> Self {880 pub fn single(path: impl AsRef<Path>, frame_count: u32) -> Self {
816 let clip = Clip {881 let clip = Clip {
882+ fade_in: 0,
883+ fade_out: 0,
817 start: 0,884 start: 0,
818 in_frame: 0,885 in_frame: 0,
819 out_frame: frame_count.max(1),886 out_frame: frame_count.max(1),
@@ -1194,6 +1261,8 @@ impl Project {
1194 self.snapshot();1261 self.snapshot();
1195 let start = self.timeline_frames();1262 let start = self.timeline_frames();
1196 let clip = Clip {1263 let clip = Clip {
1264+ fade_in: 0,
1265+ fade_out: 0,
1197 start,1266 start,
1198 in_frame: 0,1267 in_frame: 0,
1199 out_frame: frame_count.max(1),1268 out_frame: frame_count.max(1),
@@ -2402,6 +2471,76 @@ impl Project {
2402 true2471 true
2403 }2472 }
2404 2473
2474+ /// Timeline frames of ramp-up from silence at the start of the clip at
2475+ /// `idx` of `lane`. `0` for an index that is not there, same as a clip
2476+ /// that has none.
2477+ pub fn fade_in_of(&self, lane: Lane, idx: usize) -> u32 {
2478+ self.lane(lane).get(idx).map_or(0, |c| c.fade_in)
2479+ }
2480+
2481+ /// Sets it, clamped to the clip's own length ([`Clip::frames`]) -- a fade
2482+ /// can shrink a clip's audible middle to nothing but never ask for more
2483+ /// ramp than the clip has frames. One undo step like [`Project::set_fit`],
2484+ /// and `false` (no history) for an index that is not there.
2485+ pub fn set_fade_in(&mut self, lane: Lane, idx: usize, frames: u32) -> bool {
2486+ if idx >= self.lane(lane).len() {
2487+ return false;
2488+ }
2489+ self.snapshot();
2490+ let clip = &mut self.lane_mut(lane).expect("checked above")[idx];
2491+ clip.fade_in = frames.min(clip.frames());
2492+ true
2493+ }
2494+
2495+ /// Timeline frames of ramp-down to silence at the end of the clip at
2496+ /// `idx` of `lane`. Same promise as [`Project::fade_in_of`].
2497+ pub fn fade_out_of(&self, lane: Lane, idx: usize) -> u32 {
2498+ self.lane(lane).get(idx).map_or(0, |c| c.fade_out)
2499+ }
2500+
2501+ /// Sets it. Same promises as [`Project::set_fade_in`].
2502+ pub fn set_fade_out(&mut self, lane: Lane, idx: usize, frames: u32) -> bool {
2503+ if idx >= self.lane(lane).len() {
2504+ return false;
2505+ }
2506+ self.snapshot();
2507+ let clip = &mut self.lane_mut(lane).expect("checked above")[idx];
2508+ clip.fade_out = frames.min(clip.frames());
2509+ true
2510+ }
2511+
2512+ /// Crossfades the audio clip at `idx` of `lane` into the one immediately
2513+ /// after it, over `frames` timeline frames: sets `idx`'s
2514+ /// [`Clip::fade_out`] and its neighbour's [`Clip::fade_in`] to `frames`,
2515+ /// each clamped to its own clip's length. `false` -- no history -- unless
2516+ /// `lane` is audio, `idx + 1` is in bounds, and the two clips are
2517+ /// adjacent: the second's [`Clip::start`] is exactly the first's
2518+ /// [`Clip::end`], no gap between them.
2519+ ///
2520+ /// This is the whole mechanism, not a stand-in for one: a *real*
2521+ /// cross-fade -- both takes heard at once, blending -- is what two clips
2522+ /// **overlapping** on separate lanes already get for free from the
2523+ /// mixer's own per-lane sum ([`crate::audio::open_mixed_streams_master`]).
2524+ /// This call only shapes the edges of two clips already sitting
2525+ /// end-to-end on *one* lane, so the join between them fades like one did.
2526+ pub fn crossfade(&mut self, lane: Lane, idx: usize, frames: u32) -> bool {
2527+ if lane.kind != LaneKind::Audio {
2528+ return false;
2529+ }
2530+ let clips = self.lane(lane);
2531+ let (Some(a), Some(b)) = (clips.get(idx), clips.get(idx + 1)) else {
2532+ return false;
2533+ };
2534+ if a.end() != b.start {
2535+ return false;
2536+ }
2537+ self.snapshot();
2538+ let clips = self.lane_mut(lane).expect("checked above");
2539+ clips[idx].fade_out = frames.min(clips[idx].frames());
2540+ clips[idx + 1].fade_in = frames.min(clips[idx + 1].frames());
2541+ true
2542+ }
2543+
2405 /// Every frame number on every lane rewritten onto a timeline counted at2544 /// Every frame number on every lane rewritten onto a timeline counted at
2406 /// another rate: `k` is old timeline frames per new one, `counts` is how2545 /// another rate: `k` is old timeline frames per new one, `counts` is how
2407 /// long each source is on the *new* timeline (indexed as2546 /// long each source is on the *new* timeline (indexed as
@@ -2810,8 +2949,18 @@ impl Project {
2810 tail.in_frame = split_source(&tail, timeline_frame).expect("splittable said so");2949 tail.in_frame = split_source(&tail, timeline_frame).expect("splittable said so");
2811 tail.start = timeline_frame;2950 tail.start = timeline_frame;
2812 tail.link = right_of(orig[data_i]);2951 tail.link = right_of(orig[data_i]);
2952+ // A split makes a new edge for each half, and a fade is a promise
2953+ // about an edge: only the half that *kept* the original edge
2954+ // keeps that fade, re-clamped to its own now-shorter length (a
2955+ // cut inside the ramp shortens it, never leaves it pointing past
2956+ // the clip it is on); the edge the cut itself made starts, or
2957+ // ends, flat -- there was no silence there to ramp out of.
2958+ tail.fade_in = 0;
2959+ tail.fade_out = tail.fade_out.min(tail.frames());
2813 data.clips[idx].out_frame = tail.in_frame;2960 data.clips[idx].out_frame = tail.in_frame;
2814 data.clips[idx].link = orig[data_i];2961 data.clips[idx].link = orig[data_i];
2962+ data.clips[idx].fade_out = 0;
2963+ data.clips[idx].fade_in = data.clips[idx].fade_in.min(data.clips[idx].frames());
2815 data.clips.insert(idx + 1, tail);2964 data.clips.insert(idx + 1, tail);
2816 }2965 }
2817 true2966 true
@@ -3143,6 +3292,8 @@ impl Project {
3143 }3292 }
3144 self.snapshot();3293 self.snapshot();
3145 let clip = Clip {3294 let clip = Clip {
3295+ fade_in: 0,
3296+ fade_out: 0,
3146 start: timeline_frame,3297 start: timeline_frame,
3147 link: None,3298 link: None,
3148 ..clip3299 ..clip
@@ -3182,6 +3333,8 @@ impl Project {
3182 self.lanes.push(LaneData::new(LaneKind::Audio, Vec::new()));3333 self.lanes.push(LaneData::new(LaneKind::Audio, Vec::new()));
3183 }3334 }
3184 let clip = Clip {3335 let clip = Clip {
3336+ fade_in: 0,
3337+ fade_out: 0,
3185 start: timeline_frame,3338 start: timeline_frame,
3186 link: Some(self.new_link()),3339 link: Some(self.new_link()),
3187 ..clip3340 ..clip
@@ -3757,6 +3910,8 @@ impl Project {
3757 }3910 }
3758 self.snapshot();3911 self.snapshot();
3759 let clip = Clip {3912 let clip = Clip {
3913+ fade_in: 0,
3914+ fade_out: 0,
3760 start: at,3915 start: at,
3761 link: Some(self.new_link()),3916 link: Some(self.new_link()),
3762 ..clip3917 ..clip
@@ -4446,6 +4601,42 @@ impl Project {
4446 .collect()4601 .collect()
4447 }4602 }
4448 4603
4604+ /// The fade envelope each of [`audio_segments_from`](Project::audio_segments_from)'s
4605+ /// segments plays through: the same lanes in the same order, one entry per
4606+ /// segment, `None` where the segment is a gap or its clip has neither a
4607+ /// [`Clip::fade_in`] nor a [`Clip::fade_out`]. Parallel list for
4608+ /// [`audio_eqs_from`](Project::audio_eqs_from)'s reason.
4609+ pub fn audio_fades_from(&self, timeline_frame: u32, fps: f64) -> Vec<Vec<Option<Fade>>> {
4610+ self.audio_lanes()
4611+ .into_iter()
4612+ .map(|lane| self.lane_fades_from(lane, timeline_frame, fps))
4613+ .collect()
4614+ }
4615+
4616+ /// [`audio_fades_from`](Project::audio_fades_from) for one lane, matching
4617+ /// [`lane_segments_from`](Project::lane_segments_from) entry for entry.
4618+ pub fn lane_fades_from(&self, lane: Lane, timeline_frame: u32, fps: f64) -> Vec<Option<Fade>> {
4619+ if !(fps.is_finite() && fps > 0.0) {
4620+ return Vec::new();
4621+ }
4622+ self.spans_from(lane, timeline_frame)
4623+ .iter()
4624+ .map(|span| {
4625+ let (idx, _) = self.map(lane, span.start)?;
4626+ let clip = self.lane(lane).get(idx)?;
4627+ (clip.fade_in > 0 || clip.fade_out > 0).then(|| Fade {
4628+ // `span.len` is the clip's own remaining frames from
4629+ // `span.start` on -- shorter than `clip.frames()` only
4630+ // when this is the first span of a seek mid-clip.
4631+ elapsed: clip.frames().saturating_sub(span.len),
4632+ fade_in: clip.fade_in,
4633+ fade_out: clip.fade_out,
4634+ total: clip.frames(),
4635+ })
4636+ })
4637+ .collect()
4638+ }
4639+
4449 /// Pushes the undo snapshot. Every mutating method calls this once, *after*4640 /// Pushes the undo snapshot. Every mutating method calls this once, *after*
4450 /// it has decided it will succeed -- a refusal must not cost an undo step.4641 /// it has decided it will succeed -- a refusal must not cost an undo step.
4451 /// Clears the redo stack: a fresh edit branches off from here, so whatever4642 /// Clears the redo stack: a fresh edit branches off from here, so whatever
@@ -4794,6 +4985,8 @@ fn clear(clips: &mut Vec<Clip>, start: u32, end: u32) {
4794 && c.start < start4985 && c.start < start
4795 {4986 {
4796 out.push(Clip {4987 out.push(Clip {
4988+ fade_in: 0,
4989+ fade_out: 0,
4797 out_frame: c.in_frame + keep.min(c.len()),4990 out_frame: c.in_frame + keep.min(c.len()),
4798 link: None,4991 link: None,
4799 ..c4992 ..c
@@ -4807,6 +5000,8 @@ fn clear(clips: &mut Vec<Clip>, start: u32, end: u32) {
4807 && c.end() > end5000 && c.end() > end
4808 {5001 {
4809 out.push(Clip {5002 out.push(Clip {
5003+ fade_in: 0,
5004+ fade_out: 0,
4810 start: end,5005 start: end,
4811 in_frame: c.out_frame - keep.min(c.len()),5006 in_frame: c.out_frame - keep.min(c.len()),
4812 link: None,5007 link: None,
@@ -4913,6 +5108,8 @@ mod tests {
4913 /// A contiguous placement, group id ignored: what most assertions compare.5108 /// A contiguous placement, group id ignored: what most assertions compare.
4914 fn clip(start: u32, in_frame: u32, out_frame: u32, source: usize) -> Clip {5109 fn clip(start: u32, in_frame: u32, out_frame: u32, source: usize) -> Clip {
4915 Clip {5110 Clip {
5111+ fade_in: 0,
5112+ fade_out: 0,
4916 start,5113 start,
4917 in_frame,5114 in_frame,
4918 out_frame,5115 out_frame,
@@ -5041,6 +5238,89 @@ mod tests {
5041 );5238 );
5042 }5239 }
5043 5240
5241+ /// [`Fade::gain_at`]'s curve at the edges and in the middle: silence at
5242+ /// the very first frame of a fade-in, unity at its last, equal-power
5243+ /// (`sin(pi/4)`) at its midpoint, and unity anywhere neither ramp reaches
5244+ /// at all.
5245+ #[test]
5246+ fn gain_at_is_silent_at_a_fades_edge_and_unity_in_the_body() {
5247+ let f = Fade {
5248+ elapsed: 0,
5249+ fade_in: 10,
5250+ fade_out: 10,
5251+ total: 40,
5252+ };
5253+ assert_eq!(f.gain_at(0), 0.0, "silence at the very first frame");
5254+ assert_eq!(f.gain_at(10), 1.0, "unity the frame the ramp ends");
5255+ let midpoint = std::f32::consts::FRAC_PI_2 * 0.5;
5256+ assert!(
5257+ (f.gain_at(5) - midpoint.sin()).abs() < 1e-6,
5258+ "equal-power midpoint is sin(pi/4)"
5259+ );
5260+ assert_eq!(f.gain_at(20), 1.0, "unchanged in the body, past either ramp");
5261+ // The fade-out is the same curve, mirrored, counting down from the
5262+ // clip's end: unity at the frame the ramp starts, the same
5263+ // equal-power midpoint, and -- since `total` itself is one past the
5264+ // clip's last valid frame -- the very last frame is one step short of
5265+ // the silence a fade-in's own frame `0` lands on exactly.
5266+ assert_eq!(f.gain_at(30), 1.0, "unity the frame the fade-out starts");
5267+ assert!(
5268+ (f.gain_at(35) - midpoint.sin()).abs() < 1e-6,
5269+ "the fade-out's own equal-power midpoint"
5270+ );
5271+ assert!(
5272+ (f.gain_at(39) - (std::f32::consts::FRAC_PI_2 * 0.1).sin()).abs() < 1e-6,
5273+ "one step short of silence at the clip's last playable frame"
5274+ );
5275+ }
5276+
5277+ /// [`Project::crossfade`] refuses a non-audio lane and two clips that are
5278+ /// not adjacent, and otherwise sets the shared edge's fades and nothing
5279+ /// else.
5280+ #[test]
5281+ fn crossfade_only_joins_adjacent_audio_clips() {
5282+ let mut p = Project::single(FILE, 20);
5283+ assert!(p.split(10));
5284+ assert!(
5285+ !p.crossfade(Lane::V1, 0, 5),
5286+ "video is not an audio lane"
5287+ );
5288+ assert!(
5289+ !p.crossfade(Lane::A1, 1, 5),
5290+ "there is no clip after idx 1"
5291+ );
5292+ assert!(p.crossfade(Lane::A1, 0, 5), "the two halves are adjacent");
5293+ let a = p.lane(Lane::A1);
5294+ assert_eq!(a[0].fade_out, 5);
5295+ assert_eq!(a[1].fade_in, 5);
5296+ assert_eq!(a[0].fade_in, 0);
5297+ assert_eq!(a[1].fade_out, 0);
5298+
5299+ // A gap between two clips is not adjacency, even on an audio lane.
5300+ let mut p2 = Project::single(FILE, 1);
5301+ let a2 = p2.add_lane(LaneKind::Audio);
5302+ assert!(p2.place(a2, 0, clip(0, 0, 3, 0)));
5303+ assert!(p2.place(a2, 5, clip(5, 3, 6, 0)), "a gap before this one");
5304+ assert!(!p2.crossfade(a2, 0, 5), "a gap is not adjacent");
5305+ }
5306+
5307+ /// The rule [`Project::write_split`] follows for the edge the razor makes:
5308+ /// the left half keeps its old [`Clip::fade_in`] (clamped to its new,
5309+ /// shorter length) and loses its [`Clip::fade_out`]; the right half is the
5310+ /// mirror image.
5311+ #[test]
5312+ fn a_split_clamps_the_kept_fade_and_zeroes_the_cut_edge() {
5313+ let mut p = Project::single(FILE, 20);
5314+ assert!(p.set_fade_in(Lane::V1, 0, 15));
5315+ assert!(p.set_fade_out(Lane::V1, 0, 15));
5316+ assert!(p.split(5));
5317+ let v = p.lane(Lane::V1);
5318+ assert_eq!(v[0].fade_in, 5, "the left half's kept fade-in, clamped to 5 frames");
5319+ assert_eq!(v[0].fade_out, 0, "the cut edge it made starts flat");
5320+ assert_eq!(v[1].fade_in, 0, "the cut edge it made starts flat");
5321+ assert_eq!(v[1].fade_out, 15, "the right half's kept fade-out, unclamped: 15 frames fit in 15");
5322+ }
5323+
5044 /// The music video's own path: the take comes apart into halves that carry5324 /// The music video's own path: the take comes apart into halves that carry
5045 /// ids of their own, one undo puts it back, and two clips over the same5325 /// ids of their own, one undo puts it back, and two clips over the same
5046 /// frames become one take again by hand.5326 /// frames become one take again by hand.
@@ -6221,14 +6501,15 @@ mod tests {
6221 /// table like the eq and the grade: there is nothing for a table to share.6501 /// table like the eq and the grade: there is nothing for a table to share.
6222 /// It costs the clip nothing at all -- the fields before it (a `usize`6502 /// It costs the clip nothing at all -- the fields before it (a `usize`
6223 /// source and two `Option<u16>`s) already left the struct padded to 406503 /// source and two `Option<u16>`s) already left the struct padded to 40
6224- /// bytes, and the byte landed in that padding. This is the assert that says6504+ /// bytes, and the byte landed in that padding. `fade_in`/`fade_out` are the
6225- /// so: a clip that grew a word grew every undo snapshot and every clipboard6505+ /// two `u32`s after it, so those cost the clip a full word each: 48 bytes
6226- /// copy with it.6506+ /// total. This is the assert that says so: a clip that grows a word grows
6507+ /// every undo snapshot and every clipboard copy with it.
6227 #[test]6508 #[test]
6228 fn a_fit_policy_costs_the_clip_no_word() {6509 fn a_fit_policy_costs_the_clip_no_word() {
6229 assert_eq!(6510 assert_eq!(
6230 std::mem::size_of::<Clip>(),6511 std::mem::size_of::<Clip>(),
6231- 40,6512+ 48,
6232 "Clip changed size: {} bytes",6513 "Clip changed size: {} bytes",
6233 std::mem::size_of::<Clip>()6514 std::mem::size_of::<Clip>()
6234 );6515 );
@@ -6237,6 +6518,8 @@ mod tests {
6237 /// The clip a copy would hand back: source `[100, 102)`, unrelated to6518 /// The clip a copy would hand back: source `[100, 102)`, unrelated to
6238 /// anything in `three()` so it is recognisable wherever it lands.6519 /// anything in `three()` so it is recognisable wherever it lands.
6239 const PASTED: Clip = Clip {6520 const PASTED: Clip = Clip {
6521+ fade_in: 0,
6522+ fade_out: 0,
6240 start: 0,6523 start: 0,
6241 in_frame: 100,6524 in_frame: 100,
6242 out_frame: 102,6525 out_frame: 102,
@@ -6309,6 +6592,8 @@ mod tests {
6309 let mut p = three();6592 let mut p = three();
6310 let wav = p.import("/nonexistent/song.wav", 0);6593 let wav = p.import("/nonexistent/song.wav", 0);
6311 let copied = Clip {6594 let copied = Clip {
6595+ fade_in: 0,
6596+ fade_out: 0,
6312 source: wav,6597 source: wav,
6313 ..PASTED6598 ..PASTED
6314 };6599 };
@@ -7575,8 +7860,8 @@ mod tests {
7575 fn a_clip_is_still_a_small_copy() {7860 fn a_clip_is_still_a_small_copy() {
7576 assert_eq!(7861 assert_eq!(
7577 std::mem::size_of::<Clip>(),7862 std::mem::size_of::<Clip>(),
7578- 40,7863+ 48,
7579- "Clip changed size -- 32 before the colour index, 40 after"7864+ "Clip changed size -- 32 before the colour index, 40 before the fades, 48 after"
7580 );7865 );
7581 }7866 }
7582 7867
@@ -7658,6 +7943,8 @@ mod tests {
7658 // format could not have written, are refused at this door too.7943 // format could not have written, are refused at this door too.
7659 let eqd = |i: u16| {7944 let eqd = |i: u16| {
7660 vec![Clip {7945 vec![Clip {
7946+ fade_in: 0,
7947+ fade_out: 0,
7661 eq: Some(i),7948 eq: Some(i),
7662 ..video[0]7949 ..video[0]
7663 }]7950 }]
@@ -7694,6 +7981,8 @@ mod tests {
7694 // The same two refusals for a colour, at the same door.7981 // The same two refusals for a colour, at the same door.
7695 let graded = |i: u16| {7982 let graded = |i: u16| {
7696 vec![Clip {7983 vec![Clip {
7984+ fade_in: 0,
7985+ fade_out: 0,
7697 color: Some(i),7986 color: Some(i),
7698 fit: FitPolicy::default(),7987 fit: FitPolicy::default(),
7699 speed: Speed::NORMAL,7988 speed: Speed::NORMAL,
@@ -7752,6 +8041,8 @@ mod tests {
7752 fn a_link_id_is_never_two_clips_of_one_lane() {8041 fn a_link_id_is_never_two_clips_of_one_lane() {
7753 let sources = vec![Source::new(FILE, 0)];8042 let sources = vec![Source::new(FILE, 0)];
7754 let linked = |start, in_frame, out_frame, link| Clip {8043 let linked = |start, in_frame, out_frame, link| Clip {
8044+ fade_in: 0,
8045+ fade_out: 0,
7755 start,8046 start,
7756 in_frame,8047 in_frame,
7757 out_frame,8048 out_frame,
@@ -8529,6 +8820,8 @@ mod tests {
8529 fn a_group_may_span_any_lane() {8820 fn a_group_may_span_any_lane() {
8530 let lane = |kind, clips: Vec<Clip>| LaneData::new(kind, clips);8821 let lane = |kind, clips: Vec<Clip>| LaneData::new(kind, clips);
8531 let one = |start: u32, end: u32, link| Clip {8822 let one = |start: u32, end: u32, link| Clip {
8823+ fade_in: 0,
8824+ fade_out: 0,
8532 start,8825 start,
8533 in_frame: start,8826 in_frame: start,
8534 out_frame: end,8827 out_frame: end,
crates/engine/src/proxy.rsmodified+2 -0
@@ -487,6 +487,8 @@ fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Opti
487 // what makes the proxy picture-only: the export walk codes the lanes it is487 // what makes the proxy picture-only: the export walk codes the lanes it is
488 // given and there is no sound among them.488 // given and there is no sound among them.
489 let clip = Clip {489 let clip = Clip {
490+ fade_in: 0,
491+ fade_out: 0,
490 start: 0,492 start: 0,
491 in_frame: 0,493 in_frame: 0,
492 out_frame: meta.frame_count.max(1),494 out_frame: meta.frame_count.max(1),
crates/engine/src/silence.rsmodified+2 -0
@@ -295,6 +295,8 @@ mod tests {
295 295
296 fn clip(start: u32, in_frame: u32, out_frame: u32, speed: Speed) -> Clip {296 fn clip(start: u32, in_frame: u32, out_frame: u32, speed: Speed) -> Clip {
297 Clip {297 Clip {
298+ fade_in: 0,
299+ fade_out: 0,
298 start,300 start,
299 in_frame,301 in_frame,
300 out_frame,302 out_frame,
crates/engine/src/sweep.rsmodified+2 -0
@@ -66,6 +66,8 @@ fn track() -> SubtitleTrack {
66 66
67 fn clip(start: u32, in_frame: u32, out_frame: u32) -> Clip {67 fn clip(start: u32, in_frame: u32, out_frame: u32) -> Clip {
68 Clip {68 Clip {
69+ fade_in: 0,
70+ fade_out: 0,
69 start,71 start,
70 in_frame,72 in_frame,
71 out_frame,73 out_frame,
crates/engine/tests/audio_export.rsmodified+18 -0
@@ -61,6 +61,8 @@ fn wait(handle: &ExportHandle, limit: Duration) -> engine::Result<()> {
61 /// re-encodes today and once refused outright.61 /// re-encodes today and once refused outright.
62 fn mixed_project() -> Project {62 fn mixed_project() -> Project {
63 let clip = |start, source| Clip {63 let clip = |start, source| Clip {
64+ fade_in: 0,
65+ fade_out: 0,
64 start,66 start,
65 in_frame: 0,67 in_frame: 0,
66 out_frame: 30,68 out_frame: 30,
@@ -83,6 +85,8 @@ fn mixed_project() -> Project {
83 (85 (
84 LaneKind::Video,86 LaneKind::Video,
85 vec![Clip {87 vec![Clip {
88+ fade_in: 0,
89+ fade_out: 0,
86 start: 0,90 start: 0,
87 in_frame: 0,91 in_frame: 0,
88 out_frame: 90,92 out_frame: 90,
@@ -324,6 +328,8 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() {
324 let song = asset("test_tone.mp3");328 let song = asset("test_tone.mp3");
325 let still = asset("test_still.png");329 let still = asset("test_still.png");
326 let clip = |source, frames| Clip {330 let clip = |source, frames| Clip {
331+ fade_in: 0,
332+ fade_out: 0,
327 start: 0,333 start: 0,
328 in_frame: 0,334 in_frame: 0,
329 out_frame: frames,335 out_frame: frames,
@@ -388,6 +394,8 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() {
388 #[test]394 #[test]
389 fn a_fader_is_one_tracks_own_and_the_limiter_holds_the_sum() {395 fn a_fader_is_one_tracks_own_and_the_limiter_holds_the_sum() {
390 let clip = Clip {396 let clip = Clip {
397+ fade_in: 0,
398+ fade_out: 0,
391 start: 0,399 start: 0,
392 in_frame: 0,400 in_frame: 0,
393 out_frame: 30,401 out_frame: 30,
@@ -621,6 +629,8 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
621 (629 (
622 LaneKind::Video,630 LaneKind::Video,
623 vec![Clip {631 vec![Clip {
632+ fade_in: 0,
633+ fade_out: 0,
624 start: 0,634 start: 0,
625 in_frame: 0,635 in_frame: 0,
626 out_frame: 60,636 out_frame: 60,
@@ -635,6 +645,8 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
635 (645 (
636 LaneKind::Audio,646 LaneKind::Audio,
637 vec![Clip {647 vec![Clip {
648+ fade_in: 0,
649+ fade_out: 0,
638 start: 0,650 start: 0,
639 in_frame: 0,651 in_frame: 0,
640 out_frame: 60,652 out_frame: 60,
@@ -689,6 +701,8 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
689 #[test]701 #[test]
690 fn a_silent_clip_exports_as_silence_over_its_own_span() {702 fn a_silent_clip_exports_as_silence_over_its_own_span() {
691 let clip = |start, source| Clip {703 let clip = |start, source| Clip {
704+ fade_in: 0,
705+ fade_out: 0,
692 start,706 start,
693 in_frame: 0,707 in_frame: 0,
694 out_frame: 30,708 out_frame: 30,
@@ -779,6 +793,8 @@ fn a_51_ac3_source_round_trips_through_a_wav() {
779 vec![(793 vec![(
780 LaneKind::Audio,794 LaneKind::Audio,
781 vec![Clip {795 vec![Clip {
796+ fade_in: 0,
797+ fade_out: 0,
782 start: 0,798 start: 0,
783 in_frame: 0,799 in_frame: 0,
784 out_frame: 30,800 out_frame: 30,
@@ -904,6 +920,8 @@ fn a_mono_timeline_exports_as_dual_mono_ogg() {
904 vec![(920 vec![(
905 LaneKind::Audio,921 LaneKind::Audio,
906 vec![Clip {922 vec![Clip {
923+ fade_in: 0,
924+ fade_out: 0,
907 start: 0,925 start: 0,
908 in_frame: 0,926 in_frame: 0,
909 out_frame: 30,927 out_frame: 30,
crates/engine/tests/audio_files.rsmodified+2 -0
@@ -491,6 +491,8 @@ fn a_song_survives_a_save_and_a_reload() {
491 Lane::A1,491 Lane::A1,
492 1.0,492 1.0,
493 Clip {493 Clip {
494+ fade_in: 0,
495+ fade_out: 0,
494 in_frame: 0,496 in_frame: 0,
495 out_frame: 30,497 out_frame: 30,
496 ..song498 ..song
crates/engine/tests/eq_audio.rsmodified+2 -0
@@ -54,6 +54,8 @@ fn boost() -> EqParams {
54 54
55 fn clip(start: u32, source: usize, frames: u32) -> Clip {55 fn clip(start: u32, source: usize, frames: u32) -> Clip {
56 Clip {56 Clip {
57+ fade_in: 0,
58+ fade_out: 0,
57 start,59 start,
58 in_frame: 0,60 in_frame: 0,
59 out_frame: frames,61 out_frame: frames,
crates/engine/tests/export.rsmodified+4 -0
@@ -234,6 +234,8 @@ fn exports_an_edited_timeline_in_hardware() {
234 fn exports_at_the_project_resolution_with_the_watched_geometry() {234 fn exports_at_the_project_resolution_with_the_watched_geometry() {
235 let _seat = pin_software();235 let _seat = pin_software();
236 let clip = |source: usize, start: u32| engine::Clip {236 let clip = |source: usize, start: u32| engine::Clip {
237+ fade_in: 0,
238+ fade_out: 0,
237 start,239 start,
238 in_frame: 0,240 in_frame: 0,
239 out_frame: 10,241 out_frame: 10,
@@ -316,6 +318,8 @@ fn exports_the_audio_stream_the_timeline_plays() {
316 let multi = asset("test_multiaudio.mp4");318 let multi = asset("test_multiaudio.mp4");
317 let (meta, _) = engine::demux::Demuxer::open(&multi).expect("open the fixture");319 let (meta, _) = engine::demux::Demuxer::open(&multi).expect("open the fixture");
318 let whole = engine::Clip {320 let whole = engine::Clip {
321+ fade_in: 0,
322+ fade_out: 0,
319 start: 0,323 start: 0,
320 in_frame: 0,324 in_frame: 0,
321 out_frame: meta.frame_count,325 out_frame: meta.frame_count,
crates/engine/tests/lanes.rsmodified+6 -0
@@ -235,6 +235,8 @@ fn the_mp4_copy_follows_the_lane_that_holds_the_sound() {
235 pin_software();235 pin_software();
236 let source = asset("test_av.mp4");236 let source = asset("test_av.mp4");
237 let clip = Clip {237 let clip = Clip {
238+ fade_in: 0,
239+ fade_out: 0,
238 start: 0,240 start: 0,
239 in_frame: 0,241 in_frame: 0,
240 out_frame: TOTAL,242 out_frame: TOTAL,
@@ -296,6 +298,8 @@ fn two_audio_lanes_are_summed() {
296 let one_lane = Project::single(asset("test_av.mp4"), TOTAL);298 let one_lane = Project::single(asset("test_av.mp4"), TOTAL);
297 let mut project = one_lane.clone();299 let mut project = one_lane.clone();
298 let doubled = Clip {300 let doubled = Clip {
301+ fade_in: 0,
302+ fade_out: 0,
299 start: TOP_IN,303 start: TOP_IN,
300 in_frame: TOP_IN,304 in_frame: TOP_IN,
301 out_frame: TOP_OUT,305 out_frame: TOP_OUT,
@@ -553,6 +557,8 @@ fn a_paste_never_touches_the_captions() {
553 557
554 let clip = *project.lane(Lane::V1).first().expect("V1 holds the film");558 let clip = *project.lane(Lane::V1).first().expect("V1 holds the film");
555 let pasted = Clip {559 let pasted = Clip {
560+ fade_in: 0,
561+ fade_out: 0,
556 out_frame: 30,562 out_frame: 30,
557 ..clip563 ..clip
558 };564 };
crates/engine/tests/opus_export.rsmodified+4 -0
@@ -80,6 +80,8 @@ fn wait(handle: &ExportHandle, limit: Duration) -> engine::Result<()> {
80 /// `sound_in` seconds into that file: an edit, so nothing here can be a copy.80 /// `sound_in` seconds into that file: an edit, so nothing here can be a copy.
81 fn project(video: &Path, sound: &Path, sound_in: u32) -> Project {81 fn project(video: &Path, sound: &Path, sound_in: u32) -> Project {
82 let clip = |source, in_frame, out_frame| Clip {82 let clip = |source, in_frame, out_frame| Clip {
83+ fade_in: 0,
84+ fade_out: 0,
83 start: 0,85 start: 0,
84 in_frame,86 in_frame,
85 out_frame,87 out_frame,
@@ -420,6 +422,8 @@ fn a_copied_picture_names_the_sound_it_was_written_with() {
420 let (meta, _) = engine::demux::Demuxer::open(&video).expect("probe the picture");422 let (meta, _) = engine::demux::Demuxer::open(&video).expect("probe the picture");
421 let frames = meta.frame_count;423 let frames = meta.frame_count;
422 let clip = |source, out_frame| Clip {424 let clip = |source, out_frame| Clip {
425+ fade_in: 0,
426+ fade_out: 0,
423 start: 0,427 start: 0,
424 in_frame: 0,428 in_frame: 0,
425 out_frame,429 out_frame,
crates/engine/tests/silence.rsmodified+4 -0
@@ -138,6 +138,8 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() {
138 let lane = p.add_lane(LaneKind::Video);138 let lane = p.add_lane(LaneKind::Video);
139 assert_eq!(lane.label(), "V2");139 assert_eq!(lane.label(), "V2");
140 let broll = Clip {140 let broll = Clip {
141+ fade_in: 0,
142+ fade_out: 0,
141 start: 0,143 start: 0,
142 in_frame: 0,144 in_frame: 0,
143 out_frame: 20,145 out_frame: 20,
@@ -173,6 +175,8 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() {
173 /// A clip covering the whole fixture, for a second track to carry.175 /// A clip covering the whole fixture, for a second track to carry.
174 fn whole(source: usize, frames: u32) -> Clip {176 fn whole(source: usize, frames: u32) -> Clip {
175 Clip {177 Clip {
178+ fade_in: 0,
179+ fade_out: 0,
176 start: 0,180 start: 0,
177 in_frame: 0,181 in_frame: 0,
178 out_frame: frames,182 out_frame: frames,
crates/engine/tests/speed.rsmodified+2 -0
@@ -516,6 +516,8 @@ fn an_mp4_export_honours_a_speeded_picture_across_a_rate_change() {
516 Lane::V1,516 Lane::V1,
517 fast,517 fast,
518 Clip {518 Clip {
519+ fade_in: 0,
520+ fade_out: 0,
519 speed: Speed::NORMAL,521 speed: Speed::NORMAL,
520 ..whole522 ..whole
521 }523 }