forge
Explore
Log in

Don't you dare go Hollow

Audio_export builds against the v4 from_parts lane list

Browse files at this commit

563175c128a335c382b10fee279527a718a3a0a7Ahmet Kaan GümüşParent: f1ceaf3
  • fix
    • audio_export builds against the v4 from_parts lane list
Show full message
🐛 fix(test): audio_export builds against the v4 from_parts lane list
crates/app/src/main.rsmodified+7 -6
@@ -16,8 +16,8 @@ use engine::{Clip, ExportHandle, Frame, PlaybackSession};
16 use gpui::{16 use gpui::{
17 AnyElement, App, Application, Bounds, ClickEvent, Context, Div, FocusHandle, KeyDownEvent,17 AnyElement, App, Application, Bounds, ClickEvent, Context, Div, FocusHandle, KeyDownEvent,
18 MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point,18 MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point,
19- RenderImage, SharedString, Size, Stateful, TitlebarOptions, Window, WindowBounds, WindowOptions,19+ RenderImage, SharedString, Size, Stateful, TitlebarOptions, Window, WindowBounds,
20- canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size,20+ WindowOptions, canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size,
21 };21 };
22 22
23 /// Editor chrome: three grays and one accent, all darker than the picture so the23 /// Editor chrome: three grays and one accent, all darker than the picture so the
@@ -2023,9 +2023,7 @@ impl Player {
2023 // an inapplicable item in the clip menu is: it still says its piece.2023 // an inapplicable item in the clip menu is: it still says its piece.
2024 let live = |d: Stateful<Div>, enabled: bool| {2024 let live = |d: Stateful<Div>, enabled: bool| {
2025 d.when(!enabled, |d| d.opacity(0.4).cursor_not_allowed())2025 d.when(!enabled, |d| d.opacity(0.4).cursor_not_allowed())
2026- .when(enabled, |d| {2026+ .when(enabled, |d| d.cursor_pointer().hover(|s| s.bg(rgb(HOVER))))
2027- d.cursor_pointer().hover(|s| s.bg(rgb(HOVER)))
2028- })
2029 };2027 };
2030 // The formats first: the quality rows below are *video* bitrate, so2028 // The formats first: the quality rows below are *video* bitrate, so
2031 // which file is being written decides whether they mean anything.2029 // which file is being written decides whether they mean anything.
@@ -4147,7 +4145,10 @@ mod tests {
4147 // a number typed against the custom row must not leak into it.4145 // a number typed against the custom row must not leak into it.
4148 let mp4 = Format::Mp4;4146 let mp4 = Format::Mp4;
4149 assert_eq!(export_settings(Quality::Auto, 7, mp4).bitrate, None);4147 assert_eq!(export_settings(Quality::Auto, 7, mp4).bitrate, None);
4150- assert_eq!(export_settings(Quality::Low, 0, mp4).bitrate, Some(2_000_000));4148+ assert_eq!(
4149+ export_settings(Quality::Low, 0, mp4).bitrate,
4150+ Some(2_000_000)
4151+ );
4151 assert_eq!(4152 assert_eq!(
4152 export_settings(Quality::Medium, 0, mp4).bitrate,4153 export_settings(Quality::Medium, 0, mp4).bitrate,
4153 Some(6_000_000)4154 Some(6_000_000)
crates/engine/src/edith.rsmodified+1 -6
@@ -134,12 +134,7 @@ fn project_dir(path: &Path) -> PathBuf {
134 dir.canonicalize().unwrap_or_else(|_| dir.to_path_buf())134 dir.canonicalize().unwrap_or_else(|_| dir.to_path_buf())
135 }135 }
136 136
137-fn emit(137+fn emit(dir: &Path, sources: &[Source], lanes: &[(LaneKind, Vec<Clip>)], playhead: u32) -> Vec<u8> {
138- dir: &Path,
139- sources: &[Source],
140- lanes: &[(LaneKind, Vec<Clip>)],
141- playhead: u32,
142-) -> Vec<u8> {
143 let mut out = Vec::new();138 let mut out = Vec::new();
144 out.extend_from_slice(MAGIC);139 out.extend_from_slice(MAGIC);
145 out.push(b'\n');140 out.push(b'\n');
crates/engine/tests/audio_export.rsmodified+40 -16
@@ -15,6 +15,7 @@ use std::path::{Path, PathBuf};
15 use std::time::{Duration, Instant};15 use std::time::{Duration, Instant};
16 16
17 use engine::export::{ExportSettings, Format};17 use engine::export::{ExportSettings, Format};
18+use engine::project::LaneKind;
18 use engine::project::Source;19 use engine::project::Source;
19 use engine::{AudioSession, Clip, ExportHandle, Project};20 use engine::{AudioSession, Clip, ExportHandle, Project};
20 21
@@ -29,8 +30,7 @@ fn asset(name: &str) -> PathBuf {
29 /// Per-run unique, like the mp4 suite's: two suites at once must not delete30 /// Per-run unique, like the mp4 suite's: two suites at once must not delete
30 /// each other's output.31 /// each other's output.
31 fn out_path(name: &str, ext: &str) -> PathBuf {32 fn out_path(name: &str, ext: &str) -> PathBuf {
32- let path =33+ let path = std::env::temp_dir().join(format!("ve_audio_{name}_{}.{ext}", std::process::id()));
33- std::env::temp_dir().join(format!("ve_audio_{name}_{}.{ext}", std::process::id()));
34 let _ = std::fs::remove_file(&path);34 let _ = std::fs::remove_file(&path);
35 let _ = std::fs::remove_file(part_path(&path));35 let _ = std::fs::remove_file(part_path(&path));
36 path36 path
@@ -43,7 +43,10 @@ fn part_path(out: &Path) -> PathBuf {
43 fn wait(handle: &ExportHandle, limit: Duration) -> engine::Result<()> {43 fn wait(handle: &ExportHandle, limit: Duration) -> engine::Result<()> {
44 let started = Instant::now();44 let started = Instant::now();
45 while !handle.is_finished() {45 while !handle.is_finished() {
46- assert!(started.elapsed() < limit, "export did not finish in {limit:?}");46+ assert!(
47+ started.elapsed() < limit,
48+ "export did not finish in {limit:?}"
49+ );
47 std::thread::sleep(Duration::from_millis(10));50 std::thread::sleep(Duration::from_millis(10));
48 }51 }
49 handle.result().expect("a finished export has an outcome")52 handle.result().expect("a finished export has an outcome")
@@ -70,14 +73,19 @@ fn mixed_project() -> Project {
70 // The picture is beside the point here, but a project has two lanes and73 // The picture is beside the point here, but a project has two lanes and
71 // the timeline's length is the longer of them: three seconds of video74 // the timeline's length is the longer of them: three seconds of video
72 // is what makes the third second of audio part of the timeline.75 // is what makes the third second of audio part of the timeline.
73- vec![Clip {76+ vec![
74- start: 0,77+ (
75- in_frame: 0,78+ LaneKind::Video,
76- out_frame: 90,79+ vec![Clip {
77- source: 0,80+ start: 0,
78- link: None,81+ in_frame: 0,
79- }],82+ out_frame: 90,
80- vec![clip(0, 0), clip(60, 1)],83+ source: 0,
84+ link: None,
85+ }],
86+ ),
87+ (LaneKind::Audio, vec![clip(0, 0), clip(60, 1)]),
88+ ],
81 )89 )
82 .expect("a two-source project with a hole in the audio lane")90 .expect("a two-source project with a hole in the audio lane")
83 }91 }
@@ -107,7 +115,12 @@ fn rms(samples: &[f32], channels: usize, from: f64, to: f64) -> f64 {
107 let at = |secs: f64| (secs * f64::from(RATE)) as usize * channels;115 let at = |secs: f64| (secs * f64::from(RATE)) as usize * channels;
108 let window = &samples[at(from).min(samples.len())..at(to).min(samples.len())];116 let window = &samples[at(from).min(samples.len())..at(to).min(samples.len())];
109 assert!(!window.is_empty(), "no samples in [{from}, {to})");117 assert!(!window.is_empty(), "no samples in [{from}, {to})");
110- (window.iter().map(|s| f64::from(*s) * f64::from(*s)).sum::<f64>() / window.len() as f64).sqrt()118+ (window
119+ .iter()
120+ .map(|s| f64::from(*s) * f64::from(*s))
121+ .sum::<f64>()
122+ / window.len() as f64)
123+ .sqrt()
111 }124 }
112 125
113 /// What every audio export must be, whatever encoded it: exactly as long as the126 /// What every audio export must be, whatever encoded it: exactly as long as the
@@ -121,7 +134,11 @@ fn assert_timeline_shape(meta: &engine::AudioMeta, samples: &[f32]) {
121 // windows and the mp3 need not end where the second does, so this is the134 // windows and the mp3 need not end where the second does, so this is the
122 // export's own trim/pad and not an accident of the sources.135 // export's own trim/pad and not an accident of the sources.
123 let frames = (3.0 * f64::from(RATE)) as usize;136 let frames = (3.0 * f64::from(RATE)) as usize;
124- assert_eq!(samples.len(), frames * channels, "timeline length in samples");137+ assert_eq!(
138+ samples.len(),
139+ frames * channels,
140+ "timeline length in samples"
141+ );
125 142
126 // Second 0 is test_av, second 2 is the mp3; both carry the tone.143 // Second 0 is test_av, second 2 is the mp3; both carry the tone.
127 let av = rms(samples, channels, 0.05, 0.95);144 let av = rms(samples, channels, 0.05, 0.95);
@@ -138,7 +155,10 @@ fn assert_timeline_shape(meta: &engine::AudioMeta, samples: &[f32]) {
138 // t = 0.25 and the dip at t = 0.75. Ratio, never an absolute level.155 // t = 0.25 and the dip at t = 0.75. Ratio, never an absolute level.
139 let peak = rms(samples, channels, 0.2, 0.3);156 let peak = rms(samples, channels, 0.2, 0.3);
140 let dip = rms(samples, channels, 0.7, 0.8);157 let dip = rms(samples, channels, 0.7, 0.8);
141- println!("pulse: peak {peak:.4} dip {dip:.4} ratio {:.1}", peak / dip);158+ println!(
159+ "pulse: peak {peak:.4} dip {dip:.4} ratio {:.1}",
160+ peak / dip
161+ );
142 assert!(162 assert!(
143 peak > dip * 4.0,163 peak > dip * 4.0,
144 "the 1 Hz pulse survived: peak {peak:.4} vs dip {dip:.4}"164 "the 1 Hz pulse survived: peak {peak:.4} vs dip {dip:.4}"
@@ -151,7 +171,8 @@ fn assert_timeline_shape(meta: &engine::AudioMeta, samples: &[f32]) {
151 fn assert_wav_header(path: &Path, frames: usize) {171 fn assert_wav_header(path: &Path, frames: usize) {
152 let bytes = std::fs::read(path).expect("read the wav back");172 let bytes = std::fs::read(path).expect("read the wav back");
153 let u16_at = |i: usize| u16::from_le_bytes([bytes[i], bytes[i + 1]]);173 let u16_at = |i: usize| u16::from_le_bytes([bytes[i], bytes[i + 1]]);
154- let u32_at = |i: usize| u32::from_le_bytes([bytes[i], bytes[i + 1], bytes[i + 2], bytes[i + 3]]);174+ let u32_at =
175+ |i: usize| u32::from_le_bytes([bytes[i], bytes[i + 1], bytes[i + 2], bytes[i + 3]]);
155 assert_eq!(&bytes[0..4], b"RIFF");176 assert_eq!(&bytes[0..4], b"RIFF");
156 assert_eq!(&bytes[8..12], b"WAVE");177 assert_eq!(&bytes[8..12], b"WAVE");
157 assert_eq!(&bytes[12..16], b"fmt ");178 assert_eq!(&bytes[12..16], b"fmt ");
@@ -270,5 +291,8 @@ fn a_silent_timeline_refuses_an_audio_export() {
270 .expect_err("no audio to export")291 .expect_err("no audio to export")
271 .to_string();292 .to_string();
272 assert!(text.contains("no audio"), "{text}");293 assert!(text.contains("no audio"), "{text}");
273- assert!(!out.exists() && !part_path(&out).exists(), "nothing written");294+ assert!(
295+ !out.exists() && !part_path(&out).exists(),
296+ "nothing written"
297+ );
274 }298 }