One subtitle track is shown and every placed one is exported
Browse files at this commit1139174b72e4420544c5ebcc343f1318dbd53fd9Parent: e534575- feat
- one subtitle track is shown and every placed one is exported
9 changed files +177 -102
- crates/app/src/main.rs +20 -16
- crates/app/src/player/export.rs +23 -8
- crates/app/src/player/library.rs +12 -11
- crates/app/src/player/timeline_edit.rs +29 -17
- crates/app/src/subs.rs +19 -0
- crates/app/src/tests/media.rs +25 -0
- crates/app/src/tests/mod.rs +1 -1
- crates/app/src/ui/preview.rs +28 -41
- crates/app/src/ui/timeline.rs +20 -8
crates/app/src/main.rsmodified+20 -16
| @@ -226,8 +226,8 @@ struct Player { | |||
| 226 | /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement | 226 | /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement |
| 227 | /// no magnet may take away. | 227 | /// no magnet may take away. |
| 228 | snap: bool, | 228 | snap: bool, |
| 229 | - /// Whether the subtitle lanes draw at all -- the mute over every lane's eye | 229 | + /// Whether the subtitle lanes draw at all -- the mute over the shown lane |
| 230 | - /// ([`Player::subs_off`]), not a lane of its own. On by default and off by | 230 | + /// ([`Player::sub_lane`]), not a lane of its own. On by default and off by |
| 231 | /// one stroke | 231 | /// one stroke |
| 232 | /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for | 232 | /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for |
| 233 | /// anyone watching the picture rather than reading it. The player's, not the | 233 | /// anyone watching the picture rather than reading it. The player's, not the |
| @@ -243,22 +243,26 @@ struct Player { | |||
| 243 | /// like every other index here -- track 2 of one project is not track 2 of | 243 | /// like every other index here -- track 2 of one project is not track 2 of |
| 244 | /// the next. | 244 | /// the next. |
| 245 | sub_track: usize, | 245 | sub_track: usize, |
| 246 | - /// The subtitle lanes whose eye is shut: every lane shows its captions | 246 | + /// Which subtitle lane is *shown*: one of them and never two, the way a |
| 247 | - /// until this says otherwise, so a lane that was just added is a lane that | 247 | + /// player has one subtitle track chosen at a time -- two hundred lanes of |
| 248 | - /// draws. Held as the lanes that are *off* rather than a flag per lane, so | 248 | + /// different words all drawn at once is two hundred plates over one |
| 249 | - /// adding one needs no bookkeeping at all. | 249 | + /// picture, and nothing readable. |
| 250 | /// | 250 | /// |
| 251 | - /// Read where the cues are drawn ([`Player::subtitle_overlay`]): shutting an | 251 | + /// `None` is nobody having picked yet, which reads as the first subtitle |
| 252 | - /// eye takes that lane's plate off the picture and leaves its captions on | 252 | + /// lane ([`Player::active_sub_lane`]) -- so one lane is shown without a |
| 253 | - /// the lane. Not saved -- a `.edith` has no line for it yet. | 253 | + /// pick, the first lane added draws, and a pick naming a lane that has |
| 254 | + /// since gone falls back to the first rather than showing nothing. | ||
| 255 | + /// | ||
| 256 | + /// Read where the cues are drawn ([`Player::subtitle_overlay`]) and nowhere | ||
| 257 | + /// else: what an *export* writes is every lane on the timeline | ||
| 258 | + /// ([`engine::export`]), which this pick has no say in. Not saved -- a | ||
| 259 | + /// `.edith` has no line for it yet. | ||
| 254 | /// | 260 | /// |
| 255 | /// A [`Lane`] handle is a position among its kind, so a removal or a | 261 | /// A [`Lane`] handle is a position among its kind, so a removal or a |
| 256 | - /// reorder leaves every shut eye naming another track: they are dropped | 262 | + /// reorder leaves a pick naming another track: it is dropped there, |
| 257 | - /// wholesale there, exactly as the selection and the open cards are | 263 | + /// exactly as the selection and the open cards are ([`Player::remove_lane`], |
| 258 | - /// ([`Player::remove_lane`], [`Player::reorder_lane`]) -- which is why a | 264 | + /// [`Player::reorder_lane`]), which shows the first lane again. |
| 259 | - /// lane added in a removed one's place opens with its eye open, as every | 265 | + sub_lane: Option<Lane>, |
| 260 | - /// new lane does. | ||
| 261 | - subs_off: Vec<Lane>, | ||
| 262 | /// The frame the live gesture is about to land on, or `None` while it is | 266 | /// The frame the live gesture is about to land on, or `None` while it is |
| 263 | /// over open bed: the line every lane draws so the snap is seen before it | 267 | /// over open bed: the line every lane draws so the snap is seen before it |
| 264 | /// happens rather than discovered after the release. Stale between gestures, | 268 | /// happens rather than discovered after the release. Stale between gestures, |
| @@ -670,7 +674,7 @@ fn main() { | |||
| 670 | snap: true, | 674 | snap: true, |
| 671 | subs_on: true, | 675 | subs_on: true, |
| 672 | sub_track: 0, | 676 | sub_track: 0, |
| 673 | - subs_off: Vec::new(), | 677 | + sub_lane: None, |
| 674 | snap_cue: None, | 678 | snap_cue: None, |
| 675 | ghost: None, | 679 | ghost: None, |
| 676 | lane_drop: None, | 680 | lane_drop: None, |
crates/app/src/player/export.rsmodified+23 -8
| @@ -510,15 +510,24 @@ impl Player { | |||
| 510 | .detach(); | 510 | .detach(); |
| 511 | } | 511 | } |
| 512 | 512 | ||
| 513 | - /// The subtitle tracks an export of this timeline carries: every one with a | 513 | + /// The subtitle tracks an export of this timeline carries: every one a |
| 514 | - /// cue left in the exported range ([`PlaybackSession::timeline_cues`], the | 514 | + /// subtitle *lane* places, with a cue left in the exported range |
| 515 | - /// very map the file is written from), in the library's own order. | 515 | + /// ([`PlaybackSession::timeline_cues`], the very map the file is written |
| 516 | + /// from), in the library's own order. | ||
| 516 | /// | 517 | /// |
| 517 | - /// Worked out from the cues each time rather than kept as a pick, which is | 518 | + /// On the timeline or not at all: a track sitting in the palette is a track |
| 518 | - /// what makes it impossible to desync: a row added or taken off shifts every | 519 | + /// nobody put anywhere, and one dropped off its lane is one somebody took |
| 519 | - /// index after it, and a stored list would then name tracks nobody chose. | 520 | + /// away -- neither belongs in the file. Without the placement test they came |
| 520 | - /// `Player::sub_track` stays what it always was -- which palette row the | 521 | + /// back through the engine's palette door (`export::planned_subtitles` falls |
| 521 | - /// list *marks* -- and has no say here. | 522 | + /// back to these picks when no lane holds anything), so emptying every |
| 523 | + /// subtitle lane and exporting wrote all three of them into the output. | ||
| 524 | + /// | ||
| 525 | + /// Worked out from the timeline each time rather than kept as a pick, which | ||
| 526 | + /// is what makes it impossible to desync: a row added or taken off shifts | ||
| 527 | + /// every index after it, and a stored list would then name tracks nobody | ||
| 528 | + /// chose. `Player::sub_track` stays what it always was -- which palette row | ||
| 529 | + /// the list *marks* -- and has no say here, and neither has the lane that is | ||
| 530 | + /// shown over the picture ([`Player::active_sub_lane`]): every lane travels. | ||
| 522 | /// | 531 | /// |
| 523 | /// The honest input and not the final answer: the engine filters it again | 532 | /// The honest input and not the final answer: the engine filters it again |
| 524 | /// per track (a track that could not be read, a picture one) and says so in | 533 | /// per track (a track that could not be read, a picture one) and says so in |
| @@ -527,7 +536,13 @@ impl Player { | |||
| 527 | let Some(session) = self.session.as_ref() else { | 536 | let Some(session) = self.session.as_ref() else { |
| 528 | return Vec::new(); | 537 | return Vec::new(); |
| 529 | }; | 538 | }; |
| 539 | + let placed: Vec<usize> = session | ||
| 540 | + .subtitle_lanes() | ||
| 541 | + .into_iter() | ||
| 542 | + .flat_map(|lane| session.sub_lane(lane).iter().map(|sub| sub.track)) | ||
| 543 | + .collect(); | ||
| 530 | (0..session.subtitles().len()) | 544 | (0..session.subtitles().len()) |
| 545 | + .filter(|i| placed.contains(i)) | ||
| 531 | .filter(|&i| !session.timeline_cues(i).is_empty()) | 546 | .filter(|&i| !session.timeline_cues(i).is_empty()) |
| 532 | .collect() | 547 | .collect() |
| 533 | } | 548 | } |
crates/app/src/player/library.rsmodified+12 -11
| @@ -147,10 +147,10 @@ impl Player { | |||
| 147 | self.clipboard = None; | 147 | self.clipboard = None; |
| 148 | self.selected = None; | 148 | self.selected = None; |
| 149 | self.selected_asset = None; | 149 | self.selected_asset = None; |
| 150 | - // The subtitle rows go with the timeline they were on, and so do the | 150 | + // The subtitle rows go with the timeline they were on, and so does the |
| 151 | - // eyes: S1 of one project is not S1 of the next. | 151 | + // lane that was shown: S1 of one project is not S1 of the next. |
| 152 | self.sub_track = 0; | 152 | self.sub_track = 0; |
| 153 | - self.subs_off.clear(); | 153 | + self.sub_lane = None; |
| 154 | self.context_menu = None; | 154 | self.context_menu = None; |
| 155 | self.library_menu = None; | 155 | self.library_menu = None; |
| 156 | self.eq_open = None; | 156 | self.eq_open = None; |
| @@ -1105,10 +1105,11 @@ impl Player { | |||
| 1105 | self.color_open = None; | 1105 | self.color_open = None; |
| 1106 | self.speed_open = None; | 1106 | self.speed_open = None; |
| 1107 | self.close_silence(); | 1107 | self.close_silence(); |
| 1108 | - // The eyes with them: a `Lane` is a position among its | 1108 | + // The shown lane with them: a `Lane` is a position among |
| 1109 | - // kind, so every shut one now names another track -- | 1109 | + // its kind, so a pick now names another track -- the same |
| 1110 | - // the same reason the selection and the cards go. | 1110 | + // reason the selection and the cards go. The first lane |
| 1111 | - self.subs_off.clear(); | 1111 | + // left is drawn ([`subs::active_lane`]). |
| 1112 | + self.sub_lane = None; | ||
| 1112 | format!( | 1113 | format!( |
| 1113 | "{} REMOVED — {} brings it back", | 1114 | "{} REMOVED — {} brings it back", |
| 1114 | lane.label(), | 1115 | lane.label(), |
| @@ -1161,10 +1162,10 @@ impl Player { | |||
| 1161 | self.color_open = None; | 1162 | self.color_open = None; |
| 1162 | self.speed_open = None; | 1163 | self.speed_open = None; |
| 1163 | self.close_silence(); | 1164 | self.close_silence(); |
| 1164 | - // The eyes with them: a `Lane` is a position among its | 1165 | + // The shown lane with them: a `Lane` is a position among its |
| 1165 | - // kind, so every shut one now names another track -- | 1166 | + // kind, so a pick now names another track -- the same reason |
| 1166 | - // the same reason the selection and the cards go. | 1167 | + // the selection and the cards go. |
| 1167 | - self.subs_off.clear(); | 1168 | + self.sub_lane = None; |
| 1168 | } | 1169 | } |
| 1169 | self.notify_user( | 1170 | self.notify_user( |
| 1170 | format!( | 1171 | format!( |
crates/app/src/player/timeline_edit.rsmodified+29 -17
| @@ -371,29 +371,41 @@ impl Player { | |||
| 371 | cx.notify(); | 371 | cx.notify(); |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | - /// A subtitle lane's eye: whether it draws its captions. State only for now | 374 | + /// A subtitle lane's dot: the one lane whose captions are over the picture. |
| 375 | - /// -- what reads it is the slice that draws the lanes over the picture -- | 375 | + /// A pick and not a toggle -- picking one puts the one that was showing |
| 376 | - /// and said out loud, because a toggle whose only effect is a header glyph | 376 | + /// away, because two lanes of different words at one moment is two plates |
| 377 | - /// has to say what it has and has not done yet. | 377 | + /// nobody can read, and it is said out loud for that reason: what the click |
| 378 | - pub(crate) fn toggle_sub_lane(&mut self, lane: Lane, cx: &mut Context<Self>) { | 378 | + /// did *and* what it undid. |
| 379 | - let text = match self.subs_off.iter().position(|&l| l == lane) { | 379 | + /// |
| 380 | - Some(i) => { | 380 | + /// The lanes it takes off the picture keep their captions and are still |
| 381 | - self.subs_off.remove(i); | 381 | + /// exported, every one of them ([`Player::start_export`]). |
| 382 | - format!("{} SHOWS ITS CAPTIONS", lane.label()) | 382 | + pub(crate) fn show_sub_lane(&mut self, lane: Lane, cx: &mut Context<Self>) { |
| 383 | - } | 383 | + let was = self.active_sub_lane(); |
| 384 | - None => { | 384 | + self.sub_lane = Some(lane); |
| 385 | - self.subs_off.push(lane); | 385 | + let text = match was.filter(|&old| old != lane) { |
| 386 | - format!("{} IS HIDDEN — its captions stay on the lane", lane.label()) | 386 | + Some(old) => format!( |
| 387 | - } | 387 | + "{} IS SHOWN — {} is off the picture; every subtitle track is still exported", |
| 388 | + lane.label(), | ||
| 389 | + old.label() | ||
| 390 | + ), | ||
| 391 | + None => format!("{} IS SHOWN — its captions are over the picture", lane.label()), | ||
| 388 | }; | 392 | }; |
| 389 | self.notify_user(text.into()); | 393 | self.notify_user(text.into()); |
| 390 | cx.notify(); | 394 | cx.notify(); |
| 391 | } | 395 | } |
| 392 | 396 | ||
| 393 | - /// Whether that subtitle lane's captions are drawn -- the eye, read by the | 397 | + /// The subtitle lane whose captions are drawn: the pick resolved against the |
| 394 | - /// header that offers it and by whatever draws cues from here on. | 398 | + /// lanes the timeline has right now ([`active_lane`]), so it can never name |
| 399 | + /// a lane that is not there. `None` with no subtitle lane at all. | ||
| 400 | + pub(crate) fn active_sub_lane(&self) -> Option<Lane> { | ||
| 401 | + let lanes = self.session.as_ref()?.subtitle_lanes(); | ||
| 402 | + active_lane(self.sub_lane, &lanes) | ||
| 403 | + } | ||
| 404 | + | ||
| 405 | + /// Whether that subtitle lane's captions are drawn -- read by the header | ||
| 406 | + /// that offers the pick and by the plate over the picture. | ||
| 395 | pub(crate) fn sub_lane_on(&self, lane: Lane) -> bool { | 407 | pub(crate) fn sub_lane_on(&self, lane: Lane) -> bool { |
| 396 | - !self.subs_off.contains(&lane) | 408 | + self.active_sub_lane() == Some(lane) |
| 397 | } | 409 | } |
| 398 | 410 | ||
| 399 | /// Where a caption let go at window `x` wants its head: [`Player::drop_frame`]'s | 411 | /// Where a caption let go at window `x` wants its head: [`Player::drop_frame`]'s |
crates/app/src/subs.rsmodified+19 -0
| @@ -589,6 +589,25 @@ pub(crate) fn cue_box(scale: Scale, cue: &engine::subtitle::Cue) -> (f32, f32) { | |||
| 589 | ) | 589 | ) |
| 590 | } | 590 | } |
| 591 | 591 | ||
| 592 | +/// Which subtitle lane draws over the picture, out of the pick somebody made | ||
| 593 | +/// and the lanes there are *now* ([`Player::active_sub_lane`]): the picked one | ||
| 594 | +/// while it is still on the timeline, and the first lane otherwise -- which is | ||
| 595 | +/// the whole of "one lane needs no picking", "the first lane added draws" and | ||
| 596 | +/// "a removed lane's pick promotes its neighbour rather than showing nothing". | ||
| 597 | +/// | ||
| 598 | +/// `None` only with no subtitle lane at all, which is a timeline with nowhere | ||
| 599 | +/// for words to be. | ||
| 600 | +/// | ||
| 601 | +/// A pick against the live list rather than a pointer kept in step with it: a | ||
| 602 | +/// [`Lane`] is a position among its kind, so an add, a removal, a reorder and | ||
| 603 | +/// every undo of those move what a stored handle names -- and each of them is | ||
| 604 | +/// answered here, at the read, by a list that is never stale. | ||
| 605 | +pub(crate) fn active_lane(picked: Option<Lane>, lanes: &[Lane]) -> Option<Lane> { | ||
| 606 | + picked | ||
| 607 | + .filter(|lane| lanes.contains(lane)) | ||
| 608 | + .or_else(|| lanes.first().copied()) | ||
| 609 | +} | ||
| 610 | + | ||
| 592 | /// Which cues of a track are on screen at `at` seconds. Half-open, as the cue | 611 | /// Which cues of a track are on screen at `at` seconds. Half-open, as the cue |
| 593 | /// itself is: one that ends exactly where the next begins hands over rather than | 612 | /// itself is: one that ends exactly where the next begins hands over rather than |
| 594 | /// overlapping it for a frame, and several that genuinely overlap all come back | 613 | /// overlapping it for a frame, and several that genuinely overlap all come back |
crates/app/src/tests/media.rsmodified+25 -0
| @@ -1102,3 +1102,28 @@ fn subtitles_arrive_beside_the_media_and_inside_it() { | |||
| 1102 | assert!(shown(1.8).is_empty(), "between two cues the plate goes"); | 1102 | assert!(shown(1.8).is_empty(), "between two cues the plate goes"); |
| 1103 | assert_eq!(shown(2.5), ["second line\nwith a break"]); | 1103 | assert_eq!(shown(2.5), ["second line\nwith a break"]); |
| 1104 | } | 1104 | } |
| 1105 | + | ||
| 1106 | +/// One lane over the picture and never two ([`Player::active_sub_lane`]): which | ||
| 1107 | +/// one, at every moment a stack of subtitle lanes goes through -- none, one, | ||
| 1108 | +/// three, a pick, and the pick's lane going away under it. | ||
| 1109 | +#[test] | ||
| 1110 | +fn exactly_one_subtitle_lane_is_shown_whatever_the_pick_and_whatever_is_left() { | ||
| 1111 | + let sub = |ord| Lane::new(LaneKind::Subtitle, ord); | ||
| 1112 | + let (s1, s2, s3) = (sub(0), sub(1), sub(2)); | ||
| 1113 | + // Nowhere for words to be: no lane, nothing shown -- and a pick left over | ||
| 1114 | + // from a timeline that has been closed does not resurrect one. | ||
| 1115 | + assert_eq!(active_lane(None, &[]), None); | ||
| 1116 | + assert_eq!(active_lane(Some(s2), &[]), None); | ||
| 1117 | + // One lane is shown by being the only one: nobody has to pick anything, | ||
| 1118 | + // which is what the single-lane timeline always did. | ||
| 1119 | + assert_eq!(active_lane(None, &[s1]), Some(s1)); | ||
| 1120 | + // Three, unpicked: the first, so adding lanes never blanks the picture. | ||
| 1121 | + assert_eq!(active_lane(None, &[s1, s2, s3]), Some(s1)); | ||
| 1122 | + // ...and picked: that one alone, however many are there. | ||
| 1123 | + assert_eq!(active_lane(Some(s3), &[s1, s2, s3]), Some(s3)); | ||
| 1124 | + // The picked lane taken off the timeline -- a removal, or the undo of the | ||
| 1125 | + // add that made it: the first lane left is shown, never nothing. | ||
| 1126 | + assert_eq!(active_lane(Some(s3), &[s1, s2]), Some(s1)); | ||
| 1127 | + // A pick that is not a subtitle lane at all cannot name one either. | ||
| 1128 | + assert_eq!(active_lane(Some(Lane::V1), &[s1, s2]), Some(s1)); | ||
| 1129 | +} | ||
crates/app/src/tests/mod.rsmodified+1 -1
| @@ -28,7 +28,7 @@ use super::{ | |||
| 28 | format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, | 28 | format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, |
| 29 | frame_rate_ladder, histogram, | 29 | frame_rate_ladder, histogram, |
| 30 | inserted_band, is_bare_modifier, is_project, keymap, keys_filter, keys_rows, lanes_h, | 30 | inserted_band, is_bare_modifier, is_project, keymap, keys_filter, keys_rows, lanes_h, |
| 31 | - marked, menu_at, menu_items, menu_rows_h, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, | 31 | + active_lane, marked, menu_at, menu_items, menu_rows_h, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, |
| 32 | LATE_RESYNC, RESYNC_GAP, should_resync, | 32 | LATE_RESYNC, RESYNC_GAP, should_resync, |
| 33 | retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped, | 33 | retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped, |
| 34 | SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport, | 34 | SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport, |
crates/app/src/ui/preview.rsmodified+28 -41
| @@ -12,10 +12,12 @@ impl Player { | |||
| 12 | /// the palette and nothing more, exactly as a picture or a song does, and it | 12 | /// the palette and nothing more, exactly as a picture or a song does, and it |
| 13 | /// reaches the screen when a placement of it sits under the playhead | 13 | /// reaches the screen when a placement of it sits under the playhead |
| 14 | /// ([`PlaybackSession::sub_lane_cues`], the same map the export writes the | 14 | /// ([`PlaybackSession::sub_lane_cues`], the same map the export writes the |
| 15 | - /// file with -- so what is read here is what the file will say). Every lane | 15 | + /// file with -- so what is read here is what the file will say). **One** |
| 16 | - /// whose eye is open ([`Player::sub_lane_on`]) draws, so two enabled lanes | 16 | + /// lane draws, the one that is shown ([`Player::active_sub_lane`]): a |
| 17 | - /// are two plates: lane order bottom-up, the first lane where a single | 17 | + /// picture carrying every lane's words at once is unreadable at three lanes |
| 18 | - /// track's words have always been and each further one stacked above it. | 18 | + /// and nonsense at two hundred, which is the same one-track-at-a-time every |
| 19 | + /// player offers. What an export writes is untouched by this -- every lane | ||
| 20 | + /// on the timeline becomes a subtitle track of the file. | ||
| 19 | /// | 21 | /// |
| 20 | /// `None` -- no element at all -- while the toggle is off, with nothing | 22 | /// `None` -- no element at all -- while the toggle is off, with nothing |
| 21 | /// placed, and between cues: the picture is what this window is for, and a | 23 | /// placed, and between cues: the picture is what this window is for, and a |
| @@ -40,42 +42,29 @@ impl Player { | |||
| 40 | // going off, the file closing and the gap between two cues are the same | 42 | // going off, the file closing and the gap between two cues are the same |
| 41 | // "nothing on screen", and an 8 MB atlas tile may not survive any of | 43 | // "nothing on screen", and an 8 MB atlas tile may not survive any of |
| 42 | // them (an early return above this leaked one per toggle-off). | 44 | // them (an early return above this leaked one per toggle-off). |
| 43 | - // Per lane and not one flat list: the plates stack by lane below, and a | 45 | + // One lane's cues and never a walk of the lanes: the map is asked of the |
| 44 | - // picture's cache key needs the lane it came off ([`Player::sub_picture`]). | 46 | + // shown lane alone, so two hundred subtitle lanes cost this frame what |
| 45 | - let lanes: Vec<(Lane, Vec<engine::subtitle::Cue>)> = | 47 | + // one does. |
| 46 | - match self.session.as_ref().filter(|_| self.subs_on) { | 48 | + let shown: Option<(Lane, Vec<engine::subtitle::Cue>)> = self |
| 47 | - Some(session) => session | 49 | + .active_sub_lane() |
| 48 | - .subtitle_lanes() | 50 | + .filter(|_| self.subs_on) |
| 49 | - .into_iter() | 51 | + .and_then(|lane| { |
| 50 | - .filter(|&lane| self.sub_lane_on(lane)) | 52 | + let cues = self.session.as_ref()?.sub_lane_cues(lane); |
| 51 | - .map(|lane| { | 53 | + let now: Vec<_> = cues_at(&cues, at).into_iter().cloned().collect(); |
| 52 | - let cues = session.sub_lane_cues(lane); | 54 | + (!now.is_empty()).then_some((lane, now)) |
| 53 | - (lane, cues_at(&cues, at).into_iter().cloned().collect()) | 55 | + }); |
| 54 | - }) | 56 | + let Some((lane, cues)) = shown else { |
| 55 | - .filter(|(_, cues): &(_, Vec<_>)| !cues.is_empty()) | ||
| 56 | - .collect(), | ||
| 57 | - None => Vec::new(), | ||
| 58 | - }; | ||
| 59 | - if lanes.is_empty() { | ||
| 60 | self.drop_sub_image(window); | 57 | self.drop_sub_image(window); |
| 61 | return None; | 58 | return None; |
| 62 | - } | 59 | + }; |
| 63 | // The first picture cue up, decoded once and kept: two bitmap cues at | 60 | // The first picture cue up, decoded once and kept: two bitmap cues at |
| 64 | // one moment is a thing PGS composes into one display set, so there is | 61 | // one moment is a thing PGS composes into one display set, so there is |
| 65 | - // never a second picture to stack under the first *on one lane*. | 62 | + // never a second picture to stack under the first on one lane -- and one |
| 66 | - // | 63 | + // lane is all there is here. |
| 67 | - // corner-cut: two enabled lanes each showing a PGS track draw the lower | 64 | + let picture = cues |
| 68 | - // lane's picture alone -- one cache slot, one canvas over the whole | ||
| 69 | - // region, and a second canvas would cover the first anyway. The upgrade | ||
| 70 | - // path is a slot per lane, which wants the plates' stacking rule to mean | ||
| 71 | - // something for canvases too. | ||
| 72 | - let picture = lanes | ||
| 73 | .iter() | 65 | .iter() |
| 74 | - .find_map(|(lane, cues)| { | 66 | + .find_map(|cue| Some((cue.start_us, cue.image.as_ref()?))) |
| 75 | - cues.iter() | 67 | + .and_then(|(start_us, image)| self.sub_picture(lane, start_us, image, window)); |
| 76 | - .find_map(|cue| Some((*lane, cue.start_us, cue.image.as_ref()?))) | ||
| 77 | - }) | ||
| 78 | - .and_then(|(lane, start_us, image)| self.sub_picture(lane, start_us, image, window)); | ||
| 79 | // A picture is fitted onto the whole region and a plate hangs off the | 68 | // A picture is fitted onto the whole region and a plate hangs off the |
| 80 | // bottom of it, and a track is one or the other -- so they are two | 69 | // bottom of it, and a track is one or the other -- so they are two |
| 81 | // shapes and not one with the parts switched off. | 70 | // shapes and not one with the parts switched off. |
| @@ -120,12 +109,10 @@ impl Player { | |||
| 120 | // The plate takes no click: the picture behind it is still the | 109 | // The plate takes no click: the picture behind it is still the |
| 121 | // drop target the whole window is. | 110 | // drop target the whole window is. |
| 122 | // | 111 | // |
| 123 | - // Reversed, because a column anchored at the bottom lays its | 112 | + // In the lane's own order: two cues at one moment -- a sign and |
| 124 | - // children downwards: the *last* lane is written first so the | 113 | + // a line of dialogue -- stack, the first on the bottom line |
| 125 | - // first lane keeps the bottom line it has when it is the only | 114 | + // where a single cue sits. |
| 126 | - // one, and a second lane stacks above it rather than pushing it | 115 | + .children(cues.into_iter().filter(|c| c.image.is_none()).map(|cue| { |
| 127 | - // off its place. | ||
| 128 | - .children(lanes.into_iter().rev().flat_map(|(_, cues)| cues).filter(|c| c.image.is_none()).map(|cue| { | ||
| 129 | div() | 116 | div() |
| 130 | .max_w(relative(0.9)) | 117 | .max_w(relative(0.9)) |
| 131 | .px(px(6.)) | 118 | .px(px(6.)) |
crates/app/src/ui/timeline.rsmodified+20 -8
| @@ -651,8 +651,11 @@ impl Player { | |||
| 651 | _ => Vec::new(), | 651 | _ => Vec::new(), |
| 652 | }; | 652 | }; |
| 653 | let eye_tip: SharedString = match shown { | 653 | let eye_tip: SharedString = match shown { |
| 654 | - true => format!("{name} shows its captions — click to hide this track"), | 654 | + true => format!("{name} is the track shown over the picture"), |
| 655 | - false => format!("{name} is hidden — click to show its captions again"), | 655 | + false => format!( |
| 656 | + "Click to show {name} over the picture instead — one subtitle track is drawn at a \ | ||
| 657 | + time, and an export carries every one of them" | ||
| 658 | + ), | ||
| 656 | } | 659 | } |
| 657 | .into(); | 660 | .into(); |
| 658 | // What a caption's box says clicking it does; the media boxes' tooltip | 661 | // What a caption's box says clicking it does; the media boxes' tooltip |
| @@ -759,12 +762,15 @@ impl Player { | |||
| 759 | }) | 762 | }) |
| 760 | .into_any_element(), | 763 | .into_any_element(), |
| 761 | // A subtitle track's own one setting, in the same | 764 | // A subtitle track's own one setting, in the same |
| 762 | - // place and for the same reason: whether this lane's | 765 | + // place and for the same reason: whether *this* lane is |
| 763 | - // words are drawn over the picture. The eye every | 766 | + // the one drawn over the picture. A radio and not an |
| 764 | - // player puts on a track, `HIT_MIN` tall like the mix | 767 | + // eye -- one track shows at a time, so a click here |
| 765 | - // button it sits where. | 768 | + // takes the picture off whichever lane had it -- and |
| 769 | + // `HIT_MIN` tall like the mix button it sits where. | ||
| 770 | + // The lit dot and the accent tell the shown lane from | ||
| 771 | + // the rest of a stack of them at a glance. | ||
| 766 | false if sub => div() | 772 | false if sub => div() |
| 767 | - .id(("eye-lane", lane.ord)) | 773 | + .id(("show-lane", lane.ord)) |
| 768 | .flex_1() | 774 | .flex_1() |
| 769 | .w_full() | 775 | .w_full() |
| 770 | .flex() | 776 | .flex() |
| @@ -775,9 +781,15 @@ impl Player { | |||
| 775 | .cursor_pointer() | 781 | .cursor_pointer() |
| 776 | .hover(|s| s.bg(rgb(BG_HOVER()))) | 782 | .hover(|s| s.bg(rgb(BG_HOVER()))) |
| 777 | .when(!shown, |d| d.text_color(rgb(FG_DISABLED()))) | 783 | .when(!shown, |d| d.text_color(rgb(FG_DISABLED()))) |
| 784 | + .when(shown, |d| { | ||
| 785 | + d.text_color(rgb(ACCENT_PRIMARY())) | ||
| 786 | + .bg(rgb(BG_HOVER())) | ||
| 787 | + .border_1() | ||
| 788 | + .border_color(rgb(ACCENT_PRIMARY())) | ||
| 789 | + }) | ||
| 778 | .tooltip(move |_, cx| cx.new(|_| Tip(eye_tip.clone())).into()) | 790 | .tooltip(move |_, cx| cx.new(|_| Tip(eye_tip.clone())).into()) |
| 779 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 791 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { |
| 780 | - this.toggle_sub_lane(lane, cx) | 792 | + this.show_sub_lane(lane, cx) |
| 781 | })) | 793 | })) |
| 782 | .child(name.clone()) | 794 | .child(name.clone()) |
| 783 | .child( | 795 | .child( |