Per-clip audio fades, adjacency crossfade, and edith 18
Browse files at this commit6d0747c73d4ee59a4c6e885e2930fcc8d7ff51ddParent: 8f0c500- feat
- per-clip audio fades, adjacency crossfade, and edith 18
21 changed files +645 -69
- crates/app/src/tests/editing.rs +10 -0
- crates/app/src/tests/layout.rs +2 -0
- crates/app/src/tests/view.rs +2 -0
- crates/app/src/timeline_math.rs +6 -0
- crates/engine/examples/bench.rs +2 -0
- crates/engine/src/audio.rs +109 -4
- crates/engine/src/edith.rs +147 -56
- crates/engine/src/export.rs +8 -2
- crates/engine/src/playback.rs +12 -1
- crates/engine/src/project.rs +299 -6
- crates/engine/src/proxy.rs +2 -0
- crates/engine/src/silence.rs +2 -0
- crates/engine/src/sweep.rs +2 -0
- crates/engine/tests/audio_export.rs +18 -0
- crates/engine/tests/audio_files.rs +2 -0
- crates/engine/tests/eq_audio.rs +2 -0
- crates/engine/tests/export.rs +4 -0
- crates/engine/tests/lanes.rs +6 -0
- crates/engine/tests/opus_export.rs +4 -0
- crates/engine/tests/silence.rs +4 -0
- crates/engine/tests/speed.rs +2 -0
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 | ..clip | 663 | ..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 | ..clip | 689 | ..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 | ..clip | 311 | ..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 | ..clip | 318 | ..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 | ..clip | 327 | ..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 save | 413 | // 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 the | 744 | /// [`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 silent | 803 | // 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, and | 2893 | /// 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` and | 3045 | // 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.mp4 | 16 | //! subtitle 3 test_av.mp4 |
| 17 | //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk | 17 | //! eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk |
| 18 | //! color 0.1:1.2:0.9:-0.3 | 18 | //! color 0.1:1.2:0.9:-0.3 |
| 19 | -//! video 1 0 0 120 0 0 0 0 fit 1000 | 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 | 20 | +//! audio 1 0 0 120 0 0 0 - fit 1000 30 30 |
| 21 | -//! video 2 120 0 120 1 - - - fill 2000 | 21 | +//! video 2 120 0 120 1 - - - fill 2000 0 0 |
| 22 | //! audio 2 | 22 | //! audio 2 |
| 23 | //! sub 1 0 60 0 500000 1500000 | 23 | //! sub 1 0 60 0 500000 1500000 |
| 24 | //! sub 2 | 24 | //! 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 number | 113 | +//! <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 header | 114 | //! 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-open | 115 | //! 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 it | 116 | //! 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 clip | 120 | //! 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 | ||
| 122 | //! explicit, so a *gap* is simply a stretch no line covers -- there is nothing | 125 | //! 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 is | 127 | //! 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 source | 146 | //! 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 project | 151 | //! **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 no | 153 | //! **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 one | 185 | //! 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 shown | 186 | //! 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 it | 187 | //! 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 |
| 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 is | 191 | //! 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 module | 222 | /// 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. Reading | 606 | // 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 and | 1096 | + // 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.playhead | 2337 | 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.playhead | 2406 | 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 was | 2463 | /// 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 the | 2464 | /// 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, and | 2465 | /// 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.playhead | 2533 | 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 the | 2781 | // 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 the | 2897 | // Loading rejoins the *given* directory, so the file is reached by the |
| 2807 | // way the project was opened -- the same file, through the link, still | 2898 | // 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
| @@ -1671,16 +1671,18 @@ fn encode_audio( | |||
| 1671 | let segs = project.audio_segments_from(0, meta.frame_rate); | 1671 | let segs = project.audio_segments_from(0, meta.frame_rate); |
| 1672 | let eqs = project.audio_eqs_from(0, meta.frame_rate); | 1672 | let eqs = project.audio_eqs_from(0, meta.frame_rate); |
| 1673 | let speeds = project.audio_speeds_from(0, meta.frame_rate); | 1673 | let speeds = project.audio_speeds_from(0, meta.frame_rate); |
| 1674 | + let fades = project.audio_fades_from(0, meta.frame_rate); | ||
| 1674 | // Coarse stage timers, in the same voice as `export video: copy` below: an | 1675 | // Coarse stage timers, in the same voice as `export video: copy` below: an |
| 1675 | // export of a feature film spends minutes in here before a byte of picture | 1676 | // export of a feature film spends minutes in here before a byte of picture |
| 1676 | // is written, and which minutes went where is the first question asked of a | 1677 | // is written, and which minutes went where is the first question asked of a |
| 1677 | // slow export. Three lines an export, so they stay on. | 1678 | // slow export. Three lines an export, so they stay on. |
| 1678 | let mixed = std::time::Instant::now(); | 1679 | let mixed = std::time::Instant::now(); |
| 1679 | - let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at( | 1680 | + let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at_fade( |
| 1680 | &sources, | 1681 | &sources, |
| 1681 | &segs, | 1682 | &segs, |
| 1682 | &eqs, | 1683 | &eqs, |
| 1683 | &speeds, | 1684 | &speeds, |
| 1685 | + &fades, | ||
| 1684 | &project.audio_gains(), | 1686 | &project.audio_gains(), |
| 1685 | project.limiter(), | 1687 | project.limiter(), |
| 1686 | sample_rate, | 1688 | sample_rate, |
| @@ -2765,15 +2767,19 @@ fn run_audio( | |||
| 2765 | // 2x is half as long and holds the samples that were heard -- not a | 2767 | // 2x is half as long and holds the samples that were heard -- not a |
| 2766 | // second pass here that could disagree with what the ear got. | 2768 | // second pass here that could disagree with what the ear got. |
| 2767 | let speeds = project.audio_speeds_from(0, meta.frame_rate); | 2769 | let speeds = project.audio_speeds_from(0, meta.frame_rate); |
| 2770 | + // ...and the fades with them, the same choke-point reason again: a clip's | ||
| 2771 | + // envelope runs inside the worker playback feeds from too. | ||
| 2772 | + let fades = project.audio_fades_from(0, meta.frame_rate); | ||
| 2768 | // ...and the mix over both: each lane's volume into the sum, the master | 2773 | // ...and the mix over both: each lane's volume into the sum, the master |
| 2769 | // limiter out of it. The same opener playback's feeder reads from, so a | 2774 | // limiter out of it. The same opener playback's feeder reads from, so a |
| 2770 | // file is written at the levels it was heard at -- there is no second | 2775 | // file is written at the levels it was heard at -- there is no second |
| 2771 | // place here that could mix it differently. | 2776 | // place here that could mix it differently. |
| 2772 | - let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at( | 2777 | + let Some((audio, chunks)) = AudioSession::open_mixed_streams_master_at_fade( |
| 2773 | &sources, | 2778 | &sources, |
| 2774 | &segs, | 2779 | &segs, |
| 2775 | &eqs, | 2780 | &eqs, |
| 2776 | &speeds, | 2781 | &speeds, |
| 2782 | + &fades, | ||
| 2777 | &project.audio_gains(), | 2783 | &project.audio_gains(), |
| 2778 | project.limiter(), | 2784 | project.limiter(), |
| 2779 | sample_rate, | 2785 | 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 to | 618 | // *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 { |
| @@ -3248,6 +3254,10 @@ impl PlaybackSession { | |||
| 3248 | // speeded, which is the path that decodes the same samples it always | 3254 | // speeded, which is the path that decodes the same samples it always |
| 3249 | // did. | 3255 | // did. |
| 3250 | let speeds = self.project.audio_speeds_from(target, fps); | 3256 | let speeds = self.project.audio_speeds_from(target, fps); |
| 3257 | + // ...and the fades, the same way again: a clip's own envelope runs | ||
| 3258 | + // inside its worker, after the rate and the equalizer, so a fade | ||
| 3259 | + // edit is audible at once exactly as an EQ edit is. | ||
| 3260 | + let fades = self.project.audio_fades_from(target, fps); | ||
| 3251 | // Each source on the stream it was placed with: what plays is what | 3261 | // Each source on the stream it was placed with: what plays is what |
| 3252 | // the library row said, and what an export copies (`export::run`). | 3262 | // the library row said, and what an export copies (`export::run`). |
| 3253 | let sources = self.project.audio_sources(); | 3263 | let sources = self.project.audio_sources(); |
| @@ -3277,11 +3287,12 @@ impl PlaybackSession { | |||
| 3277 | // one `pread` on a cold 25 GB film is seconds, and this is called | 3287 | // one `pread` on a cold 25 GB film is seconds, and this is called |
| 3278 | // from a ruler drag ([`Audio::spawn_feeder_deferred`]). | 3288 | // from a ruler drag ([`Audio::spawn_feeder_deferred`]). |
| 3279 | audio_running = audio.spawn_feeder_deferred(move || { | 3289 | audio_running = audio.spawn_feeder_deferred(move || { |
| 3280 | - match AudioSession::open_mixed_streams_live( | 3290 | + match AudioSession::open_mixed_streams_live_fade( |
| 3281 | &sources, | 3291 | &sources, |
| 3282 | &segs, | 3292 | &segs, |
| 3283 | &eqs, | 3293 | &eqs, |
| 3284 | &speeds, | 3294 | &speeds, |
| 3295 | + &fades, | ||
| 3285 | &gains, | 3296 | &gains, |
| 3286 | limiter, | 3297 | limiter, |
| 3287 | Some(&worker_controls), | 3298 | 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 over | 430 | /// 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 in | 816 | /// 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 clips | 817 | /// 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, |
| @@ -810,6 +875,8 @@ impl Project { | |||
| 810 | /// is clamped to one frame. | 875 | /// is clamped to one frame. |
| 811 | pub fn single(path: impl AsRef<Path>, frame_count: u32) -> Self { | 876 | pub fn single(path: impl AsRef<Path>, frame_count: u32) -> Self { |
| 812 | let clip = Clip { | 877 | let clip = Clip { |
| 878 | + fade_in: 0, | ||
| 879 | + fade_out: 0, | ||
| 813 | start: 0, | 880 | start: 0, |
| 814 | in_frame: 0, | 881 | in_frame: 0, |
| 815 | out_frame: frame_count.max(1), | 882 | out_frame: frame_count.max(1), |
| @@ -1188,6 +1255,8 @@ impl Project { | |||
| 1188 | self.snapshot(); | 1255 | self.snapshot(); |
| 1189 | let start = self.timeline_frames(); | 1256 | let start = self.timeline_frames(); |
| 1190 | let clip = Clip { | 1257 | let clip = Clip { |
| 1258 | + fade_in: 0, | ||
| 1259 | + fade_out: 0, | ||
| 1191 | start, | 1260 | start, |
| 1192 | in_frame: 0, | 1261 | in_frame: 0, |
| 1193 | out_frame: frame_count.max(1), | 1262 | out_frame: frame_count.max(1), |
| @@ -2396,6 +2465,76 @@ impl Project { | |||
| 2396 | true | 2465 | true |
| 2397 | } | 2466 | } |
| 2398 | 2467 | ||
| 2468 | + /// Timeline frames of ramp-up from silence at the start of the clip at | ||
| 2469 | + /// `idx` of `lane`. `0` for an index that is not there, same as a clip | ||
| 2470 | + /// that has none. | ||
| 2471 | + pub fn fade_in_of(&self, lane: Lane, idx: usize) -> u32 { | ||
| 2472 | + self.lane(lane).get(idx).map_or(0, |c| c.fade_in) | ||
| 2473 | + } | ||
| 2474 | + | ||
| 2475 | + /// Sets it, clamped to the clip's own length ([`Clip::frames`]) -- a fade | ||
| 2476 | + /// can shrink a clip's audible middle to nothing but never ask for more | ||
| 2477 | + /// ramp than the clip has frames. One undo step like [`Project::set_fit`], | ||
| 2478 | + /// and `false` (no history) for an index that is not there. | ||
| 2479 | + pub fn set_fade_in(&mut self, lane: Lane, idx: usize, frames: u32) -> bool { | ||
| 2480 | + if idx >= self.lane(lane).len() { | ||
| 2481 | + return false; | ||
| 2482 | + } | ||
| 2483 | + self.snapshot(); | ||
| 2484 | + let clip = &mut self.lane_mut(lane).expect("checked above")[idx]; | ||
| 2485 | + clip.fade_in = frames.min(clip.frames()); | ||
| 2486 | + true | ||
| 2487 | + } | ||
| 2488 | + | ||
| 2489 | + /// Timeline frames of ramp-down to silence at the end of the clip at | ||
| 2490 | + /// `idx` of `lane`. Same promise as [`Project::fade_in_of`]. | ||
| 2491 | + pub fn fade_out_of(&self, lane: Lane, idx: usize) -> u32 { | ||
| 2492 | + self.lane(lane).get(idx).map_or(0, |c| c.fade_out) | ||
| 2493 | + } | ||
| 2494 | + | ||
| 2495 | + /// Sets it. Same promises as [`Project::set_fade_in`]. | ||
| 2496 | + pub fn set_fade_out(&mut self, lane: Lane, idx: usize, frames: u32) -> bool { | ||
| 2497 | + if idx >= self.lane(lane).len() { | ||
| 2498 | + return false; | ||
| 2499 | + } | ||
| 2500 | + self.snapshot(); | ||
| 2501 | + let clip = &mut self.lane_mut(lane).expect("checked above")[idx]; | ||
| 2502 | + clip.fade_out = frames.min(clip.frames()); | ||
| 2503 | + true | ||
| 2504 | + } | ||
| 2505 | + | ||
| 2506 | + /// Crossfades the audio clip at `idx` of `lane` into the one immediately | ||
| 2507 | + /// after it, over `frames` timeline frames: sets `idx`'s | ||
| 2508 | + /// [`Clip::fade_out`] and its neighbour's [`Clip::fade_in`] to `frames`, | ||
| 2509 | + /// each clamped to its own clip's length. `false` -- no history -- unless | ||
| 2510 | + /// `lane` is audio, `idx + 1` is in bounds, and the two clips are | ||
| 2511 | + /// adjacent: the second's [`Clip::start`] is exactly the first's | ||
| 2512 | + /// [`Clip::end`], no gap between them. | ||
| 2513 | + /// | ||
| 2514 | + /// This is the whole mechanism, not a stand-in for one: a *real* | ||
| 2515 | + /// cross-fade -- both takes heard at once, blending -- is what two clips | ||
| 2516 | + /// **overlapping** on separate lanes already get for free from the | ||
| 2517 | + /// mixer's own per-lane sum ([`crate::audio::open_mixed_streams_master`]). | ||
| 2518 | + /// This call only shapes the edges of two clips already sitting | ||
| 2519 | + /// end-to-end on *one* lane, so the join between them fades like one did. | ||
| 2520 | + pub fn crossfade(&mut self, lane: Lane, idx: usize, frames: u32) -> bool { | ||
| 2521 | + if lane.kind != LaneKind::Audio { | ||
| 2522 | + return false; | ||
| 2523 | + } | ||
| 2524 | + let clips = self.lane(lane); | ||
| 2525 | + let (Some(a), Some(b)) = (clips.get(idx), clips.get(idx + 1)) else { | ||
| 2526 | + return false; | ||
| 2527 | + }; | ||
| 2528 | + if a.end() != b.start { | ||
| 2529 | + return false; | ||
| 2530 | + } | ||
| 2531 | + self.snapshot(); | ||
| 2532 | + let clips = self.lane_mut(lane).expect("checked above"); | ||
| 2533 | + clips[idx].fade_out = frames.min(clips[idx].frames()); | ||
| 2534 | + clips[idx + 1].fade_in = frames.min(clips[idx + 1].frames()); | ||
| 2535 | + true | ||
| 2536 | + } | ||
| 2537 | + | ||
| 2399 | /// Every frame number on every lane rewritten onto a timeline counted at | 2538 | /// Every frame number on every lane rewritten onto a timeline counted at |
| 2400 | /// another rate: `k` is old timeline frames per new one, `counts` is how | 2539 | /// another rate: `k` is old timeline frames per new one, `counts` is how |
| 2401 | /// long each source is on the *new* timeline (indexed as | 2540 | /// long each source is on the *new* timeline (indexed as |
| @@ -2804,8 +2943,18 @@ impl Project { | |||
| 2804 | tail.in_frame = split_source(&tail, timeline_frame).expect("splittable said so"); | 2943 | tail.in_frame = split_source(&tail, timeline_frame).expect("splittable said so"); |
| 2805 | tail.start = timeline_frame; | 2944 | tail.start = timeline_frame; |
| 2806 | tail.link = right_of(orig[data_i]); | 2945 | tail.link = right_of(orig[data_i]); |
| 2946 | + // A split makes a new edge for each half, and a fade is a promise | ||
| 2947 | + // about an edge: only the half that *kept* the original edge | ||
| 2948 | + // keeps that fade, re-clamped to its own now-shorter length (a | ||
| 2949 | + // cut inside the ramp shortens it, never leaves it pointing past | ||
| 2950 | + // the clip it is on); the edge the cut itself made starts, or | ||
| 2951 | + // ends, flat -- there was no silence there to ramp out of. | ||
| 2952 | + tail.fade_in = 0; | ||
| 2953 | + tail.fade_out = tail.fade_out.min(tail.frames()); | ||
| 2807 | data.clips[idx].out_frame = tail.in_frame; | 2954 | data.clips[idx].out_frame = tail.in_frame; |
| 2808 | data.clips[idx].link = orig[data_i]; | 2955 | data.clips[idx].link = orig[data_i]; |
| 2956 | + data.clips[idx].fade_out = 0; | ||
| 2957 | + data.clips[idx].fade_in = data.clips[idx].fade_in.min(data.clips[idx].frames()); | ||
| 2809 | data.clips.insert(idx + 1, tail); | 2958 | data.clips.insert(idx + 1, tail); |
| 2810 | } | 2959 | } |
| 2811 | true | 2960 | true |
| @@ -3137,6 +3286,8 @@ impl Project { | |||
| 3137 | } | 3286 | } |
| 3138 | self.snapshot(); | 3287 | self.snapshot(); |
| 3139 | let clip = Clip { | 3288 | let clip = Clip { |
| 3289 | + fade_in: 0, | ||
| 3290 | + fade_out: 0, | ||
| 3140 | start: timeline_frame, | 3291 | start: timeline_frame, |
| 3141 | link: None, | 3292 | link: None, |
| 3142 | ..clip | 3293 | ..clip |
| @@ -3176,6 +3327,8 @@ impl Project { | |||
| 3176 | self.lanes.push(LaneData::new(LaneKind::Audio, Vec::new())); | 3327 | self.lanes.push(LaneData::new(LaneKind::Audio, Vec::new())); |
| 3177 | } | 3328 | } |
| 3178 | let clip = Clip { | 3329 | let clip = Clip { |
| 3330 | + fade_in: 0, | ||
| 3331 | + fade_out: 0, | ||
| 3179 | start: timeline_frame, | 3332 | start: timeline_frame, |
| 3180 | link: Some(self.new_link()), | 3333 | link: Some(self.new_link()), |
| 3181 | ..clip | 3334 | ..clip |
| @@ -3751,6 +3904,8 @@ impl Project { | |||
| 3751 | } | 3904 | } |
| 3752 | self.snapshot(); | 3905 | self.snapshot(); |
| 3753 | let clip = Clip { | 3906 | let clip = Clip { |
| 3907 | + fade_in: 0, | ||
| 3908 | + fade_out: 0, | ||
| 3754 | start: at, | 3909 | start: at, |
| 3755 | link: Some(self.new_link()), | 3910 | link: Some(self.new_link()), |
| 3756 | ..clip | 3911 | ..clip |
| @@ -4416,6 +4571,42 @@ impl Project { | |||
| 4416 | .collect() | 4571 | .collect() |
| 4417 | } | 4572 | } |
| 4418 | 4573 | ||
| 4574 | + /// The fade envelope each of [`audio_segments_from`](Project::audio_segments_from)'s | ||
| 4575 | + /// segments plays through: the same lanes in the same order, one entry per | ||
| 4576 | + /// segment, `None` where the segment is a gap or its clip has neither a | ||
| 4577 | + /// [`Clip::fade_in`] nor a [`Clip::fade_out`]. Parallel list for | ||
| 4578 | + /// [`audio_eqs_from`](Project::audio_eqs_from)'s reason. | ||
| 4579 | + pub fn audio_fades_from(&self, timeline_frame: u32, fps: f64) -> Vec<Vec<Option<Fade>>> { | ||
| 4580 | + self.audio_lanes() | ||
| 4581 | + .into_iter() | ||
| 4582 | + .map(|lane| self.lane_fades_from(lane, timeline_frame, fps)) | ||
| 4583 | + .collect() | ||
| 4584 | + } | ||
| 4585 | + | ||
| 4586 | + /// [`audio_fades_from`](Project::audio_fades_from) for one lane, matching | ||
| 4587 | + /// [`lane_segments_from`](Project::lane_segments_from) entry for entry. | ||
| 4588 | + pub fn lane_fades_from(&self, lane: Lane, timeline_frame: u32, fps: f64) -> Vec<Option<Fade>> { | ||
| 4589 | + if !(fps.is_finite() && fps > 0.0) { | ||
| 4590 | + return Vec::new(); | ||
| 4591 | + } | ||
| 4592 | + self.spans_from(lane, timeline_frame) | ||
| 4593 | + .iter() | ||
| 4594 | + .map(|span| { | ||
| 4595 | + let (idx, _) = self.map(lane, span.start)?; | ||
| 4596 | + let clip = self.lane(lane).get(idx)?; | ||
| 4597 | + (clip.fade_in > 0 || clip.fade_out > 0).then(|| Fade { | ||
| 4598 | + // `span.len` is the clip's own remaining frames from | ||
| 4599 | + // `span.start` on -- shorter than `clip.frames()` only | ||
| 4600 | + // when this is the first span of a seek mid-clip. | ||
| 4601 | + elapsed: clip.frames().saturating_sub(span.len), | ||
| 4602 | + fade_in: clip.fade_in, | ||
| 4603 | + fade_out: clip.fade_out, | ||
| 4604 | + total: clip.frames(), | ||
| 4605 | + }) | ||
| 4606 | + }) | ||
| 4607 | + .collect() | ||
| 4608 | + } | ||
| 4609 | + | ||
| 4419 | /// Pushes the undo snapshot. Every mutating method calls this once, *after* | 4610 | /// Pushes the undo snapshot. Every mutating method calls this once, *after* |
| 4420 | /// it has decided it will succeed -- a refusal must not cost an undo step. | 4611 | /// it has decided it will succeed -- a refusal must not cost an undo step. |
| 4421 | fn snapshot(&mut self) { | 4612 | fn snapshot(&mut self) { |
| @@ -4761,6 +4952,8 @@ fn clear(clips: &mut Vec<Clip>, start: u32, end: u32) { | |||
| 4761 | && c.start < start | 4952 | && c.start < start |
| 4762 | { | 4953 | { |
| 4763 | out.push(Clip { | 4954 | out.push(Clip { |
| 4955 | + fade_in: 0, | ||
| 4956 | + fade_out: 0, | ||
| 4764 | out_frame: c.in_frame + keep.min(c.len()), | 4957 | out_frame: c.in_frame + keep.min(c.len()), |
| 4765 | link: None, | 4958 | link: None, |
| 4766 | ..c | 4959 | ..c |
| @@ -4774,6 +4967,8 @@ fn clear(clips: &mut Vec<Clip>, start: u32, end: u32) { | |||
| 4774 | && c.end() > end | 4967 | && c.end() > end |
| 4775 | { | 4968 | { |
| 4776 | out.push(Clip { | 4969 | out.push(Clip { |
| 4970 | + fade_in: 0, | ||
| 4971 | + fade_out: 0, | ||
| 4777 | start: end, | 4972 | start: end, |
| 4778 | in_frame: c.out_frame - keep.min(c.len()), | 4973 | in_frame: c.out_frame - keep.min(c.len()), |
| 4779 | link: None, | 4974 | link: None, |
| @@ -4880,6 +5075,8 @@ mod tests { | |||
| 4880 | /// A contiguous placement, group id ignored: what most assertions compare. | 5075 | /// A contiguous placement, group id ignored: what most assertions compare. |
| 4881 | fn clip(start: u32, in_frame: u32, out_frame: u32, source: usize) -> Clip { | 5076 | fn clip(start: u32, in_frame: u32, out_frame: u32, source: usize) -> Clip { |
| 4882 | Clip { | 5077 | Clip { |
| 5078 | + fade_in: 0, | ||
| 5079 | + fade_out: 0, | ||
| 4883 | start, | 5080 | start, |
| 4884 | in_frame, | 5081 | in_frame, |
| 4885 | out_frame, | 5082 | out_frame, |
| @@ -5008,6 +5205,89 @@ mod tests { | |||
| 5008 | ); | 5205 | ); |
| 5009 | } | 5206 | } |
| 5010 | 5207 | ||
| 5208 | + /// [`Fade::gain_at`]'s curve at the edges and in the middle: silence at | ||
| 5209 | + /// the very first frame of a fade-in, unity at its last, equal-power | ||
| 5210 | + /// (`sin(pi/4)`) at its midpoint, and unity anywhere neither ramp reaches | ||
| 5211 | + /// at all. | ||
| 5212 | + #[test] | ||
| 5213 | + fn gain_at_is_silent_at_a_fades_edge_and_unity_in_the_body() { | ||
| 5214 | + let f = Fade { | ||
| 5215 | + elapsed: 0, | ||
| 5216 | + fade_in: 10, | ||
| 5217 | + fade_out: 10, | ||
| 5218 | + total: 40, | ||
| 5219 | + }; | ||
| 5220 | + assert_eq!(f.gain_at(0), 0.0, "silence at the very first frame"); | ||
| 5221 | + assert_eq!(f.gain_at(10), 1.0, "unity the frame the ramp ends"); | ||
| 5222 | + let midpoint = std::f32::consts::FRAC_PI_2 * 0.5; | ||
| 5223 | + assert!( | ||
| 5224 | + (f.gain_at(5) - midpoint.sin()).abs() < 1e-6, | ||
| 5225 | + "equal-power midpoint is sin(pi/4)" | ||
| 5226 | + ); | ||
| 5227 | + assert_eq!(f.gain_at(20), 1.0, "unchanged in the body, past either ramp"); | ||
| 5228 | + // The fade-out is the same curve, mirrored, counting down from the | ||
| 5229 | + // clip's end: unity at the frame the ramp starts, the same | ||
| 5230 | + // equal-power midpoint, and -- since `total` itself is one past the | ||
| 5231 | + // clip's last valid frame -- the very last frame is one step short of | ||
| 5232 | + // the silence a fade-in's own frame `0` lands on exactly. | ||
| 5233 | + assert_eq!(f.gain_at(30), 1.0, "unity the frame the fade-out starts"); | ||
| 5234 | + assert!( | ||
| 5235 | + (f.gain_at(35) - midpoint.sin()).abs() < 1e-6, | ||
| 5236 | + "the fade-out's own equal-power midpoint" | ||
| 5237 | + ); | ||
| 5238 | + assert!( | ||
| 5239 | + (f.gain_at(39) - (std::f32::consts::FRAC_PI_2 * 0.1).sin()).abs() < 1e-6, | ||
| 5240 | + "one step short of silence at the clip's last playable frame" | ||
| 5241 | + ); | ||
| 5242 | + } | ||
| 5243 | + | ||
| 5244 | + /// [`Project::crossfade`] refuses a non-audio lane and two clips that are | ||
| 5245 | + /// not adjacent, and otherwise sets the shared edge's fades and nothing | ||
| 5246 | + /// else. | ||
| 5247 | + #[test] | ||
| 5248 | + fn crossfade_only_joins_adjacent_audio_clips() { | ||
| 5249 | + let mut p = Project::single(FILE, 20); | ||
| 5250 | + assert!(p.split(10)); | ||
| 5251 | + assert!( | ||
| 5252 | + !p.crossfade(Lane::V1, 0, 5), | ||
| 5253 | + "video is not an audio lane" | ||
| 5254 | + ); | ||
| 5255 | + assert!( | ||
| 5256 | + !p.crossfade(Lane::A1, 1, 5), | ||
| 5257 | + "there is no clip after idx 1" | ||
| 5258 | + ); | ||
| 5259 | + assert!(p.crossfade(Lane::A1, 0, 5), "the two halves are adjacent"); | ||
| 5260 | + let a = p.lane(Lane::A1); | ||
| 5261 | + assert_eq!(a[0].fade_out, 5); | ||
| 5262 | + assert_eq!(a[1].fade_in, 5); | ||
| 5263 | + assert_eq!(a[0].fade_in, 0); | ||
| 5264 | + assert_eq!(a[1].fade_out, 0); | ||
| 5265 | + | ||
| 5266 | + // A gap between two clips is not adjacency, even on an audio lane. | ||
| 5267 | + let mut p2 = Project::single(FILE, 1); | ||
| 5268 | + let a2 = p2.add_lane(LaneKind::Audio); | ||
| 5269 | + assert!(p2.place(a2, 0, clip(0, 0, 3, 0))); | ||
| 5270 | + assert!(p2.place(a2, 5, clip(5, 3, 6, 0)), "a gap before this one"); | ||
| 5271 | + assert!(!p2.crossfade(a2, 0, 5), "a gap is not adjacent"); | ||
| 5272 | + } | ||
| 5273 | + | ||
| 5274 | + /// The rule [`Project::write_split`] follows for the edge the razor makes: | ||
| 5275 | + /// the left half keeps its old [`Clip::fade_in`] (clamped to its new, | ||
| 5276 | + /// shorter length) and loses its [`Clip::fade_out`]; the right half is the | ||
| 5277 | + /// mirror image. | ||
| 5278 | + #[test] | ||
| 5279 | + fn a_split_clamps_the_kept_fade_and_zeroes_the_cut_edge() { | ||
| 5280 | + let mut p = Project::single(FILE, 20); | ||
| 5281 | + assert!(p.set_fade_in(Lane::V1, 0, 15)); | ||
| 5282 | + assert!(p.set_fade_out(Lane::V1, 0, 15)); | ||
| 5283 | + assert!(p.split(5)); | ||
| 5284 | + let v = p.lane(Lane::V1); | ||
| 5285 | + assert_eq!(v[0].fade_in, 5, "the left half's kept fade-in, clamped to 5 frames"); | ||
| 5286 | + assert_eq!(v[0].fade_out, 0, "the cut edge it made starts flat"); | ||
| 5287 | + assert_eq!(v[1].fade_in, 0, "the cut edge it made starts flat"); | ||
| 5288 | + assert_eq!(v[1].fade_out, 15, "the right half's kept fade-out, unclamped: 15 frames fit in 15"); | ||
| 5289 | + } | ||
| 5290 | + | ||
| 5011 | /// The music video's own path: the take comes apart into halves that carry | 5291 | /// The music video's own path: the take comes apart into halves that carry |
| 5012 | /// ids of their own, one undo puts it back, and two clips over the same | 5292 | /// ids of their own, one undo puts it back, and two clips over the same |
| 5013 | /// frames become one take again by hand. | 5293 | /// frames become one take again by hand. |
| @@ -6188,14 +6468,15 @@ mod tests { | |||
| 6188 | /// table like the eq and the grade: there is nothing for a table to share. | 6468 | /// table like the eq and the grade: there is nothing for a table to share. |
| 6189 | /// It costs the clip nothing at all -- the fields before it (a `usize` | 6469 | /// It costs the clip nothing at all -- the fields before it (a `usize` |
| 6190 | /// source and two `Option<u16>`s) already left the struct padded to 40 | 6470 | /// source and two `Option<u16>`s) already left the struct padded to 40 |
| 6191 | - /// bytes, and the byte landed in that padding. This is the assert that says | 6471 | + /// bytes, and the byte landed in that padding. `fade_in`/`fade_out` are the |
| 6192 | - /// so: a clip that grew a word grew every undo snapshot and every clipboard | 6472 | + /// two `u32`s after it, so those cost the clip a full word each: 48 bytes |
| 6193 | - /// copy with it. | 6473 | + /// total. This is the assert that says so: a clip that grows a word grows |
| 6474 | + /// every undo snapshot and every clipboard copy with it. | ||
| 6194 | #[test] | 6475 | #[test] |
| 6195 | fn a_fit_policy_costs_the_clip_no_word() { | 6476 | fn a_fit_policy_costs_the_clip_no_word() { |
| 6196 | assert_eq!( | 6477 | assert_eq!( |
| 6197 | std::mem::size_of::<Clip>(), | 6478 | std::mem::size_of::<Clip>(), |
| 6198 | - 40, | 6479 | + 48, |
| 6199 | "Clip changed size: {} bytes", | 6480 | "Clip changed size: {} bytes", |
| 6200 | std::mem::size_of::<Clip>() | 6481 | std::mem::size_of::<Clip>() |
| 6201 | ); | 6482 | ); |
| @@ -6204,6 +6485,8 @@ mod tests { | |||
| 6204 | /// The clip a copy would hand back: source `[100, 102)`, unrelated to | 6485 | /// The clip a copy would hand back: source `[100, 102)`, unrelated to |
| 6205 | /// anything in `three()` so it is recognisable wherever it lands. | 6486 | /// anything in `three()` so it is recognisable wherever it lands. |
| 6206 | const PASTED: Clip = Clip { | 6487 | const PASTED: Clip = Clip { |
| 6488 | + fade_in: 0, | ||
| 6489 | + fade_out: 0, | ||
| 6207 | start: 0, | 6490 | start: 0, |
| 6208 | in_frame: 100, | 6491 | in_frame: 100, |
| 6209 | out_frame: 102, | 6492 | out_frame: 102, |
| @@ -6276,6 +6559,8 @@ mod tests { | |||
| 6276 | let mut p = three(); | 6559 | let mut p = three(); |
| 6277 | let wav = p.import("/nonexistent/song.wav", 0); | 6560 | let wav = p.import("/nonexistent/song.wav", 0); |
| 6278 | let copied = Clip { | 6561 | let copied = Clip { |
| 6562 | + fade_in: 0, | ||
| 6563 | + fade_out: 0, | ||
| 6279 | source: wav, | 6564 | source: wav, |
| 6280 | ..PASTED | 6565 | ..PASTED |
| 6281 | }; | 6566 | }; |
| @@ -7514,8 +7799,8 @@ mod tests { | |||
| 7514 | fn a_clip_is_still_a_small_copy() { | 7799 | fn a_clip_is_still_a_small_copy() { |
| 7515 | assert_eq!( | 7800 | assert_eq!( |
| 7516 | std::mem::size_of::<Clip>(), | 7801 | std::mem::size_of::<Clip>(), |
| 7517 | - 40, | 7802 | + 48, |
| 7518 | - "Clip changed size -- 32 before the colour index, 40 after" | 7803 | + "Clip changed size -- 32 before the colour index, 40 before the fades, 48 after" |
| 7519 | ); | 7804 | ); |
| 7520 | } | 7805 | } |
| 7521 | 7806 | ||
| @@ -7597,6 +7882,8 @@ mod tests { | |||
| 7597 | // format could not have written, are refused at this door too. | 7882 | // format could not have written, are refused at this door too. |
| 7598 | let eqd = |i: u16| { | 7883 | let eqd = |i: u16| { |
| 7599 | vec![Clip { | 7884 | vec![Clip { |
| 7885 | + fade_in: 0, | ||
| 7886 | + fade_out: 0, | ||
| 7600 | eq: Some(i), | 7887 | eq: Some(i), |
| 7601 | ..video[0] | 7888 | ..video[0] |
| 7602 | }] | 7889 | }] |
| @@ -7633,6 +7920,8 @@ mod tests { | |||
| 7633 | // The same two refusals for a colour, at the same door. | 7920 | // The same two refusals for a colour, at the same door. |
| 7634 | let graded = |i: u16| { | 7921 | let graded = |i: u16| { |
| 7635 | vec![Clip { | 7922 | vec![Clip { |
| 7923 | + fade_in: 0, | ||
| 7924 | + fade_out: 0, | ||
| 7636 | color: Some(i), | 7925 | color: Some(i), |
| 7637 | fit: FitPolicy::default(), | 7926 | fit: FitPolicy::default(), |
| 7638 | speed: Speed::NORMAL, | 7927 | speed: Speed::NORMAL, |
| @@ -7691,6 +7980,8 @@ mod tests { | |||
| 7691 | fn a_link_id_is_never_two_clips_of_one_lane() { | 7980 | fn a_link_id_is_never_two_clips_of_one_lane() { |
| 7692 | let sources = vec![Source::new(FILE, 0)]; | 7981 | let sources = vec![Source::new(FILE, 0)]; |
| 7693 | let linked = |start, in_frame, out_frame, link| Clip { | 7982 | let linked = |start, in_frame, out_frame, link| Clip { |
| 7983 | + fade_in: 0, | ||
| 7984 | + fade_out: 0, | ||
| 7694 | start, | 7985 | start, |
| 7695 | in_frame, | 7986 | in_frame, |
| 7696 | out_frame, | 7987 | out_frame, |
| @@ -8468,6 +8759,8 @@ mod tests { | |||
| 8468 | fn a_group_may_span_any_lane() { | 8759 | fn a_group_may_span_any_lane() { |
| 8469 | let lane = |kind, clips: Vec<Clip>| LaneData::new(kind, clips); | 8760 | let lane = |kind, clips: Vec<Clip>| LaneData::new(kind, clips); |
| 8470 | let one = |start: u32, end: u32, link| Clip { | 8761 | let one = |start: u32, end: u32, link| Clip { |
| 8762 | + fade_in: 0, | ||
| 8763 | + fade_out: 0, | ||
| 8471 | start, | 8764 | start, |
| 8472 | in_frame: start, | 8765 | in_frame: start, |
| 8473 | out_frame: end, | 8766 | 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 is | 487 | // 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 | ..song | 498 | ..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 | ..clip | 563 | ..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 | ..whole | 522 | ..whole |
| 521 | } | 523 | } |