forge
Explore
Log in

Don't you dare go Hollow

The picked track says which film it came out of, wherever it is named

Browse files at this commit

a29af89152260619457534f8c6d2ae2d928aa7ffAhmet Kaan GümüşParent: 388bbf4
  • feat
    • the picked track says which film it came out of, wherever it is named
Show full message
✨ feat(subtitles): the picked track says which film it came out of, wherever it is named

The strip header, the section heading and the toggle's own notice all echoed
`track.label` raw: two remuxes' "eng" tracks read alike, and a track whose only
tag is "und" named a language nobody speaks. All three now go through one
composer over the S1 grouping, so the name a header says and the row a person
clicked cannot disagree -- and the strip header wears the file's own colour,
the one its library row and its clips already wear.

A standalone `.srt` is nobody's stream: no colour, and no stem after a label
that is already the file's name.

The colour was asked for by a path spelled as it was typed and answered by
sources stored symlink-resolved, so `edith assets/film.mkv` painted no colour
at all. `file_tint` now falls back to the resolved spelling on a miss, which is
also the right answer for a file dragged in by a symlink.
crates/app/src/main.rsmodified+126 -17
@@ -1509,9 +1509,12 @@ impl Player {
1509 /// playhead happens to sit between two cues would read as broken.1509 /// playhead happens to sit between two cues would read as broken.
1510 fn toggle_subtitles(&mut self, cx: &mut Context<Self>) {1510 fn toggle_subtitles(&mut self, cx: &mut Context<Self>) {
1511 self.subs_on = !self.subs_on;1511 self.subs_on = !self.subs_on;
1512+ // Named with its film here too: a notice saying "SUBTITLES ON — eng"
1513+ // over a timeline holding two films' eng tracks names neither.
1512 let label = self1514 let label = self
1513- .subtitle_track()1515+ .session
1514- .map(|track| track.label.clone())1516+ .as_ref()
1517+ .and_then(|session| sub_pick_name(session.subtitles(), self.sub_track))
1515 .unwrap_or_else(|| "nothing imported".to_string());1518 .unwrap_or_else(|| "nothing imported".to_string());
1516 self.notice = Some(1519 self.notice = Some(
1517 match self.subs_on {1520 match self.subs_on {
@@ -5313,12 +5316,16 @@ impl Player {
5313 .truncate()5316 .truncate()
5314 .text_size(px(11.))5317 .text_size(px(11.))
5315 .text_color(rgb(INK_DIM))5318 .text_color(rgb(INK_DIM))
5316- .child(match self.subs_on {5319+ .child(match (self.subs_on, sub_pick_name(tracks, self.sub_track)) {
5317- true => "Subtitles",5320+ // Which of them is on screen, named by its film:
5321+ // the heading over a list of five is where the one
5322+ // being shown is worth saying out loud.
5323+ (true, Some(pick)) => format!("Subtitles — {pick}"),
5324+ (true, None) => "Subtitles".to_string(),
5318 // The toggle's state where the tracks are listed: a5325 // The toggle's state where the tracks are listed: a
5319 // list of subtitles nothing on screen is showing has5326 // list of subtitles nothing on screen is showing has
5320 // to say that it is showing none.5327 // to say that it is showing none.
5321- false => "Subtitles — hidden",5328+ (false, _) => "Subtitles — hidden".to_string(),
5322 }),5329 }),
5323 )5330 )
5324 .child(5331 .child(
@@ -8481,17 +8488,31 @@ impl Player {
8481 fn subtitle_strip(&self, filled: f32) -> Option<impl IntoElement + use<>> {8488 fn subtitle_strip(&self, filled: f32) -> Option<impl IntoElement + use<>> {
8482 let track = self.subtitle_track()?;8489 let track = self.subtitle_track()?;
8483 let scale = self.scale;8490 let scale = self.scale;
8484- let label = track.label.clone();8491+ // The pick with its film on it, not the raw tag: two films' "eng"
8492+ // tracks read alike otherwise, and a header saying "und" names a
8493+ // language nobody speaks.
8494+ let label = sub_pick_name(self.session.as_ref()?.subtitles(), self.sub_track)?;
8495+ // The colour the file's own rows and clips wear, so the strip says
8496+ // whose subtitles these are before the tooltip is asked. `None` for a
8497+ // standalone `.srt` -- nobody's stream, and the first film's colour
8498+ // would be a lie about where it came from.
8499+ let tint = file_tint(self.sources(), &track.path).unwrap_or(SURFACE);
8485 // The whole of what the row says in words, since a 40 px column can hold8500 // The whole of what the row says in words, since a 40 px column can hold
8486- // three characters of it: which track, how many cues, and -- for one8501+ // three characters of it: which track of which file, how many cues, the
8487- // that could not be read -- the engine's own reason, where the library8502+ // file itself in full -- one stem is two films when they are two cuts of
8488- // row's grey already says the same thing.8503+ // it -- and, for a track that could not be read, the engine's own reason,
8504+ // where the library row's grey already says the same thing.
8489 let tip: SharedString = match track.refused.is_some() {8505 let tip: SharedString = match track.refused.is_some() {
8490- true => format!("Subtitles: {label} — {}", subtitle_detail(track)),8506+ true => format!(
8507+ "Subtitles: {label} — {} — {}",
8508+ subtitle_detail(track),
8509+ track.path.display()
8510+ ),
8491 false => format!(8511 false => format!(
8492- "Subtitles: {label} — {}, {} hides them",8512+ "Subtitles: {label} — {}, {} hides them — {}",
8493 subtitle_detail(track),8513 subtitle_detail(track),
8494- self.keymap.display(ActionId::ToggleSubtitles)8514+ self.keymap.display(ActionId::ToggleSubtitles),
8515+ track.path.display()
8495 ),8516 ),
8496 }8517 }
8497 .into();8518 .into();
@@ -8528,7 +8549,7 @@ impl Player {
8528 // a centred truncation eats both of its ends.8549 // a centred truncation eats both of its ends.
8529 .px(px(2.))8550 .px(px(2.))
8530 .rounded(px(3.))8551 .rounded(px(3.))
8531- .bg(rgb(SURFACE))8552+ .bg(rgb(tint))
8532 .text_size(px(9.))8553 .text_size(px(9.))
8533 .text_color(rgb(INK_DIM))8554 .text_color(rgb(INK_DIM))
8534 .truncate()8555 .truncate()
@@ -9352,9 +9373,10 @@ fn subtitle_detail(track: &engine::subtitle::SubtitleTrack) -> String {
9352 /// before anything is drawn -- the grouping is the branchy part and it is the9373 /// before anything is drawn -- the grouping is the branchy part and it is the
9353 /// same answer whatever a styling puts around it.9374 /// same answer whatever a styling puts around it.
9354 ///9375 ///
9355-/// ponytail: nothing draws these yet -- [`Player::subtitle_section`] still9376+/// ponytail: only [`sub_pick_name`] reads these -- [`Player::subtitle_section`]
9356-/// lists the flat rows. Ceiling: the model is proven by its tests and by9377+/// still *lists* the flat rows, so the grouping shows in what the headers say
9357-/// nothing on screen. The upgrade is that section rendering groups instead.9378+/// and not yet in how the list is laid out. The upgrade is that section
9379+/// rendering groups instead.
9358 #[derive(Debug, PartialEq)]9380 #[derive(Debug, PartialEq)]
9359 #[allow(dead_code)]9381 #[allow(dead_code)]
9360 struct SubGroup {9382 struct SubGroup {
@@ -9428,6 +9450,38 @@ fn subtitle_rows(tracks: &[engine::subtitle::SubtitleTrack]) -> Vec<SubGroup> {
9428 groups9450 groups
9429 }9451 }
9430 9452
9453+/// How the picked track is named wherever the pick is echoed -- the strip
9454+/// header, the section heading, the toggle's own notice. What the track is
9455+/// *and* which file it came out of: two remuxes each carrying an "eng" track
9456+/// give the same word twice, and the file is the only thing that tells them
9457+/// apart. A file that gave several of them numbers them within itself, the way
9458+/// [`row_name`] numbers audio streams, since "eng" twice off one remux is the
9459+/// same problem one file down.
9460+///
9461+/// Goes through [`subtitle_rows`], so the name a header says and the row a
9462+/// person clicked cannot disagree -- and the label is humanised there, so an
9463+/// "und" track is named in words here without being passed through
9464+/// [`lang_human`] twice.
9465+///
9466+/// `None` for an index no track answers to, which is the silence
9467+/// [`Player::subtitle_track`] gives at the same moment.
9468+fn sub_pick_name(tracks: &[engine::subtitle::SubtitleTrack], track: usize) -> Option<String> {
9469+ subtitle_rows(tracks).into_iter().find_map(|group| {
9470+ let row = group.rows.iter().find(|row| row.track == track)?;
9471+ let track = match group.rows.len() > 1 {
9472+ false => row.label.clone(),
9473+ true => format!("{} {}", row.label, row.number),
9474+ };
9475+ // A standalone `.srt` is already named after its own file: "sub.srt —
9476+ // sub" says the one thing twice, and the film is only worth naming
9477+ // where it is not in the label yet.
9478+ Some(match row.label.starts_with(&group.name) {
9479+ true => track,
9480+ false => format!("{track} — {}", group.name),
9481+ })
9482+ })
9483+}
9484+
9431 /// Where a cue is drawn on the bed: left edge and width in pixels, through the9485 /// Where a cue is drawn on the bed: left edge and width in pixels, through the
9432 /// same [`Scale`] every clip box goes through -- so a cue and the take it is9486 /// same [`Scale`] every clip box goes through -- so a cue and the take it is
9433 /// spoken over line up at every zoom, which is the only reason the strip is9487 /// spoken over line up at every zoom, which is the only reason the strip is
@@ -10008,6 +10062,16 @@ fn file_tint(sources: &[Source], path: &Path) -> Option<u32> {
10008 sources10062 sources
10009 .iter()10063 .iter()
10010 .position(|s| s.path == path)10064 .position(|s| s.path == path)
10065+ .or_else(|| {
10066+ // A source entry is stored symlink-resolved (`Source::new`) and a
10067+ // path from anywhere else -- a subtitle track, a file being
10068+ // dragged -- is stored as it was spelled. `edith assets/film.mkv`
10069+ // is one file under two spellings, and matching by spelling alone
10070+ // said the film had no colour. Only asked when the spellings
10071+ // differ, so the common paint costs no syscall.
10072+ let path = std::fs::canonicalize(path).ok()?;
10073+ sources.iter().position(|s| s.path == path)
10074+ })
10011 .map(source_tint)10075 .map(source_tint)
10012 }10076 }
10013 10077
@@ -12025,7 +12089,7 @@ mod tests {
12025 use super::{12089 use super::{
12026 SUB_BOTTOM, SUB_CUE_MIN_W, SUB_INK, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, SUB_TEXT, cue_box,12090 SUB_BOTTOM, SUB_CUE_MIN_W, SUB_INK, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, SUB_TEXT, cue_box,
12027 cues_at, file_tint, is_matroska, is_subtitle, lang_human, subtitle_detail, subtitle_notice,12091 cues_at, file_tint, is_matroska, is_subtitle, lang_human, subtitle_detail, subtitle_notice,
12028- subtitle_rows, subtitle_strip_h,12092+ sub_pick_name, subtitle_rows, subtitle_strip_h,
12029 };12093 };
12030 12094
12031 /// What the file manager is handed: the parts a path keeps as they are, and12095 /// What the file manager is handed: the parts a path keeps as they are, and
@@ -16091,6 +16155,18 @@ mod tests {
16091 );16155 );
16092 assert_eq!(file_tint(&sources, Path::new("/subs/a.eng.srt")), None);16156 assert_eq!(file_tint(&sources, Path::new("/subs/a.eng.srt")), None);
16093 assert_eq!(file_tint(&[], Path::new("/films/a.mkv")), None);16157 assert_eq!(file_tint(&[], Path::new("/films/a.mkv")), None);
16158+ // The same file under two spellings is one file and one colour: a
16159+ // source is stored symlink-resolved, everything else as it was typed.
16160+ let here = std::fs::canonicalize(".").expect("the crate directory");
16161+ let sources = [Source {
16162+ path: here.join("Cargo.toml"),
16163+ audio_stream: 0,
16164+ }];
16165+ assert_eq!(
16166+ file_tint(&sources, Path::new("Cargo.toml")),
16167+ Some(source_tint(0)),
16168+ "a relative spelling of the source file wears the source's colour"
16169+ );
16094 }16170 }
16095 16171
16096 fn sub(path: &str, track: Option<u64>, label: &str) -> engine::subtitle::SubtitleTrack {16172 fn sub(path: &str, track: Option<u64>, label: &str) -> engine::subtitle::SubtitleTrack {
@@ -16154,6 +16230,39 @@ mod tests {
16154 assert_eq!(file_tint(&sources, &groups[2].path), None);16230 assert_eq!(file_tint(&sources, &groups[2].path), None);
16155 }16231 }
16156 16232
16233+ /// What the strip header, the section heading and the toggle's notice all
16234+ /// say. Two films each carrying an "eng" track are one word apart until the
16235+ /// film is in the name; a film carrying two is one word apart from itself.
16236+ #[test]
16237+ fn the_picked_subtitle_is_named_with_the_film_it_came_out_of() {
16238+ let tracks = [
16239+ sub("/films/a.mkv", Some(1), "eng"),
16240+ sub("/films/b.mkv", Some(1), "eng"),
16241+ sub("/films/a.mkv", Some(2), "eng"),
16242+ sub("/films/b.mkv", Some(2), "und"),
16243+ sub("/subs/late.srt", None, "late.srt"),
16244+ ];
16245+ let name = |track| sub_pick_name(&tracks, track).expect("a track that is there");
16246+ // The two "eng"s of two films: one file gave several so its tracks are
16247+ // numbered, the other gave one so it is not.
16248+ assert_eq!(name(0), "eng 1 — a");
16249+ assert_eq!(name(2), "eng 2 — a");
16250+ assert_eq!(name(1), "eng 1 — b");
16251+ assert_ne!(name(0), name(1), "two films' eng tracks read apart");
16252+ for picked in [name(0), name(1), name(2)] {
16253+ assert!(picked.contains(" — a") || picked.contains(" — b"));
16254+ }
16255+ // "und" is the tag for "nobody said", humanised once by
16256+ // `subtitle_rows` and not again here.
16257+ assert_eq!(name(3), "unknown language 2 — b");
16258+ // A standalone `.srt` is its own file and its label already says so:
16259+ // one track, so no number, and no stem after it saying it again.
16260+ assert_eq!(name(4), "late.srt");
16261+ // The silence `subtitle_track` gives at the same moment.
16262+ assert_eq!(sub_pick_name(&tracks, 5), None);
16263+ assert_eq!(sub_pick_name(&[], 0), None);
16264+ }
16265+
16157 /// The one thing regrouping must not break: `sub_track` is a flat index16266 /// The one thing regrouping must not break: `sub_track` is a flat index
16158 /// into the add-order list, a click sets it and a save writes it into the16267 /// into the add-order list, a click sets it and a save writes it into the
16159 /// `.edith`. Every row must still name the track it was made from -- rows16268 /// `.edith`. Every row must still name the track it was made from -- rows