🔀 merge(T1): mkv HEVC + 5.1 AAC import meets the EQ export
Browse files at this commit9 changed files +2661 -320
- crates/app/src/keymap.rs +67 -7
- crates/app/src/main.rs +1819 -147
- crates/engine/Cargo.toml +12 -6
- crates/engine/src/audio.rs +19 -9
- crates/engine/src/export.rs +148 -58
- crates/engine/src/playback.rs +158 -17
- crates/engine/src/project.rs +238 -26
- crates/engine/tests/eq_audio.rs +92 -50
- crates/engine/tests/images.rs +108 -0
crates/app/src/keymap.rsmodified+67 -7
| @@ -63,9 +63,14 @@ pub enum ActionId { | ||
| 63 | 63 | Color, |
| 64 | 64 | Fit, |
| 65 | 65 | Resolution, |
| 66 | + ZoomIn, | |
| 67 | + ZoomOut, | |
| 68 | + ZoomFit, | |
| 66 | 69 | Undo, |
| 67 | 70 | AddVideoLane, |
| 68 | 71 | AddAudioLane, |
| 72 | + RemoveVideoLane, | |
| 73 | + RemoveAudioLane, | |
| 69 | 74 | ToggleMute, |
| 70 | 75 | VolumeUp, |
| 71 | 76 | VolumeDown, |
| @@ -78,7 +83,7 @@ pub enum ActionId { | ||
| 78 | 83 | impl ActionId { |
| 79 | 84 | /// Display order everywhere -- the editor lists them in it and |
| 80 | 85 | /// [`Keymap::defaults`] binds them in it. |
| 81 | - pub const ALL: [ActionId; 33] = [ | |
| 86 | + pub const ALL: [ActionId; 38] = [ | |
| 82 | 87 | ActionId::Play, |
| 83 | 88 | ActionId::StepBack, |
| 84 | 89 | ActionId::StepForward, |
| @@ -102,9 +107,14 @@ impl ActionId { | ||
| 102 | 107 | ActionId::Color, |
| 103 | 108 | ActionId::Fit, |
| 104 | 109 | ActionId::Resolution, |
| 110 | + ActionId::ZoomIn, | |
| 111 | + ActionId::ZoomOut, | |
| 112 | + ActionId::ZoomFit, | |
| 105 | 113 | ActionId::Undo, |
| 106 | 114 | ActionId::AddVideoLane, |
| 107 | 115 | ActionId::AddAudioLane, |
| 116 | + ActionId::RemoveVideoLane, | |
| 117 | + ActionId::RemoveAudioLane, | |
| 108 | 118 | ActionId::ToggleMute, |
| 109 | 119 | ActionId::VolumeUp, |
| 110 | 120 | ActionId::VolumeDown, |
| @@ -140,9 +150,14 @@ impl ActionId { | ||
| 140 | 150 | ActionId::Color => "Colour…", |
| 141 | 151 | ActionId::Fit => "Fit policy: fit → fill → stretch → centre", |
| 142 | 152 | ActionId::Resolution => "Project resolution: source → 2160p → 1080p → 720p → 480p", |
| 153 | + ActionId::ZoomIn => "Zoom in on the timeline (around the playhead)", | |
| 154 | + ActionId::ZoomOut => "Zoom out of the timeline", | |
| 155 | + ActionId::ZoomFit => "Fit the whole timeline on screen", | |
| 143 | 156 | ActionId::Undo => "Undo", |
| 144 | 157 | ActionId::AddVideoLane => "Add a video track", |
| 145 | 158 | ActionId::AddAudioLane => "Add an audio track", |
| 159 | + ActionId::RemoveVideoLane => "Remove the last video track (it must be empty)", | |
| 160 | + ActionId::RemoveAudioLane => "Remove the last audio track (it must be empty)", | |
| 146 | 161 | ActionId::ToggleMute => "Mute / Unmute", |
| 147 | 162 | ActionId::VolumeUp => "Volume up", |
| 148 | 163 | ActionId::VolumeDown => "Volume down", |
| @@ -180,9 +195,14 @@ impl ActionId { | ||
| 180 | 195 | ActionId::Color => "color", |
| 181 | 196 | ActionId::Fit => "fit", |
| 182 | 197 | ActionId::Resolution => "resolution", |
| 198 | + ActionId::ZoomIn => "zoom-in", | |
| 199 | + ActionId::ZoomOut => "zoom-out", | |
| 200 | + ActionId::ZoomFit => "zoom-fit", | |
| 183 | 201 | ActionId::Undo => "undo", |
| 184 | 202 | ActionId::AddVideoLane => "add-video-lane", |
| 185 | 203 | ActionId::AddAudioLane => "add-audio-lane", |
| 204 | + ActionId::RemoveVideoLane => "remove-video-lane", | |
| 205 | + ActionId::RemoveAudioLane => "remove-audio-lane", | |
| 186 | 206 | ActionId::ToggleMute => "toggle-mute", |
| 187 | 207 | ActionId::VolumeUp => "volume-up", |
| 188 | 208 | ActionId::VolumeDown => "volume-down", |
| @@ -228,14 +248,20 @@ impl ActionId { | ||
| 228 | 248 | | ActionId::Silence => Category::Clips, |
| 229 | 249 | // The project's own picture size is not a clip's business, and not |
| 230 | 250 | // a file operation either: it is what the viewer is looking at. |
| 231 | - ActionId::Resolution => Category::View, | |
| 251 | + // Neither is how much of the timeline the panel shows: a zoom edits | |
| 252 | + // nothing, it magnifies. | |
| 253 | + ActionId::Resolution | ActionId::ZoomIn | ActionId::ZoomOut | ActionId::ZoomFit => { | |
| 254 | + Category::View | |
| 255 | + } | |
| 232 | 256 | ActionId::Cut |
| 233 | 257 | | ActionId::Regroup |
| 234 | 258 | | ActionId::Detach |
| 235 | 259 | | ActionId::Group |
| 236 | 260 | | ActionId::Undo |
| 237 | 261 | | ActionId::AddVideoLane |
| 238 | - | ActionId::AddAudioLane => Category::Editing, | |
| 262 | + | ActionId::AddAudioLane | |
| 263 | + | ActionId::RemoveVideoLane | |
| 264 | + | ActionId::RemoveAudioLane => Category::Editing, | |
| 239 | 265 | ActionId::ToggleMute |
| 240 | 266 | | ActionId::VolumeUp |
| 241 | 267 | | ActionId::VolumeDown |
| @@ -291,7 +317,15 @@ pub struct Fixed { | ||
| 291 | 317 | pub category: Category, |
| 292 | 318 | } |
| 293 | 319 | |
| 294 | -pub const FIXED: [Fixed; 14] = [ | |
| 320 | +pub const FIXED: [Fixed; 16] = [ | |
| 321 | + // Not a chord at all but a way of pressing one, and the only place the | |
| 322 | + // editor can say so: holding a key that moves a *value* runs it, and | |
| 323 | + // holding anything else still does what one press did. | |
| 324 | + Fixed { | |
| 325 | + chord: "hold ← → ↑ ↓", | |
| 326 | + label: "Run a card's slider, or the volume and zoom keys, while held", | |
| 327 | + category: Category::View, | |
| 328 | + }, | |
| 295 | 329 | Fixed { |
| 296 | 330 | chord: "esc", |
| 297 | 331 | label: "Close this card or menu, or cancel a capture", |
| @@ -340,6 +374,11 @@ pub const FIXED: [Fixed; 14] = [ | ||
| 340 | 374 | label: "Flatten every band", |
| 341 | 375 | category: Category::Audio, |
| 342 | 376 | }, |
| 377 | + Fixed { | |
| 378 | + chord: "s", | |
| 379 | + label: "Show or hide the spectrum behind the curve", | |
| 380 | + category: Category::Audio, | |
| 381 | + }, | |
| 343 | 382 | // The colour card's own three, which mean nothing outside it -- the same |
| 344 | 383 | // card-local input the export card's digits are. |
| 345 | 384 | Fixed { |
| @@ -521,6 +560,14 @@ impl Keymap { | ||
| 521 | 560 | // it changes what every clip is composed onto. |
| 522 | 561 | b(ActionId::Fit, "p", false), |
| 523 | 562 | b(ActionId::Resolution, "r", true), |
| 563 | + // The zoom pair, on the chords every editor and every browser | |
| 564 | + // magnifies with. The bare "=" and "-" are the volume keys, so | |
| 565 | + // these take the ctrl versions of them -- and ctrl+0 is the | |
| 566 | + // "back to 100%" of the same family, which here is the whole | |
| 567 | + // timeline across the bed. | |
| 568 | + b(ActionId::ZoomIn, "=", true), | |
| 569 | + b(ActionId::ZoomOut, "-", true), | |
| 570 | + b(ActionId::ZoomFit, "0", true), | |
| 524 | 571 | b(ActionId::Undo, "z", false), |
| 525 | 572 | b(ActionId::Undo, "z", true), |
| 526 | 573 | // The unshifted initials of what they add. Both were free -- |
| @@ -528,6 +575,13 @@ impl Keymap { | ||
| 528 | 575 | // is added often enough to deserve a key that is one press. |
| 529 | 576 | b(ActionId::AddVideoLane, "v", false), |
| 530 | 577 | b(ActionId::AddAudioLane, "a", false), |
| 578 | + // ...and the pair that takes one back, on ctrl chords: removing | |
| 579 | + // a track is not a stroke to hit by accident (the resolution key | |
| 580 | + // is out of the way for the same reason). Ctrl+v would be the | |
| 581 | + // matching initial and is the paste, so the video one takes the | |
| 582 | + // key beside it. | |
| 583 | + b(ActionId::RemoveVideoLane, "b", true), | |
| 584 | + b(ActionId::RemoveAudioLane, "a", true), | |
| 531 | 585 | b(ActionId::ToggleMute, "m", false), |
| 532 | 586 | // The unshifted pair, which is what gpui reports for those two |
| 533 | 587 | // keys ("=" and "-", platform.rs:862): the volume keys every |
| @@ -809,7 +863,7 @@ mod tests { | ||
| 809 | 863 | #[test] |
| 810 | 864 | fn every_default_stroke_reaches_its_action() { |
| 811 | 865 | let k = Keymap::defaults(); |
| 812 | - assert_eq!(k.entries().len(), 35); | |
| 866 | + assert_eq!(k.entries().len(), 40); | |
| 813 | 867 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); |
| 814 | 868 | // The seek keys: bare arrows a frame, ctrl arrows a second, and the two |
| 815 | 869 | // ends of the timeline. |
| @@ -843,6 +897,10 @@ mod tests { | ||
| 843 | 897 | // The track keys are the bare letters; the ctrl ones stay copy/paste. |
| 844 | 898 | assert_eq!(k.lookup("v", false), Some(ActionId::AddVideoLane)); |
| 845 | 899 | assert_eq!(k.lookup("a", false), Some(ActionId::AddAudioLane)); |
| 900 | + // ...and the ctrl ones take a track away, out of the way of a stray | |
| 901 | + // press. Ctrl+v is the paste, so the video one sits beside it. | |
| 902 | + assert_eq!(k.lookup("b", true), Some(ActionId::RemoveVideoLane)); | |
| 903 | + assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane)); | |
| 846 | 904 | assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute)); |
| 847 | 905 | assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer)); |
| 848 | 906 | // The volume pair is the unshifted one, so neither needs a modifier |
| @@ -981,7 +1039,8 @@ mod tests { | ||
| 981 | 1039 | // A bindable chord is one `rebind_action` may keep: what it writes is |
| 982 | 1040 | // what the next load reads, for every stroke that passes here. |
| 983 | 1041 | let mut k = Keymap::defaults(); |
| 984 | - k.rebind_action(ActionId::Play, chord("=", true)).unwrap(); | |
| 1042 | + // Any free chord will do here; ctrl+= is the zoom's. | |
| 1043 | + k.rebind_action(ActionId::Play, chord("w", true)).unwrap(); | |
| 985 | 1044 | assert_eq!(whole(&emit(&k)), k); |
| 986 | 1045 | } |
| 987 | 1046 | |
| @@ -1038,7 +1097,8 @@ mod tests { | ||
| 1038 | 1097 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); |
| 1039 | 1098 | // The label is the editor's column, and never the file's word for it. |
| 1040 | 1099 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); |
| 1041 | - assert_eq!(ActionId::ALL.len(), 33); | |
| 1100 | + assert_eq!(ActionId::ALL.len(), 38); | |
| 1101 | + assert_eq!(k.display(ActionId::ZoomIn), "ctrl+="); | |
| 1042 | 1102 | } |
| 1043 | 1103 | |
| 1044 | 1104 | #[test] |
crates/app/src/main.rsmodified+1819 -147
Diff too large; view file
| @@ -19,9 +19,9 @@ use engine::{Clip, ExportHandle, Frame, PlaybackSession}; | ||
| 19 | 19 | use gpui::{ |
| 20 | 20 | AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, FocusHandle, |
| 21 | 21 | KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, |
| 22 | - Point, RenderImage, SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, | |
| 23 | - WindowBounds, WindowOptions, canvas, div, img, point, prelude::*, px, relative, rgb, rgba, | |
| 24 | - size, | |
| 22 | + Point, RenderImage, ScrollDelta, ScrollWheelEvent, SharedString, Size, Stateful, TextAlign, | |
| 23 | + TitlebarOptions, Window, WindowBounds, WindowOptions, canvas, div, img, point, prelude::*, px, | |
| 24 | + relative, rgb, rgba, size, | |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | 27 | /// Editor chrome: three grays and one accent, all darker than the picture so the |
| @@ -74,6 +74,11 @@ const LABEL_MIN_W: f32 = 36.; | ||
| 74 | 74 | /// allocates one bucket per window, so a rate taken from anything the user can |
| 75 | 75 | /// influence is an allocation bomb -- and 40 is already finer than the pixels a |
| 76 | 76 | /// clip is ever given. |
| 77 | +/// | |
| 78 | +/// ponytail: "finer than the pixels" stops being true once the timeline is | |
| 79 | +/// zoomed -- past ~25 ms per bucket the envelope reads as steps rather than as | |
| 80 | +/// a shape. Ceiling: [`View::max_zoom`]'s 8 frames across the bed. The upgrade | |
| 81 | +/// is a second, finer pass over the visible span only, cached like `waves` is. | |
| 77 | 82 | const WAVE_BPS: u32 = 40; |
| 78 | 83 | /// Pixels per envelope column. Coarser than a pixel: the eye reads the shape, |
| 79 | 84 | /// and a path with a point per pixel is a path per repaint. |
| @@ -95,6 +100,9 @@ const ROW_H: f32 = 32.; | ||
| 95 | 100 | /// wear in the lanes, which is the whole of the panel<->timeline association. |
| 96 | 101 | const SWATCH_W: f32 = 4.; |
| 97 | 102 | const CONTROL_H: f32 = 28.; |
| 103 | +/// The volume slider beside its button: a hundred steps across it, so a pixel | |
| 104 | +/// is finer than a step and the drag reads as continuous. | |
| 105 | +const VOLUME_W: f32 = 110.; | |
| 98 | 106 | const RULER_HIT_H: f32 = HIT_MIN; |
| 99 | 107 | /// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits |
| 100 | 108 | /// cannot push the layout around. |
| @@ -117,6 +125,11 @@ const EXPORT_ROWS_H: f32 = 8. * KEYS_ROW_H; | ||
| 117 | 125 | const MENU_W: f32 = 260.; |
| 118 | 126 | const MENU_ROW_H: f32 = HIT_MIN; |
| 119 | 127 | const MENU_PAD: f32 = 6.; |
| 128 | +/// How much of the item list is on screen at once, capped and scrolling like the | |
| 129 | +/// keybindings and export lists: every action the pointer can reach is an item | |
| 130 | +/// here, and a menu taller than the 640x360 floor would hang its last items off | |
| 131 | +/// the bottom edge, where nobody can click them. | |
| 132 | +const MENU_ROWS_H: f32 = 12. * MENU_ROW_H; | |
| 120 | 133 | |
| 121 | 134 | /// The one key name this file still spells out, and gpui's spelling of it: it |
| 122 | 135 | /// is the way out of a capture and out of the overlay, and both have to work |
| @@ -128,6 +141,18 @@ const ESCAPE: &str = "escape"; | ||
| 128 | 141 | /// as a program name rather than as a file name. |
| 129 | 142 | const NO_FILE: &str = "no file open"; |
| 130 | 143 | |
| 144 | +/// What a press of play says when there is nothing to play: no timeline at all | |
| 145 | +/// and an emptied one are the same answer to the user, so they are one line. | |
| 146 | +const NOTHING_TO_PLAY: &str = "NOTHING TO PLAY — put a clip on the timeline first"; | |
| 147 | + | |
| 148 | +/// Whether a press of play would have anything to play. No timeline at all and | |
| 149 | +/// one every clip has been taken off are the same state to a transport, and the | |
| 150 | +/// button and the key both have to give the same answer to it -- so there is | |
| 151 | +/// one of them, and it is free of the window so it can be checked without one. | |
| 152 | +fn nothing_to_play(session: Option<&PlaybackSession>) -> bool { | |
| 153 | + session.is_none_or(PlaybackSession::is_empty) | |
| 154 | +} | |
| 155 | + | |
| 131 | 156 | /// What the monitoring output is set to. Two things, not one: the level the |
| 132 | 157 | /// user picked, and whether it is being held silent -- so unmuting comes back |
| 133 | 158 | /// to the level rather than to a guess. |
| @@ -146,29 +171,45 @@ struct Volume { | ||
| 146 | 171 | } |
| 147 | 172 | |
| 148 | 173 | impl Volume { |
| 149 | - /// 5% a press: twenty of them across the range. | |
| 150 | - const MAX_STEPS: u8 = 20; | |
| 174 | + /// One step is one percent: fine enough that a drag along the slider reads | |
| 175 | + /// as continuous, and still a count rather than a float. | |
| 176 | + const MAX_STEPS: u8 = 100; | |
| 177 | + | |
| 178 | + /// 5% a press: twenty presses across the range, which is what the keys have | |
| 179 | + /// always moved. The slider is what the finer grid is for. | |
| 180 | + const KEY_STEP: u8 = 5; | |
| 151 | 181 | |
| 152 | 182 | /// What the device is set to: mute wins, and the level is what it returns |
| 153 | 183 | /// to. `0.0..=1.0`, which is the range the plugin's ABI accepts. |
| 154 | 184 | fn gain(self) -> f32 { |
| 155 | - if self.muted { | |
| 156 | - 0. | |
| 157 | - } else { | |
| 158 | - f32::from(self.steps) / f32::from(Self::MAX_STEPS) | |
| 159 | - } | |
| 185 | + if self.muted { 0. } else { self.along() } | |
| 160 | 186 | } |
| 161 | 187 | |
| 162 | 188 | /// One press up or down, clamped at both ends -- saturating, so the count |
| 163 | 189 | /// cannot wrap past silence into full volume. |
| 164 | 190 | fn step(&mut self, up: bool) { |
| 165 | 191 | self.steps = if up { |
| 166 | - self.steps.saturating_add(1).min(Self::MAX_STEPS) | |
| 192 | + self.steps.saturating_add(Self::KEY_STEP).min(Self::MAX_STEPS) | |
| 167 | 193 | } else { |
| 168 | - self.steps.saturating_sub(1) | |
| 194 | + self.steps.saturating_sub(Self::KEY_STEP) | |
| 169 | 195 | }; |
| 170 | 196 | } |
| 171 | 197 | |
| 198 | + /// Where the hand let go along the slider, 0..1 from silence to full. The | |
| 199 | + /// grid is the same one the keys land on, so a drag to the top and a key | |
| 200 | + /// held up reach the very same number -- and a drag never touches mute: | |
| 201 | + /// asking for a level while muted is not asking for sound. | |
| 202 | + fn set_along(&mut self, frac: f32) { | |
| 203 | + self.steps = (frac.clamp(0., 1.) * f32::from(Self::MAX_STEPS)).round() as u8; | |
| 204 | + } | |
| 205 | + | |
| 206 | + /// How full the slider is drawn, 0..1. The level and not the gain: a muted | |
| 207 | + /// slider still shows what unmuting comes back to, exactly as the label | |
| 208 | + /// does. | |
| 209 | + fn along(self) -> f32 { | |
| 210 | + f32::from(self.steps) / f32::from(Self::MAX_STEPS) | |
| 211 | + } | |
| 212 | + | |
| 172 | 213 | /// What the button reads. The level shows while muted too: it is what the |
| 173 | 214 | /// next press of the mute key brings back. |
| 174 | 215 | fn label(self) -> String { |
| @@ -311,8 +352,13 @@ impl RowItem { | ||
| 311 | 352 | /// action a stroke already reaches -- the menu is a second way *to* the actions |
| 312 | 353 | /// and never a second version of them -- so both the label and the hint come |
| 313 | 354 | /// out of the keymap registry and the two can never disagree. |
| 314 | -const MENU_ITEMS: [ActionId; 11] = [ | |
| 355 | +const MENU_ITEMS: [ActionId; 14] = [ | |
| 315 | 356 | ActionId::Cut, |
| 357 | + // The clipboard pair, which had no door but a chord: copy takes the clip the | |
| 358 | + // menu names, and paste is the timeline's rather than this clip's -- the | |
| 359 | + // same kind of global item the mute below already is. | |
| 360 | + ActionId::Copy, | |
| 361 | + ActionId::Paste, | |
| 316 | 362 | ActionId::Delete, |
| 317 | 363 | ActionId::Lift, |
| 318 | 364 | ActionId::Regroup, |
| @@ -320,6 +366,10 @@ const MENU_ITEMS: [ActionId; 11] = [ | ||
| 320 | 366 | ActionId::Group, |
| 321 | 367 | ActionId::Equalizer, |
| 322 | 368 | ActionId::Speed, |
| 369 | + // The scan is a clip card like the two above it -- opened on whichever half | |
| 370 | + // was clicked -- and a card only a stroke could open is one a pointer never | |
| 371 | + // finds. | |
| 372 | + ActionId::Silence, | |
| 323 | 373 | ActionId::Color, |
| 324 | 374 | ActionId::Fit, |
| 325 | 375 | ActionId::ToggleMute, |
| @@ -358,9 +408,10 @@ fn speed_at(permille: i32) -> Speed { | ||
| 358 | 408 | } |
| 359 | 409 | |
| 360 | 410 | /// 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; | |
| 411 | +/// reaches, the threshold and the unit it is read in, the three durations a | |
| 412 | +/// scan is told, and the rate the speed-up plays at. What `silence_field` | |
| 413 | +/// indexes and what [`Player::nudge_silence`] moves. | |
| 414 | +const SILENCE_ROWS: usize = 7; | |
| 364 | 415 | |
| 365 | 416 | /// How wide a jumpcut reaches. A ripple used to be the whole timeline's |
| 366 | 417 | /// business and nothing else; it is a *choice* now, because a podcast track's |
| @@ -408,9 +459,12 @@ const SILENCE_DB_STEP: f32 = 1.; | ||
| 408 | 459 | const SILENCE_SECS_STEP: f64 = 0.05; |
| 409 | 460 | |
| 410 | 461 | /// 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.); | |
| 462 | +/// takes any finite number, but a forgiveness of ten seconds finds nothing in a | |
| 463 | +/// talking head. The threshold reaches full scale, which calls a whole take | |
| 464 | +/// silent -- that is a thing someone may want to ask for (the preview on the | |
| 465 | +/// lane says what it would cost before anything is cut), so the top is 0 rather | |
| 466 | +/// than a number this card picked for them. | |
| 467 | +const SILENCE_DB_RANGE: (f32, f32) = (-80., 0.); | |
| 414 | 468 | const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.); |
| 415 | 469 | |
| 416 | 470 | /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows |
| @@ -451,6 +505,36 @@ const EQ_TICKS: [(f32, &str); 5] = [ | ||
| 451 | 505 | (20000., "20k"), |
| 452 | 506 | ]; |
| 453 | 507 | |
| 508 | +/// The gains the graph rules a line across, besides the 0 dB one it already | |
| 509 | +/// had: half way to each limit, so a boost can be read as "about six" without | |
| 510 | +/// counting pixels. The limits themselves are the box's own edges and are | |
| 511 | +/// named at the corners instead. | |
| 512 | +const EQ_DB_GRID: [f32; 2] = [6., -6.]; | |
| 513 | + | |
| 514 | +/// The grid's ink: above the card's background and below everything drawn on | |
| 515 | +/// it, so the lines are a ruling rather than a thing to look at. | |
| 516 | +const EQ_GRID: u32 = 0x3a3a3a; | |
| 517 | + | |
| 518 | +/// How many played samples one spectrum frame is transformed from. A power of | |
| 519 | +/// two ([`fft`] is radix-2) and the whole of the engine's tap: 1024 at 48 kHz | |
| 520 | +/// is a 47 Hz bin, fine enough that the bass end is a shape and short enough | |
| 521 | +/// (21 ms) that the analyser moves with the music. | |
| 522 | +const EQ_FFT: usize = 1024; | |
| 523 | + | |
| 524 | +/// The level range the analyser is drawn across, floor to ceiling in dBFS: the | |
| 525 | +/// bottom of the box is silence and the top is a bin at -12 dBFS, which is | |
| 526 | +/// about where a mixed track's loudest band sits. A look, not a measurement -- | |
| 527 | +/// the numbers on the axis are the curve's dB, never the analyser's. | |
| 528 | +const EQ_SPECTRUM_DB: (f32, f32) = (-96., -12.); | |
| 529 | + | |
| 530 | +/// The analyser's fill, behind the curve: a dim blue-grey with enough alpha to | |
| 531 | +/// read as a haze the accent line sits on top of. | |
| 532 | +const EQ_SPECTRUM_INK: u32 = 0x7f95ad66; | |
| 533 | + | |
| 534 | +/// The area under the response curve, same accent as the line at a tenth of | |
| 535 | +/// its weight: it is what makes a boost read as a hill rather than as a wire. | |
| 536 | +const EQ_FILL_INK: u32 = 0x4a9eff26; | |
| 537 | + | |
| 454 | 538 | /// The colour card's four controls, in the order it lists them: what each is |
| 455 | 539 | /// called and the range it moves in. The order is `ColorParams`' own, which is |
| 456 | 540 | /// what [`color_band`] indexes. |
| @@ -515,6 +599,10 @@ struct Player { | ||
| 515 | 599 | /// The ruler's own box, recorded at prepaint: a mouse listener is handed |
| 516 | 600 | /// the window position and nothing else. |
| 517 | 601 | ruler: Rc<Cell<Bounds<Pixels>>>, |
| 602 | + /// How much of the timeline the ruler and the lanes are showing. Held here | |
| 603 | + /// and nowhere else: every frame-to-pixel answer in the panel comes out of | |
| 604 | + /// it, so the boxes, the playhead and the pointer cannot disagree. | |
| 605 | + view: View, | |
| 518 | 606 | /// Which clip the edit keys act on: the lane it is in and its index there. |
| 519 | 607 | /// The *clicked* half, not the group -- a group is what gets marked on |
| 520 | 608 | /// screen, but Lift has to know which half it was aimed at. Indices move |
| @@ -584,6 +672,11 @@ struct Player { | ||
| 584 | 672 | /// also why it is not written to the project file and cannot reach an |
| 585 | 673 | /// export. [`Player::apply_volume`] is what pushes it at a session. |
| 586 | 674 | volume: Volume, |
| 675 | + /// Where the volume slider was last painted, and whether a hand is on it -- | |
| 676 | + /// the speed bar's pair, for the speed bar's reason: the pointer moves | |
| 677 | + /// arrive at the root, so the bar's own geometry has to be readable there. | |
| 678 | + volume_bar: Rc<Cell<Bounds<Pixels>>>, | |
| 679 | + volume_dragging: bool, | |
| 587 | 680 | /// The keybindings overlay is up. While it is, it owns the keyboard and the |
| 588 | 681 | /// pointer: a stroke or a click meant for a row must not also cut the |
| 589 | 682 | /// timeline. |
| @@ -622,6 +715,11 @@ struct Player { | ||
| 622 | 715 | /// window position only, so this is what a press and a drag are read |
| 623 | 716 | /// against ([`frac_along`], [`frac_down`]). |
| 624 | 717 | eq_graph: Rc<Cell<Bounds<Pixels>>>, |
| 718 | + /// Whether the analyser is drawn behind the curve. On by default -- what | |
| 719 | + /// the curve is being *shaped against* is the point of drawing it -- and | |
| 720 | + /// off with one press for anyone who would rather read the curve alone. | |
| 721 | + /// Card state, not the project's: it changes nothing that plays. | |
| 722 | + eq_spectrum: bool, | |
| 625 | 723 | /// The colour card is up on this clip -- the lane it is on and its index |
| 626 | 724 | /// there. `None` when it is closed, which is the only place that state |
| 627 | 725 | /// lives: the grade itself is the project's. |
| @@ -652,6 +750,14 @@ struct Player { | ||
| 652 | 750 | /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own |
| 653 | 751 | /// focus, since nothing in it takes gpui's (ledger:182). |
| 654 | 752 | silence_field: usize, |
| 753 | + /// Whether the threshold is *labelled* dBFS or dB. Display only, and the | |
| 754 | + /// number is the same either way: the setting is a level below full scale, | |
| 755 | + /// so 0 is the loudest sample a file can hold and -40 is forty decibels | |
| 756 | + /// under it -- "dBFS" names that reference out loud, "dB" leaves it unsaid. | |
| 757 | + /// No conversion is hiding behind the row (there is no reference here worth | |
| 758 | + /// inventing, and a made-up SPL would be a lie about what was measured); | |
| 759 | + /// what it changes is which of the two spellings a person reads. | |
| 760 | + silence_dbfs: bool, | |
| 655 | 761 | /// What the last scan found, in timeline frames: what the lane draws marks |
| 656 | 762 | /// over and what an apply acts on -- *exactly* the previewed set, never a |
| 657 | 763 | /// second scan at the moment of the press. |
| @@ -819,9 +925,20 @@ impl Player { | ||
| 819 | 925 | ActionId::Color => self.open_color(cx), |
| 820 | 926 | ActionId::Fit => self.cycle_fit(cx), |
| 821 | 927 | ActionId::Resolution => self.cycle_resolution(cx), |
| 928 | + // The playhead is what a key zoom is aimed at: it is the one place | |
| 929 | + // on the timeline the user is certainly looking at, and keeping it | |
| 930 | + // still is what every editor does. | |
| 931 | + ActionId::ZoomIn => self.zoom(ZOOM_STEP, None, cx), | |
| 932 | + ActionId::ZoomOut => self.zoom(1. / ZOOM_STEP, None, cx), | |
| 933 | + ActionId::ZoomFit => self.zoom_fit(cx), | |
| 822 | 934 | ActionId::Undo => self.undo(cx), |
| 823 | 935 | ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx), |
| 824 | 936 | ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx), |
| 937 | + // The last track of that kind: the one the add key put there, so the | |
| 938 | + // two strokes undo each other press for press. Any other track goes | |
| 939 | + // through the × in its own header. | |
| 940 | + ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx), | |
| 941 | + ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx), | |
| 825 | 942 | ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx), |
| 826 | 943 | ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx), |
| 827 | 944 | ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx), |
| @@ -937,6 +1054,26 @@ impl Player { | ||
| 937 | 1054 | cx.notify(); |
| 938 | 1055 | } |
| 939 | 1056 | |
| 1057 | + /// Magnifies the timeline about a point that stays put: `anchor` is where | |
| 1058 | + /// along the bed to hold still (a ctrl+wheel holds the pointer), and with | |
| 1059 | + /// none it is the playhead -- so the frame being worked on is still the | |
| 1060 | + /// frame on screen after the zoom. Clamped at both ends by [`View`]: out | |
| 1061 | + /// stops at the whole timeline, in at a handful of frames. | |
| 1062 | + fn zoom(&mut self, factor: f32, anchor: Option<f32>, cx: &mut Context<Self>) { | |
| 1063 | + let duration = self.drawn_duration(); | |
| 1064 | + let at = self.playhead(duration); | |
| 1065 | + let anchor = anchor.unwrap_or_else(|| self.view.frac_at(at, duration).clamp(0., 1.)); | |
| 1066 | + self.view = self.view.zoomed(factor, anchor, duration, self.fps); | |
| 1067 | + cx.notify(); | |
| 1068 | + } | |
| 1069 | + | |
| 1070 | + /// All the way back out: the whole timeline across the bed, which is what | |
| 1071 | + /// the panel shows before anyone has zoomed at all. | |
| 1072 | + fn zoom_fit(&mut self, cx: &mut Context<Self>) { | |
| 1073 | + self.view = View::default(); | |
| 1074 | + cx.notify(); | |
| 1075 | + } | |
| 1076 | + | |
| 940 | 1077 | /// Cycles the *project's* resolution through [`RESOLUTIONS`], starting from |
| 941 | 1078 | /// the media's own -- the one size that must stay reachable, since a project |
| 942 | 1079 | /// moved off it has no other way back (the resolution is not an undo step). |
| @@ -1314,9 +1451,12 @@ impl Player { | ||
| 1314 | 1451 | + steps as f32 * SILENCE_DB_STEP) |
| 1315 | 1452 | .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1) |
| 1316 | 1453 | } |
| 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), | |
| 1454 | + // Two spellings of the same level, so either arrow flips it -- a | |
| 1455 | + // ring of two, like the scope row's. | |
| 1456 | + 2 => self.silence_dbfs = !self.silence_dbfs, | |
| 1457 | + 3 => self.silence.min_silence = secs(self.silence.min_silence), | |
| 1458 | + 4 => self.silence.padding = secs(self.silence.padding), | |
| 1459 | + 5 => self.silence.min_keep = secs(self.silence.min_keep), | |
| 1320 | 1460 | _ => { |
| 1321 | 1461 | self.silence_factor = |
| 1322 | 1462 | silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP) |
| @@ -1408,6 +1548,11 @@ impl Player { | ||
| 1408 | 1548 | match session.cut_regions(®ions, &lanes) { |
| 1409 | 1549 | Ok(()) => { |
| 1410 | 1550 | self.close_silence(); |
| 1551 | + // Every hole closed moves the clips after it up a place, so the | |
| 1552 | + // selection now names a different clip than the one that is | |
| 1553 | + // highlighted -- dropped here as after every other edit that | |
| 1554 | + // moves indexes (a delete, a paste, an undo). | |
| 1555 | + self.selected = None; | |
| 1411 | 1556 | self.reset_after_reseek(); |
| 1412 | 1557 | self.notice = Some( |
| 1413 | 1558 | format!( |
| @@ -1442,6 +1587,10 @@ impl Player { | ||
| 1442 | 1587 | match session.speed_regions(®ions, rate, &lanes) { |
| 1443 | 1588 | Ok(()) => { |
| 1444 | 1589 | self.close_silence(); |
| 1590 | + // Splitting each silence out and closing the room it no longer | |
| 1591 | + // needs moves indexes exactly as the cut does: the selection | |
| 1592 | + // goes with them. | |
| 1593 | + self.selected = None; | |
| 1445 | 1594 | self.reset_after_reseek(); |
| 1446 | 1595 | self.notice = Some( |
| 1447 | 1596 | format!( |
| @@ -1469,6 +1618,29 @@ impl Player { | ||
| 1469 | 1618 | || self.exporting().is_some() |
| 1470 | 1619 | } |
| 1471 | 1620 | |
| 1621 | + /// Which of [`Repeat`]'s three the window is in, for the hold gate at the | |
| 1622 | + /// top of the key handler. Not [`Player::modal`]: that asks whether an | |
| 1623 | + /// overlay is up at all, and here the cards with sliders in them are | |
| 1624 | + /// exactly the ones that answer differently from the keys menu and the | |
| 1625 | + /// export card. | |
| 1626 | + fn repeat_scope(&self) -> Repeat { | |
| 1627 | + if self.rebinding.is_some() | |
| 1628 | + || self.keys_open | |
| 1629 | + || self.export_open | |
| 1630 | + || self.exporting().is_some() | |
| 1631 | + { | |
| 1632 | + Repeat::Nothing | |
| 1633 | + } else if self.eq_open.is_some() | |
| 1634 | + || self.color_open.is_some() | |
| 1635 | + || self.speed_open.is_some() | |
| 1636 | + || self.silence_open.is_some() | |
| 1637 | + { | |
| 1638 | + Repeat::Card | |
| 1639 | + } else { | |
| 1640 | + Repeat::Keymap | |
| 1641 | + } | |
| 1642 | + } | |
| 1643 | + | |
| 1472 | 1644 | /// Opens the equalizer on the selected clip. Audio only, and it says so |
| 1473 | 1645 | /// rather than opening a card of bands that would reach nothing: a video |
| 1474 | 1646 | /// clip carries no sound of its own here (the sound is the audio lane's), |
| @@ -1980,14 +2152,16 @@ impl Player { | ||
| 1980 | 2152 | /// pointer exactly. |
| 1981 | 2153 | fn trim_to(&mut self, x: Pixels, cx: &mut Context<Self>) { |
| 1982 | 2154 | let (duration, fps) = (self.drawn_duration(), self.fps); |
| 1983 | - let frac = frac_along(x, self.ruler.get()); | |
| 2155 | + let at = self | |
| 2156 | + .view | |
| 2157 | + .time_at(frac_along(x, self.ruler.get()), duration); | |
| 1984 | 2158 | let (Some(trim), Some(session)) = (&mut self.trim, &self.session) else { |
| 1985 | 2159 | return; |
| 1986 | 2160 | }; |
| 1987 | 2161 | let Some((lo, hi)) = session.trim_room(trim.lane, trim.idx, trim.edge) else { |
| 1988 | 2162 | return; |
| 1989 | 2163 | }; |
| 1990 | - trim.to = frame_at(f64::from(frac) * duration, fps).clamp(lo, hi); | |
| 2164 | + trim.to = frame_at(at, fps).clamp(lo, hi); | |
| 1991 | 2165 | cx.notify(); |
| 1992 | 2166 | } |
| 1993 | 2167 | |
| @@ -2018,6 +2192,25 @@ impl Player { | ||
| 2018 | 2192 | return clip; |
| 2019 | 2193 | }; |
| 2020 | 2194 | match trim.edge { |
| 2195 | + // A still grows forward from source frame 0 instead, exactly as | |
| 2196 | + // `Project::trim` writes it: with the in-point clamped at 0 the box | |
| 2197 | + // below would slide left rather than stretch, and the release would | |
| 2198 | + // then commit a wider clip than the drag drew. | |
| 2199 | + Edge::Start | |
| 2200 | + if self.session.as_ref().is_some_and(|session| { | |
| 2201 | + session | |
| 2202 | + .sources() | |
| 2203 | + .get(clip.source) | |
| 2204 | + .is_some_and(|s| engine::is_image(&s.path)) | |
| 2205 | + }) => | |
| 2206 | + { | |
| 2207 | + Clip { | |
| 2208 | + in_frame: 0, | |
| 2209 | + out_frame: clip.end().saturating_sub(trim.to).max(1), | |
| 2210 | + start: trim.to, | |
| 2211 | + ..clip | |
| 2212 | + } | |
| 2213 | + } | |
| 2021 | 2214 | // The in-point follows the head, exactly as `Project::trim` moves |
| 2022 | 2215 | // it: what stays on screen plays what it always played. |
| 2023 | 2216 | Edge::Start => Clip { |
| @@ -2054,6 +2247,21 @@ impl Player { | ||
| 2054 | 2247 | } |
| 2055 | 2248 | } |
| 2056 | 2249 | |
| 2250 | + /// Where the playhead is, as the panel draws it. The clock keeps running | |
| 2251 | + /// after the last frame (wall time takes over at audio EOF) while the | |
| 2252 | + /// picture is frozen, so what the UI shows is the clamped one, pinned to | |
| 2253 | + /// the out-point once playback is done. | |
| 2254 | + fn playhead(&self, duration: f64) -> f64 { | |
| 2255 | + if self.done { | |
| 2256 | + duration | |
| 2257 | + } else { | |
| 2258 | + self.session | |
| 2259 | + .as_ref() | |
| 2260 | + .map_or(0., PlaybackSession::now) | |
| 2261 | + .clamp(0., duration) | |
| 2262 | + } | |
| 2263 | + } | |
| 2264 | + | |
| 2057 | 2265 | /// The one way a library row reaches the timeline: the Add button and a row |
| 2058 | 2266 | /// dragged onto a lane both come here, so there is a single answer to what |
| 2059 | 2267 | /// "add this source" does. The whole source goes in at the playhead as one |
| @@ -2133,20 +2341,43 @@ impl Player { | ||
| 2133 | 2341 | .as_mut() |
| 2134 | 2342 | .map(|session| session.remove_source(path, stream)); |
| 2135 | 2343 | let text = match removed { |
| 2136 | - Some(Ok(())) => { | |
| 2344 | + Some(Ok(idx)) => { | |
| 2137 | 2345 | // The picked row may be the one that just went, and the engine |
| 2138 | 2346 | // reseeks, so this owes the flag reset like every other edit. |
| 2139 | 2347 | if self.selected_asset.as_ref() == Some(&(path.to_path_buf(), stream)) { |
| 2140 | 2348 | self.selected_asset = None; |
| 2141 | 2349 | } |
| 2350 | + // A copied clip names its source by *index*, and every index | |
| 2351 | + // past the one that went has just moved down: without this the | |
| 2352 | + // next paste puts some other file on the timeline. | |
| 2353 | + self.clipboard = clipboard_after_remove(self.clipboard, idx); | |
| 2142 | 2354 | self.reset_after_reseek(); |
| 2143 | - // The undo stack goes with it (`Project::remove_source`): said | |
| 2144 | - // here, because a `z` that does nothing afterwards would | |
| 2145 | - // otherwise read as a bug. | |
| 2146 | - format!( | |
| 2147 | - "REMOVED {} — there is nothing left to undo", | |
| 2148 | - file_name(path) | |
| 2149 | - ) | |
| 2355 | + // The last row leaves a session naming no file: nothing to | |
| 2356 | + // play, nothing to save and nothing to show, which is the empty | |
| 2357 | + // window the editor launches as. The next import scaffolds a | |
| 2358 | + // fresh timeline from whatever file it is, at that file's own | |
| 2359 | + // rate -- which is why the session goes rather than lingering | |
| 2360 | + // on with the gone file's parameters. | |
| 2361 | + match self | |
| 2362 | + .session | |
| 2363 | + .as_ref() | |
| 2364 | + .is_some_and(|s| s.sources().is_empty()) | |
| 2365 | + { | |
| 2366 | + true => { | |
| 2367 | + self.close_session(); | |
| 2368 | + format!( | |
| 2369 | + "REMOVED {} — the library is empty; import a file to start again", | |
| 2370 | + file_name(path) | |
| 2371 | + ) | |
| 2372 | + } | |
| 2373 | + // The undo stack goes with it (`Project::remove_source`): | |
| 2374 | + // said here, because a `z` that does nothing afterwards | |
| 2375 | + // would otherwise read as a bug. | |
| 2376 | + false => format!( | |
| 2377 | + "REMOVED {} — there is nothing left to undo", | |
| 2378 | + file_name(path) | |
| 2379 | + ), | |
| 2380 | + } | |
| 2150 | 2381 | } |
| 2151 | 2382 | Some(Err(e)) => format!("NOT REMOVED — {e}"), |
| 2152 | 2383 | None => "NO TIMELINE — open a file first".to_string(), |
| @@ -2155,6 +2386,64 @@ impl Player { | ||
| 2155 | 2386 | cx.notify(); |
| 2156 | 2387 | } |
| 2157 | 2388 | |
| 2389 | + /// Back to the window the editor launches as: no timeline, no library, no | |
| 2390 | + /// picture -- and the hint that says to open a file. What removing the last | |
| 2391 | + /// library row leaves, since a session whose library is empty has nothing | |
| 2392 | + /// left to be ([`Player::remove_source`]). | |
| 2393 | + /// | |
| 2394 | + /// Everything a *loaded project* resets goes here for its reasons (an index | |
| 2395 | + /// into a timeline that is gone names nothing), plus the three per-file | |
| 2396 | + /// caches: they are keyed by path, and the next file to arrive fills them | |
| 2397 | + /// again. | |
| 2398 | + fn close_session(&mut self) { | |
| 2399 | + self.session = None; | |
| 2400 | + // The picture goes with it, or the empty window would keep showing the | |
| 2401 | + // last frame of a timeline that no longer exists. | |
| 2402 | + // | |
| 2403 | + // ponytail: its atlas tile is not released -- `window.drop_image` wants | |
| 2404 | + // a `&mut Window` this door has no other reason to take. One tile per | |
| 2405 | + // emptied library, against one per displayed frame in `pump`; the | |
| 2406 | + // upgrade path is threading the window through `act_on_row`. | |
| 2407 | + self.image = None; | |
| 2408 | + self.clipboard = None; | |
| 2409 | + self.selected = None; | |
| 2410 | + self.selected_asset = None; | |
| 2411 | + self.context_menu = None; | |
| 2412 | + self.library_menu = None; | |
| 2413 | + self.eq_open = None; | |
| 2414 | + self.color_open = None; | |
| 2415 | + self.speed_open = None; | |
| 2416 | + self.close_silence(); | |
| 2417 | + self.waves.clear(); | |
| 2418 | + self.streams.clear(); | |
| 2419 | + self.sizes.clear(); | |
| 2420 | + // Scanned off a source that is not in the library any more. | |
| 2421 | + self.silence_levels = None; | |
| 2422 | + // Every gesture in flight, dropped for `reset_after_reseek`'s reason | |
| 2423 | + // (it drops the trim below): a drag holds a bar, a clip or a band of a | |
| 2424 | + // timeline that has just stopped existing. | |
| 2425 | + self.scrubbing = false; | |
| 2426 | + self.volume_dragging = false; | |
| 2427 | + self.eq_dragging = false; | |
| 2428 | + self.speed_dragging = false; | |
| 2429 | + self.color_dragging = false; | |
| 2430 | + self.displayed = 0; | |
| 2431 | + self.dropped = 0; | |
| 2432 | + self.started = None; | |
| 2433 | + // The empty window's own: no name in the titlebar, nowhere chosen to | |
| 2434 | + // export or save to yet, and a rate that only keeps the timecode | |
| 2435 | + // reading in frames until a file brings its own (`main`). | |
| 2436 | + self.name = NO_FILE.into(); | |
| 2437 | + self.export_path = PathBuf::new(); | |
| 2438 | + self.project_path = PathBuf::new(); | |
| 2439 | + self.fps = 30.; | |
| 2440 | + // No decoder to wait for a frame from: the hint is what shows. | |
| 2441 | + self.reset_after_reseek(); | |
| 2442 | + self.pending_seek = false; | |
| 2443 | + self.eos = false; | |
| 2444 | + self.done = false; | |
| 2445 | + } | |
| 2446 | + | |
| 2158 | 2447 | /// One item of a library row's menu, done. Every one of them closes the |
| 2159 | 2448 | /// menu first -- the list under it is about to be rebuilt -- except the one |
| 2160 | 2449 | /// that turns the card over. |
| @@ -2188,11 +2477,22 @@ impl Player { | ||
| 2188 | 2477 | cx.notify(); |
| 2189 | 2478 | } |
| 2190 | 2479 | |
| 2191 | - /// The rate and layout the whole timeline's audio is, taken from source 0's | |
| 2192 | - /// own stream: what a library row has to match to be placeable. `None` | |
| 2193 | - /// until that file has been probed, and then nothing is greyed for it. | |
| 2480 | + /// The rate and layout the whole timeline's audio is, taken from the stream | |
| 2481 | + /// of the first source that could have one: what a library row has to match | |
| 2482 | + /// to be placeable. `None` until that file has been probed, and then nothing | |
| 2483 | + /// is greyed for it. | |
| 2484 | + /// | |
| 2485 | + /// The first source that is *not a still*, which is the rule the engine | |
| 2486 | + /// holds every import to (`playback::audio_source_of`) -- a picture at the | |
| 2487 | + /// head of the list (a removal moves indexes) has no stream to describe | |
| 2488 | + /// anything with. | |
| 2194 | 2489 | fn timeline_audio(&self) -> Option<(u32, u16)> { |
| 2195 | - let first = self.session.as_ref()?.sources().first()?; | |
| 2490 | + let first = self | |
| 2491 | + .session | |
| 2492 | + .as_ref()? | |
| 2493 | + .sources() | |
| 2494 | + .iter() | |
| 2495 | + .find(|s| !engine::is_image(&s.path))?; | |
| 2196 | 2496 | let info = self |
| 2197 | 2497 | .streams |
| 2198 | 2498 | .get(&first.path)? |
| @@ -2397,6 +2697,64 @@ impl Player { | ||
| 2397 | 2697 | cx.notify(); |
| 2398 | 2698 | } |
| 2399 | 2699 | |
| 2700 | + /// The × in a track's header: the add taken back, one undo step, and the | |
| 2701 | + /// engine's own words when it refuses -- those name the clips still on the | |
| 2702 | + /// track, so the notice says what to delete first. A removal never deletes a | |
| 2703 | + /// clip. | |
| 2704 | + /// | |
| 2705 | + /// Everything holding a `(lane, idx)` is dropped, because the tracks below | |
| 2706 | + /// the one that went have just moved up an `ord` | |
| 2707 | + /// ([`engine::Project::remove_lane`]): a selection or an open card kept | |
| 2708 | + /// across it would be pointing at the *next* track's clip. | |
| 2709 | + fn remove_lane(&mut self, lane: Lane, cx: &mut Context<Self>) { | |
| 2710 | + if self.exporting().is_some() { | |
| 2711 | + return; | |
| 2712 | + } | |
| 2713 | + let removed = self | |
| 2714 | + .session | |
| 2715 | + .as_mut() | |
| 2716 | + .map(|session| session.remove_lane(lane)); | |
| 2717 | + let text = match removed { | |
| 2718 | + Some(Ok(())) => { | |
| 2719 | + self.selected = None; | |
| 2720 | + self.context_menu = None; | |
| 2721 | + self.eq_open = None; | |
| 2722 | + self.color_open = None; | |
| 2723 | + self.speed_open = None; | |
| 2724 | + self.close_silence(); | |
| 2725 | + format!( | |
| 2726 | + "{} REMOVED — {} brings it back", | |
| 2727 | + lane.label(), | |
| 2728 | + self.keymap.display(ActionId::Undo) | |
| 2729 | + ) | |
| 2730 | + } | |
| 2731 | + Some(Err(e)) => format!("NO TRACK REMOVED — {e}"), | |
| 2732 | + None => "NO TRACK REMOVED — open a file first".to_string(), | |
| 2733 | + }; | |
| 2734 | + self.notice = Some(text.into()); | |
| 2735 | + cx.notify(); | |
| 2736 | + } | |
| 2737 | + | |
| 2738 | + /// What the remove keys act on: the last track of that kind, which is the | |
| 2739 | + /// one the matching add key appended. Nothing at all before a file is open, | |
| 2740 | + /// where the timeline drawn is a placeholder pair. | |
| 2741 | + fn remove_last_lane(&mut self, kind: LaneKind, cx: &mut Context<Self>) { | |
| 2742 | + let last = self.session.as_ref().and_then(|session| { | |
| 2743 | + session | |
| 2744 | + .lanes() | |
| 2745 | + .into_iter() | |
| 2746 | + .filter(|l| l.kind == kind) | |
| 2747 | + .next_back() | |
| 2748 | + }); | |
| 2749 | + match last { | |
| 2750 | + Some(lane) => self.remove_lane(lane, cx), | |
| 2751 | + None => { | |
| 2752 | + self.notice = Some("NO TRACK REMOVED — open a file first".into()); | |
| 2753 | + cx.notify(); | |
| 2754 | + } | |
| 2755 | + } | |
| 2756 | + } | |
| 2757 | + | |
| 2400 | 2758 | fn undo(&mut self, cx: &mut Context<Self>) { |
| 2401 | 2759 | if self.session.as_mut().is_some_and(PlaybackSession::undo) { |
| 2402 | 2760 | self.reset_after_reseek(); |
| @@ -2452,7 +2810,9 @@ impl Player { | ||
| 2452 | 2810 | let Some(session) = &self.session else { |
| 2453 | 2811 | return; |
| 2454 | 2812 | }; |
| 2455 | - let t = f64::from(frac_along(x, self.ruler.get())) * session.timeline_duration(); | |
| 2813 | + let t = self | |
| 2814 | + .view | |
| 2815 | + .time_at(frac_along(x, self.ruler.get()), session.timeline_duration()); | |
| 2456 | 2816 | let target = (t * self.fps) as u32; |
| 2457 | 2817 | if commit || scrub_due(target, self.last_target, self.last_scrub.elapsed()) { |
| 2458 | 2818 | self.last_target = target; |
| @@ -2483,10 +2843,33 @@ impl Player { | ||
| 2483 | 2843 | cx.notify(); |
| 2484 | 2844 | } |
| 2485 | 2845 | |
| 2846 | + /// Where the pointer sits along the slider, as a level. The press and every | |
| 2847 | + /// sample after it come here, so the sound follows the hand rather than the | |
| 2848 | + /// release -- there is nothing to undo about a monitoring level, which is | |
| 2849 | + /// why this writes live and keeps no gesture state beyond the flag. | |
| 2850 | + fn drag_volume(&mut self, x: Pixels, cx: &mut Context<Self>) { | |
| 2851 | + let along = frac_along(x, self.volume_bar.get()); | |
| 2852 | + self.set_volume(|volume| volume.set_along(along), cx); | |
| 2853 | + } | |
| 2854 | + | |
| 2486 | 2855 | fn toggle_or_restart(&mut self, cx: &mut Context<Self>) { |
| 2487 | 2856 | if self.exporting().is_some() { |
| 2488 | 2857 | return; |
| 2489 | 2858 | } |
| 2859 | + // Nothing to play is a message, not a transport state. An empty | |
| 2860 | + // timeline is `done` from its one black frame onward, so the restart | |
| 2861 | + // below would start a clock against a zero-length timeline -- and it is | |
| 2862 | + // `done` again by the next repaint, so no later press could ever stop | |
| 2863 | + // it: the button would read "Pause" and never pause. A delete can empty | |
| 2864 | + // the timeline mid-play, and that press must still stop it. | |
| 2865 | + if nothing_to_play(self.session.as_ref()) { | |
| 2866 | + match self.session.as_mut().filter(|s| s.is_playing()) { | |
| 2867 | + Some(session) => session.pause(), | |
| 2868 | + None => self.notice = Some(NOTHING_TO_PLAY.into()), | |
| 2869 | + } | |
| 2870 | + cx.notify(); | |
| 2871 | + return; | |
| 2872 | + } | |
| 2490 | 2873 | if self.done { |
| 2491 | 2874 | self.seek(0., cx); |
| 2492 | 2875 | if let Some(session) = &mut self.session { |
| @@ -2699,24 +3082,29 @@ impl Render for Player { | ||
| 2699 | 3082 | // timecode, the ruler and the clamp below all have to follow it -- and |
| 2700 | 3083 | // so does the room a tail being dragged needs to grow into. |
| 2701 | 3084 | let duration = self.drawn_duration(); |
| 2702 | - // The clock keeps running after the last frame (wall time takes over at | |
| 2703 | - // audio EOF) while the picture is frozen, so the timeline the UI shows is | |
| 2704 | - // the clamped one, pinned to the out-point once playback is done. | |
| 2705 | - let position = if self.done { | |
| 2706 | - duration | |
| 2707 | - } else { | |
| 2708 | - self.session | |
| 2709 | - .as_ref() | |
| 2710 | - .map_or(0., PlaybackSession::now) | |
| 2711 | - .clamp(0., duration) | |
| 2712 | - }; | |
| 3085 | + let position = self.playhead(duration); | |
| 3086 | + // Re-settled every frame against the duration this one is drawing: an | |
| 3087 | + // edit that shortens the timeline moves the far end of the view, and a | |
| 3088 | + // playhead that has run off the bed pulls the view after it -- which is | |
| 3089 | + // what makes a zoomed-in timeline scroll while it plays. | |
| 3090 | + self.view = self.view.following(position, duration, self.fps); | |
| 2713 | 3091 | |
| 2714 | 3092 | div() |
| 2715 | 3093 | .track_focus(&self.focus) |
| 2716 | 3094 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { |
| 2717 | - // `is_held` filters auto-repeat, which would otherwise toggle | |
| 2718 | - // playback -- or cut the timeline -- many times a second. | |
| 2719 | - if event.is_held { | |
| 3095 | + let key = event.keystroke.key.as_str(); | |
| 3096 | + let ctrl = event.keystroke.modifiers.control; | |
| 3097 | + // `is_held` is the auto-repeat, and a value is the one thing | |
| 3098 | + // worth running on it: a held arrow on a card moves the slider | |
| 3099 | + // it picked, and a held volume key runs the volume. Everything | |
| 3100 | + // else is filtered exactly as it always was -- a repeat that | |
| 3101 | + // toggled playback, or cut the timeline, many times a second is | |
| 3102 | + // what this guard is for, and a row waiting for a stroke takes | |
| 3103 | + // none of it either (it would bind the key, then fire what it | |
| 3104 | + // just bound). See [`repeats`]. | |
| 3105 | + if event.is_held | |
| 3106 | + && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl)) | |
| 3107 | + { | |
| 2720 | 3108 | return; |
| 2721 | 3109 | } |
| 2722 | 3110 | // Any key retires the last message, whatever it was -- and owes |
| @@ -2726,7 +3114,6 @@ impl Render for Player { | ||
| 2726 | 3114 | if this.notice.take().is_some() { |
| 2727 | 3115 | cx.notify(); |
| 2728 | 3116 | } |
| 2729 | - let key = event.keystroke.key.as_str(); | |
| 2730 | 3117 | // A row is waiting for a stroke, and while it is, that stroke is |
| 2731 | 3118 | // data: it means the binding and nothing else, which is why this |
| 2732 | 3119 | // answers before the export guard and before the keymap is |
| @@ -2735,7 +3122,7 @@ impl Render for Player { | ||
| 2735 | 3122 | if key == ESCAPE { |
| 2736 | 3123 | this.rebinding = None; |
| 2737 | 3124 | } else if !is_bare_modifier(key) { |
| 2738 | - this.capture(action, key, event.keystroke.modifiers.control); | |
| 3125 | + this.capture(action, key, ctrl); | |
| 2739 | 3126 | } |
| 2740 | 3127 | cx.notify(); |
| 2741 | 3128 | return; |
| @@ -2744,7 +3131,7 @@ impl Render for Player { | ||
| 2744 | 3131 | // control modifier set (the control code is mapped back), which |
| 2745 | 3132 | // is why the keymap is keyed on the pair and never on the key |
| 2746 | 3133 | // alone. |
| 2747 | - let action = this.keymap.lookup(key, event.keystroke.modifiers.control); | |
| 3134 | + let action = this.keymap.lookup(key, ctrl); | |
| 2748 | 3135 | // An export is reading the edit list every other action here |
| 2749 | 3136 | // would change, so cancelling is the only one that means |
| 2750 | 3137 | // anything until it is over. |
| @@ -2816,6 +3203,11 @@ impl Render for Player { | ||
| 2816 | 3203 | band.gain_db = 0.; |
| 2817 | 3204 | } |
| 2818 | 3205 | this.commit_eq(cx); |
| 3206 | + } else if key == "s" { | |
| 3207 | + // The analyser off and on. Nothing is committed: it is | |
| 3208 | + // what the card *shows*, so it survives no further than | |
| 3209 | + // this window. | |
| 3210 | + this.eq_spectrum = !this.eq_spectrum; | |
| 2819 | 3211 | } else if let Ok(digit) = key.parse::<usize>() { |
| 2820 | 3212 | // 1-based, as the rows are numbered on screen; a digit |
| 2821 | 3213 | // past the last band picks nothing rather than panics. |
| @@ -2991,6 +3383,16 @@ impl Render for Player { | ||
| 2991 | 3383 | } |
| 2992 | 3384 | return; |
| 2993 | 3385 | } |
| 3386 | + // The volume slider, the same live writes: what the hand is on | |
| 3387 | + // is what the speakers are doing, and there is nothing to undo. | |
| 3388 | + if this.volume_dragging { | |
| 3389 | + if event.pressed_button == Some(MouseButton::Left) { | |
| 3390 | + this.drag_volume(event.position.x, cx); | |
| 3391 | + } else { | |
| 3392 | + this.volume_dragging = false; | |
| 3393 | + } | |
| 3394 | + return; | |
| 3395 | + } | |
| 2994 | 3396 | if !this.scrubbing { |
| 2995 | 3397 | return; |
| 2996 | 3398 | } |
| @@ -3031,6 +3433,10 @@ impl Render for Player { | ||
| 3031 | 3433 | this.drag_speed(event.position.x, false, cx); |
| 3032 | 3434 | return; |
| 3033 | 3435 | } |
| 3436 | + if std::mem::take(&mut this.volume_dragging) { | |
| 3437 | + this.drag_volume(event.position.x, cx); | |
| 3438 | + return; | |
| 3439 | + } | |
| 3034 | 3440 | if std::mem::take(&mut this.scrubbing) { |
| 3035 | 3441 | this.scrub_to(event.position.x, true, cx); |
| 3036 | 3442 | } |
| @@ -3382,11 +3788,11 @@ impl Player { | ||
| 3382 | 3788 | playing: bool, |
| 3383 | 3789 | cx: &mut Context<Self>, |
| 3384 | 3790 | ) -> impl IntoElement { |
| 3385 | - let filled = if duration > 0. { | |
| 3386 | - (position / duration) as f32 | |
| 3387 | - } else { | |
| 3388 | - 0. | |
| 3389 | - }; | |
| 3791 | + // Where the playhead is *on the bed*, which at the fit is where along | |
| 3792 | + // the timeline it is and zoomed in is where along the visible slice. | |
| 3793 | + // Clamped because it is drawn as a width as well as an offset, and the | |
| 3794 | + // view follows the playhead anyway, so it is never off the bed. | |
| 3795 | + let filled = self.view.frac_at(position, duration).clamp(0., 1.); | |
| 3390 | 3796 | // An export owns the hint slot and the ruler while it runs: the |
| 3391 | 3797 | // percentage and the accent bar are the same number, so the playhead |
| 3392 | 3798 | // fill doubles as the progress bar for free. |
| @@ -3394,6 +3800,10 @@ impl Player { | ||
| 3394 | 3800 | // Everything but Import and Keys needs a timeline to act on: with none |
| 3395 | 3801 | // open they are dimmed rather than silently doing nothing. |
| 3396 | 3802 | let live = self.session.is_some() && !exporting; |
| 3803 | + // The project's own picture size, for the button that cycles it: read | |
| 3804 | + // per render like everything else here, so a cycle shows on the button | |
| 3805 | + // that made it. | |
| 3806 | + let resolution = self.session.as_ref().map(PlaybackSession::resolution); | |
| 3397 | 3807 | let key = |action| self.keymap.display(action); |
| 3398 | 3808 | // The lanes the project has, or the pair a fresh one starts with so the |
| 3399 | 3809 | // panel reads the same before a file is open as after. |
| @@ -3443,18 +3853,35 @@ impl Player { | ||
| 3443 | 3853 | .bg(rgb(CHROME)) |
| 3444 | 3854 | // Transport | edit | file: three groups, so the eye can skip two of |
| 3445 | 3855 | // them. Every button says what it does; the tooltip adds its key. |
| 3856 | + // | |
| 3857 | + // The row scrolls rather than losing its tail: at the 640 px floor | |
| 3858 | + // this window is sized for it is wider than the panel, and a button | |
| 3859 | + // off the right edge is a button a pointer cannot press. A plain | |
| 3860 | + // wheel moves it -- gpui puts a vertical delta on the x axis when | |
| 3861 | + // that is the only one scrolling (div.rs:2424). | |
| 3446 | 3862 | .child( |
| 3447 | 3863 | div() |
| 3864 | + .id("controls") | |
| 3448 | 3865 | .flex_none() |
| 3449 | 3866 | .flex() |
| 3450 | 3867 | .items_center() |
| 3451 | 3868 | .gap(px(8.)) |
| 3869 | + .overflow_x_scroll() | |
| 3452 | 3870 | .child(control( |
| 3453 | 3871 | "transport", |
| 3454 | 3872 | Some(transport_glyph(playing).into_any_element()), |
| 3455 | 3873 | if playing { "Pause" } else { "Play" }, |
| 3456 | - key(ActionId::Play), | |
| 3457 | - live, | |
| 3874 | + if nothing_to_play(self.session.as_ref()) && !playing { | |
| 3875 | + format!("{} — put a clip on a lane first", key(ActionId::Play)) | |
| 3876 | + } else { | |
| 3877 | + key(ActionId::Play) | |
| 3878 | + }, | |
| 3879 | + // An empty timeline has nothing to play, so the button | |
| 3880 | + // says so by being dim rather than by starting a clock | |
| 3881 | + // against nothing (the key press answers with the | |
| 3882 | + // notice). Still live while it *is* playing: a delete | |
| 3883 | + // can empty the timeline mid-play and that has to stop. | |
| 3884 | + live && (playing || !nothing_to_play(self.session.as_ref())), | |
| 3458 | 3885 | cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), |
| 3459 | 3886 | )) |
| 3460 | 3887 | .child(separator()) |
| @@ -3481,6 +3908,17 @@ impl Player { | ||
| 3481 | 3908 | live && self.selected.is_some(), |
| 3482 | 3909 | cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), |
| 3483 | 3910 | )) |
| 3911 | + // The way back from every one of them. It was a stroke and | |
| 3912 | + // nothing else, which made the whole edit group a one-way | |
| 3913 | + // door for anyone working with a pointer. | |
| 3914 | + .child(control( | |
| 3915 | + "undo", | |
| 3916 | + None, | |
| 3917 | + "Undo", | |
| 3918 | + format!("{} — takes the last edit back", key(ActionId::Undo)), | |
| 3919 | + live, | |
| 3920 | + cx.listener(|this, _: &ClickEvent, _, cx| this.undo(cx)), | |
| 3921 | + )) | |
| 3484 | 3922 | // With the edit group, beside the buttons that change the |
| 3485 | 3923 | // edit list: a track is a row of it, and adding one is an |
| 3486 | 3924 | // undoable edit like the rest. Two buttons rather than one |
| @@ -3529,20 +3967,115 @@ impl Player { | ||
| 3529 | 3967 | this.set_volume(|volume| volume.muted = !volume.muted, cx) |
| 3530 | 3968 | }), |
| 3531 | 3969 | )) |
| 3970 | + // The level itself, to drag. The button beside it stays the | |
| 3971 | + // mute -- one gesture each -- and the label above is what | |
| 3972 | + // this writes, live, so the number follows the hand. | |
| 3973 | + .child(volume_slider( | |
| 3974 | + self.volume, | |
| 3975 | + self.volume_bar.clone(), | |
| 3976 | + live, | |
| 3977 | + cx, | |
| 3978 | + )) | |
| 3532 | 3979 | .child(separator()) |
| 3980 | + // The size every clip is composed onto, which is also the | |
| 3981 | + // size the export comes out at: the one project setting a | |
| 3982 | + // stroke used to be the only way to. Cycles exactly as the | |
| 3983 | + // key does, and says where it is now rather than opening a | |
| 3984 | + // list to close again. | |
| 3985 | + .child(control( | |
| 3986 | + "resolution", | |
| 3987 | + None, | |
| 3988 | + resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")), | |
| 3989 | + match resolution { | |
| 3990 | + Some((w, h)) => format!( | |
| 3991 | + "{} — the project is {w}x{h}; cycles source → 2160p → 1080p → 720p → 480p", | |
| 3992 | + key(ActionId::Resolution) | |
| 3993 | + ), | |
| 3994 | + None => format!("{} — open a file first", key(ActionId::Resolution)), | |
| 3995 | + }, | |
| 3996 | + live, | |
| 3997 | + cx.listener(|this, _: &ClickEvent, _, cx| this.cycle_resolution(cx)), | |
| 3998 | + )) | |
| 3999 | + // How much of the timeline the panel below is showing -- | |
| 4000 | + // beside the resolution, since neither of them edits | |
| 4001 | + // anything: they are both what is being looked at. The | |
| 4002 | + // middle one reads as the state (1.0x is the whole | |
| 4003 | + // timeline) and is the way back to it. | |
| 4004 | + .child(control( | |
| 4005 | + "zoom-out", | |
| 4006 | + None, | |
| 4007 | + "−", | |
| 4008 | + format!( | |
| 4009 | + "{} — show more of the timeline; stops at the whole of it", | |
| 4010 | + key(ActionId::ZoomOut) | |
| 4011 | + ), | |
| 4012 | + live, | |
| 4013 | + cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 4014 | + this.zoom(1. / ZOOM_STEP, None, cx) | |
| 4015 | + }), | |
| 4016 | + )) | |
| 4017 | + .child(control( | |
| 4018 | + "zoom-fit", | |
| 4019 | + None, | |
| 4020 | + format!("{:.1}x", self.view.zoom), | |
| 4021 | + format!( | |
| 4022 | + "{} — fit the whole timeline; showing {} to {}", | |
| 4023 | + key(ActionId::ZoomFit), | |
| 4024 | + timecode(self.view.start, self.fps), | |
| 4025 | + timecode( | |
| 4026 | + (self.view.start + self.view.span(duration)).min(duration), | |
| 4027 | + self.fps | |
| 4028 | + ) | |
| 4029 | + ), | |
| 4030 | + live, | |
| 4031 | + cx.listener(|this, _: &ClickEvent, _, cx| this.zoom_fit(cx)), | |
| 4032 | + )) | |
| 4033 | + .child(control( | |
| 4034 | + "zoom-in", | |
| 4035 | + None, | |
| 4036 | + "+", | |
| 4037 | + format!( | |
| 4038 | + "{} — magnify around the playhead; ctrl+wheel on the bar zooms at the pointer", | |
| 4039 | + key(ActionId::ZoomIn) | |
| 4040 | + ), | |
| 4041 | + live, | |
| 4042 | + cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)), | |
| 4043 | + )) | |
| 3533 | 4044 | // Import is not here: it belongs to the media list it adds |
| 3534 | 4045 | // to, and two doors into one action is a question about |
| 3535 | 4046 | // which one is the real one. |
| 4047 | + // | |
| 4048 | + // While one runs, this button is the way out of it: the | |
| 4049 | + // progress line promised esc and nothing else, which left a | |
| 4050 | + // pointer no way to stop an export it had started. | |
| 3536 | 4051 | .child(control( |
| 3537 | 4052 | "export", |
| 3538 | 4053 | None, |
| 3539 | - "Export", | |
| 3540 | - format!( | |
| 3541 | - "{} — quality and destination, then writes the timeline out", | |
| 3542 | - key(ActionId::Export) | |
| 3543 | - ), | |
| 3544 | - live && self.export.is_none(), | |
| 3545 | - cx.listener(|this, _: &ClickEvent, _, cx| this.open_export(cx)), | |
| 4054 | + if exporting { "Cancel" } else { "Export" }, | |
| 4055 | + if exporting { | |
| 4056 | + format!( | |
| 4057 | + "{} — stops the export; the part-written file goes", | |
| 4058 | + key(ActionId::CancelExport) | |
| 4059 | + ) | |
| 4060 | + } else { | |
| 4061 | + format!( | |
| 4062 | + "{} — quality and destination, then writes the timeline out", | |
| 4063 | + key(ActionId::Export) | |
| 4064 | + ) | |
| 4065 | + }, | |
| 4066 | + if exporting { | |
| 4067 | + true | |
| 4068 | + } else { | |
| 4069 | + live && self.export.is_none() | |
| 4070 | + }, | |
| 4071 | + cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 4072 | + if this.exporting().is_some() { | |
| 4073 | + this.cancel_export(); | |
| 4074 | + cx.notify(); | |
| 4075 | + } else { | |
| 4076 | + this.open_export(cx); | |
| 4077 | + } | |
| 4078 | + }), | |
| 3546 | 4079 | )) |
| 3547 | 4080 | .child(control( |
| 3548 | 4081 | "save", |
| @@ -3620,7 +4153,32 @@ impl Player { | ||
| 3620 | 4153 | .hover(|s| s.bg(rgb(HOVER_DIM))) |
| 3621 | 4154 | // The strip carries no text, so the tooltip is the only |
| 3622 | 4155 | // place it can say what it is. |
| 3623 | - .tooltip(|_, cx| cx.new(|_| Tip("Seek — click or drag".into())).into()) | |
| 4156 | + .tooltip(|_, cx| { | |
| 4157 | + cx.new(|_| Tip("Seek — click or drag; ctrl+wheel zooms".into())) | |
| 4158 | + .into() | |
| 4159 | + }) | |
| 4160 | + // Ctrl+wheel is what every timeline zooms with, and | |
| 4161 | + // the point held still is the one under the pointer | |
| 4162 | + // rather than the playhead. Only with ctrl: a bare | |
| 4163 | + // wheel here is the window's to scroll, and the | |
| 4164 | + // controls row above scrolls on exactly that. | |
| 4165 | + .on_scroll_wheel(cx.listener( | |
| 4166 | + |this, event: &ScrollWheelEvent, _, cx| { | |
| 4167 | + if !event.modifiers.control { | |
| 4168 | + return; | |
| 4169 | + } | |
| 4170 | + let dy = match event.delta { | |
| 4171 | + ScrollDelta::Lines(d) => d.y, | |
| 4172 | + ScrollDelta::Pixels(d) => f32::from(d.y), | |
| 4173 | + }; | |
| 4174 | + if dy == 0. { | |
| 4175 | + return; | |
| 4176 | + } | |
| 4177 | + let anchor = frac_along(event.position.x, this.ruler.get()); | |
| 4178 | + let factor = if dy > 0. { ZOOM_STEP } else { 1. / ZOOM_STEP }; | |
| 4179 | + this.zoom(factor, Some(anchor), cx); | |
| 4180 | + }, | |
| 4181 | + )) | |
| 3624 | 4182 | .on_mouse_down( |
| 3625 | 4183 | MouseButton::Left, |
| 3626 | 4184 | cx.listener(|this, event: &MouseDownEvent, _, cx| { |
| @@ -4096,6 +4654,18 @@ impl Player { | ||
| 4096 | 4654 | // clip and a 48 kHz one are not the same shape. |
| 4097 | 4655 | let sample_rate = self.timeline_audio().map_or(48_000, |(rate, _)| rate); |
| 4098 | 4656 | let picked = self.eq_params.bands.get(self.eq_band); |
| 4657 | + // What is playing, drawn behind the curve -- and only while something | |
| 4658 | + // *is* playing: the tap freezes with the device, and a still spectrum | |
| 4659 | + // under a paused timeline would look like sound that is not there. | |
| 4660 | + let spectrum = self | |
| 4661 | + .eq_spectrum | |
| 4662 | + .then_some(self.session.as_ref()) | |
| 4663 | + .flatten() | |
| 4664 | + .filter(|session| session.is_playing()) | |
| 4665 | + .and_then(PlaybackSession::audio_tap) | |
| 4666 | + .map(|(samples, rate)| eq_spectrum(&samples, rate)) | |
| 4667 | + .filter(|levels| !levels.is_empty()) | |
| 4668 | + .map(eq_spectrum_curve); | |
| 4099 | 4669 | let handles: Vec<_> = self |
| 4100 | 4670 | .eq_params |
| 4101 | 4671 | .bands |
| @@ -4141,6 +4711,44 @@ impl Player { | ||
| 4141 | 4711 | }), |
| 4142 | 4712 | ) |
| 4143 | 4713 | .child(bounds_probe(self.eq_graph.clone())) |
| 4714 | + // The analyser first, so everything else is drawn on top of it. | |
| 4715 | + .children(spectrum) | |
| 4716 | + // The decades, so a hump can be read as "around 200 Hz" without | |
| 4717 | + // dropping the eye to the labels along the bottom. The two ends | |
| 4718 | + // are the box's own edges and rule nothing. | |
| 4719 | + .children( | |
| 4720 | + EQ_TICKS | |
| 4721 | + .iter() | |
| 4722 | + .filter(|(freq, _)| *freq > EQ_FREQ_LOW && *freq < EQ_FREQ_HIGH) | |
| 4723 | + .map(|(freq, _)| { | |
| 4724 | + div() | |
| 4725 | + .absolute() | |
| 4726 | + .left(relative(eq_x(*freq))) | |
| 4727 | + .w(px(1.)) | |
| 4728 | + .h_full() | |
| 4729 | + .bg(rgb(EQ_GRID)) | |
| 4730 | + }) | |
| 4731 | + .collect::<Vec<_>>(), | |
| 4732 | + ) | |
| 4733 | + // Half way to each limit, each carrying its own number: the curve | |
| 4734 | + // is a curve of decibels, and until now only one of them was drawn. | |
| 4735 | + .children(EQ_DB_GRID.map(|db| { | |
| 4736 | + div() | |
| 4737 | + .absolute() | |
| 4738 | + .top(relative(eq_y(db))) | |
| 4739 | + .w_full() | |
| 4740 | + .h(px(1.)) | |
| 4741 | + .bg(rgb(EQ_GRID)) | |
| 4742 | + .child( | |
| 4743 | + div() | |
| 4744 | + .absolute() | |
| 4745 | + .left(px(4.)) | |
| 4746 | + .top(px(-11.)) | |
| 4747 | + .text_size(px(9.)) | |
| 4748 | + .text_color(rgb(INK_DIM)) | |
| 4749 | + .child(format!("{db:+.0}")), | |
| 4750 | + ) | |
| 4751 | + })) | |
| 4144 | 4752 | // 0 dB: the line a boost is a boost *from*. |
| 4145 | 4753 | .child( |
| 4146 | 4754 | div() |
| @@ -4175,6 +4783,9 @@ impl Player { | ||
| 4175 | 4783 | .text_color(rgb(INK_DIM)) |
| 4176 | 4784 | .child(format!("+{EQ_GAIN_LIMIT:.0} dB")), |
| 4177 | 4785 | ); |
| 4786 | + // The bottom of the axis is not named: -12 dB would land in the same | |
| 4787 | + // corner as the 20 Hz tick, and the two lines above it (+6 and -6) | |
| 4788 | + // already say what the box is worth per pixel. | |
| 4178 | 4789 | Some( |
| 4179 | 4790 | div() |
| 4180 | 4791 | .absolute() |
| @@ -4209,7 +4820,7 @@ impl Player { | ||
| 4209 | 4820 | .text_size(px(11.)) |
| 4210 | 4821 | .text_color(rgb(INK_DIM)) |
| 4211 | 4822 | .child(self.notice.clone().unwrap_or_else(|| { |
| 4212 | - "drag the curve, or 1–5 then up/down — esc closes".into() | |
| 4823 | + "drag the curve, or 1–5 then up/down — s hides the spectrum, esc closes".into() | |
| 4213 | 4824 | })), |
| 4214 | 4825 | ) |
| 4215 | 4826 | .child(graph) |
| @@ -4218,34 +4829,72 @@ impl Player { | ||
| 4218 | 4829 | // one pulling the other way is not readable off it. |
| 4219 | 4830 | .child(div().flex_none().px(px(6.)).text_size(px(11.)).child( |
| 4220 | 4831 | match picked { |
| 4832 | + // Q as well as the two the curve shows: it is | |
| 4833 | + // how wide the hump under the handle is, and | |
| 4834 | + // nothing else on the card says so. | |
| 4221 | 4835 | Some(band) => format!( |
| 4222 | - "{} {} {:+.1} dB", | |
| 4836 | + "{} {} {:+.1} dB — Q {:.2}", | |
| 4223 | 4837 | self.eq_band + 1, |
| 4224 | 4838 | band_label(band), |
| 4225 | - band.gain_db | |
| 4839 | + band.gain_db, | |
| 4840 | + band.q | |
| 4226 | 4841 | ), |
| 4227 | 4842 | None => "no bands".into(), |
| 4228 | 4843 | }, |
| 4229 | 4844 | )) |
| 4230 | 4845 | .child( |
| 4231 | 4846 | div() |
| 4232 | - .id("eq-reset") | |
| 4233 | 4847 | .mt(px(4.)) |
| 4234 | 4848 | .flex() |
| 4235 | - .h(px(CONTROL_H)) | |
| 4236 | - .items_center() | |
| 4237 | - .justify_center() | |
| 4238 | - .rounded(px(3.)) | |
| 4239 | - .bg(rgb(SELECTED)) | |
| 4240 | - .cursor_pointer() | |
| 4241 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 4242 | - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 4243 | - for band in &mut this.eq_params.bands { | |
| 4244 | - band.gain_db = 0.; | |
| 4245 | - } | |
| 4246 | - this.commit_eq(cx); | |
| 4247 | - })) | |
| 4248 | - .child("Flatten"), | |
| 4849 | + .gap(px(4.)) | |
| 4850 | + .child( | |
| 4851 | + div() | |
| 4852 | + .id("eq-reset") | |
| 4853 | + .flex() | |
| 4854 | + .flex_1() | |
| 4855 | + .h(px(CONTROL_H)) | |
| 4856 | + .items_center() | |
| 4857 | + .justify_center() | |
| 4858 | + .rounded(px(3.)) | |
| 4859 | + .bg(rgb(SELECTED)) | |
| 4860 | + .cursor_pointer() | |
| 4861 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 4862 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 4863 | + for band in &mut this.eq_params.bands { | |
| 4864 | + band.gain_db = 0.; | |
| 4865 | + } | |
| 4866 | + this.commit_eq(cx); | |
| 4867 | + })) | |
| 4868 | + .child("Flatten"), | |
| 4869 | + ) | |
| 4870 | + // The analyser's switch, next to the one other | |
| 4871 | + // button the card has: `s` does the same, and a | |
| 4872 | + // toggle only a keystroke can reach is one most | |
| 4873 | + // people never find. | |
| 4874 | + .child( | |
| 4875 | + div() | |
| 4876 | + .id("eq-spectrum") | |
| 4877 | + .flex() | |
| 4878 | + .flex_1() | |
| 4879 | + .h(px(CONTROL_H)) | |
| 4880 | + .items_center() | |
| 4881 | + .justify_center() | |
| 4882 | + .rounded(px(3.)) | |
| 4883 | + .bg(rgb(match self.eq_spectrum { | |
| 4884 | + true => SELECTED, | |
| 4885 | + false => HOVER_DIM, | |
| 4886 | + })) | |
| 4887 | + .cursor_pointer() | |
| 4888 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 4889 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 4890 | + this.eq_spectrum = !this.eq_spectrum; | |
| 4891 | + cx.notify(); | |
| 4892 | + })) | |
| 4893 | + .child(match self.eq_spectrum { | |
| 4894 | + true => "Spectrum on", | |
| 4895 | + false => "Spectrum off", | |
| 4896 | + }), | |
| 4897 | + ), | |
| 4249 | 4898 | ), |
| 4250 | 4899 | ), |
| 4251 | 4900 | ) |
| @@ -4548,9 +5197,19 @@ impl Player { | ||
| 4548 | 5197 | fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { |
| 4549 | 5198 | let (lane, idx) = self.silence_open?; |
| 4550 | 5199 | let cfg = self.silence; |
| 5200 | + // The unit is a label, never a conversion: the threshold is a level | |
| 5201 | + // below full scale whichever of the two the row says (`silence_dbfs`). | |
| 5202 | + let unit = match self.silence_dbfs { | |
| 5203 | + true => "dBFS", | |
| 5204 | + false => "dB", | |
| 5205 | + }; | |
| 4551 | 5206 | let rows = [ |
| 4552 | 5207 | ("Apply to", self.silence_scope.label(&self.silence_lanes())), |
| 4553 | - ("Silence is under", format!("{:.0} dBFS", cfg.threshold_db)), | |
| 5208 | + ( | |
| 5209 | + "Silence is under", | |
| 5210 | + format!("{:.0} {unit}", cfg.threshold_db), | |
| 5211 | + ), | |
| 5212 | + ("Level read in", format!("{unit} (0 = full scale)")), | |
| 4554 | 5213 | ( |
| 4555 | 5214 | "Forgive quiet shorter than", |
| 4556 | 5215 | format!("{:.2} s", cfg.min_silence), |
| @@ -4591,7 +5250,45 @@ impl Player { | ||
| 4591 | 5250 | cx.notify(); |
| 4592 | 5251 | })) |
| 4593 | 5252 | .child(div().text_color(rgb(INK_DIM)).child(label)) |
| 4594 | - .child(value) | |
| 5253 | + // The value and the two steps that move it. Every other | |
| 5254 | + // card has something to drag or press; this one had the | |
| 5255 | + // arrow keys and nothing else, so a row was a setting a | |
| 5256 | + // pointer could pick but never change. One press each, the | |
| 5257 | + // same call the arrows make -- the hold-to-run is the | |
| 5258 | + // keyboard's own and is not a thing a button has. | |
| 5259 | + .child( | |
| 5260 | + div() | |
| 5261 | + .flex() | |
| 5262 | + .items_center() | |
| 5263 | + .gap(px(4.)) | |
| 5264 | + .child(value) | |
| 5265 | + .children([-1, 1].map(|steps: i32| { | |
| 5266 | + div() | |
| 5267 | + .id(("silence-step", n * 2 + usize::from(steps > 0))) | |
| 5268 | + .flex_none() | |
| 5269 | + .w(px(HIT_MIN)) | |
| 5270 | + .h(px(KEYS_ROW_H)) | |
| 5271 | + .flex() | |
| 5272 | + .items_center() | |
| 5273 | + .justify_center() | |
| 5274 | + .rounded(px(3.)) | |
| 5275 | + .bg(rgb(CHROME)) | |
| 5276 | + .cursor_pointer() | |
| 5277 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 5278 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 5279 | + // Picked as well as moved: the row a | |
| 5280 | + // press lands on is the row the arrows | |
| 5281 | + // carry on from. | |
| 5282 | + this.silence_field = n; | |
| 5283 | + this.nudge_silence(steps); | |
| 5284 | + cx.notify(); | |
| 5285 | + })) | |
| 5286 | + .child(match steps > 0 { | |
| 5287 | + true => "+", | |
| 5288 | + false => "−", | |
| 5289 | + }) | |
| 5290 | + })), | |
| 5291 | + ) | |
| 4595 | 5292 | }) |
| 4596 | 5293 | .collect(); |
| 4597 | 5294 | // The two buttons the ask names, side by side: a mode toggle would hide |
| @@ -4649,7 +5346,7 @@ impl Player { | ||
| 4649 | 5346 | .text_size(px(11.)) |
| 4650 | 5347 | .text_color(rgb(INK_DIM)) |
| 4651 | 5348 | .child( |
| 4652 | - "↑↓ picks a setting, ←→ moves it — the marks on the lane are what would go; esc closes", | |
| 5349 | + "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes", | |
| 4653 | 5350 | ), |
| 4654 | 5351 | ) |
| 4655 | 5352 | .children(rows) |
| @@ -4930,7 +5627,7 @@ impl Player { | ||
| 4930 | 5627 | // The one item that is not about this clip says so, and says it |
| 4931 | 5628 | // here rather than in the registry: the stroke is global too, |
| 4932 | 5629 | // but its row in the keys menu is not sitting on a clip. |
| 4933 | - let label = if action == ActionId::ToggleMute { | |
| 5630 | + let label = if matches!(action, ActionId::ToggleMute | ActionId::Paste) { | |
| 4934 | 5631 | format!("{} (global)", action.label()) |
| 4935 | 5632 | } else { |
| 4936 | 5633 | action.label().to_string() |
| @@ -4977,7 +5674,10 @@ impl Player { | ||
| 4977 | 5674 | let (x, y) = menu_at( |
| 4978 | 5675 | menu.at, |
| 4979 | 5676 | viewport, |
| 4980 | - MENU_PAD * 2. + rows.len() as f32 * MENU_ROW_H, | |
| 5677 | + // The cap once the list is longer than it: past that the list | |
| 5678 | + // scrolls and the card stops growing, exactly as the keybindings and | |
| 5679 | + // export lists do. | |
| 5680 | + MENU_PAD * 2. + (rows.len() as f32 * MENU_ROW_H).min(MENU_ROWS_H), | |
| 4981 | 5681 | ); |
| 4982 | 5682 | let full: SharedString = source.path.display().to_string().into(); |
| 4983 | 5683 | Some( |
| @@ -5032,7 +5732,18 @@ impl Player { | ||
| 5032 | 5732 | .when(menu.details, |d| { |
| 5033 | 5733 | d.tooltip(move |_, cx| cx.new(|_| Tip(full.clone())).into()) |
| 5034 | 5734 | }) |
| 5035 | - .children(rows), | |
| 5735 | + // The list scrolls where the card would otherwise grow | |
| 5736 | + // past the window's floor -- an item hanging off the | |
| 5737 | + // bottom edge is an item nobody can click. | |
| 5738 | + .child( | |
| 5739 | + div() | |
| 5740 | + .id("menu-rows") | |
| 5741 | + .flex() | |
| 5742 | + .flex_col() | |
| 5743 | + .max_h(px(MENU_ROWS_H)) | |
| 5744 | + .overflow_y_scroll() | |
| 5745 | + .children(rows), | |
| 5746 | + ), | |
| 5036 | 5747 | ), |
| 5037 | 5748 | ) |
| 5038 | 5749 | } |
| @@ -5059,6 +5770,9 @@ impl Player { | ||
| 5059 | 5770 | // one probe answers for both. Zero before the first paint, which only |
| 5060 | 5771 | // costs the labels one frame. |
| 5061 | 5772 | let bed_w = f32::from(self.ruler.get().size.width); |
| 5773 | + // The slice being shown, copied out once: every box in the row is | |
| 5774 | + // placed through it, so all of them move together when it does. | |
| 5775 | + let view = self.view; | |
| 5062 | 5776 | let clips = self |
| 5063 | 5777 | .session |
| 5064 | 5778 | .as_ref() |
| @@ -5077,6 +5791,12 @@ impl Player { | ||
| 5077 | 5791 | }); |
| 5078 | 5792 | let name = lane.label(); |
| 5079 | 5793 | let row_id: SharedString = format!("{name}-clip").into(); |
| 5794 | + let remove_id: SharedString = format!("{name}-remove").into(); | |
| 5795 | + let remove_tip: SharedString = format!( | |
| 5796 | + "Remove {name} — it must be empty first, and {} brings it back", | |
| 5797 | + self.keymap.display(ActionId::Undo) | |
| 5798 | + ) | |
| 5799 | + .into(); | |
| 5080 | 5800 | let sources = self |
| 5081 | 5801 | .session |
| 5082 | 5802 | .as_ref() |
| @@ -5106,20 +5826,44 @@ impl Player { | ||
| 5106 | 5826 | .w(px(HEADER_W)) |
| 5107 | 5827 | .h_full() |
| 5108 | 5828 | .flex() |
| 5829 | + .flex_col() | |
| 5109 | 5830 | .items_center() |
| 5110 | 5831 | .justify_center() |
| 5111 | 5832 | .rounded(px(3.)) |
| 5112 | 5833 | .bg(rgb(SURFACE)) |
| 5113 | 5834 | .text_size(px(11.)) |
| 5114 | 5835 | .text_color(rgb(INK_DIM)) |
| 5115 | - .child(name), | |
| 5116 | - ) | |
| 5117 | - .child( | |
| 5118 | - // Clips are placed at their own start rather than queued edge | |
| 5119 | - // to edge: a lift leaves a hole in the lane, and the bare bed | |
| 5120 | - // showing through it *is* how a gap looks. | |
| 5121 | - div() | |
| 5122 | - .relative() | |
| 5836 | + .child(div().flex_1().flex().items_center().child(name)) | |
| 5837 | + // The one thing a header does: take this track away again. | |
| 5838 | + // A `HIT_MIN` target rather than a glyph-sized one, and it | |
| 5839 | + // stays put on a track holding clips instead of hiding -- | |
| 5840 | + // the refusal names them, and a control that vanishes | |
| 5841 | + // teaches nothing. | |
| 5842 | + .child( | |
| 5843 | + div() | |
| 5844 | + .id(remove_id) | |
| 5845 | + .flex_none() | |
| 5846 | + .w_full() | |
| 5847 | + .h(px(HIT_MIN)) | |
| 5848 | + .flex() | |
| 5849 | + .items_center() | |
| 5850 | + .justify_center() | |
| 5851 | + .rounded(px(3.)) | |
| 5852 | + .cursor_pointer() | |
| 5853 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 5854 | + .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) | |
| 5855 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 5856 | + this.remove_lane(lane, cx) | |
| 5857 | + })) | |
| 5858 | + .child("×"), | |
| 5859 | + ), | |
| 5860 | + ) | |
| 5861 | + .child( | |
| 5862 | + // Clips are placed at their own start rather than queued edge | |
| 5863 | + // to edge: a lift leaves a hole in the lane, and the bare bed | |
| 5864 | + // showing through it *is* how a gap looks. | |
| 5865 | + div() | |
| 5866 | + .relative() | |
| 5123 | 5867 | .flex_1() |
| 5124 | 5868 | .min_w(px(0.)) |
| 5125 | 5869 | .h_full() |
| @@ -5166,7 +5910,7 @@ impl Player { | ||
| 5166 | 5910 | .and_then(|s| sources.iter().position(|o| o.path == s.path)) |
| 5167 | 5911 | .unwrap_or(clip.source), |
| 5168 | 5912 | ); |
| 5169 | - let width = width_frac(len, duration); | |
| 5913 | + let width = view.width_frac(len, duration); | |
| 5170 | 5914 | let label = sources.get(clip.source).map(|s| file_name(&s.path)); |
| 5171 | 5915 | let wave = sources |
| 5172 | 5916 | .get(clip.source) |
| @@ -5190,7 +5934,11 @@ impl Player { | ||
| 5190 | 5934 | .absolute() |
| 5191 | 5935 | .top_0() |
| 5192 | 5936 | .h_full() |
| 5193 | - .left(relative(start_frac(start, duration))) | |
| 5937 | + // Negative once the clip's head has been scrolled | |
| 5938 | + // off the left edge: the bed clips what hangs out | |
| 5939 | + // of it, so a half-visible clip is drawn as the | |
| 5940 | + // half of itself that is on screen. | |
| 5941 | + .left(relative(view.frac_at(start, duration))) | |
| 5194 | 5942 | .w(relative(width)) |
| 5195 | 5943 | .overflow_hidden() |
| 5196 | 5944 | .rounded(px(3.)) |
| @@ -5339,8 +6087,12 @@ impl Player { | ||
| 5339 | 6087 | .absolute() |
| 5340 | 6088 | .top_0() |
| 5341 | 6089 | .h_full() |
| 5342 | - .left(relative(start_frac(f64::from(at) / self.fps, duration))) | |
| 5343 | - .w(relative(width_frac(f64::from(len) / self.fps, duration))) | |
| 6090 | + .left(relative( | |
| 6091 | + view.frac_at(f64::from(at) / self.fps, duration), | |
| 6092 | + )) | |
| 6093 | + .w(relative( | |
| 6094 | + view.width_frac(f64::from(len) / self.fps, duration), | |
| 6095 | + )) | |
| 5344 | 6096 | .bg(rgba(0x4a9effaa)) |
| 5345 | 6097 | }), |
| 5346 | 6098 | ) |
| @@ -5650,6 +6402,28 @@ fn can_add(picked: Option<&(PathBuf, usize)>, timeline: bool, exporting: bool) - | ||
| 5650 | 6402 | picked.is_some() && timeline && !exporting |
| 5651 | 6403 | } |
| 5652 | 6404 | |
| 6405 | +/// What is left on the clipboard after the library row at `removed` was taken | |
| 6406 | +/// out. A copied clip names its file by *index* into the source list | |
| 6407 | +/// (`engine::Clip::source`) and a removal renumbers that list | |
| 6408 | +/// (`engine::Project::remove_source`), so a clipboard kept as it was would paste | |
| 6409 | +/// **a different file** -- the next one along -- over the range it was copied | |
| 6410 | +/// from. | |
| 6411 | +/// | |
| 6412 | +/// The clip's own file gone means there is nothing to paste: `None`, and the | |
| 6413 | +/// next paste says the clipboard is empty rather than putting some other take | |
| 6414 | +/// down. Every index past it moves down by one, exactly as the lanes' clips do. | |
| 6415 | +fn clipboard_after_remove(clip: Option<Clip>, removed: usize) -> Option<Clip> { | |
| 6416 | + let mut clip = clip?; | |
| 6417 | + match clip.source.cmp(&removed) { | |
| 6418 | + std::cmp::Ordering::Equal => None, | |
| 6419 | + std::cmp::Ordering::Greater => { | |
| 6420 | + clip.source -= 1; | |
| 6421 | + Some(clip) | |
| 6422 | + } | |
| 6423 | + std::cmp::Ordering::Less => Some(clip), | |
| 6424 | + } | |
| 6425 | +} | |
| 6426 | + | |
| 5653 | 6427 | /// One library row: a file and one of its audio streams. Plain data, planned |
| 5654 | 6428 | /// before anything is drawn -- which rows exist at all is the branchy part. |
| 5655 | 6429 | #[derive(Debug, PartialEq)] |
| @@ -5895,7 +6669,7 @@ impl Quality { | ||
| 5895 | 6669 | /// that opens but never comes back out is exactly the gap a user would other- |
| 5896 | 6670 | /// wise go looking for. |
| 5897 | 6671 | const FORMATS: [(Option<Format>, &str, &str); 9] = [ |
| 5898 | - (Some(Format::Mp4), "MP4", "H.264 picture + copied AAC"), | |
| 6672 | + (Some(Format::Mp4), "MP4", "H.264 picture + AAC sound"), | |
| 5899 | 6673 | ( |
| 5900 | 6674 | Some(Format::Av1), |
| 5901 | 6675 | "AV1", |
| @@ -5905,7 +6679,7 @@ const FORMATS: [(Option<Format>, &str, &str); 9] = [ | ||
| 5905 | 6679 | (Some(Format::Flac), "FLAC", "lossless — audio only"), |
| 5906 | 6680 | (None, "MP3", "encoder is LGPL — licence decision pending"), |
| 5907 | 6681 | (None, "OGG", "no pure-Rust Vorbis or Opus encoder"), |
| 5908 | - (None, "AAC", "encoder exists (rusty_aac) but is not wired here yet"), | |
| 6682 | + (None, "AAC", "an MP4's sound here, not a file of its own"), | |
| 5909 | 6683 | ( |
| 5910 | 6684 | None, |
| 5911 | 6685 | "HEVC", |
| @@ -6142,6 +6916,50 @@ fn cancels_export(key: &str, action: Option<ActionId>) -> bool { | ||
| 6142 | 6916 | key == ESCAPE || action == Some(ActionId::CancelExport) |
| 6143 | 6917 | } |
| 6144 | 6918 | |
| 6919 | +/// Where a held key would land, which is the whole of what auto-repeat has to | |
| 6920 | +/// know. [`Player::repeat_scope`] answers it from the same state the handler | |
| 6921 | +/// walks below itself. | |
| 6922 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] | |
| 6923 | +enum Repeat { | |
| 6924 | + /// A card with values in it owns the keyboard: equalizer, colour, speed or | |
| 6925 | + /// silence. Its arrows are sliders. | |
| 6926 | + Card, | |
| 6927 | + /// Nobody does, so the keymap answers -- and only one pair of its actions | |
| 6928 | + /// is a value being moved rather than a thing being done once. | |
| 6929 | + Keymap, | |
| 6930 | + /// A stroke is being captured, an export is running, or an overlay with no | |
| 6931 | + /// value in it is up. Nothing there is worth a repeat. | |
| 6932 | + Nothing, | |
| 6933 | +} | |
| 6934 | + | |
| 6935 | +/// Whether a *held* stroke means it again. One press is always one action; a | |
| 6936 | +/// hold is only ever a value running, so this is what tells the two apart. | |
| 6937 | +/// | |
| 6938 | +/// The cards' arrows, because that is what every one of them moves a slider | |
| 6939 | +/// with -- and only the arrows, so the equalizer's `r` cannot flatten five | |
| 6940 | +/// bands forty times a second and the silence card's `enter` cannot cut forty | |
| 6941 | +/// places again on the next tick. Outside a card the volume pair and nothing | |
| 6942 | +/// else: play, cut, delete, save, export and every other binding is a one-shot, | |
| 6943 | +/// exactly as it was when the handler filtered every held key alike. | |
| 6944 | +fn repeats(scope: Repeat, key: &str, action: Option<ActionId>) -> bool { | |
| 6945 | + match scope { | |
| 6946 | + Repeat::Card => matches!(key, "up" | "down" | "left" | "right"), | |
| 6947 | + Repeat::Keymap => matches!( | |
| 6948 | + action, | |
| 6949 | + Some( | |
| 6950 | + ActionId::VolumeUp | |
| 6951 | + | ActionId::VolumeDown | |
| 6952 | + // A zoom is a value being moved as much as a level is: | |
| 6953 | + // held, it runs from the whole timeline down to a handful | |
| 6954 | + // of frames and stops there. The fit is one press. | |
| 6955 | + | ActionId::ZoomIn | |
| 6956 | + | ActionId::ZoomOut | |
| 6957 | + ) | |
| 6958 | + ), | |
| 6959 | + Repeat::Nothing => false, | |
| 6960 | + } | |
| 6961 | +} | |
| 6962 | + | |
| 6145 | 6963 | /// The keys that are only ever half a chord. gpui delivers a lone modifier |
| 6146 | 6964 | /// press as a keystroke of its own, and taking one as a binding would leave an |
| 6147 | 6965 | /// action that fires the moment the user reaches for any chord that uses it -- |
| @@ -6235,14 +7053,127 @@ fn width_frac(len: f64, total: f64) -> f32 { | ||
| 6235 | 7053 | if total > 0. { (len / total) as f32 } else { 1. } |
| 6236 | 7054 | } |
| 6237 | 7055 | |
| 6238 | -/// Where along the lane a clip starts, 0..1. Unlike [`width_frac`] a timeline | |
| 6239 | -/// with no length pins this to the left edge -- a full-width offset would push | |
| 6240 | -/// the box out of the lane it belongs to. | |
| 6241 | -fn start_frac(start: f64, total: f64) -> f32 { | |
| 6242 | - if total > 0. { | |
| 6243 | - (start / total).clamp(0., 1.) as f32 | |
| 6244 | - } else { | |
| 6245 | - 0. | |
| 7056 | +/// One press of a zoom key, or one notch of ctrl+wheel. | |
| 7057 | +const ZOOM_STEP: f32 = 1.25; | |
| 7058 | + | |
| 7059 | +/// How few frames the bed may be narrowed down to. Past this there is nothing | |
| 7060 | +/// left to aim at -- a single frame across a whole window is a wall of colour, | |
| 7061 | +/// not an edit surface. | |
| 7062 | +const ZOOM_MIN_FRAMES: f64 = 8.; | |
| 7063 | + | |
| 7064 | +/// Which slice of the timeline the ruler and the lanes are showing: `zoom` is | |
| 7065 | +/// how many times the whole of it the bed is now worth, and `start` the moment | |
| 7066 | +/// at the bed's left edge. The one place frames become pixels -- every box, the | |
| 7067 | +/// playhead, a seek and a trim all go through it, so none of them can drift | |
| 7068 | +/// away from the others when the view moves. | |
| 7069 | +/// | |
| 7070 | +/// [`View::default`] is the whole timeline across the bed, which is what the | |
| 7071 | +/// panel drew before there was a zoom at all: at zoom 1 `start` is pinned to 0 | |
| 7072 | +/// and every fraction here is the one [`width_frac`] and `start_frac` gave. | |
| 7073 | +#[derive(Clone, Copy, Debug, PartialEq)] | |
| 7074 | +struct View { | |
| 7075 | + zoom: f32, | |
| 7076 | + start: f64, | |
| 7077 | +} | |
| 7078 | + | |
| 7079 | +impl Default for View { | |
| 7080 | + fn default() -> Self { | |
| 7081 | + View { | |
| 7082 | + zoom: 1., | |
| 7083 | + start: 0., | |
| 7084 | + } | |
| 7085 | + } | |
| 7086 | +} | |
| 7087 | + | |
| 7088 | +impl View { | |
| 7089 | + /// How much of the timeline is on the bed, in seconds. | |
| 7090 | + fn span(self, duration: f64) -> f64 { | |
| 7091 | + duration / f64::from(self.zoom) | |
| 7092 | + } | |
| 7093 | + | |
| 7094 | + /// The tightest this timeline may be zoomed: [`ZOOM_MIN_FRAMES`] across the | |
| 7095 | + /// bed. Never under 1 -- a timeline shorter than that is already at its | |
| 7096 | + /// floor, and a zoom that cannot fit the whole of it is not a zoom. | |
| 7097 | + fn max_zoom(duration: f64, fps: f64) -> f32 { | |
| 7098 | + let frames = duration * fps; | |
| 7099 | + if frames > ZOOM_MIN_FRAMES { | |
| 7100 | + (frames / ZOOM_MIN_FRAMES) as f32 | |
| 7101 | + } else { | |
| 7102 | + 1. | |
| 7103 | + } | |
| 7104 | + } | |
| 7105 | + | |
| 7106 | + /// Where a moment sits along the bed, 0 at its left edge and 1 at its | |
| 7107 | + /// right. Outside that range for a moment scrolled off the view, which is | |
| 7108 | + /// exactly the negative offset a half-visible clip is drawn at. | |
| 7109 | + fn frac_at(self, at: f64, duration: f64) -> f32 { | |
| 7110 | + let span = self.span(duration); | |
| 7111 | + if span > 0. { | |
| 7112 | + ((at - self.start) / span) as f32 | |
| 7113 | + } else { | |
| 7114 | + 0. | |
| 7115 | + } | |
| 7116 | + } | |
| 7117 | + | |
| 7118 | + /// How wide a stretch of `len` seconds is on the bed. More than the whole | |
| 7119 | + /// bed once zoomed in, which is the point of zooming in. | |
| 7120 | + fn width_frac(self, len: f64, duration: f64) -> f32 { | |
| 7121 | + width_frac(len, self.span(duration)) | |
| 7122 | + } | |
| 7123 | + | |
| 7124 | + /// The moment a pointer at `frac` along the bed is pointing at: the inverse | |
| 7125 | + /// of [`View::frac_at`], and what every seek and every trim reads. | |
| 7126 | + fn time_at(self, frac: f32, duration: f64) -> f64 { | |
| 7127 | + (self.start + f64::from(frac) * self.span(duration)).clamp(0., duration) | |
| 7128 | + } | |
| 7129 | + | |
| 7130 | + /// Zoomed by `factor` about `anchor` (0..1 along the bed): whatever moment | |
| 7131 | + /// was under that point stays under it, so a zoom magnifies what was being | |
| 7132 | + /// looked at rather than throwing it off the edge. | |
| 7133 | + fn zoomed(self, factor: f32, anchor: f32, duration: f64, fps: f64) -> Self { | |
| 7134 | + let at = self.start + f64::from(anchor) * self.span(duration); | |
| 7135 | + // Clamped *before* the offset is worked out, not after: a press that | |
| 7136 | + // runs into either stop must still leave the anchor where it is, and a | |
| 7137 | + // start measured against a zoom the stop then took away would slide it. | |
| 7138 | + let zoom = (self.zoom * factor).clamp(1., Self::max_zoom(duration, fps)); | |
| 7139 | + let start = at - f64::from(anchor) * View { zoom, start: 0. }.span(duration); | |
| 7140 | + View { zoom, start }.settled(duration, fps) | |
| 7141 | + } | |
| 7142 | + | |
| 7143 | + /// Clamped to the timeline it draws: never wider than the whole of it (the | |
| 7144 | + /// zoom-out floor is the fit), never tighter than [`View::max_zoom`], and | |
| 7145 | + /// never scrolled past either end. | |
| 7146 | + fn settled(self, duration: f64, fps: f64) -> Self { | |
| 7147 | + let zoom = if self.zoom.is_finite() { | |
| 7148 | + self.zoom.clamp(1., Self::max_zoom(duration, fps)) | |
| 7149 | + } else { | |
| 7150 | + 1. | |
| 7151 | + }; | |
| 7152 | + let span = View { zoom, start: 0. }.span(duration); | |
| 7153 | + let start = if self.start.is_finite() { | |
| 7154 | + self.start.clamp(0., (duration - span).max(0.)) | |
| 7155 | + } else { | |
| 7156 | + 0. | |
| 7157 | + }; | |
| 7158 | + View { zoom, start } | |
| 7159 | + } | |
| 7160 | + | |
| 7161 | + /// The view a playhead at `at` needs: the same one while it is on the bed, | |
| 7162 | + /// and one centred on it once it has run off -- which is how a zoomed-in | |
| 7163 | + /// timeline scrolls, during playback and after a seek alike. At the fit | |
| 7164 | + /// this can never fire, so an unzoomed panel is untouched by it. | |
| 7165 | + fn following(self, at: f64, duration: f64, fps: f64) -> Self { | |
| 7166 | + let view = self.settled(duration, fps); | |
| 7167 | + let span = view.span(duration); | |
| 7168 | + if at < view.start || at > view.start + span { | |
| 7169 | + View { | |
| 7170 | + start: at - span / 2., | |
| 7171 | + ..view | |
| 7172 | + } | |
| 7173 | + .settled(duration, fps) | |
| 7174 | + } else { | |
| 7175 | + view | |
| 7176 | + } | |
| 6246 | 7177 | } |
| 6247 | 7178 | } |
| 6248 | 7179 | |
| @@ -6440,6 +7371,59 @@ fn control( | ||
| 6440 | 7371 | }) |
| 6441 | 7372 | } |
| 6442 | 7373 | |
| 7374 | +/// The monitoring level as something to drag: 4 px of bar to look at and the | |
| 7375 | +/// whole control's height to hit (WCAG 2.5.8), the split the speed bar and the | |
| 7376 | +/// colour sliders both make. Only the level -- mute is the button beside it, so | |
| 7377 | +/// a muted slider still shows what unmuting comes back to, drawn dim. | |
| 7378 | +/// | |
| 7379 | +/// Dimmed and inert without a timeline, like every other control that would | |
| 7380 | +/// have nothing to act on. | |
| 7381 | +fn volume_slider( | |
| 7382 | + volume: Volume, | |
| 7383 | + bar: Rc<Cell<Bounds<Pixels>>>, | |
| 7384 | + enabled: bool, | |
| 7385 | + cx: &mut Context<Player>, | |
| 7386 | +) -> impl IntoElement { | |
| 7387 | + div() | |
| 7388 | + .id("volume-bar") | |
| 7389 | + .relative() | |
| 7390 | + .flex_none() | |
| 7391 | + .w(px(VOLUME_W)) | |
| 7392 | + .h(px(CONTROL_H)) | |
| 7393 | + .flex() | |
| 7394 | + .items_center() | |
| 7395 | + .tooltip(|_, cx| { | |
| 7396 | + cx.new(|_| Tip("Volume — drag to set the level; the button mutes".into())) | |
| 7397 | + .into() | |
| 7398 | + }) | |
| 7399 | + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | |
| 7400 | + .when(enabled, |d| { | |
| 7401 | + d.cursor_pointer() | |
| 7402 | + .on_mouse_down( | |
| 7403 | + MouseButton::Left, | |
| 7404 | + cx.listener(|this, event: &MouseDownEvent, _, cx| { | |
| 7405 | + this.volume_dragging = true; | |
| 7406 | + this.drag_volume(event.position.x, cx); | |
| 7407 | + }), | |
| 7408 | + ) | |
| 7409 | + .child(bounds_probe(bar)) | |
| 7410 | + }) | |
| 7411 | + .child( | |
| 7412 | + div() | |
| 7413 | + .w_full() | |
| 7414 | + .h(px(4.)) | |
| 7415 | + .rounded(px(2.)) | |
| 7416 | + .bg(rgb(SURFACE)) | |
| 7417 | + .child( | |
| 7418 | + div() | |
| 7419 | + .h_full() | |
| 7420 | + .w(relative(volume.along())) | |
| 7421 | + .rounded(px(2.)) | |
| 7422 | + .bg(rgb(if volume.muted { INK_DIM } else { ACCENT })), | |
| 7423 | + ), | |
| 7424 | + ) | |
| 7425 | +} | |
| 7426 | + | |
| 6443 | 7427 | /// The line between two groups of buttons. |
| 6444 | 7428 | fn separator() -> impl IntoElement { |
| 6445 | 7429 | div() |
| @@ -6599,6 +7583,131 @@ fn hist_curves(bins: [[u32; HIST_BINS]; 3]) -> impl IntoElement { | ||
| 6599 | 7583 | .size_full() |
| 6600 | 7584 | } |
| 6601 | 7585 | |
| 7586 | +/// In-place radix-2 FFT of `re`/`im`, whose length must be a power of two. | |
| 7587 | +/// | |
| 7588 | +/// Hand-written, and deliberately: a 1024-point transform once a frame is a | |
| 7589 | +/// few tens of microseconds of plain arithmetic, and a dependency for it would | |
| 7590 | +/// be a build cost this editor pays on every compile for one card's backdrop. | |
| 7591 | +fn fft(re: &mut [f32], im: &mut [f32]) { | |
| 7592 | + let n = re.len(); | |
| 7593 | + // Decimation in time: the input is first put in bit-reversed order, after | |
| 7594 | + // which the butterflies run over neighbours. | |
| 7595 | + let mut j = 0usize; | |
| 7596 | + for i in 1..n { | |
| 7597 | + let mut bit = n >> 1; | |
| 7598 | + while j & bit != 0 { | |
| 7599 | + j ^= bit; | |
| 7600 | + bit >>= 1; | |
| 7601 | + } | |
| 7602 | + j |= bit; | |
| 7603 | + if i < j { | |
| 7604 | + re.swap(i, j); | |
| 7605 | + im.swap(i, j); | |
| 7606 | + } | |
| 7607 | + } | |
| 7608 | + let mut span = 2; | |
| 7609 | + while span <= n { | |
| 7610 | + let step = std::f32::consts::TAU / span as f32; | |
| 7611 | + for start in (0..n).step_by(span) { | |
| 7612 | + for k in 0..span / 2 { | |
| 7613 | + // e^{-i2πk/span}: the negative sign is the forward transform. | |
| 7614 | + let (sin, cos) = (-step * k as f32).sin_cos(); | |
| 7615 | + let (a, b) = (start + k, start + k + span / 2); | |
| 7616 | + let (tr, ti) = (cos * re[b] - sin * im[b], cos * im[b] + sin * re[b]); | |
| 7617 | + re[b] = re[a] - tr; | |
| 7618 | + im[b] = im[a] - ti; | |
| 7619 | + re[a] += tr; | |
| 7620 | + im[a] += ti; | |
| 7621 | + } | |
| 7622 | + } | |
| 7623 | + span <<= 1; | |
| 7624 | + } | |
| 7625 | +} | |
| 7626 | + | |
| 7627 | +/// The played signal as one height per curve point, 0 (silence) to 1 (the top | |
| 7628 | +/// of the box) -- the analyser the response curve is drawn on top of. | |
| 7629 | +/// | |
| 7630 | +/// The newest [`EQ_FFT`] samples of the engine's tap, Hann-windowed so a tone | |
| 7631 | +/// that does not land on a bin centre is one hump rather than a smear across | |
| 7632 | +/// the axis. Each column takes the *loudest* bin between it and its | |
| 7633 | +/// neighbours: the axis is logarithmic, so one column near 20 Hz is a fraction | |
| 7634 | +/// of a bin while one near 20 kHz is hundreds, and averaging those would sink | |
| 7635 | +/// every peak up there into the noise beside it. | |
| 7636 | +/// | |
| 7637 | +/// Empty -- nothing to draw -- for a tap too short to transform, which is what | |
| 7638 | +/// a session has just after a seek. | |
| 7639 | +/// | |
| 7640 | +/// ponytail: one transform length for the whole axis, so the bass end is a bin | |
| 7641 | +/// (47 Hz at 48 kHz) wide however many columns are drawn across it -- a 60 Hz | |
| 7642 | +/// hum and an 80 Hz one are the same hump down there. Upgrade path is the | |
| 7643 | +/// analyser every mastering EQ uses: two or three transforms of different | |
| 7644 | +/// lengths, each drawn over the octaves it resolves. | |
| 7645 | +fn eq_spectrum(samples: &[f32], sample_rate: u32) -> Vec<f32> { | |
| 7646 | + if samples.len() < EQ_FFT { | |
| 7647 | + return Vec::new(); | |
| 7648 | + } | |
| 7649 | + let tail = &samples[samples.len() - EQ_FFT..]; | |
| 7650 | + let mut re: Vec<f32> = tail | |
| 7651 | + .iter() | |
| 7652 | + .enumerate() | |
| 7653 | + .map(|(i, s)| { | |
| 7654 | + let w = 0.5 * (1. - (std::f32::consts::TAU * i as f32 / EQ_FFT as f32).cos()); | |
| 7655 | + s * w | |
| 7656 | + }) | |
| 7657 | + .collect(); | |
| 7658 | + let mut im = vec![0.; EQ_FFT]; | |
| 7659 | + fft(&mut re, &mut im); | |
| 7660 | + // Magnitude per bin, scaled so a full-scale sine reads 0 dBFS: half the | |
| 7661 | + // energy is in the mirrored half of the transform, and the Hann window | |
| 7662 | + // takes another factor of two off. | |
| 7663 | + let mags: Vec<f32> = (0..EQ_FFT / 2) | |
| 7664 | + .map(|k| (re[k] * re[k] + im[k] * im[k]).sqrt() * 4. / EQ_FFT as f32) | |
| 7665 | + .collect(); | |
| 7666 | + let bin_hz = sample_rate as f32 / EQ_FFT as f32; | |
| 7667 | + let (floor, ceiling) = EQ_SPECTRUM_DB; | |
| 7668 | + let at = |along: f32| EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along); | |
| 7669 | + (0..=EQ_CURVE_STEPS) | |
| 7670 | + .map(|step| { | |
| 7671 | + let along = step as f32 / EQ_CURVE_STEPS as f32; | |
| 7672 | + let half = 0.5 / EQ_CURVE_STEPS as f32; | |
| 7673 | + // Bin 0 is DC and means nothing here, so the low end starts at 1. | |
| 7674 | + let low = (at(along - half) / bin_hz).round().max(1.) as usize; | |
| 7675 | + let high = (at(along + half) / bin_hz).round().max(1.) as usize; | |
| 7676 | + let peak = (low..=high) | |
| 7677 | + .filter_map(|k| mags.get(k)) | |
| 7678 | + .fold(0f32, |a, &b| a.max(b)); | |
| 7679 | + let db = 20. * peak.max(1e-9).log10(); | |
| 7680 | + ((db - floor) / (ceiling - floor)).clamp(0., 1.) | |
| 7681 | + }) | |
| 7682 | + .collect() | |
| 7683 | +} | |
| 7684 | + | |
| 7685 | +/// The analyser drawn as one filled shape from the floor of the box. | |
| 7686 | +fn eq_spectrum_curve(levels: Vec<f32>) -> impl IntoElement { | |
| 7687 | + canvas( | |
| 7688 | + |_, _, _| (), | |
| 7689 | + move |bounds, _, window, _| { | |
| 7690 | + let (o, s) = (bounds.origin, bounds.size); | |
| 7691 | + let last = levels.len().saturating_sub(1).max(1) as f32; | |
| 7692 | + let mut path = PathBuilder::fill(); | |
| 7693 | + path.move_to(point(o.x, o.y + s.height)); | |
| 7694 | + for (i, level) in levels.iter().enumerate() { | |
| 7695 | + path.line_to(point( | |
| 7696 | + o.x + s.width * (i as f32 / last), | |
| 7697 | + o.y + s.height * (1. - level), | |
| 7698 | + )); | |
| 7699 | + } | |
| 7700 | + path.line_to(point(o.x + s.width, o.y + s.height)); | |
| 7701 | + path.close(); | |
| 7702 | + if let Ok(path) = path.build() { | |
| 7703 | + window.paint_path(path, rgba(EQ_SPECTRUM_INK)); | |
| 7704 | + } | |
| 7705 | + }, | |
| 7706 | + ) | |
| 7707 | + .absolute() | |
| 7708 | + .size_full() | |
| 7709 | +} | |
| 7710 | + | |
| 6602 | 7711 | /// The cascade's frequency response, drawn as one line across the graph. |
| 6603 | 7712 | /// |
| 6604 | 7713 | /// Every point comes from `EqParams::response_db`, which reads the very |
| @@ -6613,14 +7722,31 @@ fn eq_curve(params: EqParams, sample_rate: u32) -> impl IntoElement { | ||
| 6613 | 7722 | |_, _, _| (), |
| 6614 | 7723 | move |bounds, _, window, _| { |
| 6615 | 7724 | let (o, s) = (bounds.origin, bounds.size); |
| 7725 | + let points: Vec<_> = (0..=EQ_CURVE_STEPS) | |
| 7726 | + .map(|step| { | |
| 7727 | + let along = step as f32 / EQ_CURVE_STEPS as f32; | |
| 7728 | + let freq = EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along); | |
| 7729 | + point( | |
| 7730 | + o.x + s.width * along, | |
| 7731 | + o.y + s.height * eq_y(params.response_db(freq, sample_rate)), | |
| 7732 | + ) | |
| 7733 | + }) | |
| 7734 | + .collect(); | |
| 7735 | + // The area between the curve and 0 dB, closed along that line: a | |
| 7736 | + // boost and a cut wind opposite ways around it, which is exactly | |
| 7737 | + // what makes both of them fill and the flat parts stay empty. | |
| 7738 | + let mut area = PathBuilder::fill(); | |
| 7739 | + area.move_to(point(o.x, o.y + s.height / 2.)); | |
| 7740 | + for at in &points { | |
| 7741 | + area.line_to(*at); | |
| 7742 | + } | |
| 7743 | + area.line_to(point(o.x + s.width, o.y + s.height / 2.)); | |
| 7744 | + area.close(); | |
| 7745 | + if let Ok(area) = area.build() { | |
| 7746 | + window.paint_path(area, rgba(EQ_FILL_INK)); | |
| 7747 | + } | |
| 6616 | 7748 | let mut path = PathBuilder::stroke(px(2.)); |
| 6617 | - for step in 0..=EQ_CURVE_STEPS { | |
| 6618 | - let along = step as f32 / EQ_CURVE_STEPS as f32; | |
| 6619 | - let freq = EQ_FREQ_LOW * (EQ_FREQ_HIGH / EQ_FREQ_LOW).powf(along); | |
| 6620 | - let at = point( | |
| 6621 | - o.x + s.width * along, | |
| 6622 | - o.y + s.height * eq_y(params.response_db(freq, sample_rate)), | |
| 6623 | - ); | |
| 7749 | + for (step, at) in points.into_iter().enumerate() { | |
| 6624 | 7750 | match step { |
| 6625 | 7751 | 0 => path.move_to(at), |
| 6626 | 7752 | _ => path.line_to(at), |
| @@ -6704,21 +7830,25 @@ fn timecode(t: f64, fps: f64) -> String { | ||
| 6704 | 7830 | #[cfg(test)] |
| 6705 | 7831 | mod tests { |
| 6706 | 7832 | use super::{ |
| 6707 | - ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_FREQ_HIGH, | |
| 6708 | - EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_TICKS, EXPORT_ROWS_H, FORMATS, | |
| 6709 | - Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, | |
| 6710 | - INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, | |
| 6711 | - LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_W, NO_FILE, PANEL_H, | |
| 6712 | - Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, | |
| 6713 | - SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Volume, WAVE_BPS, WAVE_COL, Wave, | |
| 6714 | - applicable, band_label, can_add, cancels_export, color_snap, envelope, eq_x, eq_y, | |
| 6715 | - export_path, export_settings, format_key, format_line, format_refusal, frac_along, | |
| 7833 | + ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, | |
| 7834 | + EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, | |
| 7835 | + EQ_TICKS, EXPORT_ROWS_H, FORMATS, Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, | |
| 7836 | + HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H, | |
| 7837 | + LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, | |
| 7838 | + MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, | |
| 7839 | + SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, | |
| 7840 | + Speed, StreamInfo, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, | |
| 7841 | + can_add, cancels_export, clipboard_after_remove, color_snap, envelope, eq_spectrum, eq_x, | |
| 7842 | + eq_y, export_path, export_settings, format_key, format_line, format_refusal, frac_along, | |
| 6716 | 7843 | frac_down, frame_at, histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, |
| 6717 | - menu_at, normalise, panel_h, project_path, push_digit, retarget, scrub_due, show_label, | |
| 6718 | - silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths, | |
| 6719 | - unseen_sources, whole_take, width_frac, window_title, | |
| 7844 | + menu_at, normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, | |
| 7845 | + scrub_due, show_label, silence_rate, source_tint, span_partner, speed_at, timecode, | |
| 7846 | + unseen_paths, unseen_sources, whole_take, width_frac, window_title, | |
| 7847 | + }; | |
| 7848 | + use super::{ | |
| 7849 | + LaneKind, Repeat, View, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, library_rows, | |
| 7850 | + repeats, unscannable, | |
| 6720 | 7851 | }; |
| 6721 | - use super::{LaneKind, file_name, file_uri, library_rows, unscannable}; | |
| 6722 | 7852 | |
| 6723 | 7853 | /// What the file manager is handed: the parts a path keeps as they are, and |
| 6724 | 7854 | /// the ones the bus would otherwise read as something else. |
| @@ -7067,6 +8197,93 @@ mod tests { | ||
| 7067 | 8197 | assert!(ActionId::ALL.contains(&action), "{action:?} is not listed"); |
| 7068 | 8198 | assert_ne!(keymap.display(action), "unbound", "{action:?}"); |
| 7069 | 8199 | } |
| 8200 | + // ...and the whole card still fits the 640x360 floor, however many items | |
| 8201 | + // it grows to: the list is what scrolls past the cap, never the card. | |
| 8202 | + let items = MENU_ITEMS.len() + 1; // Properties | |
| 8203 | + assert!(MENU_PAD * 2. + MENU_ROWS_H <= 360., "menu too tall"); | |
| 8204 | + assert!( | |
| 8205 | + MENU_ROWS_H / MENU_ROW_H >= 12., | |
| 8206 | + "too few items visible to scan" | |
| 8207 | + ); | |
| 8208 | + assert_eq!( | |
| 8209 | + menu_at(point(px(0.), px(0.)), size(px(640.), px(360.)), { | |
| 8210 | + MENU_PAD * 2. + (items as f32 * MENU_ROW_H).min(MENU_ROWS_H) | |
| 8211 | + }), | |
| 8212 | + (0., 0.) | |
| 8213 | + ); | |
| 8214 | + } | |
| 8215 | + | |
| 8216 | + /// The other half of the keys menu's guarantee, and the audit this batch was | |
| 8217 | + /// asked for kept as a test: no action may be a stroke and nothing else. | |
| 8218 | + /// Either the clip menu offers it, or a control in the panel does -- named | |
| 8219 | + /// here by the id [`control`] is handed, read out of this file's own source | |
| 8220 | + /// like `no_stroke_is_missing_from_the_keys_menu` reads the key handler. | |
| 8221 | + #[test] | |
| 8222 | + fn every_action_is_reachable_without_the_keyboard() { | |
| 8223 | + use keymap::ActionId; | |
| 8224 | + let source = include_str!("main.rs") | |
| 8225 | + .split("#[cfg(test)]") | |
| 8226 | + .next() | |
| 8227 | + .unwrap(); | |
| 8228 | + let element = |id: &str| source.contains(&format!("\"{id}\"")); | |
| 8229 | + for action in ActionId::ALL { | |
| 8230 | + let by_pointer = MENU_ITEMS.contains(&action) | |
| 8231 | + || match action { | |
| 8232 | + ActionId::Play => element("transport"), | |
| 8233 | + // One slot, two states: it starts an export and stops the | |
| 8234 | + // one it started. | |
| 8235 | + ActionId::Export | ActionId::CancelExport => element("export"), | |
| 8236 | + ActionId::Save => element("save"), | |
| 8237 | + ActionId::Undo => element("undo"), | |
| 8238 | + ActionId::Resolution => element("resolution"), | |
| 8239 | + // Three buttons beside it, and the ctrl+wheel on the bar. | |
| 8240 | + ActionId::ZoomIn => element("zoom-in"), | |
| 8241 | + ActionId::ZoomOut => element("zoom-out"), | |
| 8242 | + ActionId::ZoomFit => element("zoom-fit"), | |
| 8243 | + ActionId::AddVideoLane => element("add-video-lane"), | |
| 8244 | + ActionId::AddAudioLane => element("add-audio-lane"), | |
| 8245 | + // The × in a lane's own header, which takes any track and | |
| 8246 | + // not only the last one. | |
| 8247 | + ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => { | |
| 8248 | + source.contains("this.remove_lane(lane, cx)") | |
| 8249 | + } | |
| 8250 | + ActionId::ToggleMute => element("volume"), | |
| 8251 | + ActionId::VolumeUp | ActionId::VolumeDown => element("volume-bar"), | |
| 8252 | + // The ruler seeks anywhere the pointer points; the frame and | |
| 8253 | + // the second are the keyboard's finer grain of that move. | |
| 8254 | + ActionId::StepBack | |
| 8255 | + | ActionId::StepForward | |
| 8256 | + | ActionId::JumpBack | |
| 8257 | + | ActionId::JumpForward | |
| 8258 | + | ActionId::GoStart | |
| 8259 | + | ActionId::GoEnd => element("ruler"), | |
| 8260 | + // A press on a clip is the selection, group and all. | |
| 8261 | + ActionId::Select | ActionId::SelectNext | ActionId::SelectPrev => { | |
| 8262 | + source.contains("this.select((lane, i), cx)") | |
| 8263 | + } | |
| 8264 | + _ => false, | |
| 8265 | + }; | |
| 8266 | + assert!(by_pointer, "{action:?} is reachable by keyboard only"); | |
| 8267 | + } | |
| 8268 | + // The card-local strokes have the same rule, and each of them is a thing | |
| 8269 | + // on its card: the graph and its two buttons, the colour bars and their | |
| 8270 | + // reset, the speed bar and its presets, and the silence card's rows -- | |
| 8271 | + // whose steppers are the pointer's only way to a threshold. | |
| 8272 | + for id in [ | |
| 8273 | + "eq-graph", | |
| 8274 | + "eq-reset", | |
| 8275 | + "eq-spectrum", | |
| 8276 | + "color-bar", | |
| 8277 | + "color-reset", | |
| 8278 | + "speed-bar", | |
| 8279 | + "speed-preset", | |
| 8280 | + "silence-row", | |
| 8281 | + "silence-step", | |
| 8282 | + "silence-apply", | |
| 8283 | + "export-confirm", | |
| 8284 | + ] { | |
| 8285 | + assert!(element(id), "{id} is not on any card"); | |
| 8286 | + } | |
| 7070 | 8287 | } |
| 7071 | 8288 | |
| 7072 | 8289 | /// What the Detach and Group items do to a real timeline: a music video's |
| @@ -7306,17 +8523,71 @@ mod tests { | ||
| 7306 | 8523 | .expect("nothing plays av2 any more"); |
| 7307 | 8524 | assert_eq!(rows(&session), 1, "the row went with it"); |
| 7308 | 8525 | assert_eq!(session.sources().len(), 1); |
| 7309 | - // The one file left cannot go: a project that names none is not one | |
| 7310 | - // that reopens. | |
| 8526 | + // The one file left is held to the same rule and no other: its own take | |
| 8527 | + // is still on the lanes, so it stays... | |
| 8528 | + let first = session.sources()[0].path.clone(); | |
| 7311 | 8529 | let refusal = session |
| 7312 | - .remove_source(&session.sources()[0].path.clone(), 0) | |
| 7313 | - .expect_err("the last file stays") | |
| 8530 | + .remove_source(&first, 0) | |
| 8531 | + .expect_err("its take is still on the timeline") | |
| 7314 | 8532 | .to_string(); |
| 7315 | - assert!(refusal.contains("only file"), "{refusal}"); |
crates/engine/Cargo.tomlmodified+12 -6
| @@ -23,6 +23,18 @@ 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 | +# Both halves of AAC, and the only crate here that is asked for both. The | |
| 27 | +# *encoder*, so an mp4's sound can be a mix rather than a copy: an equalized (or | |
| 28 | +# otherwise processed) lane has to be decoded, and what is decoded has to be | |
| 29 | +# encoded again. The *decoder*, because symphonia's own refuses anything wider | |
| 30 | +# than stereo outright (`aac/mod.rs:93`, "aac: aac too complex") and a 5.1 film | |
| 31 | +# soundtrack in an mkv is exactly that -- this one hands 5.1 back already | |
| 32 | +# reordered into FL, FR, FC, LFE, BL, BR, which is the order the downmix in | |
| 33 | +# `audio` folds. Pure Rust with no C or FFI, Apache-2.0, same family as | |
| 34 | +# `rusty_h264` above. Nothing else in the ecosystem encodes AAC without linking | |
| 35 | +# Fraunhofer's C library, which this project's no-install rule forbids. Built | |
| 36 | +# from `vendor/rusty_aac` -- see the patch table in the workspace manifest. | |
| 37 | +rusty_aac = "0.5" | |
| 26 | 38 | symphonia-core = "0.6" |
| 27 | 39 | symphonia-codec-aac = "0.6" |
| 28 | 40 | # The umbrella crate for the standalone audio files: one dependency instead of |
| @@ -47,12 +59,6 @@ symphonia = { version = "0.6", default-features = false, features = [ | ||
| 47 | 59 | "vorbis", |
| 48 | 60 | "wav", |
| 49 | 61 | ] } |
| 50 | -# The AAC decoder symphonia is not: its own refuses anything wider than stereo | |
| 51 | -# outright (`aac/mod.rs:93`, "aac: aac too complex"), and a 5.1 film soundtrack | |
| 52 | -# in an mkv is exactly that. Pure Rust with no dependencies of its own, from the | |
| 53 | -# same family as `rusty_h264`, and it hands 5.1 back already reordered into | |
| 54 | -# FL, FR, FC, LFE, BL, BR -- which is the order the downmix here folds. | |
| 55 | -rusty_aac = "0.5" | |
| 56 | 62 | oxideav-ac3 = "=0.0.10" |
| 57 | 63 | oxideav-core = "0.1.34" |
| 58 | 64 | # The software AV1 encoder, and the only new name in this list that was already |
crates/engine/src/audio.rsmodified+19 -9
| @@ -270,14 +270,23 @@ impl AudioSession { | ||
| 270 | 270 | eqs: &[Option<EqParams>], |
| 271 | 271 | speeds: &[Option<crate::project::Stretch>], |
| 272 | 272 | ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> { |
| 273 | - let Some((path, stream)) = sources.first() else { | |
| 273 | + // The first source that could have a track, which is not always index 0: | |
| 274 | + // a still image has none, and one at the front of the list (a save | |
| 275 | + // renumbers, a library removal moves indexes) would be opened as a | |
| 276 | + // broken audio file and take the whole timeline's sound down with it. | |
| 277 | + // The same rule `PlaybackSession` probes by (`audio_source_of`). | |
| 278 | + let Some((at, (path, stream))) = sources | |
| 279 | + .iter() | |
| 280 | + .enumerate() | |
| 281 | + .find(|(_, (path, _))| !crate::is_image(path)) | |
| 282 | + else { | |
| 274 | 283 | return Ok(None); |
| 275 | 284 | }; |
| 276 | 285 | let Some(first) = Track::open(path, *stream)? else { |
| 277 | 286 | return Ok(None); |
| 278 | 287 | }; |
| 279 | - // The timeline's meta is the first source's: policy makes every other | |
| 280 | - // source match it, and the checks below hold them to that. | |
| 288 | + // The timeline's meta is that source's: policy makes every other source | |
| 289 | + // match it, and the checks below hold them to that. | |
| 281 | 290 | let meta = AudioMeta { |
| 282 | 291 | sample_rate: first.sample_rate(), |
| 283 | 292 | channels: first.channels()?, |
| @@ -288,7 +297,7 @@ impl AudioSession { | ||
| 288 | 297 | first.check_decoder()?; |
| 289 | 298 | |
| 290 | 299 | let mut tracks: Vec<Option<Track>> = sources.iter().map(|_| None).collect(); |
| 291 | - tracks[0] = Some(first); | |
| 300 | + tracks[at] = Some(first); | |
| 292 | 301 | for &(source, ..) in segs { |
| 293 | 302 | let Some(source) = source else { |
| 294 | 303 | continue; // a gap opens no file |
| @@ -461,8 +470,9 @@ impl AudioSession { | ||
| 461 | 470 | let mut meta = None; |
| 462 | 471 | let mut rxs = Vec::with_capacity(lanes.len()); |
| 463 | 472 | for (i, segs) in lanes.iter().enumerate() { |
| 464 | - // Every lane probes the same source 0, so the metas agree by | |
| 465 | - // construction; `None` from any of them is a silent timeline. | |
| 473 | + // Every lane takes its meta from the same source, so the metas | |
| 474 | + // agree by construction; `None` from any of them is a silent | |
| 475 | + // timeline. | |
| 466 | 476 | let flat = Vec::new(); |
| 467 | 477 | let plain = Vec::new(); |
| 468 | 478 | let Some((lane_meta, rx)) = Self::open_multi_streams_speed( |
| @@ -661,9 +671,9 @@ impl AudioSession { | ||
| 661 | 671 | /// The raw AAC packets covering `segs` — the same half-open source-second |
| 662 | 672 | /// windows [`open_segments`](Self::open_segments) decodes — copied out |
| 663 | 673 | /// byte for byte. Nothing is decoded and nothing is re-encoded: the bytes go |
| 664 | - /// straight into an mp4 writer, which is the only way to keep audio in an | |
| 665 | - /// export at all (nothing here *encodes* AAC: the vendored `rusty_aac` has | |
| 666 | - /// an encoder, but no export path is wired to it). | |
| 674 | + /// straight into an mp4 writer, which is how an export keeps its sound exact | |
| 675 | + /// wherever the edit lets it (a lane carrying an equalizer cannot be copied | |
| 676 | + /// and is re-encoded instead -- `export::encode_audio`). | |
| 667 | 677 | /// |
| 668 | 678 | /// Cut points do not land on 1024-sample boundaries, so each segment is |
| 669 | 679 | /// rounded to whole packets against an error carried across the joins (see |
crates/engine/src/export.rsmodified+148 -58
| @@ -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 | -//! AAC encoder wired here 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,22 +63,27 @@ 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 the | |
| 77 | - /// copy path walks an mp4 sample table, which a Matroska file has none of. | |
| 78 | - /// (Reading one's AAC is a different question and the answer is yes -- | |
| 83 | + /// this project can *write*: this engine's Matroska writer has no audio | |
| 84 | + /// track at all, and the copy path walks an mp4 sample table, which a | |
| 85 | + /// Matroska file has none of. (*Reading* one's AAC is a different question, | |
| 86 | + /// and since this engine gained a Matroska demuxer the answer is yes -- | |
| 79 | 87 | /// `audio::Track::open` does it through symphonia's mkv reader.) The sound |
| 80 | 88 | /// of an AV1 export is a WAV or FLAC beside it, which a front-end says up |
| 81 | 89 | /// front. |
| @@ -258,7 +266,9 @@ fn settle(shared: &Shared, result: crate::Result<()>) { | ||
| 258 | 266 | } |
| 259 | 267 | |
| 260 | 268 | /// The timeline's one audio lane, copied packet for packet: the mp4 path's |
| 261 | -/// sound, and the reason that path carries only one lane of it. | |
| 269 | +/// sound, and the reason that path carries only one lane of it. A lane an | |
| 270 | +/// equalizer has been put on cannot be *copied* at all and leaves through | |
| 271 | +/// [`encode_audio`] instead; every other timeline keeps this copy, bit for bit. | |
| 262 | 272 | /// |
| 263 | 273 | /// ponytail: this holds the whole exported AAC track in memory (~3 kB per |
| 264 | 274 | /// 23 ms packet, so ~500 MB for an hour). Upgrade path is a streaming |
| @@ -279,10 +289,15 @@ fn copy_audio( | ||
| 279 | 289 | // of a timeline playing a file's second audio track carries *that* track. |
| 280 | 290 | // |
| 281 | 291 | // One lane, because this path *copies* AAC packets and a mix is not a copy: |
| 282 | - // summing two lanes means decoding both and encoding the result, and there | |
| 283 | - // is no AAC encoder here to encode it with. Refused by name rather than | |
| 284 | - // silently exporting the first lane -- a file missing half its sound is the | |
| 285 | - // one failure a user would not notice. | |
| 292 | + // summing two lanes means decoding both, and only the one thing a copy | |
| 293 | + // cannot express at all -- an equalizer -- is decoded here today. Refused by | |
| 294 | + // name rather than silently exporting the first lane, which is a file | |
| 295 | + // missing half its sound: the one failure a user would not notice. | |
| 296 | + // | |
| 297 | + // ponytail: the ceiling is this routing, not the codec any more. | |
| 298 | + // [`encode_audio`] already mixes *every* audio lane (it is the WAV path's | |
| 299 | + // own opener), so lifting this refusal is routing a second case to it -- | |
| 300 | + // deliberately not done here, where the change under test is the equalizer. | |
| 286 | 301 | // |
| 287 | 302 | // *Which* lane is the same question `audio_segments_from` answers for |
| 288 | 303 | // playback, and it is asked here rather than assumed: the lane that holds |
| @@ -294,32 +309,29 @@ fn copy_audio( | ||
| 294 | 309 | let [segments] = &lanes[..] else { |
| 295 | 310 | return Err(format!( |
| 296 | 311 | "this timeline has {} audio lanes and an mp4 export copies one: \ |
| 297 | - there is no AAC encoder here to mix them with. Export WAV or FLAC, \ | |
| 298 | - which are mixed, or put the sound on one lane", | |
| 312 | + export WAV or FLAC, which are mixed, or put the sound on one lane", | |
| 299 | 313 | lanes.len() |
| 300 | 314 | ) |
| 301 | 315 | .into()); |
| 302 | 316 | }; |
| 303 | - // ...and the same list decides which clips this would be copying, which is | |
| 304 | - // the only way to ask whether any of them carries an equalizer. An EQ is | |
| 305 | - // sample math and a copy never decodes: exporting it here would write the | |
| 306 | - // clip flat, silently -- the same failure a missing audio track is. Named by | |
| 307 | - // where it sits on the timeline, because "some clip" is not a thing a user | |
| 308 | - // can go and fix. | |
| 317 | + // ...and the same list names *which* lane those clips sit on, which is the | |
| 318 | + // only way to ask what has been done to them. | |
| 309 | 319 | let lane = project.audio_lanes()[0]; |
| 310 | 320 | // ...and the same list decides whether any clip this would copy plays at a |
| 311 | 321 | // rate other than the one it was recorded at. A copy hands the mp4 the very |
| 312 | 322 | // AAC packets the source holds and there is no rate inside a packet to |
| 313 | 323 | // change: the picture would come out re-timed (the walk in [`run`] honours |
| 314 | 324 | // it) over sound at 1.00x, which is the drift a person finds only after the |
| 315 | - // file has gone somewhere. Refused by name, exactly as the equalizer below | |
| 316 | - // is -- and only *here*, on the lane being copied: AV1 carries no audio at | |
| 317 | - // all and never reaches this, so it honours a speed like WAV and FLAC do. | |
| 325 | + // file has gone somewhere. Refused by name -- and only *here*, on the lane | |
| 326 | + // being copied: AV1 carries no audio at all and never reaches this, so it | |
| 327 | + // honours a speed like WAV and FLAC do. | |
| 318 | 328 | // |
| 319 | - // ponytail: the ceiling is the packet copy itself, not the rate. Upgrade | |
| 320 | - // path is the same one the equalizer below wants -- an AAC encoder (or a | |
| 321 | - // decode-and-re-encode of this lane) -- at which point the resample the WAV | |
| 322 | - // path already runs feeds it and this refusal goes. | |
| 329 | + // ponytail: the ceiling is the packet copy itself, not the rate, and the way | |
| 330 | + // off it is now next door -- [`encode_audio`] resamples exactly as the WAV | |
| 331 | + // path does, so routing a speeded lane there is the one line the equalizer | |
| 332 | + // below takes. Left refused because this change is the equalizer's, and a | |
| 333 | + // speeded export turning silently from a copy into a re-encode is a change | |
| 334 | + // of its own to make on purpose. | |
| 323 | 335 | if let Some((at, speed)) = project |
| 324 | 336 | .lane(lane) |
| 325 | 337 | .iter() |
| @@ -333,28 +345,106 @@ fn copy_audio( | ||
| 333 | 345 | ) |
| 334 | 346 | .into()); |
| 335 | 347 | } |
| 336 | - if let Some((at, _)) = project | |
| 337 | - .lane(lane) | |
| 338 | - .iter() | |
| 339 | - .enumerate() | |
| 340 | - .find(|(idx, _)| { | |
| 341 | - project | |
| 342 | - .eq_of(lane, *idx) | |
| 343 | - .is_some_and(|eq| !eq.is_identity()) | |
| 344 | - }) | |
| 345 | - .map(|(idx, clip)| (clip.start, idx)) | |
| 346 | - { | |
| 347 | - return Err(format!( | |
| 348 | - "the clip at {} has an equalizer and an mp4 export copies AAC packets, \ | |
| 349 | - which no filter can reach: export WAV or FLAC, which are decoded and \ | |
| 350 | - mixed, or clear the equalizer", | |
| 351 | - timecode(at, meta.frame_rate) | |
| 352 | - ) | |
| 353 | - .into()); | |
| 348 | + // ...and last, whether any clip on it carries an equalizer. An EQ is sample | |
| 349 | + // math and a copy never decodes, so copying such a lane would write the clip | |
| 350 | + // *flat*, silently -- the failure a missing audio track is. This lane is | |
| 351 | + // decoded, filtered, mixed and encoded again instead ([`encode_audio`]), and | |
| 352 | + // only this case is: a timeline nobody has equalized still leaves through | |
| 353 | + // the copy below, packet for packet, so no passthrough quietly becomes a | |
| 354 | + // generation of loss. | |
| 355 | + let equalized = (0..project.lane(lane).len()) | |
| 356 | + .any(|idx| project.eq_of(lane, idx).is_some_and(|eq| !eq.is_identity())); | |
| 357 | + if equalized { | |
| 358 | + return encode_audio(project, meta); | |
| 354 | 359 | } |
| 355 | 360 | AudioSession::copy_multi_streams(&project.audio_sources(), segments) |
| 356 | 361 | } |
| 357 | 362 | |
| 363 | +/// The same lane, *decoded*: what a packet copy cannot carry comes out here as | |
| 364 | +/// AAC written by this project's own encoder. | |
| 365 | +/// | |
| 366 | +/// The samples are the very ones [`run_audio`] would put in a WAV -- the same | |
| 367 | +/// opener with the same equalizers, the same rates and the same resize onto the | |
| 368 | +/// timeline's own length -- so an mp4 and a WAV of one timeline are one mix, | |
| 369 | +/// not two that could disagree. | |
| 370 | +/// | |
| 371 | +/// AAC-LC's encoder delay is one 1024-frame block, which is exactly the priming | |
| 372 | +/// a reader drops when the file carries no edit list (`audio::DEFAULT_PRIMING`, | |
| 373 | +/// and [`crate::mux::Mp4Muxer`] writes none): the first packet is that delay, so | |
| 374 | +/// the sound starts at timeline frame 0 as a copied track's does. | |
| 375 | +/// | |
| 376 | +/// ponytail: the mix sits in memory as f32 before it is encoded (~46 MB a | |
| 377 | +/// minute of 48 kHz stereo), for [`run_audio`]'s reason -- `rusty_aac` buffers | |
| 378 | +/// the whole stream anyway, since it encodes its frames in parallel. Upgrade | |
| 379 | +/// path is a chunked push once that encoder streams. | |
| 380 | +#[allow(clippy::type_complexity)] | |
| 381 | +fn encode_audio( | |
| 382 | + project: &Project, | |
| 383 | + meta: &VideoMeta, | |
| 384 | +) -> crate::Result<Option<(crate::AacTrackParams, Vec<crate::AacPacket>)>> { | |
| 385 | + let sources = project.audio_sources(); | |
| 386 | + let segs = project.audio_segments_from(0, meta.frame_rate); | |
| 387 | + let eqs = project.audio_eqs_from(0, meta.frame_rate); | |
| 388 | + let speeds = project.audio_speeds_from(0, meta.frame_rate); | |
| 389 | + let Some((audio, chunks)) = | |
| 390 | + AudioSession::open_mixed_streams_speed(&sources, &segs, &eqs, &speeds)? | |
| 391 | + else { | |
| 392 | + return Ok(None); // no audio to write, exactly as a copy of nothing is | |
| 393 | + }; | |
| 394 | + let freq_index = rusty_aac::sf_index_for_rate(audio.sample_rate).ok_or_else(|| { | |
| 395 | + format!( | |
| 396 | + "{} Hz is not an AAC sample rate: export WAV or FLAC, which write it as it is", | |
| 397 | + audio.sample_rate | |
| 398 | + ) | |
| 399 | + })?; | |
| 400 | + let channels = usize::from(audio.channels.max(1)); | |
| 401 | + // The timeline's length, not the mix's: a segment resolves its window to | |
| 402 | + // whole samples on its own, so the sum can miss by a sample or two and a | |
| 403 | + // source that ran out early would leave the track short under a picture | |
| 404 | + // that is not. One resize settles both, as [`run_audio`]'s does. | |
| 405 | + let total = (f64::from(project.timeline_frames()) / meta.frame_rate | |
| 406 | + * f64::from(audio.sample_rate)) | |
| 407 | + .round() as usize | |
| 408 | + * channels; | |
| 409 | + let mut samples: Vec<f32> = Vec::with_capacity(total); | |
| 410 | + for chunk in chunks { | |
| 411 | + samples.extend(chunk.samples); | |
| 412 | + } | |
| 413 | + samples.resize(total, 0.0); | |
| 414 | + | |
| 415 | + // 256 kbps, not the encoder's 128 default: this is a *second* generation of | |
| 416 | + // lossy coding over a source that was already AAC, and the export is a | |
| 417 | + // master a person edits from again, not a delivery file. Measured on the | |
| 418 | + // suite's fixtures, an untouched clip re-encoded here moves 0.15 dB at this | |
| 419 | + // rate against 0.46 dB at 128 -- and 32 KB/s beside a 2.76 Mbps picture is | |
| 420 | + // not a size anyone is counting. | |
| 421 | + let mut encoder = rusty_aac::AacEncoder::new(rusty_aac::AacEncoderConfig { | |
| 422 | + bitrate_bps: 256_000, | |
| 423 | + ..Default::default() | |
| 424 | + }); | |
| 425 | + encoder.push_pcm(&samples, audio.channels.max(1), audio.sample_rate)?; | |
| 426 | + encoder.finish(); | |
| 427 | + let mut packets = Vec::new(); | |
| 428 | + // `next_packet` after `finish` yields packets until `Eof` and nothing else, | |
| 429 | + // so the loop ends on the only error it can see. | |
| 430 | + while let Ok(packet) = encoder.next_packet() { | |
| 431 | + packets.push(crate::AacPacket { | |
| 432 | + bytes: packet.data, | |
| 433 | + samples: packet.duration, | |
| 434 | + }); | |
| 435 | + } | |
| 436 | + Ok(Some(( | |
| 437 | + crate::AacTrackParams { | |
| 438 | + freq_index, | |
| 439 | + // 1 and 2 are the ISO channel configurations for mono and stereo, | |
| 440 | + // and the opener refuses anything wider than stereo already. | |
| 441 | + chan_conf: audio.channels.max(1) as u8, | |
| 442 | + sample_rate: audio.sample_rate, | |
| 443 | + }, | |
| 444 | + packets, | |
| 445 | + ))) | |
| 446 | +} | |
| 447 | + | |
| 358 | 448 | fn run( |
| 359 | 449 | project: &Project, |
| 360 | 450 | meta: &VideoMeta, |
crates/engine/src/playback.rsmodified+158 -17
| @@ -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 { |
| @@ -417,10 +442,12 @@ impl PlaybackSession { | ||
| 417 | 442 | /// |
| 418 | 443 | /// A *new* session rather than a reload of this one, so a load that fails |
| 419 | 444 | /// leaves the caller's current session untouched -- atomic by |
| 420 | - /// construction. Every named file is opened and checked here: source 0 | |
| 421 | - /// defines the timeline exactly as `open` does, every other source has to | |
| 422 | - /// match it the way [`import`](Self::import) demands, and every clip has to | |
| 423 | - /// still be inside the file it plays from. A source that vanished or | |
| 445 | + /// construction. Every named file is opened and checked here: the | |
| 446 | + /// *scaffolding* source -- the first that is not a still, since a picture | |
| 447 | + /// carries no rate -- defines the timeline exactly as `open` does, every | |
| 448 | + /// other source has to match it the way [`import`](Self::import) demands | |
| 449 | + /// (a save renumbers, so which index that is says nothing), and every clip | |
| 450 | + /// has to still be inside the file it plays from. A source that vanished or | |
| 424 | 451 | /// shrank since the save is a refusal naming it, not a silently shorter |
| 425 | 452 | /// timeline -- the disappearing-file tolerance elsewhere in this type |
| 426 | 453 | /// applies only *after* a project has loaded. |
| @@ -428,15 +455,35 @@ impl PlaybackSession { | ||
| 428 | 455 | /// The undo history is not saved: `undo` is `false` on a fresh load. |
| 429 | 456 | pub fn open_project(path: &Path) -> crate::Result<Self> { |
| 430 | 457 | let doc = crate::edith::load(path)?; |
| 458 | + // *Which* source scaffolds it: the first that is not a still, and index | |
| 459 | + // 0 only when there is no other. A still defines no frame rate -- it is | |
| 460 | + // given [`IMAGE_ONLY_RATE`] -- so scaffolding a timeline of 24 fps | |
| 461 | + // footage off a PNG that a save happened to renumber to index 0 | |
| 462 | + // (`Project::without_orphan_sources` numbers by first use, and a | |
| 463 | + // library removal moves indexes too) reads the timeline as 30 fps and | |
| 464 | + // then refuses every file on it for not matching. The rule this and | |
| 465 | + // [`audio_source_of`] share: nothing may assume what source 0 *is*. | |
| 466 | + // | |
| 467 | + // ponytail: a timeline of nothing but stills, or of stills and songs, | |
| 468 | + // still comes back at the rate its scaffold implies rather than the one | |
| 469 | + // it was cut at -- the rate is written nowhere in the file. The upgrade | |
| 470 | + // path is a dialect that writes it (`crate::edith`), which is also what | |
| 471 | + // a project naming no file at all would need. | |
| 472 | + let scaffold = doc | |
| 473 | + .sources | |
| 474 | + .iter() | |
| 475 | + .position(|s| !crate::is_image(&s.path)) | |
| 476 | + .unwrap_or(0); | |
| 431 | 477 | // Owned: the sources move into the `Project` below, and the device is |
| 432 | 478 | // opened after that (see the comment there). |
| 433 | 479 | let first = doc |
| 434 | 480 | .sources |
| 435 | - .first() | |
| 481 | + .get(scaffold) | |
| 436 | 482 | .cloned() |
| 437 | 483 | .ok_or("the project names no sources")?; |
| 438 | - // Source 0 both scaffolds the session and defines the timeline, so it | |
| 439 | - // is opened for playback rather than merely probed. | |
| 484 | + // The scaffolding source both defines the timeline and is what the | |
| 485 | + // playhead's first picture comes from, so it is opened for playback | |
| 486 | + // rather than merely probed. | |
| 440 | 487 | // One value, not two locals: everything below this line can refuse, and |
| 441 | 488 | // locals drop in reverse declaration order -- a bare worker would join |
| 442 | 489 | // its decode thread while the receiver next to it was still holding |
| @@ -503,8 +550,15 @@ impl PlaybackSession { | ||
| 503 | 550 | } |
| 504 | 551 | let first_audio = first_audio_of(&doc.sources)?; |
| 505 | 552 | |
| 506 | - let mut counts = vec![meta.frame_count]; | |
| 507 | - for source in &doc.sources[1..] { | |
| 553 | + // In source order, with the scaffold's own count in its own slot: the | |
| 554 | + // clip check below indexes this list by source, so it must line up with | |
| 555 | + // `doc.sources` whichever entry the scaffolding came from. | |
| 556 | + let mut counts = Vec::with_capacity(doc.sources.len()); | |
| 557 | + for (i, source) in doc.sources.iter().enumerate() { | |
| 558 | + if i == scaffold { | |
| 559 | + counts.push(meta.frame_count); | |
| 560 | + continue; | |
| 561 | + } | |
| 508 | 562 | // A still has neither a rate to match nor a track to match with: |
| 509 | 563 | // its length is the one it is held to, recomputed exactly as the |
| 510 | 564 | // import that first noted it did ([`image_frames`]), which is what |
| @@ -579,7 +633,15 @@ impl PlaybackSession { | ||
| 579 | 633 | // only a session's `drop` retires it, so a refusal above this line would |
| 580 | 634 | // leave a PipeWire stream and a thread behind for a project that never |
| 581 | 635 | // opened. Nothing before it needs the device. |
| 582 | - let (audio, audio_disabled) = open_audio(&first.path, first.audio_stream); | |
| 636 | + // | |
| 637 | + // On the source the timeline's *sound* is defined by, which is the | |
| 638 | + // scaffold unless that one is a still ([`audio_source_of`]): opening a | |
| 639 | + // PNG as the device is a session with no audio at all, however many | |
| 640 | + // clips with sound are on its lanes. | |
| 641 | + let (audio, audio_disabled) = match audio_source_of(project.sources()) { | |
| 642 | + Some(source) => open_audio(&source.path, source.audio_stream), | |
| 643 | + None => (None, None), | |
| 644 | + }; | |
| 583 | 645 | let mut session = Self { |
| 584 | 646 | meta, |
| 585 | 647 | native, |
| @@ -627,7 +689,16 @@ impl PlaybackSession { | ||
| 627 | 689 | /// Writes the timeline to `path` as a `.edith`, atomically (see |
| 628 | 690 | /// [`crate::edith`]). Sources no clip plays from are left out, and the |
| 629 | 691 | /// playhead is saved with it so a reopened project resumes where it stood. |
| 692 | + /// | |
| 693 | + /// Refused, writing nothing, for a session whose library is empty (every | |
| 694 | + /// row removed, [`Project::remove_source`]): a file naming no source has no | |
| 695 | + /// timeline in it and [`open_project`](Self::open_project) could only | |
| 696 | + /// refuse it, so the refusal belongs here, where nothing has been | |
| 697 | + /// overwritten yet. | |
| 630 | 698 | pub fn save_project(&self, path: &Path) -> crate::Result<()> { |
| 699 | + if self.project.sources().is_empty() { | |
| 700 | + return Err("this project names no file: there is nothing to save".into()); | |
| 701 | + } | |
| 631 | 702 | let (sources, lanes, eq, color) = self.project.without_orphan_sources(); |
| 632 | 703 | let playhead = secs_to_frame(self.now(), self.meta.frame_rate) |
| 633 | 704 | .min(self.project.timeline_frames().saturating_sub(1)); |
| @@ -876,6 +947,13 @@ impl PlaybackSession { | ||
| 876 | 947 | self.project.add_lane(kind) |
| 877 | 948 | } |
| 878 | 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 | + | |
| 879 | 957 | /// Splits every lane at `timeline_secs`, so the two sides become two |
| 880 | 958 | /// groups. Metadata only: a split never changes the timeline->source |
| 881 | 959 | /// mapping, so the running decoder stays correct and playback does not |
| @@ -1186,7 +1264,7 @@ impl PlaybackSession { | ||
| 1186 | 1264 | /// [`import`](Self::import) refuses a file with. One output device and one |
| 1187 | 1265 | /// copied AAC track mean one set of audio parameters for the whole |
| 1188 | 1266 | /// timeline, so a 22 kHz mono track cannot join a 44.1 kHz stereo one -- |
| 1189 | - /// 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. | |
| 1190 | 1268 | /// A front-end greys such a row out; this is the backstop that keeps a |
| 1191 | 1269 | /// stale one from making the whole timeline silent. |
| 1192 | 1270 | /// |
| @@ -1286,7 +1364,14 @@ impl PlaybackSession { | ||
| 1286 | 1364 | /// Reseeks like an edit even though nothing playable changed: the clip |
| 1287 | 1365 | /// indexes into the source list have just moved, and the running workers |
| 1288 | 1366 | /// were opened against the old numbering. |
| 1289 | - pub fn remove_source(&mut self, path: &Path, stream: usize) -> crate::Result<()> { | |
| 1367 | + /// | |
| 1368 | + /// The index that went, because everything past it moved down: a caller | |
| 1369 | + /// holding a source index of its own (a clipboard) has to fix it up or drop | |
| 1370 | + /// it, or it names a different file afterwards. The **last** row goes like | |
| 1371 | + /// any other and leaves a session with an empty library -- silent, empty of | |
| 1372 | + /// clips, and unsaveable ([`save_project`](Self::save_project)); a | |
| 1373 | + /// front-end showing one is showing an empty window. | |
| 1374 | + pub fn remove_source(&mut self, path: &Path, stream: usize) -> crate::Result<usize> { | |
| 1290 | 1375 | let wanted = Source::new(path, stream); |
| 1291 | 1376 | let idx = self |
| 1292 | 1377 | .project |
| @@ -1305,11 +1390,12 @@ impl PlaybackSession { | ||
| 1305 | 1390 | } |
| 1306 | 1391 | let now = self.now(); |
| 1307 | 1392 | self.seek(now); |
| 1308 | - Ok(()) | |
| 1393 | + Ok(idx) | |
| 1309 | 1394 | } |
| 1310 | 1395 | |
| 1311 | - /// What the timeline's audio *is*: source 0's chosen stream, probed. Every | |
| 1312 | - /// other source is held to it. | |
| 1396 | + /// What the timeline's audio *is*: the chosen stream of the first source | |
| 1397 | + /// that could have any ([`audio_source_of`]), probed. Every other source is | |
| 1398 | + /// held to it. | |
| 1313 | 1399 | fn first_audio(&self) -> crate::Result<Option<crate::AudioProbe>> { |
| 1314 | 1400 | first_audio_of(self.project.sources()) |
| 1315 | 1401 | } |
| @@ -1493,6 +1579,21 @@ impl PlaybackSession { | ||
| 1493 | 1579 | } |
| 1494 | 1580 | } |
| 1495 | 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 | + | |
| 1496 | 1597 | /// Repositions the timeline to `secs`, clamped to the *timeline*. Both decode |
| 1497 | 1598 | /// workers are replaced rather than steered: a fresh channel cannot hold a |
| 1498 | 1599 | /// stale frame, and it works just as well after EOF, where the old workers |
| @@ -1515,6 +1616,9 @@ impl PlaybackSession { | ||
| 1515 | 1616 | // carrying can no longer reach the ring after this point. |
| 1516 | 1617 | audio.epoch.fetch_add(1, Ordering::Release); |
| 1517 | 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(); | |
| 1518 | 1622 | } |
| 1519 | 1623 | |
| 1520 | 1624 | // Cancel first, drop second: the old worker may be parked in `send` on |
| @@ -1729,12 +1833,26 @@ fn matches_timeline( | ||
| 1729 | 1833 | /// source 0 has always given. This function widens which source is asked, not |
| 1730 | 1834 | /// what the answer means. |
| 1731 | 1835 | fn first_audio_of(sources: &[Source]) -> crate::Result<Option<crate::AudioProbe>> { |
| 1732 | - match sources.iter().find(|s| !crate::is_image(&s.path)) { | |
| 1836 | + match audio_source_of(sources) { | |
| 1733 | 1837 | Some(first) => AudioSession::probe(&first.path, first.audio_stream), |
| 1734 | 1838 | None => Ok(None), |
| 1735 | 1839 | } |
| 1736 | 1840 | } |
| 1737 | 1841 | |
| 1842 | +/// *Which* source that is: the first one that is not a still. The single answer | |
| 1843 | +/// to "what does this timeline's sound come from", so that probing it | |
| 1844 | +/// ([`first_audio_of`]) and opening the device on it | |
| 1845 | +/// ([`PlaybackSession::open_project`]) can never disagree -- source 0 is only | |
| 1846 | +/// the scaffolding file until a save renumbers it or a library removal takes it | |
| 1847 | +/// away ([`crate::Project::remove_source`]), and a PNG at index 0 opened as the | |
| 1848 | +/// device is a timeline that plays silent although every clip on it has sound. | |
| 1849 | +/// | |
| 1850 | +/// `None` for a library of nothing but stills, and for one with no file at all: | |
| 1851 | +/// both are silent timelines. | |
| 1852 | +fn audio_source_of(sources: &[Source]) -> Option<&Source> { | |
| 1853 | + sources.iter().find(|s| !crate::is_image(&s.path)) | |
| 1854 | +} | |
| 1855 | + | |
| 1738 | 1856 | fn audio_matches(source: &Source, first: &Option<crate::AudioProbe>) -> crate::Result<()> { |
| 1739 | 1857 | // Whole-probe equality: rate and layout, which the audio worker holds every |
| 1740 | 1858 | // source to anyway. Both silent is a match. |
| @@ -1832,6 +1950,7 @@ fn open_audio(path: &Path, stream: usize) -> (Option<Audio>, Option<String>) { | ||
| 1832 | 1950 | fed_all: Arc::new(AtomicBool::new(false)), |
| 1833 | 1951 | died: Arc::new(AtomicBool::new(false)), |
| 1834 | 1952 | epoch: Arc::new(AtomicU64::new(0)), |
| 1953 | + tap: Arc::new(Mutex::new(Vec::with_capacity(TAP_SAMPLES))), | |
| 1835 | 1954 | }; |
| 1836 | 1955 | (audio.spawn_feeder(rx).then_some(audio), None) |
| 1837 | 1956 | } |
| @@ -1866,6 +1985,7 @@ fn feed(rx: Receiver<AudioChunk>, audio: &Audio, epoch: u64) { | ||
| 1866 | 1985 | } |
| 1867 | 1986 | }; |
| 1868 | 1987 | audio.fed.fetch_add(accepted as u64, Ordering::Relaxed); |
| 1988 | + audio.note_tap(&pending[..accepted]); | |
| 1869 | 1989 | pending.drain(..accepted); |
| 1870 | 1990 | if !pending.is_empty() { |
| 1871 | 1991 | // Ring full: nothing to do but let the device drain it. |
| @@ -1885,7 +2005,7 @@ fn secs_to_frame(secs: f64, fps: f64) -> u32 { | ||
| 1885 | 2005 | |
| 1886 | 2006 | #[cfg(test)] |
| 1887 | 2007 | mod tests { |
| 1888 | - use super::{Edge, Lane, PlaybackSession, secs_to_frame}; | |
| 2008 | + use super::{Edge, Lane, PlaybackSession, Source, audio_source_of, secs_to_frame}; | |
| 1889 | 2009 | use std::path::PathBuf; |
| 1890 | 2010 | |
| 1891 | 2011 | fn asset(name: &str) -> PathBuf { |
| @@ -1894,6 +2014,27 @@ mod tests { | ||
| 1894 | 2014 | .join(name) |
| 1895 | 2015 | } |
| 1896 | 2016 | |
| 2017 | + /// Which source the timeline's sound is opened on -- the one rule | |
| 2018 | + /// [`open_project`](PlaybackSession::open_project), the probe every import | |
| 2019 | + /// is held to and the audio worker all read through. A still at index 0 is | |
| 2020 | + /// a picture, not a silent timeline: opening the device on it is a project | |
| 2021 | + /// that plays silent although every clip on it has sound. | |
| 2022 | + #[test] | |
| 2023 | + fn the_audio_reference_is_never_a_still() { | |
| 2024 | + let (video, still) = (asset("test_av.mp4"), asset("test_still.png")); | |
| 2025 | + let sources = [Source::new(&still, 0), Source::new(&video, 3)]; | |
| 2026 | + assert_eq!( | |
| 2027 | + audio_source_of(&sources).map(|s| (&s.path, s.audio_stream)), | |
| 2028 | + Some((&sources[1].path, 3)), | |
| 2029 | + "the first source that could have a track, with its own stream" | |
| 2030 | + ); | |
| 2031 | + assert!( | |
| 2032 | + audio_source_of(&sources[..1]).is_none(), | |
| 2033 | + "nothing but stills" | |
| 2034 | + ); | |
| 2035 | + assert!(audio_source_of(&[]).is_none(), "and no file at all"); | |
| 2036 | + } | |
| 2037 | + | |
| 1897 | 2038 | /// The seam between the two lists a source index reaches: dropping a file |
| 1898 | 2039 | /// from the library shortens `sources`, and `counts` -- the frame length |
| 1899 | 2040 | /// per source, which is what a trim is walled by -- has to lose the same |
crates/engine/src/project.rsmodified+238 -26
| @@ -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> { |
| @@ -748,10 +809,20 @@ impl Project { | ||
| 748 | 809 | /// |
| 749 | 810 | /// Refused, changing nothing, while any clip still plays from it: the |
| 750 | 811 | /// refusal names the lanes and how many clips each holds, so a caller can |
| 751 | - /// say what has to be deleted first. Refused too for the last entry left, | |
| 752 | - /// because a project that names no file cannot be reopened | |
| 753 | - /// (`PlaybackSession::open_project`) and the timeline's audio parameters | |
| 754 | - /// are read off source 0. | |
| 812 | + /// say what has to be deleted first. The *last* entry goes like any other | |
| 813 | + /// -- a project may name no file at all, which is an empty library over an | |
| 814 | + /// empty timeline (nothing can play, since a clip would have refused the | |
| 815 | + /// removal). What a front-end does with that is its own decision: `edith`'s | |
| 816 | + /// window goes back to the empty state it launches in, and | |
| 817 | + /// [`PlaybackSession::save_project`](crate::PlaybackSession::save_project) | |
| 818 | + /// refuses to write a project that names nothing, because no such file | |
| 819 | + /// could be opened again. | |
| 820 | + /// | |
| 821 | + /// Every index past `idx` moves down by one, so a caller holding a *raw* | |
| 822 | + /// source index of its own -- a clipboard, which is the one thing outside | |
| 823 | + /// this type that does -- has to fix it up or drop it, or a paste plays a | |
| 824 | + /// different file. [`PlaybackSession::remove_source`] hands back the index | |
| 825 | + /// that went for exactly that. | |
| 755 | 826 | /// |
| 756 | 827 | /// ponytail: this retires the undo stack. `history` holds lanes alone, so a |
| 757 | 828 | /// snapshot older than the removal can name the very source being removed |
| @@ -766,12 +837,6 @@ impl Project { | ||
| 766 | 837 | return Err(format!("there is no source {idx} to remove").into()); |
| 767 | 838 | }; |
| 768 | 839 | let name = source.path.display().to_string(); |
| 769 | - // Asked before the clips are counted: with one file left the answer is | |
| 770 | - // the same whatever plays, and "the only file" is the more useful half | |
| 771 | - // of it. | |
| 772 | - if self.sources.len() == 1 { | |
| 773 | - return Err(format!("{name} is the only file this project names").into()); | |
| 774 | - } | |
| 775 | 840 | let used: Vec<String> = handles(&self.lanes) |
| 776 | 841 | .into_iter() |
| 777 | 842 | .zip(&self.lanes) |
| @@ -815,9 +880,16 @@ impl Project { | ||
| 815 | 880 | /// only the ones a clip names. |
| 816 | 881 | /// |
| 817 | 882 | /// One exception, and it is the emptied timeline's: a project no clip plays |
| 818 | - /// from still keeps source 0. It is the file a session is scaffolded from -- | |
| 819 | - /// its frame rate is the timeline's and is written nowhere else -- so a save | |
| 820 | - /// that pruned it would write a project that cannot be loaded back at all. | |
| 883 | + /// from still keeps its first source, if it has one. A file is what a | |
| 884 | + /// reopened project scaffolds itself from -- the frame rate is written | |
| 885 | + /// nowhere else -- so a save that pruned the last of them would write a | |
| 886 | + /// project that cannot be loaded back at all. | |
| 887 | + /// | |
| 888 | + /// What comes out is *not* ordered by anything a reader may assume: first | |
| 889 | + /// use, lane by lane, means the entry at index 0 can be a still or a song | |
| 890 | + /// whatever the session was scaffolded from. `PlaybackSession::open_project` | |
| 891 | + /// picks its rate and its audio reference by what a source *is*, never by | |
| 892 | + /// where it sits. | |
| 821 | 893 | pub fn without_orphan_sources(&self) -> Parts { |
| 822 | 894 | let mut moved = vec![None; self.sources.len()]; |
| 823 | 895 | let mut sources = Vec::new(); |
| @@ -1658,8 +1730,19 @@ impl Project { | ||
| 1658 | 1730 | } |
| 1659 | 1731 | self.snapshot(); |
| 1660 | 1732 | for (&(l, i), keep) in members.iter().zip(fitted) { |
| 1733 | + let still = self.is_still(&self.lanes[l].clips[i]); | |
| 1661 | 1734 | let c = &mut self.lanes[l].clips[i]; |
| 1662 | 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 | + } | |
| 1663 | 1746 | Edge::Start => { |
| 1664 | 1747 | // Non-negative by `lo`, which is what keeps the in-point on |
| 1665 | 1748 | // the source. |
| @@ -1700,9 +1783,24 @@ impl Project { | ||
| 1700 | 1783 | // head than the timeline has room for -- a ripple delete |
| 1701 | 1784 | // slides a clip back to frame 0 with its in-point wherever |
| 1702 | 1785 | // the cut left it -- and frame 0 is the other wall. |
| 1703 | - c.start | |
| 1704 | - .saturating_sub(c.speed.room(c.in_frame)) | |
| 1705 | - .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())), | |
| 1706 | 1804 | // One *frame of clip* always survives, and at a rate below |
| 1707 | 1805 | // real time one frame of clip is several frames of timeline |
| 1708 | 1806 | // ([`Speed::room`]): an edge dragged closer than that would |
| @@ -1739,6 +1837,16 @@ impl Project { | ||
| 1739 | 1837 | Some((lo, hi.max(lo))) |
| 1740 | 1838 | } |
| 1741 | 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 | + | |
| 1742 | 1850 | /// The clips that move as one with the clip at `idx` of `lane` -- itself and |
| 1743 | 1851 | /// whatever carries its link on the other lanes -- as `(lane storage index, |
| 1744 | 1852 | /// clip index)` pairs. `None` for an index that is not there. |
| @@ -3411,6 +3519,56 @@ mod tests { | ||
| 3411 | 3519 | assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]); |
| 3412 | 3520 | } |
| 3413 | 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 | + | |
| 3414 | 3572 | /// Linked halves trim as one: a link is one span on however many lanes, so |
| 3415 | 3573 | /// the sound follows the picture's edge -- and the tightest wall of the two |
| 3416 | 3574 | /// is what stops both. |
| @@ -3784,10 +3942,10 @@ mod tests { | ||
| 3784 | 3942 | } |
| 3785 | 3943 | |
| 3786 | 3944 | /// The two edges of a removal: it retires the undo stack (the ponytail on |
| 3787 | - /// [`Project::remove_source`]), and the last entry standing cannot go -- | |
| 3788 | - /// source 0 is where a reopened project reads its frame rate. | |
| 3945 | + /// [`Project::remove_source`]), and the last entry goes like any other | |
| 3946 | + /// once nothing plays it -- a project may name no file at all. | |
| 3789 | 3947 | #[test] |
| 3790 | - fn remove_source_retires_undo_and_keeps_the_last_file() { | |
| 3948 | + fn remove_source_retires_undo_and_empties_the_library() { | |
| 3791 | 3949 | let mut p = two_sources(); |
| 3792 | 3950 | assert!(p.delete_in(Lane::V1, 3), "FILE2's take goes first"); |
| 3793 | 3951 | assert!(!p.history.is_empty(), "there is something to undo"); |
| @@ -3798,18 +3956,25 @@ mod tests { | ||
| 3798 | 3956 | ); |
| 3799 | 3957 | assert!(!p.undo(), "and so there is nothing left to undo"); |
| 3800 | 3958 | |
| 3801 | - // The last file standing stays, whatever plays from it: | |
| 3802 | - // `PlaybackSession::open_project` refuses a project that names no | |
| 3803 | - // sources at all, and the timeline's frame rate lives in source 0. | |
| 3959 | + // The last file standing is held to the one rule every row is -- what | |
| 3960 | + // plays cannot go -- and to no other. | |
| 3804 | 3961 | assert_eq!(p.sources().len(), 1); |
| 3805 | 3962 | let refusal = p |
| 3806 | 3963 | .remove_source(0) |
| 3807 | - .expect_err("the only source must stay") | |
| 3964 | + .expect_err("its clips are still on the lanes") | |
| 3808 | 3965 | .to_string(); |
| 3809 | - assert!(refusal.contains("only file"), "{refusal}"); | |
| 3810 | - assert_eq!(p.sources().len(), 1); | |
| 3966 | + assert!(refusal.contains("still plays"), "{refusal}"); | |
| 3967 | + assert_eq!(p.sources().len(), 1, "a refusal changes nothing"); | |
| 3968 | + while p.delete_in(Lane::V1, 0) {} | |
| 3969 | + p.remove_source(0) | |
| 3970 | + .expect("the last row goes like any other"); | |
| 3971 | + assert!( | |
| 3972 | + p.sources().is_empty(), | |
| 3973 | + "a project may name no file at all: an empty library over an empty timeline" | |
| 3974 | + ); | |
| 3975 | + assert_eq!(p.timeline_frames(), 0); | |
| 3811 | 3976 | assert!( |
| 3812 | - p.remove_source(1).is_err(), | |
| 3977 | + p.remove_source(0).is_err(), | |
| 3813 | 3978 | "and an index that is not there is refused, not panicked on" |
| 3814 | 3979 | ); |
| 3815 | 3980 | } |
| @@ -4697,6 +4862,53 @@ mod tests { | ||
| 4697 | 4862 | assert_eq!(shape(&p), shape(&three())); |
| 4698 | 4863 | } |
| 4699 | 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 | + | |
| 4700 | 4912 | /// The grouping rule across more than two lanes: a link id is one *span*, |
| 4701 | 4913 | /// on however many lanes carry it -- not a video/audio pair and not a |
| 4702 | 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+108 -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 |
| @@ -341,6 +360,95 @@ fn a_still_survives_the_project_round_trip() { | ||
| 341 | 360 | let _ = std::fs::remove_dir_all(&dir); |
| 342 | 361 | } |
| 343 | 362 | |
| 363 | +/// The save renumbers sources by first use, so a still at the head of `V1` | |
| 364 | +/// comes back as **source 0** however the session was scaffolded -- and source | |
| 365 | +/// 0 is what everything used to read the timeline off. A picture defines no | |
| 366 | +/// frame rate and has no sound, so the reload used to read this project as 30 | |
| 367 | +/// fps (refusing the 25 fps footage still on `A1` by name) and open the output | |
| 368 | +/// device on a PNG (a timeline that plays silent although its clips have | |
| 369 | +/// sound). Nothing may assume what source 0 *is*: the rate comes from the first | |
| 370 | +/// source that has one, and the sound from the first that could have any. | |
| 371 | +#[test] | |
| 372 | +fn a_still_at_saved_source_zero_keeps_the_rate_and_the_sound() { | |
| 373 | + pin_software(); | |
| 374 | + let dir = std::env::temp_dir().join(format!("ve_still_first_{}", std::process::id())); | |
| 375 | + let _ = std::fs::remove_dir_all(&dir); | |
| 376 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | |
| 377 | + let media = dir.join("test_25fps.mp4"); | |
| 378 | + let still = dir.join("test_still.png"); | |
| 379 | + std::fs::copy(asset("test_25fps.mp4"), &media).expect("copy the video"); | |
| 380 | + std::fs::copy(asset("test_still.png"), &still).expect("copy the still"); | |
| 381 | + | |
| 382 | + // 25 fps, which no still is ever given: the rate alone says which source | |
| 383 | + // the reload scaffolded from. | |
| 384 | + let mut session = PlaybackSession::open(&media).expect("open the fixture"); | |
| 385 | + session.set_gain(0.0); | |
| 386 | + assert!((session.meta().frame_rate - 25.0).abs() < 0.01); | |
| 387 | + session.import(&still).expect("a picture"); | |
| 388 | + // Over the head of V1, where it takes the whole take's picture: the sound | |
| 389 | + // stays on A1, so the still is the first clip in save order and the video | |
| 390 | + // is a source only the audio lane names. | |
| 391 | + assert!( | |
| 392 | + session | |
| 393 | + .place_stream_at(0.0, &still, 0, Some(Lane::V1)) | |
| 394 | + .expect("a still joins any timeline") | |
| 395 | + ); | |
| 396 | + assert!(session.lane_clips(Lane::V1).len() == 1 && session.lane_clips(Lane::A1).len() == 1); | |
| 397 | + | |
| 398 | + let project = dir.join("still_first.edith"); | |
| 399 | + session.save_project(&project).expect("save"); | |
| 400 | + let text = std::fs::read_to_string(&project).expect("read the project"); | |
| 401 | + let source_0 = text | |
| 402 | + .lines() | |
| 403 | + .find(|l| l.starts_with("source ")) | |
| 404 | + .expect("a source line"); | |
| 405 | + assert!( | |
| 406 | + source_0.contains("test_still.png"), | |
| 407 | + "the premise: the save put the still at index 0 -- {source_0}" | |
| 408 | + ); | |
| 409 | + | |
| 410 | + let reopened = PlaybackSession::open_project(&project).expect("a saved project always reopens"); | |
| 411 | + assert!( | |
| 412 | + (reopened.meta().frame_rate - 25.0).abs() < 0.01, | |
| 413 | + "the footage's rate, not the still's 30: {}", | |
| 414 | + reopened.meta().frame_rate | |
| 415 | + ); | |
| 416 | + // The same sound, at the same place, playing the same file -- by a *new* | |
| 417 | + // index, which is the renumbering this whole test is about. | |
| 418 | + let (sound, was) = ( | |
| 419 | + reopened.lane_clips(Lane::A1)[0], | |
| 420 | + session.lane_clips(Lane::A1)[0], | |
| 421 | + ); | |
| 422 | + assert_eq!( | |
| 423 | + (sound.start, sound.in_frame, sound.out_frame), | |
| 424 | + (was.start, was.in_frame, was.out_frame) | |
| 425 | + ); | |
| 426 | + assert!( | |
| 427 | + reopened.sources()[sound.source] | |
| 428 | + .path | |
| 429 | + .ends_with("test_25fps.mp4"), | |
| 430 | + "the take's sound still names the video" | |
| 431 | + ); | |
| 432 | + assert!( | |
| 433 | + reopened.audio_disabled_reason().is_none(), | |
| 434 | + "a still is not a reason a timeline is silent: {:?}", | |
| 435 | + reopened.audio_disabled_reason() | |
| 436 | + ); | |
| 437 | + // And the sound itself, through the very opener a seek builds its worker | |
| 438 | + // with: source 0 is the PNG here, and one opened unconditionally is an | |
| 439 | + // error that takes every lane's audio down with it. | |
| 440 | + let sources: Vec<_> = reopened | |
| 441 | + .sources() | |
| 442 | + .iter() | |
| 443 | + .map(|s| (s.path.clone(), s.audio_stream)) | |
| 444 | + .collect(); | |
| 445 | + let (meta, _rx) = engine::AudioSession::open_multi_streams(&sources, &[(Some(1), 0.0, 1.0)]) | |
| 446 | + .expect("the worker opens over a still at index 0") | |
| 447 | + .expect("the take on A1 has sound"); | |
| 448 | + assert_eq!(meta.sample_rate, 44_100, "the take's own rate"); | |
| 449 | + let _ = std::fs::remove_dir_all(&dir); | |
| 450 | +} | |
| 451 | + | |
| 344 | 452 | /// The export is what was watched: a timeline of video then still comes back |
| 345 | 453 | /// out of the mp4 as video then still, with the still's own colours in it. |
| 346 | 454 | #[test] |