🔀 merge(T6): the last media leaves, and nothing assumes source 0 stayed
Browse files at this commit10 changed files +1495 -188
- Cargo.lock +7 -0
- crates/app/src/keymap.rs +39 -5
- crates/app/src/main.rs +932 -70
- crates/engine/Cargo.toml +6 -0
- crates/engine/src/audio.rs +3 -2
- crates/engine/src/export.rs +147 -57
- crates/engine/src/playback.rs +53 -1
- crates/engine/src/project.rs +197 -3
- crates/engine/tests/eq_audio.rs +92 -50
- crates/engine/tests/images.rs +19 -0
Cargo.lockmodified+7 -0
| @@ -1638,6 +1638,7 @@ dependencies = [ | ||
| 1638 | 1638 | "oxideav-ac3", |
| 1639 | 1639 | "oxideav-core", |
| 1640 | 1640 | "rav1e", |
| 1641 | + "rusty_aac", | |
| 1641 | 1642 | "rusty_h264", |
| 1642 | 1643 | "symphonia", |
| 1643 | 1644 | "symphonia-codec-aac", |
| @@ -4880,6 +4881,12 @@ version = "1.0.23" | ||
| 4880 | 4881 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4881 | 4882 | checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" |
| 4882 | 4883 | |
| 4884 | +[[package]] | |
| 4885 | +name = "rusty_aac" | |
| 4886 | +version = "0.5.0" | |
| 4887 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 4888 | +checksum = "b7ab980ffb66a559565d09dd6727ff2da7d2a39d2e8b6149e48af6908caa99b5" | |
| 4889 | + | |
| 4883 | 4890 | [[package]] |
| 4884 | 4891 | name = "rusty_h264" |
| 4885 | 4892 | version = "0.8.0" |
crates/app/src/keymap.rsmodified+39 -5
| @@ -66,6 +66,8 @@ pub enum ActionId { | ||
| 66 | 66 | Undo, |
| 67 | 67 | AddVideoLane, |
| 68 | 68 | AddAudioLane, |
| 69 | + RemoveVideoLane, | |
| 70 | + RemoveAudioLane, | |
| 69 | 71 | ToggleMute, |
| 70 | 72 | VolumeUp, |
| 71 | 73 | VolumeDown, |
| @@ -78,7 +80,7 @@ pub enum ActionId { | ||
| 78 | 80 | impl ActionId { |
| 79 | 81 | /// Display order everywhere -- the editor lists them in it and |
| 80 | 82 | /// [`Keymap::defaults`] binds them in it. |
| 81 | - pub const ALL: [ActionId; 33] = [ | |
| 83 | + pub const ALL: [ActionId; 35] = [ | |
| 82 | 84 | ActionId::Play, |
| 83 | 85 | ActionId::StepBack, |
| 84 | 86 | ActionId::StepForward, |
| @@ -105,6 +107,8 @@ impl ActionId { | ||
| 105 | 107 | ActionId::Undo, |
| 106 | 108 | ActionId::AddVideoLane, |
| 107 | 109 | ActionId::AddAudioLane, |
| 110 | + ActionId::RemoveVideoLane, | |
| 111 | + ActionId::RemoveAudioLane, | |
| 108 | 112 | ActionId::ToggleMute, |
| 109 | 113 | ActionId::VolumeUp, |
| 110 | 114 | ActionId::VolumeDown, |
| @@ -143,6 +147,8 @@ impl ActionId { | ||
| 143 | 147 | ActionId::Undo => "Undo", |
| 144 | 148 | ActionId::AddVideoLane => "Add a video track", |
| 145 | 149 | ActionId::AddAudioLane => "Add an audio track", |
| 150 | + ActionId::RemoveVideoLane => "Remove the last video track (it must be empty)", | |
| 151 | + ActionId::RemoveAudioLane => "Remove the last audio track (it must be empty)", | |
| 146 | 152 | ActionId::ToggleMute => "Mute / Unmute", |
| 147 | 153 | ActionId::VolumeUp => "Volume up", |
| 148 | 154 | ActionId::VolumeDown => "Volume down", |
| @@ -183,6 +189,8 @@ impl ActionId { | ||
| 183 | 189 | ActionId::Undo => "undo", |
| 184 | 190 | ActionId::AddVideoLane => "add-video-lane", |
| 185 | 191 | ActionId::AddAudioLane => "add-audio-lane", |
| 192 | + ActionId::RemoveVideoLane => "remove-video-lane", | |
| 193 | + ActionId::RemoveAudioLane => "remove-audio-lane", | |
| 186 | 194 | ActionId::ToggleMute => "toggle-mute", |
| 187 | 195 | ActionId::VolumeUp => "volume-up", |
| 188 | 196 | ActionId::VolumeDown => "volume-down", |
| @@ -235,7 +243,9 @@ impl ActionId { | ||
| 235 | 243 | | ActionId::Group |
| 236 | 244 | | ActionId::Undo |
| 237 | 245 | | ActionId::AddVideoLane |
| 238 | - | ActionId::AddAudioLane => Category::Editing, | |
| 246 | + | ActionId::AddAudioLane | |
| 247 | + | ActionId::RemoveVideoLane | |
| 248 | + | ActionId::RemoveAudioLane => Category::Editing, | |
| 239 | 249 | ActionId::ToggleMute |
| 240 | 250 | | ActionId::VolumeUp |
| 241 | 251 | | ActionId::VolumeDown |
| @@ -291,7 +301,15 @@ pub struct Fixed { | ||
| 291 | 301 | pub category: Category, |
| 292 | 302 | } |
| 293 | 303 | |
| 294 | -pub const FIXED: [Fixed; 14] = [ | |
| 304 | +pub const FIXED: [Fixed; 16] = [ | |
| 305 | + // Not a chord at all but a way of pressing one, and the only place the | |
| 306 | + // editor can say so: holding a key that moves a *value* runs it, and | |
| 307 | + // holding anything else still does what one press did. | |
| 308 | + Fixed { | |
| 309 | + chord: "hold ← → ↑ ↓", | |
| 310 | + label: "Run a card's slider, or the volume keys, while held", | |
| 311 | + category: Category::View, | |
| 312 | + }, | |
| 295 | 313 | Fixed { |
| 296 | 314 | chord: "esc", |
| 297 | 315 | label: "Close this card or menu, or cancel a capture", |
| @@ -340,6 +358,11 @@ pub const FIXED: [Fixed; 14] = [ | ||
| 340 | 358 | label: "Flatten every band", |
| 341 | 359 | category: Category::Audio, |
| 342 | 360 | }, |
| 361 | + Fixed { | |
| 362 | + chord: "s", | |
| 363 | + label: "Show or hide the spectrum behind the curve", | |
| 364 | + category: Category::Audio, | |
| 365 | + }, | |
| 343 | 366 | // The colour card's own three, which mean nothing outside it -- the same |
| 344 | 367 | // card-local input the export card's digits are. |
| 345 | 368 | Fixed { |
| @@ -528,6 +551,13 @@ impl Keymap { | ||
| 528 | 551 | // is added often enough to deserve a key that is one press. |
| 529 | 552 | b(ActionId::AddVideoLane, "v", false), |
| 530 | 553 | b(ActionId::AddAudioLane, "a", false), |
| 554 | + // ...and the pair that takes one back, on ctrl chords: removing | |
| 555 | + // a track is not a stroke to hit by accident (the resolution key | |
| 556 | + // is out of the way for the same reason). Ctrl+v would be the | |
| 557 | + // matching initial and is the paste, so the video one takes the | |
| 558 | + // key beside it. | |
| 559 | + b(ActionId::RemoveVideoLane, "b", true), | |
| 560 | + b(ActionId::RemoveAudioLane, "a", true), | |
| 531 | 561 | b(ActionId::ToggleMute, "m", false), |
| 532 | 562 | // The unshifted pair, which is what gpui reports for those two |
| 533 | 563 | // keys ("=" and "-", platform.rs:862): the volume keys every |
| @@ -809,7 +839,7 @@ mod tests { | ||
| 809 | 839 | #[test] |
| 810 | 840 | fn every_default_stroke_reaches_its_action() { |
| 811 | 841 | let k = Keymap::defaults(); |
| 812 | - assert_eq!(k.entries().len(), 35); | |
| 842 | + assert_eq!(k.entries().len(), 37); | |
| 813 | 843 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); |
| 814 | 844 | // The seek keys: bare arrows a frame, ctrl arrows a second, and the two |
| 815 | 845 | // ends of the timeline. |
| @@ -843,6 +873,10 @@ mod tests { | ||
| 843 | 873 | // The track keys are the bare letters; the ctrl ones stay copy/paste. |
| 844 | 874 | assert_eq!(k.lookup("v", false), Some(ActionId::AddVideoLane)); |
| 845 | 875 | assert_eq!(k.lookup("a", false), Some(ActionId::AddAudioLane)); |
| 876 | + // ...and the ctrl ones take a track away, out of the way of a stray | |
| 877 | + // press. Ctrl+v is the paste, so the video one sits beside it. | |
| 878 | + assert_eq!(k.lookup("b", true), Some(ActionId::RemoveVideoLane)); | |
| 879 | + assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane)); | |
| 846 | 880 | assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute)); |
| 847 | 881 | assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer)); |
| 848 | 882 | // The volume pair is the unshifted one, so neither needs a modifier |
| @@ -1038,7 +1072,7 @@ mod tests { | ||
| 1038 | 1072 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); |
| 1039 | 1073 | // The label is the editor's column, and never the file's word for it. |
| 1040 | 1074 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); |
| 1041 | - assert_eq!(ActionId::ALL.len(), 33); | |
| 1075 | + assert_eq!(ActionId::ALL.len(), 35); | |
| 1042 | 1076 | } |
| 1043 | 1077 | |
| 1044 | 1078 | #[test] |
crates/app/src/main.rsmodified+932 -70
| @@ -95,6 +95,9 @@ const ROW_H: f32 = 32.; | ||
| 95 | 95 | /// wear in the lanes, which is the whole of the panel<->timeline association. |
| 96 | 96 | const SWATCH_W: f32 = 4.; |
| 97 | 97 | const CONTROL_H: f32 = 28.; |
| 98 | +/// The volume slider beside its button: a hundred steps across it, so a pixel | |
| 99 | +/// is finer than a step and the drag reads as continuous. | |
| 100 | +const VOLUME_W: f32 = 110.; | |
| 98 | 101 | const RULER_HIT_H: f32 = HIT_MIN; |
| 99 | 102 | /// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits |
| 100 | 103 | /// cannot push the layout around. |
| @@ -128,6 +131,18 @@ const ESCAPE: &str = "escape"; | ||
| 128 | 131 | /// as a program name rather than as a file name. |
| 129 | 132 | const NO_FILE: &str = "no file open"; |
| 130 | 133 | |
| 134 | +/// What a press of play says when there is nothing to play: no timeline at all | |
| 135 | +/// and an emptied one are the same answer to the user, so they are one line. | |
| 136 | +const NOTHING_TO_PLAY: &str = "NOTHING TO PLAY — put a clip on the timeline first"; | |
| 137 | + | |
| 138 | +/// Whether a press of play would have anything to play. No timeline at all and | |
| 139 | +/// one every clip has been taken off are the same state to a transport, and the | |
| 140 | +/// button and the key both have to give the same answer to it -- so there is | |
| 141 | +/// one of them, and it is free of the window so it can be checked without one. | |
| 142 | +fn nothing_to_play(session: Option<&PlaybackSession>) -> bool { | |
| 143 | + session.is_none_or(PlaybackSession::is_empty) | |
| 144 | +} | |
| 145 | + | |
| 131 | 146 | /// What the monitoring output is set to. Two things, not one: the level the |
| 132 | 147 | /// user picked, and whether it is being held silent -- so unmuting comes back |
| 133 | 148 | /// to the level rather than to a guess. |
| @@ -146,29 +161,45 @@ struct Volume { | ||
| 146 | 161 | } |
| 147 | 162 | |
| 148 | 163 | impl Volume { |
| 149 | - /// 5% a press: twenty of them across the range. | |
| 150 | - const MAX_STEPS: u8 = 20; | |
| 164 | + /// One step is one percent: fine enough that a drag along the slider reads | |
| 165 | + /// as continuous, and still a count rather than a float. | |
| 166 | + const MAX_STEPS: u8 = 100; | |
| 167 | + | |
| 168 | + /// 5% a press: twenty presses across the range, which is what the keys have | |
| 169 | + /// always moved. The slider is what the finer grid is for. | |
| 170 | + const KEY_STEP: u8 = 5; | |
| 151 | 171 | |
| 152 | 172 | /// What the device is set to: mute wins, and the level is what it returns |
| 153 | 173 | /// to. `0.0..=1.0`, which is the range the plugin's ABI accepts. |
| 154 | 174 | fn gain(self) -> f32 { |
| 155 | - if self.muted { | |
| 156 | - 0. | |
| 157 | - } else { | |
| 158 | - f32::from(self.steps) / f32::from(Self::MAX_STEPS) | |
| 159 | - } | |
| 175 | + if self.muted { 0. } else { self.along() } | |
| 160 | 176 | } |
| 161 | 177 | |
| 162 | 178 | /// One press up or down, clamped at both ends -- saturating, so the count |
| 163 | 179 | /// cannot wrap past silence into full volume. |
| 164 | 180 | fn step(&mut self, up: bool) { |
| 165 | 181 | self.steps = if up { |
| 166 | - self.steps.saturating_add(1).min(Self::MAX_STEPS) | |
| 182 | + self.steps.saturating_add(Self::KEY_STEP).min(Self::MAX_STEPS) | |
| 167 | 183 | } else { |
| 168 | - self.steps.saturating_sub(1) | |
| 184 | + self.steps.saturating_sub(Self::KEY_STEP) | |
| 169 | 185 | }; |
| 170 | 186 | } |
| 171 | 187 | |
| 188 | + /// Where the hand let go along the slider, 0..1 from silence to full. The | |
| 189 | + /// grid is the same one the keys land on, so a drag to the top and a key | |
| 190 | + /// held up reach the very same number -- and a drag never touches mute: | |
| 191 | + /// asking for a level while muted is not asking for sound. | |
| 192 | + fn set_along(&mut self, frac: f32) { | |
| 193 | + self.steps = (frac.clamp(0., 1.) * f32::from(Self::MAX_STEPS)).round() as u8; | |
| 194 | + } | |
| 195 | + | |
| 196 | + /// How full the slider is drawn, 0..1. The level and not the gain: a muted | |
| 197 | + /// slider still shows what unmuting comes back to, exactly as the label | |
| 198 | + /// does. | |
| 199 | + fn along(self) -> f32 { | |
| 200 | + f32::from(self.steps) / f32::from(Self::MAX_STEPS) | |
| 201 | + } | |
| 202 | + | |
| 172 | 203 | /// What the button reads. The level shows while muted too: it is what the |
| 173 | 204 | /// next press of the mute key brings back. |
| 174 | 205 | fn label(self) -> String { |
| @@ -358,9 +389,10 @@ fn speed_at(permille: i32) -> Speed { | ||
| 358 | 389 | } |
| 359 | 390 | |
| 360 | 391 | /// The silence card's rows, in the order it lists them: how wide the apply |
| 361 | -/// reaches, the four settings a scan is told, and the rate the speed-up plays | |
| 362 | -/// at. What `silence_field` indexes and what [`Player::nudge_silence`] moves. | |
| 363 | -const SILENCE_ROWS: usize = 6; | |
| 392 | +/// reaches, the threshold and the unit it is read in, the three durations a | |
| 393 | +/// scan is told, and the rate the speed-up plays at. What `silence_field` | |
| 394 | +/// indexes and what [`Player::nudge_silence`] moves. | |
| 395 | +const SILENCE_ROWS: usize = 7; | |
| 364 | 396 | |
| 365 | 397 | /// How wide a jumpcut reaches. A ripple used to be the whole timeline's |
| 366 | 398 | /// business and nothing else; it is a *choice* now, because a podcast track's |
| @@ -408,9 +440,12 @@ const SILENCE_DB_STEP: f32 = 1.; | ||
| 408 | 440 | const SILENCE_SECS_STEP: f64 = 0.05; |
| 409 | 441 | |
| 410 | 442 | /// How far each of them may be pushed. UI decisions, all of them: the engine |
| 411 | -/// takes any finite number, but a threshold at 0 dBFS calls a whole take silent | |
| 412 | -/// and a forgiveness of ten seconds finds nothing in a talking head. | |
| 413 | -const SILENCE_DB_RANGE: (f32, f32) = (-80., -10.); | |
| 443 | +/// takes any finite number, but a forgiveness of ten seconds finds nothing in a | |
| 444 | +/// talking head. The threshold reaches full scale, which calls a whole take | |
| 445 | +/// silent -- that is a thing someone may want to ask for (the preview on the | |
| 446 | +/// lane says what it would cost before anything is cut), so the top is 0 rather | |
| 447 | +/// than a number this card picked for them. | |
| 448 | +const SILENCE_DB_RANGE: (f32, f32) = (-80., 0.); | |
| 414 | 449 | const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.); |
| 415 | 450 | |
| 416 | 451 | /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows |
| @@ -451,6 +486,36 @@ const EQ_TICKS: [(f32, &str); 5] = [ | ||
| 451 | 486 | (20000., "20k"), |
| 452 | 487 | ]; |
| 453 | 488 | |
| 489 | +/// The gains the graph rules a line across, besides the 0 dB one it already | |
| 490 | +/// had: half way to each limit, so a boost can be read as "about six" without | |
| 491 | +/// counting pixels. The limits themselves are the box's own edges and are | |
| 492 | +/// named at the corners instead. | |
| 493 | +const EQ_DB_GRID: [f32; 2] = [6., -6.]; | |
| 494 | + | |
| 495 | +/// The grid's ink: above the card's background and below everything drawn on | |
| 496 | +/// it, so the lines are a ruling rather than a thing to look at. | |
| 497 | +const EQ_GRID: u32 = 0x3a3a3a; | |
| 498 | + | |
| 499 | +/// How many played samples one spectrum frame is transformed from. A power of | |
| 500 | +/// two ([`fft`] is radix-2) and the whole of the engine's tap: 1024 at 48 kHz | |
| 501 | +/// is a 47 Hz bin, fine enough that the bass end is a shape and short enough | |
| 502 | +/// (21 ms) that the analyser moves with the music. | |
| 503 | +const EQ_FFT: usize = 1024; | |
| 504 | + | |
| 505 | +/// The level range the analyser is drawn across, floor to ceiling in dBFS: the | |
| 506 | +/// bottom of the box is silence and the top is a bin at -12 dBFS, which is | |
| 507 | +/// about where a mixed track's loudest band sits. A look, not a measurement -- | |
| 508 | +/// the numbers on the axis are the curve's dB, never the analyser's. | |
| 509 | +const EQ_SPECTRUM_DB: (f32, f32) = (-96., -12.); | |
| 510 | + | |
| 511 | +/// The analyser's fill, behind the curve: a dim blue-grey with enough alpha to | |
| 512 | +/// read as a haze the accent line sits on top of. | |
| 513 | +const EQ_SPECTRUM_INK: u32 = 0x7f95ad66; | |
| 514 | + | |
| 515 | +/// The area under the response curve, same accent as the line at a tenth of | |
| 516 | +/// its weight: it is what makes a boost read as a hill rather than as a wire. | |
| 517 | +const EQ_FILL_INK: u32 = 0x4a9eff26; | |
| 518 | + | |
| 454 | 519 | /// The colour card's four controls, in the order it lists them: what each is |
| 455 | 520 | /// called and the range it moves in. The order is `ColorParams`' own, which is |
| 456 | 521 | /// what [`color_band`] indexes. |
| @@ -584,6 +649,11 @@ struct Player { | ||
| 584 | 649 | /// also why it is not written to the project file and cannot reach an |
| 585 | 650 | /// export. [`Player::apply_volume`] is what pushes it at a session. |
| 586 | 651 | volume: Volume, |
| 652 | + /// Where the volume slider was last painted, and whether a hand is on it -- | |
| 653 | + /// the speed bar's pair, for the speed bar's reason: the pointer moves | |
| 654 | + /// arrive at the root, so the bar's own geometry has to be readable there. | |
| 655 | + volume_bar: Rc<Cell<Bounds<Pixels>>>, | |
| 656 | + volume_dragging: bool, | |
| 587 | 657 | /// The keybindings overlay is up. While it is, it owns the keyboard and the |
| 588 | 658 | /// pointer: a stroke or a click meant for a row must not also cut the |
| 589 | 659 | /// timeline. |
| @@ -622,6 +692,11 @@ struct Player { | ||
| 622 | 692 | /// window position only, so this is what a press and a drag are read |
| 623 | 693 | /// against ([`frac_along`], [`frac_down`]). |
| 624 | 694 | eq_graph: Rc<Cell<Bounds<Pixels>>>, |
| 695 | + /// Whether the analyser is drawn behind the curve. On by default -- what | |
| 696 | + /// the curve is being *shaped against* is the point of drawing it -- and | |
| 697 | + /// off with one press for anyone who would rather read the curve alone. | |
| 698 | + /// Card state, not the project's: it changes nothing that plays. | |
| 699 | + eq_spectrum: bool, | |
| 625 | 700 | /// The colour card is up on this clip -- the lane it is on and its index |
| 626 | 701 | /// there. `None` when it is closed, which is the only place that state |
| 627 | 702 | /// lives: the grade itself is the project's. |
| @@ -652,6 +727,14 @@ struct Player { | ||
| 652 | 727 | /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own |
| 653 | 728 | /// focus, since nothing in it takes gpui's (ledger:182). |
| 654 | 729 | silence_field: usize, |
| 730 | + /// Whether the threshold is *labelled* dBFS or dB. Display only, and the | |
| 731 | + /// number is the same either way: the setting is a level below full scale, | |
| 732 | + /// so 0 is the loudest sample a file can hold and -40 is forty decibels | |
| 733 | + /// under it -- "dBFS" names that reference out loud, "dB" leaves it unsaid. | |
| 734 | + /// No conversion is hiding behind the row (there is no reference here worth | |
| 735 | + /// inventing, and a made-up SPL would be a lie about what was measured); | |
| 736 | + /// what it changes is which of the two spellings a person reads. | |
| 737 | + silence_dbfs: bool, | |
| 655 | 738 | /// What the last scan found, in timeline frames: what the lane draws marks |
| 656 | 739 | /// over and what an apply acts on -- *exactly* the previewed set, never a |
| 657 | 740 | /// second scan at the moment of the press. |
| @@ -822,6 +905,11 @@ impl Player { | ||
| 822 | 905 | ActionId::Undo => self.undo(cx), |
| 823 | 906 | ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx), |
| 824 | 907 | ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx), |
| 908 | + // The last track of that kind: the one the add key put there, so the | |
| 909 | + // two strokes undo each other press for press. Any other track goes | |
| 910 | + // through the × in its own header. | |
| 911 | + ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx), | |
| 912 | + ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx), | |
| 825 | 913 | ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx), |
| 826 | 914 | ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx), |
| 827 | 915 | ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx), |
| @@ -1314,9 +1402,12 @@ impl Player { | ||
| 1314 | 1402 | + steps as f32 * SILENCE_DB_STEP) |
| 1315 | 1403 | .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1) |
| 1316 | 1404 | } |
| 1317 | - 2 => self.silence.min_silence = secs(self.silence.min_silence), | |
| 1318 | - 3 => self.silence.padding = secs(self.silence.padding), | |
| 1319 | - 4 => self.silence.min_keep = secs(self.silence.min_keep), | |
| 1405 | + // Two spellings of the same level, so either arrow flips it -- a | |
| 1406 | + // ring of two, like the scope row's. | |
| 1407 | + 2 => self.silence_dbfs = !self.silence_dbfs, | |
| 1408 | + 3 => self.silence.min_silence = secs(self.silence.min_silence), | |
| 1409 | + 4 => self.silence.padding = secs(self.silence.padding), | |
| 1410 | + 5 => self.silence.min_keep = secs(self.silence.min_keep), | |
| 1320 | 1411 | _ => { |
| 1321 | 1412 | self.silence_factor = |
| 1322 | 1413 | silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP) |
| @@ -1478,6 +1569,29 @@ impl Player { | ||
| 1478 | 1569 | || self.exporting().is_some() |
| 1479 | 1570 | } |
| 1480 | 1571 | |
| 1572 | + /// Which of [`Repeat`]'s three the window is in, for the hold gate at the | |
| 1573 | + /// top of the key handler. Not [`Player::modal`]: that asks whether an | |
| 1574 | + /// overlay is up at all, and here the cards with sliders in them are | |
| 1575 | + /// exactly the ones that answer differently from the keys menu and the | |
| 1576 | + /// export card. | |
| 1577 | + fn repeat_scope(&self) -> Repeat { | |
| 1578 | + if self.rebinding.is_some() | |
| 1579 | + || self.keys_open | |
| 1580 | + || self.export_open | |
| 1581 | + || self.exporting().is_some() | |
| 1582 | + { | |
| 1583 | + Repeat::Nothing | |
| 1584 | + } else if self.eq_open.is_some() | |
| 1585 | + || self.color_open.is_some() | |
| 1586 | + || self.speed_open.is_some() | |
| 1587 | + || self.silence_open.is_some() | |
| 1588 | + { | |
| 1589 | + Repeat::Card | |
| 1590 | + } else { | |
| 1591 | + Repeat::Keymap | |
| 1592 | + } | |
| 1593 | + } | |
| 1594 | + | |
| 1481 | 1595 | /// Opens the equalizer on the selected clip. Audio only, and it says so |
| 1482 | 1596 | /// rather than opening a card of bands that would reach nothing: a video |
| 1483 | 1597 | /// clip carries no sound of its own here (the sound is the audio lane's), |
| @@ -2027,6 +2141,25 @@ impl Player { | ||
| 2027 | 2141 | return clip; |
| 2028 | 2142 | }; |
| 2029 | 2143 | match trim.edge { |
| 2144 | + // A still grows forward from source frame 0 instead, exactly as | |
| 2145 | + // `Project::trim` writes it: with the in-point clamped at 0 the box | |
| 2146 | + // below would slide left rather than stretch, and the release would | |
| 2147 | + // then commit a wider clip than the drag drew. | |
| 2148 | + Edge::Start | |
| 2149 | + if self.session.as_ref().is_some_and(|session| { | |
| 2150 | + session | |
| 2151 | + .sources() | |
| 2152 | + .get(clip.source) | |
| 2153 | + .is_some_and(|s| engine::is_image(&s.path)) | |
| 2154 | + }) => | |
| 2155 | + { | |
| 2156 | + Clip { | |
| 2157 | + in_frame: 0, | |
| 2158 | + out_frame: clip.end().saturating_sub(trim.to).max(1), | |
| 2159 | + start: trim.to, | |
| 2160 | + ..clip | |
| 2161 | + } | |
| 2162 | + } | |
| 2030 | 2163 | // The in-point follows the head, exactly as `Project::trim` moves |
| 2031 | 2164 | // it: what stays on screen plays what it always played. |
| 2032 | 2165 | Edge::Start => Clip { |
| @@ -2218,6 +2351,16 @@ impl Player { | ||
| 2218 | 2351 | self.waves.clear(); |
| 2219 | 2352 | self.streams.clear(); |
| 2220 | 2353 | self.sizes.clear(); |
| 2354 | + // Scanned off a source that is not in the library any more. | |
| 2355 | + self.silence_levels = None; | |
| 2356 | + // Every gesture in flight, dropped for `reset_after_reseek`'s reason | |
| 2357 | + // (it drops the trim below): a drag holds a bar, a clip or a band of a | |
| 2358 | + // timeline that has just stopped existing. | |
| 2359 | + self.scrubbing = false; | |
| 2360 | + self.volume_dragging = false; | |
| 2361 | + self.eq_dragging = false; | |
| 2362 | + self.speed_dragging = false; | |
| 2363 | + self.color_dragging = false; | |
| 2221 | 2364 | self.displayed = 0; |
| 2222 | 2365 | self.dropped = 0; |
| 2223 | 2366 | self.started = None; |
| @@ -2488,6 +2631,64 @@ impl Player { | ||
| 2488 | 2631 | cx.notify(); |
| 2489 | 2632 | } |
| 2490 | 2633 | |
| 2634 | + /// The × in a track's header: the add taken back, one undo step, and the | |
| 2635 | + /// engine's own words when it refuses -- those name the clips still on the | |
| 2636 | + /// track, so the notice says what to delete first. A removal never deletes a | |
| 2637 | + /// clip. | |
| 2638 | + /// | |
| 2639 | + /// Everything holding a `(lane, idx)` is dropped, because the tracks below | |
| 2640 | + /// the one that went have just moved up an `ord` | |
| 2641 | + /// ([`engine::Project::remove_lane`]): a selection or an open card kept | |
| 2642 | + /// across it would be pointing at the *next* track's clip. | |
| 2643 | + fn remove_lane(&mut self, lane: Lane, cx: &mut Context<Self>) { | |
| 2644 | + if self.exporting().is_some() { | |
| 2645 | + return; | |
| 2646 | + } | |
| 2647 | + let removed = self | |
| 2648 | + .session | |
| 2649 | + .as_mut() | |
| 2650 | + .map(|session| session.remove_lane(lane)); | |
| 2651 | + let text = match removed { | |
| 2652 | + Some(Ok(())) => { | |
| 2653 | + self.selected = None; | |
| 2654 | + self.context_menu = None; | |
| 2655 | + self.eq_open = None; | |
| 2656 | + self.color_open = None; | |
| 2657 | + self.speed_open = None; | |
| 2658 | + self.close_silence(); | |
| 2659 | + format!( | |
| 2660 | + "{} REMOVED — {} brings it back", | |
| 2661 | + lane.label(), | |
| 2662 | + self.keymap.display(ActionId::Undo) | |
| 2663 | + ) | |
| 2664 | + } | |
| 2665 | + Some(Err(e)) => format!("NO TRACK REMOVED — {e}"), | |
| 2666 | + None => "NO TRACK REMOVED — open a file first".to_string(), | |
| 2667 | + }; | |
| 2668 | + self.notice = Some(text.into()); | |
| 2669 | + cx.notify(); | |
| 2670 | + } | |
| 2671 | + | |
| 2672 | + /// What the remove keys act on: the last track of that kind, which is the | |
| 2673 | + /// one the matching add key appended. Nothing at all before a file is open, | |
| 2674 | + /// where the timeline drawn is a placeholder pair. | |
| 2675 | + fn remove_last_lane(&mut self, kind: LaneKind, cx: &mut Context<Self>) { | |
| 2676 | + let last = self.session.as_ref().and_then(|session| { | |
| 2677 | + session | |
| 2678 | + .lanes() | |
| 2679 | + .into_iter() | |
| 2680 | + .filter(|l| l.kind == kind) | |
| 2681 | + .next_back() | |
| 2682 | + }); | |
| 2683 | + match last { | |
| 2684 | + Some(lane) => self.remove_lane(lane, cx), | |
| 2685 | + None => { | |
| 2686 | + self.notice = Some("NO TRACK REMOVED — open a file first".into()); | |
| 2687 | + cx.notify(); | |
| 2688 | + } | |
| 2689 | + } | |
| 2690 | + } | |
| 2691 | + | |
| 2491 | 2692 | fn undo(&mut self, cx: &mut Context<Self>) { |
| 2492 | 2693 | if self.session.as_mut().is_some_and(PlaybackSession::undo) { |
| 2493 | 2694 | self.reset_after_reseek(); |
| @@ -2574,10 +2775,33 @@ impl Player { | ||
| 2574 | 2775 | cx.notify(); |
| 2575 | 2776 | } |
| 2576 | 2777 | |
| 2778 | + /// Where the pointer sits along the slider, as a level. The press and every | |
| 2779 | + /// sample after it come here, so the sound follows the hand rather than the | |
| 2780 | + /// release -- there is nothing to undo about a monitoring level, which is | |
| 2781 | + /// why this writes live and keeps no gesture state beyond the flag. | |
| 2782 | + fn drag_volume(&mut self, x: Pixels, cx: &mut Context<Self>) { | |
| 2783 | + let along = frac_along(x, self.volume_bar.get()); | |
| 2784 | + self.set_volume(|volume| volume.set_along(along), cx); | |
| 2785 | + } | |
| 2786 | + | |
| 2577 | 2787 | fn toggle_or_restart(&mut self, cx: &mut Context<Self>) { |
| 2578 | 2788 | if self.exporting().is_some() { |
| 2579 | 2789 | return; |
| 2580 | 2790 | } |
| 2791 | + // Nothing to play is a message, not a transport state. An empty | |
| 2792 | + // timeline is `done` from its one black frame onward, so the restart | |
| 2793 | + // below would start a clock against a zero-length timeline -- and it is | |
| 2794 | + // `done` again by the next repaint, so no later press could ever stop | |
| 2795 | + // it: the button would read "Pause" and never pause. A delete can empty | |
| 2796 | + // the timeline mid-play, and that press must still stop it. | |
| 2797 | + if nothing_to_play(self.session.as_ref()) { | |
| 2798 | + match self.session.as_mut().filter(|s| s.is_playing()) { | |
| 2799 | + Some(session) => session.pause(), | |
| 2800 | + None => self.notice = Some(NOTHING_TO_PLAY.into()), | |
| 2801 | + } | |
| 2802 | + cx.notify(); | |
| 2803 | + return; | |
| 2804 | + } | |
| 2581 | 2805 | if self.done { |
| 2582 | 2806 | self.seek(0., cx); |
| 2583 | 2807 | if let Some(session) = &mut self.session { |
| @@ -2805,9 +3029,19 @@ impl Render for Player { | ||
| 2805 | 3029 | div() |
| 2806 | 3030 | .track_focus(&self.focus) |
| 2807 | 3031 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { |
| 2808 | - // `is_held` filters auto-repeat, which would otherwise toggle | |
| 2809 | - // playback -- or cut the timeline -- many times a second. | |
| 2810 | - if event.is_held { | |
| 3032 | + let key = event.keystroke.key.as_str(); | |
| 3033 | + let ctrl = event.keystroke.modifiers.control; | |
| 3034 | + // `is_held` is the auto-repeat, and a value is the one thing | |
| 3035 | + // worth running on it: a held arrow on a card moves the slider | |
| 3036 | + // it picked, and a held volume key runs the volume. Everything | |
| 3037 | + // else is filtered exactly as it always was -- a repeat that | |
| 3038 | + // toggled playback, or cut the timeline, many times a second is | |
| 3039 | + // what this guard is for, and a row waiting for a stroke takes | |
| 3040 | + // none of it either (it would bind the key, then fire what it | |
| 3041 | + // just bound). See [`repeats`]. | |
| 3042 | + if event.is_held | |
| 3043 | + && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl)) | |
| 3044 | + { | |
| 2811 | 3045 | return; |
| 2812 | 3046 | } |
| 2813 | 3047 | // Any key retires the last message, whatever it was -- and owes |
| @@ -2817,7 +3051,6 @@ impl Render for Player { | ||
| 2817 | 3051 | if this.notice.take().is_some() { |
| 2818 | 3052 | cx.notify(); |
| 2819 | 3053 | } |
| 2820 | - let key = event.keystroke.key.as_str(); | |
| 2821 | 3054 | // A row is waiting for a stroke, and while it is, that stroke is |
| 2822 | 3055 | // data: it means the binding and nothing else, which is why this |
| 2823 | 3056 | // answers before the export guard and before the keymap is |
| @@ -2826,7 +3059,7 @@ impl Render for Player { | ||
| 2826 | 3059 | if key == ESCAPE { |
| 2827 | 3060 | this.rebinding = None; |
| 2828 | 3061 | } else if !is_bare_modifier(key) { |
| 2829 | - this.capture(action, key, event.keystroke.modifiers.control); | |
| 3062 | + this.capture(action, key, ctrl); | |
| 2830 | 3063 | } |
| 2831 | 3064 | cx.notify(); |
| 2832 | 3065 | return; |
| @@ -2835,7 +3068,7 @@ impl Render for Player { | ||
| 2835 | 3068 | // control modifier set (the control code is mapped back), which |
| 2836 | 3069 | // is why the keymap is keyed on the pair and never on the key |
| 2837 | 3070 | // alone. |
| 2838 | - let action = this.keymap.lookup(key, event.keystroke.modifiers.control); | |
| 3071 | + let action = this.keymap.lookup(key, ctrl); | |
| 2839 | 3072 | // An export is reading the edit list every other action here |
| 2840 | 3073 | // would change, so cancelling is the only one that means |
| 2841 | 3074 | // anything until it is over. |
| @@ -2907,6 +3140,11 @@ impl Render for Player { | ||
| 2907 | 3140 | band.gain_db = 0.; |
| 2908 | 3141 | } |
| 2909 | 3142 | this.commit_eq(cx); |
| 3143 | + } else if key == "s" { | |
| 3144 | + // The analyser off and on. Nothing is committed: it is | |
| 3145 | + // what the card *shows*, so it survives no further than | |
| 3146 | + // this window. | |
| 3147 | + this.eq_spectrum = !this.eq_spectrum; | |
| 2910 | 3148 | } else if let Ok(digit) = key.parse::<usize>() { |
| 2911 | 3149 | // 1-based, as the rows are numbered on screen; a digit |
| 2912 | 3150 | // past the last band picks nothing rather than panics. |
| @@ -3082,6 +3320,16 @@ impl Render for Player { | ||
| 3082 | 3320 | } |
| 3083 | 3321 | return; |
| 3084 | 3322 | } |
| 3323 | + // The volume slider, the same live writes: what the hand is on | |
| 3324 | + // is what the speakers are doing, and there is nothing to undo. | |
| 3325 | + if this.volume_dragging { | |
| 3326 | + if event.pressed_button == Some(MouseButton::Left) { | |
| 3327 | + this.drag_volume(event.position.x, cx); | |
| 3328 | + } else { | |
| 3329 | + this.volume_dragging = false; | |
| 3330 | + } | |
| 3331 | + return; | |
| 3332 | + } | |
| 3085 | 3333 | if !this.scrubbing { |
| 3086 | 3334 | return; |
| 3087 | 3335 | } |
| @@ -3122,6 +3370,10 @@ impl Render for Player { | ||
| 3122 | 3370 | this.drag_speed(event.position.x, false, cx); |
| 3123 | 3371 | return; |
| 3124 | 3372 | } |
| 3373 | + if std::mem::take(&mut this.volume_dragging) { | |
| 3374 | + this.drag_volume(event.position.x, cx); | |
| 3375 | + return; | |
| 3376 | + } | |
| 3125 | 3377 | if std::mem::take(&mut this.scrubbing) { |
| 3126 | 3378 | this.scrub_to(event.position.x, true, cx); |
| 3127 | 3379 | } |
| @@ -3544,8 +3796,17 @@ impl Player { | ||
| 3544 | 3796 | "transport", |
| 3545 | 3797 | Some(transport_glyph(playing).into_any_element()), |
| 3546 | 3798 | if playing { "Pause" } else { "Play" }, |
| 3547 | - key(ActionId::Play), | |
| 3548 | - live, | |
| 3799 | + if nothing_to_play(self.session.as_ref()) && !playing { | |
| 3800 | + format!("{} — put a clip on a lane first", key(ActionId::Play)) | |
| 3801 | + } else { | |
| 3802 | + key(ActionId::Play) | |
| 3803 | + }, | |
| 3804 | + // An empty timeline has nothing to play, so the button | |
| 3805 | + // says so by being dim rather than by starting a clock | |
| 3806 | + // against nothing (the key press answers with the | |
| 3807 | + // notice). Still live while it *is* playing: a delete | |
| 3808 | + // can empty the timeline mid-play and that has to stop. | |
| 3809 | + live && (playing || !nothing_to_play(self.session.as_ref())), | |
| 3549 | 3810 | cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), |
| 3550 | 3811 | )) |
| 3551 | 3812 | .child(separator()) |
| @@ -3620,6 +3881,15 @@ impl Player { | ||
| 3620 | 3881 | this.set_volume(|volume| volume.muted = !volume.muted, cx) |
| 3621 | 3882 | }), |
| 3622 | 3883 | )) |
| 3884 | + // The level itself, to drag. The button beside it stays the | |
| 3885 | + // mute -- one gesture each -- and the label above is what | |
| 3886 | + // this writes, live, so the number follows the hand. | |
| 3887 | + .child(volume_slider( | |
| 3888 | + self.volume, | |
| 3889 | + self.volume_bar.clone(), | |
| 3890 | + live, | |
| 3891 | + cx, | |
| 3892 | + )) | |
| 3623 | 3893 | .child(separator()) |
| 3624 | 3894 | // Import is not here: it belongs to the media list it adds |
| 3625 | 3895 | // to, and two doors into one action is a question about |
| @@ -4187,6 +4457,18 @@ impl Player { | ||
| 4187 | 4457 | // clip and a 48 kHz one are not the same shape. |
| 4188 | 4458 | let sample_rate = self.timeline_audio().map_or(48_000, |(rate, _)| rate); |
| 4189 | 4459 | let picked = self.eq_params.bands.get(self.eq_band); |
| 4460 | + // What is playing, drawn behind the curve -- and only while something | |
| 4461 | + // *is* playing: the tap freezes with the device, and a still spectrum | |
| 4462 | + // under a paused timeline would look like sound that is not there. | |
| 4463 | + let spectrum = self | |
| 4464 | + .eq_spectrum | |
| 4465 | + .then_some(self.session.as_ref()) | |
| 4466 | + .flatten() | |
| 4467 | + .filter(|session| session.is_playing()) | |
| 4468 | + .and_then(PlaybackSession::audio_tap) | |
| 4469 | + .map(|(samples, rate)| eq_spectrum(&samples, rate)) | |
| 4470 | + .filter(|levels| !levels.is_empty()) | |
| 4471 | + .map(eq_spectrum_curve); | |
| 4190 | 4472 | let handles: Vec<_> = self |
| 4191 | 4473 | .eq_params |
| 4192 | 4474 | .bands |
| @@ -4232,6 +4514,44 @@ impl Player { | ||
| 4232 | 4514 | }), |
| 4233 | 4515 | ) |
| 4234 | 4516 | .child(bounds_probe(self.eq_graph.clone())) |
| 4517 | + // The analyser first, so everything else is drawn on top of it. | |
| 4518 | + .children(spectrum) | |
| 4519 | + // The decades, so a hump can be read as "around 200 Hz" without | |
| 4520 | + // dropping the eye to the labels along the bottom. The two ends | |
| 4521 | + // are the box's own edges and rule nothing. | |
| 4522 | + .children( | |
| 4523 | + EQ_TICKS | |
| 4524 | + .iter() | |
| 4525 | + .filter(|(freq, _)| *freq > EQ_FREQ_LOW && *freq < EQ_FREQ_HIGH) | |
| 4526 | + .map(|(freq, _)| { | |
| 4527 | + div() | |
| 4528 | + .absolute() | |
| 4529 | + .left(relative(eq_x(*freq))) | |
| 4530 | + .w(px(1.)) | |
| 4531 | + .h_full() | |
| 4532 | + .bg(rgb(EQ_GRID)) | |
| 4533 | + }) | |
| 4534 | + .collect::<Vec<_>>(), | |
| 4535 | + ) | |
| 4536 | + // Half way to each limit, each carrying its own number: the curve | |
| 4537 | + // is a curve of decibels, and until now only one of them was drawn. | |
| 4538 | + .children(EQ_DB_GRID.map(|db| { | |
| 4539 | + div() | |
| 4540 | + .absolute() | |
| 4541 | + .top(relative(eq_y(db))) | |
| 4542 | + .w_full() | |
| 4543 | + .h(px(1.)) | |
| 4544 | + .bg(rgb(EQ_GRID)) | |
| 4545 | + .child( | |
| 4546 | + div() | |
| 4547 | + .absolute() | |
| 4548 | + .left(px(4.)) | |
| 4549 | + .top(px(-11.)) | |
| 4550 | + .text_size(px(9.)) | |
| 4551 | + .text_color(rgb(INK_DIM)) | |
| 4552 | + .child(format!("{db:+.0}")), | |
| 4553 | + ) | |
| 4554 | + })) | |
| 4235 | 4555 | // 0 dB: the line a boost is a boost *from*. |
| 4236 | 4556 | .child( |
| 4237 | 4557 | div() |
| @@ -4266,6 +4586,9 @@ impl Player { | ||
| 4266 | 4586 | .text_color(rgb(INK_DIM)) |
| 4267 | 4587 | .child(format!("+{EQ_GAIN_LIMIT:.0} dB")), |
| 4268 | 4588 | ); |
| 4589 | + // The bottom of the axis is not named: -12 dB would land in the same | |
| 4590 | + // corner as the 20 Hz tick, and the two lines above it (+6 and -6) | |
| 4591 | + // already say what the box is worth per pixel. | |
| 4269 | 4592 | Some( |
| 4270 | 4593 | div() |
| 4271 | 4594 | .absolute() |
| @@ -4300,7 +4623,7 @@ impl Player { | ||
| 4300 | 4623 | .text_size(px(11.)) |
| 4301 | 4624 | .text_color(rgb(INK_DIM)) |
| 4302 | 4625 | .child(self.notice.clone().unwrap_or_else(|| { |
| 4303 | - "drag the curve, or 1–5 then up/down — esc closes".into() | |
| 4626 | + "drag the curve, or 1–5 then up/down — s hides the spectrum, esc closes".into() | |
| 4304 | 4627 | })), |
| 4305 | 4628 | ) |
| 4306 | 4629 | .child(graph) |
| @@ -4309,34 +4632,72 @@ impl Player { | ||
| 4309 | 4632 | // one pulling the other way is not readable off it. |
| 4310 | 4633 | .child(div().flex_none().px(px(6.)).text_size(px(11.)).child( |
| 4311 | 4634 | match picked { |
| 4635 | + // Q as well as the two the curve shows: it is | |
| 4636 | + // how wide the hump under the handle is, and | |
| 4637 | + // nothing else on the card says so. | |
| 4312 | 4638 | Some(band) => format!( |
| 4313 | - "{} {} {:+.1} dB", | |
| 4639 | + "{} {} {:+.1} dB — Q {:.2}", | |
| 4314 | 4640 | self.eq_band + 1, |
| 4315 | 4641 | band_label(band), |
| 4316 | - band.gain_db | |
| 4642 | + band.gain_db, | |
| 4643 | + band.q | |
| 4317 | 4644 | ), |
| 4318 | 4645 | None => "no bands".into(), |
| 4319 | 4646 | }, |
| 4320 | 4647 | )) |
| 4321 | 4648 | .child( |
| 4322 | 4649 | div() |
| 4323 | - .id("eq-reset") | |
| 4324 | 4650 | .mt(px(4.)) |
| 4325 | 4651 | .flex() |
| 4326 | - .h(px(CONTROL_H)) | |
| 4327 | - .items_center() | |
| 4328 | - .justify_center() | |
| 4329 | - .rounded(px(3.)) | |
| 4330 | - .bg(rgb(SELECTED)) | |
| 4331 | - .cursor_pointer() | |
| 4332 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 4333 | - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 4334 | - for band in &mut this.eq_params.bands { | |
| 4335 | - band.gain_db = 0.; | |
| 4336 | - } | |
| 4337 | - this.commit_eq(cx); | |
| 4338 | - })) | |
| 4339 | - .child("Flatten"), | |
| 4652 | + .gap(px(4.)) | |
| 4653 | + .child( | |
| 4654 | + div() | |
| 4655 | + .id("eq-reset") | |
| 4656 | + .flex() | |
| 4657 | + .flex_1() | |
| 4658 | + .h(px(CONTROL_H)) | |
| 4659 | + .items_center() | |
| 4660 | + .justify_center() | |
| 4661 | + .rounded(px(3.)) | |
| 4662 | + .bg(rgb(SELECTED)) | |
| 4663 | + .cursor_pointer() | |
| 4664 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 4665 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 4666 | + for band in &mut this.eq_params.bands { | |
| 4667 | + band.gain_db = 0.; | |
| 4668 | + } | |
| 4669 | + this.commit_eq(cx); | |
| 4670 | + })) | |
| 4671 | + .child("Flatten"), | |
| 4672 | + ) | |
| 4673 | + // The analyser's switch, next to the one other | |
| 4674 | + // button the card has: `s` does the same, and a | |
| 4675 | + // toggle only a keystroke can reach is one most | |
| 4676 | + // people never find. | |
| 4677 | + .child( | |
| 4678 | + div() | |
| 4679 | + .id("eq-spectrum") | |
| 4680 | + .flex() | |
| 4681 | + .flex_1() | |
| 4682 | + .h(px(CONTROL_H)) | |
| 4683 | + .items_center() | |
| 4684 | + .justify_center() | |
| 4685 | + .rounded(px(3.)) | |
| 4686 | + .bg(rgb(match self.eq_spectrum { | |
| 4687 | + true => SELECTED, | |
| 4688 | + false => HOVER_DIM, | |
| 4689 | + })) | |
| 4690 | + .cursor_pointer() | |
| 4691 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 4692 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 4693 | + this.eq_spectrum = !this.eq_spectrum; | |
| 4694 | + cx.notify(); | |
| 4695 | + })) | |
| 4696 | + .child(match self.eq_spectrum { | |
| 4697 | + true => "Spectrum on", | |
| 4698 | + false => "Spectrum off", | |
| 4699 | + }), | |
| 4700 | + ), | |
| 4340 | 4701 | ), |
| 4341 | 4702 | ), |
| 4342 | 4703 | ) |
| @@ -4639,9 +5000,19 @@ impl Player { | ||
| 4639 | 5000 | fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { |
| 4640 | 5001 | let (lane, idx) = self.silence_open?; |
| 4641 | 5002 | let cfg = self.silence; |
| 5003 | + // The unit is a label, never a conversion: the threshold is a level | |
| 5004 | + // below full scale whichever of the two the row says (`silence_dbfs`). | |
| 5005 | + let unit = match self.silence_dbfs { | |
| 5006 | + true => "dBFS", | |
| 5007 | + false => "dB", | |
| 5008 | + }; | |
| 4642 | 5009 | let rows = [ |
| 4643 | 5010 | ("Apply to", self.silence_scope.label(&self.silence_lanes())), |
| 4644 | - ("Silence is under", format!("{:.0} dBFS", cfg.threshold_db)), | |
| 5011 | + ( | |
| 5012 | + "Silence is under", | |
| 5013 | + format!("{:.0} {unit}", cfg.threshold_db), | |
| 5014 | + ), | |
| 5015 | + ("Level read in", format!("{unit} (0 = full scale)")), | |
| 4645 | 5016 | ( |
| 4646 | 5017 | "Forgive quiet shorter than", |
| 4647 | 5018 | format!("{:.2} s", cfg.min_silence), |
| @@ -4740,7 +5111,7 @@ impl Player { | ||
| 4740 | 5111 | .text_size(px(11.)) |
| 4741 | 5112 | .text_color(rgb(INK_DIM)) |
| 4742 | 5113 | .child( |
| 4743 | - "↑↓ picks a setting, ←→ moves it — the marks on the lane are what would go; esc closes", | |
| 5114 | + "↑↓ picks a setting, ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes", | |
| 4744 | 5115 | ), |
| 4745 | 5116 | ) |
| 4746 | 5117 | .children(rows) |
| @@ -5168,6 +5539,12 @@ impl Player { | ||
| 5168 | 5539 | }); |
| 5169 | 5540 | let name = lane.label(); |
| 5170 | 5541 | let row_id: SharedString = format!("{name}-clip").into(); |
| 5542 | + let remove_id: SharedString = format!("{name}-remove").into(); | |
| 5543 | + let remove_tip: SharedString = format!( | |
| 5544 | + "Remove {name} — it must be empty first, and {} brings it back", | |
| 5545 | + self.keymap.display(ActionId::Undo) | |
| 5546 | + ) | |
| 5547 | + .into(); | |
| 5171 | 5548 | let sources = self |
| 5172 | 5549 | .session |
| 5173 | 5550 | .as_ref() |
| @@ -5197,13 +5574,37 @@ impl Player { | ||
| 5197 | 5574 | .w(px(HEADER_W)) |
| 5198 | 5575 | .h_full() |
| 5199 | 5576 | .flex() |
| 5577 | + .flex_col() | |
| 5200 | 5578 | .items_center() |
| 5201 | 5579 | .justify_center() |
| 5202 | 5580 | .rounded(px(3.)) |
| 5203 | 5581 | .bg(rgb(SURFACE)) |
| 5204 | 5582 | .text_size(px(11.)) |
| 5205 | 5583 | .text_color(rgb(INK_DIM)) |
| 5206 | - .child(name), | |
| 5584 | + .child(div().flex_1().flex().items_center().child(name)) | |
| 5585 | + // The one thing a header does: take this track away again. | |
| 5586 | + // A `HIT_MIN` target rather than a glyph-sized one, and it | |
| 5587 | + // stays put on a track holding clips instead of hiding -- | |
| 5588 | + // the refusal names them, and a control that vanishes | |
| 5589 | + // teaches nothing. | |
| 5590 | + .child( | |
| 5591 | + div() | |
| 5592 | + .id(remove_id) | |
| 5593 | + .flex_none() | |
| 5594 | + .w_full() | |
| 5595 | + .h(px(HIT_MIN)) | |
| 5596 | + .flex() | |
| 5597 | + .items_center() | |
| 5598 | + .justify_center() | |
| 5599 | + .rounded(px(3.)) | |
| 5600 | + .cursor_pointer() | |
| 5601 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 5602 | + .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) | |
| 5603 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 5604 | + this.remove_lane(lane, cx) | |
| 5605 | + })) | |
| 5606 | + .child("×"), | |
| 5607 | + ), | |
| 5207 | 5608 | ) |
| 5208 | 5609 | .child( |
| 5209 | 5610 | // Clips are placed at their own start rather than queued edge |
| @@ -6008,7 +6409,7 @@ impl Quality { | ||
| 6008 | 6409 | /// that opens but never comes back out is exactly the gap a user would other- |
| 6009 | 6410 | /// wise go looking for. |
| 6010 | 6411 | const FORMATS: [(Option<Format>, &str, &str); 9] = [ |
| 6011 | - (Some(Format::Mp4), "MP4", "H.264 picture + copied AAC"), | |
| 6412 | + (Some(Format::Mp4), "MP4", "H.264 picture + AAC sound"), | |
| 6012 | 6413 | ( |
| 6013 | 6414 | Some(Format::Av1), |
| 6014 | 6415 | "AV1", |
| @@ -6018,7 +6419,7 @@ const FORMATS: [(Option<Format>, &str, &str); 9] = [ | ||
| 6018 | 6419 | (Some(Format::Flac), "FLAC", "lossless — audio only"), |
| 6019 | 6420 | (None, "MP3", "encoder is LGPL — licence decision pending"), |
| 6020 | 6421 | (None, "OGG", "no pure-Rust Vorbis or Opus encoder"), |
| 6021 | - (None, "AAC", "no pure-Rust AAC encoder"), | |
| 6422 | + (None, "AAC", "an MP4's sound here, not a file of its own"), | |
| 6022 | 6423 | ( |
| 6023 | 6424 | None, |
| 6024 | 6425 | "HEVC", |
| @@ -6255,6 +6656,39 @@ fn cancels_export(key: &str, action: Option<ActionId>) -> bool { | ||
| 6255 | 6656 | key == ESCAPE || action == Some(ActionId::CancelExport) |
| 6256 | 6657 | } |
| 6257 | 6658 | |
| 6659 | +/// Where a held key would land, which is the whole of what auto-repeat has to | |
| 6660 | +/// know. [`Player::repeat_scope`] answers it from the same state the handler | |
| 6661 | +/// walks below itself. | |
| 6662 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] | |
| 6663 | +enum Repeat { | |
| 6664 | + /// A card with values in it owns the keyboard: equalizer, colour, speed or | |
| 6665 | + /// silence. Its arrows are sliders. | |
| 6666 | + Card, | |
| 6667 | + /// Nobody does, so the keymap answers -- and only one pair of its actions | |
| 6668 | + /// is a value being moved rather than a thing being done once. | |
| 6669 | + Keymap, | |
| 6670 | + /// A stroke is being captured, an export is running, or an overlay with no | |
| 6671 | + /// value in it is up. Nothing there is worth a repeat. | |
| 6672 | + Nothing, | |
| 6673 | +} | |
| 6674 | + | |
| 6675 | +/// Whether a *held* stroke means it again. One press is always one action; a | |
| 6676 | +/// hold is only ever a value running, so this is what tells the two apart. | |
| 6677 | +/// | |
| 6678 | +/// The cards' arrows, because that is what every one of them moves a slider | |
| 6679 | +/// with -- and only the arrows, so the equalizer's `r` cannot flatten five | |
| 6680 | +/// bands forty times a second and the silence card's `enter` cannot cut forty | |
| 6681 | +/// places again on the next tick. Outside a card the volume pair and nothing | |
| 6682 | +/// else: play, cut, delete, save, export and every other binding is a one-shot, | |
| 6683 | +/// exactly as it was when the handler filtered every held key alike. | |
| 6684 | +fn repeats(scope: Repeat, key: &str, action: Option<ActionId>) -> bool { | |
| 6685 | + match scope { | |
| 6686 | + Repeat::Card => matches!(key, "up" | "down" | "left" | "right"), | |
| 6687 | + Repeat::Keymap => matches!(action, Some(ActionId::VolumeUp | ActionId::VolumeDown)), | |
| 6688 | + Repeat::Nothing => false, | |
| 6689 | + } | |
| 6690 | +} | |
| 6691 | + | |
| 6258 | 6692 | /// The keys that are only ever half a chord. gpui delivers a lone modifier |
| 6259 | 6693 | /// press as a keystroke of its own, and taking one as a binding would leave an |
| 6260 | 6694 | /// action that fires the moment the user reaches for any chord that uses it -- |
| @@ -6553,6 +6987,59 @@ fn control( | ||
| 6553 | 6987 | }) |
| 6554 | 6988 | } |
| 6555 | 6989 | |
| 6990 | +/// The monitoring level as something to drag: 4 px of bar to look at and the | |
| 6991 | +/// whole control's height to hit (WCAG 2.5.8), the split the speed bar and the | |
| 6992 | +/// colour sliders both make. Only the level -- mute is the button beside it, so | |
| 6993 | +/// a muted slider still shows what unmuting comes back to, drawn dim. | |
| 6994 | +/// | |
| 6995 | +/// Dimmed and inert without a timeline, like every other control that would | |
| 6996 | +/// have nothing to act on. | |
| 6997 | +fn volume_slider( | |
| 6998 | + volume: Volume, | |
| 6999 | + bar: Rc<Cell<Bounds<Pixels>>>, | |
| 7000 | + enabled: bool, | |
| 7001 | + cx: &mut Context<Player>, | |
| 7002 | +) -> impl IntoElement { | |
| 7003 | + div() | |
| 7004 | + .id("volume-bar") | |
| 7005 | + .relative() | |
| 7006 | + .flex_none() | |
| 7007 | + .w(px(VOLUME_W)) | |
| 7008 | + .h(px(CONTROL_H)) | |
| 7009 | + .flex() | |
| 7010 | + .items_center() | |
| 7011 | + .tooltip(|_, cx| { | |
| 7012 | + cx.new(|_| Tip("Volume — drag to set the level; the button mutes".into())) | |
| 7013 | + .into() | |
| 7014 | + }) | |
| 7015 | + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | |
| 7016 | + .when(enabled, |d| { | |
| 7017 | + d.cursor_pointer() | |
| 7018 | + .on_mouse_down( | |
| 7019 | + MouseButton::Left, | |
| 7020 | + cx.listener(|this, event: &MouseDownEvent, _, cx| { | |
| 7021 | + this.volume_dragging = true; | |
| 7022 | + this.drag_volume(event.position.x, cx); | |
| 7023 | + }), | |
| 7024 | + ) | |
| 7025 | + .child(bounds_probe(bar)) | |
| 7026 | + }) | |
| 7027 | + .child( | |
| 7028 | + div() | |
| 7029 | + .w_full() | |
| 7030 | + .h(px(4.)) | |
| 7031 | + .rounded(px(2.)) | |
| 7032 | + .bg(rgb(SURFACE)) | |
| 7033 | + .child( | |
| 7034 | + div() | |
| 7035 | + .h_full() | |
| 7036 | + .w(relative(volume.along())) | |
| 7037 | + .rounded(px(2.)) | |
| 7038 | + .bg(rgb(if volume.muted { INK_DIM } else { ACCENT })), | |
| 7039 | + ), | |
| 7040 | + ) | |
| 7041 | +} | |
| 7042 | + | |
| 6556 | 7043 | /// The line between two groups of buttons. |
| 6557 | 7044 | fn separator() -> impl IntoElement { |
| 6558 | 7045 | div() |
| @@ -6712,6 +7199,131 @@ fn hist_curves(bins: [[u32; HIST_BINS]; 3]) -> impl IntoElement { | ||
| 6712 | 7199 | .size_full() |
| 6713 | 7200 | } |
| 6714 | 7201 | |
| 7202 | +/// In-place radix-2 FFT of `re`/`im`, whose length must be a power of two. | |
| 7203 | +/// | |
| 7204 | +/// Hand-written, and deliberately: a 1024-point transform once a frame is a | |
| 7205 | +/// few tens of microseconds of plain arithmetic, and a dependency for it would | |
| 7206 | +/// be a build cost this editor pays on every compile for one card's backdrop. | |
| 7207 | +fn fft(re: &mut [f32], im: &mut [f32]) { | |
| 7208 | + let n = re.len(); | |
| 7209 | + // Decimation in time: the input is first put in bit-reversed order, after | |
| 7210 | + // which the butterflies run over neighbours. | |
| 7211 | + let mut j = 0usize; | |
| 7212 | + for i in 1..n { | |
| 7213 | + let mut bit = n >> 1; | |
| 7214 | + while j & bit != 0 { | |
| 7215 | + j ^= bit; | |
| 7216 | + bit >>= 1; | |
| 7217 | + } | |
| 7218 | + j |= bit; | |
| 7219 | + if i < j { | |
| 7220 | + re.swap(i, j); | |
| 7221 | + im.swap(i, j); | |
| 7222 | + } | |
| 7223 | + } | |
| 7224 | + let mut span = 2; | |
| 7225 | + while span <= n { | |
| 7226 | + let step = std::f32::consts::TAU / span as f32; | |
| 7227 | + for start in (0..n).step_by(span) { | |
| 7228 | + for k in 0..span / 2 { | |
| 7229 | + // e^{-i2πk/span}: the negative sign is the forward transform. | |
| 7230 | + let (sin, cos) = (-step * k as f32).sin_cos(); | |
| 7231 | + let (a, b) = (start + k, start + k + span / 2); | |
| 7232 | + let (tr, ti) = (cos * re[b] - sin * im[b], cos * im[b] + sin * re[b]); | |
| 7233 | + re[b] = re[a] - tr; | |
| 7234 | + im[b] = im[a] - ti; | |
| 7235 | + re[a] += tr; | |
| 7236 | + im[a] += ti; | |
| 7237 | + } | |
| 7238 | + } | |
| 7239 | + span <<= 1; | |
| 7240 | + } | |
| 7241 | +} | |
| 7242 | + | |
| 7243 | +/// The played signal as one height per curve point, 0 (silence) to 1 (the top | |
| 7244 | +/// of the box) -- the analyser the response curve is drawn on top of. | |
| 7245 | +/// | |
| 7246 | +/// The newest [`EQ_FFT`] samples of the engine's tap, Hann-windowed so a tone | |
| 7247 | +/// that does not land on a bin centre is one hump rather than a smear across | |
| 7248 | +/// the axis. Each column takes the *loudest* bin between it and its | |
| 7249 | +/// neighbours: the axis is logarithmic, so one column near 20 Hz is a fraction | |
| 7250 | +/// of a bin while one near 20 kHz is hundreds, and averaging those would sink | |
| 7251 | +/// every peak up there into the noise beside it. | |
| 7252 | +/// | |
| 7253 | +/// Empty -- nothing to draw -- for a tap too short to transform, which is what | |
| 7254 | +/// a session has just after a seek. | |
| 7255 | +/// | |
| 7256 | +/// ponytail: one transform length for the whole axis, so the bass end is a bin | |
| 7257 | +/// (47 Hz at 48 kHz) wide however many columns are drawn across it -- a 60 Hz | |
| 7258 | +/// hum and an 80 Hz one are the same hump down there. Upgrade path is the | |
| 7259 | +/// analyser every mastering EQ uses: two or three transforms of different | |
| 7260 | +/// lengths, each drawn over the octaves it resolves. | |
| 7261 | +fn eq_spectrum(samples: &[f32], sample_rate: u32) -> Vec<f32> { | |
| 7262 | + if samples.len() < EQ_FFT { | |
| 7263 | + return Vec::new(); | |
| 7264 | + } | |
| 7265 | + let tail = &samples[samples.len() - EQ_FFT..]; | |
| 7266 | + let mut re: Vec<f32> = tail | |
| 7267 | + .iter() | |
| 7268 | + .enumerate() | |
| 7269 | + .map(|(i, s)| { | |
| 7270 | + let w = 0.5 * (1. - (std::f32::consts::TAU * i as f32 / EQ_FFT as f32).cos()); | |
| 7271 | + s * w | |
| 7272 | + }) | |
| 7273 | + .collect(); | |
| 7274 | + let mut im = vec![0.; EQ_FFT]; | |
| 7275 | + fft(&mut re, &mut im); | |
| 7276 | + // Magnitude per bin, scaled so a full-scale sine reads 0 dBFS: half the | |
| 7277 | + // energy is in the mirrored half of the transform, and the Hann window | |
| 7278 | + // takes another factor of two off. | |
| 7279 | + let mags: Vec<f32> = (0..EQ_FFT / 2) | |
| 7280 | + .map(|k| (re[k] * re[k] + im[k] * im[k]).sqrt() * 4. / EQ_FFT as f32) | |
| 7281 | + .collect(); | |
| 7282 | + let bin_hz = sample_rate as f32 / EQ_FFT as f32; | |
| 7283 | + let (floor, ceiling) = EQ_SPECTRUM_DB; | |
| 7284 | + let at = |along: f32| EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along); | |
| 7285 | + (0..=EQ_CURVE_STEPS) | |
| 7286 | + .map(|step| { | |
| 7287 | + let along = step as f32 / EQ_CURVE_STEPS as f32; | |
| 7288 | + let half = 0.5 / EQ_CURVE_STEPS as f32; | |
| 7289 | + // Bin 0 is DC and means nothing here, so the low end starts at 1. | |
| 7290 | + let low = (at(along - half) / bin_hz).round().max(1.) as usize; | |
| 7291 | + let high = (at(along + half) / bin_hz).round().max(1.) as usize; | |
| 7292 | + let peak = (low..=high) | |
| 7293 | + .filter_map(|k| mags.get(k)) | |
| 7294 | + .fold(0f32, |a, &b| a.max(b)); | |
| 7295 | + let db = 20. * peak.max(1e-9).log10(); | |
| 7296 | + ((db - floor) / (ceiling - floor)).clamp(0., 1.) | |
| 7297 | + }) | |
| 7298 | + .collect() | |
| 7299 | +} | |
| 7300 | + | |
| 7301 | +/// The analyser drawn as one filled shape from the floor of the box. | |
| 7302 | +fn eq_spectrum_curve(levels: Vec<f32>) -> impl IntoElement { | |
| 7303 | + canvas( | |
| 7304 | + |_, _, _| (), | |
| 7305 | + move |bounds, _, window, _| { | |
| 7306 | + let (o, s) = (bounds.origin, bounds.size); | |
| 7307 | + let last = levels.len().saturating_sub(1).max(1) as f32; | |
| 7308 | + let mut path = PathBuilder::fill(); | |
| 7309 | + path.move_to(point(o.x, o.y + s.height)); | |
| 7310 | + for (i, level) in levels.iter().enumerate() { | |
| 7311 | + path.line_to(point( | |
| 7312 | + o.x + s.width * (i as f32 / last), | |
| 7313 | + o.y + s.height * (1. - level), | |
| 7314 | + )); | |
| 7315 | + } | |
| 7316 | + path.line_to(point(o.x + s.width, o.y + s.height)); | |
| 7317 | + path.close(); | |
| 7318 | + if let Ok(path) = path.build() { | |
| 7319 | + window.paint_path(path, rgba(EQ_SPECTRUM_INK)); | |
| 7320 | + } | |
| 7321 | + }, | |
| 7322 | + ) | |
| 7323 | + .absolute() | |
| 7324 | + .size_full() | |
| 7325 | +} | |
| 7326 | + | |
| 6715 | 7327 | /// The cascade's frequency response, drawn as one line across the graph. |
| 6716 | 7328 | /// |
| 6717 | 7329 | /// Every point comes from `EqParams::response_db`, which reads the very |
| @@ -6726,14 +7338,31 @@ fn eq_curve(params: EqParams, sample_rate: u32) -> impl IntoElement { | ||
| 6726 | 7338 | |_, _, _| (), |
| 6727 | 7339 | move |bounds, _, window, _| { |
| 6728 | 7340 | let (o, s) = (bounds.origin, bounds.size); |
| 7341 | + let points: Vec<_> = (0..=EQ_CURVE_STEPS) | |
| 7342 | + .map(|step| { | |
| 7343 | + let along = step as f32 / EQ_CURVE_STEPS as f32; | |
| 7344 | + let freq = EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along); | |
| 7345 | + point( | |
| 7346 | + o.x + s.width * along, | |
| 7347 | + o.y + s.height * eq_y(params.response_db(freq, sample_rate)), | |
| 7348 | + ) | |
| 7349 | + }) | |
| 7350 | + .collect(); | |
| 7351 | + // The area between the curve and 0 dB, closed along that line: a | |
| 7352 | + // boost and a cut wind opposite ways around it, which is exactly | |
| 7353 | + // what makes both of them fill and the flat parts stay empty. | |
| 7354 | + let mut area = PathBuilder::fill(); | |
| 7355 | + area.move_to(point(o.x, o.y + s.height / 2.)); | |
| 7356 | + for at in &points { | |
| 7357 | + area.line_to(*at); | |
| 7358 | + } | |
| 7359 | + area.line_to(point(o.x + s.width, o.y + s.height / 2.)); | |
| 7360 | + area.close(); | |
| 7361 | + if let Ok(area) = area.build() { | |
| 7362 | + window.paint_path(area, rgba(EQ_FILL_INK)); | |
| 7363 | + } | |
| 6729 | 7364 | let mut path = PathBuilder::stroke(px(2.)); |
| 6730 | - for step in 0..=EQ_CURVE_STEPS { | |
| 6731 | - let along = step as f32 / EQ_CURVE_STEPS as f32; | |
| 6732 | - let freq = EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along); | |
| 6733 | - let at = point( | |
| 6734 | - o.x + s.width * along, | |
| 6735 | - o.y + s.height * eq_y(params.response_db(freq, sample_rate)), | |
| 6736 | - ); | |
| 7365 | + for (step, at) in points.into_iter().enumerate() { | |
| 6737 | 7366 | match step { |
| 6738 | 7367 | 0 => path.move_to(at), |
| 6739 | 7368 | _ => path.line_to(at), |
| @@ -6817,21 +7446,22 @@ fn timecode(t: f64, fps: f64) -> String { | ||
| 6817 | 7446 | #[cfg(test)] |
| 6818 | 7447 | mod tests { |
| 6819 | 7448 | use super::{ |
| 6820 | - ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_FREQ_HIGH, | |
| 6821 | - EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_TICKS, EXPORT_ROWS_H, FORMATS, | |
| 6822 | - Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, | |
| 6823 | - INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, | |
| 6824 | - LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_W, NO_FILE, PANEL_H, | |
| 6825 | - Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, | |
| 6826 | - SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Volume, WAVE_BPS, WAVE_COL, Wave, | |
| 6827 | - applicable, band_label, can_add, cancels_export, clipboard_after_remove, color_snap, | |
| 6828 | - envelope, eq_x, eq_y, export_path, export_settings, format_key, format_line, | |
| 6829 | - format_refusal, frac_along, frac_down, frame_at, histogram, is_bare_modifier, is_project, | |
| 6830 | - keymap, lanes_h, marked, menu_at, normalise, panel_h, project_path, push_digit, retarget, | |
| 7449 | + ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, | |
| 7450 | + EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, | |
| 7451 | + EQ_TICKS, EXPORT_ROWS_H, FORMATS, Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, | |
| 7452 | + HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H, | |
| 7453 | + LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, | |
| 7454 | + MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, | |
| 7455 | + SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, | |
| 7456 | + VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add, | |
| 7457 | + cancels_export, clipboard_after_remove, color_snap, envelope, eq_spectrum, eq_x, eq_y, | |
| 7458 | + export_path, export_settings, format_key, format_line, format_refusal, frac_along, | |
| 7459 | + frac_down, frame_at, histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, | |
| 7460 | + menu_at, normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, | |
| 6831 | 7461 | scrub_due, show_label, silence_rate, source_tint, span_partner, speed_at, start_frac, |
| 6832 | 7462 | timecode, unseen_paths, unseen_sources, whole_take, width_frac, window_title, |
| 6833 | 7463 | }; |
| 6834 | - use super::{LaneKind, file_name, file_uri, library_rows, unscannable}; | |
| 7464 | + use super::{LaneKind, Repeat, file_name, file_uri, library_rows, repeats, unscannable}; | |
| 6835 | 7465 | |
| 6836 | 7466 | /// What the file manager is handed: the parts a path keeps as they are, and |
| 6837 | 7467 | /// the ones the bus would otherwise read as something else. |
| @@ -8085,6 +8715,86 @@ mod tests { | ||
| 8085 | 8715 | assert!(KEYS_ROW_H >= HIT_MIN); |
| 8086 | 8716 | } |
| 8087 | 8717 | |
| 8718 | + /// The analyser drawn behind the curve: a tone has to land on its own | |
| 8719 | + /// frequency, or the backdrop is a decoration rather than a reading of what | |
| 8720 | + /// is playing -- and someone shaping a band against it would be aiming at | |
| 8721 | + /// the wrong octave. | |
| 8722 | + #[test] | |
| 8723 | + fn the_spectrum_puts_a_tone_under_its_own_frequency() { | |
| 8724 | + use std::f32::consts::TAU; | |
| 8725 | + let rate = 48_000u32; | |
| 8726 | + let sine = |hz: f32, amp: f32| -> Vec<f32> { | |
| 8727 | + (0..EQ_FFT) | |
| 8728 | + .map(|i| amp * (TAU * hz * i as f32 / rate as f32).sin()) | |
| 8729 | + .collect() | |
| 8730 | + }; | |
| 8731 | + | |
| 8732 | + // Silence is the floor of the box everywhere, not a band of noise. | |
| 8733 | + let quiet = eq_spectrum(&vec![0.; EQ_FFT], rate); | |
| 8734 | + assert_eq!(quiet.len(), EQ_CURVE_STEPS + 1); | |
| 8735 | + assert!(quiet.iter().all(|&l| l == 0.), "silence drew something"); | |
| 8736 | + | |
| 8737 | + // A tone peaks over its own frequency, and the columns two octaves | |
| 8738 | + // either side of it are near the floor. "Over" to within a bin down low | |
| 8739 | + // and a column up high, which is all a 1024-point transform on a log | |
| 8740 | + // axis can promise: at 200 Hz a whole column is a fraction of a bin | |
| 8741 | + // wide, so the peak sits on the bin the tone fell in. | |
| 8742 | + let column = |freq: f32| (eq_x(freq) * EQ_CURVE_STEPS as f32).round() as usize; | |
| 8743 | + let freq_at = |col: usize| { | |
| 8744 | + let along = col as f32 / EQ_CURVE_STEPS as f32; | |
| 8745 | + EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along) | |
| 8746 | + }; | |
| 8747 | + for hz in [200., 1000., 5000.] { | |
| 8748 | + let levels = eq_spectrum(&sine(hz, 0.05), rate); | |
| 8749 | + let (at, top) = | |
| 8750 | + levels | |
| 8751 | + .iter() | |
| 8752 | + .enumerate() | |
| 8753 | + .fold((0, 0f32), |best, (i, &l)| match l > best.1 { | |
| 8754 | + true => (i, l), | |
| 8755 | + false => best, | |
| 8756 | + }); | |
| 8757 | + let slack = 1.5 * rate as f32 / EQ_FFT as f32 + 0.04 * hz; | |
| 8758 | + assert!( | |
| 8759 | + (freq_at(at) - hz).abs() <= slack, | |
| 8760 | + "{hz} Hz peaked at {:.0} Hz (column {at})", | |
| 8761 | + freq_at(at) | |
| 8762 | + ); | |
| 8763 | + // -26 dBFS, which is where a 0.05 tone sits on the axis. | |
| 8764 | + let want = | |
| 8765 | + (20. * 0.05f32.log10() - EQ_SPECTRUM_DB.0) / (EQ_SPECTRUM_DB.1 - EQ_SPECTRUM_DB.0); | |
| 8766 | + assert!( | |
| 8767 | + (top - want).abs() < 0.05, | |
| 8768 | + "a -26 dBFS tone drew {top} of the box, not {want}" | |
| 8769 | + ); | |
| 8770 | + // Two octaves off is far enough down the box that the hump reads as | |
| 8771 | + // one hump: 0.4 of the axis is a little over 30 dB. | |
| 8772 | + for off in [hz / 4., hz * 4.] { | |
| 8773 | + let away = levels[column(off).min(EQ_CURVE_STEPS)]; | |
| 8774 | + assert!( | |
| 8775 | + top - away > 0.4, | |
| 8776 | + "{hz} Hz drew {top} but still {away} at {off} Hz" | |
| 8777 | + ); | |
| 8778 | + } | |
| 8779 | + } | |
| 8780 | + | |
| 8781 | + // Level reads as level: 40 dB quieter sits lower by the fraction of the | |
| 8782 | + // axis those 40 dB are. | |
| 8783 | + let loud = eq_spectrum(&sine(1000., 0.05), rate); | |
| 8784 | + let soft = eq_spectrum(&sine(1000., 0.0005), rate); | |
| 8785 | + let at = column(1000.); | |
| 8786 | + let drop = loud[at] - soft[at]; | |
| 8787 | + let (floor, ceiling) = EQ_SPECTRUM_DB; | |
| 8788 | + assert!( | |
| 8789 | + (drop - 40. / (ceiling - floor)).abs() < 0.05, | |
| 8790 | + "40 dB quieter moved the analyser {drop} of the box" | |
| 8791 | + ); | |
| 8792 | + | |
| 8793 | + // A tap the engine has not filled yet (right after a seek) draws | |
| 8794 | + // nothing at all rather than a transform of half a window. | |
| 8795 | + assert!(eq_spectrum(&[0.; 16], rate).is_empty()); | |
| 8796 | + } | |
| 8797 | + | |
| 8088 | 8798 | /// The speed bar is the same round trip -- pixels -> rate -> fill -- with |
| 8089 | 8799 | /// one thing the colour sliders do not have to promise: **exactly 1.00x has |
| 8090 | 8800 | /// to be reachable**, by a hand as well as by the reset. A grid that missed |
| @@ -8393,11 +9103,47 @@ mod tests { | ||
| 8393 | 9103 | ); |
| 8394 | 9104 | } |
| 8395 | 9105 | |
| 9106 | + /// The hold gate: a value runs, everything else still means one press one | |
| 9107 | + /// action -- which is the whole invariant the blanket `is_held` filter used | |
| 9108 | + /// to carry on its own. | |
| 9109 | + #[test] | |
| 9110 | + fn a_held_key_moves_a_value_and_nothing_else() { | |
| 9111 | + use keymap::ActionId; | |
| 9112 | + // A card's four arrows, whichever card it is. | |
| 9113 | + for key in ["up", "down", "left", "right"] { | |
| 9114 | + assert!(repeats(Repeat::Card, key, None), "{key} on a card"); | |
| 9115 | + } | |
| 9116 | + // The card's own one-shots: flatten every band, cut forty places, play | |
| 9117 | + // them fast, close. None of them on a hold. | |
| 9118 | + for key in ["r", "enter", "f", "1", "escape"] { | |
| 9119 | + assert!(!repeats(Repeat::Card, key, None), "{key} on a card"); | |
| 9120 | + } | |
| 9121 | + // Outside a card the keymap answers, and only the volume pair is a | |
| 9122 | + // value being moved. | |
| 9123 | + assert!(repeats(Repeat::Keymap, "up", Some(ActionId::VolumeUp))); | |
| 9124 | + assert!(repeats(Repeat::Keymap, "down", Some(ActionId::VolumeDown))); | |
| 9125 | + for action in ActionId::ALL { | |
| 9126 | + let held = repeats(Repeat::Keymap, "k", Some(action)); | |
| 9127 | + assert_eq!( | |
| 9128 | + held, | |
| 9129 | + matches!(action, ActionId::VolumeUp | ActionId::VolumeDown), | |
| 9130 | + "{action:?} on a hold" | |
| 9131 | + ); | |
| 9132 | + } | |
| 9133 | + // An arrow with nothing bound to it moves nothing on the timeline. | |
| 9134 | + assert!(!repeats(Repeat::Keymap, "left", None)); | |
| 9135 | + // And a stroke being captured, an export, or the overlays: nothing at | |
| 9136 | + // all, or the hold would bind a key and then fire what it just bound. | |
| 9137 | + for key in ["up", "left", "escape", "5"] { | |
| 9138 | + assert!(!repeats(Repeat::Nothing, key, Some(ActionId::VolumeUp))); | |
| 9139 | + } | |
| 9140 | + } | |
| 9141 | + | |
| 8396 | 9142 | #[test] |
| 8397 | 9143 | fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() { |
| 8398 | 9144 | // The same 640x360 floor, and this card starts below the header: a |
| 8399 | - // title and a hint over its five rows, the count line and the two | |
| 8400 | - // buttons. | |
| 9145 | + // title and a hint over its [`SILENCE_ROWS`] rows, the count line and | |
| 9146 | + // the two buttons. | |
| 8401 | 9147 | let (title, hint, count) = (17., 17., 17.); |
| 8402 | 9148 | let gaps = 6. * 5.; |
| 8403 | 9149 | let padding = 24.; |
| @@ -8728,6 +9474,116 @@ mod tests { | ||
| 8728 | 9474 | assert_eq!(source_tint(9), source_tint(1)); |
| 8729 | 9475 | assert_eq!(source_tint(usize::MAX), SOURCE_TINTS[usize::MAX % 4]); |
| 8730 | 9476 | } |
| 9477 | + | |
| 9478 | + /// The bug: an empty timeline is end-of-stream from its one black frame | |
| 9479 | + /// onward, so the pump had `done` set before anything was ever pressed -- | |
| 9480 | + /// and the transport's restart branch read that as "played out, start from | |
| 9481 | + /// the top". It started a clock against a zero-length timeline, which was | |
| 9482 | + /// `done` again by the next repaint, so every further press restarted it | |
| 9483 | + /// too: the button read "Pause" and no press of it ever paused. | |
| 9484 | + /// | |
| 9485 | + /// What holds it now is one predicate, checked here against real sessions | |
| 9486 | + /// on both sides -- the emptied one refuses, a timeline with clips on it | |
| 9487 | + /// does not. | |
| 9488 | + #[test] | |
| 9489 | + fn an_empty_timeline_has_nothing_to_play() { | |
| 9490 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | |
| 9491 | + // Silent like the engine suite: this opens the real device. | |
| 9492 | + session.set_gain(0.0); | |
| 9493 | + // A timeline with clips on it plays, and always did: the guard must not | |
| 9494 | + // touch that side. | |
| 9495 | + assert!(!session.is_empty()); | |
| 9496 | + assert!(!nothing_to_play(Some(&session))); | |
| 9497 | + | |
| 9498 | + // Every clip taken off, which is a state and not a failure. | |
| 9499 | + while session.delete_clip(Lane::V1, 0) {} | |
| 9500 | + while session.delete_clip(Lane::A1, 0) {} | |
| 9501 | + assert!(session.is_empty(), "the timeline is empty"); | |
| 9502 | + assert_eq!(session.timeline_duration(), 0.0); | |
| 9503 | + | |
| 9504 | + // What the pump does every render, and what set `done` before the fix: | |
| 9505 | + // the black frame goes by and the session is at its end at once. | |
| 9506 | + for _ in 0..40 { | |
| 9507 | + while session.try_frame().is_some() {} | |
| 9508 | + std::thread::sleep(Duration::from_millis(10)); | |
| 9509 | + } | |
| 9510 | + assert!(session.is_eos(), "an empty timeline is done before it starts"); | |
| 9511 | + | |
| 9512 | + // So the press is refused rather than sent down the restart branch -- | |
| 9513 | + // and with no session at all it is the same refusal. | |
| 9514 | + assert!(nothing_to_play(Some(&session))); | |
| 9515 | + assert!(nothing_to_play(None)); | |
| 9516 | + assert!(!session.is_playing(), "and nothing was started"); | |
| 9517 | + } | |
| 9518 | + | |
| 9519 | + /// The slider writes the same numbers the keys do, and mute is not one of | |
| 9520 | + /// them: dragging while muted picks the level unmuting comes back to. | |
| 9521 | + #[test] | |
| 9522 | + fn the_slider_lands_on_the_grid_the_keys_move_on() { | |
| 9523 | + let mut volume = Volume::default(); | |
| 9524 | + // Both ends exactly, and clamped past them. | |
| 9525 | + volume.set_along(0.); | |
| 9526 | + assert_eq!(volume.gain(), 0.0); | |
| 9527 | + assert_eq!(volume.label(), "Vol 0%"); | |
| 9528 | + volume.set_along(1.5); | |
| 9529 | + assert_eq!(volume.gain(), 1.0); | |
| 9530 | + assert_eq!(volume.along(), 1.0); | |
| 9531 | + | |
| 9532 | + // Halfway is 50%, and a key press from there is 5% -- the same step | |
| 9533 | + // count as before, on a finer grid. | |
| 9534 | + volume.set_along(0.5); | |
| 9535 | + assert_eq!(volume.label(), "Vol 50%"); | |
| 9536 | + volume.step(true); | |
| 9537 | + assert_eq!(volume.label(), "Vol 55%"); | |
| 9538 | + volume.step(false); | |
| 9539 | + assert_eq!(volume.gain(), 0.5); | |
| 9540 | + | |
| 9541 | + // A number no step lands on comes back as the nearest one, so the label | |
| 9542 | + // and the fill are the same value the device was handed. | |
| 9543 | + volume.set_along(0.333); | |
| 9544 | + assert_eq!(volume.label(), "Vol 33%"); | |
| 9545 | + assert_eq!(volume.along(), 0.33); | |
| 9546 | + | |
| 9547 | + // Muted, the drag moves the level and nothing comes out. | |
| 9548 | + volume.muted = true; | |
| 9549 | + volume.set_along(0.8); | |
| 9550 | + assert_eq!(volume.gain(), 0.0); | |
| 9551 | + assert_eq!(volume.label(), "Muted 80%"); | |
| 9552 | + volume.muted = false; | |
| 9553 | + assert_eq!(volume.gain(), 0.8); | |
| 9554 | + } | |
| 9555 | + | |
| 9556 | + /// The slider lands where it paints: the arithmetic `Player::drag_volume` | |
| 9557 | + /// runs over the bar's own painted width, which is the one thing a test of | |
| 9558 | + /// it can share without re-deriving it. | |
| 9559 | + #[test] | |
| 9560 | + fn the_volume_slider_lands_where_it_paints() { | |
| 9561 | + let bar = Bounds { | |
| 9562 | + origin: point(px(420.), px(508.)), | |
| 9563 | + size: size(px(VOLUME_W), px(CONTROL_H)), | |
| 9564 | + }; | |
| 9565 | + let at = |x: f32| { | |
| 9566 | + let mut volume = Volume::default(); | |
| 9567 | + volume.set_along(frac_along(px(x), bar)); | |
| 9568 | + volume | |
| 9569 | + }; | |
| 9570 | + assert_eq!(at(420.).gain(), 0.0, "the left end is silence"); | |
| 9571 | + assert_eq!(at(420. + VOLUME_W).gain(), 1.0, "the right end is full"); | |
| 9572 | + assert_eq!(at(-4000.).gain(), 0.0, "off the left clamps"); | |
| 9573 | + assert_eq!(at(9999.).gain(), 1.0, "off the right clamps"); | |
| 9574 | + // Every pixel along it: a level the keys could also reach, painted back | |
| 9575 | + // where the hand pressed to within the half step the rounding costs. | |
| 9576 | + for step in 0..=(VOLUME_W as u32) { | |
| 9577 | + let along = step as f32 / VOLUME_W; | |
| 9578 | + let volume = at(420. + along * VOLUME_W); | |
| 9579 | + let painted = volume.along(); | |
| 9580 | + let slack = 0.5 / f32::from(Volume::MAX_STEPS) + 1e-4; | |
| 9581 | + assert!( | |
| 9582 | + (painted - along).abs() <= slack, | |
| 9583 | + "pressed at {along}, paints at {painted}" | |
| 9584 | + ); | |
| 9585 | + } | |
| 9586 | + } | |
| 8731 | 9587 | } |
| 8732 | 9588 | |
| 8733 | 9589 | fn main() { |
| @@ -8848,6 +9704,8 @@ fn main() { | ||
| 8848 | 9704 | // Full and unmuted, which is what the session it was just |
| 8849 | 9705 | // handed is already set to: nothing to push at startup. |
| 8850 | 9706 | volume: Volume::default(), |
| 9707 | + volume_bar: Rc::default(), | |
| 9708 | + volume_dragging: false, | |
| 8851 | 9709 | // Only ever used with a timeline; 30 keeps the empty |
| 8852 | 9710 | // timecode reading in frames rather than in NaN. |
| 8853 | 9711 | fps: meta.map_or(30., |meta| meta.frame_rate), |
| @@ -8883,6 +9741,7 @@ fn main() { | ||
| 8883 | 9741 | eq_band: 0, |
| 8884 | 9742 | eq_dragging: false, |
| 8885 | 9743 | eq_graph: Rc::default(), |
| 9744 | + eq_spectrum: true, | |
| 8886 | 9745 | speed_open: None, |
| 8887 | 9746 | speed_bar: Rc::default(), |
| 8888 | 9747 | speed_dragging: false, |
| @@ -8895,6 +9754,9 @@ fn main() { | ||
| 8895 | 9754 | // one a person can widen on purpose. |
| 8896 | 9755 | silence_scope: Scope::Take, |
| 8897 | 9756 | silence_field: 0, |
| 9757 | + // The reference named, which is what the card said before | |
| 9758 | + // there was a choice about it. | |
| 9759 | + silence_dbfs: true, | |
| 8898 | 9760 | silence_marks: Vec::new(), |
| 8899 | 9761 | silence_levels: None, |
| 8900 | 9762 | color_open: None, |
crates/engine/Cargo.tomlmodified+6 -0
| @@ -23,6 +23,12 @@ image = { version = "0.25", default-features = false, features = [ | ||
| 23 | 23 | ] } |
| 24 | 24 | mp4 = "0.14" |
| 25 | 25 | rusty_h264 = { version = "0.8", default-features = false } |
| 26 | +# The AAC-LC *encoder*, so an mp4's sound can be a mix rather than a copy: an | |
| 27 | +# equalized (or otherwise processed) lane has to be decoded, and what is decoded | |
| 28 | +# has to be encoded again. Pure Rust with no C or FFI, Apache-2.0, same family | |
| 29 | +# as `rusty_h264` above. Nothing else in the ecosystem encodes AAC without | |
| 30 | +# linking Fraunhofer's C library, which this project's no-install rule forbids. | |
| 31 | +rusty_aac = "0.5" | |
| 26 | 32 | symphonia-core = "0.6" |
| 27 | 33 | symphonia-codec-aac = "0.6" |
| 28 | 34 | # The umbrella crate for the standalone audio files: one dependency instead of |
crates/engine/src/audio.rsmodified+3 -2
| @@ -657,8 +657,9 @@ impl AudioSession { | ||
| 657 | 657 | /// The raw AAC packets covering `segs` — the same half-open source-second |
| 658 | 658 | /// windows [`open_segments`](Self::open_segments) decodes — copied out |
| 659 | 659 | /// byte for byte. Nothing is decoded and nothing is re-encoded: the bytes go |
| 660 | - /// straight into an mp4 writer, which is the only way to keep audio in an | |
| 661 | - /// export at all (no pure-Rust AAC encoder exists). | |
| 660 | + /// straight into an mp4 writer, which is how an export keeps its sound exact | |
| 661 | + /// wherever the edit lets it (a lane carrying an equalizer cannot be copied | |
| 662 | + /// and is re-encoded instead -- `export::encode_audio`). | |
| 662 | 663 | /// |
| 663 | 664 | /// Cut points do not land on 1024-sample boundaries, so each segment is |
| 664 | 665 | /// rounded to whole packets against an error carried across the joins (see |
crates/engine/src/export.rsmodified+147 -57
| @@ -2,20 +2,23 @@ | ||
| 2 | 2 | //! or, picture left behind, as one WAV or FLAC of the timeline's audio alone. |
| 3 | 3 | //! |
| 4 | 4 | //! Video is fully re-encoded — a cut lands mid-GOP, so stream-copying across it |
| 5 | -//! is impossible — while audio is copied packet for packet, because there is no | |
| 6 | -//! pure-Rust AAC encoder to re-encode with. The audio-only formats have no such | |
| 7 | -//! trouble: `hound` writes PCM and `flacenc` encodes FLAC, both pure Rust, so | |
| 8 | -//! those are *decoded* out of the timeline instead of copied. The worker owns | |
| 9 | -//! everything: the caller gets an [`ExportHandle`] and polls it from its render | |
| 10 | -//! loop. | |
| 5 | +//! is impossible — while audio is copied packet for packet wherever a copy can | |
| 6 | +//! say what the timeline says: a copy is exact, free and never a generation of | |
| 7 | +//! loss. Where it *cannot* — an equalized lane, which is sample math no packet | |
| 8 | +//! copy can reach — that lane is decoded, mixed and encoded again with | |
| 9 | +//! `rusty_aac` ([`encode_audio`]). The audio-only formats have no such split: | |
| 10 | +//! `hound` writes PCM and `flacenc` encodes FLAC, so those are always *decoded* | |
| 11 | +//! out of the timeline. The worker owns everything: the caller gets an | |
| 12 | +//! [`ExportHandle`] and polls it from its render loop. | |
| 11 | 13 | //! |
| 12 | 14 | //! A **speeded** clip splits along the same line, and for the same reason. The |
| 13 | 15 | //! picture is re-encoded, so the frame walk honours a rate: it takes the source |
| 14 | 16 | //! frame each timeline frame shows ([`crate::project::Speed::source_at`], the |
| 15 | 17 | //! very frame preview holds there) and encodes a held one again rather than |
| 16 | -//! decoding it twice. The sound is *copied*, and a packet carries no rate -- so | |
| 17 | -//! a speeded clip on the one audio lane an mp4 copies is refused by name | |
| 18 | -//! ([`copy_audio`]) rather than written out at 1.00x under a re-timed picture. | |
| 18 | +//! decoding it twice. The sound is *copied* unless a filter forces a decode, and | |
| 19 | +//! a packet carries no rate -- so a speeded clip on the one audio lane an mp4 | |
| 20 | +//! copies is refused by name ([`copy_audio`]) rather than written out at 1.00x | |
| 21 | +//! under a re-timed picture. | |
| 19 | 22 | //! AV1 carries no audio at all and never meets that refusal; WAV and FLAC are |
| 20 | 23 | //! decoded and resampled, so they honour a rate like the picture does. |
| 21 | 24 | //! |
| @@ -60,21 +63,26 @@ const AV1_SPEED: u8 = 10; | ||
| 60 | 63 | |
| 61 | 64 | /// What an export writes. Four, not more: H.264-in-mp4 and AV1-in-Matroska are |
| 62 | 65 | /// the only *video* pairs with both an encoder and a decoder under this |
| 63 | -/// project's no-install rule, and WAV and FLAC are the only audio formats with | |
| 64 | -/// a pure-Rust encoder at all. MP3 has one (`shine-rs`) under LGPL-2.0, which is | |
| 65 | -/// a licensing decision this project has not taken; Vorbis, Opus and AAC have | |
| 66 | -/// none. HEVC and VP9 have no encoder here at all (`hevc`/`vp9` import through | |
| 67 | -/// the plugin and stop there). A front-end says so rather than hiding the rows. | |
| 66 | +/// project's no-install rule, and WAV and FLAC are the only *standalone* audio | |
| 67 | +/// formats with a pure-Rust encoder at all. MP3 has one (`shine-rs`) under | |
| 68 | +/// LGPL-2.0, which is a licensing decision this project has not taken; Vorbis | |
| 69 | +/// and Opus have none. (AAC does -- `rusty_aac`, which is what an equalized mp4 | |
| 70 | +/// track is encoded with -- but AAC is an mp4's own audio, never a file of its | |
| 71 | +/// own here.) HEVC and VP9 have no encoder here at all (`hevc`/`vp9` import | |
| 72 | +/// through the plugin and stop there). A front-end says so rather than hiding | |
| 73 | +/// the rows. | |
| 68 | 74 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 69 | 75 | pub enum Format { |
| 70 | - /// Picture and sound: video re-encoded, AAC copied. Copied, so it carries | |
| 71 | - /// **one** audio lane: a timeline whose sound is spread over two is refused | |
| 72 | - /// by name here and mixed by the other two formats, which decode. | |
| 76 | + /// Picture and sound: video re-encoded, AAC copied -- or re-encoded too, | |
| 77 | + /// where a copy could not carry the edit (an equalized lane). Either way it | |
| 78 | + /// carries **one** audio lane: a timeline whose sound is spread over two is | |
| 79 | + /// refused by name here and mixed by the other two formats, which decode. | |
| 73 | 80 | #[default] |
| 74 | 81 | Mp4, |
| 75 | 82 | /// Picture alone, AV1 in Matroska. Alone because Matroska carries no sound |
| 76 | - /// this project can write: there is no AAC or Opus encoder here, and an AAC | |
| 77 | - /// track copied in would be one *this engine's own reader* leaves silent | |
| 83 | + /// this project can write: this engine's Matroska writer has no audio track | |
| 84 | + /// at all, and an AAC track written into one would be one *this engine's own | |
| 85 | + /// reader* leaves silent | |
| 78 | 86 | /// (`audio::AudioSession::open` refuses Matroska audio). The sound of an AV1 |
| 79 | 87 | /// export is a WAV or FLAC beside it, which a front-end says up front. |
| 80 | 88 | Av1, |
| @@ -256,7 +264,9 @@ fn settle(shared: &Shared, result: crate::Result<()>) { | ||
| 256 | 264 | } |
| 257 | 265 | |
| 258 | 266 | /// The timeline's one audio lane, copied packet for packet: the mp4 path's |
| 259 | -/// sound, and the reason that path carries only one lane of it. | |
| 267 | +/// sound, and the reason that path carries only one lane of it. A lane an | |
| 268 | +/// equalizer has been put on cannot be *copied* at all and leaves through | |
| 269 | +/// [`encode_audio`] instead; every other timeline keeps this copy, bit for bit. | |
| 260 | 270 | /// |
| 261 | 271 | /// ponytail: this holds the whole exported AAC track in memory (~3 kB per |
| 262 | 272 | /// 23 ms packet, so ~500 MB for an hour). Upgrade path is a streaming |
| @@ -277,10 +287,15 @@ fn copy_audio( | ||
| 277 | 287 | // of a timeline playing a file's second audio track carries *that* track. |
| 278 | 288 | // |
| 279 | 289 | // One lane, because this path *copies* AAC packets and a mix is not a copy: |
| 280 | - // summing two lanes means decoding both and encoding the result, and there | |
| 281 | - // is no AAC encoder here to encode it with. Refused by name rather than | |
| 282 | - // silently exporting the first lane -- a file missing half its sound is the | |
| 283 | - // one failure a user would not notice. | |
| 290 | + // summing two lanes means decoding both, and only the one thing a copy | |
| 291 | + // cannot express at all -- an equalizer -- is decoded here today. Refused by | |
| 292 | + // name rather than silently exporting the first lane, which is a file | |
| 293 | + // missing half its sound: the one failure a user would not notice. | |
| 294 | + // | |
| 295 | + // ponytail: the ceiling is this routing, not the codec any more. | |
| 296 | + // [`encode_audio`] already mixes *every* audio lane (it is the WAV path's | |
| 297 | + // own opener), so lifting this refusal is routing a second case to it -- | |
| 298 | + // deliberately not done here, where the change under test is the equalizer. | |
| 284 | 299 | // |
| 285 | 300 | // *Which* lane is the same question `audio_segments_from` answers for |
| 286 | 301 | // playback, and it is asked here rather than assumed: the lane that holds |
| @@ -292,32 +307,29 @@ fn copy_audio( | ||
| 292 | 307 | let [segments] = &lanes[..] else { |
| 293 | 308 | return Err(format!( |
| 294 | 309 | "this timeline has {} audio lanes and an mp4 export copies one: \ |
| 295 | - there is no AAC encoder here to mix them with. Export WAV or FLAC, \ | |
| 296 | - which are mixed, or put the sound on one lane", | |
| 310 | + export WAV or FLAC, which are mixed, or put the sound on one lane", | |
| 297 | 311 | lanes.len() |
| 298 | 312 | ) |
| 299 | 313 | .into()); |
| 300 | 314 | }; |
| 301 | - // ...and the same list decides which clips this would be copying, which is | |
| 302 | - // the only way to ask whether any of them carries an equalizer. An EQ is | |
| 303 | - // sample math and a copy never decodes: exporting it here would write the | |
| 304 | - // clip flat, silently -- the same failure a missing audio track is. Named by | |
| 305 | - // where it sits on the timeline, because "some clip" is not a thing a user | |
| 306 | - // can go and fix. | |
| 315 | + // ...and the same list names *which* lane those clips sit on, which is the | |
| 316 | + // only way to ask what has been done to them. | |
| 307 | 317 | let lane = project.audio_lanes()[0]; |
| 308 | 318 | // ...and the same list decides whether any clip this would copy plays at a |
| 309 | 319 | // rate other than the one it was recorded at. A copy hands the mp4 the very |
| 310 | 320 | // AAC packets the source holds and there is no rate inside a packet to |
| 311 | 321 | // change: the picture would come out re-timed (the walk in [`run`] honours |
| 312 | 322 | // it) over sound at 1.00x, which is the drift a person finds only after the |
| 313 | - // file has gone somewhere. Refused by name, exactly as the equalizer below | |
| 314 | - // is -- and only *here*, on the lane being copied: AV1 carries no audio at | |
| 315 | - // all and never reaches this, so it honours a speed like WAV and FLAC do. | |
| 323 | + // file has gone somewhere. Refused by name -- and only *here*, on the lane | |
| 324 | + // being copied: AV1 carries no audio at all and never reaches this, so it | |
| 325 | + // honours a speed like WAV and FLAC do. | |
| 316 | 326 | // |
| 317 | - // ponytail: the ceiling is the packet copy itself, not the rate. Upgrade | |
| 318 | - // path is the same one the equalizer below wants -- an AAC encoder (or a | |
| 319 | - // decode-and-re-encode of this lane) -- at which point the resample the WAV | |
| 320 | - // path already runs feeds it and this refusal goes. | |
| 327 | + // ponytail: the ceiling is the packet copy itself, not the rate, and the way | |
| 328 | + // off it is now next door -- [`encode_audio`] resamples exactly as the WAV | |
| 329 | + // path does, so routing a speeded lane there is the one line the equalizer | |
| 330 | + // below takes. Left refused because this change is the equalizer's, and a | |
| 331 | + // speeded export turning silently from a copy into a re-encode is a change | |
| 332 | + // of its own to make on purpose. | |
| 321 | 333 | if let Some((at, speed)) = project |
| 322 | 334 | .lane(lane) |
| 323 | 335 | .iter() |
| @@ -331,28 +343,106 @@ fn copy_audio( | ||
| 331 | 343 | ) |
| 332 | 344 | .into()); |
| 333 | 345 | } |
| 334 | - if let Some((at, _)) = project | |
| 335 | - .lane(lane) | |
| 336 | - .iter() | |
| 337 | - .enumerate() | |
| 338 | - .find(|(idx, _)| { | |
| 339 | - project | |
| 340 | - .eq_of(lane, *idx) | |
| 341 | - .is_some_and(|eq| !eq.is_identity()) | |
| 342 | - }) | |
| 343 | - .map(|(idx, clip)| (clip.start, idx)) | |
| 344 | - { | |
| 345 | - return Err(format!( | |
| 346 | - "the clip at {} has an equalizer and an mp4 export copies AAC packets, \ | |
| 347 | - which no filter can reach: export WAV or FLAC, which are decoded and \ | |
| 348 | - mixed, or clear the equalizer", | |
| 349 | - timecode(at, meta.frame_rate) | |
| 350 | - ) | |
| 351 | - .into()); | |
| 346 | + // ...and last, whether any clip on it carries an equalizer. An EQ is sample | |
| 347 | + // math and a copy never decodes, so copying such a lane would write the clip | |
| 348 | + // *flat*, silently -- the failure a missing audio track is. This lane is | |
| 349 | + // decoded, filtered, mixed and encoded again instead ([`encode_audio`]), and | |
| 350 | + // only this case is: a timeline nobody has equalized still leaves through | |
| 351 | + // the copy below, packet for packet, so no passthrough quietly becomes a | |
| 352 | + // generation of loss. | |
| 353 | + let equalized = (0..project.lane(lane).len()) | |
| 354 | + .any(|idx| project.eq_of(lane, idx).is_some_and(|eq| !eq.is_identity())); | |
| 355 | + if equalized { | |
| 356 | + return encode_audio(project, meta); | |
| 352 | 357 | } |
| 353 | 358 | AudioSession::copy_multi_streams(&project.audio_sources(), segments) |
| 354 | 359 | } |
| 355 | 360 | |
| 361 | +/// The same lane, *decoded*: what a packet copy cannot carry comes out here as | |
| 362 | +/// AAC written by this project's own encoder. | |
| 363 | +/// | |
| 364 | +/// The samples are the very ones [`run_audio`] would put in a WAV -- the same | |
| 365 | +/// opener with the same equalizers, the same rates and the same resize onto the | |
| 366 | +/// timeline's own length -- so an mp4 and a WAV of one timeline are one mix, | |
| 367 | +/// not two that could disagree. | |
| 368 | +/// | |
| 369 | +/// AAC-LC's encoder delay is one 1024-frame block, which is exactly the priming | |
| 370 | +/// a reader drops when the file carries no edit list (`audio::DEFAULT_PRIMING`, | |
| 371 | +/// and [`crate::mux::Mp4Muxer`] writes none): the first packet is that delay, so | |
| 372 | +/// the sound starts at timeline frame 0 as a copied track's does. | |
| 373 | +/// | |
| 374 | +/// ponytail: the mix sits in memory as f32 before it is encoded (~46 MB a | |
| 375 | +/// minute of 48 kHz stereo), for [`run_audio`]'s reason -- `rusty_aac` buffers | |
| 376 | +/// the whole stream anyway, since it encodes its frames in parallel. Upgrade | |
| 377 | +/// path is a chunked push once that encoder streams. | |
| 378 | +#[allow(clippy::type_complexity)] | |
| 379 | +fn encode_audio( | |
| 380 | + project: &Project, | |
| 381 | + meta: &VideoMeta, | |
| 382 | +) -> crate::Result<Option<(crate::AacTrackParams, Vec<crate::AacPacket>)>> { | |
| 383 | + let sources = project.audio_sources(); | |
| 384 | + let segs = project.audio_segments_from(0, meta.frame_rate); | |
| 385 | + let eqs = project.audio_eqs_from(0, meta.frame_rate); | |
| 386 | + let speeds = project.audio_speeds_from(0, meta.frame_rate); | |
| 387 | + let Some((audio, chunks)) = | |
| 388 | + AudioSession::open_mixed_streams_speed(&sources, &segs, &eqs, &speeds)? | |
| 389 | + else { | |
| 390 | + return Ok(None); // no audio to write, exactly as a copy of nothing is | |
| 391 | + }; | |
| 392 | + let freq_index = rusty_aac::sf_index_for_rate(audio.sample_rate).ok_or_else(|| { | |
| 393 | + format!( | |
| 394 | + "{} Hz is not an AAC sample rate: export WAV or FLAC, which write it as it is", | |
| 395 | + audio.sample_rate | |
| 396 | + ) | |
| 397 | + })?; | |
| 398 | + let channels = usize::from(audio.channels.max(1)); | |
| 399 | + // The timeline's length, not the mix's: a segment resolves its window to | |
| 400 | + // whole samples on its own, so the sum can miss by a sample or two and a | |
| 401 | + // source that ran out early would leave the track short under a picture | |
| 402 | + // that is not. One resize settles both, as [`run_audio`]'s does. | |
| 403 | + let total = (f64::from(project.timeline_frames()) / meta.frame_rate | |
| 404 | + * f64::from(audio.sample_rate)) | |
| 405 | + .round() as usize | |
| 406 | + * channels; | |
| 407 | + let mut samples: Vec<f32> = Vec::with_capacity(total); | |
| 408 | + for chunk in chunks { | |
| 409 | + samples.extend(chunk.samples); | |
| 410 | + } | |
| 411 | + samples.resize(total, 0.0); | |
| 412 | + | |
| 413 | + // 256 kbps, not the encoder's 128 default: this is a *second* generation of | |
| 414 | + // lossy coding over a source that was already AAC, and the export is a | |
| 415 | + // master a person edits from again, not a delivery file. Measured on the | |
| 416 | + // suite's fixtures, an untouched clip re-encoded here moves 0.15 dB at this | |
| 417 | + // rate against 0.46 dB at 128 -- and 32 KB/s beside a 2.76 Mbps picture is | |
| 418 | + // not a size anyone is counting. | |
| 419 | + let mut encoder = rusty_aac::AacEncoder::new(rusty_aac::AacEncoderConfig { | |
| 420 | + bitrate_bps: 256_000, | |
| 421 | + ..Default::default() | |
| 422 | + }); | |
| 423 | + encoder.push_pcm(&samples, audio.channels.max(1), audio.sample_rate)?; | |
| 424 | + encoder.finish(); | |
| 425 | + let mut packets = Vec::new(); | |
| 426 | + // `next_packet` after `finish` yields packets until `Eof` and nothing else, | |
| 427 | + // so the loop ends on the only error it can see. | |
| 428 | + while let Ok(packet) = encoder.next_packet() { | |
| 429 | + packets.push(crate::AacPacket { | |
| 430 | + bytes: packet.data, | |
| 431 | + samples: packet.duration, | |
| 432 | + }); | |
| 433 | + } | |
| 434 | + Ok(Some(( | |
| 435 | + crate::AacTrackParams { | |
| 436 | + freq_index, | |
| 437 | + // 1 and 2 are the ISO channel configurations for mono and stereo, | |
| 438 | + // and the opener refuses anything wider than stereo already. | |
| 439 | + chan_conf: audio.channels.max(1) as u8, | |
| 440 | + sample_rate: audio.sample_rate, | |
| 441 | + }, | |
| 442 | + packets, | |
| 443 | + ))) | |
| 444 | +} | |
| 445 | + | |
| 356 | 446 | fn run( |
| 357 | 447 | project: &Project, |
| 358 | 448 | meta: &VideoMeta, |
crates/engine/src/playback.rsmodified+53 -1
| @@ -90,8 +90,18 @@ struct Audio { | ||
| 90 | 90 | /// Bumped by every seek. A feeder only owns the device while this still |
| 91 | 91 | /// matches the value it started with; see [`feed`]. |
| 92 | 92 | epoch: Arc<AtomicU64>, |
| 93 | + /// The last [`TAP_SAMPLES`] mono samples handed to the device, oldest | |
| 94 | + /// first: what a meter or an analyser draws. Written by the feeder, which | |
| 95 | + /// is not the device's own callback -- the plugin's RT thread never sees | |
| 96 | + /// this lock, and the feeder holds it for one memcpy per write. | |
| 97 | + tap: Arc<Mutex<Vec<f32>>>, | |
| 93 | 98 | } |
| 94 | 99 | |
| 100 | +/// How much of the played signal the tap keeps. A power of two, because what | |
| 101 | +/// reads it transforms it, and long enough that the lowest band the editor | |
| 102 | +/// draws (20 Hz) has a whole cycle in the window at any rate we open. | |
| 103 | +const TAP_SAMPLES: usize = 2048; | |
| 104 | + | |
| 95 | 105 | impl Audio { |
| 96 | 106 | /// Whether the device has played everything there will ever be, i.e. the |
| 97 | 107 | /// audio clock is about to stop meaning anything. |
| @@ -100,6 +110,21 @@ impl Audio { | ||
| 100 | 110 | && position as u64 * self.channels >= self.fed.load(Ordering::Relaxed) |
| 101 | 111 | } |
| 102 | 112 | |
| 113 | + /// Keeps the newest [`TAP_SAMPLES`] of what was just queued, downmixed to | |
| 114 | + /// mono. Called from the feeder only, once per accepted write. | |
| 115 | + fn note_tap(&self, accepted: &[f32]) { | |
| 116 | + let channels = self.channels.max(1) as usize; | |
| 117 | + let mut tap = self.tap.lock().unwrap(); | |
| 118 | + // Only the tail can survive anyway: a big write replaces the window | |
| 119 | + // outright rather than being summed into it and then thrown away. | |
| 120 | + let from = accepted.len().saturating_sub(TAP_SAMPLES * channels); | |
| 121 | + for frame in accepted[from..].chunks_exact(channels) { | |
| 122 | + tap.push(frame.iter().sum::<f32>() / channels as f32); | |
| 123 | + } | |
| 124 | + let over = tap.len().saturating_sub(TAP_SAMPLES); | |
| 125 | + tap.drain(..over); | |
| 126 | + } | |
| 127 | + | |
| 103 | 128 | /// Starts a feeder for the current epoch, draining `rx` into the device. |
| 104 | 129 | /// `false` if the thread would not start, i.e. nothing will ever be fed. |
| 105 | 130 | fn spawn_feeder(&self, rx: Receiver<AudioChunk>) -> bool { |
| @@ -922,6 +947,13 @@ impl PlaybackSession { | ||
| 922 | 947 | self.project.add_lane(kind) |
| 923 | 948 | } |
| 924 | 949 | |
| 950 | + /// Drops that empty lane again, in [`Project::remove_lane`]'s words when it | |
| 951 | + /// refuses. One undo step, and no reseek for the same reason the add needs | |
| 952 | + /// none: an empty lane was playing nothing. | |
| 953 | + pub fn remove_lane(&mut self, lane: Lane) -> crate::Result<()> { | |
| 954 | + self.project.remove_lane(lane) | |
| 955 | + } | |
| 956 | + | |
| 925 | 957 | /// Splits every lane at `timeline_secs`, so the two sides become two |
| 926 | 958 | /// groups. Metadata only: a split never changes the timeline->source |
| 927 | 959 | /// mapping, so the running decoder stays correct and playback does not |
| @@ -1232,7 +1264,7 @@ impl PlaybackSession { | ||
| 1232 | 1264 | /// [`import`](Self::import) refuses a file with. One output device and one |
| 1233 | 1265 | /// copied AAC track mean one set of audio parameters for the whole |
| 1234 | 1266 | /// timeline, so a 22 kHz mono track cannot join a 44.1 kHz stereo one -- |
| 1235 | - /// there is no resampler here, and no AAC encoder to write the join with. | |
| 1267 | + /// there is no resampler here to make one rate of two. | |
| 1236 | 1268 | /// A front-end greys such a row out; this is the backstop that keeps a |
| 1237 | 1269 | /// stale one from making the whole timeline silent. |
| 1238 | 1270 | /// |
| @@ -1547,6 +1579,21 @@ impl PlaybackSession { | ||
| 1547 | 1579 | } |
| 1548 | 1580 | } |
| 1549 | 1581 | |
| 1582 | + /// A copy of the most recent mono samples the device was handed, and the | |
| 1583 | + /// rate they play at: the signal *after* every clip's equalizer, speed and | |
| 1584 | + /// the mix, which is what an analyser drawn behind an EQ curve has to show. | |
| 1585 | + /// `None` with no audio output at all, and empty until the feeder has | |
| 1586 | + /// written once (right after a seek, for instance). | |
| 1587 | + /// | |
| 1588 | + /// Never blocks anything that matters: the feeder holds this lock for one | |
| 1589 | + /// memcpy and the device's own callback lives in the plugin, on the far | |
| 1590 | + /// side of a ring buffer, where it cannot see this at all. | |
| 1591 | + pub fn audio_tap(&self) -> Option<(Vec<f32>, u32)> { | |
| 1592 | + let audio = self.audio.as_ref()?; | |
| 1593 | + let tap = audio.tap.lock().unwrap().clone(); | |
| 1594 | + Some((tap, audio.sample_rate)) | |
| 1595 | + } | |
| 1596 | + | |
| 1550 | 1597 | /// Repositions the timeline to `secs`, clamped to the *timeline*. Both decode |
| 1551 | 1598 | /// workers are replaced rather than steered: a fresh channel cannot hold a |
| 1552 | 1599 | /// stale frame, and it works just as well after EOF, where the old workers |
| @@ -1569,6 +1616,9 @@ impl PlaybackSession { | ||
| 1569 | 1616 | // carrying can no longer reach the ring after this point. |
| 1570 | 1617 | audio.epoch.fetch_add(1, Ordering::Release); |
| 1571 | 1618 | ao.flush(); |
| 1619 | + // The flushed samples are not being played any more, so nothing may | |
| 1620 | + // still be drawn from them. | |
| 1621 | + audio.tap.lock().unwrap().clear(); | |
| 1572 | 1622 | } |
| 1573 | 1623 | |
| 1574 | 1624 | // Cancel first, drop second: the old worker may be parked in `send` on |
| @@ -1900,6 +1950,7 @@ fn open_audio(path: &Path, stream: usize) -> (Option<Audio>, Option<String>) { | ||
| 1900 | 1950 | fed_all: Arc::new(AtomicBool::new(false)), |
| 1901 | 1951 | died: Arc::new(AtomicBool::new(false)), |
| 1902 | 1952 | epoch: Arc::new(AtomicU64::new(0)), |
| 1953 | + tap: Arc::new(Mutex::new(Vec::with_capacity(TAP_SAMPLES))), | |
| 1903 | 1954 | }; |
| 1904 | 1955 | (audio.spawn_feeder(rx).then_some(audio), None) |
| 1905 | 1956 | } |
| @@ -1934,6 +1985,7 @@ fn feed(rx: Receiver<AudioChunk>, audio: &Audio, epoch: u64) { | ||
| 1934 | 1985 | } |
| 1935 | 1986 | }; |
| 1936 | 1987 | audio.fed.fetch_add(accepted as u64, Ordering::Relaxed); |
| 1988 | + audio.note_tap(&pending[..accepted]); | |
| 1937 | 1989 | pending.drain(..accepted); |
| 1938 | 1990 | if !pending.is_empty() { |
| 1939 | 1991 | // Ring full: nothing to do but let the device drain it. |
crates/engine/src/project.rsmodified+197 -3
| @@ -666,6 +666,67 @@ impl Project { | ||
| 666 | 666 | Lane::new(kind, self.lane_count(kind) - 1) |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | + /// Drops an *empty* lane -- [`add_lane`](Project::add_lane) taken back, and | |
| 670 | + /// one undo step like it, which restores the lane where it stood. | |
| 671 | + /// | |
| 672 | + /// Refused, changing nothing, while the lane holds anything: the refusal | |
| 673 | + /// names the clips (file and first frame), because a track removal that | |
| 674 | + /// deleted takes with it would be the one edit nobody sees coming. Refused | |
| 675 | + /// too for the last lane of its kind, which is `V1` or `A1`: those two are | |
| 676 | + /// where an import and a paste land ([`Project::paste`] takes lane 0 of each | |
| 677 | + /// kind and *skips* a kind that is not there), so a project without one | |
| 678 | + /// would swallow half of every file dropped on it, silently. | |
| 679 | + /// | |
| 680 | + /// The lanes below it move up one `ord`, so a handle a caller was holding | |
| 681 | + /// (a selection, an open card) names the lane after it from here on -- the | |
| 682 | + /// one thing a front-end owes this call. | |
| 683 | + pub fn remove_lane(&mut self, lane: Lane) -> crate::Result<()> { | |
| 684 | + let Some(i) = self.index(lane) else { | |
| 685 | + return Err(format!("there is no {} to remove", lane.label()).into()); | |
| 686 | + }; | |
| 687 | + if self.lane_count(lane.kind) == 1 { | |
| 688 | + return Err(format!( | |
| 689 | + "{} is the only {} track: every import lands on it", | |
| 690 | + lane.label(), | |
| 691 | + match lane.kind { | |
| 692 | + LaneKind::Video => "video", | |
| 693 | + LaneKind::Audio => "audio", | |
| 694 | + } | |
| 695 | + ) | |
| 696 | + .into()); | |
| 697 | + } | |
| 698 | + let clips = &self.lanes[i].clips; | |
| 699 | + if !clips.is_empty() { | |
| 700 | + // Three names and a count: a lane can hold forty clips and a | |
| 701 | + // refusal nobody reads to the end says nothing at all. | |
| 702 | + let named: Vec<String> = clips | |
| 703 | + .iter() | |
| 704 | + .take(3) | |
| 705 | + .map(|c| { | |
| 706 | + let name = self.sources.get(c.source).map_or_else( | |
| 707 | + || format!("source {}", c.source), | |
| 708 | + |s| s.path.display().to_string(), | |
| 709 | + ); | |
| 710 | + format!("{name} at frame {}", c.start) | |
| 711 | + }) | |
| 712 | + .collect(); | |
| 713 | + let rest = match clips.len().saturating_sub(named.len()) { | |
| 714 | + 0 => String::new(), | |
| 715 | + n => format!(" and {n} more"), | |
| 716 | + }; | |
| 717 | + return Err(format!( | |
| 718 | + "{} still holds {}{rest}: delete those clips (or drag them to \ | |
| 719 | + another track) first", | |
| 720 | + lane.label(), | |
| 721 | + named.join(", ") | |
| 722 | + ) | |
| 723 | + .into()); | |
| 724 | + } | |
| 725 | + self.snapshot(); | |
| 726 | + self.lanes.remove(i); | |
| 727 | + Ok(()) | |
| 728 | + } | |
| 729 | + | |
| 669 | 730 | /// Where `lane` sits in [`Project::lanes`], or `None` for a lane that is |
| 670 | 731 | /// not there. The one place a handle becomes a position. |
| 671 | 732 | fn index(&self, lane: Lane) -> Option<usize> { |
| @@ -1669,8 +1730,19 @@ impl Project { | ||
| 1669 | 1730 | } |
| 1670 | 1731 | self.snapshot(); |
| 1671 | 1732 | for (&(l, i), keep) in members.iter().zip(fitted) { |
| 1733 | + let still = self.is_still(&self.lanes[l].clips[i]); | |
| 1672 | 1734 | let c = &mut self.lanes[l].clips[i]; |
| 1673 | 1735 | match edge { |
| 1736 | + // A still has no earlier frame to walk an in-point back to -- | |
| 1737 | + // every frame of it is the same picture -- so its head grows | |
| 1738 | + // *forward*: the range it plays is however long the new room | |
| 1739 | + // is, anchored at the source's frame 0. Bounded by `lo`, which | |
| 1740 | + // is where the cap in `source_frames` is applied. | |
| 1741 | + Edge::Start if still => { | |
| 1742 | + c.in_frame = 0; | |
| 1743 | + c.out_frame = keep; | |
| 1744 | + c.start = to; | |
| 1745 | + } | |
| 1674 | 1746 | Edge::Start => { |
| 1675 | 1747 | // Non-negative by `lo`, which is what keeps the in-point on |
| 1676 | 1748 | // the source. |
| @@ -1711,9 +1783,24 @@ impl Project { | ||
| 1711 | 1783 | // head than the timeline has room for -- a ripple delete |
| 1712 | 1784 | // slides a clip back to frame 0 with its in-point wherever |
| 1713 | 1785 | // the cut left it -- and frame 0 is the other wall. |
| 1714 | - c.start | |
| 1715 | - .saturating_sub(c.speed.room(c.in_frame)) | |
| 1716 | - .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), | |
| 1786 | + // | |
| 1787 | + // A still is measured from its *tail* instead: it has no | |
| 1788 | + // in-point worth the name (every frame the same picture), so | |
| 1789 | + // its head reaches exactly as far as its tail does -- out to | |
| 1790 | + // the length the caller's table gives it, whole. Measured | |
| 1791 | + // from the in-point it would have no head room at all, which | |
| 1792 | + // is a placed picture whose left edge cannot be dragged out. | |
| 1793 | + // No entry in the table means no growth, as it does at the | |
| 1794 | + // other end. | |
| 1795 | + if self.is_still(&c) { | |
| 1796 | + c.end().saturating_sub( | |
| 1797 | + c.speed | |
| 1798 | + .room(source_frames.get(c.source).copied().unwrap_or(c.len())), | |
| 1799 | + ) | |
| 1800 | + } else { | |
| 1801 | + c.start.saturating_sub(c.speed.room(c.in_frame)) | |
| 1802 | + } | |
| 1803 | + .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), | |
| 1717 | 1804 | // One *frame of clip* always survives, and at a rate below |
| 1718 | 1805 | // real time one frame of clip is several frames of timeline |
| 1719 | 1806 | // ([`Speed::room`]): an edge dragged closer than that would |
| @@ -1750,6 +1837,16 @@ impl Project { | ||
| 1750 | 1837 | Some((lo, hi.max(lo))) |
| 1751 | 1838 | } |
| 1752 | 1839 | |
| 1840 | + /// Whether `clip` plays a still image ([`crate::is_image`]): a file whose | |
| 1841 | + /// every frame is the same picture, so which frame of it a clip's in-point | |
| 1842 | + /// names is not a question -- what [`Project::trim`] lets grow at either | |
| 1843 | + /// end. `false` for a source that is not there. | |
| 1844 | + fn is_still(&self, clip: &Clip) -> bool { | |
| 1845 | + self.sources | |
| 1846 | + .get(clip.source) | |
| 1847 | + .is_some_and(|s| crate::is_image(&s.path)) | |
| 1848 | + } | |
| 1849 | + | |
| 1753 | 1850 | /// The clips that move as one with the clip at `idx` of `lane` -- itself and |
| 1754 | 1851 | /// whatever carries its link on the other lanes -- as `(lane storage index, |
| 1755 | 1852 | /// clip index)` pairs. `None` for an index that is not there. |
| @@ -3422,6 +3519,56 @@ mod tests { | ||
| 3422 | 3519 | assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]); |
| 3423 | 3520 | } |
| 3424 | 3521 | |
| 3522 | + /// A still is trimmed from its head exactly as it is from its tail: it has | |
| 3523 | + /// no earlier frame to walk an in-point back to, so the wall is the length | |
| 3524 | + /// the caller's table allows it, measured back from the tail. Measured from | |
| 3525 | + /// the in-point -- which a placed picture has at 0 -- its left edge could | |
| 3526 | + /// never be dragged outwards at all. | |
| 3527 | + #[test] | |
| 3528 | + fn a_stills_head_stretches_out_like_its_tail() { | |
| 3529 | + const STILL: &str = "/nonexistent/card.png"; | |
| 3530 | + /// What a still is held to, as `PlaybackSession` fills the table in. | |
| 3531 | + const CAP: &[u32] = &[60]; | |
| 3532 | + | |
| 3533 | + let mut p = Project::single(STILL, 20); | |
| 3534 | + assert!(p.lift(Lane::A1, 0), "a picture is silent"); | |
| 3535 | + assert!(p.lift(Lane::V1, 0), "and this one is not at frame 0"); | |
| 3536 | + assert!(p.place(Lane::V1, 100, clip(0, 0, 20, 0))); | |
| 3537 | + | |
| 3538 | + // A source with no entry in the table may not grow, here as at the tail. | |
| 3539 | + assert_eq!( | |
| 3540 | + p.trim_room(Lane::V1, 0, Edge::Start, &[]), | |
| 3541 | + Some((100, 119)), | |
| 3542 | + "a length nobody told us buys no head room" | |
| 3543 | + ); | |
| 3544 | + assert_eq!( | |
| 3545 | + p.trim_room(Lane::V1, 0, Edge::Start, CAP), | |
| 3546 | + Some((60, 119)), | |
| 3547 | + "back to a whole cap's worth, one frame of clip surviving" | |
| 3548 | + ); | |
| 3549 | + assert!(p.trim(Lane::V1, 0, Edge::Start, 80, CAP)); | |
| 3550 | + assert_eq!( | |
| 3551 | + shape(&p)[0][0], | |
| 3552 | + clip(80, 0, 40, 0), | |
| 3553 | + "twenty frames longer, and still read from the source's first frame" | |
| 3554 | + ); | |
| 3555 | + // Past the cap is clamped, exactly as the tail is -- not refused. | |
| 3556 | + assert!(p.trim(Lane::V1, 0, Edge::Start, 0, CAP)); | |
| 3557 | + assert_eq!(shape(&p)[0][0], clip(60, 0, 60, 0), "a cap's worth, no more"); | |
| 3558 | + // ...and the clip in front is the nearer wall of the two: no head trim | |
| 3559 | + // may open an overlap. | |
| 3560 | + assert!(p.trim(Lane::V1, 0, Edge::Start, 90, CAP)); | |
| 3561 | + assert!(p.place(Lane::V1, 70, clip(0, 0, 15, 0))); | |
| 3562 | + assert_eq!( | |
| 3563 | + p.trim_room(Lane::V1, 1, Edge::Start, CAP), | |
| 3564 | + Some((85, 119)), | |
| 3565 | + "up to the neighbour's last frame and not over it" | |
| 3566 | + ); | |
| 3567 | + assert!(p.trim(Lane::V1, 1, Edge::Start, 0, CAP)); | |
| 3568 | + assert_eq!(shape(&p)[0][1], clip(85, 0, 35, 0), "butted against it"); | |
| 3569 | + assert!(sorted_disjoint(p.lane(Lane::V1)), "no overlap"); | |
| 3570 | + } | |
| 3571 | + | |
| 3425 | 3572 | /// Linked halves trim as one: a link is one span on however many lanes, so |
| 3426 | 3573 | /// the sound follows the picture's edge -- and the tightest wall of the two |
| 3427 | 3574 | /// is what stops both. |
| @@ -4715,6 +4862,53 @@ mod tests { | ||
| 4715 | 4862 | assert_eq!(shape(&p), shape(&three())); |
| 4716 | 4863 | } |
| 4717 | 4864 | |
| 4865 | + /// The add taken back: an empty lane comes off, a lane holding clips never | |
| 4866 | + /// does (and says which clips), the last lane of a kind never does, the | |
| 4867 | + /// lanes below the one that went move up an `ord`, and one undo puts it | |
| 4868 | + /// back where it stood. | |
| 4869 | + #[test] | |
| 4870 | + fn an_empty_lane_comes_off_again() { | |
| 4871 | + let mut p = three(); | |
| 4872 | + let v2 = p.add_lane(LaneKind::Video); | |
| 4873 | + let v3 = p.add_lane(LaneKind::Video); | |
| 4874 | + assert!(p.place(v3, 0, clip(0, 0, 3, 0))); | |
| 4875 | + let why = |r: crate::Result<()>| r.expect_err("refused").to_string(); | |
| 4876 | + let history = p.history.len(); | |
| 4877 | + | |
| 4878 | + // The last lane of its kind stays: `V1`/`A1` are where an import and a | |
| 4879 | + // paste land, and a project missing one would swallow half of a file | |
| 4880 | + // dropped on it. | |
| 4881 | + assert!(why(p.remove_lane(Lane::A1)).contains("only audio track")); | |
| 4882 | + assert_eq!( | |
| 4883 | + why(p.remove_lane(Lane::new(LaneKind::Video, 9))), | |
| 4884 | + "there is no V10 to remove" | |
| 4885 | + ); | |
| 4886 | + | |
| 4887 | + // A lane with clips on it refuses and names them: a track removal never | |
| 4888 | + // deletes a take. | |
| 4889 | + let refusal = why(p.remove_lane(v3)); | |
| 4890 | + assert!(refusal.contains("V3 still holds"), "{refusal}"); | |
| 4891 | + assert!(refusal.contains(FILE), "{refusal}"); | |
| 4892 | + assert!(refusal.contains("at frame 0"), "{refusal}"); | |
| 4893 | + assert_eq!(p.lane_spans(v3), vec![(0, 3)], "the clip is still there"); | |
| 4894 | + assert_eq!(p.history.len(), history, "a refusal snapshots nothing"); | |
| 4895 | + | |
| 4896 | + // The empty one in the middle goes, and `V3` becomes `V2` -- clip and | |
| 4897 | + // all. | |
| 4898 | + p.remove_lane(v2).expect("V2 is empty"); | |
| 4899 | + assert_eq!(p.lane_count(LaneKind::Video), 2); | |
| 4900 | + assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2]); | |
| 4901 | + assert_eq!(p.lane_spans(v2), vec![(0, 3)], "the lane below moved up"); | |
| 4902 | + assert_eq!(p.history.len(), history + 1, "one snapshot per removal"); | |
| 4903 | + invariants_hold(&p, "remove V2"); | |
| 4904 | + | |
| 4905 | + // ...and one stroke puts the empty lane back above it. | |
| 4906 | + assert!(p.undo()); | |
| 4907 | + assert_eq!(p.lane_count(LaneKind::Video), 3); | |
| 4908 | + assert!(p.lane(v2).is_empty(), "back where it stood, still empty"); | |
| 4909 | + assert_eq!(p.lane_spans(v3), vec![(0, 3)]); | |
| 4910 | + } | |
| 4911 | + | |
| 4718 | 4912 | /// The grouping rule across more than two lanes: a link id is one *span*, |
| 4719 | 4913 | /// on however many lanes carry it -- not a video/audio pair and not a |
| 4720 | 4914 | /// pairing by `ord`. So a split shares an id with every lane whose half |
crates/engine/tests/eq_audio.rsmodified+92 -50
| @@ -277,72 +277,114 @@ fn a_lane_is_equalized_before_the_mix_and_never_after_it() { | ||
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /// The export half of the same claim, through `export::start`: what is written |
| 280 | -/// is what is heard, so the WAV carries the boost at the same ratio the feeder | |
| 281 | -/// path measured. | |
| 280 | +/// is what is heard, so both audio-only formats carry the boost at the same | |
| 281 | +/// ratio the feeder path measured. Both, because both are lossless and both are | |
| 282 | +/// one `run_audio` -- a FLAC that disagreed with the WAV beside it would be the | |
| 283 | +/// writer, and this is where that would show. | |
| 282 | 284 | #[test] |
| 283 | -fn a_wav_export_carries_the_same_boost_playback_does() { | |
| 285 | +fn the_audio_only_exports_carry_the_same_boost_playback_does() { | |
| 284 | 286 | let flat = project(vec![clip(0, 0, 30)]); |
| 285 | 287 | let mut eqd = flat.clone(); |
| 286 | 288 | assert!(eqd.set_eq(Lane::A1, 0, Some(boost()))); |
| 287 | 289 | |
| 290 | + for format in [Format::Wav, Format::Flac] { | |
| 291 | + let mut written = Vec::new(); | |
| 292 | + for (name, project) in [("flat", &flat), ("eqd", &eqd)] { | |
| 293 | + let out = out_path(name, format.ext()); | |
| 294 | + let handle = engine::export::start( | |
| 295 | + project.clone(), | |
| 296 | + meta(), | |
| 297 | + &out, | |
| 298 | + &ExportSettings { | |
| 299 | + format, | |
| 300 | + ..Default::default() | |
| 301 | + }, | |
| 302 | + ); | |
| 303 | + wait(&handle, Duration::from_secs(60)).expect("an audio-only export"); | |
| 304 | + written.push(decode(&out)); | |
| 305 | + std::fs::remove_file(&out).unwrap(); | |
| 306 | + } | |
| 307 | + let [plain, boosted] = &written[..] else { | |
| 308 | + unreachable!("two exports") | |
| 309 | + }; | |
| 310 | + assert_boosted( | |
| 311 | + rms(boosted, 0.05, 0.95) / rms(plain, 0.05, 0.95), | |
| 312 | + format.name(), | |
| 313 | + ); | |
| 314 | + // ...and the same number to the ear: the export is not a second, kinder | |
| 315 | + // filter run at a different point in the chain. | |
| 316 | + let played = rms(&play(&eqd), 0.05, 0.95) / rms(&play(&flat), 0.05, 0.95); | |
| 317 | + let exported = rms(boosted, 0.05, 0.95) / rms(plain, 0.05, 0.95); | |
| 318 | + assert!( | |
| 319 | + (played - exported).abs() < 0.05, | |
| 320 | + "playback boosted by {played:.3} and {} by {exported:.3}", | |
| 321 | + format.name() | |
| 322 | + ); | |
| 323 | + } | |
| 324 | +} | |
| 325 | + | |
| 326 | +/// An mp4 export *copies* AAC packets and no filter can reach a copy, so an | |
| 327 | +/// equalized lane is decoded, mixed and encoded again instead | |
| 328 | +/// (`export::encode_audio`). The claim is the same one the WAV makes: the boost | |
| 329 | +/// is in the file, on the clip that was given it and on no other -- and the | |
| 330 | +/// track still starts where the picture does, which is what the encoder's own | |
| 331 | +/// priming packet is for. | |
| 332 | +#[test] | |
| 333 | +fn an_mp4_export_carries_the_boost_a_packet_copy_could_not() { | |
| 334 | + let flat = project(vec![clip(0, 0, 30), clip(30, 0, 30)]); | |
| 335 | + let mut eqd = flat.clone(); | |
| 336 | + assert!(eqd.set_eq(Lane::A1, 1, Some(boost()))); | |
| 337 | + | |
| 288 | 338 | let mut written = Vec::new(); |
| 289 | 339 | for (name, project) in [("flat", &flat), ("eqd", &eqd)] { |
| 290 | - let out = out_path(name, "wav"); | |
| 291 | - let handle = engine::export::start( | |
| 292 | - project.clone(), | |
| 293 | - meta(), | |
| 294 | - &out, | |
| 295 | - &ExportSettings { | |
| 296 | - format: Format::Wav, | |
| 297 | - ..Default::default() | |
| 298 | - }, | |
| 299 | - ); | |
| 300 | - wait(&handle, Duration::from_secs(60)).expect("wav export"); | |
| 340 | + let out = out_path(name, "mp4"); | |
| 341 | + let settings = ExportSettings::default(); | |
| 342 | + let handle = engine::export::start(project.clone(), meta(), &out, &settings); | |
| 343 | + wait(&handle, Duration::from_secs(180)).expect("an equalized timeline exports as mp4"); | |
| 301 | 344 | written.push(decode(&out)); |
| 302 | 345 | std::fs::remove_file(&out).unwrap(); |
| 303 | 346 | } |
| 304 | 347 | let [plain, boosted] = &written[..] else { |
| 305 | 348 | unreachable!("two exports") |
| 306 | 349 | }; |
| 307 | - assert_boosted( | |
| 308 | - rms(boosted, 0.05, 0.95) / rms(plain, 0.05, 0.95), | |
| 309 | - "wav export", | |
| 350 | + | |
| 351 | + // Two seconds of timeline, to within the one 1024-frame packet the length | |
| 352 | + // rounds up to: an encoder delay left uncompensated would show up here as a | |
| 353 | + // whole packet of shift, and in the windows below as a smeared cut. | |
| 354 | + let secs = |s: &[f32]| s.len() as f64 / 2.0 / f64::from(RATE); | |
| 355 | + println!( | |
| 356 | + "mp4 lengths: flat {:.3}s, eqd {:.3}s", | |
| 357 | + secs(plain), | |
| 358 | + secs(boosted) | |
| 310 | 359 | ); |
| 311 | - // ...and the same number to the ear: the export is not a second, kinder | |
| 312 | - // filter run at a different point in the chain. | |
| 313 | - let played = rms(&play(&eqd), 0.05, 0.95) / rms(&play(&flat), 0.05, 0.95); | |
| 314 | - let exported = rms(boosted, 0.05, 0.95) / rms(plain, 0.05, 0.95); | |
| 360 | + for samples in [plain, boosted] { | |
| 361 | + assert!( | |
| 362 | + (secs(samples) - 2.0).abs() < 1024.0 / f64::from(RATE), | |
| 363 | + "the exported track is {:.3}s of a 2.000s timeline", | |
| 364 | + secs(samples) | |
| 365 | + ); | |
| 366 | + } | |
| 367 | + | |
| 368 | + // The boost itself. Not to `assert_boosted`'s fifth of a dB: this file is | |
| 369 | + // AAC at 128 kbps measured against a *copied* one, so a fraction of a dB is | |
| 370 | + // the codec, not the filter. A dB either way is far tighter than the 12 the | |
| 371 | + // band asks for and far wider than any coding noise. | |
| 372 | + let db = 20.0 * (rms(boosted, 1.05, 1.95) / rms(plain, 1.05, 1.95)).log10(); | |
| 373 | + println!("mp4 equalized clip: {db:+.2} dB"); | |
| 315 | 374 | assert!( |
| 316 | - (played - exported).abs() < 0.05, | |
| 317 | - "playback boosted by {played:.3} and the export by {exported:.3}" | |
| 375 | + (db - f64::from(BOOST_DB)).abs() < 1.0, | |
| 376 | + "the equalized clip in the mp4 measured {db:+.2} dB, the band asks for {BOOST_DB:+.1}" | |
| 318 | 377 | ); |
| 319 | -} | |
| 320 | - | |
| 321 | -/// An mp4 export *copies* AAC packets, and no filter can reach a packet copy. | |
| 322 | -/// Refused by name, with the clip's own position in it -- silently writing the | |
| 323 | -/// clip flat is the one failure nobody would notice. | |
| 324 | -#[test] | |
| 325 | -fn an_mp4_export_refuses_an_equalized_clip_and_names_where_it_is() { | |
| 326 | - let mut p = project(vec![clip(0, 0, 30), clip(30, 0, 30)]); | |
| 327 | - assert!(p.set_eq(Lane::A1, 1, Some(boost()))); | |
| 328 | - | |
| 329 | - let out = out_path("refused", "mp4"); | |
| 330 | - let handle = engine::export::start(p.clone(), meta(), &out, &ExportSettings::default()); | |
| 331 | - let err = wait(&handle, Duration::from_secs(60)) | |
| 332 | - .expect_err("an equalized clip cannot leave through the copy path") | |
| 333 | - .to_string(); | |
| 334 | - println!("mp4 refusal: {err}"); | |
| 335 | - assert!(err.contains("00:01"), "the refusal names the clip: {err}"); | |
| 336 | - assert!(err.contains("equalizer"), "{err}"); | |
| 337 | - assert!(err.contains("WAV or FLAC"), "and the way out: {err}"); | |
| 338 | - assert!(!out.exists(), "a refused export leaves no file"); | |
| 339 | - | |
| 340 | - // Taking the curve off is all it takes -- the refusal is about the setting, | |
| 341 | - // never about the clip having once had one. | |
| 342 | - assert!(p.set_eq(Lane::A1, 1, None)); | |
| 343 | - let handle = engine::export::start(p, meta(), &out, &ExportSettings::default()); | |
| 344 | - wait(&handle, Duration::from_secs(120)).expect("a flat timeline exports as mp4"); | |
| 345 | - std::fs::remove_file(&out).unwrap(); | |
| 378 | + // The clip before it is the same sound: not to the bit -- this file is a | |
| 379 | + // re-encode and that one is a copy -- but to a fraction of a dB, which is | |
| 380 | + // what says the filter stopped at the cut rather than lifting the lot. | |
| 381 | + let leak = 20.0 * (rms(boosted, 0.05, 0.95) / rms(plain, 0.05, 0.95)).log10(); | |
| 382 | + println!("mp4 flat clip moved {leak:+.2} dB"); | |
| 383 | + assert!(leak.abs() < 0.5, "the flat clip moved {leak:+.2} dB"); | |
| 384 | + | |
| 385 | + // ...and a timeline nobody equalized never reaches the encoder at all: its | |
| 386 | + // audio track is still the source's own packets, which | |
| 387 | + // `export::exported_packets_are_the_copied_stream` holds to the byte. | |
| 346 | 388 | } |
| 347 | 389 | |
| 348 | 390 | /// A band moved while the timeline is playing: `PlaybackSession::set_eq` writes |
crates/engine/tests/images.rsmodified+19 -0
| @@ -208,6 +208,25 @@ fn a_still_trims_out_to_its_cap_and_no_further() { | ||
| 208 | 208 | // ...and back in, which is the half a five-second title card actually uses. |
| 209 | 209 | assert!(session.trim_clip(Lane::V1, 0, Edge::End, clip.start + 60)); |
| 210 | 210 | assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60); |
| 211 | + | |
| 212 | + // The *head* is the same story from the other side: a still has no first | |
| 213 | + // frame to walk an in-point back to, so its left edge stretches out to the | |
| 214 | + // same cap. Pulled in first, since a clip at frame 0 has nowhere to go. | |
| 215 | + assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 20)); | |
| 216 | + let clip = session.lane_clips(Lane::V1)[0]; | |
| 217 | + assert_eq!((clip.start, clip.len()), (20, 40)); | |
| 218 | + assert_eq!( | |
| 219 | + session.trim_room(Lane::V1, 0, Edge::Start), | |
| 220 | + Some((0, clip.end() - 1)), | |
| 221 | + "out to frame 0: the cap is further off than the timeline reaches" | |
| 222 | + ); | |
| 223 | + assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 0), "dragged out"); | |
| 224 | + let clip = session.lane_clips(Lane::V1)[0]; | |
| 225 | + assert_eq!( | |
| 226 | + (clip.start, clip.in_frame, clip.len()), | |
| 227 | + (0, 0, 60), | |
| 228 | + "longer by what the head took, and still read from the first frame" | |
| 229 | + ); | |
| 211 | 230 | } |
| 212 | 231 | |
| 213 | 232 | /// The *clipboard* door, which is the second way a clip picks its lanes and |