diff --git a/crates/app/src/interact.rs b/crates/app/src/interact.rs index 779458d..2f22791 100644 --- a/crates/app/src/interact.rs +++ b/crates/app/src/interact.rs @@ -96,12 +96,17 @@ pub(crate) struct Trim { pub(crate) lane: Lane, pub(crate) idx: usize, pub(crate) edge: Edge, + /// Where the edge stood at the press: with `to`, the delta the whole group + /// follows by -- each member's own edge moves this far, clamped to its own + /// room, which is exactly what the engine commits at the release. + pub(crate) from: u32, /// Already clamped by `PlaybackSession::trim_room`, so the width drawn from /// it is the width the release commits -- an edge stops under the pointer /// rather than snapping back after the fact. pub(crate) to: u32, - /// The dragged clip's group, so its other halves' boxes follow the edge on - /// screen exactly as the engine will move them. + /// The dragged placement's group, so the boxes of everything it names -- + /// clips and captions alike -- follow the edge on screen exactly as the + /// engine will move them. pub(crate) link: Option, } diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index baec5a2..9e79c2b 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -86,6 +86,10 @@ actions! { Select, SelectNext, SelectPrev, + /// Every placement on every lane in one selection -- the companion of the + /// ctrl-click that builds a selection by hand, for the times everything + /// wants selecting at once. + SelectAll, Delete, Lift, Color, @@ -159,11 +163,12 @@ impl ActionId { // Neither half's action: it takes the *pair* apart, and the menu // that offers it hangs on whichever half was right-clicked -- worded // from the picture's side it read as a video item on an audio clip. - ActionId::Detach => "Ungroup the picture and the sound", - ActionId::Group => "Group with the clip on another track", + ActionId::Detach => "Ungroup the selection (clips and captions)", + ActionId::Group => "Group the selection (ctrl-click the clips first)", ActionId::Select => "Select the clip under the playhead (again for the next lane)", ActionId::SelectNext => "Select the next clip in the lane", ActionId::SelectPrev => "Select the previous clip in the lane", + ActionId::SelectAll => "Select everything (every clip and caption)", ActionId::Delete => "Delete", ActionId::Lift => "Lift (leave a gap)", ActionId::Color => "Colour…", @@ -221,6 +226,7 @@ impl ActionId { ActionId::Select => "select", ActionId::SelectNext => "select-next", ActionId::SelectPrev => "select-prev", + ActionId::SelectAll => "select-all", ActionId::Delete => "delete", ActionId::Lift => "lift", ActionId::Color => "color", @@ -277,6 +283,7 @@ impl ActionId { | ActionId::Select | ActionId::SelectNext | ActionId::SelectPrev + | ActionId::SelectAll | ActionId::Delete | ActionId::Lift | ActionId::Color @@ -776,6 +783,11 @@ impl Keymap { b(ActionId::Select, "tab", false), b(ActionId::SelectNext, "]", false), b(ActionId::SelectPrev, "[", false), + // Select-all, on the chord every editor and every text field + // already means it by -- which is why the audio-lane removal + // below had to move off ctrl+a: a stroke that universal was + // never really the removal's to keep. + b(ActionId::SelectAll, "a", true), b(ActionId::Delete, "x", false), b(ActionId::Delete, "delete", false), b(ActionId::Lift, "l", false), @@ -811,7 +823,10 @@ impl Keymap { // 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), + // Ctrl+a is the select-all above now, so the audio removal + // takes the free key beside its own letter: "a" neighbours + // "q" on the row, and ctrl+q was taken by nothing. + b(ActionId::RemoveAudioLane, "q", true), // The subtitle pair reads the same way: the unshifted initial // adds one -- "s" is free, the save is the *ctrl* chord -- and a // ctrl chord takes it back. Ctrl+s is that save, so the removal @@ -862,7 +877,7 @@ impl Keymap { // Making them takes the key next to it, ctrl+o: the pair is one // subject and the two chords are under the same finger, and // every letter of the word itself is spoken for ("a" adds an - // audio lane, ctrl+a removes one). + // audio lane, ctrl+a selects everything). b(ActionId::ToggleAutoProxies, "o", true), // The theme takes ctrl+h -- the h of the word, since "t" is the // subtitles and ctrl+t takes one off -- and a ctrl chord because @@ -1143,7 +1158,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 52); + assert_eq!(k.entries().len(), 53); assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies)); assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies)); assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); @@ -1189,9 +1204,12 @@ mod tests { 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. + // press. Ctrl+v is the paste, so the video one sits beside it; ctrl+a + // is the select-all every editor shares, so the audio one sits beside + // its own letter instead. assert_eq!(k.lookup("b", true), Some(ActionId::RemoveVideoLane)); - assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane)); + assert_eq!(k.lookup("q", true), Some(ActionId::RemoveAudioLane)); + assert_eq!(k.lookup("a", true), Some(ActionId::SelectAll)); // The subtitle pair, the third kind of track: the initial adds and the // subtitle letter's chord takes it back. assert_eq!(k.lookup("s", false), Some(ActionId::AddSubtitleLane)); diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 3be6e72..4c35375 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -116,11 +116,13 @@ struct Player { /// the head is on screen again, and by every transport ask (a seek, a /// play/pause) outright -- those are a person saying where to look. panned: bool, - /// Which clip the edit keys act on: the lane it is in and its index there. - /// The *clicked* half, not the group -- a group is what gets marked on - /// screen, but Lift has to know which half it was aimed at. Indices move - /// under every edit, so this is cleared by all of them. - selected: Option<(Lane, usize)>, + /// Which placements the edit keys act on: the lane each is in and its + /// index there, every ctrl-click in the order it was made. The *clicked* + /// half and not the group -- a group is what gets marked on screen, but + /// Lift has to know which half it was aimed at -- and the last pick is the + /// [`anchor`](Selection::anchor) every single-thing action uses. Indices + /// move under every edit, so this is cleared by all of them. + selected: Selection, /// The clip menu a right-click opened, if one is up. Holds an index like /// `selected` does, so it is closed by anything that can move indices -- /// every stroke, and every item of its own. @@ -660,7 +662,7 @@ fn main() { // Nobody has scrolled anything yet, so the follow has the // view: the first frame is drawn where the head is. panned: false, - selected: None, + selected: Selection::new(), context_menu: None, picker: None, library_menu: None, diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index 3723685..60bcc7d 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -74,6 +74,14 @@ pub(crate) struct Ctx { /// about a clip. pub(crate) playable: bool, pub(crate) exporting: bool, + /// How many placements the selection holds, and on how many distinct + /// lanes -- the manual group's two questions in one reading. Picks that + /// name nothing (a stroke moved the indices under them) count as none. + pub(crate) picks: usize, + pub(crate) pick_lanes: usize, + /// The group id of the marked caption, when what is marked is one: the + /// detach question, asked over a box the clip index space cannot name. + pub(crate) caption_link: Option, } /// Whether `action` can be asked for, on `ctx`. One arm per action and nothing @@ -137,7 +145,10 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { // nothing else* have nothing to act on over a placed subtitle, so they are // refusals of kind -- not rows at all, rather than rows saying "click a clip // first" over a clicked caption. Delete is the one that means something: it - // routes to [`Player::lift_sub`] when what is marked is a caption. + // routes to [`Player::lift_sub`] when what is marked is a caption, and so + // are Group and Detach now that a caption may be grouped by hand -- the one + // over the selection the menu was opened on, the other over the group the + // marked caption is in. // // And it is *only* those. The playhead actions are about the timeline rather // than about what is marked -- the split and the regroup act at the line @@ -150,12 +161,7 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { if ctx.caption && matches!( action, - ActionId::Copy - | ActionId::Delete - | ActionId::Lift - | ActionId::Detach - | ActionId::Group - | ActionId::Equalizer + ActionId::Copy | ActionId::Delete | ActionId::Lift | ActionId::Equalizer ) { return match action { @@ -216,11 +222,25 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { } _ => Enable::Yes, }, - // Nothing to take apart in a clip that names no group at all. Whether - // the group it names still has another half is the engine's question, - // like the regroup above. - ActionId::Detach => match ctx.clip { - Some((clip, _)) if clip.link.is_none() => Enable::No("this clip is not grouped"), + // Nothing to take apart in a placement that names no group at all -- + // a clip by its own field, a caption by the one the mark carries. + // Whether the group it names still has another half is the engine's + // question, like the regroup above. + ActionId::Detach => match (ctx.clip, ctx.caption) { + (Some((clip, _)), _) if clip.link.is_none() => Enable::No("this clip is not grouped"), + (None, true) if ctx.caption_link.is_none() => { + Enable::No("this caption is not grouped") + } + _ => Enable::Yes, + }, + // The manual group: a *selection* of placements, at most one per lane. + // Two picks or more, all on their own lanes, is a group waiting to be + // made; a lane picked twice is the one thing a group may never hold; + // and a single pick is the partner hunt it always was, which the engine + // words itself. + ActionId::Group => match ctx.picks { + 2.. if ctx.pick_lanes == ctx.picks => Enable::Yes, + 2.. => Enable::No("a group is one clip per lane: keep one pick per track"), _ => Enable::Yes, }, // The three that act on the marked clip and on nothing else: with none @@ -266,10 +286,12 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { /// caption -- [`enable`] says so, and the strokes and the toolbar read that -- /// but a split, a rate, a grade or a fit listed under a right-clicked caption /// reads as something the caption is about to get, when what they reach is the -/// video clip the playhead is standing in. So a caption's menu carries the one -/// row that is the caption's ([`Player::lift_sub`], reached through Delete) and -/// the rows the card already prints "(global)" beside, which say for themselves -/// that they are not about what was clicked. +/// video clip the playhead is standing in. So a caption's menu carries the rows +/// that are the caption's -- its removal ([`Player::lift_sub`], reached through +/// Delete) and, since a caption may be grouped by hand, the group pair over the +/// selection and its own group -- and the rows the card already prints +/// "(global)" beside, which say for themselves that they are not about what was +/// clicked. pub(crate) fn menu_items(ctx: Ctx) -> Vec { MENU_ITEMS .into_iter() @@ -278,7 +300,11 @@ pub(crate) fn menu_items(ctx: Ctx) -> Vec { !ctx.caption || matches!( action, - ActionId::Delete | ActionId::Paste | ActionId::ToggleMute + ActionId::Delete + | ActionId::Paste + | ActionId::ToggleMute + | ActionId::Group + | ActionId::Detach ) }) .collect() diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index b0a9062..f1b34b6 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -54,6 +54,7 @@ impl Player { ActionId::Select => self.select_under_playhead(cx), ActionId::SelectNext => self.select_step(true, cx), ActionId::SelectPrev => self.select_step(false, cx), + ActionId::SelectAll => self.select_all(cx), ActionId::Delete => self.delete_selected(cx), ActionId::Lift => self.lift_selected(cx), ActionId::Color => self.open_color(cx), @@ -213,16 +214,30 @@ impl Player { let Some(session) = &self.session else { return Ctx::default(); }; - let on = on.or(self.selected); + let on = on.or(self.selected.anchor()); let clip = on .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| (*clip, lane))); + let caption = on.is_some_and(|(lane, idx)| { + lane.kind == LaneKind::Subtitle && idx < session.sub_lane(lane).len() + }); + // The selection's shape, over the picks that still name something: + // how many placements, and on how many lanes. The lane count is the + // manual group's one-per-lane question -- equal counts say a group, a + // short one says a lane is picked twice. + let (picks, _) = self.marks(); + let mut lanes = Vec::new(); + for &(lane, _) in &picks { + if !lanes.contains(&lane) { + lanes.push(lane); + } + } + let pick_lanes = lanes.len(); Ctx { clip, // The same pair read in the other index space: a subtitle lane's // own, where the box that was clicked is a caption. - caption: on.is_some_and(|(lane, idx)| { - lane.kind == LaneKind::Subtitle && idx < session.sub_lane(lane).len() - }), + caption, + caption_link: caption.then(|| on.and_then(|(lane, idx)| session.sub_lane(lane).get(idx)).and_then(|s| s.link)).flatten(), image: clip.is_some_and(|(clip, _)| { session .sources() @@ -235,6 +250,8 @@ impl Player { subtitles: !session.subtitles().is_empty(), playable: !nothing_to_play(Some(session)), exporting: self.exporting().is_some(), + picks: picks.len(), + pick_lanes, } } @@ -347,7 +364,7 @@ impl Player { if self.session.as_mut().is_some_and(PlaybackSession::undo) { self.reset_after_reseek(); } - self.selected = None; + self.selected.clear(); cx.notify(); } diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 01906ea..0610084 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -178,6 +178,7 @@ impl Player { }; let target = self .selected + .anchor() .filter(|(lane, _)| lane.kind == LaneKind::Video) .or_else(|| session.video_clip_at(session.now())); match target { @@ -310,6 +311,7 @@ impl Player { }; match self .selected + .anchor() .or_else(|| session.video_clip_at(session.now())) { Some(clip) => { @@ -452,6 +454,7 @@ impl Player { }; match self .selected + .anchor() .or_else(|| session.video_clip_at(session.now())) .map(|clip| audio_half(session, clip)) { @@ -842,7 +845,7 @@ impl Player { // selection now names a different clip than the one that is // highlighted -- dropped here as after every other edit that // moves indexes (a delete, a paste, an undo). - self.selected = None; + self.selected.clear(); self.reset_after_reseek(); self.notify_user( format!( @@ -881,7 +884,7 @@ impl Player { // Splitting each silence out and closing the room it no longer // needs moves indexes exactly as the cut does: the selection // goes with them. - self.selected = None; + self.selected.clear(); self.reset_after_reseek(); self.notify_user( format!( @@ -958,7 +961,7 @@ impl Player { if self.exporting().is_some() { return; } - let refusal = match (self.selected, &self.session) { + let refusal = match (self.selected.anchor(), &self.session) { (_, None) => Some("NO TIMELINE — open a file first".to_string()), (None, _) => Some(format!( "NOTHING SELECTED — click an audio clip or press {}, then ask again", @@ -974,7 +977,7 @@ impl Player { cx.notify(); return; } - let (lane, idx) = self.selected.expect("checked above"); + let (lane, idx) = self.selected.anchor().expect("checked above"); let session = self.session.as_ref().expect("checked above"); // What the clip already plays through, or the flat default -- so the // card opens on the curve that is in force and a reopen shows the last diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index cc1ba76..82b6332 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -51,7 +51,7 @@ impl Player { }; match placed { Ok(true) => { - self.selected = None; + self.selected.clear(); self.reset_after_reseek(); } // The engine's own words: a stream that cannot join this timeline @@ -145,7 +145,7 @@ impl Player { // The drawn cue with it, and its tile for the same reason as above. self.sub_image = None; self.clipboard = None; - self.selected = None; + self.selected.clear(); self.selected_asset = None; // The subtitle rows go with the timeline they were on, and so does the // lane that was shown: S1 of one project is not S1 of the next. @@ -1154,7 +1154,7 @@ impl Player { // A copied clip names its source by index, which means a // different file -- or none -- in another project. self.clipboard = None; - self.selected = None; + self.selected.clear(); // A menu can be up while a project is dropped on the window -- // the scrim swallows clicks, never a drop -- and its index // would name some other timeline's clip. The two clip cards @@ -1256,7 +1256,7 @@ impl Player { .map(|session| session.remove_lane(lane)); let text = match removed { Some(Ok(())) => { - self.selected = None; + self.selected.clear(); self.context_menu = None; self.eq_open = None; self.color_open = None; @@ -1313,7 +1313,7 @@ impl Player { return; }; if moved != lane { - self.selected = None; + self.selected.clear(); self.context_menu = None; self.eq_open = None; self.color_open = None; diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 17dda2f..4521ad0 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -27,7 +27,7 @@ impl Player { if let Some(session) = &mut self.session { session.cut_at(f64::from(at) / self.fps); } - self.selected = None; + self.selected.clear(); cx.notify(); } @@ -42,7 +42,7 @@ impl Player { } if let Some(session) = &mut self.session { if session.regroup_at(session.now()) { - self.selected = None; + self.selected.clear(); } else { self.notify_user( "NOTHING TO REGROUP — put the playhead where two clips meet, on frames that were cut apart" @@ -61,7 +61,7 @@ impl Player { if self.exporting().is_some() { return; } - match (&mut self.session, self.selected) { + match (&mut self.session, self.selected.anchor()) { (Some(session), Some((lane, idx))) => { if !session.ungroup(lane, idx) { self.notify_user( @@ -77,35 +77,55 @@ impl Player { cx.notify(); } - /// Puts the selected clip back in a group with the clip covering exactly the - /// same frames on another track -- the way back from [`Player::detach`], and - /// the way to group a picture with sound it was never opened with. The - /// partner is not clicked because there is nothing to choose: a group id - /// names one span, so only a clip covering these very frames could join it, - /// and the engine words what to do when none does. + /// Puts the selection into one group. Two paths, by how much of a + /// selection there is: + /// + /// * **One pick** -- the way back from [`Player::detach`], and the way to + /// group a picture with sound it was never opened with. The partner is + /// not clicked because there is nothing to choose: the clip covering + /// exactly the same frames on another track, and the engine words what to + /// do when none does. + /// + /// * **A ctrl-click selection** -- the group a hand builds: every pick it + /// names, clips and captions alike, into one id, whatever frames each of + /// them covers. The members keep their own offsets, which is the point: + /// from here they move, trim and delete together. pub(crate) fn group(&mut self, cx: &mut Context) { if self.exporting().is_some() { return; } - let partner = match (&self.session, self.selected) { - (Some(session), Some((lane, idx))) => span_partner(session, lane, idx), - _ => None, - }; - match (&mut self.session, self.selected, partner) { - (Some(session), Some((lane, idx)), Some((other, o_idx))) => { - if let Err(e) = session.group(lane, idx, other, o_idx) { + // The picks the selection holds that still name something: a stale + // index (a stroke nobody saw) is not a thing to group. + let picks = self.marks().0; + match (&mut self.session, self.selected.anchor(), picks.len()) { + (_, None, _) => { + self.notify_user("NOTHING GROUPED — click one of the halves first".into()) + } + // The hand's group: every pick, one id. + (Some(session), _, 2..) => { + if let Err(e) = session.group_all(&picks) { self.notify_user(format!("NOT GROUPED — {e}").into()); } } - (Some(_), Some(_), None) => { - self.notify_user( - "NOTHING TO GROUP WITH — no clip on another track covers exactly these frames" - .into(), - ) - } - (Some(_), None, _) => { - self.notify_user("NOTHING GROUPED — click one of the halves first".into()) + // One pick that no longer names anything. + (Some(_), Some(_), 0) => { + self.notify_user("NOTHING GROUPED — that clip is no longer there".into()) } + // One pick: the partner flow it always was. + (Some(session), Some((lane, idx)), _) => match span_partner(session, lane, idx) { + Some((other, o_idx)) => { + if let Err(e) = session.group(lane, idx, other, o_idx) { + self.notify_user(format!("NOT GROUPED — {e}").into()); + } + } + None => { + self.notify_user( + "NOTHING TO GROUP WITH — no clip on another track covers exactly these \ + frames; ctrl-click the clips to group instead" + .into(), + ) + } + }, (None, ..) => {} } cx.notify(); @@ -120,20 +140,43 @@ impl Player { if self.exporting().is_some() { return; } - let selected = self.selected.take(); + let selected = self.selected.anchor(); + self.selected.clear(); // A caption is marked in its own lane's index space -- that lane holds // no `Clip` -- so the same key reaches it through the one removal a - // placed subtitle has ([`Player::lift_sub`], one undo step). Parity: the - // box on a subtitle lane goes by the stroke every other box goes by. + // placed subtitle has ([`Player::lift_sub`], one undo step), unless a + // hand put it in a group: then it goes the way its group goes. + // Parity: the box on a subtitle lane goes by the stroke every other box + // goes by. if let Some((lane, idx)) = selected.filter(|(lane, _)| lane.kind == LaneKind::Subtitle) { - self.lift_sub(lane, idx, cx); + // A caption carrying a group id is a member, and a member goes the + // way its group goes -- the engine's own door decides how much of + // that is media (and so a reseek) and how much is a lift. + let grouped = self + .session + .as_ref() + .is_some_and(|session| session.sub_lane(lane).get(idx).is_some_and(|s| s.link.is_some())); + match grouped { + true => { + if self + .session + .as_mut() + .is_some_and(|session| session.delete_sub(lane, idx)) + { + self.reset_after_reseek(); + } + } + false => self.lift_sub(lane, idx, cx), + } + cx.notify(); return; } // Whichever lane it was clicked in: the index is that lane's own, and - // the ripple cuts the clip's span out of every lane -- a group covers - // one span, so deleting a take by its audio half is the same edit as by - // its picture. What is not a whole take is lifted instead, which is what - // reaches a clip on an added track ([`whole_take`]). + // the engine cuts what the clip covers out of the lanes it covers -- a + // lone clip's span out of every lane, a grouped member's own span out + // of its own lane and its caption members off their lanes. What is not + // a whole take is lifted instead, which is what reaches a clip on an + // added track ([`whole_take`]). let deleted = match (&mut self.session, selected) { (Some(session), Some((lane, idx))) => match whole_take(session, lane, idx) { true => session.delete_clip(lane, idx), @@ -157,7 +200,9 @@ impl Player { if self.exporting().is_some() { return; } - match (&mut self.session, self.selected.take()) { + let selected = self.selected.anchor(); + self.selected.clear(); + match (&mut self.session, selected) { (Some(session), Some((lane, idx))) => { if session.lift_clip(lane, idx) { self.reset_after_reseek(); @@ -181,16 +226,34 @@ impl Player { // frames is a paste of the wrong thing. if let Some(clip) = self .selected + .anchor() .and_then(|(lane, idx)| session?.lane_clips(lane).get(idx).copied()) { self.clipboard = Some(clip); } } - /// The group id of the clicked clip, which is what marks the other half. - pub(crate) fn selected_link(&self) -> Option { - let (lane, idx) = self.selected?; - self.session.as_ref()?.lane_clips(lane).get(idx)?.link + /// The picks and their group ids, in click order: the two halves of what + /// [`marked`] asks about every box on the bed -- which picks there are, and + /// which groups they carry (a caption's included, which is what marks the + /// clip it was pinned to). Picks an edit has left stale name nothing and + /// contribute no id. + pub(crate) fn marks(&self) -> (Vec<(Lane, usize)>, Vec>) { + let Some(session) = &self.session else { + return (Vec::new(), Vec::new()); + }; + let (mut picks, mut links) = (Vec::new(), Vec::new()); + for &(lane, idx) in self.selected.picks() { + let link = match lane.kind { + LaneKind::Subtitle => session.sub_lane(lane).get(idx).map(|s| s.link), + _ => session.lane_clips(lane).get(idx).map(|c| c.link), + }; + if let Some(link) = link { + picks.push((lane, idx)); + links.push(link); + } + } + (picks, links) } /// Drops the copied clip in at the playhead. The engine reseeks itself, so @@ -202,7 +265,7 @@ impl Player { _ => false, }; if pasted { - self.selected = None; + self.selected.clear(); self.reset_after_reseek(); } cx.notify(); @@ -240,7 +303,7 @@ impl Player { }; match moved { true => { - self.selected = None; + self.selected.clear(); self.reset_after_reseek(); } // The three ways a drag is refused, told apart by what the @@ -289,6 +352,9 @@ impl Player { track, in_us: 0, out_us, + // A palette row arrives in no group: pinning its words to a clip is + // a hand's decision, made with the Group row afterwards. + link: None, }) } @@ -308,6 +374,7 @@ impl Player { // frame is its name on its lane ([`sub_mark`]). let marked = self .selected + .anchor() .filter(|&(lane, _)| lane == to) .and_then(|(lane, idx)| Some(self.session.as_ref()?.sub_lane(lane).get(idx)?.start)); let text = match (self.sub_of_track(track), &mut self.session) { @@ -331,11 +398,19 @@ impl Player { // names its new neighbour -- the caption the next Delete would take. // The mark goes back on the caption it was on. (None, Some(start)) => { - self.selected = self + let mark = self .session .as_ref() .and_then(|session| sub_mark(session.sub_lane(to), start)) .map(|i| (to, i)); + self.selected = match mark { + Some(mark) => { + let mut sel = Selection::new(); + sel.set_one(mark); + sel + } + None => Selection::new(), + }; } (None, None) => {} } @@ -385,11 +460,19 @@ impl Player { // landed rather than left on the index it had, which after the move // is a neighbour's. Some(Ok(())) => { - self.selected = self + let mark = self .session .as_ref() .and_then(|session| sub_mark(session.sub_lane(to), start)) .map(|i| (to, i)); + self.selected = match mark { + Some(mark) => { + let mut sel = Selection::new(); + sel.set_one(mark); + sel + } + None => Selection::new(), + }; } None => {} } @@ -425,8 +508,12 @@ impl Player { // so a mark or an open menu left at or past it names a *different* // caption now -- and the next Delete would take that one. Both go // with the caption they were on. - if self.selected.is_some_and(|(l, i)| l == lane && i >= idx) { - self.selected = None; + if self + .selected + .anchor() + .is_some_and(|(l, i)| l == lane && i >= idx) + { + self.selected.clear(); } self.context_menu = None; } @@ -714,8 +801,19 @@ impl Player { }; let lanes = session.lanes(); let clips: Vec<&[Clip]> = lanes.iter().map(|&lane| session.lane_clips(lane)).collect(); + // The dragged placement's group, whatever kind it is: the clips of the + // group travel with a clip's drag, and a caption's drag -- which has no + // clip of its own to skip by -- must not snap onto the very clips it is + // carrying. + let skip_link = skip.and_then(|(lane, idx)| { + match lane.kind { + LaneKind::Subtitle => session.sub_lane(lane).get(idx).map(|s| s.link), + _ => session.lane_clips(lane).get(idx).map(|c| c.link), + } + .flatten() + }); let skip = skip.and_then(|(lane, idx)| Some((lanes.iter().position(|&l| l == lane)?, idx))); - snap_marks(&clips, skip, frame_at(session.now(), self.fps)) + snap_marks(&clips, skip, skip_link, frame_at(session.now(), self.fps)) } /// Where a gesture at `raw` lands and the mark that pulled it there, with @@ -854,12 +952,17 @@ impl Player { /// Opens the clip menu on the box under the pointer, from the right button /// wherever it was pressed on that box -- its middle or one of its edge /// strips, which cover the middle's own listener. Selecting first is part of - /// it: every item acts on the clip the menu names. + /// it: every item acts on the clip the menu names -- and a right-click on + /// one of the clips a ctrl-click selection already holds keeps that + /// selection, so the menu's Group is about the whole of it. A right-click + /// anywhere else is the single mark, exactly as a left press is. pub(crate) fn open_menu(&mut self, lane: Lane, idx: usize, at: Point, cx: &mut Context) { if self.modal() { return; } - self.select((lane, idx), cx); + if !self.selected.contains((lane, idx)) { + self.select((lane, idx), cx); + } self.context_menu = Some(ContextMenu { lane, idx, @@ -869,11 +972,19 @@ impl Player { cx.notify(); } - /// A press on a clip's edge: the start of the drag that changes how much of - /// its source it plays. It selects the clip as a press anywhere else on the + /// A press on an edge: the start of the drag that changes how much of a + /// source it plays. It picks the placement as a press anywhere else on the /// box does -- the edge strip covers the box's own listener (`occlude`), so - /// this is the only one that fires there. - pub(crate) fn start_trim(&mut self, lane: Lane, idx: usize, edge: Edge, cx: &mut Context) { + /// this is the only one that fires there -- and ctrl makes that pick the + /// toggle it is everywhere else on the bed. + pub(crate) fn start_trim( + &mut self, + lane: Lane, + idx: usize, + edge: Edge, + ctrl: bool, + cx: &mut Context, + ) { if self.modal() || self.exporting().is_some() { return; } @@ -881,9 +992,8 @@ impl Player { // gesture, the same `Trim`, and the branch is the lane's kind wherever // the drag is asked about ([`Player::trim_to`], // [`Player::commit_trim`]). A caption *is* markable -- the mark is its - // lane and its index like a clip's ([`Player::select`]) -- but an edge - // drag is a trim and not a pick, so this leaves the mark where the hand - // left it. No group either: a caption has no half on another lane. + // lane and its index like a clip's ([`Player::pick`]) -- and a caption + // in a group carries its link, so its trim drags the group with it. if lane.kind == LaneKind::Subtitle { let Some(sub) = self .session @@ -892,15 +1002,22 @@ impl Player { else { return; }; + self.pick((lane, idx), ctrl, cx); self.trim = Some(Trim { lane, idx, edge, + // Where the edge already is: a press that never moves is not an + // edit, and the engine refuses exactly that. + from: match edge { + Edge::Start => sub.start, + Edge::End => sub.end(), + }, to: match edge { Edge::Start => sub.start, Edge::End => sub.end(), }, - link: None, + link: sub.link, }); cx.notify(); return; @@ -912,13 +1029,17 @@ impl Player { else { return; }; - self.select((lane, idx), cx); + self.pick((lane, idx), ctrl, cx); self.trim = Some(Trim { lane, idx, edge, // Where the edge already is: a press that never moves is not an // edit, and `Project::trim` refuses exactly that. + from: match edge { + Edge::Start => clip.start, + Edge::End => clip.end(), + }, to: match edge { Edge::Start => clip.start, Edge::End => clip.end(), @@ -1006,30 +1127,73 @@ impl Player { } /// The clip as the drag is showing it: an edge under the pointer moves its - /// own box, and the boxes of the halves linked to it, before anything is + /// own box, and the boxes of everything linked to it, before anything is /// committed. Display only -- the project is not touched until the release. + /// A member of the group follows by the same delta, clamped to its own + /// room, which is the arithmetic the release commits -- so a box let go of + /// is the box that lands. pub(crate) fn trimmed(&self, lane: Lane, idx: usize, clip: Clip) -> Clip { let Some(trim) = self.trim.filter(|t| { (t.lane, t.idx) == (lane, idx) || (t.link.is_some() && t.link == clip.link) }) else { return clip; }; + let to = self.followed(trim, (lane, idx), match trim.edge { + Edge::Start => clip.start, + Edge::End => clip.end(), + }); let still = self.session.as_ref().is_some_and(|session| { session .sources() .get(clip.source) .is_some_and(|s| engine::is_image(&s.path)) }); - trimmed_clip(clip, trim.edge, trim.to, still) + trimmed_clip(clip, trim.edge, to, still) } /// The caption as the drag is showing it, [`Player::trimmed`]'s twin: - /// display only, and the engine hears about it once, at the release. + /// display only, and the engine hears about it once, at the release. A + /// caption in the dragged group follows by the same delta, against its own + /// walls. pub(crate) fn trimmed_sub(&self, lane: Lane, idx: usize, sub: SubClip) -> SubClip { - match self.trim.filter(|t| (t.lane, t.idx) == (lane, idx)) { - Some(trim) => trimmed_sub(sub, trim.edge, trim.to), - None => sub, + let Some(trim) = self.trim.filter(|t| { + (t.lane, t.idx) == (lane, idx) || (t.link.is_some() && t.link == sub.link) + }) else { + return sub; + }; + let to = self.followed( + trim, + (lane, idx), + match trim.edge { + Edge::Start => sub.start, + Edge::End => sub.end(), + }, + ); + trimmed_sub(sub, trim.edge, to) + } + + /// The frame a trim is showing for the placement at `here`, whose edge + /// stands at `at`: the drag's own `to` when `here` is the placement the + /// press started on, and that `to`'s delta from where the press started, + /// clamped to this placement's own room, when it is a member following. + fn followed(&self, trim: Trim, here: (Lane, usize), at: u32) -> u32 { + if (trim.lane, trim.idx) == here { + return trim.to; } + let delta = i64::from(trim.to) - i64::from(trim.from); + let room = match here.0.kind { + LaneKind::Subtitle => self + .session + .as_ref() + .and_then(|session| session.trim_sub_room(here.0, here.1, trim.edge)), + _ => self + .session + .as_ref() + .and_then(|session| session.trim_room(here.0, here.1, trim.edge)), + }; + room.map_or(trim.to, |(lo, hi)| { + (i64::from(at) + delta).clamp(i64::from(lo), i64::from(hi)) as u32 + }) } /// How long the timeline is *drawn* as: its own length, and while a tail is diff --git a/crates/app/src/player/view.rs b/crates/app/src/player/view.rs index 086e259..607a8a8 100644 --- a/crates/app/src/player/view.rs +++ b/crates/app/src/player/view.rs @@ -4,12 +4,26 @@ use crate::*; impl Player { - /// The one place a clip becomes *the* selected one: a click, a right-click - /// that opens the menu, and every selection key go through here, so what a - /// keyboard marks and what a pointer marks are the same state marked the - /// same way (group and all -- see [`marked`]). + /// The one place a clip becomes *the* selected one: a plain click, a + /// right-click that opens the menu, and every selection key go through + /// here, so what a keyboard marks and what a pointer marks are the same + /// state marked the same way (group and all -- see [`marked`]). One pick, + /// because one click names one thing; [`Player::pick`] is the ctrl+click + /// that grows the selection instead. pub(crate) fn select(&mut self, target: (Lane, usize), cx: &mut Context) { - self.selected = Some(target); + self.selected.set_one(target); + cx.notify(); + } + + /// A press with ctrl held: the pick joins the selection, or leaves it if + /// it was already in -- the toggle that assembles a group by hand. Without + /// ctrl this is exactly [`Player::select`], which is why every box on the + /// bed asks this one and lets the modifier decide. + pub(crate) fn pick(&mut self, target: (Lane, usize), ctrl: bool, cx: &mut Context) { + match ctrl { + true => self.selected.toggle(target), + false => self.selected.set_one(target), + } cx.notify(); } @@ -27,7 +41,6 @@ impl Player { .filter_map(|lane| Some((lane, session.lane_clip_at(lane, now)?))) .collect() } - /// Selects the clip under the playhead, and on a repeat press the next /// lane's -- so one key reaches every clip the playhead is over, which is /// what makes selection (and everything that acts on a selection: delete, @@ -43,6 +56,7 @@ impl Player { // means; a selection off the playhead starts the walk over. let next = self .selected + .anchor() .and_then(|sel| under.iter().position(|&clip| clip == sel)) .map_or(first, |at| under[(at + 1) % under.len()]); self.select(next, cx); @@ -54,9 +68,10 @@ impl Player { pub(crate) fn select_step(&mut self, forward: bool, cx: &mut Context) { let clips = self .selected + .anchor() .zip(self.session.as_ref()) .map_or(0, |((lane, _), session)| session.lane_clips(lane).len()); - match (self.selected, clips) { + match (self.selected.anchor(), clips) { // An empty lane is a selection nothing can be stepped from -- as is // no selection at all, and the playhead answers both. (Some((lane, idx)), len) if len > 0 => { @@ -71,6 +86,32 @@ impl Player { } } + /// Every placement on every lane, in the order the lanes are drawn: what + /// Select All marks -- the clips and the captions both, one selection that + /// a Group can take apart lane by lane and a Delete can walk pick by pick. + pub(crate) fn select_all(&mut self, cx: &mut Context) { + let Some(session) = &self.session else { + return; + }; + let mut selected = Selection::new(); + for lane in session.lanes() { + let len = match lane.kind { + LaneKind::Subtitle => session.sub_lane(lane).len(), + _ => session.lane_clips(lane).len(), + }; + for idx in 0..len { + selected.add((lane, idx)); + } + } + self.selected = selected; + if self.selected.is_empty() { + // A key that does nothing looks broken: an empty timeline has + // nothing to select, and that is a thing to say rather than skip. + self.notify_user("NOTHING TO SELECT — the timeline is empty".into()); + } + cx.notify(); + } + /// Cycles the fit policy of the clip the picture is coming from -- the /// clicked one when it is a video clip, else the composite's own, exactly as /// the colour card picks its target. A whole card for one four-valued @@ -91,6 +132,7 @@ impl Player { }; let target = self .selected + .anchor() .filter(|(lane, _)| lane.kind == LaneKind::Video) .or_else(|| session.video_clip_at(session.now())); let Some((lane, idx)) = target else { diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index c71a2b5..1080dcc 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -261,12 +261,14 @@ fn every_audio_stream_of_a_file_is_a_row_usable_or_not() { /// What the clip menu offers, and where it hangs. The two items that act on /// the playhead rather than on the clicked clip are the ones that can be -/// inapplicable, and a menu at the edge of the window has to come back -/// inside it or its last item cannot be clicked at all. -/// A caption's own menu, opened on a box that is not a clip: one row that acts -/// on it -- Delete, which routes to `Player::lift_sub` -- the timeline's global -/// item beside it, and nothing else drawn at all. What a placed subtitle used to -/// have no menu, and no stroke, to do. +/// inapplicable, and a menu at the edge of the window has to come back inside +/// it or its last item cannot be clicked at all. +/// +/// A caption's own menu, opened on a box that is not a clip: the rows that act +/// on it -- Delete, which routes to `Player::lift_sub`, and the group pair now +/// that a caption may be grouped by hand -- the timeline's global items beside +/// them, and nothing else drawn at all. What a placed subtitle used to have no +/// menu, and no stroke, to do. #[test] fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { use keymap::ActionId; @@ -281,26 +283,35 @@ fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { assert_eq!( enable(ActionId::Delete, cap), Enable::Yes, - "the one thing a placed caption can be asked to do", - ); - // The clip rows are refusals of *kind* on a caption, so the menu leaves them - // out rather than drawing "click a clip first" over a clicked box. - for clip_only in [ - ActionId::Copy, - ActionId::Lift, - ActionId::Detach, - ActionId::Group, - ActionId::Equalizer, - ] { + "the one thing a placed caption could always be asked to do", + ); + // The clip rows are refusals of *kind* on a caption, so the menu leaves + // them out rather than drawing "click a clip first" over a clicked box. + for clip_only in [ActionId::Copy, ActionId::Lift, ActionId::Equalizer] { assert_eq!( enable(clip_only, cap), Enable::Hidden("this is a caption"), "{clip_only:?} is not a row on a caption", ); } - // ...and the playhead's actions are *not* among them: the split and the - // regroup act at the line and the cards fall back to the clip under it, so a - // caption in hand is no reason for them to go dead -- which, hidden, is + // The group rows are the caption's now: a caption out of any group says so + // in the detach's own words, and Group over one pick is the partner hunt. + assert_eq!( + enable(ActionId::Detach, cap), + Enable::No("this caption is not grouped") + ); + assert_eq!(enable(ActionId::Group, cap), Enable::Yes); + // ...and a caption in a group detaches like a clip does. + let grouped = Ctx { + caption: true, + caption_link: Some(3), + timeline: true, + ..Ctx::default() + }; + assert_eq!(enable(ActionId::Detach, grouped), Enable::Yes); + // ...and the playhead's actions are *not* refusals: the split and the + // regroup act at the line and the cards fall back to the clip under it, so + // a caption in hand is no reason for them to go dead -- which, hidden, is // exactly what they went: `Player::act` returns without a word on `Hidden`, // and no click on the bed clears the mark that put them there. for playhead in [ @@ -320,11 +331,17 @@ fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { // ...but live is not *listed*: every one of those rows reaches the clip // under the playhead and not the caption, and a menu opened on a caption // that offered a grade would read as the caption's. The caption's menu is - // its one row and the global pair the card already names as global. + // its own rows and the global pair the card already names as global. assert_eq!( menu_items(cap), - vec![ActionId::Paste, ActionId::Delete, ActionId::ToggleMute], - "the caption's menu is its removal and the global rows alone", + vec![ + ActionId::Paste, + ActionId::Delete, + ActionId::Detach, + ActionId::Group, + ActionId::ToggleMute, + ], + "the caption's menu is its removal, its group rows, and the global ones", ); // ...and the same reading with a clip under it is the clip menu, untouched: // the flag is off wherever a `Clip` was clicked. @@ -353,6 +370,7 @@ fn one_second(start: u32) -> SubClip { track: 0, in_us: 0, out_us: 1_000_000, + link: None, } } @@ -434,6 +452,82 @@ fn a_caption_placed_before_the_marked_one_leaves_the_mark_on_the_original() { ); } +/// A caption a hand grouped with a clip pairs it for the whole-take question: +/// deleting the picture takes the group, because the group -- not the lane's +/// kind -- is what pairs. The engine door is the one the menu's Group row +/// reaches (`group_all`), tested here from the selection's own side of it. +#[test] +fn a_caption_grouped_with_a_clip_pairs_it_for_the_whole_take_question() { + let (mut session, lane) = with_subtitle_lane(); + session + .place_sub(lane, 0, one_second(0)) + .expect("the caption goes down"); + session + .group_all(&[(Lane::V1, 0), (lane, 0)]) + .expect("a clip and a caption are a group"); + // Paired through the caption alone: the sound half is gone (the fixture's + // take was split above), and the question is the picture's to answer. + assert!( + whole_take(&session, Lane::V1, 0), + "the caption the clip was grouped with pairs it" + ); + // ...and the detach takes the pairing off again. + assert!(session.ungroup(lane, 0)); + assert!( + !whole_take(&session, Lane::V1, 0), + "ungrouped, the clip is a half like any other" + ); +} + +/// The manual group's oracle question: a selection of placements, one per lane. +/// Two picks on two lanes is a group waiting to happen; a lane picked twice is +/// the one thing a group may never hold; a single pick is the partner hunt. +#[test] +fn group_is_live_over_a_multi_selection_and_words_a_repeated_lane() { + use keymap::ActionId; + let distinct = Ctx { + timeline: true, + picks: 2, + pick_lanes: 2, + ..Ctx::default() + }; + assert_eq!(enable(ActionId::Group, distinct), Enable::Yes); + let twice = Ctx { + timeline: true, + picks: 2, + pick_lanes: 1, + ..Ctx::default() + }; + assert_eq!( + enable(ActionId::Group, twice), + Enable::No("a group is one clip per lane: keep one pick per track") + ); + // One pick and none at all: the partner hunt and its own refusal, which + // the player words rather than the oracle. + let one = Ctx { + timeline: true, + picks: 1, + pick_lanes: 1, + ..Ctx::default() + }; + assert_eq!(enable(ActionId::Group, one), Enable::Yes); + // Nothing picked at all, on an open timeline: the partner hunt's own + // refusal, worded by the player rather than the oracle. + let none = Ctx { + timeline: true, + ..Ctx::default() + }; + assert_eq!(enable(ActionId::Group, none), Enable::Yes); + // Stale picks (an edit moved the indices) count as none. + let stale = Ctx { + timeline: true, + picks: 0, + pick_lanes: 0, + ..Ctx::default() + }; + assert_eq!(enable(ActionId::Group, stale), Enable::Yes); +} + /// The playhead's actions with a caption marked: live, and doing what they say. /// Hidden, they were dead *and* silent -- `Player::act` says nothing on a class /// refusal -- from the first click on a caption until something else was @@ -1338,7 +1432,7 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { // bed: ten seconds in, five seconds past the end of the timeline, and // no mark anywhere near enough to pull it back. let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)]; - let marks = snap_marks(&clips, None, frame_at(session.now(), fps)); + let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps)); let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps); let (at, cue) = landing(under, 0, 0, true, scale.snap_frames(fps), &marks); assert_eq!((at, cue), (300, None), "the pointer is on frame 300"); diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index d522f4f..8d32672 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -266,22 +266,77 @@ fn a_lane_row_is_a_fixed_header_and_a_bed_that_can_be_hit() { assert_eq!(lanes_h(2), 2. * LANE_H + 8.); } +/// The selection itself: clicks in order, the anchor under the hand, the +/// toggle that assembles a group, and the plain click that replaces it all. +#[test] +fn a_selection_holds_its_picks_in_click_order_and_anchors_the_last() { + use crate::Selection; + + let mut sel = Selection::new(); + assert!(sel.is_empty()); + assert_eq!(sel.anchor(), None); + + let (v, a, cap) = ( + (Lane::V1, 0), + (Lane::A1, 1), + (Lane::new(LaneKind::Subtitle, 0), 0), + ); + sel.set_one(v); + assert_eq!(sel.len(), 1); + assert_eq!(sel.anchor(), Some(v)); + + // Ctrl-clicks join, in the order they were made. + sel.toggle(a); + sel.toggle(cap); + assert_eq!(sel.picks(), &[v, a, cap]); + assert_eq!(sel.anchor(), Some(cap), "the last pick is the anchor"); + assert!(sel.contains(a)); + + // ...and a ctrl-click on a pick already held takes it back out, leaving + // the others where they were. + sel.toggle(a); + assert_eq!(sel.picks(), &[v, cap]); + assert!(!sel.contains(a)); + + // A plain click is the whole selection, one pick: whatever was held gives + // way to the thing just named. + sel.set_one(a); + assert_eq!(sel.picks(), &[a]); + + // `add` joins without disturbing -- Select All's builder. + let mut all = Selection::new(); + all.add(v); + all.add(a); + all.add(v); + assert_eq!(all.picks(), &[v, a], "a pick is never held twice"); + + sel.clear(); + assert!(sel.is_empty()); + assert_eq!(sel.anchor(), None); +} + #[test] fn a_click_marks_the_whole_group_and_nothing_else() { let (v, a) = ((Lane::V1, 0), (Lane::A1, 0)); - // Clicking the video half of group 1 marks the audio half with it. - assert!(marked(v, Some(1), Some(v), Some(1))); - assert!(marked(a, Some(1), Some(v), Some(1))); + // Clicking the video half of group 1 marks the audio half with it -- the + // pick, and everything sharing its link. + assert!(marked(v, Some(1), &[v], &[Some(1)])); + assert!(marked(a, Some(1), &[v], &[Some(1)])); // Another group's clips stay unmarked, in either lane. - assert!(!marked((Lane::V1, 1), Some(2), Some(v), Some(1))); - assert!(!marked((Lane::A1, 1), Some(2), Some(v), Some(1))); + assert!(!marked((Lane::V1, 1), Some(2), &[v], &[Some(1)])); + assert!(!marked((Lane::A1, 1), Some(2), &[v], &[Some(1)])); // A half a lift left behind has no group: it marks itself only, which // is what makes it separately deletable. Two ungrouped clips must not // mark each other by both being ungrouped. - assert!(marked(a, None, Some(a), None)); - assert!(!marked(v, None, Some(a), None)); + assert!(marked(a, None, &[a], &[None])); + assert!(!marked(v, None, &[a], &[None])); + // A caption ctrl-clicked into the selection marks the clip it was pinned + // to, and the caption is marked by the clip's pick just the same. + let cap = (Lane::new(LaneKind::Subtitle, 0), 0); + assert!(marked(cap, Some(1), &[cap, v], &[None, Some(1)])); + assert!(marked(a, Some(1), &[cap, v], &[None, Some(1)])); // Nothing selected marks nothing. - assert!(!marked(v, Some(1), None, None)); + assert!(!marked(v, Some(1), &[], &[])); } #[test] @@ -435,6 +490,7 @@ fn a_caption_trim_preview_lands_where_the_release_commits() { track: 0, in_us: 0, out_us, + link: None, }; session .place_sub(lane, 30, whole) diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index f180c98..adb7527 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -1085,6 +1085,7 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { track: 0, in_us: 0, out_us: 5_000_000, + link: None, }, ) .expect("the palette row goes down on the lane"); diff --git a/crates/app/src/tests/view.rs b/crates/app/src/tests/view.rs index 8ace825..67118c2 100644 --- a/crates/app/src/tests/view.rs +++ b/crates/app/src/tests/view.rs @@ -164,20 +164,21 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { let lanes: [&[Clip]; 2] = [&video, &audio]; // Nothing in the hand: both lanes' edges, the playhead, and 0. - let mut all = snap_marks(&lanes, None, 300); + let mut all = snap_marks(&lanes, None, None, 300); all.sort_unstable(); assert_eq!(all, [0, 100, 100, 160, 160, 300, 400, 430]); - // The video half in the hand: its own edges are gone, and so are its - // group's on the other lane -- both boxes travel with the drag. The - // lone audio clip is still a target, which is the whole point: a take - // being carried on V1 lands flush with a sound on A1. - let mut carried = snap_marks(&lanes, Some((0, 0)), 300); + // The video half in the hand, with its group named as the caller reads it + // off the pick: its own edges are gone, and so are its group's on the + // other lane -- both boxes travel with the drag. The lone audio clip is + // still a target, which is the whole point: a take being carried on V1 + // lands flush with a sound on A1. + let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300); carried.sort_unstable(); assert_eq!(carried, [0, 300, 400, 430]); // An index that names no clip skips nothing and still answers. - assert_eq!(snap_marks(&[], Some((3, 9)), 0), [0, 0]); + assert_eq!(snap_marks(&[], Some((3, 9)), None, 0), [0, 0]); } /// The line the bed draws, and the switch that turns the whole thing off. diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 2730314..4e416e6 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -5,7 +5,8 @@ use crate::*; /// Whether this clip is a whole take, i.e. whether deleting it may close the /// hole under it: a take is what the first pair of lanes carries between them, /// `V1`'s picture and the sound grouped with it, and dropping one moves the -/// frames after it on every lane. +/// frames after it on every lane. A caption a hand grouped with the clip +/// counts as its partner too: the group is what pairs, not the lane's kind. /// /// Everything else is a half or a layer, and is *lifted* instead: a half whose /// picture was lifted (what a lift leaves behind) has no take to ripple, and a @@ -20,8 +21,12 @@ pub(crate) fn whole_take(session: &PlaybackSession, lane: Lane, idx: usize) -> b .lanes() .into_iter() .filter(|&other| other != lane) - .flat_map(|other| session.lane_clips(other)) - .any(|o| o.link.is_some() && o.link == clip.link) + .flat_map(|other| { + let clips = session.lane_clips(other).iter().map(|c| c.link); + let subs = session.sub_lane(other).iter().map(|s| s.link); + clips.chain(subs) + }) + .any(|link| link.is_some() && link == clip.link) }; match (lane.kind, lane.ord) { (_, 1..) => false, @@ -69,19 +74,108 @@ pub(crate) fn span_partner(session: &PlaybackSession, lane: Lane, idx: usize) -> opposite.into_iter().chain(same).find_map(matches) } -/// Whether a click marks this clip: the clip that was clicked always, and the -/// other lane's clip of the same group with it. A clip whose group has no other -/// half -- what a lift leaves behind -- marks only itself, which is what makes a -/// detached half separately deletable. +/// What the timeline has picked: every clip and caption a hand ctrl-clicked +/// into the selection, in click order and with no two the same. The last of +/// them is the [`anchor`](Selection::anchor) -- the one every action that is +/// about *one* thing (delete, lift, copy, the equalizer) acts on -- and the +/// whole list is what a manual Group names to the engine. +/// +/// Indices move under every edit, exactly as the single mark this replaces +/// did, so every edit that renumbers a lane clears the picks it cannot keep +/// honest. Pure and engine-free, so a test can build one without a window. +#[derive(Clone, Debug, Default, PartialEq)] +pub(crate) struct Selection { + /// `(lane, index into that lane's own list)` -- a subtitle lane's index + /// space for a caption, exactly the pair a click was told about. + picks: Vec<(Lane, usize)>, +} + +impl Selection { + /// Nothing picked: what the timeline starts as and what an edit that moved + /// indices leaves behind. + pub(crate) fn new() -> Self { + Self::default() + } + + /// The one a plain click and every selection key leave: the whole of the + /// selection, one pick. A click names a thing, and the things it had been + /// naming along with it are no longer named. + pub(crate) fn set_one(&mut self, pick: (Lane, usize)) { + self.picks.clear(); + self.picks.push(pick); + } + + /// A ctrl-click: the pick joins the selection if it was not in it and + /// leaves if it was -- the toggle that assembles a group by hand. The + /// order is the order they were picked in, and the anchor rides on it. + pub(crate) fn toggle(&mut self, pick: (Lane, usize)) { + match self.picks.iter().position(|&p| p == pick) { + Some(at) => { + self.picks.remove(at); + } + None => self.picks.push(pick), + } + } + + /// The last pick: what "the selected clip" is to every action that acts on + /// one thing. The click order puts it under the hand, which is where the + /// eye is. + pub(crate) fn anchor(&self) -> Option<(Lane, usize)> { + self.picks.last().copied() + } + + /// Whether `pick` is one of the selection's -- the question a right-click + /// asks before it decides whether the menu is about the selection or + /// about the clip under it. + pub(crate) fn contains(&self, pick: (Lane, usize)) -> bool { + self.picks.contains(&pick) + } + + /// Every pick, in click order: what a manual Group names to the engine. + pub(crate) fn picks(&self) -> &[(Lane, usize)] { + &self.picks + } + + pub(crate) fn is_empty(&self) -> bool { + self.picks.is_empty() + } + + /// A pick that joins without disturbing the rest -- Select All's builder, + /// which names every placement there is and cannot be a `set_one`. + pub(crate) fn add(&mut self, pick: (Lane, usize)) { + if !self.picks.contains(&pick) { + self.picks.push(pick); + } + } + + pub(crate) fn len(&self) -> usize { + self.picks.len() + } + + pub(crate) fn clear(&mut self) { + self.picks.clear(); + } +} + +/// Whether a click marks this box: any pick on it always, and any box sharing +/// a group id with a pick -- the clip the anchor was ctrl-clicked beside, and +/// the caption a hand pinned to a clip. A group whose only member is picked +/// marks that member alone, which is what makes a detached half separately +/// deletable. +/// +/// `pick_links` are the group ids of the picks themselves, read by the caller +/// off the session in the same order as `picks` -- the one fact this pure +/// question cannot know. pub(crate) fn marked( here: (Lane, usize), link: Option, - sel: Option<(Lane, usize)>, - sel_link: Option, + picks: &[(Lane, usize)], + pick_links: &[Option], ) -> bool { - sel == Some(here) || (link.is_some() && link == sel_link) + picks.contains(&here) || (link.is_some() && pick_links.contains(&link)) } + /// Whether a clip is wide enough to be worth naming. pub(crate) fn show_label(w: f32) -> bool { w >= LABEL_MIN_W @@ -368,18 +462,22 @@ pub(crate) fn snapped(raw: u32, len: u32, tol: u32, marks: &[u32]) -> u32 { /// The edges worth landing on, off *every* lane: both ends of every clip on the /// timeline, less `skip` -- the clip being dragged, which does not snap to where -/// it already is -- and less the other halves of its group, which travel with -/// it. `skip` is a lane's place in `lanes` and an index into it. The playhead -/// and the head of the timeline go on the end: a clip meets the cursor and the -/// start of the show as readily as it meets another take. +/// it already is -- and less `skip_link`, the group id of whatever is being +/// dragged: its clips travel with it, and so does any caption the id names. +/// `skip` is a lane's place in `lanes` and an index into it; `skip_link` is +/// read off a caption by the caller, whose drag has no clip for `skip` to +/// name. The playhead and the head of the timeline go on the end: a clip meets +/// the cursor and the start of the show as readily as it meets another take. /// /// All lanes rather than the one being dropped on, because a cut is made across /// the timeline: a title on V2 lines up with the shot under it, and a sound /// effect lines up with the frame it belongs to. -pub(crate) fn snap_marks(lanes: &[&[Clip]], skip: Option<(usize, usize)>, playhead: u32) -> Vec { - let link = skip - .and_then(|(lane, idx)| lanes.get(lane)?.get(idx)) - .and_then(|clip| clip.link); +pub(crate) fn snap_marks( + lanes: &[&[Clip]], + skip: Option<(usize, usize)>, + skip_link: Option, + playhead: u32, +) -> Vec { let mut marks: Vec = lanes .iter() .enumerate() @@ -388,7 +486,8 @@ pub(crate) fn snap_marks(lanes: &[&[Clip]], skip: Option<(usize, usize)>, playhe .iter() .enumerate() .filter(move |&(idx, clip)| { - Some((lane, idx)) != skip && !(link.is_some() && clip.link == link) + Some((lane, idx)) != skip + && !(skip_link.is_some() && clip.link == skip_link) }) .flat_map(|(_, clip)| [clip.start, clip.end()]) }) diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index df1328e..2e88167 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -91,7 +91,7 @@ impl Player { /// with nothing marked the section says how to get one, and each button is /// dimmed with the oracle's reason rather than missing. fn selection_section(&self, cx: &mut Context) -> impl IntoElement { - let picked = self.selected.and_then(|(lane, idx)| { + let picked = self.selected.anchor().and_then(|(lane, idx)| { let session = self.session.as_ref()?; let clip = session.lane_clips(lane).get(idx).copied()?; let source = session.sources().get(clip.source); @@ -107,15 +107,27 @@ impl Player { // marked caption -- while the bed draws that caption in the selection's // own colours and this panel's Delete lifts it. The panel says what is // marked or it is telling the user the opposite of what they can see. - let caption = self.selected.filter(|_| picked.is_none()).and_then(|(lane, idx)| { + let caption = self + .selected + .anchor() + .filter(|_| picked.is_none()) + .and_then(|(lane, idx)| { let sub = self.session.as_ref()?.sub_lane(lane).get(idx).copied()?; Some((lane, sub)) }); + // A multi-selection is named for its anchor and counted: what the + // panel shows is the anchor's settings, and the count says there is + // more in hand than the panel is showing. + let more = self.selected.len().saturating_sub(1); let head = match (&picked, &caption) { (Some((lane, _, name, _)), _) => format!("{} · {}", lane.label(), name), (None, Some((lane, _))) => format!("{} · caption", lane.label()), (None, None) => "Nothing selected".to_string(), }; + let head = match more { + 0 => head, + n => format!("{head} · and {n} more picked"), + }; let detail = match &picked { Some((_, clip, _, _)) => format!( "{} → {} · {} · {}", diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index cbccc37..676e67e 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -596,13 +596,20 @@ impl Player { // The group ids some *other* lane carries: a clip whose id is in here // has a half elsewhere, and one whose is not is a detached half however // many lanes there are. + // The group ids some *other* lane carries, on either of its lists: a + // placement whose id is in here has a half elsewhere -- a clip on + // another track, or a caption pinned to this clip -- and one whose is + // not is detached however many lanes there are. let others: Vec = self.session.as_ref().map_or_else(Vec::new, |session| { session .lanes() .into_iter() .filter(|&other| other != lane) - .flat_map(|other| session.lane_clips(other)) - .filter_map(|clip| clip.link) + .flat_map(|other| { + let clips = session.lane_clips(other).iter().filter_map(|c| c.link); + let subs = session.sub_lane(other).iter().filter_map(|s| s.link); + clips.chain(subs) + }) .collect() }); let name = lane.label(); @@ -629,7 +636,7 @@ impl Player { .session .as_ref() .map_or(&[][..], PlaybackSession::sources); - let (sel, sel_link) = (self.selected, self.selected_link()); + let (picks, pick_links) = self.marks(); let audio = lane.kind == LaneKind::Audio; // A subtitle lane holds no `Clip` and every other lane holds no // `SubClip`, so the two lists below are never both full and the bed @@ -964,7 +971,7 @@ impl Player { f64::from(clip.start) / self.fps, f64::from(clip.frames()) / self.fps, ); - let on = marked((lane, i), clip.link, sel, sel_link); + let on = marked((lane, i), clip.link, &picks, &pick_links); // A group with a half in the other lane wears its tint; // one without is outlined, so a detached half is visible // as detached before anyone clicks it. @@ -1074,7 +1081,10 @@ impl Player { // than jump its head under it. this.grab = this.frame_under(event.position.x).saturating_sub(head); - this.select((lane, i), cx); + // Ctrl held, the pick joins the selection + // instead of replacing it -- the toggle a + // group is assembled by hand with. + this.pick((lane, i), event.modifiers.control, cx); }), ) // The right button selects exactly as the left one @@ -1115,8 +1125,14 @@ impl Player { .on_mouse_down( MouseButton::Left, cx.listener( - move |this, _: &MouseDownEvent, _, cx| { - this.start_trim(lane, i, edge, cx); + move |this, event: &MouseDownEvent, _, cx| { + this.start_trim( + lane, + i, + edge, + event.modifiers.control, + cx, + ); }, ), ) @@ -1277,9 +1293,13 @@ impl Player { let tip = sub_tip.clone(); let head = shown_sub.start; // Marked the way every other box on this bed is marked, - // in this lane's own index space -- a caption has no - // group, so nothing else lights with it. - let on = sel == Some((lane, i)); + // in this lane's own index space -- and a caption in a + // group lights with the clips it was pinned to, exactly + // as a clip lights with its halves. + let on = marked((lane, i), placed.link, &picks, &pick_links); + // ...and wears the group's border rather than a lone + // box's, so what travels together reads together. + let grouped = placed.link.is_some_and(|link| others.contains(&link)); div() .id((row_id.clone(), i)) .absolute() @@ -1292,6 +1312,8 @@ impl Player { .border_1() .border_color(rgb(if on { STROKE_SELECTED() + } else if grouped { + ACCENT_PRIMARY() } else { FG_SECONDARY() })) @@ -1325,8 +1347,9 @@ impl Player { // ...and it marks the caption, exactly as // the press that may become a clip's drag // marks the clip: picking a caption up and - // putting it back down is a click. - this.select((lane, i), cx); + // putting it back down is a click. Ctrl + // toggles it into the selection like a clip. + this.pick((lane, i), event.modifiers.control, cx); }), ) // The right button marks it and hangs the menu at @@ -1358,8 +1381,14 @@ impl Player { .on_mouse_down( MouseButton::Left, cx.listener( - move |this, _: &MouseDownEvent, _, cx| { - this.start_trim(lane, i, edge, cx); + move |this, event: &MouseDownEvent, _, cx| { + this.start_trim( + lane, + i, + edge, + event.modifiers.control, + cx, + ); }, ), ) diff --git a/crates/engine/tests/export.rs b/crates/engine/tests/export.rs index 5595f43..4d05b2d 100644 --- a/crates/engine/tests/export.rs +++ b/crates/engine/tests/export.rs @@ -1010,7 +1010,7 @@ fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() { session.set_proxies(true); session.save_project(&project).expect("save"); let text = std::fs::read_to_string(&project).expect("read the project back"); - assert!(text.starts_with("edith 15\n"), "{text}"); + assert!(text.starts_with("edith 16\n"), "{text}"); assert!(text.contains("\nproxy on\n"), "{text}"); let reopened = PlaybackSession::open_project(&project).expect("load"); assert!(reopened.proxies(), "the switch came back on"); diff --git a/crates/engine/tests/export_subs.rs b/crates/engine/tests/export_subs.rs index 4478265..e219b79 100644 --- a/crates/engine/tests/export_subs.rs +++ b/crates/engine/tests/export_subs.rs @@ -826,6 +826,7 @@ fn on_lanes(tracks: Vec, placed: &[(usize, u32, u32, i64, i64)]) track, in_us, out_us, + link: None, }, ) .expect("the lane is empty, so the placement lands"); diff --git a/crates/engine/tests/lanes.rs b/crates/engine/tests/lanes.rs index 2609d15..84e1e3e 100644 --- a/crates/engine/tests/lanes.rs +++ b/crates/engine/tests/lanes.rs @@ -449,6 +449,7 @@ fn a_subtitle_lane_is_a_peer_and_every_media_path_refuses_it() { track: 0, in_us: 0, out_us: 2_000_000, + link: None, }; project.place_sub(s1, 0, caption).expect("a caption goes down"); @@ -541,6 +542,7 @@ fn a_paste_opens_its_room_under_the_captions_too() { track: 0, in_us: 0, out_us: 2_000_000, + link: None, }, ) .expect("a caption over the first two seconds"); diff --git a/crates/engine/tests/pgs_bitmaps.rs b/crates/engine/tests/pgs_bitmaps.rs index eedbf1d..e11fb31 100644 --- a/crates/engine/tests/pgs_bitmaps.rs +++ b/crates/engine/tests/pgs_bitmaps.rs @@ -98,6 +98,7 @@ fn the_session_maps_a_pgs_track_onto_the_timeline_and_draws_it() { track: pick, in_us: cues[0].start_us, out_us: cues[0].end_us, + link: None, }, ) .expect("the lane is empty, so the placement lands"); diff --git a/crates/engine/tests/saveload.rs b/crates/engine/tests/saveload.rs index f75f311..b9cf190 100644 --- a/crates/engine/tests/saveload.rs +++ b/crates/engine/tests/saveload.rs @@ -291,7 +291,7 @@ fn a_version_1_project_loads_fully_grouped_and_saves_as_version_7() { let v2 = dir.join("new.edith"); loaded.save_project(&v2).expect("save"); let text = std::fs::read_to_string(&v2).expect("read back"); - assert!(text.starts_with("edith 15\n"), "{text}"); + assert!(text.starts_with("edith 16\n"), "{text}"); assert!( text.contains("\nresolution 1280 720\n"), "a project with no resolution of its own is saved at source 0's: {text}" @@ -379,7 +379,7 @@ fn a_version_4_project_holds_more_than_two_lanes() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 16\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ video 1 0 0 30 0 3 - - fit 1000\naudio 1\n\ video 2 40 0 20 0 - - - fit 1000\naudio 2 0 0 30 0 3 - - fit 1000\n", "a four-lane project is written as it was read, three versions on" @@ -409,7 +409,7 @@ fn a_version_5_project_carries_per_clip_equalizers() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 16\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ eq 12000.0:6.25:0.5:hs\n\ video 1 0 0 30 0 - 0 - fit 1000\nvideo 1 30 30 60 0 - 1 - fit 1000\n\ @@ -444,7 +444,7 @@ fn a_version_6_project_carries_per_clip_colours() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 16\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ eq 80.0:-3.0:0.707:ls\n\ color 0.1:1.2:0.9:-0.3\n\ color -0.25:1.0:0.0:0.5\n\ @@ -494,7 +494,7 @@ fn a_version_7_project_carries_a_resolution_and_fit_policies() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 15\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 16\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\ video 1 0 0 30 0 - - - fill 1000\nvideo 1 30 30 60 0 - - - center 1000\n\ audio 1 0 0 60 0 - - - fit 1000\n", "a v7 project is written back as the v8 it now is: the same clips, each \ @@ -752,7 +752,7 @@ fn malformed_files_are_numbered_errors_and_never_panics() { for (text, want) in [ ( - "edith 16\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n", + "edith 17\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n", "line 1", ), // An eq index the table does not hold, and a band shape there is none. diff --git a/crates/engine/tests/silence.rs b/crates/engine/tests/silence.rs index ccde715..3c756ef 100644 --- a/crates/engine/tests/silence.rs +++ b/crates/engine/tests/silence.rs @@ -386,7 +386,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() { .expect("save"); let text = std::fs::read_to_string(&file).expect("read it back"); assert!( - text.starts_with("edith 15"), + text.starts_with("edith 16"), "{:?}", &text[..16.min(text.len())] ); diff --git a/crates/engine/tests/subtitles.rs b/crates/engine/tests/subtitles.rs index 0a8d7df..489b567 100644 --- a/crates/engine/tests/subtitles.rs +++ b/crates/engine/tests/subtitles.rs @@ -260,7 +260,7 @@ fn a_project_keeps_its_subtitles_across_a_save() { let project = dir.join("cut.edith"); session.save_project(&project).expect("save"); let text = std::fs::read_to_string(&project).expect("read the project back"); - assert!(text.starts_with("edith 15\n"), "{text}"); + assert!(text.starts_with("edith 16\n"), "{text}"); assert!( text.contains("\nsubtitle - test_subs.srt\n"), "the reference is written relative, and no cue is: {text}" @@ -722,6 +722,7 @@ fn whole(track: usize) -> SubClip { track, in_us: 0, out_us: 5_000_000, + link: None, } } @@ -754,6 +755,7 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() { track: 0, in_us: 0, out_us: 2_000_000, + link: None, } ); @@ -770,6 +772,7 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() { track: 0, in_us: 500_000, out_us: 2_000_000, + link: None, } ); @@ -785,6 +788,7 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() { track: 0, in_us: 500_000, out_us: 2_000_000, + link: None, } ); @@ -805,6 +809,7 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() { track: 0, in_us: 500_000, out_us: 2_000_000, + link: None, }, SubClip { start: 30, @@ -812,8 +817,10 @@ fn a_caption_is_placed_trimmed_moved_and_undone_on_its_lane() { track: 0, in_us: 0, out_us: 2_000_000, + link: None, }, SubClip { + link: None, start: 30, ..whole(0) }, @@ -1237,13 +1244,14 @@ fn subtitle_lanes_and_their_captions_survive_a_save() { track: 0, in_us: 500_000, out_us: 1_500_000, + link: None, }; session.place_sub(s1, 10, caption).expect("a caption goes down"); let project = dir.join("cut.edith"); session.save_project(&project).expect("save"); let text = std::fs::read_to_string(&project).expect("read the project back"); - assert!(text.starts_with("edith 15\n"), "{text}"); + assert!(text.starts_with("edith 16\n"), "{text}"); assert!( text.contains("\nsub 1 10 45 0 500000 1500000\n"), "the placement is one line: where it sits, how long, whose words, and \ @@ -1309,7 +1317,7 @@ fn a_version_14_project_keeps_its_palette_and_places_nothing() { let now = dir.join("new.edith"); loaded.save_project(&now).expect("save"); let text = std::fs::read_to_string(&now).expect("read back"); - assert!(text.starts_with("edith 15\n"), "{text}"); + assert!(text.starts_with("edith 16\n"), "{text}"); assert!( text.contains("\nsubtitle - test_subs.srt\n"), "the row survives the migration: {text}" @@ -1334,7 +1342,7 @@ fn a_caption_naming_a_track_the_palette_does_not_have_is_refused() { let path = dir.join("bad.edith"); std::fs::write( &path, - "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 16\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ subtitle - test_subs.srt\nvideo 1 0 0 30 0 0 - - fit 1000\n\ audio 1 0 0 30 0 0 - - fit 1000\nsub 1 0 45 3 0 1000000\n", ) @@ -1349,7 +1357,7 @@ fn a_caption_naming_a_track_the_palette_does_not_have_is_refused() { let empty = dir.join("empty.edith"); std::fs::write( &empty, - "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 16\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ subtitle - test_subs.srt\nvideo 1 0 0 30 0 0 - - fit 1000\n\ audio 1 0 0 30 0 0 - - fit 1000\nsub 1 0 45 0 1000000 1000000\n", )