From afea3b27659c5556a131d9432879cb672f06e410 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 06:38:09 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20the=20picture=20shows?= =?UTF-8?q?=20what=20is=20placed,=20and=20every=20open=20eye?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The overlay stops reading the picked palette row and reads the subtitle lanes: the union of every enabled lane's cues at the playhead (`PlaybackSession::sub_lane_cues` minus `Player::subs_off`), one plate per cue, lane order bottom-up so S1 keeps the line it has when it is the only one. Nothing shows until it is placed -- the model every other medium here already follows, and the end of the auto-show a walked file used to get. The palette row's click loses its show semantics and keeps the selection the × acts on; the heading names no track any more, and the tooltip and the import tail say where a track landed and what the next move is. `Player::sub_image` is keyed by (lane, start_us): two lanes are two placements at one microsecond, and a shut eye must not leave the picture before it on screen. A picture cue draws from the lowest enabled lane alone (one cache slot, one canvas over the whole region) and the plate stack still steps over the transient bars. --- crates/app/src/main.rs | 37 +++++++++-------- crates/app/src/subs.rs | 10 ++++- crates/app/src/tests/media.rs | 50 +++++++++++++++++++++-- crates/app/src/ui/preview.rs | 75 +++++++++++++++++++++++++---------- crates/app/src/ui/timeline.rs | 34 ++++++++-------- 5 files changed, 146 insertions(+), 60 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index ffba6b6..0bfc639 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -86,11 +86,11 @@ struct Player { /// drawn ([`engine::subtitle::CueImage::rgba`]), which is a thing to do /// when the cue changes -- every few seconds -- and not at every repaint. /// - /// The *track* is half the key because the four PGS tracks of a remux are - /// one film's subtitles in four languages: they start at the same - /// microsecond, and a picked row that only changed the language would go on - /// showing the one before it. - sub_image: Option<((usize, i64), Arc)>, + /// The *lane* is half the key because the four PGS tracks of a remux are + /// one film's subtitles in four languages: placed one over the other they + /// start at the same microsecond, and a lane whose eye was shut would leave + /// the one before it on screen. + sub_image: Option<((Lane, i64), Arc)>, /// A frame that arrived before its time; shown on the tick it comes due. /// The pump's buffer, not transport state -- but a frame waiting here is /// what keeps a finished decoder from reading as [`Transport::Ended`] one @@ -228,28 +228,31 @@ struct Player { /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement /// no magnet may take away. snap: bool, - /// Whether the cue under the playhead is drawn over the picture. On by - /// default -- a subtitle imported and then invisible is an import nobody can - /// tell happened -- and off by one stroke + /// 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 + /// one stroke /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for /// anyone watching the picture rather than reading it. The player's, not the /// project's: it changes nothing that is saved and nothing that is exported. subs_on: bool, - /// Which subtitle track is the one on screen: an index into - /// [`PlaybackSession::subtitles`], since a file may carry several and only - /// one can be read at a time. Cleared with the timeline like every other - /// index here -- track 2 of one project is not track 2 of the next. + /// Which palette row is *selected*: an index into + /// [`PlaybackSession::subtitles`], which is what the × takes off + /// ([`ActionId::RemoveSubtitleTrack`](keymap::ActionId::RemoveSubtitleTrack)) + /// and what the list marks. A selection and nothing more -- what is on + /// screen is what is placed on a subtitle lane + /// ([`Player::subtitle_overlay`]), so picking a row shows nothing by itself, + /// exactly as clicking a media row plays nothing. Cleared with the timeline + /// 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. /// - /// State only this slice: the preview reads the picked palette track still - /// ([`Player::sub_picture`]), so shutting an eye marks the header and - /// changes nothing over the picture until the slice that draws the lanes' - /// cues there reads this field. Not saved either -- a `.edith` has no line - /// for it yet. + /// 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. /// /// 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 diff --git a/crates/app/src/subs.rs b/crates/app/src/subs.rs index 5e0395d..e0adbfb 100644 --- a/crates/app/src/subs.rs +++ b/crates/app/src/subs.rs @@ -235,6 +235,11 @@ pub(crate) type Subs = engine::Result>; /// argv named, an import, and an import into an empty window cannot say the same /// thing differently, whichever thread read the cues. /// +/// Worded for where they actually land: a *list* beside the media and nothing +/// over the picture -- a track shows when it is dragged onto a subtitle lane +/// ([`Player::subtitle_overlay`]), so the tail says the next move rather than +/// letting a count read as "and there they are on screen". +/// /// `None` for a file that gave none and for one whose tracks are on the timeline /// already -- an import that adds nothing says nothing about subtitles. A /// refusal is a tail too, never a failure of the import: the picture and the @@ -243,7 +248,10 @@ pub(crate) fn subtitle_tail(session: &mut PlaybackSession, subs: Subs) -> Option match subs { Ok(tracks) => match session.add_subtitle_tracks(tracks) { 0 => None, - n => Some(format!(" — {n} subtitle track(s) in the file")), + n => Some(format!( + " — {n} subtitle track(s) in the file, in the subtitle list: drag one onto a \ + subtitle track to show it" + )), }, Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")), } diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index 193cc4a..f336bd5 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -954,7 +954,14 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { let track = &session.subtitles()[0]; assert_eq!(track.label, "test_subs.srt"); assert_eq!(subtitle_detail(track), "3 cues"); - // What the overlay draws at a moment inside the first cue, and between + // Arriving is landing in the *list* and nowhere else: no lane is made for + // it, so there is nothing over the picture yet -- the rule every other + // medium follows here, and what `Player::subtitle_overlay` reads. + assert!( + session.subtitle_lanes().is_empty(), + "an import places nothing: the palette is where a track lands" + ); + // What the track itself says at a moment inside the first cue, and between // two of them -- the fixture's own timings (0.5-1.5 s, 2.0-3.25 s). let text = |t: f64| -> Vec { cues_at(&track.cues, t) @@ -1019,7 +1026,7 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { assert!(subtitle_detail(&refused).contains("pictures")); assert!(cues_at(&refused.cues, 1.).is_empty()); - // ...and what the plate and the strip draw after a *cut*: the timeline's + // ...and what an embedded track carried through a *cut* maps to: the timeline's // own clock, asked of the engine through the very map an export writes // the file with (`PlaybackSession::timeline_cues`), so the preview and // the file cannot drift apart. The numbers are the export's own @@ -1042,7 +1049,7 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { .collect::>(), vec![(500_000, 1_500_000), (2_000_000, 3_000_000)] ); - // The overlay's own two lines, at the same moments as above. + // The export's own two lines, at the same moments as above. let drawn = |t: f64| -> Vec { cues_at(&mapped, t) .into_iter() @@ -1057,4 +1064,41 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { ); // ...and the strip's: the second cue is one second wide now, not 1.25. assert_eq!(cue_box(scale, &mapped[1]), (80., 40.)); + + // The last mile, what the plate over the picture actually reads + // (`Player::subtitle_overlay` -> `PlaybackSession::sub_lane_cues`): a lane + // added and still empty draws nothing, and the palette row reaches the + // screen the moment it is *placed* on it -- shifted by where it sits, the + // way a clip is. + let lane = session.add_lane(LaneKind::Subtitle); + assert!( + session.sub_lane_cues(lane).is_empty(), + "an empty subtitle lane draws nothing" + ); + session + .place_sub( + lane, + 0, + SubClip { + start: 0, + frames: 90, + track: 0, + in_us: 0, + out_us: 5_000_000, + }, + ) + .expect("the palette row goes down on the lane"); + let placed = session.sub_lane_cues(lane); + let shown = |t: f64| -> Vec { + cues_at(&placed, t) + .into_iter() + .map(|c| c.text.clone()) + .collect() + }; + // The placement keeps the track's own clock (it starts at frame 0 and + // holds the whole of it), so the words are back at the times the file + // wrote them -- the cut above moved the *carried* map, not this one. + assert_eq!(shown(0.7), ["first line"]); + assert!(shown(1.8).is_empty(), "between two cues the plate goes"); + assert_eq!(shown(2.5), ["second line\nwith a break"]); } diff --git a/crates/app/src/ui/preview.rs b/crates/app/src/ui/preview.rs index 001c870..aed346a 100644 --- a/crates/app/src/ui/preview.rs +++ b/crates/app/src/ui/preview.rs @@ -4,19 +4,23 @@ use crate::*; use crate::ui::widgets::*; impl Player { - /// The cues of the picked track that are on screen at `at`, over the picture - /// and nothing else: bottom-centred where every player puts them, white on a + /// The cues the *subtitle lanes* put on screen at `at`, over the picture and + /// nothing else: bottom-centred where every player puts them, white on a /// plate so the film underneath cannot swallow them, and each cue its own /// plate so two at one moment stack rather than run together. /// - /// `None` -- no element at all -- while the toggle is off, with no track - /// picked, and between cues: the picture is what this window is for, and a - /// permanent empty band across it would be in the way of exactly that. + /// What is drawn is what was *placed*: a track walked out of a file lands in + /// 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. /// - /// The cues are the *timeline's* ([`PlaybackSession::timeline_cues`]) and - /// not the track's own: on a cut timeline an embedded track's cues ride the - /// pictures they belong to, and this is the same map the export writes the - /// file with -- so what is read here is what the file says. + /// `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 + /// permanent empty band across it would be in the way of exactly that. /// /// A cue off a PGS track is a *picture* and not a line /// ([`engine::subtitle::CueImage`]), and is drawn as one: the disc's whole @@ -37,22 +41,42 @@ 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). - let mapped = match self.session.as_ref().filter(|_| self.subs_on) { - Some(session) => session.timeline_cues(self.sub_track), - None => Vec::new(), - }; - let cues = cues_at(&mapped, at); - if cues.is_empty() { + // 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() { 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. - let picture = cues + // 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 .iter() - .find_map(|cue| Some((cue.start_us, cue.image.as_ref()?))) - .and_then(|(start_us, image)| self.sub_picture(start_us, image, window)); + .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)); // 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. @@ -96,7 +120,13 @@ impl Player { .gap(px(2.)) // The plate takes no click: the picture behind it is still the // drop target the whole window is. - .children(cues.into_iter().filter(|c| c.image.is_none()).map(|cue| { + // + // 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| { div() .max_w(relative(0.9)) .px(px(6.)) @@ -118,7 +148,7 @@ impl Player { ) } - /// The cue starting at `start_us` as a drawable picture, decoded on the + /// The cue `lane` starts at `start_us` as a drawable picture, decoded on the /// first repaint it is up for and kept until another cue takes its place /// ([`Player::sub_image`]). `None` for a display set the decoder refuses, /// which draws nothing rather than failing the frame. @@ -128,11 +158,12 @@ impl Player { /// sprite atlas by the whole film. pub(crate) fn sub_picture( &mut self, + lane: Lane, start_us: i64, image: &engine::subtitle::CueImage, window: &mut Window, ) -> Option> { - let key = (self.sub_track, start_us); + let key = (lane, start_us); if let Some((up, ready)) = &self.sub_image && *up == key { diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 888a448..0eb0245 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -363,8 +363,8 @@ impl Player { let tip: SharedString = match &row.refused { Some(why) => format!("{} — {why}", path.display()), None => format!( - "{} — drag it onto a subtitle track to place it, click to show it \ - over the picture", + "{} — drag it onto a subtitle track to place it; nothing is over \ + the picture until it is placed", path.display() ), } @@ -406,13 +406,14 @@ impl Player { .on_drag(SubPick(track), move |_, _, _, cx| { cx.new(|_| Tip(carried.clone())) }) + // Selects the row and shows nothing: a + // subtitle track reaches the picture by + // being placed on a subtitle lane, the way + // a film reaches it by being placed on a + // video one. What the selection is for is + // the × and the mark on the row. .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.sub_track = track; - // Picking a track is asking to see it: a - // click that changed nothing on screen - // because the toggle was off would read - // as a dead row. - this.subs_on = true; cx.notify(); })) }) @@ -550,16 +551,15 @@ impl Player { .truncate() .text_size(px(11.)) .text_color(rgb(FG_SECONDARY())) - .child(match (self.subs_on, sub_pick_name(tracks, self.sub_track)) { - // Which of them is on screen, named by its film: - // the heading over a list of five is where the one - // being shown is worth saying out loud. - (true, Some(pick)) => format!("Subtitles — {pick}"), - (true, None) => "Subtitles".to_string(), - // The toggle's state where the tracks are listed: a - // list of subtitles nothing on screen is showing has - // to say that it is showing none. - (false, _) => "Subtitles — hidden".to_string(), + .child(match self.subs_on { + // A palette and not a picker: none of these rows is + // "the one on screen" any more, so the heading names + // no track. What is on screen is on the subtitle + // lanes, each with its own eye. + true => "Subtitles", + // The mute's state where the tracks are listed: with + // it off no lane draws, however many are placed. + false => "Subtitles — hidden", }), ) .child(