forge
Explore
Log in

Don't you dare go Hollow

Merge remote-tracking branch 'origin/main' into worktree-agent-a5df3068013f45eda

Browse files at this commit

cd8f9fa25ccf8d994ebaae3b20c82984adbb6e3fAhmet Kaan GümüşParent: 264c10c388bbf4
crates/app/src/main.rsmodified+305 -21
@@ -38,8 +38,11 @@ const SELECTED: u32 = 0x2a4a6b;
38 /// One per source, so a clip that came from an imported file reads as coming38 /// One per source, so a clip that came from an imported file reads as coming
39 /// from somewhere else. Same brightness as `SURFACE` and only the hue moves:39 /// from somewhere else. Same brightness as `SURFACE` and only the hue moves:
40 /// the lane stays in the dark family the rest of the chrome lives in40 /// the lane stays in the dark family the rest of the chrome lives in
41-/// (ledger:187), and the first source keeps `SURFACE` exactly.41+/// (ledger:187). The first entry is a colour like the rest rather than `SURFACE`
42-const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b];42+/// itself -- a first import whose swatch is the panel's own background is a
43+/// swatch nobody can see, and a file with one colour is what the whole
44+/// association is built on.
45+const SOURCE_TINTS: [u32; 4] = [0x29333b, 0x3b3329, 0x293b33, 0x33293b];
43 /// The mirror of `SELECTED`: a drop the lane will not take, tinting the shadow46 /// The mirror of `SELECTED`: a drop the lane will not take, tinting the shadow
44 /// a drag draws ([`Ghost`]) so a refusal is seen before the release rather than47 /// a drag draws ([`Ghost`]) so a refusal is seen before the release rather than
45 /// read afterwards. Same brightness as the rest of the chrome -- a warning, not48 /// read afterwards. Same brightness as the rest of the chrome -- a warning, not
@@ -352,7 +355,7 @@ struct Ghost {
352 /// as wide as the clip is *long where it lands*. Zero for a library row of355 /// as wide as the clip is *long where it lands*. Zero for a library row of
353 /// unknown length, drawn as a head marker.356 /// unknown length, drawn as a head marker.
354 frames: u32,357 frames: u32,
355- /// The swatch of the file being carried ([`Player::file_tint`]), so the358+ /// The swatch of the file being carried ([`file_tint`]), so the
356 /// ghost reads as the thing in the hand.359 /// ghost reads as the thing in the hand.
357 tint: u32,360 tint: u32,
358 refused: bool,361 refused: bool,
@@ -3144,7 +3147,9 @@ impl Player {
3144 .session3147 .session
3145 .as_ref()3148 .as_ref()
3146 .map_or(0, |session| session.file_frames(path)),3149 .map_or(0, |session| session.file_frames(path)),
3147- tint: self.file_tint(path),3150+ // A path with no source entry has no colour of its own, and the
3151+ // shadow wears the lane's own instead of borrowing another file's.
3152+ tint: file_tint(self.sources(), path).unwrap_or(SURFACE),
3148 refused: lane_refuses(path, to).is_some(),3153 refused: lane_refuses(path, to).is_some(),
3149 };3154 };
3150 self.set_ghost(Some(ghost), cx);3155 self.set_ghost(Some(ghost), cx);
@@ -3167,20 +3172,10 @@ impl Player {
3167 /// two sources and one colour. Every box on a lane and every ghost a drag3172 /// two sources and one colour. Every box on a lane and every ghost a drag
3168 /// draws asks this, so the shadow is recognisably the thing in the hand.3173 /// draws asks this, so the shadow is recognisably the thing in the hand.
3169 fn clip_tint(&self, source: usize) -> u32 {3174 fn clip_tint(&self, source: usize) -> u32 {
3170- match self.sources().get(source) {
3171- Some(entry) => self.file_tint(&entry.path),
3172- None => source_tint(source),
3173- }
3174- }
3175-
3176- /// The same swatch asked by path, which is what a library row is named by.
3177- fn file_tint(&self, path: &Path) -> u32 {
3178- source_tint(
3179 self.sources()3175 self.sources()
3180- .iter()3176+ .get(source)
3181- .position(|s| s.path == path)3177+ .and_then(|entry| file_tint(self.sources(), &entry.path))
3182- .unwrap_or(0),3178+ .unwrap_or_else(|| source_tint(source))
3183- )
3184 }3179 }
3185 3180
3186 fn sources(&self) -> &[Source] {3181 fn sources(&self) -> &[Source] {
@@ -9353,6 +9348,86 @@ fn subtitle_detail(track: &engine::subtitle::SubtitleTrack) -> String {
9353 }9348 }
9354 }9349 }
9355 9350
9351+/// Every subtitle track one file gave, kept together. Plain data, planned
9352+/// before anything is drawn -- the grouping is the branchy part and it is the
9353+/// same answer whatever a styling puts around it.
9354+///
9355+/// ponytail: nothing draws these yet -- [`Player::subtitle_section`] still
9356+/// lists the flat rows. Ceiling: the model is proven by its tests and by
9357+/// nothing on screen. The upgrade is that section rendering groups instead.
9358+#[derive(Debug, PartialEq)]
9359+#[allow(dead_code)]
9360+struct SubGroup {
9361+ /// What the group is called: the file without its extension, which is what
9362+ /// a person named the film even when the subtitles came out of a remux.
9363+ name: String,
9364+ /// What the swatch is asked by ([`file_tint`]) -- the file, so a subtitle
9365+ /// row and the media rows of the same file wear one colour. `None` from
9366+ /// that lookup for a standalone `.srt`, which is nobody's stream.
9367+ path: PathBuf,
9368+ rows: Vec<SubRow>,
9369+}
9370+
9371+/// One subtitle track, as a row shows it.
9372+#[derive(Debug, PartialEq)]
9373+#[allow(dead_code)]
9374+struct SubRow {
9375+ /// Which track of the session's list this row is: the *flat* index into the
9376+ /// add-order Vec `PlaybackSession::subtitles` hands back, which is what a
9377+ /// click sets `sub_track` to and what a save writes into the `.edith`.
9378+ /// Grouping moves rows around on screen and never touches this number.
9379+ track: usize,
9380+ /// Which of *this file's* tracks it is, counted from 1 -- the numbering
9381+ /// [`row_name`] gives audio streams, for the same reason: two tracks off one
9382+ /// remux that both say "eng" are told apart by nothing else.
9383+ number: usize,
9384+ label: String,
9385+ /// The row's second line ([`subtitle_detail`]).
9386+ detail: String,
9387+ /// Why it cannot be shown, for a track that cannot: the only thing that
9388+ /// greys a row out. Listed all the same -- a picker that hides them is a
9389+ /// picker that lies.
9390+ refused: Option<String>,
9391+ /// Pictures rather than lines ([`engine::subtitle::SubtitleTrack::bitmap`]).
9392+ bitmap: bool,
9393+}
9394+
9395+/// The subtitle list as rows under the file each came out of: one group per
9396+/// distinct path, in the order the files first appear, and each file's tracks
9397+/// in the order they were added. Two remuxes' tracks arriving interleaved --
9398+/// which is what importing a second film does -- still read as two films.
9399+#[allow(dead_code)]
9400+fn subtitle_rows(tracks: &[engine::subtitle::SubtitleTrack]) -> Vec<SubGroup> {
9401+ let mut groups: Vec<SubGroup> = Vec::new();
9402+ for (track, sub) in tracks.iter().enumerate() {
9403+ let group = match groups.iter().position(|g| g.path == sub.path) {
9404+ Some(i) => &mut groups[i],
9405+ None => {
9406+ groups.push(SubGroup {
9407+ name: sub
9408+ .path
9409+ .file_stem()
9410+ .map_or_else(|| file_name(&sub.path), |s| s.to_string_lossy().into()),
9411+ path: sub.path.clone(),
9412+ rows: Vec::new(),
9413+ });
9414+ groups.last_mut().expect("just pushed")
9415+ }
9416+ };
9417+ group.rows.push(SubRow {
9418+ track,
9419+ number: group.rows.len() + 1,
9420+ // A track whose only name is the tag for "nobody said" says that
9421+ // in words, here, rather than showing the tag itself.
9422+ label: lang_human(&sub.label).to_string(),
9423+ detail: subtitle_detail(sub),
9424+ refused: sub.refused.clone(),
9425+ bitmap: sub.is_bitmap(),
9426+ });
9427+ }
9428+ groups
9429+}
9430+
9356 /// Where a cue is drawn on the bed: left edge and width in pixels, through the9431 /// Where a cue is drawn on the bed: left edge and width in pixels, through the
9357 /// same [`Scale`] every clip box goes through -- so a cue and the take it is9432 /// same [`Scale`] every clip box goes through -- so a cue and the take it is
9358 /// spoken over line up at every zoom, which is the only reason the strip is9433 /// spoken over line up at every zoom, which is the only reason the strip is
@@ -9832,7 +9907,7 @@ fn row_name(path: &Path, stream: usize, several: bool) -> String {
9832 fn stream_detail(info: &StreamInfo) -> String {9907 fn stream_detail(info: &StreamInfo) -> String {
9833 let mut parts: Vec<String> = Vec::new();9908 let mut parts: Vec<String> = Vec::new();
9834 if let Some(lang) = &info.lang {9909 if let Some(lang) = &info.lang {
9835- parts.push(lang.clone());9910+ parts.push(lang_human(lang).to_string());
9836 }9911 }
9837 if info.sample_rate > 0 {9912 if info.sample_rate > 0 {
9838 parts.push(format!("{} kHz", f64::from(info.sample_rate) / 1000.));9913 parts.push(format!("{} kHz", f64::from(info.sample_rate) / 1000.));
@@ -9841,6 +9916,17 @@ fn stream_detail(info: &StreamInfo) -> String {
9841 parts.join(" ")9916 parts.join(" ")
9842 }9917 }
9843 9918
9919+/// A language tag as a person reads it. Everything a file writes is passed
9920+/// through untouched bar the one tag that is not a language: "und" is what a
9921+/// muxer writes when nobody said, and a row showing it verbatim names a
9922+/// language nobody speaks.
9923+fn lang_human(lang: &str) -> &str {
9924+ match lang {
9925+ "und" => "unknown language",
9926+ lang => lang,
9927+ }
9928+}
9929+
9844 fn layout(channels: u16) -> Option<String> {9930 fn layout(channels: u16) -> Option<String> {
9845 match channels {9931 match channels {
9846 0 => None,9932 0 => None,
@@ -9911,6 +9997,20 @@ fn source_tint(source: usize) -> u32 {
9911 SOURCE_TINTS[source % SOURCE_TINTS.len()]9997 SOURCE_TINTS[source % SOURCE_TINTS.len()]
9912 }9998 }
9913 9999
10000+/// The tint of a *file*, which is what a library row is named by: the first
10001+/// source entry naming it, since two audio streams of one file are two sources
10002+/// and one colour.
10003+///
10004+/// `None` for a path no source names -- a standalone `.srt` is on nobody's
10005+/// timeline, and painting it with the first file's colour would say it came out
10006+/// of that file. No swatch says what is true: it belongs to itself.
10007+fn file_tint(sources: &[Source], path: &Path) -> Option<u32> {
10008+ sources
10009+ .iter()
10010+ .position(|s| s.path == path)
10011+ .map(source_tint)
10012+}
10013+
9914 /// What the export card offers, top to bottom. Bitrate is the only thing the10014 /// What the export card offers, top to bottom. Bitrate is the only thing the
9915 /// encoder actually takes: the codec and the container are what this program10015 /// encoder actually takes: the codec and the container are what this program
9916 /// can write and nothing else, so the card states them rather than offering10016 /// can write and nothing else, so the card states them rather than offering
@@ -11924,7 +12024,8 @@ mod tests {
11924 };12024 };
11925 use super::{12025 use super::{
11926 SUB_BOTTOM, SUB_CUE_MIN_W, SUB_INK, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, SUB_TEXT, cue_box,12026 SUB_BOTTOM, SUB_CUE_MIN_W, SUB_INK, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, SUB_TEXT, cue_box,
11927- cues_at, is_matroska, is_subtitle, subtitle_detail, subtitle_notice, subtitle_strip_h,12027+ cues_at, file_tint, is_matroska, is_subtitle, lang_human, subtitle_detail, subtitle_notice,
12028+ subtitle_rows, subtitle_strip_h,
11928 };12029 };
11929 12030
11930 /// What the file manager is handed: the parts a path keeps as they are, and12031 /// What the file manager is handed: the parts a path keeps as they are, and
@@ -15909,8 +16010,10 @@ mod tests {
15909 16010
15910 #[test]16011 #[test]
15911 fn source_tints_differ_per_source_and_cycle() {16012 fn source_tints_differ_per_source_and_cycle() {
15912- // The file the session opened with is the unchanged lane colour.16013+ // The bug: the first entry *was* `SURFACE`, so the first file imported
15913- assert_eq!(source_tint(0), SURFACE);16014+ // -- the one every session has -- wore the panel's own background and
16015+ // had no visible swatch at all.
16016+ assert_ne!(source_tint(0), SURFACE);
15914 // Neighbouring sources must not share one, or an import is invisible.16017 // Neighbouring sources must not share one, or an import is invisible.
15915 assert_ne!(source_tint(0), source_tint(1));16018 assert_ne!(source_tint(0), source_tint(1));
15916 assert_ne!(source_tint(1), source_tint(2));16019 assert_ne!(source_tint(1), source_tint(2));
@@ -15921,6 +16024,187 @@ mod tests {
15921 assert_eq!(source_tint(usize::MAX), SOURCE_TINTS[usize::MAX % 4]);16024 assert_eq!(source_tint(usize::MAX), SOURCE_TINTS[usize::MAX % 4]);
15922 }16025 }
15923 16026
16027+ /// Not "they are different numbers" -- different *enough to see*, against
16028+ /// each other and against the surface a swatch is drawn on. The palette is
16029+ /// deliberately dark and low-saturation, so the margin is thin and a new
16030+ /// tint picked by eye can land inside it without anyone noticing.
16031+ #[test]
16032+ fn source_tints_are_all_discernible() {
16033+ // Summed channel distance: `SURFACE` to the warm tint is 18, and that
16034+ // step is the one already accepted as readable on a lane.
16035+ let apart = |a: u32, b: u32| {
16036+ (0..3)
16037+ .map(|i| {
16038+ let shift = i * 8;
16039+ ((a >> shift) & 0xff).abs_diff((b >> shift) & 0xff)
16040+ })
16041+ .sum::<u32>()
16042+ };
16043+ for (i, &tint) in SOURCE_TINTS.iter().enumerate() {
16044+ assert!(
16045+ apart(tint, SURFACE) >= 16,
16046+ "tint {i} is {} from the panel it sits on",
16047+ apart(tint, SURFACE)
16048+ );
16049+ for (j, &other) in SOURCE_TINTS.iter().enumerate().skip(i + 1) {
16050+ assert!(
16051+ apart(tint, other) >= 16,
16052+ "tints {i} and {j} are only {} apart",
16053+ apart(tint, other)
16054+ );
16055+ }
16056+ }
16057+ // The two a person sees side by side first must be further apart than
16058+ // the floor: source 0 and source 1 are the first import and the second.
16059+ assert!(apart(SOURCE_TINTS[0], SOURCE_TINTS[1]) >= 32);
16060+ }
16061+
16062+ /// A `.srt` dropped on the window is nobody's stream: it has no source
16063+ /// entry, and the lookup that used to fall back to index 0 painted it with
16064+ /// the first file's colour -- a swatch saying it came out of a film it
16065+ /// never touched.
16066+ #[test]
16067+ fn a_standalone_subtitle_wears_no_file_tint() {
16068+ let sources = [
16069+ Source {
16070+ path: PathBuf::from("/films/a.mkv"),
16071+ audio_stream: 0,
16072+ },
16073+ Source {
16074+ path: PathBuf::from("/films/b.mp4"),
16075+ audio_stream: 0,
16076+ },
16077+ // A second stream of the first file is a second source and the
16078+ // same colour.
16079+ Source {
16080+ path: PathBuf::from("/films/a.mkv"),
16081+ audio_stream: 1,
16082+ },
16083+ ];
16084+ assert_eq!(
16085+ file_tint(&sources, Path::new("/films/a.mkv")),
16086+ Some(source_tint(0))
16087+ );
16088+ assert_eq!(
16089+ file_tint(&sources, Path::new("/films/b.mp4")),
16090+ Some(source_tint(1))
16091+ );
16092+ assert_eq!(file_tint(&sources, Path::new("/subs/a.eng.srt")), None);
16093+ assert_eq!(file_tint(&[], Path::new("/films/a.mkv")), None);
16094+ }
16095+
16096+ fn sub(path: &str, track: Option<u64>, label: &str) -> engine::subtitle::SubtitleTrack {
16097+ engine::subtitle::SubtitleTrack {
16098+ path: PathBuf::from(path),
16099+ track,
16100+ label: label.to_string(),
16101+ cues: Vec::new(),
16102+ bitmap: false,
16103+ refused: None,
16104+ }
16105+ }
16106+
16107+ /// The list is in the order tracks were added, which is not the order a
16108+ /// person reads it in: importing a second film puts its tracks after the
16109+ /// first film's, and importing a third `.srt` for the first film puts that
16110+ /// one last of all. The rows still read as three sources.
16111+ #[test]
16112+ fn subtitle_rows_group_a_source_however_they_were_added() {
16113+ let tracks = [
16114+ sub("/films/a.mkv", Some(1), "eng"),
16115+ sub("/films/b.mkv", Some(1), "eng"),
16116+ sub("/films/a.mkv", Some(2), "fre"),
16117+ sub("/subs/late.srt", None, "late.srt"),
16118+ sub("/films/b.mkv", Some(3), "ger"),
16119+ ];
16120+ let groups = subtitle_rows(&tracks);
16121+ assert_eq!(
16122+ groups.iter().map(|g| g.name.as_str()).collect::<Vec<_>>(),
16123+ ["a", "b", "late"],
16124+ "one group per file, in the order the files first appear"
16125+ );
16126+ assert_eq!(
16127+ groups
16128+ .iter()
16129+ .map(|g| g.rows.iter().map(|r| r.label.as_str()).collect::<Vec<_>>())
16130+ .collect::<Vec<_>>(),
16131+ [vec!["eng", "fre"], vec!["eng", "ger"], vec!["late.srt"]],
16132+ "a file's tracks are contiguous and in add order"
16133+ );
16134+ // Numbered within the file, the way `row_name` numbers audio streams:
16135+ // two tracks that both say "eng" are told apart by nothing else.
16136+ assert_eq!(
16137+ groups
16138+ .iter()
16139+ .map(|g| g.rows.iter().map(|r| r.number).collect::<Vec<_>>())
16140+ .collect::<Vec<_>>(),
16141+ [vec![1, 2], vec![1, 2], vec![1]]
16142+ );
16143+ // The swatch key is the file, so a group and that file's media rows
16144+ // wear one colour -- and the standalone one has none.
16145+ let sources = [Source {
16146+ path: PathBuf::from("/films/a.mkv"),
16147+ audio_stream: 0,
16148+ }];
16149+ assert_eq!(
16150+ file_tint(&sources, &groups[0].path),
16151+ Some(source_tint(0)),
16152+ "the group carries the path the tint is asked by"
16153+ );
16154+ assert_eq!(file_tint(&sources, &groups[2].path), None);
16155+ }
16156+
16157+ /// 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 the
16159+ /// `.edith`. Every row must still name the track it was made from -- rows
16160+ /// for refused tracks included, because they take a number in that list
16161+ /// whether or not anyone can pick them.
16162+ #[test]
16163+ fn a_subtitle_row_names_the_flat_track_it_was_made_from() {
16164+ let mut tracks = vec![
16165+ sub("/films/a.mkv", Some(1), "eng"),
16166+ sub("/films/b.mkv", Some(1), "eng"),
16167+ sub("/films/a.mkv", Some(2), "fre"),
16168+ ];
16169+ // Track 1 of b is pictures: still a row, still index 1 of the list.
16170+ tracks[1].bitmap = true;
16171+ tracks[1].refused = Some("PGS subtitles are pictures".to_string());
16172+ let groups = subtitle_rows(&tracks);
16173+ let flat: Vec<(usize, &str)> = groups
16174+ .iter()
16175+ .flat_map(|g| g.rows.iter().map(|r| (r.track, r.label.as_str())))
16176+ .collect();
16177+ assert_eq!(flat, [(0, "eng"), (2, "fre"), (1, "eng")]);
16178+ for (track, label) in flat {
16179+ assert_eq!(
16180+ tracks[track].label, label,
16181+ "row {track} picks the track it names"
16182+ );
16183+ }
16184+ // (c) The refused one is here, saying why, and greyable by that alone.
16185+ let refused = &groups[1].rows[0];
16186+ assert_eq!(
16187+ refused.refused.as_deref(),
16188+ Some("PGS subtitles are pictures")
16189+ );
16190+ assert_eq!(refused.detail, "PGS subtitles are pictures");
16191+ assert!(refused.bitmap);
16192+ // ...and it was counted: the row after it in add order is still 2.
16193+ assert_eq!(groups[0].rows[1].track, 2);
16194+ }
16195+
16196+ /// "und" is what a muxer writes when nobody said what the language is. A
16197+ /// row showing it verbatim names a language nobody speaks.
16198+ #[test]
16199+ fn an_untagged_language_says_it_is_unknown() {
16200+ assert_eq!(lang_human("und"), "unknown language");
16201+ assert_eq!(lang_human("eng"), "eng");
16202+ assert_eq!(lang_human("fre — Commentary"), "fre — Commentary");
16203+ // Reaching the subtitle rows too: a track whose only name was the tag.
16204+ let groups = subtitle_rows(&[sub("/films/a.mkv", Some(1), "und")]);
16205+ assert_eq!(groups[0].rows[0].label, "unknown language");
16206+ }
16207+
15924 /// The bug: an empty timeline is end-of-stream from its one black frame16208 /// The bug: an empty timeline is end-of-stream from its one black frame
15925 /// onward, so the pump had `done` set before anything was ever pressed --16209 /// onward, so the pump had `done` set before anything was ever pressed --
15926 /// and the transport's restart branch read that as "played out, start from16210 /// and the transport's restart branch read that as "played out, start from