The picture shows what is placed, and every open eye
Browse files at this commitafea3b27659c5556a131d9432879cb672f06e410Parent: 57fb0f3- feat
- the picture shows what is placed, and every open eye
5 changed files +146 -60
- crates/app/src/main.rs +20 -17
- crates/app/src/subs.rs +9 -1
- crates/app/src/tests/media.rs +47 -3
- crates/app/src/ui/preview.rs +53 -22
- crates/app/src/ui/timeline.rs +17 -17
crates/app/src/main.rsmodified+20 -17
| @@ -86,11 +86,11 @@ struct Player { | ||
| 86 | 86 | /// drawn ([`engine::subtitle::CueImage::rgba`]), which is a thing to do |
| 87 | 87 | /// when the cue changes -- every few seconds -- and not at every repaint. |
| 88 | 88 | /// |
| 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>)>, | |
| 94 | 94 | /// A frame that arrived before its time; shown on the tick it comes due. |
| 95 | 95 | /// The pump's buffer, not transport state -- but a frame waiting here is |
| 96 | 96 | /// what keeps a finished decoder from reading as [`Transport::Ended`] one |
| @@ -228,28 +228,31 @@ struct Player { | ||
| 228 | 228 | /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement |
| 229 | 229 | /// no magnet may take away. |
| 230 | 230 | 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 | |
| 234 | 234 | /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for |
| 235 | 235 | /// anyone watching the picture rather than reading it. The player's, not the |
| 236 | 236 | /// project's: it changes nothing that is saved and nothing that is exported. |
| 237 | 237 | 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. | |
| 242 | 247 | sub_track: usize, |
| 243 | 248 | /// The subtitle lanes whose eye is shut: every lane shows its captions |
| 244 | 249 | /// until this says otherwise, so a lane that was just added is a lane that |
| 245 | 250 | /// draws. Held as the lanes that are *off* rather than a flag per lane, so |
| 246 | 251 | /// adding one needs no bookkeeping at all. |
| 247 | 252 | /// |
| 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. | |
| 253 | 256 | /// |
| 254 | 257 | /// A [`Lane`] handle is a position among its kind, so a removal or a |
| 255 | 258 | /// 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>>; | ||
| 235 | 235 | /// argv named, an import, and an import into an empty window cannot say the same |
| 236 | 236 | /// thing differently, whichever thread read the cues. |
| 237 | 237 | /// |
| 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 | +/// | |
| 238 | 243 | /// `None` for a file that gave none and for one whose tracks are on the timeline |
| 239 | 244 | /// already -- an import that adds nothing says nothing about subtitles. A |
| 240 | 245 | /// 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 | ||
| 243 | 248 | match subs { |
| 244 | 249 | Ok(tracks) => match session.add_subtitle_tracks(tracks) { |
| 245 | 250 | 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 | + )), | |
| 247 | 255 | }, |
| 248 | 256 | Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")), |
| 249 | 257 | } |
crates/app/src/tests/media.rsmodified+47 -3
| @@ -954,7 +954,14 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { | ||
| 954 | 954 | let track = &session.subtitles()[0]; |
| 955 | 955 | assert_eq!(track.label, "test_subs.srt"); |
| 956 | 956 | 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 | |
| 958 | 965 | // two of them -- the fixture's own timings (0.5-1.5 s, 2.0-3.25 s). |
| 959 | 966 | let text = |t: f64| -> Vec<String> { |
| 960 | 967 | cues_at(&track.cues, t) |
| @@ -1019,7 +1026,7 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { | ||
| 1019 | 1026 | assert!(subtitle_detail(&refused).contains("pictures")); |
| 1020 | 1027 | assert!(cues_at(&refused.cues, 1.).is_empty()); |
| 1021 | 1028 | |
| 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 | |
| 1023 | 1030 | // own clock, asked of the engine through the very map an export writes |
| 1024 | 1031 | // the file with (`PlaybackSession::timeline_cues`), so the preview and |
| 1025 | 1032 | // 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() { | ||
| 1042 | 1049 | .collect::<Vec<_>>(), |
| 1043 | 1050 | vec![(500_000, 1_500_000), (2_000_000, 3_000_000)] |
| 1044 | 1051 | ); |
| 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. | |
| 1046 | 1053 | let drawn = |t: f64| -> Vec<String> { |
| 1047 | 1054 | cues_at(&mapped, t) |
| 1048 | 1055 | .into_iter() |
| @@ -1057,4 +1064,41 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { | ||
| 1057 | 1064 | ); |
| 1058 | 1065 | // ...and the strip's: the second cue is one second wide now, not 1.25. |
| 1059 | 1066 | 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"]); | |
| 1060 | 1104 | } |
crates/app/src/ui/preview.rsmodified+53 -22
| @@ -4,19 +4,23 @@ use crate::*; | ||
| 4 | 4 | use crate::ui::widgets::*; |
| 5 | 5 | |
| 6 | 6 | 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 | |
| 9 | 9 | /// plate so the film underneath cannot swallow them, and each cue its own |
| 10 | 10 | /// plate so two at one moment stack rather than run together. |
| 11 | 11 | /// |
| 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. | |
| 15 | 20 | /// |
| 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. | |
| 20 | 24 | /// |
| 21 | 25 | /// A cue off a PGS track is a *picture* and not a line |
| 22 | 26 | /// ([`engine::subtitle::CueImage`]), and is drawn as one: the disc's whole |
| @@ -37,22 +41,42 @@ impl Player { | ||
| 37 | 41 | // going off, the file closing and the gap between two cues are the same |
| 38 | 42 | // "nothing on screen", and an 8 MB atlas tile may not survive any of |
| 39 | 43 | // 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() { | |
| 46 | 61 | self.drop_sub_image(window); |
| 47 | 62 | return None; |
| 48 | 63 | } |
| 49 | 64 | // The first picture cue up, decoded once and kept: two bitmap cues at |
| 50 | 65 | // 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 | |
| 53 | 74 | .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)); | |
| 56 | 80 | // A picture is fitted onto the whole region and a plate hangs off the |
| 57 | 81 | // bottom of it, and a track is one or the other -- so they are two |
| 58 | 82 | // shapes and not one with the parts switched off. |
| @@ -96,7 +120,13 @@ impl Player { | ||
| 96 | 120 | .gap(px(2.)) |
| 97 | 121 | // The plate takes no click: the picture behind it is still the |
| 98 | 122 | // 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| { | |
| 100 | 130 | div() |
| 101 | 131 | .max_w(relative(0.9)) |
| 102 | 132 | .px(px(6.)) |
| @@ -118,7 +148,7 @@ impl Player { | ||
| 118 | 148 | ) |
| 119 | 149 | } |
| 120 | 150 | |
| 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 | |
| 122 | 152 | /// first repaint it is up for and kept until another cue takes its place |
| 123 | 153 | /// ([`Player::sub_image`]). `None` for a display set the decoder refuses, |
| 124 | 154 | /// which draws nothing rather than failing the frame. |
| @@ -128,11 +158,12 @@ impl Player { | ||
| 128 | 158 | /// sprite atlas by the whole film. |
| 129 | 159 | pub(crate) fn sub_picture( |
| 130 | 160 | &mut self, |
| 161 | + lane: Lane, | |
| 131 | 162 | start_us: i64, |
| 132 | 163 | image: &engine::subtitle::CueImage, |
| 133 | 164 | window: &mut Window, |
| 134 | 165 | ) -> Option<Arc<RenderImage>> { |
| 135 | - let key = (self.sub_track, start_us); | |
| 166 | + let key = (lane, start_us); | |
| 136 | 167 | if let Some((up, ready)) = &self.sub_image |
| 137 | 168 | && *up == key |
| 138 | 169 | { |
crates/app/src/ui/timeline.rsmodified+17 -17
| @@ -363,8 +363,8 @@ impl Player { | ||
| 363 | 363 | let tip: SharedString = match &row.refused { |
| 364 | 364 | Some(why) => format!("{} — {why}", path.display()), |
| 365 | 365 | 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", | |
| 368 | 368 | path.display() |
| 369 | 369 | ), |
| 370 | 370 | } |
| @@ -406,13 +406,14 @@ impl Player { | ||
| 406 | 406 | .on_drag(SubPick(track), move |_, _, _, cx| { |
| 407 | 407 | cx.new(|_| Tip(carried.clone())) |
| 408 | 408 | }) |
| 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. | |
| 409 | 415 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { |
| 410 | 416 | 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; | |
| 416 | 417 | cx.notify(); |
| 417 | 418 | })) |
| 418 | 419 | }) |
| @@ -550,16 +551,15 @@ impl Player { | ||
| 550 | 551 | .truncate() |
| 551 | 552 | .text_size(px(11.)) |
| 552 | 553 | .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", | |
| 563 | 563 | }), |
| 564 | 564 | ) |
| 565 | 565 | .child( |