From 1139174b72e4420544c5ebcc343f1318dbd53fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 14 Aug 2026 18:55:47 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(subs):=20one=20subtitle=20trac?= =?UTF-8?q?k=20is=20shown=20and=20every=20placed=20one=20is=20exported?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The picture drew every subtitle lane at once, so three lanes of different words were three plates over one film and two hundred were nonsense. One lane draws now -- the one whose header dot is lit -- and clicking another lane's header moves the picture to it. The pick is resolved against the lanes there are at the moment it is read (`subs::active_lane`), so one lane needs no picking, the first lane added draws, and removing the shown lane promotes the first one left instead of blanking the picture. The overlay asks the shown lane for its cues and no other, so a frame costs what one lane costs whatever the stack is. What travels in a file is untouched by that pick: every subtitle lane on the timeline is its own track in the output. What did travel wrongly is a track sitting in the *palette* on no lane at all -- with every subtitle lane emptied, the engine's palette fallback wrote all of them into the file. `Player::export_subs` now answers with the tracks a lane places, which is the same sentence the card says. --- crates/app/src/main.rs | 36 ++++++++------ crates/app/src/player/export.rs | 31 +++++++++--- crates/app/src/player/library.rs | 23 +++++---- crates/app/src/player/timeline_edit.rs | 46 ++++++++++------- crates/app/src/subs.rs | 19 +++++++ crates/app/src/tests/media.rs | 25 ++++++++++ crates/app/src/tests/mod.rs | 2 +- crates/app/src/ui/preview.rs | 69 +++++++++++--------------- crates/app/src/ui/timeline.rs | 28 ++++++++--- 9 files changed, 177 insertions(+), 102 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index f8c20c7..bb9d181 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -226,8 +226,8 @@ struct Player { /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement /// no magnet may take away. snap: bool, - /// Whether the subtitle lanes draw at all -- the mute over every lane's eye - /// ([`Player::subs_off`]), not a lane of its own. On by default and off by + /// Whether the subtitle lanes draw at all -- the mute over the shown lane + /// ([`Player::sub_lane`]), not a lane of its own. On by default and off by /// one stroke /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for /// anyone watching the picture rather than reading it. The player's, not the @@ -243,22 +243,26 @@ struct Player { /// like every other index here -- track 2 of one project is not track 2 of /// the next. sub_track: usize, - /// The subtitle lanes whose eye is shut: every lane shows its captions - /// until this says otherwise, so a lane that was just added is a lane that - /// draws. Held as the lanes that are *off* rather than a flag per lane, so - /// adding one needs no bookkeeping at all. + /// Which subtitle lane is *shown*: one of them and never two, the way a + /// player has one subtitle track chosen at a time -- two hundred lanes of + /// different words all drawn at once is two hundred plates over one + /// picture, and nothing readable. /// - /// Read where the cues are drawn ([`Player::subtitle_overlay`]): shutting an - /// eye takes that lane's plate off the picture and leaves its captions on - /// the lane. Not saved -- a `.edith` has no line for it yet. + /// `None` is nobody having picked yet, which reads as the first subtitle + /// lane ([`Player::active_sub_lane`]) -- so one lane is shown without a + /// pick, the first lane added draws, and a pick naming a lane that has + /// since gone falls back to the first rather than showing nothing. + /// + /// Read where the cues are drawn ([`Player::subtitle_overlay`]) and nowhere + /// else: what an *export* writes is every lane on the timeline + /// ([`engine::export`]), which this pick has no say in. Not saved -- a + /// `.edith` has no line for it yet. /// /// A [`Lane`] handle is a position among its kind, so a removal or a - /// reorder leaves every shut eye naming another track: they are dropped - /// wholesale there, exactly as the selection and the open cards are - /// ([`Player::remove_lane`], [`Player::reorder_lane`]) -- which is why a - /// lane added in a removed one's place opens with its eye open, as every - /// new lane does. - subs_off: Vec, + /// reorder leaves a pick naming another track: it is dropped there, + /// exactly as the selection and the open cards are ([`Player::remove_lane`], + /// [`Player::reorder_lane`]), which shows the first lane again. + sub_lane: Option, /// The frame the live gesture is about to land on, or `None` while it is /// over open bed: the line every lane draws so the snap is seen before it /// happens rather than discovered after the release. Stale between gestures, @@ -670,7 +674,7 @@ fn main() { snap: true, subs_on: true, sub_track: 0, - subs_off: Vec::new(), + sub_lane: None, snap_cue: None, ghost: None, lane_drop: None, diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index c02ab14..939a83d 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -510,15 +510,24 @@ impl Player { .detach(); } - /// The subtitle tracks an export of this timeline carries: every one with a - /// cue left in the exported range ([`PlaybackSession::timeline_cues`], the - /// very map the file is written from), in the library's own order. + /// The subtitle tracks an export of this timeline carries: every one a + /// subtitle *lane* places, with a cue left in the exported range + /// ([`PlaybackSession::timeline_cues`], the very map the file is written + /// from), in the library's own order. /// - /// Worked out from the cues each time rather than kept as a pick, which is - /// what makes it impossible to desync: a row added or taken off shifts every - /// index after it, and a stored list would then name tracks nobody chose. - /// `Player::sub_track` stays what it always was -- which palette row the - /// list *marks* -- and has no say here. + /// On the timeline or not at all: a track sitting in the palette is a track + /// nobody put anywhere, and one dropped off its lane is one somebody took + /// away -- neither belongs in the file. Without the placement test they came + /// back through the engine's palette door (`export::planned_subtitles` falls + /// back to these picks when no lane holds anything), so emptying every + /// subtitle lane and exporting wrote all three of them into the output. + /// + /// Worked out from the timeline each time rather than kept as a pick, which + /// is what makes it impossible to desync: a row added or taken off shifts + /// every index after it, and a stored list would then name tracks nobody + /// chose. `Player::sub_track` stays what it always was -- which palette row + /// the list *marks* -- and has no say here, and neither has the lane that is + /// shown over the picture ([`Player::active_sub_lane`]): every lane travels. /// /// The honest input and not the final answer: the engine filters it again /// per track (a track that could not be read, a picture one) and says so in @@ -527,7 +536,13 @@ impl Player { let Some(session) = self.session.as_ref() else { return Vec::new(); }; + let placed: Vec = session + .subtitle_lanes() + .into_iter() + .flat_map(|lane| session.sub_lane(lane).iter().map(|sub| sub.track)) + .collect(); (0..session.subtitles().len()) + .filter(|i| placed.contains(i)) .filter(|&i| !session.timeline_cues(i).is_empty()) .collect() } diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 1d92e2b..e1e4ec0 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -147,10 +147,10 @@ impl Player { self.clipboard = None; self.selected = None; self.selected_asset = None; - // The subtitle rows go with the timeline they were on, and so do the - // eyes: S1 of one project is not S1 of the next. + // 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. self.sub_track = 0; - self.subs_off.clear(); + self.sub_lane = None; self.context_menu = None; self.library_menu = None; self.eq_open = None; @@ -1105,10 +1105,11 @@ impl Player { self.color_open = None; self.speed_open = None; self.close_silence(); - // The eyes with them: a `Lane` is a position among its - // kind, so every shut one now names another track -- - // the same reason the selection and the cards go. - self.subs_off.clear(); + // The shown lane with them: a `Lane` is a position among + // its kind, so a pick now names another track -- the same + // reason the selection and the cards go. The first lane + // left is drawn ([`subs::active_lane`]). + self.sub_lane = None; format!( "{} REMOVED — {} brings it back", lane.label(), @@ -1161,10 +1162,10 @@ impl Player { self.color_open = None; self.speed_open = None; self.close_silence(); - // The eyes with them: a `Lane` is a position among its - // kind, so every shut one now names another track -- - // the same reason the selection and the cards go. - self.subs_off.clear(); + // The shown lane with them: a `Lane` is a position among its + // kind, so a pick now names another track -- the same reason + // the selection and the cards go. + self.sub_lane = None; } self.notify_user( format!( diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 02dbf5f..f437111 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -371,29 +371,41 @@ impl Player { cx.notify(); } - /// A subtitle lane's eye: whether it draws its captions. State only for now - /// -- what reads it is the slice that draws the lanes over the picture -- - /// and said out loud, because a toggle whose only effect is a header glyph - /// has to say what it has and has not done yet. - pub(crate) fn toggle_sub_lane(&mut self, lane: Lane, cx: &mut Context) { - let text = match self.subs_off.iter().position(|&l| l == lane) { - Some(i) => { - self.subs_off.remove(i); - format!("{} SHOWS ITS CAPTIONS", lane.label()) - } - None => { - self.subs_off.push(lane); - format!("{} IS HIDDEN — its captions stay on the lane", lane.label()) - } + /// A subtitle lane's dot: the one lane whose captions are over the picture. + /// A pick and not a toggle -- picking one puts the one that was showing + /// away, because two lanes of different words at one moment is two plates + /// nobody can read, and it is said out loud for that reason: what the click + /// did *and* what it undid. + /// + /// The lanes it takes off the picture keep their captions and are still + /// exported, every one of them ([`Player::start_export`]). + pub(crate) fn show_sub_lane(&mut self, lane: Lane, cx: &mut Context) { + let was = self.active_sub_lane(); + self.sub_lane = Some(lane); + let text = match was.filter(|&old| old != lane) { + Some(old) => format!( + "{} IS SHOWN — {} is off the picture; every subtitle track is still exported", + lane.label(), + old.label() + ), + None => format!("{} IS SHOWN — its captions are over the picture", lane.label()), }; self.notify_user(text.into()); cx.notify(); } - /// Whether that subtitle lane's captions are drawn -- the eye, read by the - /// header that offers it and by whatever draws cues from here on. + /// The subtitle lane whose captions are drawn: the pick resolved against the + /// lanes the timeline has right now ([`active_lane`]), so it can never name + /// a lane that is not there. `None` with no subtitle lane at all. + pub(crate) fn active_sub_lane(&self) -> Option { + let lanes = self.session.as_ref()?.subtitle_lanes(); + active_lane(self.sub_lane, &lanes) + } + + /// Whether that subtitle lane's captions are drawn -- read by the header + /// that offers the pick and by the plate over the picture. pub(crate) fn sub_lane_on(&self, lane: Lane) -> bool { - !self.subs_off.contains(&lane) + self.active_sub_lane() == Some(lane) } /// Where a caption let go at window `x` wants its head: [`Player::drop_frame`]'s diff --git a/crates/app/src/subs.rs b/crates/app/src/subs.rs index dfdc4d4..87e9a5c 100644 --- a/crates/app/src/subs.rs +++ b/crates/app/src/subs.rs @@ -589,6 +589,25 @@ pub(crate) fn cue_box(scale: Scale, cue: &engine::subtitle::Cue) -> (f32, f32) { ) } +/// Which subtitle lane draws over the picture, out of the pick somebody made +/// and the lanes there are *now* ([`Player::active_sub_lane`]): the picked one +/// while it is still on the timeline, and the first lane otherwise -- which is +/// the whole of "one lane needs no picking", "the first lane added draws" and +/// "a removed lane's pick promotes its neighbour rather than showing nothing". +/// +/// `None` only with no subtitle lane at all, which is a timeline with nowhere +/// for words to be. +/// +/// A pick against the live list rather than a pointer kept in step with it: a +/// [`Lane`] is a position among its kind, so an add, a removal, a reorder and +/// every undo of those move what a stored handle names -- and each of them is +/// answered here, at the read, by a list that is never stale. +pub(crate) fn active_lane(picked: Option, lanes: &[Lane]) -> Option { + picked + .filter(|lane| lanes.contains(lane)) + .or_else(|| lanes.first().copied()) +} + /// Which cues of a track are on screen at `at` seconds. Half-open, as the cue /// itself is: one that ends exactly where the next begins hands over rather than /// overlapping it for a frame, and several that genuinely overlap all come back diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index f336bd5..f180c98 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -1102,3 +1102,28 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { assert!(shown(1.8).is_empty(), "between two cues the plate goes"); assert_eq!(shown(2.5), ["second line\nwith a break"]); } + +/// One lane over the picture and never two ([`Player::active_sub_lane`]): which +/// one, at every moment a stack of subtitle lanes goes through -- none, one, +/// three, a pick, and the pick's lane going away under it. +#[test] +fn exactly_one_subtitle_lane_is_shown_whatever_the_pick_and_whatever_is_left() { + let sub = |ord| Lane::new(LaneKind::Subtitle, ord); + let (s1, s2, s3) = (sub(0), sub(1), sub(2)); + // Nowhere for words to be: no lane, nothing shown -- and a pick left over + // from a timeline that has been closed does not resurrect one. + assert_eq!(active_lane(None, &[]), None); + assert_eq!(active_lane(Some(s2), &[]), None); + // One lane is shown by being the only one: nobody has to pick anything, + // which is what the single-lane timeline always did. + assert_eq!(active_lane(None, &[s1]), Some(s1)); + // Three, unpicked: the first, so adding lanes never blanks the picture. + assert_eq!(active_lane(None, &[s1, s2, s3]), Some(s1)); + // ...and picked: that one alone, however many are there. + assert_eq!(active_lane(Some(s3), &[s1, s2, s3]), Some(s3)); + // The picked lane taken off the timeline -- a removal, or the undo of the + // add that made it: the first lane left is shown, never nothing. + assert_eq!(active_lane(Some(s3), &[s1, s2]), Some(s1)); + // A pick that is not a subtitle lane at all cannot name one either. + assert_eq!(active_lane(Some(Lane::V1), &[s1, s2]), Some(s1)); +} diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index b2426c2..685d755 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -28,7 +28,7 @@ use super::{ format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, frame_rate_ladder, histogram, inserted_band, is_bare_modifier, is_project, keymap, keys_filter, keys_rows, lanes_h, - marked, menu_at, menu_items, menu_rows_h, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, + active_lane, marked, menu_at, menu_items, menu_rows_h, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, LATE_RESYNC, RESYNC_GAP, should_resync, retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped, SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport, diff --git a/crates/app/src/ui/preview.rs b/crates/app/src/ui/preview.rs index 8d1def8..9f5171e 100644 --- a/crates/app/src/ui/preview.rs +++ b/crates/app/src/ui/preview.rs @@ -12,10 +12,12 @@ impl Player { /// the palette and nothing more, exactly as a picture or a song does, and it /// reaches the screen when a placement of it sits under the playhead /// ([`PlaybackSession::sub_lane_cues`], the same map the export writes the - /// file with -- so what is read here is what the file will say). Every lane - /// whose eye is open ([`Player::sub_lane_on`]) draws, so two enabled lanes - /// are two plates: lane order bottom-up, the first lane where a single - /// track's words have always been and each further one stacked above it. + /// file with -- so what is read here is what the file will say). **One** + /// lane draws, the one that is shown ([`Player::active_sub_lane`]): a + /// picture carrying every lane's words at once is unreadable at three lanes + /// and nonsense at two hundred, which is the same one-track-at-a-time every + /// player offers. What an export writes is untouched by this -- every lane + /// on the timeline becomes a subtitle track of the file. /// /// `None` -- no element at all -- while the toggle is off, with nothing /// placed, and between cues: the picture is what this window is for, and a @@ -40,42 +42,29 @@ impl Player { // going off, the file closing and the gap between two cues are the same // "nothing on screen", and an 8 MB atlas tile may not survive any of // them (an early return above this leaked one per toggle-off). - // Per lane and not one flat list: the plates stack by lane below, and a - // picture's cache key needs the lane it came off ([`Player::sub_picture`]). - let lanes: Vec<(Lane, Vec)> = - match self.session.as_ref().filter(|_| self.subs_on) { - Some(session) => session - .subtitle_lanes() - .into_iter() - .filter(|&lane| self.sub_lane_on(lane)) - .map(|lane| { - let cues = session.sub_lane_cues(lane); - (lane, cues_at(&cues, at).into_iter().cloned().collect()) - }) - .filter(|(_, cues): &(_, Vec<_>)| !cues.is_empty()) - .collect(), - None => Vec::new(), - }; - if lanes.is_empty() { + // One lane's cues and never a walk of the lanes: the map is asked of the + // shown lane alone, so two hundred subtitle lanes cost this frame what + // one does. + let shown: Option<(Lane, Vec)> = self + .active_sub_lane() + .filter(|_| self.subs_on) + .and_then(|lane| { + let cues = self.session.as_ref()?.sub_lane_cues(lane); + let now: Vec<_> = cues_at(&cues, at).into_iter().cloned().collect(); + (!now.is_empty()).then_some((lane, now)) + }); + let Some((lane, cues)) = shown else { self.drop_sub_image(window); return None; - } + }; // The first picture cue up, decoded once and kept: two bitmap cues at // one moment is a thing PGS composes into one display set, so there is - // never a second picture to stack under the first *on one lane*. - // - // corner-cut: two enabled lanes each showing a PGS track draw the lower - // lane's picture alone -- one cache slot, one canvas over the whole - // region, and a second canvas would cover the first anyway. The upgrade - // path is a slot per lane, which wants the plates' stacking rule to mean - // something for canvases too. - let picture = lanes + // never a second picture to stack under the first on one lane -- and one + // lane is all there is here. + let picture = cues .iter() - .find_map(|(lane, cues)| { - cues.iter() - .find_map(|cue| Some((*lane, cue.start_us, cue.image.as_ref()?))) - }) - .and_then(|(lane, start_us, image)| self.sub_picture(lane, start_us, image, window)); + .find_map(|cue| Some((cue.start_us, cue.image.as_ref()?))) + .and_then(|(start_us, image)| self.sub_picture(lane, start_us, image, window)); // A picture is fitted onto the whole region and a plate hangs off the // bottom of it, and a track is one or the other -- so they are two // shapes and not one with the parts switched off. @@ -120,12 +109,10 @@ impl Player { // The plate takes no click: the picture behind it is still the // drop target the whole window is. // - // Reversed, because a column anchored at the bottom lays its - // children downwards: the *last* lane is written first so the - // first lane keeps the bottom line it has when it is the only - // one, and a second lane stacks above it rather than pushing it - // off its place. - .children(lanes.into_iter().rev().flat_map(|(_, cues)| cues).filter(|c| c.image.is_none()).map(|cue| { + // In the lane's own order: two cues at one moment -- a sign and + // a line of dialogue -- stack, the first on the bottom line + // where a single cue sits. + .children(cues.into_iter().filter(|c| c.image.is_none()).map(|cue| { div() .max_w(relative(0.9)) .px(px(6.)) diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 2fad105..ead0862 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -651,8 +651,11 @@ impl Player { _ => Vec::new(), }; let eye_tip: SharedString = match shown { - true => format!("{name} shows its captions — click to hide this track"), - false => format!("{name} is hidden — click to show its captions again"), + true => format!("{name} is the track shown over the picture"), + false => format!( + "Click to show {name} over the picture instead — one subtitle track is drawn at a \ + time, and an export carries every one of them" + ), } .into(); // What a caption's box says clicking it does; the media boxes' tooltip @@ -759,12 +762,15 @@ impl Player { }) .into_any_element(), // A subtitle track's own one setting, in the same - // place and for the same reason: whether this lane's - // words are drawn over the picture. The eye every - // player puts on a track, `HIT_MIN` tall like the mix - // button it sits where. + // place and for the same reason: whether *this* lane is + // the one drawn over the picture. A radio and not an + // eye -- one track shows at a time, so a click here + // takes the picture off whichever lane had it -- and + // `HIT_MIN` tall like the mix button it sits where. + // The lit dot and the accent tell the shown lane from + // the rest of a stack of them at a glance. false if sub => div() - .id(("eye-lane", lane.ord)) + .id(("show-lane", lane.ord)) .flex_1() .w_full() .flex() @@ -775,9 +781,15 @@ impl Player { .cursor_pointer() .hover(|s| s.bg(rgb(BG_HOVER()))) .when(!shown, |d| d.text_color(rgb(FG_DISABLED()))) + .when(shown, |d| { + d.text_color(rgb(ACCENT_PRIMARY())) + .bg(rgb(BG_HOVER())) + .border_1() + .border_color(rgb(ACCENT_PRIMARY())) + }) .tooltip(move |_, cx| cx.new(|_| Tip(eye_tip.clone())).into()) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.toggle_sub_lane(lane, cx) + this.show_sub_lane(lane, cx) })) .child(name.clone()) .child(