forge
Explore
Log in

Don't you dare go Hollow

A track you added comes off again

Browse files at this commit

21fe7cb4f64e7715d5738e1ad34c6b8af3c7351bAhmet Kaan GümüşParent: 88fbed0
  • feat
    • a track you added comes off again
Show full message
✨ feat(timeline): a track you added comes off again
crates/app/src/keymap.rsmodified+25 -4
@@ -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 and81 /// 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::Group243 | ActionId::Group
236 | ActionId::Undo244 | ActionId::Undo
237 | ActionId::AddVideoLane245 | ActionId::AddVideoLane
238- | ActionId::AddAudioLane => Category::Editing,246+ | ActionId::AddAudioLane
247+ | ActionId::RemoveVideoLane
248+ | ActionId::RemoveAudioLane => Category::Editing,
239 ActionId::ToggleMute249 ActionId::ToggleMute
240 | ActionId::VolumeUp250 | ActionId::VolumeUp
241 | ActionId::VolumeDown251 | ActionId::VolumeDown
@@ -528,6 +538,13 @@ impl Keymap {
528 // is added often enough to deserve a key that is one press.538 // is added often enough to deserve a key that is one press.
529 b(ActionId::AddVideoLane, "v", false),539 b(ActionId::AddVideoLane, "v", false),
530 b(ActionId::AddAudioLane, "a", false),540 b(ActionId::AddAudioLane, "a", false),
541+ // ...and the pair that takes one back, on ctrl chords: removing
542+ // a track is not a stroke to hit by accident (the resolution key
543+ // is out of the way for the same reason). Ctrl+v would be the
544+ // matching initial and is the paste, so the video one takes the
545+ // key beside it.
546+ b(ActionId::RemoveVideoLane, "b", true),
547+ b(ActionId::RemoveAudioLane, "a", true),
531 b(ActionId::ToggleMute, "m", false),548 b(ActionId::ToggleMute, "m", false),
532 // The unshifted pair, which is what gpui reports for those two549 // The unshifted pair, which is what gpui reports for those two
533 // keys ("=" and "-", platform.rs:862): the volume keys every550 // keys ("=" and "-", platform.rs:862): the volume keys every
@@ -809,7 +826,7 @@ mod tests {
809 #[test]826 #[test]
810 fn every_default_stroke_reaches_its_action() {827 fn every_default_stroke_reaches_its_action() {
811 let k = Keymap::defaults();828 let k = Keymap::defaults();
812- assert_eq!(k.entries().len(), 35);829+ assert_eq!(k.entries().len(), 37);
813 assert_eq!(k.lookup("space", false), Some(ActionId::Play));830 assert_eq!(k.lookup("space", false), Some(ActionId::Play));
814 // The seek keys: bare arrows a frame, ctrl arrows a second, and the two831 // The seek keys: bare arrows a frame, ctrl arrows a second, and the two
815 // ends of the timeline.832 // ends of the timeline.
@@ -843,6 +860,10 @@ mod tests {
843 // The track keys are the bare letters; the ctrl ones stay copy/paste.860 // The track keys are the bare letters; the ctrl ones stay copy/paste.
844 assert_eq!(k.lookup("v", false), Some(ActionId::AddVideoLane));861 assert_eq!(k.lookup("v", false), Some(ActionId::AddVideoLane));
845 assert_eq!(k.lookup("a", false), Some(ActionId::AddAudioLane));862 assert_eq!(k.lookup("a", false), Some(ActionId::AddAudioLane));
863+ // ...and the ctrl ones take a track away, out of the way of a stray
864+ // press. Ctrl+v is the paste, so the video one sits beside it.
865+ assert_eq!(k.lookup("b", true), Some(ActionId::RemoveVideoLane));
866+ assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane));
846 assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute));867 assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute));
847 assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer));868 assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer));
848 // The volume pair is the unshifted one, so neither needs a modifier869 // The volume pair is the unshifted one, so neither needs a modifier
@@ -1038,7 +1059,7 @@ mod tests {
1038 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");1059 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");
1039 // The label is the editor's column, and never the file's word for it.1060 // The label is the editor's column, and never the file's word for it.
1040 assert_eq!(ActionId::CancelExport.label(), "Cancel export");1061 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
1041- assert_eq!(ActionId::ALL.len(), 33);1062+ assert_eq!(ActionId::ALL.len(), 35);
1042 }1063 }
1043 1064
1044 #[test]1065 #[test]
crates/app/src/main.rsmodified+94 -1
@@ -822,6 +822,11 @@ impl Player {
822 ActionId::Undo => self.undo(cx),822 ActionId::Undo => self.undo(cx),
823 ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx),823 ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx),
824 ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx),824 ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx),
825+ // The last track of that kind: the one the add key put there, so the
826+ // two strokes undo each other press for press. Any other track goes
827+ // through the × in its own header.
828+ ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx),
829+ ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx),
825 ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx),830 ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx),
826 ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx),831 ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx),
827 ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx),832 ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx),
@@ -2397,6 +2402,64 @@ impl Player {
2397 cx.notify();2402 cx.notify();
2398 }2403 }
2399 2404
2405+ /// The × in a track's header: the add taken back, one undo step, and the
2406+ /// engine's own words when it refuses -- those name the clips still on the
2407+ /// track, so the notice says what to delete first. A removal never deletes a
2408+ /// clip.
2409+ ///
2410+ /// Everything holding a `(lane, idx)` is dropped, because the tracks below
2411+ /// the one that went have just moved up an `ord`
2412+ /// ([`engine::Project::remove_lane`]): a selection or an open card kept
2413+ /// across it would be pointing at the *next* track's clip.
2414+ fn remove_lane(&mut self, lane: Lane, cx: &mut Context<Self>) {
2415+ if self.exporting().is_some() {
2416+ return;
2417+ }
2418+ let removed = self
2419+ .session
2420+ .as_mut()
2421+ .map(|session| session.remove_lane(lane));
2422+ let text = match removed {
2423+ Some(Ok(())) => {
2424+ self.selected = None;
2425+ self.context_menu = None;
2426+ self.eq_open = None;
2427+ self.color_open = None;
2428+ self.speed_open = None;
2429+ self.close_silence();
2430+ format!(
2431+ "{} REMOVED — {} brings it back",
2432+ lane.label(),
2433+ self.keymap.display(ActionId::Undo)
2434+ )
2435+ }
2436+ Some(Err(e)) => format!("NO TRACK REMOVED — {e}"),
2437+ None => "NO TRACK REMOVED — open a file first".to_string(),
2438+ };
2439+ self.notice = Some(text.into());
2440+ cx.notify();
2441+ }
2442+
2443+ /// What the remove keys act on: the last track of that kind, which is the
2444+ /// one the matching add key appended. Nothing at all before a file is open,
2445+ /// where the timeline drawn is a placeholder pair.
2446+ fn remove_last_lane(&mut self, kind: LaneKind, cx: &mut Context<Self>) {
2447+ let last = self.session.as_ref().and_then(|session| {
2448+ session
2449+ .lanes()
2450+ .into_iter()
2451+ .filter(|l| l.kind == kind)
2452+ .next_back()
2453+ });
2454+ match last {
2455+ Some(lane) => self.remove_lane(lane, cx),
2456+ None => {
2457+ self.notice = Some("NO TRACK REMOVED — open a file first".into());
2458+ cx.notify();
2459+ }
2460+ }
2461+ }
2462+
2400 fn undo(&mut self, cx: &mut Context<Self>) {2463 fn undo(&mut self, cx: &mut Context<Self>) {
2401 if self.session.as_mut().is_some_and(PlaybackSession::undo) {2464 if self.session.as_mut().is_some_and(PlaybackSession::undo) {
2402 self.reset_after_reseek();2465 self.reset_after_reseek();
@@ -5077,6 +5140,12 @@ impl Player {
5077 });5140 });
5078 let name = lane.label();5141 let name = lane.label();
5079 let row_id: SharedString = format!("{name}-clip").into();5142 let row_id: SharedString = format!("{name}-clip").into();
5143+ let remove_id: SharedString = format!("{name}-remove").into();
5144+ let remove_tip: SharedString = format!(
5145+ "Remove {name} — it must be empty first, and {} brings it back",
5146+ self.keymap.display(ActionId::Undo)
5147+ )
5148+ .into();
5080 let sources = self5149 let sources = self
5081 .session5150 .session
5082 .as_ref()5151 .as_ref()
@@ -5106,13 +5175,37 @@ impl Player {
5106 .w(px(HEADER_W))5175 .w(px(HEADER_W))
5107 .h_full()5176 .h_full()
5108 .flex()5177 .flex()
5178+ .flex_col()
5109 .items_center()5179 .items_center()
5110 .justify_center()5180 .justify_center()
5111 .rounded(px(3.))5181 .rounded(px(3.))
5112 .bg(rgb(SURFACE))5182 .bg(rgb(SURFACE))
5113 .text_size(px(11.))5183 .text_size(px(11.))
5114 .text_color(rgb(INK_DIM))5184 .text_color(rgb(INK_DIM))
5115- .child(name),5185+ .child(div().flex_1().flex().items_center().child(name))
5186+ // The one thing a header does: take this track away again.
5187+ // A `HIT_MIN` target rather than a glyph-sized one, and it
5188+ // stays put on a track holding clips instead of hiding --
5189+ // the refusal names them, and a control that vanishes
5190+ // teaches nothing.
5191+ .child(
5192+ div()
5193+ .id(remove_id)
5194+ .flex_none()
5195+ .w_full()
5196+ .h(px(HIT_MIN))
5197+ .flex()
5198+ .items_center()
5199+ .justify_center()
5200+ .rounded(px(3.))
5201+ .cursor_pointer()
5202+ .hover(|s| s.bg(rgb(HOVER)))
5203+ .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into())
5204+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
5205+ this.remove_lane(lane, cx)
5206+ }))
5207+ .child("×"),
5208+ ),
5116 )5209 )
5117 .child(5210 .child(
5118 // Clips are placed at their own start rather than queued edge5211 // Clips are placed at their own start rather than queued edge
crates/engine/src/playback.rsmodified+7 -0
@@ -876,6 +876,13 @@ impl PlaybackSession {
876 self.project.add_lane(kind)876 self.project.add_lane(kind)
877 }877 }
878 878
879+ /// Drops that empty lane again, in [`Project::remove_lane`]'s words when it
880+ /// refuses. One undo step, and no reseek for the same reason the add needs
881+ /// none: an empty lane was playing nothing.
882+ pub fn remove_lane(&mut self, lane: Lane) -> crate::Result<()> {
883+ self.project.remove_lane(lane)
884+ }
885+
879 /// Splits every lane at `timeline_secs`, so the two sides become two886 /// Splits every lane at `timeline_secs`, so the two sides become two
880 /// groups. Metadata only: a split never changes the timeline->source887 /// groups. Metadata only: a split never changes the timeline->source
881 /// mapping, so the running decoder stays correct and playback does not888 /// mapping, so the running decoder stays correct and playback does not
crates/engine/src/project.rsmodified+108 -0
@@ -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 is730 /// 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> {
@@ -4697,6 +4758,53 @@ mod tests {
4697 assert_eq!(shape(&p), shape(&three()));4758 assert_eq!(shape(&p), shape(&three()));
4698 }4759 }
4699 4760
4761+ /// The add taken back: an empty lane comes off, a lane holding clips never
4762+ /// does (and says which clips), the last lane of a kind never does, the
4763+ /// lanes below the one that went move up an `ord`, and one undo puts it
4764+ /// back where it stood.
4765+ #[test]
4766+ fn an_empty_lane_comes_off_again() {
4767+ let mut p = three();
4768+ let v2 = p.add_lane(LaneKind::Video);
4769+ let v3 = p.add_lane(LaneKind::Video);
4770+ assert!(p.place(v3, 0, clip(0, 0, 3, 0)));
4771+ let why = |r: crate::Result<()>| r.expect_err("refused").to_string();
4772+ let history = p.history.len();
4773+
4774+ // The last lane of its kind stays: `V1`/`A1` are where an import and a
4775+ // paste land, and a project missing one would swallow half of a file
4776+ // dropped on it.
4777+ assert!(why(p.remove_lane(Lane::A1)).contains("only audio track"));
4778+ assert_eq!(
4779+ why(p.remove_lane(Lane::new(LaneKind::Video, 9))),
4780+ "there is no V10 to remove"
4781+ );
4782+
4783+ // A lane with clips on it refuses and names them: a track removal never
4784+ // deletes a take.
4785+ let refusal = why(p.remove_lane(v3));
4786+ assert!(refusal.contains("V3 still holds"), "{refusal}");
4787+ assert!(refusal.contains(FILE), "{refusal}");
4788+ assert!(refusal.contains("at frame 0"), "{refusal}");
4789+ assert_eq!(p.lane_spans(v3), vec![(0, 3)], "the clip is still there");
4790+ assert_eq!(p.history.len(), history, "a refusal snapshots nothing");
4791+
4792+ // The empty one in the middle goes, and `V3` becomes `V2` -- clip and
4793+ // all.
4794+ p.remove_lane(v2).expect("V2 is empty");
4795+ assert_eq!(p.lane_count(LaneKind::Video), 2);
4796+ assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2]);
4797+ assert_eq!(p.lane_spans(v2), vec![(0, 3)], "the lane below moved up");
4798+ assert_eq!(p.history.len(), history + 1, "one snapshot per removal");
4799+ invariants_hold(&p, "remove V2");
4800+
4801+ // ...and one stroke puts the empty lane back above it.
4802+ assert!(p.undo());
4803+ assert_eq!(p.lane_count(LaneKind::Video), 3);
4804+ assert!(p.lane(v2).is_empty(), "back where it stood, still empty");
4805+ assert_eq!(p.lane_spans(v3), vec![(0, 3)]);
4806+ }
4807+
4700 /// The grouping rule across more than two lanes: a link id is one *span*,4808 /// 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 a4809 /// 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 half4810 /// pairing by `ord`. So a split shares an id with every lane whose half