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() {
615615 use keymap::{ActionId, Keymap};
616616 // Frames 30..90 of the timeline, taken from the head of its source.
617617 let clip = Clip {
618+ fade_in: 0,
619+ fade_out: 0,
618620 start: 30,
619621 in_frame: 0,
620622 out_frame: 60,
@@ -655,6 +657,8 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
655657 // clip by any reading of the playhead, so "only from inside a clip"
656658 // there is a refusal claiming something the screen contradicts.
657659 let slow = Clip {
660+ fade_in: 0,
661+ fade_out: 0,
658662 speed: Speed::MIN,
659663 ..clip
660664 };
@@ -679,6 +683,8 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
679683 // engine's question. Group is offered on every clip, for that reason.
680684 assert!(!offered(&clip, v1, ActionId::Detach, 0));
681685 let grouped = Clip {
686+ fade_in: 0,
687+ fade_out: 0,
682688 link: Some(3),
683689 ..clip
684690 };
@@ -981,6 +987,8 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
981987 fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() {
982988 use keymap::ActionId;
983989 let clip = Clip {
990+ fade_in: 0,
991+ fade_out: 0,
984992 start: 30,
985993 in_frame: 0,
986994 out_frame: 60,
@@ -1611,6 +1619,8 @@ fn removing_a_row_is_refused_while_it_plays_and_takes_the_row_away() {
16111619 #[test]
16121620 fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() {
16131621 let clip = |source: usize| Clip {
1622+ fade_in: 0,
1623+ fade_out: 0,
16141624 start: 0,
16151625 in_frame: 0,
16161626 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() {
801801 #[test]
802802 fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() {
803803 let at = |start: u32| Clip {
804+ fade_in: 0,
805+ fade_out: 0,
804806 start,
805807 in_frame: 0,
806808 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() {
147147 #[test]
148148 fn the_marks_are_every_lane_the_playhead_and_the_start() {
149149 let clip = |start: u32, frames: u32, link| Clip {
150+ fade_in: 0,
151+ fade_out: 0,
150152 start,
151153 in_frame: 0,
152154 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
303303 };
304304 match still {
305305 true => Clip {
306+ fade_in: 0,
307+ fade_out: 0,
306308 in_frame: 0,
307309 out_frame: keep,
308310 start: to,
309311 ..clip
310312 },
311313 false => Clip {
314+ fade_in: 0,
315+ fade_out: 0,
312316 in_frame: clip.out_frame - keep.min(clip.out_frame),
313317 start: to,
314318 ..clip
@@ -317,6 +321,8 @@ pub(crate) fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip
317321 }
318322 Edge::End => match clip.speed.fit(to.saturating_sub(clip.start)) {
319323 Some(keep) => Clip {
324+ fade_in: 0,
325+ fade_out: 0,
320326 out_frame: clip.in_frame + keep,
321327 ..clip
322328 },
crates/engine/examples/bench.rsmodified+2 -0
@@ -860,6 +860,8 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) {
860860 .min(meta.frame_count.max(1));
861861 let in_frame = (meta.frame_count / 10).min(meta.frame_count.saturating_sub(span));
862862 let clip = Clip {
863+ fade_in: 0,
864+ fade_out: 0,
863865 start: 0,
864866 in_frame,
865867 out_frame: in_frame + span,
crates/engine/src/audio.rsmodified+109 -4
@@ -392,6 +392,22 @@ impl AudioSession {
392392 eqs: &[Option<EqParams>],
393393 speeds: &[Option<crate::project::Stretch>],
394394 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>,
395411 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
396412 // The first source that could have a track, which is not always index 0:
397413 // a still image has none, and one at the front of the list (a save
@@ -571,6 +587,17 @@ impl AudioSession {
571587 })
572588 .collect();
573589
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+
574601 let (tx, rx) = sync_channel(32);
575602 thread::Builder::new()
576603 .name("audio-decode".into())
@@ -581,6 +608,7 @@ impl AudioSession {
581608 segments,
582609 eqs,
583610 speeds,
611+ fades,
584612 timeline,
585613 tx,
586614 })
@@ -690,7 +718,27 @@ impl AudioSession {
690718 limiter: Limiter,
691719 sample_rate: Option<u32>,
692720 ) -> 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+ )
694742 }
695743
696744 /// [`open_mixed_streams_master`](Self::open_mixed_streams_master) with the
@@ -710,6 +758,27 @@ impl AudioSession {
710758 limiter: Limiter,
711759 live: Option<&Arc<MixControls>>,
712760 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>,
713782 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
714783 let [first, ..] = lanes else {
715784 return Ok(None);
@@ -717,11 +786,13 @@ impl AudioSession {
717786 if !Self::is_mixed(lanes.len(), gains, limiter) {
718787 let flat = Vec::new();
719788 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(
721791 sources,
722792 first,
723793 eqs.first().unwrap_or(&flat),
724794 speeds.first().unwrap_or(&plain),
795+ fades.first().unwrap_or(&flat_fade),
725796 sample_rate,
726797 );
727798 }
@@ -732,12 +803,14 @@ impl AudioSession {
732803 // agree by construction; `None` from any of them is a silent
733804 // timeline.
734805 let flat = Vec::new();
806+ let flat_fade = Vec::new();
735807 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(
737809 sources,
738810 segs,
739811 eqs.get(i).unwrap_or(&flat),
740812 speeds.get(i).unwrap_or(&plain),
813+ fades.get(i).unwrap_or(&flat_fade),
741814 sample_rate,
742815 )?
743816 else {
@@ -2820,6 +2893,10 @@ struct Worker {
28202893 /// every segment of a project nobody has speeded or rate-mismatched, and
28212894 /// the path that emits the decoder's own samples untouched.
28222895 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>>,
28232900 /// `start_sample` of the first chunk.
28242901 timeline: u64,
28252902 tx: SyncSender<AudioChunk>,
@@ -2953,8 +3030,16 @@ fn run(mut w: Worker) {
29533030 let mut speeds = std::mem::take(&mut w.speeds);
29543031 // ...and a short rate list is "real time from here on", for the same reason.
29553032 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);
29563036
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+ {
29583043 let Some(source) = seg.source else {
29593044 // A gap: hand the device real silence rather than nothing at all,
29603045 // in the same packet-sized chunks decoding produces, so `fed` and
@@ -2984,6 +3069,7 @@ fn run(mut w: Worker) {
29843069 seg,
29853070 eq.as_mut(),
29863071 speed,
3072+ fade,
29873073 channels,
29883074 &mut timeline,
29893075 &w.tx,
@@ -2999,6 +3085,7 @@ fn run(mut w: Worker) {
29993085 seg,
30003086 eq.as_mut(),
30013087 speed,
3088+ fade,
30023089 channels,
30033090 &mut timeline,
30043091 &w.tx,
@@ -3014,6 +3101,7 @@ fn run(mut w: Worker) {
30143101 seg,
30153102 eq.as_mut(),
30163103 speed,
3104+ fade,
30173105 channels,
30183106 &mut timeline,
30193107 &w.tx,
@@ -3063,6 +3151,7 @@ fn run(mut w: Worker) {
30633151 seg,
30643152 eq.as_mut(),
30653153 speed.as_mut(),
3154+ fade.as_mut(),
30663155 pos,
30673156 next,
30683157 &mut timeline,
@@ -3115,6 +3204,7 @@ fn emit(
31153204 seg: &Segment,
31163205 eq: Option<&mut EqState>,
31173206 speed: Option<&mut Rate>,
3207+ fade: Option<&mut crate::project::Fade>,
31183208 pos: u64,
31193209 next: u64,
31203210 timeline: &mut u64,
@@ -3147,6 +3237,15 @@ fn emit(
31473237 if let Some(eq) = eq {
31483238 eq.process(interleaved);
31493239 }
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+ }
31503249 let chunk = AudioChunk {
31513250 start_sample: *timeline,
31523251 samples: std::mem::take(interleaved),
@@ -3164,6 +3263,7 @@ fn run_ac3(
31643263 seg: &Segment,
31653264 mut eq: Option<&mut EqState>,
31663265 speed: &mut Option<Rate>,
3266+ fade: &mut Option<crate::project::Fade>,
31673267 channels: usize,
31683268 timeline: &mut u64,
31693269 tx: &SyncSender<AudioChunk>,
@@ -3206,6 +3306,7 @@ fn run_ac3(
32063306 seg,
32073307 eq.as_deref_mut(),
32083308 speed.as_mut(),
3309+ fade.as_mut(),
32093310 pos,
32103311 next,
32113312 timeline,
@@ -3227,6 +3328,7 @@ fn run_mkv_ac3(
32273328 seg: &Segment,
32283329 mut eq: Option<&mut EqState>,
32293330 speed: &mut Option<Rate>,
3331+ fade: &mut Option<crate::project::Fade>,
32303332 channels: usize,
32313333 timeline: &mut u64,
32323334 tx: &SyncSender<AudioChunk>,
@@ -3268,6 +3370,7 @@ fn run_mkv_ac3(
32683370 seg,
32693371 eq.as_deref_mut(),
32703372 speed.as_mut(),
3373+ fade.as_mut(),
32713374 pos,
32723375 next,
32733376 timeline,
@@ -3294,6 +3397,7 @@ fn run_sym(
32943397 seg: &Segment,
32953398 mut eq: Option<&mut EqState>,
32963399 speed: &mut Option<Rate>,
3400+ fade: &mut Option<crate::project::Fade>,
32973401 channels: usize,
32983402 timeline: &mut u64,
32993403 tx: &SyncSender<AudioChunk>,
@@ -3342,6 +3446,7 @@ fn run_sym(
33423446 seg,
33433447 eq.as_deref_mut(),
33443448 speed.as_mut(),
3449+ fade.as_mut(),
33453450 pos,
33463451 next,
33473452 timeline,
crates/engine/src/edith.rsmodified+147 -56
@@ -16,9 +16,9 @@
1616 //! subtitle 3 test_av.mp4
1717 //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk
1818 //! color 0.1:1.2:0.9:-0.3
19-//! video 1 0 0 120 0 0 0 0 fit 1000
20-//! audio 1 0 0 120 0 0 0 - fit 1000
21-//! video 2 120 0 120 1 - - - fill 2000
19+//! video 1 0 0 120 0 0 0 0 fit 1000 0 0
20+//! audio 1 0 0 120 0 0 0 - fit 1000 30 30
21+//! video 2 120 0 120 1 - - - fill 2000 0 0
2222 //! audio 2
2323 //! sub 1 0 60 0 500000 1500000
2424 //! sub 2
@@ -110,15 +110,18 @@
110110 //! -- the first colour line is color 0 -- printed and refused by the same rules.
111111 //!
112112 //! 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 number
113+//! <color> <fit> <speed> <fade_in> <fade_out>`: which lane the clip is on -- its kind and its 1-based number
114114 //! among the lanes of that kind, the [`crate::project::Lane::label`] a header
115115 //! column shows -- then where the clip sits on the timeline, the half-open
116116 //! source range it plays, the file it plays from, its group id, the eq line it
117117 //! plays through, the colour line it is graded by (`-` for none of those three)
118118 //! 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,
120120 //! in thousandths of real time ([`crate::project::Speed`], `1000` for a clip
121-//! nobody has speeded). Timeline placement is
121+//! 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
122125 //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing
123126 //! to write for one, and nothing that can disagree about its length. The `<in>`
124127 //! and `<out>` are *source* frames whatever the speed says: how long the clip is
@@ -143,6 +146,8 @@
143146 //! track 3 of a two-track palette is refused here, as a clip naming a source
144147 //! that is not there is.
145148 //!
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.
146151 //! **Version 15** was this without the caption's group field: such a project
147152 //! holds captions no hand ever grouped, which is every caption there could be.
148153 //! **Version 14** was that without the `sub` lines: such a project holds no
@@ -180,7 +185,7 @@
180185 //! nothing, and an older one plays everything at real time, and an older one
181186 //! mixes flat, and an older one shows no subtitles, and an older one is shown
182187 //! in the reference rendition, and an older one places none of the words it
183-//! names -- and saving any of them writes v16. An older
188+//! names -- and saving any of them writes v18. An older
184189 //! reader refuses a newer file by name.
185190 //!
186191 //! Text because an edit list is a few integers and a path, and a path is
@@ -216,7 +221,8 @@ use crate::subtitle::SubtitleTrack;
216221
217222 /// What [`save`] writes. Read support goes back to `edith 1`; see the module
218223 /// 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";
220226 const MAGIC_V16: &[u8] = b"edith 16";
221227 const MAGIC_V15: &[u8] = b"edith 15";
222228 const MAGIC_V14: &[u8] = b"edith 14";
@@ -549,13 +555,15 @@ fn emit(
549555 let color = c.color.map_or("-".to_string(), |e| e.to_string());
550556 out.extend_from_slice(
551557 format!(
552- "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {}\n",
558+ "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {}\n",
553559 c.start,
554560 c.in_frame,
555561 c.out_frame,
556562 c.source,
557563 fit_name(c.fit),
558- c.speed.permille()
564+ c.speed.permille(),
565+ c.fade_in,
566+ c.fade_out,
559567 )
560568 .as_bytes(),
561569 );
@@ -598,8 +606,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
598606 // The dialects that wrote a source line without its stream field. Reading
599607 // one is the whole of what "an old project still opens" means here.
600608 let streamless = v1 || first == MAGIC_V2;
601- // The one that carries an explicit sound rate...
602- let v17 = first == MAGIC;
609+ // The one that carries a per-clip fade envelope...
610+ let v18 = first == MAGIC;
611+ // ...the one that carries an explicit sound rate...
612+ let v17 = v18 || first == MAGIC_V17;
603613 // ...the one whose captions may carry a group id...
604614 let v16 = v17 || first == MAGIC_V16;
605615 // ...the one that places the words it names...
@@ -963,6 +973,8 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
963973 let f = fields(rest, 3, "clip", n)?;
964974 let clip = check(
965975 Clip {
976+ fade_in: 0,
977+ fade_out: 0,
966978 start: queued,
967979 in_frame: number(f[0], n)?,
968980 out_frame: number(f[1], n)?,
@@ -1081,16 +1093,31 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
10811093 if numbered && rest.is_empty() {
10821094 continue;
10831095 }
1084- // v8 grew the speed field, v7 the fit one, v6 the colour one and
1085- // v5 the eq one; every older dialect ends at the link.
1086- let want =
1087- 5 + usize::from(v5) + usize::from(v6) + usize::from(v7) + usize::from(v8);
1096+ // v18 grew the two fade fields, v8 the speed one, v7 the fit
1097+ // one, v6 the colour one and v5 the eq one; every older
1098+ // dialect ends at the link.
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);
10881105 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));
10891114 let clip = check(
10901115 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),
10911118 start: number(f[0], n)?,
1092- in_frame: number(f[1], n)?,
1093- out_frame: number(f[2], n)?,
1119+ in_frame,
1120+ out_frame,
10941121 source: number(f[3], n)? as usize,
10951122 link: match f[4] {
10961123 b"-" => None,
@@ -1099,7 +1126,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
10991126 eq: table_index(f.get(5).copied(), doc.eq.len(), "eq", n)?,
11001127 color: table_index(f.get(6).copied(), doc.color.len(), "color", n)?,
11011128 fit: fit_policy(f.get(7).copied(), n)?,
1102- speed: speed_of(f.get(8).copied(), n)?,
1129+ speed,
11031130 },
11041131 &doc,
11051132 n,
@@ -1509,7 +1536,7 @@ mod tests {
15091536 video 1 0 0 30 0 - - - fit 1000\n";
15101537 let old = parse(v9, &dir).expect("v9 still loads");
15111538 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"));
15131540 // ...and the line itself is not a v9 line: a dialect may not be mixed.
15141541 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)
15151542 .unwrap_err()
@@ -1851,7 +1878,7 @@ mod tests {
18511878 assert_eq!(mixed, "line 3: unknown keyword \"samplerate\"");
18521879 // A number out of a sound rate's range is a corrupt line, by name.
18531880 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}");
18551882 assert!(
18561883 parse(file.as_bytes(), &dir).is_err(),
18571884 "{line:?} is not a sound rate line"
@@ -1919,6 +1946,8 @@ mod tests {
19191946
19201947 fn clip(start: u32, in_frame: u32, out_frame: u32, source: usize, link: Option<u32>) -> Clip {
19211948 Clip {
1949+ fade_in: 0,
1950+ fade_out: 0,
19221951 start,
19231952 in_frame,
19241953 out_frame,
@@ -1977,10 +2006,10 @@ mod tests {
19772006 let bytes = flat(&dir, &sources, &lanes, 12);
19782007 assert_eq!(
19792008 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\
19812010 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\
1983- audio 1 0 0 30 0 0 - - 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\
2012+ audio 1 0 0 30 0 0 - - fit 1000 0 0\n",
19842013 "the file under the project directory is written relative to it, \
19852014 each with the audio stream it plays"
19862015 );
@@ -2014,9 +2043,9 @@ mod tests {
20142043 let bytes = flat(&dir, &sources, &lanes, 7);
20152044 assert_eq!(
20162045 String::from_utf8_lossy(&bytes),
2017- "edith 17\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
2018- video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\
2019- video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n",
2046+ "edith 18\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
2047+ video 1 0 0 30 0 4 - - fit 1000 0 0\naudio 1\n\
2048+ video 2 40 0 10 0 - - - fit 1000 0 0\naudio 2 0 0 30 0 4 - - fit 1000 0 0\n",
20202049 "an empty lane is a line of its own; everything else is its clips"
20212050 );
20222051 let back = parse(&bytes, &dir).expect("parse");
@@ -2100,20 +2129,28 @@ mod tests {
21002129 let lanes = two(
21012130 vec![
21022131 Clip {
2132+ fade_in: 0,
2133+ fade_out: 0,
21032134 eq: Some(0),
21042135 ..clip(0, 0, 30, 0, Some(0))
21052136 },
21062137 Clip {
2138+ fade_in: 0,
2139+ fade_out: 0,
21072140 eq: Some(1),
21082141 ..clip(30, 10, 20, 0, None)
21092142 },
21102143 ],
21112144 vec![
21122145 Clip {
2146+ fade_in: 0,
2147+ fade_out: 0,
21132148 eq: Some(0),
21142149 ..clip(0, 0, 30, 0, Some(0))
21152150 },
21162151 Clip {
2152+ fade_in: 0,
2153+ fade_out: 0,
21172154 eq: Some(2),
21182155 ..clip(30, 0, 10, 0, None)
21192156 },
@@ -2122,12 +2159,12 @@ mod tests {
21222159 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);
21232160 assert_eq!(
21242161 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\
21262163 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
21272164 eq 16777215.0:-0.1:3.918315e-39:hs\n\
21282165 eq\n\
2129- video 1 0 0 30 0 0 0 - fit 1000\nvideo 1 30 10 20 0 - 1 - fit 1000\n\
2130- audio 1 0 0 30 0 0 0 - fit 1000\naudio 1 30 0 10 0 - 2 - 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\
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",
21312168 "the table comes before the clips, and a clip names a line of it"
21322169 );
21332170
@@ -2196,12 +2233,16 @@ mod tests {
21962233 let lanes = two(
21972234 vec![
21982235 Clip {
2236+ fade_in: 0,
2237+ fade_out: 0,
21992238 color: Some(0),
22002239 fit: FitPolicy::default(),
22012240 speed: Speed::NORMAL,
22022241 ..clip(0, 0, 30, 0, Some(0))
22032242 },
22042243 Clip {
2244+ fade_in: 0,
2245+ fade_out: 0,
22052246 color: Some(1),
22062247 fit: FitPolicy::default(),
22072248 speed: Speed::NORMAL,
@@ -2210,12 +2251,16 @@ mod tests {
22102251 ],
22112252 vec![
22122253 Clip {
2254+ fade_in: 0,
2255+ fade_out: 0,
22132256 color: Some(0),
22142257 fit: FitPolicy::default(),
22152258 speed: Speed::NORMAL,
22162259 ..clip(0, 0, 30, 0, Some(0))
22172260 },
22182261 Clip {
2262+ fade_in: 0,
2263+ fade_out: 0,
22192264 color: Some(2),
22202265 fit: FitPolicy::default(),
22212266 speed: Speed::NORMAL,
@@ -2226,12 +2271,12 @@ mod tests {
22262271 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);
22272272 assert_eq!(
22282273 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\
22302275 color 0.1:1.2:0.9:-0.3\n\
22312276 color -1e-7:16777215.0:3.918315e-39:-0.0\n\
22322277 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\
2234- audio 1 0 0 30 0 0 - 0 fit 1000\naudio 1 30 0 10 0 - - 2 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\
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",
22352280 "the table comes before the clips, and a clip names a line of it"
22362281 );
22372282
@@ -2291,9 +2336,9 @@ mod tests {
22912336 (1280, 720),
22922337 old.playhead
22932338 )),
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\
22952340 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"
22972342 );
22982343 }
22992344
@@ -2306,6 +2351,8 @@ mod tests {
23062351 let dir = PathBuf::from("/proj");
23072352 let sources = vec![Source::new("/proj/a.mp4", 0)];
23082353 let speeded = |start, in_frame, out_frame, permille| Clip {
2354+ fade_in: 0,
2355+ fade_out: 0,
23092356 start,
23102357 in_frame,
23112358 out_frame,
@@ -2329,9 +2376,9 @@ mod tests {
23292376 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
23302377 assert_eq!(
23312378 String::from_utf8_lossy(&bytes),
2332- "edith 17\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\
2334- audio 1 0 0 30 0 - - - fit 2000\n",
2379+ "edith 18\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2380+ video 1 0 0 30 0 - - - fit 2000 0 0\nvideo 1 15 30 40 0 - - - fit 250 0 0\n\
2381+ audio 1 0 0 30 0 - - - fit 2000 0 0\n",
23352382 "the rate is the clip line's last field, in thousandths"
23362383 );
23372384 let back = parse(&bytes, &dir).expect("parse");
@@ -2358,8 +2405,8 @@ mod tests {
23582405 (1280, 720),
23592406 old.playhead
23602407 )),
2361- "edith 17\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"
2408+ "edith 18\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\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"
23632410 );
23642411 // A rate outside what the editor can set is a corrupt line, by name.
23652412 let bad = b"edith 8\nsource 0 a.mp4\nvideo 1 0 0 30 0 - - - fit 9000\n";
@@ -2369,6 +2416,50 @@ mod tests {
23692416 );
23702417 }
23712418
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+
23722463 /// The whole of the v9 bump, the speed test's twin: the mix a project was
23732464 /// left at -- every track's own volume and the master limiter -- plus the
23742465 /// rate it was cut at, all written, all read back as the very numbers, and
@@ -2409,10 +2500,10 @@ mod tests {
24092500 );
24102501 assert_eq!(
24112502 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\
24132504 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\
2415- audio 2 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\
2506+ audio 2 0 0 30 0 - - - fit 1000 0 0\n\
24162507 gain audio 1 3.0\ngain audio 2 -6.5\n",
24172508 "the mix is lines of its own, the gains after the lanes they name"
24182509 );
@@ -2441,8 +2532,8 @@ mod tests {
24412532 (1280, 720),
24422533 old.playhead
24432534 )),
2444- "edith 17\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"
2535+ "edith 18\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2536+ video 1 0 0 30 0 - - - fit 1000 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0\n"
24462537 );
24472538
24482539 // Each of the three refuses by name, on its own line.
@@ -2605,10 +2696,10 @@ mod tests {
26052696 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");
26062697 assert_eq!(
26072698 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\
26092700 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\
2611- audio 1 0 0 30 0 0 - - 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\
2702+ audio 1 0 0 30 0 0 - - fit 1000 0 0\n"
26122703 );
26132704 // An empty lane's line is still the whole of that lane, eq or no eq.
26142705 let empty = parse(
@@ -2658,10 +2749,10 @@ mod tests {
26582749 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
26592750 assert_eq!(
26602751 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\
26622753 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\
2664- audio 1 0 0 30 0 0 - - 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\
2755+ audio 1 0 0 30 0 0 - - fit 1000 0 0\n",
26652756 "a re-saved v2 project differs only by its version, the lane \
26662757 numbers, the streams it always meant and an equalizer it has none of"
26672758 );
@@ -2690,7 +2781,7 @@ mod tests {
26902781 // Saved again it is the current version, which round-trips to the
26912782 // same document.
26922783 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"));
26942785 let again = parse(&v5, &dir).expect("v5 parses");
26952786 assert_eq!(again.lanes, back.lanes);
26962787 // A dialect may not be mixed: lane lines under v1, `clip` under v2.
@@ -2800,8 +2891,8 @@ mod tests {
28002891 let bytes = std::fs::read(&path).expect("read back");
28012892 assert_eq!(
28022893 String::from_utf8_lossy(&bytes),
2803- "edith 17\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"
2894+ "edith 18\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
2895+ video 1 0 0 30 0 - - - fit 1000 0 0\naudio 1 0 0 30 0 - - - fit 1000 0 0\n"
28052896 );
28062897 // Loading rejoins the *given* directory, so the file is reached by the
28072898 // way the project was opened -- the same file, through the link, still
@@ -2845,10 +2936,10 @@ mod tests {
28452936 #[test]
28462937 fn a_wrong_first_line_is_refused_by_name() {
28472938 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)
28492940 .unwrap_err()
28502941 .to_string();
2851- assert_eq!(err, "line 1: unsupported version 18");
2942+ assert_eq!(err, "line 1: unsupported version 19");
28522943 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {
28532944 assert_eq!(
28542945 parse(junk, &dir).unwrap_err().to_string(),
crates/engine/src/export.rsmodified+8 -2
@@ -1717,16 +1717,18 @@ fn encode_audio(
17171717 let segs = project.audio_segments_from(offset, meta.frame_rate);
17181718 let eqs = project.audio_eqs_from(offset, meta.frame_rate);
17191719 let speeds = project.audio_speeds_from(offset, meta.frame_rate);
1720+ let fades = project.audio_fades_from(offset, meta.frame_rate);
17201721 // Coarse stage timers, in the same voice as `export video: copy` below: an
17211722 // export of a feature film spends minutes in here before a byte of picture
17221723 // is written, and which minutes went where is the first question asked of a
17231724 // slow export. Three lines an export, so they stay on.
17241725 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(
17261727 &sources,
17271728 &segs,
17281729 &eqs,
17291730 &speeds,
1731+ &fades,
17301732 &project.audio_gains(),
17311733 project.limiter(),
17321734 sample_rate,
@@ -2820,15 +2822,19 @@ fn run_audio(
28202822 // 2x is half as long and holds the samples that were heard -- not a
28212823 // second pass here that could disagree with what the ear got.
28222824 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);
28232828 // ...and the mix over both: each lane's volume into the sum, the master
28242829 // limiter out of it. The same opener playback's feeder reads from, so a
28252830 // file is written at the levels it was heard at -- there is no second
28262831 // 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(
28282833 &sources,
28292834 &segs,
28302835 &eqs,
28312836 &speeds,
2837+ &fades,
28322838 &project.audio_gains(),
28332839 project.limiter(),
28342840 sample_rate,
crates/engine/src/playback.rsmodified+12 -1
@@ -618,6 +618,8 @@ impl PlaybackSession {
618618 // *video* open's pair of grouped clips: here there is no picture to
619619 // group the sound with, so the video lane starts empty.
620620 let clip = Clip {
621+ fade_in: 0,
622+ fade_out: 0,
621623 start: 0,
622624 in_frame: 0,
623625 out_frame: meta.frame_count,
@@ -701,6 +703,8 @@ impl PlaybackSession {
701703 color: ColorDescription::default(),
702704 };
703705 let clip = Clip {
706+ fade_in: 0,
707+ fade_out: 0,
704708 start: 0,
705709 in_frame: 0,
706710 out_frame: place_frames(meta.frame_count, IMAGE_ONLY_RATE),
@@ -2625,6 +2629,8 @@ impl PlaybackSession {
26252629 let source = self.project.import(path, stream);
26262630 self.note_frames(source, frames, rate);
26272631 let clip = Clip {
2632+ fade_in: 0,
2633+ fade_out: 0,
26282634 start: 0,
26292635 in_frame: 0,
26302636 out_frame: match image {
@@ -3254,6 +3260,10 @@ impl PlaybackSession {
32543260 // speeded, which is the path that decodes the same samples it always
32553261 // did.
32563262 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);
32573267 // Each source on the stream it was placed with: what plays is what
32583268 // the library row said, and what an export copies (`export::run`).
32593269 let sources = self.project.audio_sources();
@@ -3283,11 +3293,12 @@ impl PlaybackSession {
32833293 // one `pread` on a cold 25 GB film is seconds, and this is called
32843294 // from a ruler drag ([`Audio::spawn_feeder_deferred`]).
32853295 audio_running = audio.spawn_feeder_deferred(move || {
3286- match AudioSession::open_mixed_streams_live(
3296+ match AudioSession::open_mixed_streams_live_fade(
32873297 &sources,
32883298 &segs,
32893299 &eqs,
32903300 &speeds,
3301+ &fades,
32913302 &gains,
32923303 limiter,
32933304 Some(&worker_controls),
crates/engine/src/project.rsmodified+299 -6
@@ -430,6 +430,15 @@ pub struct Clip {
430430 /// changes is how many *timeline* frames that range is spread over
431431 /// ([`Clip::frames`]).
432432 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,
433442 }
434443
435444 impl Clip {
@@ -748,6 +757,62 @@ pub struct Stretch {
748757 pub timeline_secs: f64,
749758 }
750759
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+
751816 /// What a save writes and a load takes back: the sources, every lane in
752817 /// display order with its kind, and the equalizer and colour tables their clips
753818 /// index into -- [`Project::without_orphan_sources`] out,
@@ -814,6 +879,8 @@ impl Project {
814879 /// is clamped to one frame.
815880 pub fn single(path: impl AsRef<Path>, frame_count: u32) -> Self {
816881 let clip = Clip {
882+ fade_in: 0,
883+ fade_out: 0,
817884 start: 0,
818885 in_frame: 0,
819886 out_frame: frame_count.max(1),
@@ -1194,6 +1261,8 @@ impl Project {
11941261 self.snapshot();
11951262 let start = self.timeline_frames();
11961263 let clip = Clip {
1264+ fade_in: 0,
1265+ fade_out: 0,
11971266 start,
11981267 in_frame: 0,
11991268 out_frame: frame_count.max(1),
@@ -2402,6 +2471,76 @@ impl Project {
24022471 true
24032472 }
24042473
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+
24052544 /// Every frame number on every lane rewritten onto a timeline counted at
24062545 /// another rate: `k` is old timeline frames per new one, `counts` is how
24072546 /// long each source is on the *new* timeline (indexed as
@@ -2810,8 +2949,18 @@ impl Project {
28102949 tail.in_frame = split_source(&tail, timeline_frame).expect("splittable said so");
28112950 tail.start = timeline_frame;
28122951 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());
28132960 data.clips[idx].out_frame = tail.in_frame;
28142961 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());
28152964 data.clips.insert(idx + 1, tail);
28162965 }
28172966 true
@@ -3143,6 +3292,8 @@ impl Project {
31433292 }
31443293 self.snapshot();
31453294 let clip = Clip {
3295+ fade_in: 0,
3296+ fade_out: 0,
31463297 start: timeline_frame,
31473298 link: None,
31483299 ..clip
@@ -3182,6 +3333,8 @@ impl Project {
31823333 self.lanes.push(LaneData::new(LaneKind::Audio, Vec::new()));
31833334 }
31843335 let clip = Clip {
3336+ fade_in: 0,
3337+ fade_out: 0,
31853338 start: timeline_frame,
31863339 link: Some(self.new_link()),
31873340 ..clip
@@ -3757,6 +3910,8 @@ impl Project {
37573910 }
37583911 self.snapshot();
37593912 let clip = Clip {
3913+ fade_in: 0,
3914+ fade_out: 0,
37603915 start: at,
37613916 link: Some(self.new_link()),
37623917 ..clip
@@ -4446,6 +4601,42 @@ impl Project {
44464601 .collect()
44474602 }
44484603
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+
44494640 /// Pushes the undo snapshot. Every mutating method calls this once, *after*
44504641 /// it has decided it will succeed -- a refusal must not cost an undo step.
44514642 /// 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) {
47944985 && c.start < start
47954986 {
47964987 out.push(Clip {
4988+ fade_in: 0,
4989+ fade_out: 0,
47974990 out_frame: c.in_frame + keep.min(c.len()),
47984991 link: None,
47994992 ..c
@@ -4807,6 +5000,8 @@ fn clear(clips: &mut Vec<Clip>, start: u32, end: u32) {
48075000 && c.end() > end
48085001 {
48095002 out.push(Clip {
5003+ fade_in: 0,
5004+ fade_out: 0,
48105005 start: end,
48115006 in_frame: c.out_frame - keep.min(c.len()),
48125007 link: None,
@@ -4913,6 +5108,8 @@ mod tests {
49135108 /// A contiguous placement, group id ignored: what most assertions compare.
49145109 fn clip(start: u32, in_frame: u32, out_frame: u32, source: usize) -> Clip {
49155110 Clip {
5111+ fade_in: 0,
5112+ fade_out: 0,
49165113 start,
49175114 in_frame,
49185115 out_frame,
@@ -5041,6 +5238,89 @@ mod tests {
50415238 );
50425239 }
50435240
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+
50445324 /// The music video's own path: the take comes apart into halves that carry
50455325 /// ids of their own, one undo puts it back, and two clips over the same
50465326 /// frames become one take again by hand.
@@ -6221,14 +6501,15 @@ mod tests {
62216501 /// table like the eq and the grade: there is nothing for a table to share.
62226502 /// It costs the clip nothing at all -- the fields before it (a `usize`
62236503 /// 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 says
6225- /// so: a clip that grew a word grew every undo snapshot and every clipboard
6226- /// copy with it.
6504+ /// bytes, and the byte landed in that padding. `fade_in`/`fade_out` are the
6505+ /// two `u32`s after it, so those cost the clip a full word each: 48 bytes
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.
62276508 #[test]
62286509 fn a_fit_policy_costs_the_clip_no_word() {
62296510 assert_eq!(
62306511 std::mem::size_of::<Clip>(),
6231- 40,
6512+ 48,
62326513 "Clip changed size: {} bytes",
62336514 std::mem::size_of::<Clip>()
62346515 );
@@ -6237,6 +6518,8 @@ mod tests {
62376518 /// The clip a copy would hand back: source `[100, 102)`, unrelated to
62386519 /// anything in `three()` so it is recognisable wherever it lands.
62396520 const PASTED: Clip = Clip {
6521+ fade_in: 0,
6522+ fade_out: 0,
62406523 start: 0,
62416524 in_frame: 100,
62426525 out_frame: 102,
@@ -6309,6 +6592,8 @@ mod tests {
63096592 let mut p = three();
63106593 let wav = p.import("/nonexistent/song.wav", 0);
63116594 let copied = Clip {
6595+ fade_in: 0,
6596+ fade_out: 0,
63126597 source: wav,
63136598 ..PASTED
63146599 };
@@ -7575,8 +7860,8 @@ mod tests {
75757860 fn a_clip_is_still_a_small_copy() {
75767861 assert_eq!(
75777862 std::mem::size_of::<Clip>(),
7578- 40,
7579- "Clip changed size -- 32 before the colour index, 40 after"
7863+ 48,
7864+ "Clip changed size -- 32 before the colour index, 40 before the fades, 48 after"
75807865 );
75817866 }
75827867
@@ -7658,6 +7943,8 @@ mod tests {
76587943 // format could not have written, are refused at this door too.
76597944 let eqd = |i: u16| {
76607945 vec![Clip {
7946+ fade_in: 0,
7947+ fade_out: 0,
76617948 eq: Some(i),
76627949 ..video[0]
76637950 }]
@@ -7694,6 +7981,8 @@ mod tests {
76947981 // The same two refusals for a colour, at the same door.
76957982 let graded = |i: u16| {
76967983 vec![Clip {
7984+ fade_in: 0,
7985+ fade_out: 0,
76977986 color: Some(i),
76987987 fit: FitPolicy::default(),
76997988 speed: Speed::NORMAL,
@@ -7752,6 +8041,8 @@ mod tests {
77528041 fn a_link_id_is_never_two_clips_of_one_lane() {
77538042 let sources = vec![Source::new(FILE, 0)];
77548043 let linked = |start, in_frame, out_frame, link| Clip {
8044+ fade_in: 0,
8045+ fade_out: 0,
77558046 start,
77568047 in_frame,
77578048 out_frame,
@@ -8529,6 +8820,8 @@ mod tests {
85298820 fn a_group_may_span_any_lane() {
85308821 let lane = |kind, clips: Vec<Clip>| LaneData::new(kind, clips);
85318822 let one = |start: u32, end: u32, link| Clip {
8823+ fade_in: 0,
8824+ fade_out: 0,
85328825 start,
85338826 in_frame: start,
85348827 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
487487 // what makes the proxy picture-only: the export walk codes the lanes it is
488488 // given and there is no sound among them.
489489 let clip = Clip {
490+ fade_in: 0,
491+ fade_out: 0,
490492 start: 0,
491493 in_frame: 0,
492494 out_frame: meta.frame_count.max(1),
crates/engine/src/silence.rsmodified+2 -0
@@ -295,6 +295,8 @@ mod tests {
295295
296296 fn clip(start: u32, in_frame: u32, out_frame: u32, speed: Speed) -> Clip {
297297 Clip {
298+ fade_in: 0,
299+ fade_out: 0,
298300 start,
299301 in_frame,
300302 out_frame,
crates/engine/src/sweep.rsmodified+2 -0
@@ -66,6 +66,8 @@ fn track() -> SubtitleTrack {
6666
6767 fn clip(start: u32, in_frame: u32, out_frame: u32) -> Clip {
6868 Clip {
69+ fade_in: 0,
70+ fade_out: 0,
6971 start,
7072 in_frame,
7173 out_frame,
crates/engine/tests/audio_export.rsmodified+18 -0
@@ -61,6 +61,8 @@ fn wait(handle: &ExportHandle, limit: Duration) -> engine::Result<()> {
6161 /// re-encodes today and once refused outright.
6262 fn mixed_project() -> Project {
6363 let clip = |start, source| Clip {
64+ fade_in: 0,
65+ fade_out: 0,
6466 start,
6567 in_frame: 0,
6668 out_frame: 30,
@@ -83,6 +85,8 @@ fn mixed_project() -> Project {
8385 (
8486 LaneKind::Video,
8587 vec![Clip {
88+ fade_in: 0,
89+ fade_out: 0,
8690 start: 0,
8791 in_frame: 0,
8892 out_frame: 90,
@@ -324,6 +328,8 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() {
324328 let song = asset("test_tone.mp3");
325329 let still = asset("test_still.png");
326330 let clip = |source, frames| Clip {
331+ fade_in: 0,
332+ fade_out: 0,
327333 start: 0,
328334 in_frame: 0,
329335 out_frame: frames,
@@ -388,6 +394,8 @@ fn a_still_and_a_song_export_as_an_mp4_with_sound() {
388394 #[test]
389395 fn a_fader_is_one_tracks_own_and_the_limiter_holds_the_sum() {
390396 let clip = Clip {
397+ fade_in: 0,
398+ fade_out: 0,
391399 start: 0,
392400 in_frame: 0,
393401 out_frame: 30,
@@ -621,6 +629,8 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
621629 (
622630 LaneKind::Video,
623631 vec![Clip {
632+ fade_in: 0,
633+ fade_out: 0,
624634 start: 0,
625635 in_frame: 0,
626636 out_frame: 60,
@@ -635,6 +645,8 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
635645 (
636646 LaneKind::Audio,
637647 vec![Clip {
648+ fade_in: 0,
649+ fade_out: 0,
638650 start: 0,
639651 in_frame: 0,
640652 out_frame: 60,
@@ -689,6 +701,8 @@ fn the_sound_is_written_at_the_rate_that_was_asked_for() {
689701 #[test]
690702 fn a_silent_clip_exports_as_silence_over_its_own_span() {
691703 let clip = |start, source| Clip {
704+ fade_in: 0,
705+ fade_out: 0,
692706 start,
693707 in_frame: 0,
694708 out_frame: 30,
@@ -779,6 +793,8 @@ fn a_51_ac3_source_round_trips_through_a_wav() {
779793 vec![(
780794 LaneKind::Audio,
781795 vec![Clip {
796+ fade_in: 0,
797+ fade_out: 0,
782798 start: 0,
783799 in_frame: 0,
784800 out_frame: 30,
@@ -904,6 +920,8 @@ fn a_mono_timeline_exports_as_dual_mono_ogg() {
904920 vec![(
905921 LaneKind::Audio,
906922 vec![Clip {
923+ fade_in: 0,
924+ fade_out: 0,
907925 start: 0,
908926 in_frame: 0,
909927 out_frame: 30,
crates/engine/tests/audio_files.rsmodified+2 -0
@@ -491,6 +491,8 @@ fn a_song_survives_a_save_and_a_reload() {
491491 Lane::A1,
492492 1.0,
493493 Clip {
494+ fade_in: 0,
495+ fade_out: 0,
494496 in_frame: 0,
495497 out_frame: 30,
496498 ..song
crates/engine/tests/eq_audio.rsmodified+2 -0
@@ -54,6 +54,8 @@ fn boost() -> EqParams {
5454
5555 fn clip(start: u32, source: usize, frames: u32) -> Clip {
5656 Clip {
57+ fade_in: 0,
58+ fade_out: 0,
5759 start,
5860 in_frame: 0,
5961 out_frame: frames,
crates/engine/tests/export.rsmodified+4 -0
@@ -234,6 +234,8 @@ fn exports_an_edited_timeline_in_hardware() {
234234 fn exports_at_the_project_resolution_with_the_watched_geometry() {
235235 let _seat = pin_software();
236236 let clip = |source: usize, start: u32| engine::Clip {
237+ fade_in: 0,
238+ fade_out: 0,
237239 start,
238240 in_frame: 0,
239241 out_frame: 10,
@@ -316,6 +318,8 @@ fn exports_the_audio_stream_the_timeline_plays() {
316318 let multi = asset("test_multiaudio.mp4");
317319 let (meta, _) = engine::demux::Demuxer::open(&multi).expect("open the fixture");
318320 let whole = engine::Clip {
321+ fade_in: 0,
322+ fade_out: 0,
319323 start: 0,
320324 in_frame: 0,
321325 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() {
235235 pin_software();
236236 let source = asset("test_av.mp4");
237237 let clip = Clip {
238+ fade_in: 0,
239+ fade_out: 0,
238240 start: 0,
239241 in_frame: 0,
240242 out_frame: TOTAL,
@@ -296,6 +298,8 @@ fn two_audio_lanes_are_summed() {
296298 let one_lane = Project::single(asset("test_av.mp4"), TOTAL);
297299 let mut project = one_lane.clone();
298300 let doubled = Clip {
301+ fade_in: 0,
302+ fade_out: 0,
299303 start: TOP_IN,
300304 in_frame: TOP_IN,
301305 out_frame: TOP_OUT,
@@ -553,6 +557,8 @@ fn a_paste_never_touches_the_captions() {
553557
554558 let clip = *project.lane(Lane::V1).first().expect("V1 holds the film");
555559 let pasted = Clip {
560+ fade_in: 0,
561+ fade_out: 0,
556562 out_frame: 30,
557563 ..clip
558564 };
crates/engine/tests/opus_export.rsmodified+4 -0
@@ -80,6 +80,8 @@ fn wait(handle: &ExportHandle, limit: Duration) -> engine::Result<()> {
8080 /// `sound_in` seconds into that file: an edit, so nothing here can be a copy.
8181 fn project(video: &Path, sound: &Path, sound_in: u32) -> Project {
8282 let clip = |source, in_frame, out_frame| Clip {
83+ fade_in: 0,
84+ fade_out: 0,
8385 start: 0,
8486 in_frame,
8587 out_frame,
@@ -420,6 +422,8 @@ fn a_copied_picture_names_the_sound_it_was_written_with() {
420422 let (meta, _) = engine::demux::Demuxer::open(&video).expect("probe the picture");
421423 let frames = meta.frame_count;
422424 let clip = |source, out_frame| Clip {
425+ fade_in: 0,
426+ fade_out: 0,
423427 start: 0,
424428 in_frame: 0,
425429 out_frame,
crates/engine/tests/silence.rsmodified+4 -0
@@ -138,6 +138,8 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() {
138138 let lane = p.add_lane(LaneKind::Video);
139139 assert_eq!(lane.label(), "V2");
140140 let broll = Clip {
141+ fade_in: 0,
142+ fade_out: 0,
141143 start: 0,
142144 in_frame: 0,
143145 out_frame: 20,
@@ -173,6 +175,8 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() {
173175 /// A clip covering the whole fixture, for a second track to carry.
174176 fn whole(source: usize, frames: u32) -> Clip {
175177 Clip {
178+ fade_in: 0,
179+ fade_out: 0,
176180 start: 0,
177181 in_frame: 0,
178182 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() {
516516 Lane::V1,
517517 fast,
518518 Clip {
519+ fade_in: 0,
520+ fade_out: 0,
519521 speed: Speed::NORMAL,
520522 ..whole
521523 }