Merge branch 'main' into worktree-agent-a46e3271de2d17ff3
Browse files at this commit5 changed files +793 -46
- crates/app/src/keymap.rs +34 -5
- crates/app/src/main.rs +536 -38
- crates/engine/src/playback.rs +7 -0
- crates/engine/src/project.rs +197 -3
- crates/engine/tests/images.rs +19 -0
crates/app/src/keymap.rsmodified+34 -5
| @@ -66,6 +66,8 @@ pub enum ActionId { | |||
| 66 | Undo, | 66 | Undo, |
| 67 | AddVideoLane, | 67 | AddVideoLane, |
| 68 | AddAudioLane, | 68 | AddAudioLane, |
| 69 | + RemoveVideoLane, | ||
| 70 | + RemoveAudioLane, | ||
| 69 | ToggleMute, | 71 | ToggleMute, |
| 70 | VolumeUp, | 72 | VolumeUp, |
| 71 | VolumeDown, | 73 | VolumeDown, |
| @@ -78,7 +80,7 @@ pub enum ActionId { | |||
| 78 | impl ActionId { | 80 | impl ActionId { |
| 79 | /// Display order everywhere -- the editor lists them in it and | 81 | /// Display order everywhere -- the editor lists them in it and |
| 80 | /// [`Keymap::defaults`] binds them in it. | 82 | /// [`Keymap::defaults`] binds them in it. |
| 81 | - pub const ALL: [ActionId; 33] = [ | 83 | + pub const ALL: [ActionId; 35] = [ |
| 82 | ActionId::Play, | 84 | ActionId::Play, |
| 83 | ActionId::StepBack, | 85 | ActionId::StepBack, |
| 84 | ActionId::StepForward, | 86 | ActionId::StepForward, |
| @@ -105,6 +107,8 @@ impl ActionId { | |||
| 105 | ActionId::Undo, | 107 | ActionId::Undo, |
| 106 | ActionId::AddVideoLane, | 108 | ActionId::AddVideoLane, |
| 107 | ActionId::AddAudioLane, | 109 | ActionId::AddAudioLane, |
| 110 | + ActionId::RemoveVideoLane, | ||
| 111 | + ActionId::RemoveAudioLane, | ||
| 108 | ActionId::ToggleMute, | 112 | ActionId::ToggleMute, |
| 109 | ActionId::VolumeUp, | 113 | ActionId::VolumeUp, |
| 110 | ActionId::VolumeDown, | 114 | ActionId::VolumeDown, |
| @@ -143,6 +147,8 @@ impl ActionId { | |||
| 143 | ActionId::Undo => "Undo", | 147 | ActionId::Undo => "Undo", |
| 144 | ActionId::AddVideoLane => "Add a video track", | 148 | ActionId::AddVideoLane => "Add a video track", |
| 145 | ActionId::AddAudioLane => "Add an audio track", | 149 | ActionId::AddAudioLane => "Add an audio track", |
| 150 | + ActionId::RemoveVideoLane => "Remove the last video track (it must be empty)", | ||
| 151 | + ActionId::RemoveAudioLane => "Remove the last audio track (it must be empty)", | ||
| 146 | ActionId::ToggleMute => "Mute / Unmute", | 152 | ActionId::ToggleMute => "Mute / Unmute", |
| 147 | ActionId::VolumeUp => "Volume up", | 153 | ActionId::VolumeUp => "Volume up", |
| 148 | ActionId::VolumeDown => "Volume down", | 154 | ActionId::VolumeDown => "Volume down", |
| @@ -183,6 +189,8 @@ impl ActionId { | |||
| 183 | ActionId::Undo => "undo", | 189 | ActionId::Undo => "undo", |
| 184 | ActionId::AddVideoLane => "add-video-lane", | 190 | ActionId::AddVideoLane => "add-video-lane", |
| 185 | ActionId::AddAudioLane => "add-audio-lane", | 191 | ActionId::AddAudioLane => "add-audio-lane", |
| 192 | + ActionId::RemoveVideoLane => "remove-video-lane", | ||
| 193 | + ActionId::RemoveAudioLane => "remove-audio-lane", | ||
| 186 | ActionId::ToggleMute => "toggle-mute", | 194 | ActionId::ToggleMute => "toggle-mute", |
| 187 | ActionId::VolumeUp => "volume-up", | 195 | ActionId::VolumeUp => "volume-up", |
| 188 | ActionId::VolumeDown => "volume-down", | 196 | ActionId::VolumeDown => "volume-down", |
| @@ -235,7 +243,9 @@ impl ActionId { | |||
| 235 | | ActionId::Group | 243 | | ActionId::Group |
| 236 | | ActionId::Undo | 244 | | ActionId::Undo |
| 237 | | ActionId::AddVideoLane | 245 | | ActionId::AddVideoLane |
| 238 | - | ActionId::AddAudioLane => Category::Editing, | 246 | + | ActionId::AddAudioLane |
| 247 | + | ActionId::RemoveVideoLane | ||
| 248 | + | ActionId::RemoveAudioLane => Category::Editing, | ||
| 239 | ActionId::ToggleMute | 249 | ActionId::ToggleMute |
| 240 | | ActionId::VolumeUp | 250 | | ActionId::VolumeUp |
| 241 | | ActionId::VolumeDown | 251 | | ActionId::VolumeDown |
| @@ -291,7 +301,15 @@ pub struct Fixed { | |||
| 291 | pub category: Category, | 301 | pub category: Category, |
| 292 | } | 302 | } |
| 293 | 303 | ||
| 294 | -pub const FIXED: [Fixed; 15] = [ | 304 | +pub const FIXED: [Fixed; 16] = [ |
| 305 | + // Not a chord at all but a way of pressing one, and the only place the | ||
| 306 | + // editor can say so: holding a key that moves a *value* runs it, and | ||
| 307 | + // holding anything else still does what one press did. | ||
| 308 | + Fixed { | ||
| 309 | + chord: "hold ← → ↑ ↓", | ||
| 310 | + label: "Run a card's slider, or the volume keys, while held", | ||
| 311 | + category: Category::View, | ||
| 312 | + }, | ||
| 295 | Fixed { | 313 | Fixed { |
| 296 | chord: "esc", | 314 | chord: "esc", |
| 297 | label: "Close this card or menu, or cancel a capture", | 315 | label: "Close this card or menu, or cancel a capture", |
| @@ -533,6 +551,13 @@ impl Keymap { | |||
| 533 | // is added often enough to deserve a key that is one press. | 551 | // is added often enough to deserve a key that is one press. |
| 534 | b(ActionId::AddVideoLane, "v", false), | 552 | b(ActionId::AddVideoLane, "v", false), |
| 535 | b(ActionId::AddAudioLane, "a", false), | 553 | b(ActionId::AddAudioLane, "a", false), |
| 554 | + // ...and the pair that takes one back, on ctrl chords: removing | ||
| 555 | + // a track is not a stroke to hit by accident (the resolution key | ||
| 556 | + // is out of the way for the same reason). Ctrl+v would be the | ||
| 557 | + // matching initial and is the paste, so the video one takes the | ||
| 558 | + // key beside it. | ||
| 559 | + b(ActionId::RemoveVideoLane, "b", true), | ||
| 560 | + b(ActionId::RemoveAudioLane, "a", true), | ||
| 536 | b(ActionId::ToggleMute, "m", false), | 561 | b(ActionId::ToggleMute, "m", false), |
| 537 | // The unshifted pair, which is what gpui reports for those two | 562 | // The unshifted pair, which is what gpui reports for those two |
| 538 | // keys ("=" and "-", platform.rs:862): the volume keys every | 563 | // keys ("=" and "-", platform.rs:862): the volume keys every |
| @@ -814,7 +839,7 @@ mod tests { | |||
| 814 | #[test] | 839 | #[test] |
| 815 | fn every_default_stroke_reaches_its_action() { | 840 | fn every_default_stroke_reaches_its_action() { |
| 816 | let k = Keymap::defaults(); | 841 | let k = Keymap::defaults(); |
| 817 | - assert_eq!(k.entries().len(), 35); | 842 | + assert_eq!(k.entries().len(), 37); |
| 818 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); | 843 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); |
| 819 | // The seek keys: bare arrows a frame, ctrl arrows a second, and the two | 844 | // The seek keys: bare arrows a frame, ctrl arrows a second, and the two |
| 820 | // ends of the timeline. | 845 | // ends of the timeline. |
| @@ -848,6 +873,10 @@ mod tests { | |||
| 848 | // The track keys are the bare letters; the ctrl ones stay copy/paste. | 873 | // The track keys are the bare letters; the ctrl ones stay copy/paste. |
| 849 | assert_eq!(k.lookup("v", false), Some(ActionId::AddVideoLane)); | 874 | assert_eq!(k.lookup("v", false), Some(ActionId::AddVideoLane)); |
| 850 | assert_eq!(k.lookup("a", false), Some(ActionId::AddAudioLane)); | 875 | assert_eq!(k.lookup("a", false), Some(ActionId::AddAudioLane)); |
| 876 | + // ...and the ctrl ones take a track away, out of the way of a stray | ||
| 877 | + // press. Ctrl+v is the paste, so the video one sits beside it. | ||
| 878 | + assert_eq!(k.lookup("b", true), Some(ActionId::RemoveVideoLane)); | ||
| 879 | + assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane)); | ||
| 851 | assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute)); | 880 | assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute)); |
| 852 | assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer)); | 881 | assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer)); |
| 853 | // The volume pair is the unshifted one, so neither needs a modifier | 882 | // The volume pair is the unshifted one, so neither needs a modifier |
| @@ -1043,7 +1072,7 @@ mod tests { | |||
| 1043 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); | 1072 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); |
| 1044 | // The label is the editor's column, and never the file's word for it. | 1073 | // The label is the editor's column, and never the file's word for it. |
| 1045 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); | 1074 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); |
| 1046 | - assert_eq!(ActionId::ALL.len(), 33); | 1075 | + assert_eq!(ActionId::ALL.len(), 35); |
| 1047 | } | 1076 | } |
| 1048 | 1077 | ||
| 1049 | #[test] | 1078 | #[test] |
crates/app/src/main.rsmodified+536 -38
| @@ -95,6 +95,9 @@ const ROW_H: f32 = 32.; | |||
| 95 | /// wear in the lanes, which is the whole of the panel<->timeline association. | 95 | /// wear in the lanes, which is the whole of the panel<->timeline association. |
| 96 | const SWATCH_W: f32 = 4.; | 96 | const SWATCH_W: f32 = 4.; |
| 97 | const CONTROL_H: f32 = 28.; | 97 | const CONTROL_H: f32 = 28.; |
| 98 | +/// The volume slider beside its button: a hundred steps across it, so a pixel | ||
| 99 | +/// is finer than a step and the drag reads as continuous. | ||
| 100 | +const VOLUME_W: f32 = 110.; | ||
| 98 | const RULER_HIT_H: f32 = HIT_MIN; | 101 | const RULER_HIT_H: f32 = HIT_MIN; |
| 99 | /// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits | 102 | /// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits |
| 100 | /// cannot push the layout around. | 103 | /// cannot push the layout around. |
| @@ -128,6 +131,18 @@ const ESCAPE: &str = "escape"; | |||
| 128 | /// as a program name rather than as a file name. | 131 | /// as a program name rather than as a file name. |
| 129 | const NO_FILE: &str = "no file open"; | 132 | const NO_FILE: &str = "no file open"; |
| 130 | 133 | ||
| 134 | +/// What a press of play says when there is nothing to play: no timeline at all | ||
| 135 | +/// and an emptied one are the same answer to the user, so they are one line. | ||
| 136 | +const NOTHING_TO_PLAY: &str = "NOTHING TO PLAY — put a clip on the timeline first"; | ||
| 137 | + | ||
| 138 | +/// Whether a press of play would have anything to play. No timeline at all and | ||
| 139 | +/// one every clip has been taken off are the same state to a transport, and the | ||
| 140 | +/// button and the key both have to give the same answer to it -- so there is | ||
| 141 | +/// one of them, and it is free of the window so it can be checked without one. | ||
| 142 | +fn nothing_to_play(session: Option<&PlaybackSession>) -> bool { | ||
| 143 | + session.is_none_or(PlaybackSession::is_empty) | ||
| 144 | +} | ||
| 145 | + | ||
| 131 | /// What the monitoring output is set to. Two things, not one: the level the | 146 | /// What the monitoring output is set to. Two things, not one: the level the |
| 132 | /// user picked, and whether it is being held silent -- so unmuting comes back | 147 | /// user picked, and whether it is being held silent -- so unmuting comes back |
| 133 | /// to the level rather than to a guess. | 148 | /// to the level rather than to a guess. |
| @@ -146,29 +161,45 @@ struct Volume { | |||
| 146 | } | 161 | } |
| 147 | 162 | ||
| 148 | impl Volume { | 163 | impl Volume { |
| 149 | - /// 5% a press: twenty of them across the range. | 164 | + /// One step is one percent: fine enough that a drag along the slider reads |
| 150 | - const MAX_STEPS: u8 = 20; | 165 | + /// as continuous, and still a count rather than a float. |
| 166 | + const MAX_STEPS: u8 = 100; | ||
| 167 | + | ||
| 168 | + /// 5% a press: twenty presses across the range, which is what the keys have | ||
| 169 | + /// always moved. The slider is what the finer grid is for. | ||
| 170 | + const KEY_STEP: u8 = 5; | ||
| 151 | 171 | ||
| 152 | /// What the device is set to: mute wins, and the level is what it returns | 172 | /// What the device is set to: mute wins, and the level is what it returns |
| 153 | /// to. `0.0..=1.0`, which is the range the plugin's ABI accepts. | 173 | /// to. `0.0..=1.0`, which is the range the plugin's ABI accepts. |
| 154 | fn gain(self) -> f32 { | 174 | fn gain(self) -> f32 { |
| 155 | - if self.muted { | 175 | + if self.muted { 0. } else { self.along() } |
| 156 | - 0. | ||
| 157 | - } else { | ||
| 158 | - f32::from(self.steps) / f32::from(Self::MAX_STEPS) | ||
| 159 | - } | ||
| 160 | } | 176 | } |
| 161 | 177 | ||
| 162 | /// One press up or down, clamped at both ends -- saturating, so the count | 178 | /// One press up or down, clamped at both ends -- saturating, so the count |
| 163 | /// cannot wrap past silence into full volume. | 179 | /// cannot wrap past silence into full volume. |
| 164 | fn step(&mut self, up: bool) { | 180 | fn step(&mut self, up: bool) { |
| 165 | self.steps = if up { | 181 | self.steps = if up { |
| 166 | - self.steps.saturating_add(1).min(Self::MAX_STEPS) | 182 | + self.steps.saturating_add(Self::KEY_STEP).min(Self::MAX_STEPS) |
| 167 | } else { | 183 | } else { |
| 168 | - self.steps.saturating_sub(1) | 184 | + self.steps.saturating_sub(Self::KEY_STEP) |
| 169 | }; | 185 | }; |
| 170 | } | 186 | } |
| 171 | 187 | ||
| 188 | + /// Where the hand let go along the slider, 0..1 from silence to full. The | ||
| 189 | + /// grid is the same one the keys land on, so a drag to the top and a key | ||
| 190 | + /// held up reach the very same number -- and a drag never touches mute: | ||
| 191 | + /// asking for a level while muted is not asking for sound. | ||
| 192 | + fn set_along(&mut self, frac: f32) { | ||
| 193 | + self.steps = (frac.clamp(0., 1.) * f32::from(Self::MAX_STEPS)).round() as u8; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + /// How full the slider is drawn, 0..1. The level and not the gain: a muted | ||
| 197 | + /// slider still shows what unmuting comes back to, exactly as the label | ||
| 198 | + /// does. | ||
| 199 | + fn along(self) -> f32 { | ||
| 200 | + f32::from(self.steps) / f32::from(Self::MAX_STEPS) | ||
| 201 | + } | ||
| 202 | + | ||
| 172 | /// What the button reads. The level shows while muted too: it is what the | 203 | /// What the button reads. The level shows while muted too: it is what the |
| 173 | /// next press of the mute key brings back. | 204 | /// next press of the mute key brings back. |
| 174 | fn label(self) -> String { | 205 | fn label(self) -> String { |
| @@ -358,9 +389,10 @@ fn speed_at(permille: i32) -> Speed { | |||
| 358 | } | 389 | } |
| 359 | 390 | ||
| 360 | /// The silence card's rows, in the order it lists them: how wide the apply | 391 | /// The silence card's rows, in the order it lists them: how wide the apply |
| 361 | -/// reaches, the four settings a scan is told, and the rate the speed-up plays | 392 | +/// reaches, the threshold and the unit it is read in, the three durations a |
| 362 | -/// at. What `silence_field` indexes and what [`Player::nudge_silence`] moves. | 393 | +/// scan is told, and the rate the speed-up plays at. What `silence_field` |
| 363 | -const SILENCE_ROWS: usize = 6; | 394 | +/// indexes and what [`Player::nudge_silence`] moves. |
| 395 | +const SILENCE_ROWS: usize = 7; | ||
| 364 | 396 | ||
| 365 | /// How wide a jumpcut reaches. A ripple used to be the whole timeline's | 397 | /// How wide a jumpcut reaches. A ripple used to be the whole timeline's |
| 366 | /// business and nothing else; it is a *choice* now, because a podcast track's | 398 | /// business and nothing else; it is a *choice* now, because a podcast track's |
| @@ -408,9 +440,12 @@ const SILENCE_DB_STEP: f32 = 1.; | |||
| 408 | const SILENCE_SECS_STEP: f64 = 0.05; | 440 | const SILENCE_SECS_STEP: f64 = 0.05; |
| 409 | 441 | ||
| 410 | /// How far each of them may be pushed. UI decisions, all of them: the engine | 442 | /// How far each of them may be pushed. UI decisions, all of them: the engine |
| 411 | -/// takes any finite number, but a threshold at 0 dBFS calls a whole take silent | 443 | +/// takes any finite number, but a forgiveness of ten seconds finds nothing in a |
| 412 | -/// and a forgiveness of ten seconds finds nothing in a talking head. | 444 | +/// talking head. The threshold reaches full scale, which calls a whole take |
| 413 | -const SILENCE_DB_RANGE: (f32, f32) = (-80., -10.); | 445 | +/// silent -- that is a thing someone may want to ask for (the preview on the |
| 446 | +/// lane says what it would cost before anything is cut), so the top is 0 rather | ||
| 447 | +/// than a number this card picked for them. | ||
| 448 | +const SILENCE_DB_RANGE: (f32, f32) = (-80., 0.); | ||
| 414 | const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.); | 449 | const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.); |
| 415 | 450 | ||
| 416 | /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows | 451 | /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows |
| @@ -614,6 +649,11 @@ struct Player { | |||
| 614 | /// also why it is not written to the project file and cannot reach an | 649 | /// also why it is not written to the project file and cannot reach an |
| 615 | /// export. [`Player::apply_volume`] is what pushes it at a session. | 650 | /// export. [`Player::apply_volume`] is what pushes it at a session. |
| 616 | volume: Volume, | 651 | volume: Volume, |
| 652 | + /// Where the volume slider was last painted, and whether a hand is on it -- | ||
| 653 | + /// the speed bar's pair, for the speed bar's reason: the pointer moves | ||
| 654 | + /// arrive at the root, so the bar's own geometry has to be readable there. | ||
| 655 | + volume_bar: Rc<Cell<Bounds<Pixels>>>, | ||
| 656 | + volume_dragging: bool, | ||
| 617 | /// The keybindings overlay is up. While it is, it owns the keyboard and the | 657 | /// The keybindings overlay is up. While it is, it owns the keyboard and the |
| 618 | /// pointer: a stroke or a click meant for a row must not also cut the | 658 | /// pointer: a stroke or a click meant for a row must not also cut the |
| 619 | /// timeline. | 659 | /// timeline. |
| @@ -687,6 +727,14 @@ struct Player { | |||
| 687 | /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own | 727 | /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own |
| 688 | /// focus, since nothing in it takes gpui's (ledger:182). | 728 | /// focus, since nothing in it takes gpui's (ledger:182). |
| 689 | silence_field: usize, | 729 | silence_field: usize, |
| 730 | + /// Whether the threshold is *labelled* dBFS or dB. Display only, and the | ||
| 731 | + /// number is the same either way: the setting is a level below full scale, | ||
| 732 | + /// so 0 is the loudest sample a file can hold and -40 is forty decibels | ||
| 733 | + /// under it -- "dBFS" names that reference out loud, "dB" leaves it unsaid. | ||
| 734 | + /// No conversion is hiding behind the row (there is no reference here worth | ||
| 735 | + /// inventing, and a made-up SPL would be a lie about what was measured); | ||
| 736 | + /// what it changes is which of the two spellings a person reads. | ||
| 737 | + silence_dbfs: bool, | ||
| 690 | /// What the last scan found, in timeline frames: what the lane draws marks | 738 | /// What the last scan found, in timeline frames: what the lane draws marks |
| 691 | /// over and what an apply acts on -- *exactly* the previewed set, never a | 739 | /// over and what an apply acts on -- *exactly* the previewed set, never a |
| 692 | /// second scan at the moment of the press. | 740 | /// second scan at the moment of the press. |
| @@ -857,6 +905,11 @@ impl Player { | |||
| 857 | ActionId::Undo => self.undo(cx), | 905 | ActionId::Undo => self.undo(cx), |
| 858 | ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx), | 906 | ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx), |
| 859 | ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx), | 907 | ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx), |
| 908 | + // The last track of that kind: the one the add key put there, so the | ||
| 909 | + // two strokes undo each other press for press. Any other track goes | ||
| 910 | + // through the × in its own header. | ||
| 911 | + ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx), | ||
| 912 | + ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx), | ||
| 860 | ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx), | 913 | ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx), |
| 861 | ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx), | 914 | ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx), |
| 862 | ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx), | 915 | ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx), |
| @@ -1349,9 +1402,12 @@ impl Player { | |||
| 1349 | + steps as f32 * SILENCE_DB_STEP) | 1402 | + steps as f32 * SILENCE_DB_STEP) |
| 1350 | .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1) | 1403 | .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1) |
| 1351 | } | 1404 | } |
| 1352 | - 2 => self.silence.min_silence = secs(self.silence.min_silence), | 1405 | + // Two spellings of the same level, so either arrow flips it -- a |
| 1353 | - 3 => self.silence.padding = secs(self.silence.padding), | 1406 | + // ring of two, like the scope row's. |
| 1354 | - 4 => self.silence.min_keep = secs(self.silence.min_keep), | 1407 | + 2 => self.silence_dbfs = !self.silence_dbfs, |
| 1408 | + 3 => self.silence.min_silence = secs(self.silence.min_silence), | ||
| 1409 | + 4 => self.silence.padding = secs(self.silence.padding), | ||
| 1410 | + 5 => self.silence.min_keep = secs(self.silence.min_keep), | ||
| 1355 | _ => { | 1411 | _ => { |
| 1356 | self.silence_factor = | 1412 | self.silence_factor = |
| 1357 | silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP) | 1413 | silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP) |
| @@ -1504,6 +1560,29 @@ impl Player { | |||
| 1504 | || self.exporting().is_some() | 1560 | || self.exporting().is_some() |
| 1505 | } | 1561 | } |
| 1506 | 1562 | ||
| 1563 | + /// Which of [`Repeat`]'s three the window is in, for the hold gate at the | ||
| 1564 | + /// top of the key handler. Not [`Player::modal`]: that asks whether an | ||
| 1565 | + /// overlay is up at all, and here the cards with sliders in them are | ||
| 1566 | + /// exactly the ones that answer differently from the keys menu and the | ||
| 1567 | + /// export card. | ||
| 1568 | + fn repeat_scope(&self) -> Repeat { | ||
| 1569 | + if self.rebinding.is_some() | ||
| 1570 | + || self.keys_open | ||
| 1571 | + || self.export_open | ||
| 1572 | + || self.exporting().is_some() | ||
| 1573 | + { | ||
| 1574 | + Repeat::Nothing | ||
| 1575 | + } else if self.eq_open.is_some() | ||
| 1576 | + || self.color_open.is_some() | ||
| 1577 | + || self.speed_open.is_some() | ||
| 1578 | + || self.silence_open.is_some() | ||
| 1579 | + { | ||
| 1580 | + Repeat::Card | ||
| 1581 | + } else { | ||
| 1582 | + Repeat::Keymap | ||
| 1583 | + } | ||
| 1584 | + } | ||
| 1585 | + | ||
| 1507 | /// Opens the equalizer on the selected clip. Audio only, and it says so | 1586 | /// Opens the equalizer on the selected clip. Audio only, and it says so |
| 1508 | /// rather than opening a card of bands that would reach nothing: a video | 1587 | /// rather than opening a card of bands that would reach nothing: a video |
| 1509 | /// clip carries no sound of its own here (the sound is the audio lane's), | 1588 | /// clip carries no sound of its own here (the sound is the audio lane's), |
| @@ -2053,6 +2132,25 @@ impl Player { | |||
| 2053 | return clip; | 2132 | return clip; |
| 2054 | }; | 2133 | }; |
| 2055 | match trim.edge { | 2134 | match trim.edge { |
| 2135 | + // A still grows forward from source frame 0 instead, exactly as | ||
| 2136 | + // `Project::trim` writes it: with the in-point clamped at 0 the box | ||
| 2137 | + // below would slide left rather than stretch, and the release would | ||
| 2138 | + // then commit a wider clip than the drag drew. | ||
| 2139 | + Edge::Start | ||
| 2140 | + if self.session.as_ref().is_some_and(|session| { | ||
| 2141 | + session | ||
| 2142 | + .sources() | ||
| 2143 | + .get(clip.source) | ||
| 2144 | + .is_some_and(|s| engine::is_image(&s.path)) | ||
| 2145 | + }) => | ||
| 2146 | + { | ||
| 2147 | + Clip { | ||
| 2148 | + in_frame: 0, | ||
| 2149 | + out_frame: clip.end().saturating_sub(trim.to).max(1), | ||
| 2150 | + start: trim.to, | ||
| 2151 | + ..clip | ||
| 2152 | + } | ||
| 2153 | + } | ||
| 2056 | // The in-point follows the head, exactly as `Project::trim` moves | 2154 | // The in-point follows the head, exactly as `Project::trim` moves |
| 2057 | // it: what stays on screen plays what it always played. | 2155 | // it: what stays on screen plays what it always played. |
| 2058 | Edge::Start => Clip { | 2156 | Edge::Start => Clip { |
| @@ -2432,6 +2530,64 @@ impl Player { | |||
| 2432 | cx.notify(); | 2530 | cx.notify(); |
| 2433 | } | 2531 | } |
| 2434 | 2532 | ||
| 2533 | + /// The × in a track's header: the add taken back, one undo step, and the | ||
| 2534 | + /// engine's own words when it refuses -- those name the clips still on the | ||
| 2535 | + /// track, so the notice says what to delete first. A removal never deletes a | ||
| 2536 | + /// clip. | ||
| 2537 | + /// | ||
| 2538 | + /// Everything holding a `(lane, idx)` is dropped, because the tracks below | ||
| 2539 | + /// the one that went have just moved up an `ord` | ||
| 2540 | + /// ([`engine::Project::remove_lane`]): a selection or an open card kept | ||
| 2541 | + /// across it would be pointing at the *next* track's clip. | ||
| 2542 | + fn remove_lane(&mut self, lane: Lane, cx: &mut Context<Self>) { | ||
| 2543 | + if self.exporting().is_some() { | ||
| 2544 | + return; | ||
| 2545 | + } | ||
| 2546 | + let removed = self | ||
| 2547 | + .session | ||
| 2548 | + .as_mut() | ||
| 2549 | + .map(|session| session.remove_lane(lane)); | ||
| 2550 | + let text = match removed { | ||
| 2551 | + Some(Ok(())) => { | ||
| 2552 | + self.selected = None; | ||
| 2553 | + self.context_menu = None; | ||
| 2554 | + self.eq_open = None; | ||
| 2555 | + self.color_open = None; | ||
| 2556 | + self.speed_open = None; | ||
| 2557 | + self.close_silence(); | ||
| 2558 | + format!( | ||
| 2559 | + "{} REMOVED — {} brings it back", | ||
| 2560 | + lane.label(), | ||
| 2561 | + self.keymap.display(ActionId::Undo) | ||
| 2562 | + ) | ||
| 2563 | + } | ||
| 2564 | + Some(Err(e)) => format!("NO TRACK REMOVED — {e}"), | ||
| 2565 | + None => "NO TRACK REMOVED — open a file first".to_string(), | ||
| 2566 | + }; | ||
| 2567 | + self.notice = Some(text.into()); | ||
| 2568 | + cx.notify(); | ||
| 2569 | + } | ||
| 2570 | + | ||
| 2571 | + /// What the remove keys act on: the last track of that kind, which is the | ||
| 2572 | + /// one the matching add key appended. Nothing at all before a file is open, | ||
| 2573 | + /// where the timeline drawn is a placeholder pair. | ||
| 2574 | + fn remove_last_lane(&mut self, kind: LaneKind, cx: &mut Context<Self>) { | ||
| 2575 | + let last = self.session.as_ref().and_then(|session| { | ||
| 2576 | + session | ||
| 2577 | + .lanes() | ||
| 2578 | + .into_iter() | ||
| 2579 | + .filter(|l| l.kind == kind) | ||
| 2580 | + .next_back() | ||
| 2581 | + }); | ||
| 2582 | + match last { | ||
| 2583 | + Some(lane) => self.remove_lane(lane, cx), | ||
| 2584 | + None => { | ||
| 2585 | + self.notice = Some("NO TRACK REMOVED — open a file first".into()); | ||
| 2586 | + cx.notify(); | ||
| 2587 | + } | ||
| 2588 | + } | ||
| 2589 | + } | ||
| 2590 | + | ||
| 2435 | fn undo(&mut self, cx: &mut Context<Self>) { | 2591 | fn undo(&mut self, cx: &mut Context<Self>) { |
| 2436 | if self.session.as_mut().is_some_and(PlaybackSession::undo) { | 2592 | if self.session.as_mut().is_some_and(PlaybackSession::undo) { |
| 2437 | self.reset_after_reseek(); | 2593 | self.reset_after_reseek(); |
| @@ -2518,10 +2674,33 @@ impl Player { | |||
| 2518 | cx.notify(); | 2674 | cx.notify(); |
| 2519 | } | 2675 | } |
| 2520 | 2676 | ||
| 2677 | + /// Where the pointer sits along the slider, as a level. The press and every | ||
| 2678 | + /// sample after it come here, so the sound follows the hand rather than the | ||
| 2679 | + /// release -- there is nothing to undo about a monitoring level, which is | ||
| 2680 | + /// why this writes live and keeps no gesture state beyond the flag. | ||
| 2681 | + fn drag_volume(&mut self, x: Pixels, cx: &mut Context<Self>) { | ||
| 2682 | + let along = frac_along(x, self.volume_bar.get()); | ||
| 2683 | + self.set_volume(|volume| volume.set_along(along), cx); | ||
| 2684 | + } | ||
| 2685 | + | ||
| 2521 | fn toggle_or_restart(&mut self, cx: &mut Context<Self>) { | 2686 | fn toggle_or_restart(&mut self, cx: &mut Context<Self>) { |
| 2522 | if self.exporting().is_some() { | 2687 | if self.exporting().is_some() { |
| 2523 | return; | 2688 | return; |
| 2524 | } | 2689 | } |
| 2690 | + // Nothing to play is a message, not a transport state. An empty | ||
| 2691 | + // timeline is `done` from its one black frame onward, so the restart | ||
| 2692 | + // below would start a clock against a zero-length timeline -- and it is | ||
| 2693 | + // `done` again by the next repaint, so no later press could ever stop | ||
| 2694 | + // it: the button would read "Pause" and never pause. A delete can empty | ||
| 2695 | + // the timeline mid-play, and that press must still stop it. | ||
| 2696 | + if nothing_to_play(self.session.as_ref()) { | ||
| 2697 | + match self.session.as_mut().filter(|s| s.is_playing()) { | ||
| 2698 | + Some(session) => session.pause(), | ||
| 2699 | + None => self.notice = Some(NOTHING_TO_PLAY.into()), | ||
| 2700 | + } | ||
| 2701 | + cx.notify(); | ||
| 2702 | + return; | ||
| 2703 | + } | ||
| 2525 | if self.done { | 2704 | if self.done { |
| 2526 | self.seek(0., cx); | 2705 | self.seek(0., cx); |
| 2527 | if let Some(session) = &mut self.session { | 2706 | if let Some(session) = &mut self.session { |
| @@ -2749,9 +2928,19 @@ impl Render for Player { | |||
| 2749 | div() | 2928 | div() |
| 2750 | .track_focus(&self.focus) | 2929 | .track_focus(&self.focus) |
| 2751 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { | 2930 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { |
| 2752 | - // `is_held` filters auto-repeat, which would otherwise toggle | 2931 | + let key = event.keystroke.key.as_str(); |
| 2753 | - // playback -- or cut the timeline -- many times a second. | 2932 | + let ctrl = event.keystroke.modifiers.control; |
| 2754 | - if event.is_held { | 2933 | + // `is_held` is the auto-repeat, and a value is the one thing |
| 2934 | + // worth running on it: a held arrow on a card moves the slider | ||
| 2935 | + // it picked, and a held volume key runs the volume. Everything | ||
| 2936 | + // else is filtered exactly as it always was -- a repeat that | ||
| 2937 | + // toggled playback, or cut the timeline, many times a second is | ||
| 2938 | + // what this guard is for, and a row waiting for a stroke takes | ||
| 2939 | + // none of it either (it would bind the key, then fire what it | ||
| 2940 | + // just bound). See [`repeats`]. | ||
| 2941 | + if event.is_held | ||
| 2942 | + && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl)) | ||
| 2943 | + { | ||
| 2755 | return; | 2944 | return; |
| 2756 | } | 2945 | } |
| 2757 | // Any key retires the last message, whatever it was -- and owes | 2946 | // Any key retires the last message, whatever it was -- and owes |
| @@ -2761,7 +2950,6 @@ impl Render for Player { | |||
| 2761 | if this.notice.take().is_some() { | 2950 | if this.notice.take().is_some() { |
| 2762 | cx.notify(); | 2951 | cx.notify(); |
| 2763 | } | 2952 | } |
| 2764 | - let key = event.keystroke.key.as_str(); | ||
| 2765 | // A row is waiting for a stroke, and while it is, that stroke is | 2953 | // A row is waiting for a stroke, and while it is, that stroke is |
| 2766 | // data: it means the binding and nothing else, which is why this | 2954 | // data: it means the binding and nothing else, which is why this |
| 2767 | // answers before the export guard and before the keymap is | 2955 | // answers before the export guard and before the keymap is |
| @@ -2770,7 +2958,7 @@ impl Render for Player { | |||
| 2770 | if key == ESCAPE { | 2958 | if key == ESCAPE { |
| 2771 | this.rebinding = None; | 2959 | this.rebinding = None; |
| 2772 | } else if !is_bare_modifier(key) { | 2960 | } else if !is_bare_modifier(key) { |
| 2773 | - this.capture(action, key, event.keystroke.modifiers.control); | 2961 | + this.capture(action, key, ctrl); |
| 2774 | } | 2962 | } |
| 2775 | cx.notify(); | 2963 | cx.notify(); |
| 2776 | return; | 2964 | return; |
| @@ -2779,7 +2967,7 @@ impl Render for Player { | |||
| 2779 | // control modifier set (the control code is mapped back), which | 2967 | // control modifier set (the control code is mapped back), which |
| 2780 | // is why the keymap is keyed on the pair and never on the key | 2968 | // is why the keymap is keyed on the pair and never on the key |
| 2781 | // alone. | 2969 | // alone. |
| 2782 | - let action = this.keymap.lookup(key, event.keystroke.modifiers.control); | 2970 | + let action = this.keymap.lookup(key, ctrl); |
| 2783 | // An export is reading the edit list every other action here | 2971 | // An export is reading the edit list every other action here |
| 2784 | // would change, so cancelling is the only one that means | 2972 | // would change, so cancelling is the only one that means |
| 2785 | // anything until it is over. | 2973 | // anything until it is over. |
| @@ -3031,6 +3219,16 @@ impl Render for Player { | |||
| 3031 | } | 3219 | } |
| 3032 | return; | 3220 | return; |
| 3033 | } | 3221 | } |
| 3222 | + // The volume slider, the same live writes: what the hand is on | ||
| 3223 | + // is what the speakers are doing, and there is nothing to undo. | ||
| 3224 | + if this.volume_dragging { | ||
| 3225 | + if event.pressed_button == Some(MouseButton::Left) { | ||
| 3226 | + this.drag_volume(event.position.x, cx); | ||
| 3227 | + } else { | ||
| 3228 | + this.volume_dragging = false; | ||
| 3229 | + } | ||
| 3230 | + return; | ||
| 3231 | + } | ||
| 3034 | if !this.scrubbing { | 3232 | if !this.scrubbing { |
| 3035 | return; | 3233 | return; |
| 3036 | } | 3234 | } |
| @@ -3071,6 +3269,10 @@ impl Render for Player { | |||
| 3071 | this.drag_speed(event.position.x, false, cx); | 3269 | this.drag_speed(event.position.x, false, cx); |
| 3072 | return; | 3270 | return; |
| 3073 | } | 3271 | } |
| 3272 | + if std::mem::take(&mut this.volume_dragging) { | ||
| 3273 | + this.drag_volume(event.position.x, cx); | ||
| 3274 | + return; | ||
| 3275 | + } | ||
| 3074 | if std::mem::take(&mut this.scrubbing) { | 3276 | if std::mem::take(&mut this.scrubbing) { |
| 3075 | this.scrub_to(event.position.x, true, cx); | 3277 | this.scrub_to(event.position.x, true, cx); |
| 3076 | } | 3278 | } |
| @@ -3493,8 +3695,17 @@ impl Player { | |||
| 3493 | "transport", | 3695 | "transport", |
| 3494 | Some(transport_glyph(playing).into_any_element()), | 3696 | Some(transport_glyph(playing).into_any_element()), |
| 3495 | if playing { "Pause" } else { "Play" }, | 3697 | if playing { "Pause" } else { "Play" }, |
| 3496 | - key(ActionId::Play), | 3698 | + if nothing_to_play(self.session.as_ref()) && !playing { |
| 3497 | - live, | 3699 | + format!("{} — put a clip on a lane first", key(ActionId::Play)) |
| 3700 | + } else { | ||
| 3701 | + key(ActionId::Play) | ||
| 3702 | + }, | ||
| 3703 | + // An empty timeline has nothing to play, so the button | ||
| 3704 | + // says so by being dim rather than by starting a clock | ||
| 3705 | + // against nothing (the key press answers with the | ||
| 3706 | + // notice). Still live while it *is* playing: a delete | ||
| 3707 | + // can empty the timeline mid-play and that has to stop. | ||
| 3708 | + live && (playing || !nothing_to_play(self.session.as_ref())), | ||
| 3498 | cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), | 3709 | cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), |
| 3499 | )) | 3710 | )) |
| 3500 | .child(separator()) | 3711 | .child(separator()) |
| @@ -3569,6 +3780,15 @@ impl Player { | |||
| 3569 | this.set_volume(|volume| volume.muted = !volume.muted, cx) | 3780 | this.set_volume(|volume| volume.muted = !volume.muted, cx) |
| 3570 | }), | 3781 | }), |
| 3571 | )) | 3782 | )) |
| 3783 | + // The level itself, to drag. The button beside it stays the | ||
| 3784 | + // mute -- one gesture each -- and the label above is what | ||
| 3785 | + // this writes, live, so the number follows the hand. | ||
| 3786 | + .child(volume_slider( | ||
| 3787 | + self.volume, | ||
| 3788 | + self.volume_bar.clone(), | ||
| 3789 | + live, | ||
| 3790 | + cx, | ||
| 3791 | + )) | ||
| 3572 | .child(separator()) | 3792 | .child(separator()) |
| 3573 | // Import is not here: it belongs to the media list it adds | 3793 | // Import is not here: it belongs to the media list it adds |
| 3574 | // to, and two doors into one action is a question about | 3794 | // to, and two doors into one action is a question about |
| @@ -4679,9 +4899,19 @@ impl Player { | |||
| 4679 | fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | 4899 | fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { |
| 4680 | let (lane, idx) = self.silence_open?; | 4900 | let (lane, idx) = self.silence_open?; |
| 4681 | let cfg = self.silence; | 4901 | let cfg = self.silence; |
| 4902 | + // The unit is a label, never a conversion: the threshold is a level | ||
| 4903 | + // below full scale whichever of the two the row says (`silence_dbfs`). | ||
| 4904 | + let unit = match self.silence_dbfs { | ||
| 4905 | + true => "dBFS", | ||
| 4906 | + false => "dB", | ||
| 4907 | + }; | ||
| 4682 | let rows = [ | 4908 | let rows = [ |
| 4683 | ("Apply to", self.silence_scope.label(&self.silence_lanes())), | 4909 | ("Apply to", self.silence_scope.label(&self.silence_lanes())), |
| 4684 | - ("Silence is under", format!("{:.0} dBFS", cfg.threshold_db)), | 4910 | + ( |
| 4911 | + "Silence is under", | ||
| 4912 | + format!("{:.0} {unit}", cfg.threshold_db), | ||
| 4913 | + ), | ||
| 4914 | + ("Level read in", format!("{unit} (0 = full scale)")), | ||
| 4685 | ( | 4915 | ( |
| 4686 | "Forgive quiet shorter than", | 4916 | "Forgive quiet shorter than", |
| 4687 | format!("{:.2} s", cfg.min_silence), | 4917 | format!("{:.2} s", cfg.min_silence), |
| @@ -4780,7 +5010,7 @@ impl Player { | |||
| 4780 | .text_size(px(11.)) | 5010 | .text_size(px(11.)) |
| 4781 | .text_color(rgb(INK_DIM)) | 5011 | .text_color(rgb(INK_DIM)) |
| 4782 | .child( | 5012 | .child( |
| 4783 | - "↑↓ picks a setting, ←→ moves it — the marks on the lane are what would go; esc closes", | 5013 | + "↑↓ picks a setting, ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes", |
| 4784 | ), | 5014 | ), |
| 4785 | ) | 5015 | ) |
| 4786 | .children(rows) | 5016 | .children(rows) |
| @@ -5208,6 +5438,12 @@ impl Player { | |||
| 5208 | }); | 5438 | }); |
| 5209 | let name = lane.label(); | 5439 | let name = lane.label(); |
| 5210 | let row_id: SharedString = format!("{name}-clip").into(); | 5440 | let row_id: SharedString = format!("{name}-clip").into(); |
| 5441 | + let remove_id: SharedString = format!("{name}-remove").into(); | ||
| 5442 | + let remove_tip: SharedString = format!( | ||
| 5443 | + "Remove {name} — it must be empty first, and {} brings it back", | ||
| 5444 | + self.keymap.display(ActionId::Undo) | ||
| 5445 | + ) | ||
| 5446 | + .into(); | ||
| 5211 | let sources = self | 5447 | let sources = self |
| 5212 | .session | 5448 | .session |
| 5213 | .as_ref() | 5449 | .as_ref() |
| @@ -5237,13 +5473,37 @@ impl Player { | |||
| 5237 | .w(px(HEADER_W)) | 5473 | .w(px(HEADER_W)) |
| 5238 | .h_full() | 5474 | .h_full() |
| 5239 | .flex() | 5475 | .flex() |
| 5476 | + .flex_col() | ||
| 5240 | .items_center() | 5477 | .items_center() |
| 5241 | .justify_center() | 5478 | .justify_center() |
| 5242 | .rounded(px(3.)) | 5479 | .rounded(px(3.)) |
| 5243 | .bg(rgb(SURFACE)) | 5480 | .bg(rgb(SURFACE)) |
| 5244 | .text_size(px(11.)) | 5481 | .text_size(px(11.)) |
| 5245 | .text_color(rgb(INK_DIM)) | 5482 | .text_color(rgb(INK_DIM)) |
| 5246 | - .child(name), | 5483 | + .child(div().flex_1().flex().items_center().child(name)) |
| 5484 | + // The one thing a header does: take this track away again. | ||
| 5485 | + // A `HIT_MIN` target rather than a glyph-sized one, and it | ||
| 5486 | + // stays put on a track holding clips instead of hiding -- | ||
| 5487 | + // the refusal names them, and a control that vanishes | ||
| 5488 | + // teaches nothing. | ||
| 5489 | + .child( | ||
| 5490 | + div() | ||
| 5491 | + .id(remove_id) | ||
| 5492 | + .flex_none() | ||
| 5493 | + .w_full() | ||
| 5494 | + .h(px(HIT_MIN)) | ||
| 5495 | + .flex() | ||
| 5496 | + .items_center() | ||
| 5497 | + .justify_center() | ||
| 5498 | + .rounded(px(3.)) | ||
| 5499 | + .cursor_pointer() | ||
| 5500 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5501 | + .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) | ||
| 5502 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 5503 | + this.remove_lane(lane, cx) | ||
| 5504 | + })) | ||
| 5505 | + .child("×"), | ||
| 5506 | + ), | ||
| 5247 | ) | 5507 | ) |
| 5248 | .child( | 5508 | .child( |
| 5249 | // Clips are placed at their own start rather than queued edge | 5509 | // Clips are placed at their own start rather than queued edge |
| @@ -6273,6 +6533,39 @@ fn cancels_export(key: &str, action: Option<ActionId>) -> bool { | |||
| 6273 | key == ESCAPE || action == Some(ActionId::CancelExport) | 6533 | key == ESCAPE || action == Some(ActionId::CancelExport) |
| 6274 | } | 6534 | } |
| 6275 | 6535 | ||
| 6536 | +/// Where a held key would land, which is the whole of what auto-repeat has to | ||
| 6537 | +/// know. [`Player::repeat_scope`] answers it from the same state the handler | ||
| 6538 | +/// walks below itself. | ||
| 6539 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
| 6540 | +enum Repeat { | ||
| 6541 | + /// A card with values in it owns the keyboard: equalizer, colour, speed or | ||
| 6542 | + /// silence. Its arrows are sliders. | ||
| 6543 | + Card, | ||
| 6544 | + /// Nobody does, so the keymap answers -- and only one pair of its actions | ||
| 6545 | + /// is a value being moved rather than a thing being done once. | ||
| 6546 | + Keymap, | ||
| 6547 | + /// A stroke is being captured, an export is running, or an overlay with no | ||
| 6548 | + /// value in it is up. Nothing there is worth a repeat. | ||
| 6549 | + Nothing, | ||
| 6550 | +} | ||
| 6551 | + | ||
| 6552 | +/// Whether a *held* stroke means it again. One press is always one action; a | ||
| 6553 | +/// hold is only ever a value running, so this is what tells the two apart. | ||
| 6554 | +/// | ||
| 6555 | +/// The cards' arrows, because that is what every one of them moves a slider | ||
| 6556 | +/// with -- and only the arrows, so the equalizer's `r` cannot flatten five | ||
| 6557 | +/// bands forty times a second and the silence card's `enter` cannot cut forty | ||
| 6558 | +/// places again on the next tick. Outside a card the volume pair and nothing | ||
| 6559 | +/// else: play, cut, delete, save, export and every other binding is a one-shot, | ||
| 6560 | +/// exactly as it was when the handler filtered every held key alike. | ||
| 6561 | +fn repeats(scope: Repeat, key: &str, action: Option<ActionId>) -> bool { | ||
| 6562 | + match scope { | ||
| 6563 | + Repeat::Card => matches!(key, "up" | "down" | "left" | "right"), | ||
| 6564 | + Repeat::Keymap => matches!(action, Some(ActionId::VolumeUp | ActionId::VolumeDown)), | ||
| 6565 | + Repeat::Nothing => false, | ||
| 6566 | + } | ||
| 6567 | +} | ||
| 6568 | + | ||
| 6276 | /// The keys that are only ever half a chord. gpui delivers a lone modifier | 6569 | /// The keys that are only ever half a chord. gpui delivers a lone modifier |
| 6277 | /// press as a keystroke of its own, and taking one as a binding would leave an | 6570 | /// press as a keystroke of its own, and taking one as a binding would leave an |
| 6278 | /// action that fires the moment the user reaches for any chord that uses it -- | 6571 | /// action that fires the moment the user reaches for any chord that uses it -- |
| @@ -6571,6 +6864,59 @@ fn control( | |||
| 6571 | }) | 6864 | }) |
| 6572 | } | 6865 | } |
| 6573 | 6866 | ||
| 6867 | +/// The monitoring level as something to drag: 4 px of bar to look at and the | ||
| 6868 | +/// whole control's height to hit (WCAG 2.5.8), the split the speed bar and the | ||
| 6869 | +/// colour sliders both make. Only the level -- mute is the button beside it, so | ||
| 6870 | +/// a muted slider still shows what unmuting comes back to, drawn dim. | ||
| 6871 | +/// | ||
| 6872 | +/// Dimmed and inert without a timeline, like every other control that would | ||
| 6873 | +/// have nothing to act on. | ||
| 6874 | +fn volume_slider( | ||
| 6875 | + volume: Volume, | ||
| 6876 | + bar: Rc<Cell<Bounds<Pixels>>>, | ||
| 6877 | + enabled: bool, | ||
| 6878 | + cx: &mut Context<Player>, | ||
| 6879 | +) -> impl IntoElement { | ||
| 6880 | + div() | ||
| 6881 | + .id("volume-bar") | ||
| 6882 | + .relative() | ||
| 6883 | + .flex_none() | ||
| 6884 | + .w(px(VOLUME_W)) | ||
| 6885 | + .h(px(CONTROL_H)) | ||
| 6886 | + .flex() | ||
| 6887 | + .items_center() | ||
| 6888 | + .tooltip(|_, cx| { | ||
| 6889 | + cx.new(|_| Tip("Volume — drag to set the level; the button mutes".into())) | ||
| 6890 | + .into() | ||
| 6891 | + }) | ||
| 6892 | + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | ||
| 6893 | + .when(enabled, |d| { | ||
| 6894 | + d.cursor_pointer() | ||
| 6895 | + .on_mouse_down( | ||
| 6896 | + MouseButton::Left, | ||
| 6897 | + cx.listener(|this, event: &MouseDownEvent, _, cx| { | ||
| 6898 | + this.volume_dragging = true; | ||
| 6899 | + this.drag_volume(event.position.x, cx); | ||
| 6900 | + }), | ||
| 6901 | + ) | ||
| 6902 | + .child(bounds_probe(bar)) | ||
| 6903 | + }) | ||
| 6904 | + .child( | ||
| 6905 | + div() | ||
| 6906 | + .w_full() | ||
| 6907 | + .h(px(4.)) | ||
| 6908 | + .rounded(px(2.)) | ||
| 6909 | + .bg(rgb(SURFACE)) | ||
| 6910 | + .child( | ||
| 6911 | + div() | ||
| 6912 | + .h_full() | ||
| 6913 | + .w(relative(volume.along())) | ||
| 6914 | + .rounded(px(2.)) | ||
| 6915 | + .bg(rgb(if volume.muted { INK_DIM } else { ACCENT })), | ||
| 6916 | + ), | ||
| 6917 | + ) | ||
| 6918 | +} | ||
| 6919 | + | ||
| 6574 | /// The line between two groups of buttons. | 6920 | /// The line between two groups of buttons. |
| 6575 | fn separator() -> impl IntoElement { | 6921 | fn separator() -> impl IntoElement { |
| 6576 | div() | 6922 | div() |
| @@ -6984,14 +7330,15 @@ mod tests { | |||
| 6984 | LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, | 7330 | LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, |
| 6985 | MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, | 7331 | MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, |
| 6986 | SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, | 7332 | SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, |
| 6987 | - Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add, cancels_export, | 7333 | + VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add, |
| 6988 | - color_snap, envelope, eq_spectrum, eq_x, eq_y, export_path, export_settings, format_key, | 7334 | + cancels_export, color_snap, envelope, eq_spectrum, eq_x, eq_y, export_path, |
| 6989 | - format_line, format_refusal, frac_along, frac_down, frame_at, histogram, is_bare_modifier, | 7335 | + export_settings, format_key, format_line, format_refusal, frac_along, frac_down, frame_at, |
| 6990 | - is_project, keymap, lanes_h, marked, menu_at, normalise, panel_h, project_path, push_digit, | 7336 | + histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, menu_at, normalise, |
| 6991 | - retarget, scrub_due, show_label, silence_rate, source_tint, span_partner, speed_at, | 7337 | + nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, show_label, |
| 6992 | - start_frac, timecode, unseen_paths, unseen_sources, whole_take, width_frac, window_title, | 7338 | + silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths, |
| 7339 | + unseen_sources, whole_take, width_frac, window_title, | ||
| 6993 | }; | 7340 | }; |
| 6994 | - use super::{LaneKind, file_name, file_uri, library_rows, unscannable}; | 7341 | + use super::{LaneKind, Repeat, file_name, file_uri, library_rows, repeats, unscannable}; |
| 6995 | 7342 | ||
| 6996 | /// What the file manager is handed: the parts a path keeps as they are, and | 7343 | /// What the file manager is handed: the parts a path keeps as they are, and |
| 6997 | /// the ones the bus would otherwise read as something else. | 7344 | /// the ones the bus would otherwise read as something else. |
| @@ -8579,11 +8926,47 @@ mod tests { | |||
| 8579 | ); | 8926 | ); |
| 8580 | } | 8927 | } |
| 8581 | 8928 | ||
| 8929 | + /// The hold gate: a value runs, everything else still means one press one | ||
| 8930 | + /// action -- which is the whole invariant the blanket `is_held` filter used | ||
| 8931 | + /// to carry on its own. | ||
| 8932 | + #[test] | ||
| 8933 | + fn a_held_key_moves_a_value_and_nothing_else() { | ||
| 8934 | + use keymap::ActionId; | ||
| 8935 | + // A card's four arrows, whichever card it is. | ||
| 8936 | + for key in ["up", "down", "left", "right"] { | ||
| 8937 | + assert!(repeats(Repeat::Card, key, None), "{key} on a card"); | ||
| 8938 | + } | ||
| 8939 | + // The card's own one-shots: flatten every band, cut forty places, play | ||
| 8940 | + // them fast, close. None of them on a hold. | ||
| 8941 | + for key in ["r", "enter", "f", "1", "escape"] { | ||
| 8942 | + assert!(!repeats(Repeat::Card, key, None), "{key} on a card"); | ||
| 8943 | + } | ||
| 8944 | + // Outside a card the keymap answers, and only the volume pair is a | ||
| 8945 | + // value being moved. | ||
| 8946 | + assert!(repeats(Repeat::Keymap, "up", Some(ActionId::VolumeUp))); | ||
| 8947 | + assert!(repeats(Repeat::Keymap, "down", Some(ActionId::VolumeDown))); | ||
| 8948 | + for action in ActionId::ALL { | ||
| 8949 | + let held = repeats(Repeat::Keymap, "k", Some(action)); | ||
| 8950 | + assert_eq!( | ||
| 8951 | + held, | ||
| 8952 | + matches!(action, ActionId::VolumeUp | ActionId::VolumeDown), | ||
| 8953 | + "{action:?} on a hold" | ||
| 8954 | + ); | ||
| 8955 | + } | ||
| 8956 | + // An arrow with nothing bound to it moves nothing on the timeline. | ||
| 8957 | + assert!(!repeats(Repeat::Keymap, "left", None)); | ||
| 8958 | + // And a stroke being captured, an export, or the overlays: nothing at | ||
| 8959 | + // all, or the hold would bind a key and then fire what it just bound. | ||
| 8960 | + for key in ["up", "left", "escape", "5"] { | ||
| 8961 | + assert!(!repeats(Repeat::Nothing, key, Some(ActionId::VolumeUp))); | ||
| 8962 | + } | ||
| 8963 | + } | ||
| 8964 | + | ||
| 8582 | #[test] | 8965 | #[test] |
| 8583 | fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() { | 8966 | fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() { |
| 8584 | // The same 640x360 floor, and this card starts below the header: a | 8967 | // The same 640x360 floor, and this card starts below the header: a |
| 8585 | - // title and a hint over its five rows, the count line and the two | 8968 | + // title and a hint over its [`SILENCE_ROWS`] rows, the count line and |
| 8586 | - // buttons. | 8969 | + // the two buttons. |
| 8587 | let (title, hint, count) = (17., 17., 17.); | 8970 | let (title, hint, count) = (17., 17., 17.); |
| 8588 | let gaps = 6. * 5.; | 8971 | let gaps = 6. * 5.; |
| 8589 | let padding = 24.; | 8972 | let padding = 24.; |
| @@ -8914,6 +9297,116 @@ mod tests { | |||
| 8914 | assert_eq!(source_tint(9), source_tint(1)); | 9297 | assert_eq!(source_tint(9), source_tint(1)); |
| 8915 | assert_eq!(source_tint(usize::MAX), SOURCE_TINTS[usize::MAX % 4]); | 9298 | assert_eq!(source_tint(usize::MAX), SOURCE_TINTS[usize::MAX % 4]); |
| 8916 | } | 9299 | } |
| 9300 | + | ||
| 9301 | + /// The bug: an empty timeline is end-of-stream from its one black frame | ||
| 9302 | + /// onward, so the pump had `done` set before anything was ever pressed -- | ||
| 9303 | + /// and the transport's restart branch read that as "played out, start from | ||
| 9304 | + /// the top". It started a clock against a zero-length timeline, which was | ||
| 9305 | + /// `done` again by the next repaint, so every further press restarted it | ||
| 9306 | + /// too: the button read "Pause" and no press of it ever paused. | ||
| 9307 | + /// | ||
| 9308 | + /// What holds it now is one predicate, checked here against real sessions | ||
| 9309 | + /// on both sides -- the emptied one refuses, a timeline with clips on it | ||
| 9310 | + /// does not. | ||
| 9311 | + #[test] | ||
| 9312 | + fn an_empty_timeline_has_nothing_to_play() { | ||
| 9313 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 9314 | + // Silent like the engine suite: this opens the real device. | ||
| 9315 | + session.set_gain(0.0); | ||
| 9316 | + // A timeline with clips on it plays, and always did: the guard must not | ||
| 9317 | + // touch that side. | ||
| 9318 | + assert!(!session.is_empty()); | ||
| 9319 | + assert!(!nothing_to_play(Some(&session))); | ||
| 9320 | + | ||
| 9321 | + // Every clip taken off, which is a state and not a failure. | ||
| 9322 | + while session.delete_clip(Lane::V1, 0) {} | ||
| 9323 | + while session.delete_clip(Lane::A1, 0) {} | ||
| 9324 | + assert!(session.is_empty(), "the timeline is empty"); | ||
| 9325 | + assert_eq!(session.timeline_duration(), 0.0); | ||
| 9326 | + | ||
| 9327 | + // What the pump does every render, and what set `done` before the fix: | ||
| 9328 | + // the black frame goes by and the session is at its end at once. | ||
| 9329 | + for _ in 0..40 { | ||
| 9330 | + while session.try_frame().is_some() {} | ||
| 9331 | + std::thread::sleep(Duration::from_millis(10)); | ||
| 9332 | + } | ||
| 9333 | + assert!(session.is_eos(), "an empty timeline is done before it starts"); | ||
| 9334 | + | ||
| 9335 | + // So the press is refused rather than sent down the restart branch -- | ||
| 9336 | + // and with no session at all it is the same refusal. | ||
| 9337 | + assert!(nothing_to_play(Some(&session))); | ||
| 9338 | + assert!(nothing_to_play(None)); | ||
| 9339 | + assert!(!session.is_playing(), "and nothing was started"); | ||
| 9340 | + } | ||
| 9341 | + | ||
| 9342 | + /// The slider writes the same numbers the keys do, and mute is not one of | ||
| 9343 | + /// them: dragging while muted picks the level unmuting comes back to. | ||
| 9344 | + #[test] | ||
| 9345 | + fn the_slider_lands_on_the_grid_the_keys_move_on() { | ||
| 9346 | + let mut volume = Volume::default(); | ||
| 9347 | + // Both ends exactly, and clamped past them. | ||
| 9348 | + volume.set_along(0.); | ||
| 9349 | + assert_eq!(volume.gain(), 0.0); | ||
| 9350 | + assert_eq!(volume.label(), "Vol 0%"); | ||
| 9351 | + volume.set_along(1.5); | ||
| 9352 | + assert_eq!(volume.gain(), 1.0); | ||
| 9353 | + assert_eq!(volume.along(), 1.0); | ||
| 9354 | + | ||
| 9355 | + // Halfway is 50%, and a key press from there is 5% -- the same step | ||
| 9356 | + // count as before, on a finer grid. | ||
| 9357 | + volume.set_along(0.5); | ||
| 9358 | + assert_eq!(volume.label(), "Vol 50%"); | ||
| 9359 | + volume.step(true); | ||
| 9360 | + assert_eq!(volume.label(), "Vol 55%"); | ||
| 9361 | + volume.step(false); | ||
| 9362 | + assert_eq!(volume.gain(), 0.5); | ||
| 9363 | + | ||
| 9364 | + // A number no step lands on comes back as the nearest one, so the label | ||
| 9365 | + // and the fill are the same value the device was handed. | ||
| 9366 | + volume.set_along(0.333); | ||
| 9367 | + assert_eq!(volume.label(), "Vol 33%"); | ||
| 9368 | + assert_eq!(volume.along(), 0.33); | ||
| 9369 | + | ||
| 9370 | + // Muted, the drag moves the level and nothing comes out. | ||
| 9371 | + volume.muted = true; | ||
| 9372 | + volume.set_along(0.8); | ||
| 9373 | + assert_eq!(volume.gain(), 0.0); | ||
| 9374 | + assert_eq!(volume.label(), "Muted 80%"); | ||
| 9375 | + volume.muted = false; | ||
| 9376 | + assert_eq!(volume.gain(), 0.8); | ||
| 9377 | + } | ||
| 9378 | + | ||
| 9379 | + /// The slider lands where it paints: the arithmetic `Player::drag_volume` | ||
| 9380 | + /// runs over the bar's own painted width, which is the one thing a test of | ||
| 9381 | + /// it can share without re-deriving it. | ||
| 9382 | + #[test] | ||
| 9383 | + fn the_volume_slider_lands_where_it_paints() { | ||
| 9384 | + let bar = Bounds { | ||
| 9385 | + origin: point(px(420.), px(508.)), | ||
| 9386 | + size: size(px(VOLUME_W), px(CONTROL_H)), | ||
| 9387 | + }; | ||
| 9388 | + let at = |x: f32| { | ||
| 9389 | + let mut volume = Volume::default(); | ||
| 9390 | + volume.set_along(frac_along(px(x), bar)); | ||
| 9391 | + volume | ||
| 9392 | + }; | ||
| 9393 | + assert_eq!(at(420.).gain(), 0.0, "the left end is silence"); | ||
| 9394 | + assert_eq!(at(420. + VOLUME_W).gain(), 1.0, "the right end is full"); | ||
| 9395 | + assert_eq!(at(-4000.).gain(), 0.0, "off the left clamps"); | ||
| 9396 | + assert_eq!(at(9999.).gain(), 1.0, "off the right clamps"); | ||
| 9397 | + // Every pixel along it: a level the keys could also reach, painted back | ||
| 9398 | + // where the hand pressed to within the half step the rounding costs. | ||
| 9399 | + for step in 0..=(VOLUME_W as u32) { | ||
| 9400 | + let along = step as f32 / VOLUME_W; | ||
| 9401 | + let volume = at(420. + along * VOLUME_W); | ||
| 9402 | + let painted = volume.along(); | ||
| 9403 | + let slack = 0.5 / f32::from(Volume::MAX_STEPS) + 1e-4; | ||
| 9404 | + assert!( | ||
| 9405 | + (painted - along).abs() <= slack, | ||
| 9406 | + "pressed at {along}, paints at {painted}" | ||
| 9407 | + ); | ||
| 9408 | + } | ||
| 9409 | + } | ||
| 8917 | } | 9410 | } |
| 8918 | 9411 | ||
| 8919 | fn main() { | 9412 | fn main() { |
| @@ -9034,6 +9527,8 @@ fn main() { | |||
| 9034 | // Full and unmuted, which is what the session it was just | 9527 | // Full and unmuted, which is what the session it was just |
| 9035 | // handed is already set to: nothing to push at startup. | 9528 | // handed is already set to: nothing to push at startup. |
| 9036 | volume: Volume::default(), | 9529 | volume: Volume::default(), |
| 9530 | + volume_bar: Rc::default(), | ||
| 9531 | + volume_dragging: false, | ||
| 9037 | // Only ever used with a timeline; 30 keeps the empty | 9532 | // Only ever used with a timeline; 30 keeps the empty |
| 9038 | // timecode reading in frames rather than in NaN. | 9533 | // timecode reading in frames rather than in NaN. |
| 9039 | fps: meta.map_or(30., |meta| meta.frame_rate), | 9534 | fps: meta.map_or(30., |meta| meta.frame_rate), |
| @@ -9082,6 +9577,9 @@ fn main() { | |||
| 9082 | // one a person can widen on purpose. | 9577 | // one a person can widen on purpose. |
| 9083 | silence_scope: Scope::Take, | 9578 | silence_scope: Scope::Take, |
| 9084 | silence_field: 0, | 9579 | silence_field: 0, |
| 9580 | + // The reference named, which is what the card said before | ||
| 9581 | + // there was a choice about it. | ||
| 9582 | + silence_dbfs: true, | ||
| 9085 | silence_marks: Vec::new(), | 9583 | silence_marks: Vec::new(), |
| 9086 | silence_levels: None, | 9584 | silence_levels: None, |
| 9087 | color_open: None, | 9585 | color_open: None, |
crates/engine/src/playback.rsmodified+7 -0
| @@ -901,6 +901,13 @@ impl PlaybackSession { | |||
| 901 | self.project.add_lane(kind) | 901 | self.project.add_lane(kind) |
| 902 | } | 902 | } |
| 903 | 903 | ||
| 904 | + /// Drops that empty lane again, in [`Project::remove_lane`]'s words when it | ||
| 905 | + /// refuses. One undo step, and no reseek for the same reason the add needs | ||
| 906 | + /// none: an empty lane was playing nothing. | ||
| 907 | + pub fn remove_lane(&mut self, lane: Lane) -> crate::Result<()> { | ||
| 908 | + self.project.remove_lane(lane) | ||
| 909 | + } | ||
| 910 | + | ||
| 904 | /// Splits every lane at `timeline_secs`, so the two sides become two | 911 | /// Splits every lane at `timeline_secs`, so the two sides become two |
| 905 | /// groups. Metadata only: a split never changes the timeline->source | 912 | /// groups. Metadata only: a split never changes the timeline->source |
| 906 | /// mapping, so the running decoder stays correct and playback does not | 913 | /// mapping, so the running decoder stays correct and playback does not |
crates/engine/src/project.rsmodified+197 -3
| @@ -666,6 +666,67 @@ impl Project { | |||
| 666 | Lane::new(kind, self.lane_count(kind) - 1) | 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 | /// Where `lane` sits in [`Project::lanes`], or `None` for a lane that is | 730 | /// Where `lane` sits in [`Project::lanes`], or `None` for a lane that is |
| 670 | /// not there. The one place a handle becomes a position. | 731 | /// not there. The one place a handle becomes a position. |
| 671 | fn index(&self, lane: Lane) -> Option<usize> { | 732 | fn index(&self, lane: Lane) -> Option<usize> { |
| @@ -1658,8 +1719,19 @@ impl Project { | |||
| 1658 | } | 1719 | } |
| 1659 | self.snapshot(); | 1720 | self.snapshot(); |
| 1660 | for (&(l, i), keep) in members.iter().zip(fitted) { | 1721 | for (&(l, i), keep) in members.iter().zip(fitted) { |
| 1722 | + let still = self.is_still(&self.lanes[l].clips[i]); | ||
| 1661 | let c = &mut self.lanes[l].clips[i]; | 1723 | let c = &mut self.lanes[l].clips[i]; |
| 1662 | match edge { | 1724 | match edge { |
| 1725 | + // A still has no earlier frame to walk an in-point back to -- | ||
| 1726 | + // every frame of it is the same picture -- so its head grows | ||
| 1727 | + // *forward*: the range it plays is however long the new room | ||
| 1728 | + // is, anchored at the source's frame 0. Bounded by `lo`, which | ||
| 1729 | + // is where the cap in `source_frames` is applied. | ||
| 1730 | + Edge::Start if still => { | ||
| 1731 | + c.in_frame = 0; | ||
| 1732 | + c.out_frame = keep; | ||
| 1733 | + c.start = to; | ||
| 1734 | + } | ||
| 1663 | Edge::Start => { | 1735 | Edge::Start => { |
| 1664 | // Non-negative by `lo`, which is what keeps the in-point on | 1736 | // Non-negative by `lo`, which is what keeps the in-point on |
| 1665 | // the source. | 1737 | // the source. |
| @@ -1700,9 +1772,24 @@ impl Project { | |||
| 1700 | // head than the timeline has room for -- a ripple delete | 1772 | // head than the timeline has room for -- a ripple delete |
| 1701 | // slides a clip back to frame 0 with its in-point wherever | 1773 | // slides a clip back to frame 0 with its in-point wherever |
| 1702 | // the cut left it -- and frame 0 is the other wall. | 1774 | // the cut left it -- and frame 0 is the other wall. |
| 1703 | - c.start | 1775 | + // |
| 1704 | - .saturating_sub(c.speed.room(c.in_frame)) | 1776 | + // A still is measured from its *tail* instead: it has no |
| 1705 | - .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), | 1777 | + // in-point worth the name (every frame the same picture), so |
| 1778 | + // its head reaches exactly as far as its tail does -- out to | ||
| 1779 | + // the length the caller's table gives it, whole. Measured | ||
| 1780 | + // from the in-point it would have no head room at all, which | ||
| 1781 | + // is a placed picture whose left edge cannot be dragged out. | ||
| 1782 | + // No entry in the table means no growth, as it does at the | ||
| 1783 | + // other end. | ||
| 1784 | + if self.is_still(&c) { | ||
| 1785 | + c.end().saturating_sub( | ||
| 1786 | + c.speed | ||
| 1787 | + .room(source_frames.get(c.source).copied().unwrap_or(c.len())), | ||
| 1788 | + ) | ||
| 1789 | + } else { | ||
| 1790 | + c.start.saturating_sub(c.speed.room(c.in_frame)) | ||
| 1791 | + } | ||
| 1792 | + .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), | ||
| 1706 | // One *frame of clip* always survives, and at a rate below | 1793 | // One *frame of clip* always survives, and at a rate below |
| 1707 | // real time one frame of clip is several frames of timeline | 1794 | // real time one frame of clip is several frames of timeline |
| 1708 | // ([`Speed::room`]): an edge dragged closer than that would | 1795 | // ([`Speed::room`]): an edge dragged closer than that would |
| @@ -1739,6 +1826,16 @@ impl Project { | |||
| 1739 | Some((lo, hi.max(lo))) | 1826 | Some((lo, hi.max(lo))) |
| 1740 | } | 1827 | } |
| 1741 | 1828 | ||
| 1829 | + /// Whether `clip` plays a still image ([`crate::is_image`]): a file whose | ||
| 1830 | + /// every frame is the same picture, so which frame of it a clip's in-point | ||
| 1831 | + /// names is not a question -- what [`Project::trim`] lets grow at either | ||
| 1832 | + /// end. `false` for a source that is not there. | ||
| 1833 | + fn is_still(&self, clip: &Clip) -> bool { | ||
| 1834 | + self.sources | ||
| 1835 | + .get(clip.source) | ||
| 1836 | + .is_some_and(|s| crate::is_image(&s.path)) | ||
| 1837 | + } | ||
| 1838 | + | ||
| 1742 | /// The clips that move as one with the clip at `idx` of `lane` -- itself and | 1839 | /// The clips that move as one with the clip at `idx` of `lane` -- itself and |
| 1743 | /// whatever carries its link on the other lanes -- as `(lane storage index, | 1840 | /// whatever carries its link on the other lanes -- as `(lane storage index, |
| 1744 | /// clip index)` pairs. `None` for an index that is not there. | 1841 | /// clip index)` pairs. `None` for an index that is not there. |
| @@ -3411,6 +3508,56 @@ mod tests { | |||
| 3411 | assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]); | 3508 | assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]); |
| 3412 | } | 3509 | } |
| 3413 | 3510 | ||
| 3511 | + /// A still is trimmed from its head exactly as it is from its tail: it has | ||
| 3512 | + /// no earlier frame to walk an in-point back to, so the wall is the length | ||
| 3513 | + /// the caller's table allows it, measured back from the tail. Measured from | ||
| 3514 | + /// the in-point -- which a placed picture has at 0 -- its left edge could | ||
| 3515 | + /// never be dragged outwards at all. | ||
| 3516 | + #[test] | ||
| 3517 | + fn a_stills_head_stretches_out_like_its_tail() { | ||
| 3518 | + const STILL: &str = "/nonexistent/card.png"; | ||
| 3519 | + /// What a still is held to, as `PlaybackSession` fills the table in. | ||
| 3520 | + const CAP: &[u32] = &[60]; | ||
| 3521 | + | ||
| 3522 | + let mut p = Project::single(STILL, 20); | ||
| 3523 | + assert!(p.lift(Lane::A1, 0), "a picture is silent"); | ||
| 3524 | + assert!(p.lift(Lane::V1, 0), "and this one is not at frame 0"); | ||
| 3525 | + assert!(p.place(Lane::V1, 100, clip(0, 0, 20, 0))); | ||
| 3526 | + | ||
| 3527 | + // A source with no entry in the table may not grow, here as at the tail. | ||
| 3528 | + assert_eq!( | ||
| 3529 | + p.trim_room(Lane::V1, 0, Edge::Start, &[]), | ||
| 3530 | + Some((100, 119)), | ||
| 3531 | + "a length nobody told us buys no head room" | ||
| 3532 | + ); | ||
| 3533 | + assert_eq!( | ||
| 3534 | + p.trim_room(Lane::V1, 0, Edge::Start, CAP), | ||
| 3535 | + Some((60, 119)), | ||
| 3536 | + "back to a whole cap's worth, one frame of clip surviving" | ||
| 3537 | + ); | ||
| 3538 | + assert!(p.trim(Lane::V1, 0, Edge::Start, 80, CAP)); | ||
| 3539 | + assert_eq!( | ||
| 3540 | + shape(&p)[0][0], | ||
| 3541 | + clip(80, 0, 40, 0), | ||
| 3542 | + "twenty frames longer, and still read from the source's first frame" | ||
| 3543 | + ); | ||
| 3544 | + // Past the cap is clamped, exactly as the tail is -- not refused. | ||
| 3545 | + assert!(p.trim(Lane::V1, 0, Edge::Start, 0, CAP)); | ||
| 3546 | + assert_eq!(shape(&p)[0][0], clip(60, 0, 60, 0), "a cap's worth, no more"); | ||
| 3547 | + // ...and the clip in front is the nearer wall of the two: no head trim | ||
| 3548 | + // may open an overlap. | ||
| 3549 | + assert!(p.trim(Lane::V1, 0, Edge::Start, 90, CAP)); | ||
| 3550 | + assert!(p.place(Lane::V1, 70, clip(0, 0, 15, 0))); | ||
| 3551 | + assert_eq!( | ||
| 3552 | + p.trim_room(Lane::V1, 1, Edge::Start, CAP), | ||
| 3553 | + Some((85, 119)), | ||
| 3554 | + "up to the neighbour's last frame and not over it" | ||
| 3555 | + ); | ||
| 3556 | + assert!(p.trim(Lane::V1, 1, Edge::Start, 0, CAP)); | ||
| 3557 | + assert_eq!(shape(&p)[0][1], clip(85, 0, 35, 0), "butted against it"); | ||
| 3558 | + assert!(sorted_disjoint(p.lane(Lane::V1)), "no overlap"); | ||
| 3559 | + } | ||
| 3560 | + | ||
| 3414 | /// Linked halves trim as one: a link is one span on however many lanes, so | 3561 | /// Linked halves trim as one: a link is one span on however many lanes, so |
| 3415 | /// the sound follows the picture's edge -- and the tightest wall of the two | 3562 | /// the sound follows the picture's edge -- and the tightest wall of the two |
| 3416 | /// is what stops both. | 3563 | /// is what stops both. |
| @@ -4697,6 +4844,53 @@ mod tests { | |||
| 4697 | assert_eq!(shape(&p), shape(&three())); | 4844 | assert_eq!(shape(&p), shape(&three())); |
| 4698 | } | 4845 | } |
| 4699 | 4846 | ||
| 4847 | + /// The add taken back: an empty lane comes off, a lane holding clips never | ||
| 4848 | + /// does (and says which clips), the last lane of a kind never does, the | ||
| 4849 | + /// lanes below the one that went move up an `ord`, and one undo puts it | ||
| 4850 | + /// back where it stood. | ||
| 4851 | + #[test] | ||
| 4852 | + fn an_empty_lane_comes_off_again() { | ||
| 4853 | + let mut p = three(); | ||
| 4854 | + let v2 = p.add_lane(LaneKind::Video); | ||
| 4855 | + let v3 = p.add_lane(LaneKind::Video); | ||
| 4856 | + assert!(p.place(v3, 0, clip(0, 0, 3, 0))); | ||
| 4857 | + let why = |r: crate::Result<()>| r.expect_err("refused").to_string(); | ||
| 4858 | + let history = p.history.len(); | ||
| 4859 | + | ||
| 4860 | + // The last lane of its kind stays: `V1`/`A1` are where an import and a | ||
| 4861 | + // paste land, and a project missing one would swallow half of a file | ||
| 4862 | + // dropped on it. | ||
| 4863 | + assert!(why(p.remove_lane(Lane::A1)).contains("only audio track")); | ||
| 4864 | + assert_eq!( | ||
| 4865 | + why(p.remove_lane(Lane::new(LaneKind::Video, 9))), | ||
| 4866 | + "there is no V10 to remove" | ||
| 4867 | + ); | ||
| 4868 | + | ||
| 4869 | + // A lane with clips on it refuses and names them: a track removal never | ||
| 4870 | + // deletes a take. | ||
| 4871 | + let refusal = why(p.remove_lane(v3)); | ||
| 4872 | + assert!(refusal.contains("V3 still holds"), "{refusal}"); | ||
| 4873 | + assert!(refusal.contains(FILE), "{refusal}"); | ||
| 4874 | + assert!(refusal.contains("at frame 0"), "{refusal}"); | ||
| 4875 | + assert_eq!(p.lane_spans(v3), vec![(0, 3)], "the clip is still there"); | ||
| 4876 | + assert_eq!(p.history.len(), history, "a refusal snapshots nothing"); | ||
| 4877 | + | ||
| 4878 | + // The empty one in the middle goes, and `V3` becomes `V2` -- clip and | ||
| 4879 | + // all. | ||
| 4880 | + p.remove_lane(v2).expect("V2 is empty"); | ||
| 4881 | + assert_eq!(p.lane_count(LaneKind::Video), 2); | ||
| 4882 | + assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2]); | ||
| 4883 | + assert_eq!(p.lane_spans(v2), vec![(0, 3)], "the lane below moved up"); | ||
| 4884 | + assert_eq!(p.history.len(), history + 1, "one snapshot per removal"); | ||
| 4885 | + invariants_hold(&p, "remove V2"); | ||
| 4886 | + | ||
| 4887 | + // ...and one stroke puts the empty lane back above it. | ||
| 4888 | + assert!(p.undo()); | ||
| 4889 | + assert_eq!(p.lane_count(LaneKind::Video), 3); | ||
| 4890 | + assert!(p.lane(v2).is_empty(), "back where it stood, still empty"); | ||
| 4891 | + assert_eq!(p.lane_spans(v3), vec![(0, 3)]); | ||
| 4892 | + } | ||
| 4893 | + | ||
| 4700 | /// The grouping rule across more than two lanes: a link id is one *span*, | 4894 | /// The grouping rule across more than two lanes: a link id is one *span*, |
| 4701 | /// on however many lanes carry it -- not a video/audio pair and not a | 4895 | /// on however many lanes carry it -- not a video/audio pair and not a |
| 4702 | /// pairing by `ord`. So a split shares an id with every lane whose half | 4896 | /// pairing by `ord`. So a split shares an id with every lane whose half |
crates/engine/tests/images.rsmodified+19 -0
| @@ -208,6 +208,25 @@ fn a_still_trims_out_to_its_cap_and_no_further() { | |||
| 208 | // ...and back in, which is the half a five-second title card actually uses. | 208 | // ...and back in, which is the half a five-second title card actually uses. |
| 209 | assert!(session.trim_clip(Lane::V1, 0, Edge::End, clip.start + 60)); | 209 | assert!(session.trim_clip(Lane::V1, 0, Edge::End, clip.start + 60)); |
| 210 | assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60); | 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 | /// The *clipboard* door, which is the second way a clip picks its lanes and | 232 | /// The *clipboard* door, which is the second way a clip picks its lanes and |