forge
Explore
Log in

Don't you dare go Hollow

The picture shows what is placed, and every open eye

Browse files at this commit

afea3b27659c5556a131d9432879cb672f06e410Ahmet Kaan GümüşParent: 57fb0f3
  • feat
    • the picture shows what is placed, and every open eye
Show full message
✨ feat(app): the picture shows what is placed, and every open eye

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.rsmodified+20 -17
@@ -86,11 +86,11 @@ struct Player {
8686 /// drawn ([`engine::subtitle::CueImage::rgba`]), which is a thing to do
8787 /// when the cue changes -- every few seconds -- and not at every repaint.
8888 ///
89- /// The *track* is half the key because the four PGS tracks of a remux are
90- /// one film's subtitles in four languages: they start at the same
91- /// microsecond, and a picked row that only changed the language would go on
92- /// showing the one before it.
93- sub_image: Option<((usize, i64), Arc<RenderImage>)>,
89+ /// The *lane* is half the key because the four PGS tracks of a remux are
90+ /// one film's subtitles in four languages: placed one over the other they
91+ /// start at the same microsecond, and a lane whose eye was shut would leave
92+ /// the one before it on screen.
93+ sub_image: Option<((Lane, i64), Arc<RenderImage>)>,
9494 /// A frame that arrived before its time; shown on the tick it comes due.
9595 /// The pump's buffer, not transport state -- but a frame waiting here is
9696 /// what keeps a finished decoder from reading as [`Transport::Ended`] one
@@ -228,28 +228,31 @@ struct Player {
228228 /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement
229229 /// no magnet may take away.
230230 snap: bool,
231- /// Whether the cue under the playhead is drawn over the picture. On by
232- /// default -- a subtitle imported and then invisible is an import nobody can
233- /// tell happened -- and off by one stroke
231+ /// Whether the subtitle lanes draw at all -- the mute over every lane's eye
232+ /// ([`Player::subs_off`]), not a lane of its own. On by default and off by
233+ /// one stroke
234234 /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for
235235 /// anyone watching the picture rather than reading it. The player's, not the
236236 /// project's: it changes nothing that is saved and nothing that is exported.
237237 subs_on: bool,
238- /// Which subtitle track is the one on screen: an index into
239- /// [`PlaybackSession::subtitles`], since a file may carry several and only
240- /// one can be read at a time. Cleared with the timeline like every other
241- /// index here -- track 2 of one project is not track 2 of the next.
238+ /// Which palette row is *selected*: an index into
239+ /// [`PlaybackSession::subtitles`], which is what the × takes off
240+ /// ([`ActionId::RemoveSubtitleTrack`](keymap::ActionId::RemoveSubtitleTrack))
241+ /// and what the list marks. A selection and nothing more -- what is on
242+ /// screen is what is placed on a subtitle lane
243+ /// ([`Player::subtitle_overlay`]), so picking a row shows nothing by itself,
244+ /// exactly as clicking a media row plays nothing. Cleared with the timeline
245+ /// like every other index here -- track 2 of one project is not track 2 of
246+ /// the next.
242247 sub_track: usize,
243248 /// The subtitle lanes whose eye is shut: every lane shows its captions
244249 /// until this says otherwise, so a lane that was just added is a lane that
245250 /// draws. Held as the lanes that are *off* rather than a flag per lane, so
246251 /// adding one needs no bookkeeping at all.
247252 ///
248- /// State only this slice: the preview reads the picked palette track still
249- /// ([`Player::sub_picture`]), so shutting an eye marks the header and
250- /// changes nothing over the picture until the slice that draws the lanes'
251- /// cues there reads this field. Not saved either -- a `.edith` has no line
252- /// for it yet.
253+ /// Read where the cues are drawn ([`Player::subtitle_overlay`]): shutting an
254+ /// eye takes that lane's plate off the picture and leaves its captions on
255+ /// the lane. Not saved -- a `.edith` has no line for it yet.
253256 ///
254257 /// A [`Lane`] handle is a position among its kind, so a removal or a
255258 /// reorder leaves every shut eye naming another track: they are dropped
crates/app/src/subs.rsmodified+9 -1
@@ -235,6 +235,11 @@ pub(crate) type Subs = engine::Result<Vec<engine::subtitle::SubtitleTrack>>;
235235 /// argv named, an import, and an import into an empty window cannot say the same
236236 /// thing differently, whichever thread read the cues.
237237 ///
238+/// Worded for where they actually land: a *list* beside the media and nothing
239+/// over the picture -- a track shows when it is dragged onto a subtitle lane
240+/// ([`Player::subtitle_overlay`]), so the tail says the next move rather than
241+/// letting a count read as "and there they are on screen".
242+///
238243 /// `None` for a file that gave none and for one whose tracks are on the timeline
239244 /// already -- an import that adds nothing says nothing about subtitles. A
240245 /// 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
243248 match subs {
244249 Ok(tracks) => match session.add_subtitle_tracks(tracks) {
245250 0 => None,
246- n => Some(format!(" — {n} subtitle track(s) in the file")),
251+ n => Some(format!(
252+ " — {n} subtitle track(s) in the file, in the subtitle list: drag one onto a \
253+ subtitle track to show it"
254+ )),
247255 },
248256 Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")),
249257 }
crates/app/src/tests/media.rsmodified+47 -3
@@ -954,7 +954,14 @@ fn subtitles_arrive_beside_the_media_and_inside_it() {
954954 let track = &session.subtitles()[0];
955955 assert_eq!(track.label, "test_subs.srt");
956956 assert_eq!(subtitle_detail(track), "3 cues");
957- // What the overlay draws at a moment inside the first cue, and between
957+ // Arriving is landing in the *list* and nowhere else: no lane is made for
958+ // it, so there is nothing over the picture yet -- the rule every other
959+ // medium follows here, and what `Player::subtitle_overlay` reads.
960+ assert!(
961+ session.subtitle_lanes().is_empty(),
962+ "an import places nothing: the palette is where a track lands"
963+ );
964+ // What the track itself says at a moment inside the first cue, and between
958965 // two of them -- the fixture's own timings (0.5-1.5 s, 2.0-3.25 s).
959966 let text = |t: f64| -> Vec<String> {
960967 cues_at(&track.cues, t)
@@ -1019,7 +1026,7 @@ fn subtitles_arrive_beside_the_media_and_inside_it() {
10191026 assert!(subtitle_detail(&refused).contains("pictures"));
10201027 assert!(cues_at(&refused.cues, 1.).is_empty());
10211028
1022- // ...and what the plate and the strip draw after a *cut*: the timeline's
1029+ // ...and what an embedded track carried through a *cut* maps to: the timeline's
10231030 // own clock, asked of the engine through the very map an export writes
10241031 // the file with (`PlaybackSession::timeline_cues`), so the preview and
10251032 // 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() {
10421049 .collect::<Vec<_>>(),
10431050 vec![(500_000, 1_500_000), (2_000_000, 3_000_000)]
10441051 );
1045- // The overlay's own two lines, at the same moments as above.
1052+ // The export's own two lines, at the same moments as above.
10461053 let drawn = |t: f64| -> Vec<String> {
10471054 cues_at(&mapped, t)
10481055 .into_iter()
@@ -1057,4 +1064,41 @@ fn subtitles_arrive_beside_the_media_and_inside_it() {
10571064 );
10581065 // ...and the strip's: the second cue is one second wide now, not 1.25.
10591066 assert_eq!(cue_box(scale, &mapped[1]), (80., 40.));
1067+
1068+ // The last mile, what the plate over the picture actually reads
1069+ // (`Player::subtitle_overlay` -> `PlaybackSession::sub_lane_cues`): a lane
1070+ // added and still empty draws nothing, and the palette row reaches the
1071+ // screen the moment it is *placed* on it -- shifted by where it sits, the
1072+ // way a clip is.
1073+ let lane = session.add_lane(LaneKind::Subtitle);
1074+ assert!(
1075+ session.sub_lane_cues(lane).is_empty(),
1076+ "an empty subtitle lane draws nothing"
1077+ );
1078+ session
1079+ .place_sub(
1080+ lane,
1081+ 0,
1082+ SubClip {
1083+ start: 0,
1084+ frames: 90,
1085+ track: 0,
1086+ in_us: 0,
1087+ out_us: 5_000_000,
1088+ },
1089+ )
1090+ .expect("the palette row goes down on the lane");
1091+ let placed = session.sub_lane_cues(lane);
1092+ let shown = |t: f64| -> Vec<String> {
1093+ cues_at(&placed, t)
1094+ .into_iter()
1095+ .map(|c| c.text.clone())
1096+ .collect()
1097+ };
1098+ // The placement keeps the track's own clock (it starts at frame 0 and
1099+ // holds the whole of it), so the words are back at the times the file
1100+ // wrote them -- the cut above moved the *carried* map, not this one.
1101+ assert_eq!(shown(0.7), ["first line"]);
1102+ assert!(shown(1.8).is_empty(), "between two cues the plate goes");
1103+ assert_eq!(shown(2.5), ["second line\nwith a break"]);
10601104 }
crates/app/src/ui/preview.rsmodified+53 -22
@@ -4,19 +4,23 @@ use crate::*;
44 use crate::ui::widgets::*;
55
66 impl Player {
7- /// The cues of the picked track that are on screen at `at`, over the picture
8- /// and nothing else: bottom-centred where every player puts them, white on a
7+ /// The cues the *subtitle lanes* put on screen at `at`, over the picture and
8+ /// nothing else: bottom-centred where every player puts them, white on a
99 /// plate so the film underneath cannot swallow them, and each cue its own
1010 /// plate so two at one moment stack rather than run together.
1111 ///
12- /// `None` -- no element at all -- while the toggle is off, with no track
13- /// picked, and between cues: the picture is what this window is for, and a
14- /// permanent empty band across it would be in the way of exactly that.
12+ /// What is drawn is what was *placed*: a track walked out of a file lands in
13+ /// the palette and nothing more, exactly as a picture or a song does, and it
14+ /// reaches the screen when a placement of it sits under the playhead
15+ /// ([`PlaybackSession::sub_lane_cues`], the same map the export writes the
16+ /// file with -- so what is read here is what the file will say). Every lane
17+ /// whose eye is open ([`Player::sub_lane_on`]) draws, so two enabled lanes
18+ /// are two plates: lane order bottom-up, the first lane where a single
19+ /// track's words have always been and each further one stacked above it.
1520 ///
16- /// The cues are the *timeline's* ([`PlaybackSession::timeline_cues`]) and
17- /// not the track's own: on a cut timeline an embedded track's cues ride the
18- /// pictures they belong to, and this is the same map the export writes the
19- /// file with -- so what is read here is what the file says.
21+ /// `None` -- no element at all -- while the toggle is off, with nothing
22+ /// placed, and between cues: the picture is what this window is for, and a
23+ /// permanent empty band across it would be in the way of exactly that.
2024 ///
2125 /// A cue off a PGS track is a *picture* and not a line
2226 /// ([`engine::subtitle::CueImage`]), and is drawn as one: the disc's whole
@@ -37,22 +41,42 @@ impl Player {
3741 // going off, the file closing and the gap between two cues are the same
3842 // "nothing on screen", and an 8 MB atlas tile may not survive any of
3943 // them (an early return above this leaked one per toggle-off).
40- let mapped = match self.session.as_ref().filter(|_| self.subs_on) {
41- Some(session) => session.timeline_cues(self.sub_track),
42- None => Vec::new(),
43- };
44- let cues = cues_at(&mapped, at);
45- if cues.is_empty() {
44+ // Per lane and not one flat list: the plates stack by lane below, and a
45+ // picture's cache key needs the lane it came off ([`Player::sub_picture`]).
46+ let lanes: Vec<(Lane, Vec<engine::subtitle::Cue>)> =
47+ match self.session.as_ref().filter(|_| self.subs_on) {
48+ Some(session) => session
49+ .subtitle_lanes()
50+ .into_iter()
51+ .filter(|&lane| self.sub_lane_on(lane))
52+ .map(|lane| {
53+ let cues = session.sub_lane_cues(lane);
54+ (lane, cues_at(&cues, at).into_iter().cloned().collect())
55+ })
56+ .filter(|(_, cues): &(_, Vec<_>)| !cues.is_empty())
57+ .collect(),
58+ None => Vec::new(),
59+ };
60+ if lanes.is_empty() {
4661 self.drop_sub_image(window);
4762 return None;
4863 }
4964 // The first picture cue up, decoded once and kept: two bitmap cues at
5065 // one moment is a thing PGS composes into one display set, so there is
51- // never a second picture to stack under the first.
52- let picture = cues
66+ // never a second picture to stack under the first *on one lane*.
67+ //
68+ // corner-cut: two enabled lanes each showing a PGS track draw the lower
69+ // lane's picture alone -- one cache slot, one canvas over the whole
70+ // region, and a second canvas would cover the first anyway. The upgrade
71+ // path is a slot per lane, which wants the plates' stacking rule to mean
72+ // something for canvases too.
73+ let picture = lanes
5374 .iter()
54- .find_map(|cue| Some((cue.start_us, cue.image.as_ref()?)))
55- .and_then(|(start_us, image)| self.sub_picture(start_us, image, window));
75+ .find_map(|(lane, cues)| {
76+ cues.iter()
77+ .find_map(|cue| Some((*lane, cue.start_us, cue.image.as_ref()?)))
78+ })
79+ .and_then(|(lane, start_us, image)| self.sub_picture(lane, start_us, image, window));
5680 // A picture is fitted onto the whole region and a plate hangs off the
5781 // bottom of it, and a track is one or the other -- so they are two
5882 // shapes and not one with the parts switched off.
@@ -96,7 +120,13 @@ impl Player {
96120 .gap(px(2.))
97121 // The plate takes no click: the picture behind it is still the
98122 // drop target the whole window is.
99- .children(cues.into_iter().filter(|c| c.image.is_none()).map(|cue| {
123+ //
124+ // Reversed, because a column anchored at the bottom lays its
125+ // children downwards: the *last* lane is written first so the
126+ // first lane keeps the bottom line it has when it is the only
127+ // one, and a second lane stacks above it rather than pushing it
128+ // off its place.
129+ .children(lanes.into_iter().rev().flat_map(|(_, cues)| cues).filter(|c| c.image.is_none()).map(|cue| {
100130 div()
101131 .max_w(relative(0.9))
102132 .px(px(6.))
@@ -118,7 +148,7 @@ impl Player {
118148 )
119149 }
120150
121- /// The cue starting at `start_us` as a drawable picture, decoded on the
151+ /// The cue `lane` starts at `start_us` as a drawable picture, decoded on the
122152 /// first repaint it is up for and kept until another cue takes its place
123153 /// ([`Player::sub_image`]). `None` for a display set the decoder refuses,
124154 /// which draws nothing rather than failing the frame.
@@ -128,11 +158,12 @@ impl Player {
128158 /// sprite atlas by the whole film.
129159 pub(crate) fn sub_picture(
130160 &mut self,
161+ lane: Lane,
131162 start_us: i64,
132163 image: &engine::subtitle::CueImage,
133164 window: &mut Window,
134165 ) -> Option<Arc<RenderImage>> {
135- let key = (self.sub_track, start_us);
166+ let key = (lane, start_us);
136167 if let Some((up, ready)) = &self.sub_image
137168 && *up == key
138169 {
crates/app/src/ui/timeline.rsmodified+17 -17
@@ -363,8 +363,8 @@ impl Player {
363363 let tip: SharedString = match &row.refused {
364364 Some(why) => format!("{} — {why}", path.display()),
365365 None => format!(
366- "{} — drag it onto a subtitle track to place it, click to show it \
367- over the picture",
366+ "{} — drag it onto a subtitle track to place it; nothing is over \
367+ the picture until it is placed",
368368 path.display()
369369 ),
370370 }
@@ -406,13 +406,14 @@ impl Player {
406406 .on_drag(SubPick(track), move |_, _, _, cx| {
407407 cx.new(|_| Tip(carried.clone()))
408408 })
409+ // Selects the row and shows nothing: a
410+ // subtitle track reaches the picture by
411+ // being placed on a subtitle lane, the way
412+ // a film reaches it by being placed on a
413+ // video one. What the selection is for is
414+ // the × and the mark on the row.
409415 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
410416 this.sub_track = track;
411- // Picking a track is asking to see it: a
412- // click that changed nothing on screen
413- // because the toggle was off would read
414- // as a dead row.
415- this.subs_on = true;
416417 cx.notify();
417418 }))
418419 })
@@ -550,16 +551,15 @@ impl Player {
550551 .truncate()
551552 .text_size(px(11.))
552553 .text_color(rgb(FG_SECONDARY()))
553- .child(match (self.subs_on, sub_pick_name(tracks, self.sub_track)) {
554- // Which of them is on screen, named by its film:
555- // the heading over a list of five is where the one
556- // being shown is worth saying out loud.
557- (true, Some(pick)) => format!("Subtitles — {pick}"),
558- (true, None) => "Subtitles".to_string(),
559- // The toggle's state where the tracks are listed: a
560- // list of subtitles nothing on screen is showing has
561- // to say that it is showing none.
562- (false, _) => "Subtitles — hidden".to_string(),
554+ .child(match self.subs_on {
555+ // A palette and not a picker: none of these rows is
556+ // "the one on screen" any more, so the heading names
557+ // no track. What is on screen is on the subtitle
558+ // lanes, each with its own eye.
559+ true => "Subtitles",
560+ // The mute's state where the tracks are listed: with
561+ // it off no lane draws, however many are placed.
562+ false => "Subtitles — hidden",
563563 }),
564564 )
565565 .child(