forge
Explore
Log in

Don't you dare go Hollow

Every lane draws and tracks can be added

Browse files at this commit

30e8aaed5edc9d47f67c475db3fe32cae0631563Ahmet Kaan GümüşParent: 2c7cf37
  • feat
    • every lane draws and tracks can be added
Show full message
✨ feat(timeline): every lane draws and tracks can be added

The panel drew V1 and A1 and nothing else, so the N-lane model, the
composite playback and the v6 format had no way into the window. It now
draws a row per project lane, labelled from Lane::label, and grows the
panel per row up to a cap past which the lane column scrolls.

+ V / + A -- and the v / a chords, in the registry so the keys menu lists
them -- add a track; undo takes one back like any other edit.

The V1/A1 pinning the last two slices flagged is gone: delete_clip takes
the lane its index belongs to (Project::delete_in), a drop names the lane
it was let go over (place_stream_at's onto), and whole_take decides
ripple-or-lift per lane -- a clip on an added track is a layer and is
lifted, while the first pair keeps exactly the semantics it had.
Project::paste now inserts into V1/A1 only while still opening room
everywhere, or an Add with three lanes would have played one sound twice.

The export card greys MP4 out with its reason when more than one audio
lane carries sound, on the row and on the m chord both, so the engine's
refusal arrives before a destination is picked.
crates/app/src/keymap.rsmodified+24 -4
@@ -48,6 +48,8 @@ pub enum ActionId {
48 Delete,48 Delete,
49 Lift,49 Lift,
50 Undo,50 Undo,
51+ AddVideoLane,
52+ AddAudioLane,
51 ToggleMute,53 ToggleMute,
52 VolumeUp,54 VolumeUp,
53 VolumeDown,55 VolumeDown,
@@ -57,7 +59,7 @@ pub enum ActionId {
57 impl ActionId {59 impl ActionId {
58 /// Display order everywhere -- the editor lists them in it and60 /// Display order everywhere -- the editor lists them in it and
59 /// [`Keymap::defaults`] binds them in it.61 /// [`Keymap::defaults`] binds them in it.
60- pub const ALL: [ActionId; 14] = [62+ pub const ALL: [ActionId; 16] = [
61 ActionId::Play,63 ActionId::Play,
62 ActionId::Export,64 ActionId::Export,
63 ActionId::Save,65 ActionId::Save,
@@ -68,6 +70,8 @@ impl ActionId {
68 ActionId::Delete,70 ActionId::Delete,
69 ActionId::Lift,71 ActionId::Lift,
70 ActionId::Undo,72 ActionId::Undo,
73+ ActionId::AddVideoLane,
74+ ActionId::AddAudioLane,
71 ActionId::ToggleMute,75 ActionId::ToggleMute,
72 ActionId::VolumeUp,76 ActionId::VolumeUp,
73 ActionId::VolumeDown,77 ActionId::VolumeDown,
@@ -87,6 +91,8 @@ impl ActionId {
87 ActionId::Delete => "Delete",91 ActionId::Delete => "Delete",
88 ActionId::Lift => "Lift (leave a gap)",92 ActionId::Lift => "Lift (leave a gap)",
89 ActionId::Undo => "Undo",93 ActionId::Undo => "Undo",
94+ ActionId::AddVideoLane => "Add a video track",
95+ ActionId::AddAudioLane => "Add an audio track",
90 ActionId::ToggleMute => "Mute / Unmute",96 ActionId::ToggleMute => "Mute / Unmute",
91 ActionId::VolumeUp => "Volume up",97 ActionId::VolumeUp => "Volume up",
92 ActionId::VolumeDown => "Volume down",98 ActionId::VolumeDown => "Volume down",
@@ -108,6 +114,8 @@ impl ActionId {
108 ActionId::Delete => "delete",114 ActionId::Delete => "delete",
109 ActionId::Lift => "lift",115 ActionId::Lift => "lift",
110 ActionId::Undo => "undo",116 ActionId::Undo => "undo",
117+ ActionId::AddVideoLane => "add-video-lane",
118+ ActionId::AddAudioLane => "add-audio-lane",
111 ActionId::ToggleMute => "toggle-mute",119 ActionId::ToggleMute => "toggle-mute",
112 ActionId::VolumeUp => "volume-up",120 ActionId::VolumeUp => "volume-up",
113 ActionId::VolumeDown => "volume-down",121 ActionId::VolumeDown => "volume-down",
@@ -126,7 +134,11 @@ impl ActionId {
126 match self {134 match self {
127 ActionId::Play => Category::Playback,135 ActionId::Play => Category::Playback,
128 ActionId::Copy | ActionId::Paste | ActionId::Delete | ActionId::Lift => Category::Clips,136 ActionId::Copy | ActionId::Paste | ActionId::Delete | ActionId::Lift => Category::Clips,
129- ActionId::Cut | ActionId::Regroup | ActionId::Undo => Category::Editing,137+ ActionId::Cut
138+ | ActionId::Regroup
139+ | ActionId::Undo
140+ | ActionId::AddVideoLane
141+ | ActionId::AddAudioLane => Category::Editing,
130 ActionId::ToggleMute | ActionId::VolumeUp | ActionId::VolumeDown => Category::Audio,142 ActionId::ToggleMute | ActionId::VolumeUp | ActionId::VolumeDown => Category::Audio,
131 ActionId::Save | ActionId::Export | ActionId::CancelExport => Category::File,143 ActionId::Save | ActionId::Export | ActionId::CancelExport => Category::File,
132 }144 }
@@ -310,6 +322,11 @@ impl Keymap {
310 b(ActionId::Lift, "l", false),322 b(ActionId::Lift, "l", false),
311 b(ActionId::Undo, "z", false),323 b(ActionId::Undo, "z", false),
312 b(ActionId::Undo, "z", true),324 b(ActionId::Undo, "z", true),
325+ // The unshifted initials of what they add. Both were free --
326+ // the copy and paste chords are the *ctrl* ones -- and a track
327+ // is added often enough to deserve a key that is one press.
328+ b(ActionId::AddVideoLane, "v", false),
329+ b(ActionId::AddAudioLane, "a", false),
313 b(ActionId::ToggleMute, "m", false),330 b(ActionId::ToggleMute, "m", false),
314 // The unshifted pair, which is what gpui reports for those two331 // The unshifted pair, which is what gpui reports for those two
315 // keys ("=" and "-", platform.rs:862): the volume keys every332 // keys ("=" and "-", platform.rs:862): the volume keys every
@@ -542,7 +559,7 @@ mod tests {
542 #[test]559 #[test]
543 fn every_default_stroke_reaches_its_action() {560 fn every_default_stroke_reaches_its_action() {
544 let k = Keymap::defaults();561 let k = Keymap::defaults();
545- assert_eq!(k.entries().len(), 16);562+ assert_eq!(k.entries().len(), 18);
546 assert_eq!(k.lookup("space", false), Some(ActionId::Play));563 assert_eq!(k.lookup("space", false), Some(ActionId::Play));
547 assert_eq!(k.lookup("e", false), Some(ActionId::Export));564 assert_eq!(k.lookup("e", false), Some(ActionId::Export));
548 assert_eq!(k.lookup("s", true), Some(ActionId::Save));565 assert_eq!(k.lookup("s", true), Some(ActionId::Save));
@@ -555,6 +572,9 @@ mod tests {
555 assert_eq!(k.lookup("l", false), Some(ActionId::Lift));572 assert_eq!(k.lookup("l", false), Some(ActionId::Lift));
556 assert_eq!(k.lookup("z", false), Some(ActionId::Undo));573 assert_eq!(k.lookup("z", false), Some(ActionId::Undo));
557 assert_eq!(k.lookup("z", true), Some(ActionId::Undo));574 assert_eq!(k.lookup("z", true), Some(ActionId::Undo));
575+ // The track keys are the bare letters; the ctrl ones stay copy/paste.
576+ assert_eq!(k.lookup("v", false), Some(ActionId::AddVideoLane));
577+ assert_eq!(k.lookup("a", false), Some(ActionId::AddAudioLane));
558 assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute));578 assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute));
559 // The volume pair is the unshifted one, so neither needs a modifier579 // The volume pair is the unshifted one, so neither needs a modifier
560 // and neither is the "+" gpui reports for shift+=.580 // and neither is the "+" gpui reports for shift+=.
@@ -689,7 +709,7 @@ mod tests {
689 );709 );
690 // The label is the editor's column, and never the file's word for it.710 // The label is the editor's column, and never the file's word for it.
691 assert_eq!(ActionId::CancelExport.label(), "Cancel export");711 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
692- assert_eq!(ActionId::ALL.len(), 14);712+ assert_eq!(ActionId::ALL.len(), 16);
693 }713 }
694 714
695 #[test]715 #[test]
crates/app/src/main.rsmodified+307 -70
@@ -50,6 +50,10 @@ const HEADER_H: f32 = 32.;
50 // between them, with a few px of slack so a taller text line cannot push a lane50 // between them, with a few px of slack so a taller text line cannot push a lane
51 // off the bottom.51 // off the bottom.
52 const PANEL_H: f32 = 220.;52 const PANEL_H: f32 = 220.;
53+/// How many lane rows are drawn before the lane column starts scrolling: past
54+/// this the panel would be taller than the picture it belongs under, and a
55+/// timeline that pushes the video off the window is not a timeline.
56+const LANES_MAX: usize = 6;
53 const LANE_H: f32 = 48.;57 const LANE_H: f32 = 48.;
54 /// The lane header column: wide enough for `V1`/`A1` and fixed, so both lanes58 /// The lane header column: wide enough for `V1`/`A1` and fixed, so both lanes
55 /// and the ruler above them start at the same pixel and are the same width --59 /// and the ruler above them start at the same pixel and are the same width --
@@ -428,6 +432,8 @@ impl Player {
428 ActionId::Delete => self.delete_selected(cx),432 ActionId::Delete => self.delete_selected(cx),
429 ActionId::Lift => self.lift_selected(cx),433 ActionId::Lift => self.lift_selected(cx),
430 ActionId::Undo => self.undo(cx),434 ActionId::Undo => self.undo(cx),
435+ ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx),
436+ ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx),
431 ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx),437 ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx),
432 ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx),438 ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx),
433 ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx),439 ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx),
@@ -502,32 +508,20 @@ impl Player {
502 return;508 return;
503 }509 }
504 let selected = self.selected.take();510 let selected = self.selected.take();
505- // Exhaustive over the kind, and explicit about the ord: both engine511+ // Whichever lane it was clicked in: the index is that lane's own, and
506- // calls below take a *first*-lane index (`delete_clip` deletes the V1512+ // the ripple cuts the clip's span out of every lane -- a group covers
507- // clip at `idx`, `video_half` reads A1), so a selection on a second513+ // one span, so deleting a take by its audio half is the same edit as by
508- // lane of either kind would delete a different clip than the one514+ // its picture. What is not a whole take is lifted instead, which is what
509- // clicked. It is refused by name until the add-track slice teaches515+ // reaches a clip on an added track ([`whole_take`]).
510- // those two a lane -- a wildcard here would drop it silently.
511 let deleted = match (&mut self.session, selected) {516 let deleted = match (&mut self.session, selected) {
512- (Some(session), Some((lane, idx))) if lane.ord == 0 => match lane.kind {517+ (Some(session), Some((lane, idx))) => match whole_take(session, lane, idx) {
513- LaneKind::Video => session.delete_clip(idx),518+ true => session.delete_clip(lane, idx),
514- LaneKind::Audio => match video_half(session, idx) {519+ false => session.lift_clip(lane, idx),
515- Some(video) => session.delete_clip(video),
516- None => session.lift_clip(lane, idx),
517- },
518 },520 },
519 _ => false,521 _ => false,
520 };522 };
521- if let Some((lane, _)) = selected.filter(|_| !deleted) {523+ if selected.is_some() && !deleted {
522- if lane.ord > 0 {524+ self.notice = Some("NOTHING DELETED — the timeline cannot be emptied".into());
523- self.notice = Some(
524- format!(
525- "NOTHING DELETED — delete does not reach {} yet",
526- lane.label()
527- )
528- .into(),
529- );
530- }
531 }525 }
532 if deleted {526 if deleted {
533 self.reset_after_reseek();527 self.reset_after_reseek();
@@ -677,14 +671,15 @@ impl Player {
677 if self.exporting().is_some() {671 if self.exporting().is_some() {
678 return;672 return;
679 }673 }
680- // A file with no picture belongs on the audio lane and nowhere else:674+ // A file with no picture belongs on an audio lane and nowhere else:
681- // dropped on the video lane it is refused by name, and asked for by the675+ // dropped on a video lane it is refused by name, and asked for by the
682 // Add button (which names no lane) it goes to the audio one -- which is676 // Add button (which names no lane) it goes to the audio one -- which is
683 // the engine's choice, in `place_stream_at`, not one made twice here.677 // the engine's choice, in `place_stream_at`, not one made twice here.
684- if engine::is_audio(path) && onto == Some(Lane::V1) {678+ if engine::is_audio(path) && onto.is_some_and(|lane| lane.kind == LaneKind::Video) {
685 let name = file_name(path);679 let name = file_name(path);
680+ let lane = onto.expect("checked above").label();
686 self.notice = Some(681 self.notice = Some(
687- format!("NOT ON THE VIDEO LANE — {name} has no picture; drop it on A1").into(),682+ format!("NOT ON {lane} — {name} has no picture; drop it on an audio lane").into(),
688 );683 );
689 cx.notify();684 cx.notify();
690 return;685 return;
@@ -696,7 +691,9 @@ impl Player {
696 // -- an undone import leaves the source entry behind (project.rs:264)691 // -- an undone import leaves the source entry behind (project.rs:264)
697 // -- so there is no length to insert and no file to ask for one.692 // -- so there is no length to insert and no file to ask for one.
698 let placed = match (&mut self.session, frames) {693 let placed = match (&mut self.session, frames) {
699- (Some(session), 1..) => session.place_stream_at(session.now(), path, stream, frames),694+ (Some(session), 1..) => {
695+ session.place_stream_at(session.now(), path, stream, frames, onto)
696+ }
700 _ => Ok(false),697 _ => Ok(false),
701 };698 };
702 match placed {699 match placed {
@@ -875,6 +872,31 @@ impl Player {
875 cx.notify();872 cx.notify();
876 }873 }
877 874
875+ /// A new empty track under the ones already there. One undo step in the
876+ /// engine, so the stroke that takes back an edit takes back a track too, and
877+ /// no reseek: nothing plays differently until something is dropped on it.
878+ /// The selection stays -- the lanes it indexes into have not moved.
879+ fn add_lane(&mut self, kind: LaneKind, cx: &mut Context<Self>) {
880+ if self.exporting().is_some() {
881+ return;
882+ }
883+ match &mut self.session {
884+ Some(session) => {
885+ let lane = session.add_lane(kind);
886+ self.notice = Some(
887+ format!(
888+ "{} ADDED — drag a clip onto it, {} takes it back",
889+ lane.label(),
890+ self.keymap.display(ActionId::Undo)
891+ )
892+ .into(),
893+ );
894+ }
895+ None => self.notice = Some("NO TRACK ADDED — open a file first".into()),
896+ }
897+ cx.notify();
898+ }
899+
878 fn undo(&mut self, cx: &mut Context<Self>) {900 fn undo(&mut self, cx: &mut Context<Self>) {
879 if self.session.as_mut().is_some_and(PlaybackSession::undo) {901 if self.session.as_mut().is_some_and(PlaybackSession::undo) {
880 self.reset_after_reseek();902 self.reset_after_reseek();
@@ -998,6 +1020,12 @@ impl Player {
998 /// written to a path ending in `.mp4` is a file every player will lie1020 /// written to a path ending in `.mp4` is a file every player will lie
999 /// about -- keeping whatever stem the save dialog last left there.1021 /// about -- keeping whatever stem the save dialog last left there.
1000 fn set_format(&mut self, format: Format) {1022 fn set_format(&mut self, format: Format) {
1023+ // The one door both the row and its initial go through, so a format the
1024+ // card greys out cannot be picked by keyboard either.
1025+ if let (Format::Mp4, Some(why)) = (format, self.session.as_ref().and_then(mp4_refusal)) {
1026+ self.notice = Some(format!("NOT MP4 — {why}").into());
1027+ return;
1028+ }
1001 self.format = format;1029 self.format = format;
1002 self.export_path = retarget(&self.export_path, format);1030 self.export_path = retarget(&self.export_path, format);
1003 }1031 }
@@ -1591,6 +1619,18 @@ impl Player {
1591 // open they are dimmed rather than silently doing nothing.1619 // open they are dimmed rather than silently doing nothing.
1592 let live = self.session.is_some() && !exporting;1620 let live = self.session.is_some() && !exporting;
1593 let key = |action| self.keymap.display(action);1621 let key = |action| self.keymap.display(action);
1622+ // The lanes the project has, or the pair a fresh one starts with so the
1623+ // panel reads the same before a file is open as after.
1624+ let lanes = self
1625+ .session
1626+ .as_ref()
1627+ .map_or_else(|| vec![Lane::V1, Lane::A1], PlaybackSession::lanes);
1628+ // A loop rather than a `map`: each row takes `cx` in turn, where a
1629+ // closure would hold it for as long as the iterator lives.
1630+ let mut rows = Vec::new();
1631+ for &lane in &lanes {
1632+ rows.push(self.lane_row(lane, duration, filled, cx));
1633+ }
1594 let (hint, filled) = if let Some(export) = self.exporting() {1634 let (hint, filled) = if let Some(export) = self.exporting() {
1595 let progress = export.progress();1635 let progress = export.progress();
1596 (1636 (
@@ -1618,7 +1658,7 @@ impl Player {
1618 };1658 };
1619 div()1659 div()
1620 .flex_none()1660 .flex_none()
1621- .h(px(PANEL_H))1661+ .h(px(panel_h(lanes.len())))
1622 .flex()1662 .flex()
1623 .flex_col()1663 .flex_col()
1624 .gap(px(8.))1664 .gap(px(8.))
@@ -1665,6 +1705,36 @@ impl Player {
1665 live && self.selected.is_some(),1705 live && self.selected.is_some(),
1666 cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)),1706 cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)),
1667 ))1707 ))
1708+ // With the edit group, beside the buttons that change the
1709+ // edit list: a track is a row of it, and adding one is an
1710+ // undoable edit like the rest. Two buttons rather than one
1711+ // with a choice, because the choice is the whole action.
1712+ .child(control(
1713+ "add-video-lane",
1714+ None,
1715+ "+ V",
1716+ format!(
1717+ "{} — adds a video track under the ones there",
1718+ key(ActionId::AddVideoLane)
1719+ ),
1720+ live,
1721+ cx.listener(|this, _: &ClickEvent, _, cx| {
1722+ this.add_lane(LaneKind::Video, cx)
1723+ }),
1724+ ))
1725+ .child(control(
1726+ "add-audio-lane",
1727+ None,
1728+ "+ A",
1729+ format!(
1730+ "{} — adds an audio track under the ones there",
1731+ key(ActionId::AddAudioLane)
1732+ ),
1733+ live,
1734+ cx.listener(|this, _: &ClickEvent, _, cx| {
1735+ this.add_lane(LaneKind::Audio, cx)
1736+ }),
1737+ ))
1668 // With the transport, not the edit group: it changes what1738 // With the transport, not the edit group: it changes what
1669 // the file sounds like, never what it is. Reads as its own1739 // the file sounds like, never what it is. Reads as its own
1670 // state, so muted is legible without a tooltip.1740 // state, so muted is legible without a tooltip.
@@ -1799,8 +1869,22 @@ impl Player {
1799 ),1869 ),
1800 ),1870 ),
1801 )1871 )
1802- .child(self.lane_row(Lane::V1, "V1", duration, filled, cx))1872+ // Every lane the project has, in its own order -- and its own
1803- .child(self.lane_row(Lane::A1, "A1", duration, filled, cx))1873+ // column, so a project with more lanes than the panel is tall
1874+ // scrolls its tracks instead of pushing the picture off the window.
1875+ // The gap is the panel's own, so two lanes lay out exactly as they
1876+ // did when they were two children of it.
1877+ .child(
1878+ div()
1879+ .id("lanes")
1880+ .flex_none()
1881+ .flex()
1882+ .flex_col()
1883+ .gap(px(8.))
1884+ .max_h(px(lanes_h(LANES_MAX)))
1885+ .overflow_y_scroll()
1886+ .children(rows),
1887+ )
1804 }1888 }
1805 1889
1806 /// A notice holds its own bar, full width, until it is answered: any key1890 /// A notice holds its own bar, full width, until it is answered: any key
@@ -2027,11 +2111,21 @@ impl Player {
2027 };2111 };
2028 // The formats first: the quality rows below are *video* bitrate, so2112 // The formats first: the quality rows below are *video* bitrate, so
2029 // which file is being written decides whether they mean anything.2113 // which file is being written decides whether they mean anything.
2114+ // An mp4 this timeline cannot be written as reads exactly like the
2115+ // formats there is no encoder for: dimmed, unclickable, and carrying its
2116+ // own reason instead of the detail line.
2117+ let refused = self.session.as_ref().and_then(mp4_refusal);
2030 let formats: Vec<_> = FORMATS2118 let formats: Vec<_> = FORMATS
2031 .into_iter()2119 .into_iter()
2032 .enumerate()2120 .enumerate()
2033 .map(|(i, (format, label, detail))| {2121 .map(|(i, (format, label, detail))| {
2034- let picked = format == Some(self.format);2122+ let blocked = format == Some(Format::Mp4) && refused.is_some();
2123+ let detail: SharedString = match &refused {
2124+ Some(why) if blocked => why.clone().into(),
2125+ _ => detail.into(),
2126+ };
2127+ let picked = format == Some(self.format) && !blocked;
2128+ let format = format.filter(|_| !blocked);
2035 live(row(("format", i)), format.is_some())2129 live(row(("format", i)), format.is_some())
2036 .when(picked, |d| d.bg(rgb(SELECTED)))2130 .when(picked, |d| d.bg(rgb(SELECTED)))
2037 .when_some(format, |d, format| {2131 .when_some(format, |d, format| {
@@ -2363,27 +2457,36 @@ impl Player {
2363 fn lane_row(2457 fn lane_row(
2364 &self,2458 &self,
2365 lane: Lane,2459 lane: Lane,
2366- name: &'static str,
2367 duration: f64,2460 duration: f64,
2368 filled: f32,2461 filled: f32,
2369 cx: &mut Context<Self>,2462 cx: &mut Context<Self>,
2370- ) -> impl IntoElement {2463+ // Borrows nothing it was given (`use<>`): the rows are built one after
2464+ // another into a list, and a row still holding `cx` would be the only
2465+ // one that could be built.
2466+ ) -> impl IntoElement + use<> {
2371 // The bed's own width, measured last repaint off the ruler's bar: the2467 // The bed's own width, measured last repaint off the ruler's bar: the
2372 // two are laid out identically (same header offset, same `flex_1`), so2468 // two are laid out identically (same header offset, same `flex_1`), so
2373 // one probe answers for both. Zero before the first paint, which only2469 // one probe answers for both. Zero before the first paint, which only
2374 // costs the labels one frame.2470 // costs the labels one frame.
2375 let bed_w = f32::from(self.ruler.get().size.width);2471 let bed_w = f32::from(self.ruler.get().size.width);
2376- let (clips, others) = match &self.session {2472+ let clips = self
2377- Some(session) => (2473+ .session
2378- session.lane_clips(lane),2474+ .as_ref()
2379- session.lane_clips(if lane.kind == LaneKind::Video {2475+ .map_or(&[][..], |session| session.lane_clips(lane));
2380- Lane::A12476+ // The group ids some *other* lane carries: a clip whose id is in here
2381- } else {2477+ // has a half elsewhere, and one whose is not is a detached half however
2382- Lane::V12478+ // many lanes there are.
2383- }),2479+ let others: Vec<u32> = self.session.as_ref().map_or_else(Vec::new, |session| {
2384- ),2480+ session
2385- None => (&[][..], &[][..]),2481+ .lanes()
2386- };2482+ .into_iter()
2483+ .filter(|&other| other != lane)
2484+ .flat_map(|other| session.lane_clips(other))
2485+ .filter_map(|clip| clip.link)
2486+ .collect()
2487+ });
2488+ let name = lane.label();
2489+ let row_id: SharedString = format!("{name}-clip").into();
2387 let sources = self2490 let sources = self
2388 .session2491 .session
2389 .as_ref()2492 .as_ref()
@@ -2447,8 +2550,7 @@ impl Player {
2447 // A group with a half in the other lane wears its tint;2550 // A group with a half in the other lane wears its tint;
2448 // one without is outlined, so a detached half is visible2551 // one without is outlined, so a detached half is visible
2449 // as detached before anyone clicks it.2552 // as detached before anyone clicks it.
2450- let grouped =2553+ let grouped = clip.link.is_some_and(|link| others.contains(&link));
2451- clip.link.is_some() && others.iter().any(|o| o.link == clip.link);
2452 // Tinted by *file*, not by source entry: two audio2554 // Tinted by *file*, not by source entry: two audio
2453 // streams of one file are two sources, and the library2555 // streams of one file are two sources, and the library
2454 // gives them one swatch because they are one file.2556 // gives them one swatch because they are one file.
@@ -2470,7 +2572,9 @@ impl Player {
2470 );2572 );
2471 let tip = tip.clone();2573 let tip = tip.clone();
2472 div()2574 div()
2473- .id((if audio { "aclip" } else { "vclip" }, i))2575+ // Named per lane: two rows numbering their clips
2576+ // from zero would hand gpui the same id twice.
2577+ .id((row_id.clone(), i))
2474 .absolute()2578 .absolute()
2475 .top_0()2579 .top_0()
2476 .h_full()2580 .h_full()
@@ -2708,12 +2812,14 @@ fn unseen_paths(sources: &[Source], streams: &HashMap<PathBuf, Vec<StreamInfo>>)
2708 out2812 out
2709 }2813 }
2710 2814
2711-/// Both lanes' clips, which is everything the timeline knows about its sources.2815+/// Every lane's clips, which is everything the timeline knows about its sources.
2816+/// Every lane, not the first two: a clip that plays only on `V2` is still a clip
2817+/// the source is used by, and a walk that missed it would call the file unused.
2712 fn lane_clips(session: &PlaybackSession) -> impl Iterator<Item = &Clip> {2818 fn lane_clips(session: &PlaybackSession) -> impl Iterator<Item = &Clip> {
2713 session2819 session
2714- .lane_clips(Lane::V1)2820+ .lanes()
2715- .iter()2821+ .into_iter()
2716- .chain(session.lane_clips(Lane::A1))2822+ .flat_map(|lane| session.lane_clips(lane))
2717 }2823 }
2718 2824
2719 /// How long a source is, as the timeline knows it: the furthest frame any clip2825 /// How long a source is, as the timeline knows it: the furthest frame any clip
@@ -3121,6 +3227,37 @@ fn is_bare_modifier(key: &str) -> bool {
3121 3227
3122 /// A clip's share of the lane. A timeline with no length reads as one full-width3228 /// A clip's share of the lane. A timeline with no length reads as one full-width
3123 /// box rather than as NaN, which gpui would carry into layout.3229 /// box rather than as NaN, which gpui would carry into layout.
3230+/// Why this timeline cannot be written as an mp4, if it cannot: the mp4 path
3231+/// *copies* one AAC track and there is no encoder here to mix several with, so a
3232+/// timeline whose sound is spread over more than one audio lane is refused by
3233+/// the engine (`export::run`). Said on the row, before a destination has been
3234+/// picked, rather than after the write has started.
3235+fn mp4_refusal(session: &PlaybackSession) -> Option<String> {
3236+ let lanes = session
3237+ .lanes()
3238+ .into_iter()
3239+ .filter(|&lane| lane.kind == LaneKind::Audio && !session.lane_clips(lane).is_empty())
3240+ .count();
3241+ (lanes > 1).then(|| format!("{lanes} audio lanes — an mp4 copies one"))
3242+}
3243+
3244+/// How tall a column of `lanes` rows is, gaps included -- the panel's own gap
3245+/// between them, since the rows sit in it.
3246+fn lanes_h(lanes: usize) -> f32 {
3247+ match lanes {
3248+ 0 => 0.,
3249+ n => n as f32 * LANE_H + (n - 1) as f32 * 8.,
3250+ }
3251+}
3252+
3253+/// How tall the panel is with `lanes` tracks in it: [`PANEL_H`] is sized for the
3254+/// two a project starts with, and every further one adds its own row -- up to
3255+/// [`LANES_MAX`], past which the lane column scrolls instead and the panel stops
3256+/// growing.
3257+fn panel_h(lanes: usize) -> f32 {
3258+ PANEL_H + lanes_h(lanes.clamp(2, LANES_MAX)) - lanes_h(2)
3259+}
3260+
3124 fn width_frac(len: f64, total: f64) -> f32 {3261 fn width_frac(len: f64, total: f64) -> f32 {
3125 if total > 0. { (len / total) as f32 } else { 1. }3262 if total > 0. { (len / total) as f32 } else { 1. }
3126 }3263 }
@@ -3136,15 +3273,31 @@ fn start_frac(start: f64, total: f64) -> f32 {
3136 }3273 }
3137 }3274 }
3138 3275
3139-/// The video-lane index of the take an audio clip belongs to, if the video lane3276+/// Whether this clip is a whole take, i.e. whether deleting it may close the
3140-/// still holds that half. `None` for a half whose picture was lifted -- which is3277+/// hole under it: a take is what the first pair of lanes carries between them,
3141-/// what makes it a thing of its own to delete.3278+/// `V1`'s picture and the sound grouped with it, and dropping one moves the
3142-fn video_half(session: &PlaybackSession, audio: usize) -> Option<usize> {3279+/// frames after it on every lane.
3143- let link = session.lane_clips(Lane::A1).get(audio)?.link?;3280+///
3144- session3281+/// Everything else is a half or a layer, and is *lifted* instead: a half whose
3145- .lane_clips(Lane::V1)3282+/// picture was lifted (what a lift leaves behind) has no take to ripple, and a
3146- .iter()3283+/// clip on a further lane is laid over the timeline rather than part of it --
3147- .position(|clip| clip.link == Some(link))3284+/// closing a hole under it would drag the take beneath out of step with it.
3285+fn whole_take(session: &PlaybackSession, lane: Lane, idx: usize) -> bool {
3286+ let Some(clip) = session.lane_clips(lane).get(idx) else {
3287+ return false;
3288+ };
3289+ match (lane.kind, lane.ord) {
3290+ (_, 1..) => false,
3291+ (LaneKind::Video, _) => true,
3292+ // The sound of a take, only while the take is still there: its group is
3293+ // carried by a clip on some other lane.
3294+ (LaneKind::Audio, _) => session
3295+ .lanes()
3296+ .into_iter()
3297+ .filter(|&other| other != lane)
3298+ .flat_map(|other| session.lane_clips(other))
3299+ .any(|o| o.link.is_some() && o.link == clip.link),
3300+ }
3148 }3301 }
3149 3302
3150 /// Whether a click marks this clip: the clip that was clicked always, and the3303 /// Whether a click marks this clip: the clip that was clicked always, and the
@@ -3428,14 +3581,14 @@ fn timecode(t: f64, fps: f64) -> String {
3428 mod tests {3581 mod tests {
3429 use super::{3582 use super::{
3430 ACCENT, CONTROL_H, Clip, EXPORT_ROWS_H, FORMATS, Format, HEADER_GAP, HEADER_W, HIT_MIN,3583 ACCENT, CONTROL_H, Clip, EXPORT_ROWS_H, FORMATS, Format, HEADER_GAP, HEADER_W, HIT_MIN,
3431- INK, INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LETTERBOX,3584+ INK, INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX,
3432- LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H,3585+ LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_W, NO_FILE, PANEL_H,
3433- RULER_HIT_H, SELECTED, SOURCE_TINTS, SURFACE, SWATCH_W, Source, StreamInfo, Volume,3586+ Quality, ROW_H, RULER_HIT_H, SELECTED, SOURCE_TINTS, SURFACE, SWATCH_W, Source, StreamInfo,
3434- WAVE_BPS, WAVE_COL, Wave, applicable, can_add, cancels_export, envelope, export_path,3587+ Volume, WAVE_BPS, WAVE_COL, Wave, applicable, can_add, cancels_export, envelope,
3435- export_settings, format_line, frac_along, frame_at, is_bare_modifier, is_project, keymap,3588+ export_path, export_settings, format_line, frac_along, frame_at, is_bare_modifier,
3436- lane_clips, marked, menu_at, normalise, project_path, push_digit, retarget, scrub_due,3589+ is_project, keymap, lane_clips, lanes_h, marked, menu_at, mp4_refusal, normalise, panel_h,
3437- show_label, source_frames, source_tint, start_frac, timecode, unseen_paths, unseen_sources,3590+ project_path, push_digit, retarget, scrub_due, show_label, source_frames, source_tint,
3438- width_frac, window_title,3591+ start_frac, timecode, unseen_paths, unseen_sources, whole_take, width_frac, window_title,
3439 };3592 };
3440 use super::{file_name, library_rows};3593 use super::{file_name, library_rows};
3441 use engine::PlaybackSession;3594 use engine::PlaybackSession;
@@ -3740,7 +3893,7 @@ mod tests {
3740 // stream: the button, the drop and this are one call.3893 // stream: the button, the drop and this are one call.
3741 assert!(3894 assert!(
3742 session3895 session
3743- .place_stream_at(2.0, &second, 0, frames)3896+ .place_stream_at(2.0, &second, 0, frames, None)
3744 .expect("av2 is already on the timeline")3897 .expect("av2 is already on the timeline")
3745 );3898 );
3746 // The whole of source 1 went in and nothing was painted over: the3899 // The whole of source 1 went in and nothing was painted over: the
@@ -3772,7 +3925,7 @@ mod tests {
3772 let end = session.timeline_duration();3925 let end = session.timeline_duration();
3773 assert!(3926 assert!(
3774 session3927 session
3775- .place_stream_at(end, &path, 1, frames)3928+ .place_stream_at(end, &path, 1, frames, None)
3776 .expect("the French track shares the timeline's parameters")3929 .expect("the French track shares the timeline's parameters")
3777 );3930 );
3778 assert_eq!(session.sources()[1].audio_stream, 1);3931 assert_eq!(session.sources()[1].audio_stream, 1);
@@ -3785,6 +3938,74 @@ mod tests {
3785 );3938 );
3786 }3939 }
3787 3940
3941+ /// The add-a-track path end to end through the doors the buttons and the
3942+ /// drop use: `+ V` adds a row, a library row let go over it lands there and
3943+ /// nowhere else, Delete on it leaves the lanes under it where they are, and
3944+ /// undo takes the whole thing back one step at a time.
3945+ #[test]
3946+ fn a_track_can_be_added_dropped_on_edited_and_taken_back() {
3947+ use engine::project::LaneKind;
3948+
3949+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
3950+ session.set_gain(0.0);
3951+ assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1]);
3952+ // What the `+ V` button asks for, and what the row it draws is called.
3953+ let v2 = session.add_lane(LaneKind::Video);
3954+ assert_eq!(v2.label(), "V2");
3955+ assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1, v2]);
3956+ assert!(session.lane_clips(v2).is_empty());
3957+ // A library row let go over that row: the same door the Add button
3958+ // uses, told which lane it was let go over.
3959+ let path = session.sources()[0].path.clone();
3960+ let frames = source_frames(lane_clips(&session), session.sources(), &path);
3961+ assert!(
3962+ session
3963+ .place_stream_at(1.0, &path, 0, frames, Some(v2))
3964+ .expect("its own file is on this timeline")
3965+ );
3966+ assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2");
3967+ assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead");
3968+ // And nowhere else: the first pair is exactly as it was, one take each.
3969+ assert_eq!(session.lane_clips(Lane::V1).len(), 1);
3970+ assert_eq!(session.lane_clips(Lane::A1).len(), 1);
3971+ // Delete on the layer is a lift: it is laid over the timeline, so
3972+ // closing a hole under it would drag the take beneath out of step with
3973+ // it. The take on the first pair is still a take, and still ripples.
3974+ assert!(!whole_take(&session, v2, 0));
3975+ assert!(whole_take(&session, Lane::V1, 0));
3976+ assert!(whole_take(&session, Lane::A1, 0));
3977+ assert!(session.lift_clip(v2, 0));
3978+ assert!(session.lane_clips(v2).is_empty());
3979+ assert_eq!(session.lane_clips(Lane::V1).len(), 1, "V1 stayed put");
3980+
3981+ // A second audio lane carrying sound is what an mp4 export cannot
3982+ // write, so the card greys that row before a destination is picked.
3983+ assert_eq!(mp4_refusal(&session), None);
3984+ let a2 = session.add_lane(LaneKind::Audio);
3985+ assert_eq!(a2.label(), "A2");
3986+ assert_eq!(mp4_refusal(&session), None, "an empty lane carries nothing");
3987+ assert!(
3988+ session
3989+ .place_stream_at(0.0, &path, 0, frames, Some(a2))
3990+ .expect("its own file is on this timeline")
3991+ );
3992+ assert_eq!(
3993+ mp4_refusal(&session).as_deref(),
3994+ Some("2 audio lanes — an mp4 copies one")
3995+ );
3996+
3997+ // Undo, one edit at a time and backwards: the drop on A2, the lane A2
3998+ // itself, the lift, the drop on V2, and last the lane V2 -- an added
3999+ // track is one step like every other edit.
4000+ for lanes in [4, 3, 3, 3, 2] {
4001+ assert!(session.undo());
4002+ assert_eq!(session.lanes().len(), lanes);
4003+ }
4004+ assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1]);
4005+ assert_eq!(session.lane_clips(Lane::V1).len(), 1);
4006+ assert_eq!(mp4_refusal(&session), None);
4007+ }
4008+
3788 #[test]4009 #[test]
3789 fn a_source_is_only_ever_asked_for_its_peaks_once() {4010 fn a_source_is_only_ever_asked_for_its_peaks_once() {
3790 let (a, b) = (asset("test_av.mp4"), asset("test_av2.mp4"));4011 let (a, b) = (asset("test_av.mp4"), asset("test_av2.mp4"));
@@ -4301,6 +4522,22 @@ mod tests {
4301 assert!(LANE_H >= HIT_MIN);4522 assert!(LANE_H >= HIT_MIN);
4302 // A label row that ate the whole lane would leave no waveform.4523 // A label row that ate the whole lane would leave no waveform.
4303 assert!(LABEL_H < LANE_H / 2.);4524 assert!(LABEL_H < LANE_H / 2.);
4525+ // An added track adds its own row to the panel, and the two a project
4526+ // starts with leave it exactly the height it has always been.
4527+ assert_eq!(panel_h(2), PANEL_H);
4528+ assert_eq!(panel_h(1), PANEL_H);
4529+ assert_eq!(panel_h(3), PANEL_H + LANE_H + 8.);
4530+ assert_eq!(
4531+ panel_h(LANES_MAX),
4532+ PANEL_H + lanes_h(LANES_MAX) - lanes_h(2)
4533+ );
4534+ // Past the cap the column scrolls instead: the panel stops growing, so
4535+ // no number of tracks can push the picture off the window.
4536+ assert_eq!(panel_h(LANES_MAX + 1), panel_h(LANES_MAX));
4537+ assert_eq!(panel_h(50), panel_h(LANES_MAX));
4538+ assert_eq!(lanes_h(0), 0.);
4539+ assert_eq!(lanes_h(1), LANE_H);
4540+ assert_eq!(lanes_h(2), 2. * LANE_H + 8.);
4304 }4541 }
4305 4542
4306 #[test]4543 #[test]
crates/engine/src/playback.rsmodified+48 -12
@@ -453,6 +453,19 @@ impl PlaybackSession {
453 self.project.lane(lane)453 self.project.lane(lane)
454 }454 }
455 455
456+ /// Every lane's handle, in display order -- what a front-end lays out top to
457+ /// bottom, and the list [`add_lane`](Self::add_lane) grows.
458+ pub fn lanes(&self) -> Vec<Lane> {
459+ self.project.lanes()
460+ }
461+
462+ /// Appends an empty lane and hands back its handle. One undo step
463+ /// ([`Project::add_lane`]), and no reseek: an empty lane changes nothing
464+ /// that plays until something is placed on it.
465+ pub fn add_lane(&mut self, kind: LaneKind) -> Lane {
466+ self.project.add_lane(kind)
467+ }
468+
456 /// Splits every lane at `timeline_secs`, so the two sides become two469 /// Splits every lane at `timeline_secs`, so the two sides become two
457 /// groups. Metadata only: a split never changes the timeline->source470 /// groups. Metadata only: a split never changes the timeline->source
458 /// mapping, so the running decoder stays correct and playback does not471 /// mapping, so the running decoder stays correct and playback does not
@@ -510,16 +523,21 @@ impl PlaybackSession {
510 /// A front-end greys such a row out; this is the backstop that keeps a523 /// A front-end greys such a row out; this is the backstop that keeps a
511 /// stale one from making the whole timeline silent.524 /// stale one from making the whole timeline silent.
512 ///525 ///
513- /// Which lane it lands on is decided here, from the file: one with a526+ /// Which lane it lands on is decided here, from the file and from `onto` --
514- /// picture is pasted across both lanes as a grouped take, one without527+ /// the lane it was let go over, if it was let go over one at all: a file
515- /// ([`crate::is_audio`]) is *placed* on the audio lane alone, overwriting528+ /// with a picture asked for by no lane, or for one of the first pair, is
516- /// what it lands on and rippling nothing. A caller never has to ask.529+ /// pasted across `V1` and `A1` as a grouped take; asked for by any further
530+ /// lane it is *placed* there alone, overwriting what it lands on and
531+ /// rippling nothing. A file with no picture ([`crate::is_audio`]) is placed
532+ /// on the audio lane it was asked for, or on `A1`, and never on a video
533+ /// lane. A caller never has to ask.
517 pub fn place_stream_at(534 pub fn place_stream_at(
518 &mut self,535 &mut self,
519 timeline_secs: f64,536 timeline_secs: f64,
520 path: &Path,537 path: &Path,
521 stream: usize,538 stream: usize,
522 frames: u32,539 frames: u32,
540+ onto: Option<Lane>,
523 ) -> crate::Result<bool> {541 ) -> crate::Result<bool> {
524 let wanted = Source::new(path, stream);542 let wanted = Source::new(path, stream);
525 // Another stream of a file whose picture is *already* on the timeline:543 // Another stream of a file whose picture is *already* on the timeline:
@@ -542,12 +560,26 @@ impl PlaybackSession {
542 };560 };
543 // Which lane a source may land on is decided here and only here, so a561 // Which lane a source may land on is decided here and only here, so a
544 // front-end never has to make the same call twice: a file with no562 // front-end never has to make the same call twice: a file with no
545- // picture goes on the audio lane alone, overwriting and rippling563+ // picture goes on an audio lane alone, overwriting and rippling
546 // nothing, because there is nothing on the video lane to move along564 // nothing, because there is nothing on the video lane to move along
547- // with it.565+ // with it. A lane of the source's own kind takes it as it is dropped;
548- Ok(match crate::is_audio(path) {566+ // only `V1` means the grouped take, since that is the pair the paste
549- true => self.place_at(Lane::A1, timeline_secs, clip),567+ // spans and a second video lane is a layer of its own.
550- false => self.paste_at(timeline_secs, clip),568+ let onto = match (crate::is_audio(path), onto) {
569+ // No picture: an audio lane and nothing else, whichever one was
570+ // asked for -- `A1` when none was.
571+ (true, Some(lane)) if lane.kind == LaneKind::Audio => Some(lane),
572+ (true, _) => Some(Lane::A1),
573+ // A picture: the lane it was let go over, unless that is one of the
574+ // first pair. Those two are the grouped take a paste spans, and a
575+ // further lane is a layer of its own -- its picture on `V2`, its
576+ // sound on `A2`.
577+ (false, Some(lane)) if lane.ord > 0 => Some(lane),
578+ (false, _) => None,
579+ };
580+ Ok(match onto {
581+ Some(lane) => self.place_at(lane, timeline_secs, clip),
582+ None => self.paste_at(timeline_secs, clip),
551 })583 })
552 }584 }
553 585
@@ -568,13 +600,17 @@ impl PlaybackSession {
568 self.edit(|p| p.place(lane, at, clip))600 self.edit(|p| p.place(lane, at, clip))
569 }601 }
570 602
571- /// Removes the video clip at `idx` and everything under it, closing the gap603+ /// Removes `lane`'s clip at `idx` and everything under it, closing the gap
572 /// on every lane. Unlike a split this *does* move every following frame, so604 /// on every lane. Unlike a split this *does* move every following frame, so
573 /// the session reseeks to wherever the playhead now points.605 /// the session reseeks to wherever the playhead now points.
574 /// [`lift_clip`](Self::lift_clip) is the one that leaves a hole instead.606 /// [`lift_clip`](Self::lift_clip) is the one that leaves a hole instead.
575 /// `false` for a bad index or the last remaining clip.607 /// `false` for a bad index or the last remaining clip.
576- pub fn delete_clip(&mut self, idx: usize) -> bool {608+ ///
577- self.edit(|p| p.delete(idx))609+ /// The lane travels because the index is a lane's own: `V2`'s third clip is
610+ /// not `V1`'s, and a front-end that could only say "the third clip" would
611+ /// delete the wrong one the moment a second lane exists.
612+ pub fn delete_clip(&mut self, lane: Lane, idx: usize) -> bool {
613+ self.edit(|p| p.delete_in(lane, idx))
578 }614 }
579 615
580 /// Undoes the last successful edit, and reseeks like a delete.616 /// Undoes the last successful edit, and reseeks like a delete.
crates/engine/src/project.rsmodified+30 -9
@@ -919,13 +919,20 @@ impl Project {
919 true919 true
920 }920 }
921 921
922- /// Insert `clip` into *every* lane at `timeline_frame` as one new group,922+ /// Insert `clip` into the first lane of each kind at `timeline_frame` as one
923- /// pushing everything from there on later by its length -- the grouped,923+ /// new group, pushing everything from there on later by its length in
924- /// rippling paste a clipboard does. Mid-clip the clip it lands in is split924+ /// *every* lane -- the grouped, rippling paste a clipboard does. Mid-clip
925- /// around it; at or past the end of the timeline it is appended, because a925+ /// the clip it lands in is split around it; at or past the end of the
926- /// paste means "put it here", not "put it here and leave black in front".926+ /// timeline it is appended, because a paste means "put it here", not "put it
927+ /// here and leave black in front".
927 /// Use [`place`](Project::place) to paste into one lane, or to make a gap.928 /// Use [`place`](Project::place) to paste into one lane, or to make a gap.
928 ///929 ///
930+ /// `V1` and `A1` and no other lane, because a take is one picture and one
931+ /// sound: copying it onto every lane there is would play the same audio
932+ /// twice over (and leave an mp4 export with two tracks to copy). The room is
933+ /// still opened everywhere, or the lanes it was not inserted into would slide
934+ /// out of step with the ones it was.
935+ ///
929 /// Exactly one history snapshot, so one [`Project::undo`] takes it back.936 /// Exactly one history snapshot, so one [`Project::undo`] takes it back.
930 /// Changes the timeline->source mapping: the caller must reseek. Refused937 /// Changes the timeline->source mapping: the caller must reseek. Refused
931 /// only for an empty `clip`, which the never-empty invariant forbids but the938 /// only for an empty `clip`, which the never-empty invariant forbids but the
@@ -941,10 +948,16 @@ impl Project {
941 link: Some(self.new_link()),948 link: Some(self.new_link()),
942 ..clip949 ..clip
943 };950 };
944- for data in &mut self.lanes {951+ let takes: Vec<usize> = [LaneKind::Video, LaneKind::Audio]
952+ .into_iter()
953+ .filter_map(|kind| self.index(Lane::new(kind, 0)))
954+ .collect();
955+ for (i, data) in self.lanes.iter_mut().enumerate() {
945 open_room(&mut data.clips, at, clip.len());956 open_room(&mut data.clips, at, clip.len());
946- let idx = data.clips.partition_point(|c| c.start < at);957+ if takes.contains(&i) {
947- data.clips.insert(idx, clip);958+ let idx = data.clips.partition_point(|c| c.start < at);
959+ data.clips.insert(idx, clip);
960+ }
948 debug_assert!(sorted_disjoint(&data.clips));961 debug_assert!(sorted_disjoint(&data.clips));
949 }962 }
950 true963 true
@@ -1001,7 +1014,15 @@ impl Project {
1001 /// -- the whole-group delete a single-lane front-end means. `false` for a1014 /// -- the whole-group delete a single-lane front-end means. `false` for a
1002 /// bad index. Changes the mapping: the caller must reseek.1015 /// bad index. Changes the mapping: the caller must reseek.
1003 pub fn delete(&mut self, idx: usize) -> bool {1016 pub fn delete(&mut self, idx: usize) -> bool {
1004- let Some(clip) = self.clips().get(idx).copied() else {1017+ self.delete_in(Lane::V1, idx)
1018+ }
1019+
1020+ /// [`delete`](Project::delete) for the lane the clip was picked on: the
1021+ /// clip's own span is cut out of *every* lane, so a take deletes whole from
1022+ /// whichever half of it was clicked. `false` for a bad index, and for a lane
1023+ /// that is not there.
1024+ pub fn delete_in(&mut self, lane: Lane, idx: usize) -> bool {
1025+ let Some(clip) = self.lane(lane).get(idx).copied() else {
1005 return false;1026 return false;
1006 };1027 };
1007 self.ripple_delete(clip.start, clip.len())1028 self.ripple_delete(clip.start, clip.len())
crates/engine/tests/export.rsmodified+1 -1
@@ -74,7 +74,7 @@ fn edited(source: &Path) -> PlaybackSession {
74 let mut session = PlaybackSession::open(source).expect("open source");74 let mut session = PlaybackSession::open(source).expect("open source");
75 assert!(session.cut_at(30.0 / FPS), "cut at frame 30");75 assert!(session.cut_at(30.0 / FPS), "cut at frame 30");
76 assert!(session.cut_at(60.0 / FPS), "cut at frame 60");76 assert!(session.cut_at(60.0 / FPS), "cut at frame 60");
77- assert!(session.delete_clip(1), "drop the middle clip");77+ assert!(session.delete_clip(Lane::V1, 1), "drop the middle clip");
78 assert_eq!(session.clip_spans().len(), 2);78 assert_eq!(session.clip_spans().len(), 2);
79 session79 session
80 }80 }
crates/engine/tests/playback.rsmodified+3 -3
@@ -343,7 +343,7 @@ fn edits_traverse_cuts() {
343 assert!((session.timeline_duration() - whole).abs() < 1e-9);343 assert!((session.timeline_duration() - whole).abs() < 1e-9);
344 344
345 let (cut, hole_end) = ((2.0 * fps) as u32, (3.5 * fps) as u32);345 let (cut, hole_end) = ((2.0 * fps) as u32, (3.5 * fps) as u32);
346- assert!(session.delete_clip(1), "drop the middle clip");346+ assert!(session.delete_clip(Lane::V1, 1), "drop the middle clip");
347 let kept = total - (hole_end - cut);347 let kept = total - (hole_end - cut);
348 assert_eq!(session.clip_spans().len(), 2);348 assert_eq!(session.clip_spans().len(), 2);
349 assert!(349 assert!(
@@ -597,7 +597,7 @@ fn edits_keep_the_audio_clock() {
597 // Deleting the head clip moves everything after it, so the session reseeks597 // Deleting the head clip moves everything after it, so the session reseeks
598 // under the playhead: same timeline position, new source frame, and the598 // under the playhead: same timeline position, new source frame, and the
599 // frame numbering restarts at the landing frame.599 // frame numbering restarts at the landing frame.
600- assert!(session.delete_clip(0), "drop the head clip");600+ assert!(session.delete_clip(Lane::V1, 0), "drop the head clip");
601 let landed = session.now();601 let landed = session.now();
602 assert!(602 assert!(
603 (landed - after_cut).abs() < 0.2,603 (landed - after_cut).abs() < 0.2,
@@ -695,7 +695,7 @@ fn import_appends_a_second_source_and_plays_across_the_join() {
695 // second into the imported clip, then drop the whole original.695 // second into the imported clip, then drop the whole original.
696 assert!(session.cut_at(6.0), "cut 1 s into the imported clip");696 assert!(session.cut_at(6.0), "cut 1 s into the imported clip");
697 assert_eq!(session.clip_spans().len(), 3);697 assert_eq!(session.clip_spans().len(), 3);
698- assert!(session.delete_clip(0), "drop the first source");698+ assert!(session.delete_clip(Lane::V1, 0), "drop the first source");
699 assert_eq!(session.clip_spans_by_source()[0].2, 1);699 assert_eq!(session.clip_spans_by_source()[0].2, 1);
700 assert!(700 assert!(
701 (session.timeline_duration() - f64::from(second) / fps).abs() < 1e-9,701 (session.timeline_duration() - f64::from(second) / fps).abs() < 1e-9,
crates/engine/tests/saveload.rsmodified+8 -5
@@ -10,7 +10,7 @@
10 use std::path::{Path, PathBuf};10 use std::path::{Path, PathBuf};
11 11
12 use engine::PlaybackSession;12 use engine::PlaybackSession;
13-use engine::project::Source;13+use engine::project::{Lane, Source};
14 14
15 fn asset(name: &str) -> PathBuf {15 fn asset(name: &str) -> PathBuf {
16 PathBuf::from(env!("CARGO_MANIFEST_DIR"))16 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
@@ -51,7 +51,7 @@ fn a_picked_audio_stream_lands_saves_and_comes_back() {
51 // can join this timeline; it lands as a second source of the same file.51 // can join this timeline; it lands as a second source of the same file.
52 assert!(52 assert!(
53 session53 session
54- .place_stream_at(end, &media, 1, frames)54+ .place_stream_at(end, &media, 1, frames, None)
55 .expect("stream 1 matches the timeline")55 .expect("stream 1 matches the timeline")
56 );56 );
57 assert_eq!(57 assert_eq!(
@@ -85,13 +85,13 @@ fn a_picked_audio_stream_lands_saves_and_comes_back() {
85 session.set_gain(0.0);85 session.set_gain(0.0);
86 let frames = session.clip_at(0).expect("one clip").out_frame;86 let frames = session.clip_at(0).expect("one clip").out_frame;
87 let err = session87 let err = session
88- .place_stream_at(0.0, &other, 1, frames)88+ .place_stream_at(0.0, &other, 1, frames, None)
89 .expect_err("22.05 kHz mono cannot join a 44.1 kHz stereo timeline")89 .expect_err("22.05 kHz mono cannot join a 44.1 kHz stereo timeline")
90 .to_string();90 .to_string();
91 assert!(err.contains("22050"), "unhelpful refusal: {err}");91 assert!(err.contains("22050"), "unhelpful refusal: {err}");
92 assert!(92 assert!(
93 session93 session
94- .place_stream_at(0.0, &media, 1, frames)94+ .place_stream_at(0.0, &media, 1, frames, None)
95 .expect_err("a file that is not a source")95 .expect_err("a file that is not a source")
96 .to_string()96 .to_string()
97 .contains("not on this timeline")97 .contains("not on this timeline")
@@ -109,7 +109,10 @@ fn edited(dir: &Path) -> PlaybackSession {
109 .expect("import the second file");109 .expect("import the second file");
110 assert!(session.cut_at(2.0), "cut inside the first file");110 assert!(session.cut_at(2.0), "cut inside the first file");
111 assert!(session.cut_at(6.5), "cut inside the second file");111 assert!(session.cut_at(6.5), "cut inside the second file");
112- assert!(session.delete_clip(1), "drop the second half of the first");112+ assert!(
113+ session.delete_clip(Lane::V1, 1),
114+ "drop the second half of the first"
115+ );
113 session.seek(3.0);116 session.seek(3.0);
114 assert_eq!(session.timeline_duration(), 6.0);117 assert_eq!(session.timeline_duration(), 6.0);
115 session118 session