diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 1bdbd9f..60f76da 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -66,6 +66,8 @@ pub enum ActionId { Undo, AddVideoLane, AddAudioLane, + RemoveVideoLane, + RemoveAudioLane, ToggleMute, VolumeUp, VolumeDown, @@ -78,7 +80,7 @@ pub enum ActionId { impl ActionId { /// Display order everywhere -- the editor lists them in it and /// [`Keymap::defaults`] binds them in it. - pub const ALL: [ActionId; 33] = [ + pub const ALL: [ActionId; 35] = [ ActionId::Play, ActionId::StepBack, ActionId::StepForward, @@ -105,6 +107,8 @@ impl ActionId { ActionId::Undo, ActionId::AddVideoLane, ActionId::AddAudioLane, + ActionId::RemoveVideoLane, + ActionId::RemoveAudioLane, ActionId::ToggleMute, ActionId::VolumeUp, ActionId::VolumeDown, @@ -143,6 +147,8 @@ impl ActionId { ActionId::Undo => "Undo", ActionId::AddVideoLane => "Add a video track", ActionId::AddAudioLane => "Add an audio track", + ActionId::RemoveVideoLane => "Remove the last video track (it must be empty)", + ActionId::RemoveAudioLane => "Remove the last audio track (it must be empty)", ActionId::ToggleMute => "Mute / Unmute", ActionId::VolumeUp => "Volume up", ActionId::VolumeDown => "Volume down", @@ -183,6 +189,8 @@ impl ActionId { ActionId::Undo => "undo", ActionId::AddVideoLane => "add-video-lane", ActionId::AddAudioLane => "add-audio-lane", + ActionId::RemoveVideoLane => "remove-video-lane", + ActionId::RemoveAudioLane => "remove-audio-lane", ActionId::ToggleMute => "toggle-mute", ActionId::VolumeUp => "volume-up", ActionId::VolumeDown => "volume-down", @@ -235,7 +243,9 @@ impl ActionId { | ActionId::Group | ActionId::Undo | ActionId::AddVideoLane - | ActionId::AddAudioLane => Category::Editing, + | ActionId::AddAudioLane + | ActionId::RemoveVideoLane + | ActionId::RemoveAudioLane => Category::Editing, ActionId::ToggleMute | ActionId::VolumeUp | ActionId::VolumeDown @@ -291,7 +301,15 @@ pub struct Fixed { pub category: Category, } -pub const FIXED: [Fixed; 15] = [ +pub const FIXED: [Fixed; 16] = [ + // Not a chord at all but a way of pressing one, and the only place the + // editor can say so: holding a key that moves a *value* runs it, and + // holding anything else still does what one press did. + Fixed { + chord: "hold ← → ↑ ↓", + label: "Run a card's slider, or the volume keys, while held", + category: Category::View, + }, Fixed { chord: "esc", label: "Close this card or menu, or cancel a capture", @@ -533,6 +551,13 @@ impl Keymap { // is added often enough to deserve a key that is one press. b(ActionId::AddVideoLane, "v", false), b(ActionId::AddAudioLane, "a", false), + // ...and the pair that takes one back, on ctrl chords: removing + // a track is not a stroke to hit by accident (the resolution key + // is out of the way for the same reason). Ctrl+v would be the + // matching initial and is the paste, so the video one takes the + // key beside it. + b(ActionId::RemoveVideoLane, "b", true), + b(ActionId::RemoveAudioLane, "a", true), b(ActionId::ToggleMute, "m", false), // The unshifted pair, which is what gpui reports for those two // keys ("=" and "-", platform.rs:862): the volume keys every @@ -814,7 +839,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 35); + assert_eq!(k.entries().len(), 37); assert_eq!(k.lookup("space", false), Some(ActionId::Play)); // The seek keys: bare arrows a frame, ctrl arrows a second, and the two // ends of the timeline. @@ -848,6 +873,10 @@ mod tests { // The track keys are the bare letters; the ctrl ones stay copy/paste. assert_eq!(k.lookup("v", false), Some(ActionId::AddVideoLane)); assert_eq!(k.lookup("a", false), Some(ActionId::AddAudioLane)); + // ...and the ctrl ones take a track away, out of the way of a stray + // press. Ctrl+v is the paste, so the video one sits beside it. + assert_eq!(k.lookup("b", true), Some(ActionId::RemoveVideoLane)); + assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane)); assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute)); assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer)); // The volume pair is the unshifted one, so neither needs a modifier @@ -1043,7 +1072,7 @@ mod tests { assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); // The label is the editor's column, and never the file's word for it. assert_eq!(ActionId::CancelExport.label(), "Cancel export"); - assert_eq!(ActionId::ALL.len(), 33); + assert_eq!(ActionId::ALL.len(), 35); } #[test] diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 5fad151..0500f4b 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -95,6 +95,9 @@ const ROW_H: f32 = 32.; /// wear in the lanes, which is the whole of the panel<->timeline association. const SWATCH_W: f32 = 4.; const CONTROL_H: f32 = 28.; +/// The volume slider beside its button: a hundred steps across it, so a pixel +/// is finer than a step and the drag reads as continuous. +const VOLUME_W: f32 = 110.; const RULER_HIT_H: f32 = HIT_MIN; /// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits /// cannot push the layout around. @@ -128,6 +131,18 @@ const ESCAPE: &str = "escape"; /// as a program name rather than as a file name. const NO_FILE: &str = "no file open"; +/// What a press of play says when there is nothing to play: no timeline at all +/// and an emptied one are the same answer to the user, so they are one line. +const NOTHING_TO_PLAY: &str = "NOTHING TO PLAY — put a clip on the timeline first"; + +/// Whether a press of play would have anything to play. No timeline at all and +/// one every clip has been taken off are the same state to a transport, and the +/// button and the key both have to give the same answer to it -- so there is +/// one of them, and it is free of the window so it can be checked without one. +fn nothing_to_play(session: Option<&PlaybackSession>) -> bool { + session.is_none_or(PlaybackSession::is_empty) +} + /// What the monitoring output is set to. Two things, not one: the level the /// user picked, and whether it is being held silent -- so unmuting comes back /// to the level rather than to a guess. @@ -146,29 +161,45 @@ struct Volume { } impl Volume { - /// 5% a press: twenty of them across the range. - const MAX_STEPS: u8 = 20; + /// One step is one percent: fine enough that a drag along the slider reads + /// as continuous, and still a count rather than a float. + const MAX_STEPS: u8 = 100; + + /// 5% a press: twenty presses across the range, which is what the keys have + /// always moved. The slider is what the finer grid is for. + const KEY_STEP: u8 = 5; /// What the device is set to: mute wins, and the level is what it returns /// to. `0.0..=1.0`, which is the range the plugin's ABI accepts. fn gain(self) -> f32 { - if self.muted { - 0. - } else { - f32::from(self.steps) / f32::from(Self::MAX_STEPS) - } + if self.muted { 0. } else { self.along() } } /// One press up or down, clamped at both ends -- saturating, so the count /// cannot wrap past silence into full volume. fn step(&mut self, up: bool) { self.steps = if up { - self.steps.saturating_add(1).min(Self::MAX_STEPS) + self.steps.saturating_add(Self::KEY_STEP).min(Self::MAX_STEPS) } else { - self.steps.saturating_sub(1) + self.steps.saturating_sub(Self::KEY_STEP) }; } + /// Where the hand let go along the slider, 0..1 from silence to full. The + /// grid is the same one the keys land on, so a drag to the top and a key + /// held up reach the very same number -- and a drag never touches mute: + /// asking for a level while muted is not asking for sound. + fn set_along(&mut self, frac: f32) { + self.steps = (frac.clamp(0., 1.) * f32::from(Self::MAX_STEPS)).round() as u8; + } + + /// How full the slider is drawn, 0..1. The level and not the gain: a muted + /// slider still shows what unmuting comes back to, exactly as the label + /// does. + fn along(self) -> f32 { + f32::from(self.steps) / f32::from(Self::MAX_STEPS) + } + /// What the button reads. The level shows while muted too: it is what the /// next press of the mute key brings back. fn label(self) -> String { @@ -358,9 +389,10 @@ fn speed_at(permille: i32) -> Speed { } /// The silence card's rows, in the order it lists them: how wide the apply -/// reaches, the four settings a scan is told, and the rate the speed-up plays -/// at. What `silence_field` indexes and what [`Player::nudge_silence`] moves. -const SILENCE_ROWS: usize = 6; +/// reaches, the threshold and the unit it is read in, the three durations a +/// scan is told, and the rate the speed-up plays at. What `silence_field` +/// indexes and what [`Player::nudge_silence`] moves. +const SILENCE_ROWS: usize = 7; /// How wide a jumpcut reaches. A ripple used to be the whole timeline's /// business and nothing else; it is a *choice* now, because a podcast track's @@ -408,9 +440,12 @@ const SILENCE_DB_STEP: f32 = 1.; const SILENCE_SECS_STEP: f64 = 0.05; /// How far each of them may be pushed. UI decisions, all of them: the engine -/// takes any finite number, but a threshold at 0 dBFS calls a whole take silent -/// and a forgiveness of ten seconds finds nothing in a talking head. -const SILENCE_DB_RANGE: (f32, f32) = (-80., -10.); +/// takes any finite number, but a forgiveness of ten seconds finds nothing in a +/// talking head. The threshold reaches full scale, which calls a whole take +/// silent -- that is a thing someone may want to ask for (the preview on the +/// lane says what it would cost before anything is cut), so the top is 0 rather +/// than a number this card picked for them. +const SILENCE_DB_RANGE: (f32, f32) = (-80., 0.); const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.); /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows @@ -614,6 +649,11 @@ struct Player { /// also why it is not written to the project file and cannot reach an /// export. [`Player::apply_volume`] is what pushes it at a session. volume: Volume, + /// Where the volume slider was last painted, and whether a hand is on it -- + /// the speed bar's pair, for the speed bar's reason: the pointer moves + /// arrive at the root, so the bar's own geometry has to be readable there. + volume_bar: Rc>>, + volume_dragging: bool, /// The keybindings overlay is up. While it is, it owns the keyboard and the /// pointer: a stroke or a click meant for a row must not also cut the /// timeline. @@ -687,6 +727,14 @@ struct Player { /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own /// focus, since nothing in it takes gpui's (ledger:182). silence_field: usize, + /// Whether the threshold is *labelled* dBFS or dB. Display only, and the + /// number is the same either way: the setting is a level below full scale, + /// so 0 is the loudest sample a file can hold and -40 is forty decibels + /// under it -- "dBFS" names that reference out loud, "dB" leaves it unsaid. + /// No conversion is hiding behind the row (there is no reference here worth + /// inventing, and a made-up SPL would be a lie about what was measured); + /// what it changes is which of the two spellings a person reads. + silence_dbfs: bool, /// What the last scan found, in timeline frames: what the lane draws marks /// over and what an apply acts on -- *exactly* the previewed set, never a /// second scan at the moment of the press. @@ -857,6 +905,11 @@ impl Player { ActionId::Undo => self.undo(cx), ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx), ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx), + // The last track of that kind: the one the add key put there, so the + // two strokes undo each other press for press. Any other track goes + // through the × in its own header. + ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx), + ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx), ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx), ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx), ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx), @@ -1349,9 +1402,12 @@ impl Player { + steps as f32 * SILENCE_DB_STEP) .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1) } - 2 => self.silence.min_silence = secs(self.silence.min_silence), - 3 => self.silence.padding = secs(self.silence.padding), - 4 => self.silence.min_keep = secs(self.silence.min_keep), + // Two spellings of the same level, so either arrow flips it -- a + // ring of two, like the scope row's. + 2 => self.silence_dbfs = !self.silence_dbfs, + 3 => self.silence.min_silence = secs(self.silence.min_silence), + 4 => self.silence.padding = secs(self.silence.padding), + 5 => self.silence.min_keep = secs(self.silence.min_keep), _ => { self.silence_factor = silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP) @@ -1504,6 +1560,29 @@ impl Player { || self.exporting().is_some() } + /// Which of [`Repeat`]'s three the window is in, for the hold gate at the + /// top of the key handler. Not [`Player::modal`]: that asks whether an + /// overlay is up at all, and here the cards with sliders in them are + /// exactly the ones that answer differently from the keys menu and the + /// export card. + fn repeat_scope(&self) -> Repeat { + if self.rebinding.is_some() + || self.keys_open + || self.export_open + || self.exporting().is_some() + { + Repeat::Nothing + } else if self.eq_open.is_some() + || self.color_open.is_some() + || self.speed_open.is_some() + || self.silence_open.is_some() + { + Repeat::Card + } else { + Repeat::Keymap + } + } + /// Opens the equalizer on the selected clip. Audio only, and it says so /// rather than opening a card of bands that would reach nothing: a video /// clip carries no sound of its own here (the sound is the audio lane's), @@ -2053,6 +2132,25 @@ impl Player { return clip; }; match trim.edge { + // A still grows forward from source frame 0 instead, exactly as + // `Project::trim` writes it: with the in-point clamped at 0 the box + // below would slide left rather than stretch, and the release would + // then commit a wider clip than the drag drew. + Edge::Start + if self.session.as_ref().is_some_and(|session| { + session + .sources() + .get(clip.source) + .is_some_and(|s| engine::is_image(&s.path)) + }) => + { + Clip { + in_frame: 0, + out_frame: clip.end().saturating_sub(trim.to).max(1), + start: trim.to, + ..clip + } + } // The in-point follows the head, exactly as `Project::trim` moves // it: what stays on screen plays what it always played. Edge::Start => Clip { @@ -2432,6 +2530,64 @@ impl Player { cx.notify(); } + /// The × in a track's header: the add taken back, one undo step, and the + /// engine's own words when it refuses -- those name the clips still on the + /// track, so the notice says what to delete first. A removal never deletes a + /// clip. + /// + /// Everything holding a `(lane, idx)` is dropped, because the tracks below + /// the one that went have just moved up an `ord` + /// ([`engine::Project::remove_lane`]): a selection or an open card kept + /// across it would be pointing at the *next* track's clip. + fn remove_lane(&mut self, lane: Lane, cx: &mut Context) { + if self.exporting().is_some() { + return; + } + let removed = self + .session + .as_mut() + .map(|session| session.remove_lane(lane)); + let text = match removed { + Some(Ok(())) => { + self.selected = None; + self.context_menu = None; + self.eq_open = None; + self.color_open = None; + self.speed_open = None; + self.close_silence(); + format!( + "{} REMOVED — {} brings it back", + lane.label(), + self.keymap.display(ActionId::Undo) + ) + } + Some(Err(e)) => format!("NO TRACK REMOVED — {e}"), + None => "NO TRACK REMOVED — open a file first".to_string(), + }; + self.notice = Some(text.into()); + cx.notify(); + } + + /// What the remove keys act on: the last track of that kind, which is the + /// one the matching add key appended. Nothing at all before a file is open, + /// where the timeline drawn is a placeholder pair. + fn remove_last_lane(&mut self, kind: LaneKind, cx: &mut Context) { + let last = self.session.as_ref().and_then(|session| { + session + .lanes() + .into_iter() + .filter(|l| l.kind == kind) + .next_back() + }); + match last { + Some(lane) => self.remove_lane(lane, cx), + None => { + self.notice = Some("NO TRACK REMOVED — open a file first".into()); + cx.notify(); + } + } + } + fn undo(&mut self, cx: &mut Context) { if self.session.as_mut().is_some_and(PlaybackSession::undo) { self.reset_after_reseek(); @@ -2518,10 +2674,33 @@ impl Player { cx.notify(); } + /// Where the pointer sits along the slider, as a level. The press and every + /// sample after it come here, so the sound follows the hand rather than the + /// release -- there is nothing to undo about a monitoring level, which is + /// why this writes live and keeps no gesture state beyond the flag. + fn drag_volume(&mut self, x: Pixels, cx: &mut Context) { + let along = frac_along(x, self.volume_bar.get()); + self.set_volume(|volume| volume.set_along(along), cx); + } + fn toggle_or_restart(&mut self, cx: &mut Context) { if self.exporting().is_some() { return; } + // Nothing to play is a message, not a transport state. An empty + // timeline is `done` from its one black frame onward, so the restart + // below would start a clock against a zero-length timeline -- and it is + // `done` again by the next repaint, so no later press could ever stop + // it: the button would read "Pause" and never pause. A delete can empty + // the timeline mid-play, and that press must still stop it. + if nothing_to_play(self.session.as_ref()) { + match self.session.as_mut().filter(|s| s.is_playing()) { + Some(session) => session.pause(), + None => self.notice = Some(NOTHING_TO_PLAY.into()), + } + cx.notify(); + return; + } if self.done { self.seek(0., cx); if let Some(session) = &mut self.session { @@ -2749,9 +2928,19 @@ impl Render for Player { div() .track_focus(&self.focus) .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { - // `is_held` filters auto-repeat, which would otherwise toggle - // playback -- or cut the timeline -- many times a second. - if event.is_held { + let key = event.keystroke.key.as_str(); + let ctrl = event.keystroke.modifiers.control; + // `is_held` is the auto-repeat, and a value is the one thing + // worth running on it: a held arrow on a card moves the slider + // it picked, and a held volume key runs the volume. Everything + // else is filtered exactly as it always was -- a repeat that + // toggled playback, or cut the timeline, many times a second is + // what this guard is for, and a row waiting for a stroke takes + // none of it either (it would bind the key, then fire what it + // just bound). See [`repeats`]. + if event.is_held + && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl)) + { return; } // Any key retires the last message, whatever it was -- and owes @@ -2761,7 +2950,6 @@ impl Render for Player { if this.notice.take().is_some() { cx.notify(); } - let key = event.keystroke.key.as_str(); // A row is waiting for a stroke, and while it is, that stroke is // data: it means the binding and nothing else, which is why this // answers before the export guard and before the keymap is @@ -2770,7 +2958,7 @@ impl Render for Player { if key == ESCAPE { this.rebinding = None; } else if !is_bare_modifier(key) { - this.capture(action, key, event.keystroke.modifiers.control); + this.capture(action, key, ctrl); } cx.notify(); return; @@ -2779,7 +2967,7 @@ impl Render for Player { // control modifier set (the control code is mapped back), which // is why the keymap is keyed on the pair and never on the key // alone. - let action = this.keymap.lookup(key, event.keystroke.modifiers.control); + let action = this.keymap.lookup(key, ctrl); // An export is reading the edit list every other action here // would change, so cancelling is the only one that means // anything until it is over. @@ -3031,6 +3219,16 @@ impl Render for Player { } return; } + // The volume slider, the same live writes: what the hand is on + // is what the speakers are doing, and there is nothing to undo. + if this.volume_dragging { + if event.pressed_button == Some(MouseButton::Left) { + this.drag_volume(event.position.x, cx); + } else { + this.volume_dragging = false; + } + return; + } if !this.scrubbing { return; } @@ -3071,6 +3269,10 @@ impl Render for Player { this.drag_speed(event.position.x, false, cx); return; } + if std::mem::take(&mut this.volume_dragging) { + this.drag_volume(event.position.x, cx); + return; + } if std::mem::take(&mut this.scrubbing) { this.scrub_to(event.position.x, true, cx); } @@ -3493,8 +3695,17 @@ impl Player { "transport", Some(transport_glyph(playing).into_any_element()), if playing { "Pause" } else { "Play" }, - key(ActionId::Play), - live, + if nothing_to_play(self.session.as_ref()) && !playing { + format!("{} — put a clip on a lane first", key(ActionId::Play)) + } else { + key(ActionId::Play) + }, + // An empty timeline has nothing to play, so the button + // says so by being dim rather than by starting a clock + // against nothing (the key press answers with the + // notice). Still live while it *is* playing: a delete + // can empty the timeline mid-play and that has to stop. + live && (playing || !nothing_to_play(self.session.as_ref())), cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), )) .child(separator()) @@ -3569,6 +3780,15 @@ impl Player { this.set_volume(|volume| volume.muted = !volume.muted, cx) }), )) + // The level itself, to drag. The button beside it stays the + // mute -- one gesture each -- and the label above is what + // this writes, live, so the number follows the hand. + .child(volume_slider( + self.volume, + self.volume_bar.clone(), + live, + cx, + )) .child(separator()) // Import is not here: it belongs to the media list it adds // to, and two doors into one action is a question about @@ -4679,9 +4899,19 @@ impl Player { fn silence_card(&self, cx: &mut Context) -> Option { let (lane, idx) = self.silence_open?; let cfg = self.silence; + // The unit is a label, never a conversion: the threshold is a level + // below full scale whichever of the two the row says (`silence_dbfs`). + let unit = match self.silence_dbfs { + true => "dBFS", + false => "dB", + }; let rows = [ ("Apply to", self.silence_scope.label(&self.silence_lanes())), - ("Silence is under", format!("{:.0} dBFS", cfg.threshold_db)), + ( + "Silence is under", + format!("{:.0} {unit}", cfg.threshold_db), + ), + ("Level read in", format!("{unit} (0 = full scale)")), ( "Forgive quiet shorter than", format!("{:.2} s", cfg.min_silence), @@ -4780,7 +5010,7 @@ impl Player { .text_size(px(11.)) .text_color(rgb(INK_DIM)) .child( - "↑↓ picks a setting, ←→ moves it — the marks on the lane are what would go; esc closes", + "↑↓ picks a setting, ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes", ), ) .children(rows) @@ -5208,6 +5438,12 @@ impl Player { }); let name = lane.label(); let row_id: SharedString = format!("{name}-clip").into(); + let remove_id: SharedString = format!("{name}-remove").into(); + let remove_tip: SharedString = format!( + "Remove {name} — it must be empty first, and {} brings it back", + self.keymap.display(ActionId::Undo) + ) + .into(); let sources = self .session .as_ref() @@ -5237,13 +5473,37 @@ impl Player { .w(px(HEADER_W)) .h_full() .flex() + .flex_col() .items_center() .justify_center() .rounded(px(3.)) .bg(rgb(SURFACE)) .text_size(px(11.)) .text_color(rgb(INK_DIM)) - .child(name), + .child(div().flex_1().flex().items_center().child(name)) + // The one thing a header does: take this track away again. + // A `HIT_MIN` target rather than a glyph-sized one, and it + // stays put on a track holding clips instead of hiding -- + // the refusal names them, and a control that vanishes + // teaches nothing. + .child( + div() + .id(remove_id) + .flex_none() + .w_full() + .h(px(HIT_MIN)) + .flex() + .items_center() + .justify_center() + .rounded(px(3.)) + .cursor_pointer() + .hover(|s| s.bg(rgb(HOVER))) + .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.remove_lane(lane, cx) + })) + .child("×"), + ), ) .child( // Clips are placed at their own start rather than queued edge @@ -6273,6 +6533,39 @@ fn cancels_export(key: &str, action: Option) -> bool { key == ESCAPE || action == Some(ActionId::CancelExport) } +/// Where a held key would land, which is the whole of what auto-repeat has to +/// know. [`Player::repeat_scope`] answers it from the same state the handler +/// walks below itself. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +enum Repeat { + /// A card with values in it owns the keyboard: equalizer, colour, speed or + /// silence. Its arrows are sliders. + Card, + /// Nobody does, so the keymap answers -- and only one pair of its actions + /// is a value being moved rather than a thing being done once. + Keymap, + /// A stroke is being captured, an export is running, or an overlay with no + /// value in it is up. Nothing there is worth a repeat. + Nothing, +} + +/// Whether a *held* stroke means it again. One press is always one action; a +/// hold is only ever a value running, so this is what tells the two apart. +/// +/// The cards' arrows, because that is what every one of them moves a slider +/// with -- and only the arrows, so the equalizer's `r` cannot flatten five +/// bands forty times a second and the silence card's `enter` cannot cut forty +/// places again on the next tick. Outside a card the volume pair and nothing +/// else: play, cut, delete, save, export and every other binding is a one-shot, +/// exactly as it was when the handler filtered every held key alike. +fn repeats(scope: Repeat, key: &str, action: Option) -> bool { + match scope { + Repeat::Card => matches!(key, "up" | "down" | "left" | "right"), + Repeat::Keymap => matches!(action, Some(ActionId::VolumeUp | ActionId::VolumeDown)), + Repeat::Nothing => false, + } +} + /// The keys that are only ever half a chord. gpui delivers a lone modifier /// press as a keystroke of its own, and taking one as a binding would leave an /// action that fires the moment the user reaches for any chord that uses it -- @@ -6571,6 +6864,59 @@ fn control( }) } +/// The monitoring level as something to drag: 4 px of bar to look at and the +/// whole control's height to hit (WCAG 2.5.8), the split the speed bar and the +/// colour sliders both make. Only the level -- mute is the button beside it, so +/// a muted slider still shows what unmuting comes back to, drawn dim. +/// +/// Dimmed and inert without a timeline, like every other control that would +/// have nothing to act on. +fn volume_slider( + volume: Volume, + bar: Rc>>, + enabled: bool, + cx: &mut Context, +) -> impl IntoElement { + div() + .id("volume-bar") + .relative() + .flex_none() + .w(px(VOLUME_W)) + .h(px(CONTROL_H)) + .flex() + .items_center() + .tooltip(|_, cx| { + cx.new(|_| Tip("Volume — drag to set the level; the button mutes".into())) + .into() + }) + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) + .when(enabled, |d| { + d.cursor_pointer() + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, event: &MouseDownEvent, _, cx| { + this.volume_dragging = true; + this.drag_volume(event.position.x, cx); + }), + ) + .child(bounds_probe(bar)) + }) + .child( + div() + .w_full() + .h(px(4.)) + .rounded(px(2.)) + .bg(rgb(SURFACE)) + .child( + div() + .h_full() + .w(relative(volume.along())) + .rounded(px(2.)) + .bg(rgb(if volume.muted { INK_DIM } else { ACCENT })), + ), + ) +} + /// The line between two groups of buttons. fn separator() -> impl IntoElement { div() @@ -6984,14 +7330,15 @@ mod tests { LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, - Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add, cancels_export, - color_snap, envelope, eq_spectrum, eq_x, eq_y, export_path, export_settings, format_key, - format_line, format_refusal, frac_along, frac_down, frame_at, histogram, is_bare_modifier, - is_project, keymap, lanes_h, marked, menu_at, normalise, panel_h, project_path, push_digit, - retarget, scrub_due, show_label, silence_rate, source_tint, span_partner, speed_at, - start_frac, timecode, unseen_paths, unseen_sources, whole_take, width_frac, window_title, + VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add, + cancels_export, color_snap, envelope, eq_spectrum, eq_x, eq_y, export_path, + export_settings, format_key, format_line, format_refusal, frac_along, frac_down, frame_at, + histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, menu_at, normalise, + nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, show_label, + silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths, + unseen_sources, whole_take, width_frac, window_title, }; - use super::{LaneKind, file_name, file_uri, library_rows, unscannable}; + use super::{LaneKind, Repeat, file_name, file_uri, library_rows, repeats, unscannable}; /// What the file manager is handed: the parts a path keeps as they are, and /// the ones the bus would otherwise read as something else. @@ -8579,11 +8926,47 @@ mod tests { ); } + /// The hold gate: a value runs, everything else still means one press one + /// action -- which is the whole invariant the blanket `is_held` filter used + /// to carry on its own. + #[test] + fn a_held_key_moves_a_value_and_nothing_else() { + use keymap::ActionId; + // A card's four arrows, whichever card it is. + for key in ["up", "down", "left", "right"] { + assert!(repeats(Repeat::Card, key, None), "{key} on a card"); + } + // The card's own one-shots: flatten every band, cut forty places, play + // them fast, close. None of them on a hold. + for key in ["r", "enter", "f", "1", "escape"] { + assert!(!repeats(Repeat::Card, key, None), "{key} on a card"); + } + // Outside a card the keymap answers, and only the volume pair is a + // value being moved. + assert!(repeats(Repeat::Keymap, "up", Some(ActionId::VolumeUp))); + assert!(repeats(Repeat::Keymap, "down", Some(ActionId::VolumeDown))); + for action in ActionId::ALL { + let held = repeats(Repeat::Keymap, "k", Some(action)); + assert_eq!( + held, + matches!(action, ActionId::VolumeUp | ActionId::VolumeDown), + "{action:?} on a hold" + ); + } + // An arrow with nothing bound to it moves nothing on the timeline. + assert!(!repeats(Repeat::Keymap, "left", None)); + // And a stroke being captured, an export, or the overlays: nothing at + // all, or the hold would bind a key and then fire what it just bound. + for key in ["up", "left", "escape", "5"] { + assert!(!repeats(Repeat::Nothing, key, Some(ActionId::VolumeUp))); + } + } + #[test] fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() { // The same 640x360 floor, and this card starts below the header: a - // title and a hint over its five rows, the count line and the two - // buttons. + // title and a hint over its [`SILENCE_ROWS`] rows, the count line and + // the two buttons. let (title, hint, count) = (17., 17., 17.); let gaps = 6. * 5.; let padding = 24.; @@ -8914,6 +9297,116 @@ mod tests { assert_eq!(source_tint(9), source_tint(1)); assert_eq!(source_tint(usize::MAX), SOURCE_TINTS[usize::MAX % 4]); } + + /// The bug: an empty timeline is end-of-stream from its one black frame + /// onward, so the pump had `done` set before anything was ever pressed -- + /// and the transport's restart branch read that as "played out, start from + /// the top". It started a clock against a zero-length timeline, which was + /// `done` again by the next repaint, so every further press restarted it + /// too: the button read "Pause" and no press of it ever paused. + /// + /// What holds it now is one predicate, checked here against real sessions + /// on both sides -- the emptied one refuses, a timeline with clips on it + /// does not. + #[test] + fn an_empty_timeline_has_nothing_to_play() { + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); + // Silent like the engine suite: this opens the real device. + session.set_gain(0.0); + // A timeline with clips on it plays, and always did: the guard must not + // touch that side. + assert!(!session.is_empty()); + assert!(!nothing_to_play(Some(&session))); + + // Every clip taken off, which is a state and not a failure. + while session.delete_clip(Lane::V1, 0) {} + while session.delete_clip(Lane::A1, 0) {} + assert!(session.is_empty(), "the timeline is empty"); + assert_eq!(session.timeline_duration(), 0.0); + + // What the pump does every render, and what set `done` before the fix: + // the black frame goes by and the session is at its end at once. + for _ in 0..40 { + while session.try_frame().is_some() {} + std::thread::sleep(Duration::from_millis(10)); + } + assert!(session.is_eos(), "an empty timeline is done before it starts"); + + // So the press is refused rather than sent down the restart branch -- + // and with no session at all it is the same refusal. + assert!(nothing_to_play(Some(&session))); + assert!(nothing_to_play(None)); + assert!(!session.is_playing(), "and nothing was started"); + } + + /// The slider writes the same numbers the keys do, and mute is not one of + /// them: dragging while muted picks the level unmuting comes back to. + #[test] + fn the_slider_lands_on_the_grid_the_keys_move_on() { + let mut volume = Volume::default(); + // Both ends exactly, and clamped past them. + volume.set_along(0.); + assert_eq!(volume.gain(), 0.0); + assert_eq!(volume.label(), "Vol 0%"); + volume.set_along(1.5); + assert_eq!(volume.gain(), 1.0); + assert_eq!(volume.along(), 1.0); + + // Halfway is 50%, and a key press from there is 5% -- the same step + // count as before, on a finer grid. + volume.set_along(0.5); + assert_eq!(volume.label(), "Vol 50%"); + volume.step(true); + assert_eq!(volume.label(), "Vol 55%"); + volume.step(false); + assert_eq!(volume.gain(), 0.5); + + // A number no step lands on comes back as the nearest one, so the label + // and the fill are the same value the device was handed. + volume.set_along(0.333); + assert_eq!(volume.label(), "Vol 33%"); + assert_eq!(volume.along(), 0.33); + + // Muted, the drag moves the level and nothing comes out. + volume.muted = true; + volume.set_along(0.8); + assert_eq!(volume.gain(), 0.0); + assert_eq!(volume.label(), "Muted 80%"); + volume.muted = false; + assert_eq!(volume.gain(), 0.8); + } + + /// The slider lands where it paints: the arithmetic `Player::drag_volume` + /// runs over the bar's own painted width, which is the one thing a test of + /// it can share without re-deriving it. + #[test] + fn the_volume_slider_lands_where_it_paints() { + let bar = Bounds { + origin: point(px(420.), px(508.)), + size: size(px(VOLUME_W), px(CONTROL_H)), + }; + let at = |x: f32| { + let mut volume = Volume::default(); + volume.set_along(frac_along(px(x), bar)); + volume + }; + assert_eq!(at(420.).gain(), 0.0, "the left end is silence"); + assert_eq!(at(420. + VOLUME_W).gain(), 1.0, "the right end is full"); + assert_eq!(at(-4000.).gain(), 0.0, "off the left clamps"); + assert_eq!(at(9999.).gain(), 1.0, "off the right clamps"); + // Every pixel along it: a level the keys could also reach, painted back + // where the hand pressed to within the half step the rounding costs. + for step in 0..=(VOLUME_W as u32) { + let along = step as f32 / VOLUME_W; + let volume = at(420. + along * VOLUME_W); + let painted = volume.along(); + let slack = 0.5 / f32::from(Volume::MAX_STEPS) + 1e-4; + assert!( + (painted - along).abs() <= slack, + "pressed at {along}, paints at {painted}" + ); + } + } } fn main() { @@ -9034,6 +9527,8 @@ fn main() { // Full and unmuted, which is what the session it was just // handed is already set to: nothing to push at startup. volume: Volume::default(), + volume_bar: Rc::default(), + volume_dragging: false, // Only ever used with a timeline; 30 keeps the empty // timecode reading in frames rather than in NaN. fps: meta.map_or(30., |meta| meta.frame_rate), @@ -9082,6 +9577,9 @@ fn main() { // one a person can widen on purpose. silence_scope: Scope::Take, silence_field: 0, + // The reference named, which is what the card said before + // there was a choice about it. + silence_dbfs: true, silence_marks: Vec::new(), silence_levels: None, color_open: None, diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 939eda9..4aef749 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -901,6 +901,13 @@ impl PlaybackSession { self.project.add_lane(kind) } + /// Drops that empty lane again, in [`Project::remove_lane`]'s words when it + /// refuses. One undo step, and no reseek for the same reason the add needs + /// none: an empty lane was playing nothing. + pub fn remove_lane(&mut self, lane: Lane) -> crate::Result<()> { + self.project.remove_lane(lane) + } + /// Splits every lane at `timeline_secs`, so the two sides become two /// groups. Metadata only: a split never changes the timeline->source /// mapping, so the running decoder stays correct and playback does not diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 9d1b789..1620522 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -666,6 +666,67 @@ impl Project { Lane::new(kind, self.lane_count(kind) - 1) } + /// Drops an *empty* lane -- [`add_lane`](Project::add_lane) taken back, and + /// one undo step like it, which restores the lane where it stood. + /// + /// Refused, changing nothing, while the lane holds anything: the refusal + /// names the clips (file and first frame), because a track removal that + /// deleted takes with it would be the one edit nobody sees coming. Refused + /// too for the last lane of its kind, which is `V1` or `A1`: those two are + /// where an import and a paste land ([`Project::paste`] takes lane 0 of each + /// kind and *skips* a kind that is not there), so a project without one + /// would swallow half of every file dropped on it, silently. + /// + /// The lanes below it move up one `ord`, so a handle a caller was holding + /// (a selection, an open card) names the lane after it from here on -- the + /// one thing a front-end owes this call. + pub fn remove_lane(&mut self, lane: Lane) -> crate::Result<()> { + let Some(i) = self.index(lane) else { + return Err(format!("there is no {} to remove", lane.label()).into()); + }; + if self.lane_count(lane.kind) == 1 { + return Err(format!( + "{} is the only {} track: every import lands on it", + lane.label(), + match lane.kind { + LaneKind::Video => "video", + LaneKind::Audio => "audio", + } + ) + .into()); + } + let clips = &self.lanes[i].clips; + if !clips.is_empty() { + // Three names and a count: a lane can hold forty clips and a + // refusal nobody reads to the end says nothing at all. + let named: Vec = clips + .iter() + .take(3) + .map(|c| { + let name = self.sources.get(c.source).map_or_else( + || format!("source {}", c.source), + |s| s.path.display().to_string(), + ); + format!("{name} at frame {}", c.start) + }) + .collect(); + let rest = match clips.len().saturating_sub(named.len()) { + 0 => String::new(), + n => format!(" and {n} more"), + }; + return Err(format!( + "{} still holds {}{rest}: delete those clips (or drag them to \ + another track) first", + lane.label(), + named.join(", ") + ) + .into()); + } + self.snapshot(); + self.lanes.remove(i); + Ok(()) + } + /// Where `lane` sits in [`Project::lanes`], or `None` for a lane that is /// not there. The one place a handle becomes a position. fn index(&self, lane: Lane) -> Option { @@ -1658,8 +1719,19 @@ impl Project { } self.snapshot(); for (&(l, i), keep) in members.iter().zip(fitted) { + let still = self.is_still(&self.lanes[l].clips[i]); let c = &mut self.lanes[l].clips[i]; match edge { + // A still has no earlier frame to walk an in-point back to -- + // every frame of it is the same picture -- so its head grows + // *forward*: the range it plays is however long the new room + // is, anchored at the source's frame 0. Bounded by `lo`, which + // is where the cap in `source_frames` is applied. + Edge::Start if still => { + c.in_frame = 0; + c.out_frame = keep; + c.start = to; + } Edge::Start => { // Non-negative by `lo`, which is what keeps the in-point on // the source. @@ -1700,9 +1772,24 @@ impl Project { // head than the timeline has room for -- a ripple delete // slides a clip back to frame 0 with its in-point wherever // the cut left it -- and frame 0 is the other wall. - c.start - .saturating_sub(c.speed.room(c.in_frame)) - .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), + // + // A still is measured from its *tail* instead: it has no + // in-point worth the name (every frame the same picture), so + // its head reaches exactly as far as its tail does -- out to + // the length the caller's table gives it, whole. Measured + // from the in-point it would have no head room at all, which + // is a placed picture whose left edge cannot be dragged out. + // No entry in the table means no growth, as it does at the + // other end. + if self.is_still(&c) { + c.end().saturating_sub( + c.speed + .room(source_frames.get(c.source).copied().unwrap_or(c.len())), + ) + } else { + c.start.saturating_sub(c.speed.room(c.in_frame)) + } + .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), // One *frame of clip* always survives, and at a rate below // real time one frame of clip is several frames of timeline // ([`Speed::room`]): an edge dragged closer than that would @@ -1739,6 +1826,16 @@ impl Project { Some((lo, hi.max(lo))) } + /// Whether `clip` plays a still image ([`crate::is_image`]): a file whose + /// every frame is the same picture, so which frame of it a clip's in-point + /// names is not a question -- what [`Project::trim`] lets grow at either + /// end. `false` for a source that is not there. + fn is_still(&self, clip: &Clip) -> bool { + self.sources + .get(clip.source) + .is_some_and(|s| crate::is_image(&s.path)) + } + /// The clips that move as one with the clip at `idx` of `lane` -- itself and /// whatever carries its link on the other lanes -- as `(lane storage index, /// clip index)` pairs. `None` for an index that is not there. @@ -3411,6 +3508,56 @@ mod tests { assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]); } + /// A still is trimmed from its head exactly as it is from its tail: it has + /// no earlier frame to walk an in-point back to, so the wall is the length + /// the caller's table allows it, measured back from the tail. Measured from + /// the in-point -- which a placed picture has at 0 -- its left edge could + /// never be dragged outwards at all. + #[test] + fn a_stills_head_stretches_out_like_its_tail() { + const STILL: &str = "/nonexistent/card.png"; + /// What a still is held to, as `PlaybackSession` fills the table in. + const CAP: &[u32] = &[60]; + + let mut p = Project::single(STILL, 20); + assert!(p.lift(Lane::A1, 0), "a picture is silent"); + assert!(p.lift(Lane::V1, 0), "and this one is not at frame 0"); + assert!(p.place(Lane::V1, 100, clip(0, 0, 20, 0))); + + // A source with no entry in the table may not grow, here as at the tail. + assert_eq!( + p.trim_room(Lane::V1, 0, Edge::Start, &[]), + Some((100, 119)), + "a length nobody told us buys no head room" + ); + assert_eq!( + p.trim_room(Lane::V1, 0, Edge::Start, CAP), + Some((60, 119)), + "back to a whole cap's worth, one frame of clip surviving" + ); + assert!(p.trim(Lane::V1, 0, Edge::Start, 80, CAP)); + assert_eq!( + shape(&p)[0][0], + clip(80, 0, 40, 0), + "twenty frames longer, and still read from the source's first frame" + ); + // Past the cap is clamped, exactly as the tail is -- not refused. + assert!(p.trim(Lane::V1, 0, Edge::Start, 0, CAP)); + assert_eq!(shape(&p)[0][0], clip(60, 0, 60, 0), "a cap's worth, no more"); + // ...and the clip in front is the nearer wall of the two: no head trim + // may open an overlap. + assert!(p.trim(Lane::V1, 0, Edge::Start, 90, CAP)); + assert!(p.place(Lane::V1, 70, clip(0, 0, 15, 0))); + assert_eq!( + p.trim_room(Lane::V1, 1, Edge::Start, CAP), + Some((85, 119)), + "up to the neighbour's last frame and not over it" + ); + assert!(p.trim(Lane::V1, 1, Edge::Start, 0, CAP)); + assert_eq!(shape(&p)[0][1], clip(85, 0, 35, 0), "butted against it"); + assert!(sorted_disjoint(p.lane(Lane::V1)), "no overlap"); + } + /// Linked halves trim as one: a link is one span on however many lanes, so /// the sound follows the picture's edge -- and the tightest wall of the two /// is what stops both. @@ -4697,6 +4844,53 @@ mod tests { assert_eq!(shape(&p), shape(&three())); } + /// The add taken back: an empty lane comes off, a lane holding clips never + /// does (and says which clips), the last lane of a kind never does, the + /// lanes below the one that went move up an `ord`, and one undo puts it + /// back where it stood. + #[test] + fn an_empty_lane_comes_off_again() { + let mut p = three(); + let v2 = p.add_lane(LaneKind::Video); + let v3 = p.add_lane(LaneKind::Video); + assert!(p.place(v3, 0, clip(0, 0, 3, 0))); + let why = |r: crate::Result<()>| r.expect_err("refused").to_string(); + let history = p.history.len(); + + // The last lane of its kind stays: `V1`/`A1` are where an import and a + // paste land, and a project missing one would swallow half of a file + // dropped on it. + assert!(why(p.remove_lane(Lane::A1)).contains("only audio track")); + assert_eq!( + why(p.remove_lane(Lane::new(LaneKind::Video, 9))), + "there is no V10 to remove" + ); + + // A lane with clips on it refuses and names them: a track removal never + // deletes a take. + let refusal = why(p.remove_lane(v3)); + assert!(refusal.contains("V3 still holds"), "{refusal}"); + assert!(refusal.contains(FILE), "{refusal}"); + assert!(refusal.contains("at frame 0"), "{refusal}"); + assert_eq!(p.lane_spans(v3), vec![(0, 3)], "the clip is still there"); + assert_eq!(p.history.len(), history, "a refusal snapshots nothing"); + + // The empty one in the middle goes, and `V3` becomes `V2` -- clip and + // all. + p.remove_lane(v2).expect("V2 is empty"); + assert_eq!(p.lane_count(LaneKind::Video), 2); + assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2]); + assert_eq!(p.lane_spans(v2), vec![(0, 3)], "the lane below moved up"); + assert_eq!(p.history.len(), history + 1, "one snapshot per removal"); + invariants_hold(&p, "remove V2"); + + // ...and one stroke puts the empty lane back above it. + assert!(p.undo()); + assert_eq!(p.lane_count(LaneKind::Video), 3); + assert!(p.lane(v2).is_empty(), "back where it stood, still empty"); + assert_eq!(p.lane_spans(v3), vec![(0, 3)]); + } + /// The grouping rule across more than two lanes: a link id is one *span*, /// on however many lanes carry it -- not a video/audio pair and not a /// pairing by `ord`. So a split shares an id with every lane whose half diff --git a/crates/engine/tests/images.rs b/crates/engine/tests/images.rs index aab2847..ba0d666 100644 --- a/crates/engine/tests/images.rs +++ b/crates/engine/tests/images.rs @@ -208,6 +208,25 @@ fn a_still_trims_out_to_its_cap_and_no_further() { // ...and back in, which is the half a five-second title card actually uses. assert!(session.trim_clip(Lane::V1, 0, Edge::End, clip.start + 60)); assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60); + + // The *head* is the same story from the other side: a still has no first + // frame to walk an in-point back to, so its left edge stretches out to the + // same cap. Pulled in first, since a clip at frame 0 has nowhere to go. + assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 20)); + let clip = session.lane_clips(Lane::V1)[0]; + assert_eq!((clip.start, clip.len()), (20, 40)); + assert_eq!( + session.trim_room(Lane::V1, 0, Edge::Start), + Some((0, clip.end() - 1)), + "out to frame 0: the cap is further off than the timeline reaches" + ); + assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 0), "dragged out"); + let clip = session.lane_clips(Lane::V1)[0]; + assert_eq!( + (clip.start, clip.in_frame, clip.len()), + (0, 0, 60), + "longer by what the head took, and still read from the first frame" + ); } /// The *clipboard* door, which is the second way a clip picks its lanes and