✨ merge(T15): export card speaks plainly — grouped rows, live summary, honest refusals
Browse files at this commit2 changed files +872 -286
- crates/app/src/keymap.rs +33 -4
- crates/app/src/main.rs +839 -282
crates/app/src/keymap.rsmodified+33 -4
| @@ -326,7 +326,7 @@ pub struct Fixed { | |||
| 326 | pub category: Category, | 326 | pub category: Category, |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | -pub const FIXED: [Fixed; 16] = [ | 329 | +pub const FIXED: [Fixed; 21] = [ |
| 330 | // Not a chord at all but a way of pressing one, and the only place the | 330 | // Not a chord at all but a way of pressing one, and the only place the |
| 331 | // editor can say so: holding a key that moves a *value* runs it, and | 331 | // editor can say so: holding a key that moves a *value* runs it, and |
| 332 | // holding anything else still does what one press did. | 332 | // holding anything else still does what one press did. |
| @@ -346,9 +346,38 @@ pub const FIXED: [Fixed; 16] = [ | |||
| 346 | category: Category::File, | 346 | category: Category::File, |
| 347 | }, | 347 | }, |
| 348 | Fixed { | 348 | Fixed { |
| 349 | - chord: "m / a / v / h / x / w / f / p", | 349 | + chord: "m / a / h / w / f / p", |
| 350 | - label: "Pick the export format: MP4, AV1 in MKV, AV1 in MP4, HEVC in MKV, \ | 350 | + label: "Pick the export codec: H.264, AV1, HEVC, WAV, FLAC or MP3", |
| 351 | - HEVC in MP4, WAV, FLAC or MP3", | 351 | + category: Category::File, |
| 352 | + }, | ||
| 353 | + // The rest of the export card's own rows, each on the letter its row is | ||
| 354 | + // named after. They shadow the clip keys of the same letter while the card | ||
| 355 | + // is up, exactly as its digits shadow nothing and its arrows would: a modal | ||
| 356 | + // card owns the keyboard, and cutting a clip under it is not a thing that | ||
| 357 | + // can happen anyway. | ||
| 358 | + Fixed { | ||
| 359 | + chord: "c", | ||
| 360 | + label: "Switch the export container: Matroska or MP4", | ||
| 361 | + category: Category::File, | ||
| 362 | + }, | ||
| 363 | + Fixed { | ||
| 364 | + chord: "q", | ||
| 365 | + label: "Step through the export quality rows", | ||
| 366 | + category: Category::File, | ||
| 367 | + }, | ||
| 368 | + Fixed { | ||
| 369 | + chord: "d", | ||
| 370 | + label: "Choose where the export is written", | ||
| 371 | + category: Category::File, | ||
| 372 | + }, | ||
| 373 | + Fixed { | ||
| 374 | + chord: "g", | ||
| 375 | + label: "Export card: sections or one flat list", | ||
| 376 | + category: Category::File, | ||
| 377 | + }, | ||
| 378 | + Fixed { | ||
| 379 | + chord: "r", | ||
| 380 | + label: "Export card: the formats with no encoder as rows or as one line", | ||
| 352 | category: Category::File, | 381 | category: Category::File, |
| 353 | }, | 382 | }, |
| 354 | Fixed { | 383 | Fixed { |
crates/app/src/main.rsmodified+839 -282
| @@ -117,10 +117,28 @@ const KEYS_ROW_H: f32 = HIT_MIN; | |||
| 117 | /// keeps the card inside the smallest window no matter how many actions the | 117 | /// keeps the card inside the smallest window no matter how many actions the |
| 118 | /// editor grows -- ten rows fit here, and the eleventh is a scroll away. | 118 | /// editor grows -- ten rows fit here, and the eleventh is a scroll away. |
| 119 | const KEYS_ROWS_H: f32 = 10. * KEYS_ROW_H; | 119 | const KEYS_ROWS_H: f32 = 10. * KEYS_ROW_H; |
| 120 | -/// The same for the export card, which carries a fixed-format line and a button | 120 | +/// The same for the export card, which carries two summary lines and a button |
| 121 | -/// under its list and so has less room: destination, ten formats and five | 121 | +/// under its list and so has less room: a section header, six codecs, the |
| 122 | -/// qualities are fifteen rows, eight of them on screen. | 122 | +/// container, five qualities and the destination are more rows than a 360 px |
| 123 | +/// window holds. Eight on screen, which is the whole format section and its | ||
| 124 | +/// header -- what a user picks first is never behind a scroll. | ||
| 123 | const EXPORT_ROWS_H: f32 = 8. * KEYS_ROW_H; | 125 | const EXPORT_ROWS_H: f32 = 8. * KEYS_ROW_H; |
| 126 | +/// The export card is wider than the keybindings one: its rows carry a key, a | ||
| 127 | +/// name *and* what the choice means, and the two summary lines under them state | ||
| 128 | +/// the whole file. At `KEYS_W` every one of those wrapped to two lines, which is | ||
| 129 | +/// the card the user called unfriendly. Still inside the 640 px floor with the | ||
| 130 | +/// scrim showing either side of it. | ||
| 131 | +const EXPORT_W: f32 = 420.; | ||
| 132 | +/// The column the key of a row is printed in, wide enough for `0–9`: every row | ||
| 133 | +/// in the export card says what picks it, so the card is drivable by keyboard | ||
| 134 | +/// without a legend to memorise. | ||
| 135 | +const EXPORT_KEY_W: f32 = 26.; | ||
| 136 | +/// Everything in the export card that is *not* the row list: the title, the | ||
| 137 | +/// status line, the head and tail of the summary, the button, the gaps between | ||
| 138 | +/// them and the padding around the lot. What the list may be is the window | ||
| 139 | +/// minus this -- and never less than [`EXPORT_ROWS_H`], which is the number | ||
| 140 | +/// that makes the card fit the 360 px floor. | ||
| 141 | +const EXPORT_FIXED_H: f32 = 17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.; | ||
| 124 | /// The menu a right-click on a clip opens: wide enough for the longest label | 142 | /// The menu a right-click on a clip opens: wide enough for the longest label |
| 125 | /// beside the stroke that does the same thing, with the click targets `HIT_MIN` | 143 | /// beside the stroke that does the same thing, with the click targets `HIT_MIN` |
| 126 | /// binds like every other list here. | 144 | /// binds like every other list here. |
| @@ -725,6 +743,15 @@ struct Player { | |||
| 725 | /// time -- opening either closes the other, since both are the whole window | 743 | /// time -- opening either closes the other, since both are the whole window |
| 726 | /// and two stacked scrims say nothing about which one is listening. | 744 | /// and two stacked scrims say nothing about which one is listening. |
| 727 | export_open: bool, | 745 | export_open: bool, |
| 746 | + /// How the card lays its rows out, and where the formats this program | ||
| 747 | + /// cannot write are said. Two shapes of the same card, kept behind `g` and | ||
| 748 | + /// `r` so the choice between them can be made by looking at both rather | ||
| 749 | + /// than by argument: sections with headers against one flat list, and a | ||
| 750 | + /// collapsed "cannot write" footer against a dimmed row each. The defaults | ||
| 751 | + /// are grouped and collapsed -- the five dead rows used to eat the fold. | ||
| 752 | + /// Not persisted: this is a look, not a setting. | ||
| 753 | + export_grouped: bool, | ||
| 754 | + export_refusals_inline: bool, | ||
| 728 | /// Which quality row the card has picked, and the megabits typed against | 755 | /// Which quality row the card has picked, and the megabits typed against |
| 729 | /// the custom one. Kept across closes, so a second export offers what the | 756 | /// the custom one. Kept across closes, so a second export offers what the |
| 730 | /// first one chose. | 757 | /// first one chose. |
| @@ -3212,6 +3239,38 @@ impl Player { | |||
| 3212 | self.export_path = retarget(&self.export_path, format); | 3239 | self.export_path = retarget(&self.export_path, format); |
| 3213 | } | 3240 | } |
| 3214 | 3241 | ||
| 3242 | + /// The container row: the same codec in the other box, which retargets the | ||
| 3243 | + /// destination exactly as picking a codec does -- and does nothing at all | ||
| 3244 | + /// for a codec with only one box, so the stroke cannot invent a choice the | ||
| 3245 | + /// card is not offering. | ||
| 3246 | + fn cycle_container(&mut self) { | ||
| 3247 | + self.set_format(next_container(self.format)); | ||
| 3248 | + } | ||
| 3249 | + | ||
| 3250 | + /// The quality rows by keyboard, wrapping. Refused by name where the format | ||
| 3251 | + /// has no bitrate to pick: a key that silently does nothing is the card | ||
| 3252 | + /// looking broken. | ||
| 3253 | + fn cycle_quality(&mut self) { | ||
| 3254 | + if let Some(why) = bitrate_refusal(self.format) { | ||
| 3255 | + self.notice = Some(why.into()); | ||
| 3256 | + return; | ||
| 3257 | + } | ||
| 3258 | + let at = Quality::ALL | ||
| 3259 | + .iter() | ||
| 3260 | + .position(|&q| q == self.quality) | ||
| 3261 | + .unwrap_or(0); | ||
| 3262 | + self.quality = Quality::ALL[(at + 1) % Quality::ALL.len()]; | ||
| 3263 | + } | ||
| 3264 | + | ||
| 3265 | + /// The custom bitrate by pointer: the typed digits were the only control in | ||
| 3266 | + /// this card a mouse could not reach. Clamped to the range the row states | ||
| 3267 | + /// (the engine's own 1..20 Mbps), and picking the row is part of the step -- | ||
| 3268 | + /// a stepper that moves a number nobody is using would move nothing. | ||
| 3269 | + fn nudge_mbps(&mut self, step: i32) { | ||
| 3270 | + self.custom_mbps = (self.custom_mbps as i32 + step).clamp(1, 20) as u32; | ||
| 3271 | + self.quality = Quality::Custom; | ||
| 3272 | + } | ||
| 3273 | + | ||
| 3215 | /// The card's Destination row: the desktop's save dialog, on a background | 3274 | /// The card's Destination row: the desktop's save dialog, on a background |
| 3216 | /// thread like the import chooser -- the user may sit in it and the window | 3275 | /// thread like the import chooser -- the user may sit in it and the window |
| 3217 | /// behind must not freeze. No chooser at all leaves the default path, which | 3276 | /// behind must not freeze. No chooser at all leaves the default path, which |
| @@ -3450,16 +3509,35 @@ impl Render for Player { | |||
| 3450 | // The card's own button, by keyboard: the one thing in | 3509 | // The card's own button, by keyboard: the one thing in |
| 3451 | // it that writes a file must not be pointer-only either. | 3510 | // it that writes a file must not be pointer-only either. |
| 3452 | this.start_export(cx); | 3511 | this.start_export(cx); |
| 3453 | - } else if let Some(format) = format_key(key) { | 3512 | + } else if let Some(format) = format_key(key, this.format) { |
| 3454 | - // The format rows by their initial, so the card can be | 3513 | + // The codec rows by their own letter, so the card can be |
| 3455 | // driven without a mouse -- the same card-local input | 3514 | // driven without a mouse -- the same card-local input |
| 3456 | // the typed bitrate is, and for the same reason: a | 3515 | // the typed bitrate is, and for the same reason: a |
| 3457 | // choice reachable only by pointer is not reachable by | 3516 | // choice reachable only by pointer is not reachable by |
| 3458 | // everyone. Not a keymap binding: it means nothing | 3517 | // everyone. Not a keymap binding: it means nothing |
| 3459 | // outside this card, exactly like the digits. | 3518 | // outside this card, exactly like the digits. |
| 3460 | this.set_format(format); | 3519 | this.set_format(format); |
| 3520 | + } else if key == "c" { | ||
| 3521 | + this.cycle_container(); | ||
| 3522 | + } else if key == "q" { | ||
| 3523 | + this.cycle_quality(); | ||
| 3524 | + } else if key == "d" { | ||
| 3525 | + // The save dialog, which was the one row here a | ||
| 3526 | + // keyboard could not open. | ||
| 3527 | + this.pick_destination(cx); | ||
| 3528 | + } else if key == "g" { | ||
| 3529 | + this.export_grouped = !this.export_grouped; | ||
| 3530 | + } else if key == "r" { | ||
| 3531 | + this.export_refusals_inline = !this.export_refusals_inline; | ||
| 3461 | } else if let Ok(digit) = key.parse::<u32>() { | 3532 | } else if let Ok(digit) = key.parse::<u32>() { |
| 3462 | - this.custom_mbps = push_digit(this.custom_mbps, digit); | 3533 | + let next = push_digit(this.custom_mbps, digit); |
| 3534 | + // A refused third digit says so: it used to be dropped | ||
| 3535 | + // in silence, which left the card showing a number the | ||
| 3536 | + // user had already typed past. | ||
| 3537 | + if next == this.custom_mbps && this.custom_mbps > 0 { | ||
| 3538 | + this.notice = Some("1–20 Mbps — a third digit is refused".into()); | ||
| 3539 | + } | ||
| 3540 | + this.custom_mbps = next; | ||
| 3463 | this.quality = Quality::Custom; | 3541 | this.quality = Quality::Custom; |
| 3464 | } else if key == "backspace" { | 3542 | } else if key == "backspace" { |
| 3465 | this.custom_mbps /= 10; | 3543 | this.custom_mbps /= 10; |
| @@ -3816,7 +3894,7 @@ impl Render for Player { | |||
| 3816 | // Last, so they are over everything -- they take no room in the | 3894 | // Last, so they are over everything -- they take no room in the |
| 3817 | // column, and only one of the two is ever up. | 3895 | // column, and only one of the two is ever up. |
| 3818 | .children(self.keys_overlay(cx)) | 3896 | .children(self.keys_overlay(cx)) |
| 3819 | - .children(self.export_card(cx)) | 3897 | + .children(self.export_card(window.viewport_size(), cx)) |
| 3820 | .children(self.eq_card(cx)) | 3898 | .children(self.eq_card(cx)) |
| 3821 | .children(self.color_card(cx)) | 3899 | .children(self.color_card(cx)) |
| 3822 | .children(self.speed_card(cx)) | 3900 | .children(self.speed_card(cx)) |
| @@ -4799,16 +4877,33 @@ impl Player { | |||
| 4799 | ) | 4877 | ) |
| 4800 | } | 4878 | } |
| 4801 | 4879 | ||
| 4802 | - /// What an export is going to be, before there is one: the destination, the | 4880 | + /// What an export is going to be, before there is one: the codec, the box |
| 4803 | - /// quality rows, and the two things that are not a choice at all. The same | 4881 | + /// it goes into, the bitrate, where it lands -- and, above the button, the |
| 4804 | - /// scrim, width and row shape as the keybindings overlay -- two cards of | 4882 | + /// two lines that state the file all of that adds up to. The same scrim and |
| 4805 | - /// different builds over one window read as two different programs -- and | 4883 | + /// row shape as the keybindings overlay (two cards of different builds over |
| 4806 | - /// the same plain divs, so the root keeps the keyboard and a typed digit | 4884 | + /// one window read as two different programs) and the same plain divs, so |
| 4807 | - /// reaches the custom row. | 4885 | + /// the root keeps the keyboard and a typed digit reaches the custom row. |
| 4808 | - fn export_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | 4886 | + /// |
| 4887 | + /// Every row carries the key that picks it, so the card is drivable end to | ||
| 4888 | + /// end without a pointer *and* without a legend to memorise -- and every | ||
| 4889 | + /// row is clickable, the bitrate's steppers included, so it is drivable end | ||
| 4890 | + /// to end without a keyboard as well. | ||
| 4891 | + /// | ||
| 4892 | + /// Two shapes of it, behind `g` and `r`: sections against one flat list, | ||
| 4893 | + /// and the codecs with no encoder collapsed into a footer against a dimmed | ||
| 4894 | + /// row each. Grouped and collapsed is what opens. | ||
| 4895 | + fn export_card( | ||
| 4896 | + &self, | ||
| 4897 | + viewport: Size<Pixels>, | ||
| 4898 | + cx: &mut Context<Self>, | ||
| 4899 | + ) -> Option<impl IntoElement> { | ||
| 4809 | if !self.export_open { | 4900 | if !self.export_open { |
| 4810 | return None; | 4901 | return None; |
| 4811 | } | 4902 | } |
| 4903 | + // The cap is what keeps the card inside the smallest window; a taller | ||
| 4904 | + // one gets a taller list rather than a scroll past empty space, and the | ||
| 4905 | + // card is still only as tall as the rows it has. | ||
| 4906 | + let rows_h = (f32::from(viewport.height) - EXPORT_FIXED_H - 24.).max(EXPORT_ROWS_H); | ||
| 4812 | let row = |id: (&'static str, usize)| { | 4907 | let row = |id: (&'static str, usize)| { |
| 4813 | div() | 4908 | div() |
| 4814 | .id(id) | 4909 | .id(id) |
| @@ -4825,70 +4920,261 @@ impl Player { | |||
| 4825 | // A row that cannot be picked is dimmed and takes no click, exactly as | 4920 | // A row that cannot be picked is dimmed and takes no click, exactly as |
| 4826 | // an inapplicable item in the clip menu is: it still says its piece. | 4921 | // an inapplicable item in the clip menu is: it still says its piece. |
| 4827 | let live = |d: Stateful<Div>, enabled: bool| { | 4922 | let live = |d: Stateful<Div>, enabled: bool| { |
| 4828 | - d.when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | 4923 | + d.when(!enabled, |d| { |
| 4829 | - .when(enabled, |d| d.cursor_pointer().hover(|s| s.bg(rgb(HOVER)))) | 4924 | + d.cursor_not_allowed().text_color(rgb(INK_DIM)) |
| 4925 | + }) | ||
| 4926 | + .when(enabled, |d| d.cursor_pointer().hover(|s| s.bg(rgb(HOVER)))) | ||
| 4830 | }; | 4927 | }; |
| 4831 | - // The formats first: the quality rows below are *video* bitrate, so | 4928 | + // A row as this card writes them: the mark saying which one is picked, |
| 4832 | - // which file is being written decides whether they mean anything. | 4929 | + // the key that picks it, its name, and what the choice means. The mark |
| 4833 | - // An mp4 this timeline cannot be written as reads exactly like the | 4930 | + // is a glyph and not only a colour -- a background alone is gone the |
| 4834 | - // formats there is no encoder for: dimmed, unclickable, and carrying its | 4931 | + // moment a hover lands on the row, and invisible to anyone who cannot |
| 4835 | - // own reason instead of the detail line. | 4932 | + // tell the two greys apart (WCAG 1.4.1). |
| 4836 | - let formats: Vec<_> = FORMATS | 4933 | + let entry = |id: (&'static str, usize), |
| 4837 | - .into_iter() | 4934 | + key: &str, |
| 4838 | - .enumerate() | 4935 | + label: SharedString, |
| 4839 | - .map(|(i, (format, _, label, detail))| { | 4936 | + detail: SharedString, |
| 4840 | - // Per row, because the two picture formats are refused by | 4937 | + picked: bool, |
| 4841 | - // different things: an audio-only timeline greys both, a second | 4938 | + enabled: bool| { |
| 4842 | - // audio lane only the mp4. | 4939 | + // The small print of a picked row sits on the highlight, where the |
| 4843 | - let refused = format | 4940 | + // dim ink is only 3.3:1 -- the row it lands on lifts it (WCAG |
| 4844 | - .zip(self.session.as_ref()) | 4941 | + // 1.4.3, and the fit test pins both numbers). |
| 4845 | - .and_then(|(f, s)| format_refusal(s, f)); | 4942 | + let ink = match picked { |
| 4846 | - let blocked = refused.is_some(); | 4943 | + true => INK, |
| 4847 | - let detail: SharedString = match &refused { | 4944 | + false => INK_DIM, |
| 4848 | - Some(why) => why.clone().into(), | 4945 | + }; |
| 4849 | - None => detail.into(), | 4946 | + live(row(id), enabled) |
| 4850 | - }; | 4947 | + .when(picked, |d| d.bg(rgb(SELECTED))) |
| 4851 | - let picked = format == Some(self.format) && !blocked; | 4948 | + .child( |
| 4852 | - let format = format.filter(|_| !blocked); | 4949 | + div() |
| 4853 | - live(row(("format", i)), format.is_some()) | 4950 | + .flex() |
| 4854 | - .when(picked, |d| d.bg(rgb(SELECTED))) | 4951 | + .flex_none() |
| 4855 | - .when_some(format, |d, format| { | 4952 | + .items_center() |
| 4856 | - d.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 4953 | + .gap(px(8.)) |
| 4857 | - this.set_format(format); | 4954 | + .child(div().w(px(10.)).child(match picked { |
| 4858 | - cx.notify(); | 4955 | + true => "✓", |
| 4956 | + false => " ", | ||
| 4859 | })) | 4957 | })) |
| 4860 | - }) | 4958 | + .child( |
| 4861 | - .child(label) | 4959 | + div() |
| 4862 | - .child( | 4960 | + .w(px(EXPORT_KEY_W)) |
| 4863 | - div() | 4961 | + .text_size(px(11.)) |
| 4864 | - .text_size(px(11.)) | 4962 | + .text_color(rgb(ink)) |
| 4865 | - .text_color(rgb(INK_DIM)) | 4963 | + .child(SharedString::from(key.to_string())), |
| 4866 | - .child(detail), | 4964 | + ) |
| 4965 | + .child(label), | ||
| 4966 | + ) | ||
| 4967 | + // Wraps rather than runs off the row: a refusal is the longest | ||
| 4968 | + // thing in this column and the half of it past the edge is the | ||
| 4969 | + // half that says what to do instead. | ||
| 4970 | + .child( | ||
| 4971 | + div() | ||
| 4972 | + .min_w(px(0.)) | ||
| 4973 | + .flex_shrink() | ||
| 4974 | + .text_size(px(11.)) | ||
| 4975 | + .text_color(rgb(ink)) | ||
| 4976 | + .child(detail), | ||
| 4977 | + ) | ||
| 4978 | + }; | ||
| 4979 | + let header = |text: &'static str| { | ||
| 4980 | + div() | ||
| 4981 | + .flex_none() | ||
| 4982 | + .px(px(6.)) | ||
| 4983 | + .pt(px(4.)) | ||
| 4984 | + .text_size(px(10.)) | ||
| 4985 | + .text_color(rgb(INK_DIM)) | ||
| 4986 | + .child(text) | ||
| 4987 | + .into_any_element() | ||
| 4988 | + }; | ||
| 4989 | + let mut list: Vec<AnyElement> = Vec::new(); | ||
| 4990 | + if self.export_grouped { | ||
| 4991 | + list.push(header("FORMAT")); | ||
| 4992 | + } | ||
| 4993 | + // The codecs first: which one is being written decides whether every | ||
| 4994 | + // row under it means anything. One a *this* timeline cannot be written | ||
| 4995 | + // as (an audio-only edit, for a picture codec) reads exactly like one | ||
| 4996 | + // there is no encoder for -- dimmed, unclickable, and carrying its own | ||
| 4997 | + // reason where its detail was, with nothing to click to find that out. | ||
| 4998 | + let mut refusals: Vec<String> = Vec::new(); | ||
| 4999 | + for (i, (boxes, key, label, detail)) in FORMATS.into_iter().enumerate() { | ||
| 5000 | + let format = same_box(boxes, self.format); | ||
| 5001 | + let refused = format | ||
| 5002 | + .zip(self.session.as_ref()) | ||
| 5003 | + .and_then(|(f, s)| format_refusal(s, f)); | ||
| 5004 | + // A codec with no encoder here at all is the other kind of refusal, | ||
| 5005 | + // and the one the footer collects: it can never become pickable, so | ||
| 5006 | + // a row each is dead rows above the fold. | ||
| 5007 | + if format.is_none() { | ||
| 5008 | + refusals.push(format!("{label} — {detail}")); | ||
| 5009 | + if !self.export_refusals_inline { | ||
| 5010 | + continue; | ||
| 5011 | + } | ||
| 5012 | + } | ||
| 5013 | + let detail: SharedString = match &refused { | ||
| 5014 | + Some(why) => why.clone().into(), | ||
| 5015 | + None => detail.into(), | ||
| 5016 | + }; | ||
| 5017 | + let format = format.filter(|_| refused.is_none()); | ||
| 5018 | + let mut r = entry( | ||
| 5019 | + ("format", i), | ||
| 5020 | + key, | ||
| 5021 | + label.into(), | ||
| 5022 | + detail, | ||
| 5023 | + boxes.contains(&self.format), | ||
| 5024 | + format.is_some(), | ||
| 5025 | + ); | ||
| 5026 | + if let Some(format) = format { | ||
| 5027 | + r = r.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 5028 | + this.set_format(format); | ||
| 5029 | + cx.notify(); | ||
| 5030 | + })); | ||
| 5031 | + } | ||
| 5032 | + list.push(r.into_any_element()); | ||
| 5033 | + } | ||
| 5034 | + if self.export_grouped { | ||
| 5035 | + list.push(header("DETAILS")); | ||
| 5036 | + } | ||
| 5037 | + // The container, and only where the picked codec has more than one box: | ||
| 5038 | + // a row offering a single choice reads as a choice. | ||
| 5039 | + let boxes = containers(self.format); | ||
| 5040 | + if boxes.len() > 1 { | ||
| 5041 | + let next = next_container(self.format); | ||
| 5042 | + list.push( | ||
| 5043 | + entry( | ||
| 5044 | + ("container", 0), | ||
| 5045 | + "c", | ||
| 5046 | + "Container".into(), | ||
| 5047 | + format!( | ||
| 5048 | + "{} — c for {}", | ||
| 5049 | + self.format.ext().to_uppercase(), | ||
| 5050 | + next.ext().to_uppercase() | ||
| 4867 | ) | 5051 | ) |
| 4868 | - }) | 5052 | + .into(), |
| 4869 | - .collect(); | 5053 | + false, |
| 4870 | - let video = self.format.has_video(); | 5054 | + true, |
| 4871 | - let rows: Vec<_> = Quality::ALL | 5055 | + ) |
| 4872 | - .into_iter() | 5056 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { |
| 4873 | - .enumerate() | 5057 | + this.cycle_container(); |
| 4874 | - .map(|(i, quality)| { | 5058 | + cx.notify(); |
| 4875 | - live(row(("quality", i)), video) | 5059 | + })) |
| 4876 | - .when(video && self.quality == quality, |d| d.bg(rgb(SELECTED))) | 5060 | + .into_any_element(), |
| 4877 | - .when(video, |d| { | 5061 | + ); |
| 4878 | - d.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 5062 | + } |
| 5063 | + match bitrate_refusal(self.format) { | ||
| 5064 | + // One dimmed row carrying the reason, rather than five rows of a | ||
| 5065 | + // figure that will not be written: the quality rows are the | ||
| 5066 | + // *picture's* bitrate, and this file has no picture in it. | ||
| 5067 | + Some(why) => list.push( | ||
| 5068 | + entry( | ||
| 5069 | + ("quality", 0), | ||
| 5070 | + "q", | ||
| 5071 | + "Quality".into(), | ||
| 5072 | + why.into(), | ||
| 5073 | + false, | ||
| 5074 | + false, | ||
| 5075 | + ) | ||
| 5076 | + .into_any_element(), | ||
| 5077 | + ), | ||
| 5078 | + None => { | ||
| 5079 | + for (i, quality) in Quality::ALL.into_iter().enumerate() { | ||
| 5080 | + let mut r = entry( | ||
| 5081 | + ("quality", i), | ||
| 5082 | + match quality { | ||
| 5083 | + // The one row a key does not step to but types | ||
| 5084 | + // into, which is what its key column says. | ||
| 5085 | + Quality::Custom => "0–9", | ||
| 5086 | + _ => "q", | ||
| 5087 | + }, | ||
| 5088 | + quality.label().into(), | ||
| 5089 | + quality.detail(self.custom_mbps).into(), | ||
| 5090 | + self.quality == quality, | ||
| 5091 | + true, | ||
| 5092 | + ) | ||
| 5093 | + .on_click(cx.listener( | ||
| 5094 | + move |this, _: &ClickEvent, _, cx| { | ||
| 4879 | this.quality = quality; | 5095 | this.quality = quality; |
| 4880 | cx.notify(); | 5096 | cx.notify(); |
| 4881 | - })) | 5097 | + }, |
| 4882 | - }) | 5098 | + )); |
| 4883 | - .child(quality.label()) | 5099 | + if quality == Quality::Custom { |
| 4884 | - .child( | 5100 | + r = r.child(self.mbps_steppers(cx)); |
| 4885 | - div() | 5101 | + } |
| 4886 | - .text_size(px(11.)) | 5102 | + list.push(r.into_any_element()); |
| 4887 | - .text_color(rgb(INK_DIM)) | 5103 | + } |
| 4888 | - .child(quality.detail(self.custom_mbps)), | 5104 | + } |
| 4889 | - ) | 5105 | + } |
| 4890 | - }) | 5106 | + let destination = entry( |
| 4891 | - .collect(); | 5107 | + ("destination", 0), |
| 5108 | + "d", | ||
| 5109 | + "Destination".into(), | ||
| 5110 | + file_name(&self.export_path).into(), | ||
| 5111 | + false, | ||
| 5112 | + true, | ||
| 5113 | + ) | ||
| 5114 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))) | ||
| 5115 | + .into_any_element(); | ||
| 5116 | + match self.export_grouped { | ||
| 5117 | + true => list.push(destination), | ||
| 5118 | + // Flat: the same rows with no headers over them, and the | ||
| 5119 | + // destination back at the top where the card used to open with it. | ||
| 5120 | + false => list.insert(0, destination), | ||
| 5121 | + } | ||
| 5122 | + if !self.export_refusals_inline && !refusals.is_empty() { | ||
| 5123 | + // Last, and one line: the reason travels with the name (a footer | ||
| 5124 | + // that only listed them would be the "why not?" the rows exist to | ||
| 5125 | + // answer), but nothing here can ever be picked, so it sits under | ||
| 5126 | + // every row that can rather than above them. | ||
| 5127 | + list.push( | ||
| 5128 | + div() | ||
| 5129 | + .flex_none() | ||
| 5130 | + .px(px(6.)) | ||
| 5131 | + .py(px(2.)) | ||
| 5132 | + .text_size(px(11.)) | ||
| 5133 | + .text_color(rgb(INK_DIM)) | ||
| 5134 | + .child(format!("cannot write: {}", refusals.join(" · "))) | ||
| 5135 | + .into_any_element(), | ||
| 5136 | + ); | ||
| 5137 | + } | ||
| 5138 | + // What the rows add up to, which is the one thing that has to be right: | ||
| 5139 | + // codec, box, size, rate, sound, where it goes and about how big. Two | ||
| 5140 | + // lines, outside the scrolling list, so it is on screen whatever the | ||
| 5141 | + // list is scrolled to and whatever is picked. | ||
| 5142 | + let picture = self | ||
| 5143 | + .session | ||
| 5144 | + .as_ref() | ||
| 5145 | + .map(|s| (s.resolution(), s.meta().frame_rate)); | ||
| 5146 | + let audio = self | ||
| 5147 | + .session | ||
| 5148 | + .as_ref() | ||
| 5149 | + .map_or("", |s| s.planned_audio(self.format)); | ||
| 5150 | + let settings = export_settings(self.quality, self.custom_mbps, self.format); | ||
| 5151 | + let mb = estimated_mb( | ||
| 5152 | + settings.bitrate.filter(|_| self.format.has_video()), | ||
| 5153 | + self.session | ||
| 5154 | + .as_ref() | ||
| 5155 | + .map_or(0., PlaybackSession::timeline_duration), | ||
| 5156 | + ); | ||
| 5157 | + let head = summary_head(self.format, picture, audio); | ||
| 5158 | + let tail = summary_tail( | ||
| 5159 | + &self.export_path, | ||
| 5160 | + mb, | ||
| 5161 | + self.export_seat.and_then(|(.., seat)| seat), | ||
| 5162 | + self.format.has_video(), | ||
| 5163 | + ); | ||
| 5164 | + // The button says the refusal *before* it is pressed: the picked codec | ||
| 5165 | + // can go invalid one edit after it was picked (a cleared video lane), | ||
| 5166 | + // and a button that looks ready until it is pressed is the lie the | ||
| 5167 | + // dimmed rows above it are there to avoid. | ||
| 5168 | + let blocked = self | ||
| 5169 | + .session | ||
| 5170 | + .as_ref() | ||
| 5171 | + .and_then(|s| format_refusal(s, self.format)); | ||
| 5172 | + let action: SharedString = match &blocked { | ||
| 5173 | + Some(why) => { | ||
| 5174 | + format!("Cannot export — {}", why.split(" — ").next().unwrap_or(why)).into() | ||
| 5175 | + } | ||
| 5176 | + None => "Export".into(), | ||
| 5177 | + }; | ||
| 4892 | Some( | 5178 | Some( |
| 4893 | div() | 5179 | div() |
| 4894 | .absolute() | 5180 | .absolute() |
| @@ -4902,7 +5188,7 @@ impl Player { | |||
| 4902 | }) | 5188 | }) |
| 4903 | .child( | 5189 | .child( |
| 4904 | div() | 5190 | div() |
| 4905 | - .w(px(KEYS_W)) | 5191 | + .w(px(EXPORT_W)) |
| 4906 | .flex() | 5192 | .flex() |
| 4907 | .flex_col() | 5193 | .flex_col() |
| 4908 | .gap(px(2.)) | 5194 | .gap(px(2.)) |
| @@ -4912,7 +5198,9 @@ impl Player { | |||
| 4912 | .child(div().flex_none().px(px(6.)).child("Export")) | 5198 | .child(div().flex_none().px(px(6.)).child("Export")) |
| 4913 | // The status line, where a refusal from the save dialog | 5199 | // The status line, where a refusal from the save dialog |
| 4914 | // lands: the notice bar it would otherwise take is under | 5200 | // lands: the notice bar it would otherwise take is under |
| 4915 | - // the scrim. | 5201 | + // the scrim. The keys are on the rows, so this says how |
| 5202 | + // the card as a whole is answered rather than listing | ||
| 5203 | + // them a second time. | ||
| 4916 | .child( | 5204 | .child( |
| 4917 | div() | 5205 | div() |
| 4918 | .flex_none() | 5206 | .flex_none() |
| @@ -4920,56 +5208,33 @@ impl Player { | |||
| 4920 | .text_size(px(11.)) | 5208 | .text_size(px(11.)) |
| 4921 | .text_color(rgb(INK_DIM)) | 5209 | .text_color(rgb(INK_DIM)) |
| 4922 | .child(self.notice.clone().unwrap_or_else(|| { | 5210 | .child(self.notice.clone().unwrap_or_else(|| { |
| 4923 | - "pick a format (m/a/v/h/x/w/f/p), then Export — esc closes" | 5211 | + "the keys are on the rows · enter exports · esc closes · \ |
| 5212 | + g/r change the layout" | ||
| 4924 | .into() | 5213 | .into() |
| 4925 | })), | 5214 | })), |
| 4926 | ) | 5215 | ) |
| 4927 | // Capped and scrolling like the keybindings list: the | 5216 | // Capped and scrolling like the keybindings list: the |
| 4928 | - // destination, ten formats and five qualities are more | 5217 | + // rows are more than a 360 px window has room for, and |
| 4929 | - // rows than a 360 px window has room for, and it is the | 5218 | + // it is the list that scrolls, never the card that |
| 4930 | - // list that scrolls, never the card that grows. | 5219 | + // grows -- the summary and the button below stay put. |
| 4931 | .child( | 5220 | .child( |
| 4932 | div() | 5221 | div() |
| 4933 | .id("export-rows") | 5222 | .id("export-rows") |
| 4934 | .flex() | 5223 | .flex() |
| 4935 | .flex_col() | 5224 | .flex_col() |
| 4936 | .gap(px(2.)) | 5225 | .gap(px(2.)) |
| 4937 | - .max_h(px(EXPORT_ROWS_H)) | 5226 | + .max_h(px(rows_h)) |
| 4938 | .overflow_y_scroll() | 5227 | .overflow_y_scroll() |
| 4939 | - .child( | 5228 | + .children(list), |
| 4940 | - live(row(("destination", 0)), true) | ||
| 4941 | - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 4942 | - this.pick_destination(cx) | ||
| 4943 | - })) | ||
| 4944 | - .child("Destination") | ||
| 4945 | - .child( | ||
| 4946 | - div() | ||
| 4947 | - .text_size(px(11.)) | ||
| 4948 | - .text_color(rgb(INK_DIM)) | ||
| 4949 | - .child(file_name(&self.export_path)), | ||
| 4950 | - ), | ||
| 4951 | - ) | ||
| 4952 | - .children(formats) | ||
| 4953 | - .children(rows), | ||
| 4954 | ) | 5229 | ) |
| 4955 | - // What the picked row really writes. `moov` last is the | 5230 | + .child(div().flex_none().px(px(6.)).text_size(px(11.)).child(head)) |
| 4956 | - // muxer's own shape -- an mp4 is playable only once it | ||
| 4957 | - // is finished. The project's resolution is on the same | ||
| 4958 | - // line because it *is* what the file comes out at, | ||
| 4959 | - // whatever size the media on the timeline are: this is | ||
| 4960 | - // the one place the number is shown, and ctrl+r is what | ||
| 4961 | - // changes it. | ||
| 4962 | .child( | 5231 | .child( |
| 4963 | div() | 5232 | div() |
| 4964 | .flex_none() | 5233 | .flex_none() |
| 4965 | .px(px(6.)) | 5234 | .px(px(6.)) |
| 4966 | .text_size(px(11.)) | 5235 | .text_size(px(11.)) |
| 4967 | .text_color(rgb(INK_DIM)) | 5236 | .text_color(rgb(INK_DIM)) |
| 4968 | - .child(export_line( | 5237 | + .child(tail), |
| 4969 | - self.format, | ||
| 4970 | - self.session.as_ref(), | ||
| 4971 | - self.export_seat.and_then(|(.., seat)| seat), | ||
| 4972 | - )), | ||
| 4973 | ) | 5238 | ) |
| 4974 | .child( | 5239 | .child( |
| 4975 | div() | 5240 | div() |
| @@ -4980,7 +5245,10 @@ impl Player { | |||
| 4980 | .items_center() | 5245 | .items_center() |
| 4981 | .justify_center() | 5246 | .justify_center() |
| 4982 | .rounded(px(3.)) | 5247 | .rounded(px(3.)) |
| 4983 | - .bg(rgb(SELECTED)) | 5248 | + .bg(rgb(match blocked.is_some() { |
| 5249 | + true => CHROME, | ||
| 5250 | + false => SELECTED, | ||
| 5251 | + })) | ||
| 4984 | .cursor_pointer() | 5252 | .cursor_pointer() |
| 4985 | .hover(|s| s.bg(rgb(HOVER))) | 5253 | .hover(|s| s.bg(rgb(HOVER))) |
| 4986 | .on_click( | 5254 | .on_click( |
| @@ -4988,12 +5256,42 @@ impl Player { | |||
| 4988 | this.start_export(cx) | 5256 | this.start_export(cx) |
| 4989 | }), | 5257 | }), |
| 4990 | ) | 5258 | ) |
| 4991 | - .child("Export"), | 5259 | + .child(action), |
| 4992 | ), | 5260 | ), |
| 4993 | ), | 5261 | ), |
| 4994 | ) | 5262 | ) |
| 4995 | } | 5263 | } |
| 4996 | 5264 | ||
| 5265 | + /// The custom bitrate's two pointer buttons. The typed digits were the last | ||
| 5266 | + /// control in this card a mouse could not reach at all -- and a number that | ||
| 5267 | + /// can only be typed is a number a hand on the pointer has to leave the | ||
| 5268 | + /// card to change. `HIT_MIN` square, like every other target here. | ||
| 5269 | + fn mbps_steppers(&self, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 5270 | + let step = |id: &'static str, label: &'static str, by: i32, cx: &mut Context<Self>| { | ||
| 5271 | + div() | ||
| 5272 | + .id(id) | ||
| 5273 | + .flex() | ||
| 5274 | + .w(px(HIT_MIN)) | ||
| 5275 | + .h(px(HIT_MIN)) | ||
| 5276 | + .items_center() | ||
| 5277 | + .justify_center() | ||
| 5278 | + .rounded(px(3.)) | ||
| 5279 | + .bg(rgb(CHROME)) | ||
| 5280 | + .cursor_pointer() | ||
| 5281 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5282 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 5283 | + this.nudge_mbps(by); | ||
| 5284 | + cx.notify(); | ||
| 5285 | + })) | ||
| 5286 | + .child(label) | ||
| 5287 | + }; | ||
| 5288 | + div() | ||
| 5289 | + .flex() | ||
| 5290 | + .gap(px(4.)) | ||
| 5291 | + .child(step("mbps-down", "−", -1, cx)) | ||
| 5292 | + .child(step("mbps-up", "+", 1, cx)) | ||
| 5293 | + } | ||
| 5294 | + | ||
| 4997 | /// The equalizer of one audio clip: its frequency response drawn as a | 5295 | /// The equalizer of one audio clip: its frequency response drawn as a |
| 4998 | /// curve, a handle per band sitting on it, and a row that flattens them | 5296 | /// curve, a handle per band sitting on it, and a row that flattens them |
| 4999 | /// all. The curve is the clip's actual filter (`EqParams::response_db` | 5297 | /// all. The curve is the clip's actual filter (`EqParams::response_db` |
| @@ -7281,58 +7579,97 @@ impl Quality { | |||
| 7281 | /// for. AAC is not a row at all: it is what both containers' sound *is*, never a | 7579 | /// for. AAC is not a row at all: it is what both containers' sound *is*, never a |
| 7282 | /// file of its own. | 7580 | /// file of its own. |
| 7283 | /// | 7581 | /// |
| 7284 | -/// AV1 is two rows because a codec and a container are two choices: the same | 7582 | +/// A codec is one row, and the boxes it can be written into are the row's |
| 7285 | -/// picture and the same AAC track go into a Matroska file or into an mp4, and | 7583 | +/// containers: the same AV1 picture and the same AAC track go into a Matroska |
| 7286 | -/// which one a user needs is about what has to play the file, not about the | 7584 | +/// file or into an mp4, and which one a user needs is about what has to play |
| 7287 | -/// encode. HEVC is two rows for the same reason. | 7585 | +/// the file, not about the encode. So the container is asked *once*, in a row |
| 7288 | -const FORMATS: [(Option<Format>, &str, &str, &str); 10] = [ | 7586 | +/// of its own, and only where there is more than one to ask about -- five |
| 7289 | - (Some(Format::Mp4), "m", "MP4", "H.264 picture + AAC sound"), | 7587 | +/// picture rows to read past were four of them saying the same codec twice. |
| 7588 | +const FORMATS: [(&[Format], &str, &str, &str); 8] = [ | ||
| 7290 | ( | 7589 | ( |
| 7291 | - Some(Format::Av1), | 7590 | + &[Format::Mp4], |
| 7292 | - "a", | 7591 | + "m", |
| 7293 | - "AV1 · MKV", | 7592 | + "H.264", |
| 7294 | - "AV1 picture + AAC sound in .mkv", | 7593 | + "plays everywhere · AAC sound · MP4 only", |
| 7295 | ), | 7594 | ), |
| 7296 | ( | 7595 | ( |
| 7297 | - Some(Format::Av1Mp4), | 7596 | + &[Format::Av1, Format::Av1Mp4], |
| 7298 | - "v", | 7597 | + "a", |
| 7299 | - "AV1 · MP4", | 7598 | + "AV1", |
| 7300 | - "the same AV1 picture and sound in .mp4", | 7599 | + "smallest file for the picture · AAC sound", |
| 7301 | ), | 7600 | ), |
| 7302 | ( | 7601 | ( |
| 7303 | - Some(Format::Hevc), | 7602 | + &[Format::Hevc, Format::HevcMp4], |
| 7304 | "h", | 7603 | "h", |
| 7305 | - "HEVC · MKV", | 7604 | + "HEVC", |
| 7306 | - "intra-only HEVC + AAC in .mkv — large files", | 7605 | + "intra-only, every frame a cut point — large files", |
| 7307 | - ), | ||
| 7308 | - ( | ||
| 7309 | - Some(Format::HevcMp4), | ||
| 7310 | - "x", | ||
| 7311 | - "HEVC · MP4", | ||
| 7312 | - "the same intra-only HEVC and sound in .mp4", | ||
| 7313 | ), | 7606 | ), |
| 7314 | - (Some(Format::Wav), "w", "WAV", "16-bit PCM — audio only"), | 7607 | + (&[Format::Wav], "w", "WAV", "16-bit PCM — audio only"), |
| 7315 | - (Some(Format::Flac), "f", "FLAC", "lossless — audio only"), | 7608 | + (&[Format::Flac], "f", "FLAC", "lossless — audio only"), |
| 7316 | ( | 7609 | ( |
| 7317 | - Some(Format::Mp3), | 7610 | + &[Format::Mp3], |
| 7318 | "p", | 7611 | "p", |
| 7319 | "MP3", | 7612 | "MP3", |
| 7320 | "MPEG-1 Layer III, 256 kbps — audio only", | 7613 | "MPEG-1 Layer III, 256 kbps — audio only", |
| 7321 | ), | 7614 | ), |
| 7322 | - (None, "", "OGG", "no pure-Rust Vorbis or Opus encoder"), | 7615 | + (&[], "", "OGG", "no pure-Rust Vorbis or Opus encoder"), |
| 7323 | - (None, "", "VP9", "superseded by AV1, which is the row above"), | 7616 | + (&[], "", "VP9", "AV1 above replaces it"), |
| 7324 | ]; | 7617 | ]; |
| 7325 | 7618 | ||
| 7326 | -/// The format a key picks while the export card is up. A letter of the row's | 7619 | +/// The codec row a key picks, landed in the container already chosen: pressing |
| 7327 | -/// own name, spelled out in the table rather than taken from the initial: `MP4` | 7620 | +/// `a` after an mp4 gives AV1 *in mp4*, because a box decided once is not a |
| 7328 | -/// and `MP3` share one, and so do the two AV1 containers, so an initial cannot | 7621 | +/// question again. A letter of the row's own name, spelled out in the table |
| 7329 | -/// tell six rows apart. Never a digit -- those are the bitrate's. `None` for | 7622 | +/// rather than taken from the initial (`MP4` and `MP3` share one). Never a |
| 7330 | -/// everything else, the rows that cannot be picked included. | 7623 | +/// digit -- those are the bitrate's. `None` for every other stroke, the rows |
| 7331 | -fn format_key(key: &str) -> Option<Format> { | 7624 | +/// that cannot be picked included. |
| 7625 | +fn format_key(key: &str, current: Format) -> Option<Format> { | ||
| 7332 | FORMATS | 7626 | FORMATS |
| 7333 | .into_iter() | 7627 | .into_iter() |
| 7334 | .filter(|(_, stroke, ..)| !stroke.is_empty() && stroke.eq_ignore_ascii_case(key)) | 7628 | .filter(|(_, stroke, ..)| !stroke.is_empty() && stroke.eq_ignore_ascii_case(key)) |
| 7335 | - .find_map(|(format, ..)| format) | 7629 | + .find_map(|(row, ..)| same_box(row, current)) |
| 7630 | +} | ||
| 7631 | + | ||
| 7632 | +/// The boxes one codec may be written into, in the order its container row | ||
| 7633 | +/// cycles them. Empty for a codec this program cannot write at all. | ||
| 7634 | +fn containers(format: Format) -> &'static [Format] { | ||
| 7635 | + FORMATS | ||
| 7636 | + .into_iter() | ||
| 7637 | + .map(|(row, ..)| row) | ||
| 7638 | + .find(|row| row.contains(&format)) | ||
| 7639 | + .unwrap_or(&[]) | ||
| 7640 | +} | ||
| 7641 | + | ||
| 7642 | +/// This row's format under the container `current` is already in, or the row's | ||
| 7643 | +/// first when it has no such box: an AV1 picked from a WAV lands in Matroska, | ||
| 7644 | +/// and picked from an mp4 stays in the mp4. | ||
| 7645 | +fn same_box(row: &[Format], current: Format) -> Option<Format> { | ||
| 7646 | + row.iter() | ||
| 7647 | + .copied() | ||
| 7648 | + .find(|f| f.ext() == current.ext()) | ||
| 7649 | + .or_else(|| row.first().copied()) | ||
| 7650 | +} | ||
| 7651 | + | ||
| 7652 | +/// The next box for the same codec, wrapping -- what the container row's key | ||
| 7653 | +/// does. The format itself for a codec with only one, so the stroke cannot | ||
| 7654 | +/// change what it is not offering. | ||
| 7655 | +fn next_container(format: Format) -> Format { | ||
| 7656 | + let row = containers(format); | ||
| 7657 | + let at = row.iter().position(|&f| f == format).unwrap_or(0); | ||
| 7658 | + row.get((at + 1) % row.len().max(1)) | ||
| 7659 | + .copied() | ||
| 7660 | + .unwrap_or(format) | ||
| 7661 | +} | ||
| 7662 | + | ||
| 7663 | +/// Why the quality rows say nothing about this format, or `None` where they | ||
| 7664 | +/// decide the picture. Only a picture encoder is given a bitrate here: the two | ||
| 7665 | +/// lossless audio formats have none to give and MP3 is written at one fixed | ||
| 7666 | +/// figure, so a live row over either would be a control that changes nothing. | ||
| 7667 | +fn bitrate_refusal(format: Format) -> Option<&'static str> { | ||
| 7668 | + match format { | ||
| 7669 | + Format::Wav | Format::Flac => Some("lossless audio — no bitrate to pick"), | ||
| 7670 | + Format::Mp3 => Some("MP3 is written at a fixed 256 kbps"), | ||
| 7671 | + _ => None, | ||
| 7672 | + } | ||
| 7336 | } | 7673 | } |
| 7337 | 7674 | ||
| 7338 | /// What one of the colour card's own strokes does. Its keys are card-local -- | 7675 | /// What one of the colour card's own strokes does. Its keys are card-local -- |
| @@ -7467,57 +7804,84 @@ fn next_resolution(current: (u32, u32), native: (u32, u32)) -> (u32, u32) { | |||
| 7467 | sizes[at.map_or(0, |at| (at + 1) % sizes.len())] | 7804 | sizes[at.map_or(0, |at| (at + 1) % sizes.len())] |
| 7468 | } | 7805 | } |
| 7469 | 7806 | ||
| 7470 | -/// [`format_line`] plus the project's resolution, which is what a video export | 7807 | +/// The first of the two lines the card keeps above its button: what will be |
| 7471 | -/// is written at however many sizes the media on the timeline are. Only for the | 7808 | +/// *inside* the file. [`format_line`]'s codec and box, then the project's own |
| 7472 | -/// formats that carry a picture -- a WAV has no resolution to state. | 7809 | +/// picture size and rate -- which is what a video export is written at however |
| 7473 | -fn export_line( | 7810 | +/// many sizes and rates the media on the timeline are -- and last what the |
| 7474 | - format: Format, | 7811 | +/// sound will be, or that there is none. Every field here is one `ffprobe` |
| 7475 | - session: Option<&PlaybackSession>, | 7812 | +/// reads back off the finished file, so the line is checkable rather than a |
| 7476 | - seat: Option<&'static str>, | 7813 | +/// promise. |
| 7477 | -) -> String { | 7814 | +fn summary_head(format: Format, picture: Option<((u32, u32), f64)>, audio: &str) -> String { |
| 7478 | - let line = format_line(format); | 7815 | + let line = match picture.filter(|_| format.has_video()) { |
| 7479 | - // What it will really be encoded by, on the same line: the picture's seat | 7816 | + Some(((w, h), fps)) => { |
| 7480 | - // as the probe found it (`…` until it lands, never a guess) and the sound's, | 7817 | + format!("{} · {w}x{h} · {} fps", format_line(format), fps_label(fps)) |
| 7481 | - // which is decided without opening anything. Both are what a running export | 7818 | + } |
| 7482 | - // then names on its progress line, from the same two functions. | 7819 | + None => format_line(format).to_string(), |
| 7483 | - let encoders = match session { | ||
| 7484 | - Some(session) => join_detail( | ||
| 7485 | - seat.unwrap_or(match format.has_video() { | ||
| 7486 | - true => "encoder …", | ||
| 7487 | - false => "", | ||
| 7488 | - }), | ||
| 7489 | - session.planned_audio(format), | ||
| 7490 | - ), | ||
| 7491 | - None => String::new(), | ||
| 7492 | }; | 7820 | }; |
| 7493 | - match session.filter(|_| format.has_video()) { | 7821 | + join_detail(&line, audio) |
| 7494 | - Some(session) => { | 7822 | +} |
| 7495 | - let (w, h) = session.resolution(); | 7823 | + |
| 7496 | - format!("{line} · project {w}x{h} · {encoders}") | 7824 | +/// The second: where it lands, roughly how big, and what will encode the |
| 7497 | - } | 7825 | +/// picture -- the seat as the probe found it (`…` until it lands, never a |
| 7498 | - None => join_detail(line, &encoders), | 7826 | +/// guess), which is what the running export then names on its progress line. |
| 7827 | +fn summary_tail(path: &Path, mb: Option<u64>, seat: Option<&'static str>, video: bool) -> String { | ||
| 7828 | + let size = mb.map_or_else(String::new, |mb| format!("≈ {mb} MB")); | ||
| 7829 | + let seat = match (video, seat) { | ||
| 7830 | + (true, Some(seat)) => seat, | ||
| 7831 | + (true, None) => "encoder …", | ||
| 7832 | + (false, _) => "", | ||
| 7833 | + }; | ||
| 7834 | + join_detail(&join_detail(&file_name(path), &size), seat) | ||
| 7835 | +} | ||
| 7836 | + | ||
| 7837 | +/// A frame rate as a person writes it: `30`, not `30.000`, and `23.976` for the | ||
| 7838 | +/// rate that is a ratio. | ||
| 7839 | +fn fps_label(fps: f64) -> String { | ||
| 7840 | + match (fps - fps.round()).abs() < 0.001 { | ||
| 7841 | + true => format!("{fps:.0}"), | ||
| 7842 | + false => format!("{fps:.3}") | ||
| 7843 | + .trim_end_matches('0') | ||
| 7844 | + .trim_end_matches('.') | ||
| 7845 | + .to_string(), | ||
| 7499 | } | 7846 | } |
| 7500 | } | 7847 | } |
| 7501 | 7848 | ||
| 7849 | +/// About how big a *chosen* bitrate makes the file: the picture's megabits over | ||
| 7850 | +/// the timeline's length. `None` for `Auto`, whose figure is the encoder's to | ||
| 7851 | +/// decide, and for a format with no bitrate at all -- a number nobody picked is | ||
| 7852 | +/// not an estimate. The sound and the container's own overhead are not in it, | ||
| 7853 | +/// which is why the card says "≈". | ||
| 7854 | +fn estimated_mb(bitrate: Option<u64>, duration: f64) -> Option<u64> { | ||
| 7855 | + let bitrate = bitrate.filter(|&b| b > 0 && duration > 0.)?; | ||
| 7856 | + Some((bitrate as f64 * duration / 8e6).round() as u64) | ||
| 7857 | +} | ||
| 7858 | + | ||
| 7859 | +/// What is in the file and what box it is in, which is the head of the summary. | ||
| 7860 | +/// Terse on purpose: the fields after it (size, rate, sound) are what the line | ||
| 7861 | +/// is *for*, and a head that spent its width on prose used to push the whole | ||
| 7862 | +/// summary onto a second line -- what each codec means is on its row. | ||
| 7502 | fn format_line(format: Format) -> &'static str { | 7863 | fn format_line(format: Format) -> &'static str { |
| 7503 | match format { | 7864 | match format { |
| 7504 | - Format::Mp4 => "H.264 · MP4 · moov at end", | 7865 | + Format::Mp4 => "H.264 · MP4", |
| 7505 | - Format::Av1 => "AV1 · Matroska · picture and sound", | 7866 | + Format::Av1 => "AV1 · MKV", |
| 7506 | - Format::Av1Mp4 => "AV1 · MP4 · picture and sound", | 7867 | + Format::Av1Mp4 => "AV1 · MP4", |
| 7507 | - Format::Hevc => "HEVC intra · Matroska · picture and sound", | 7868 | + Format::Hevc => "HEVC intra · MKV", |
| 7508 | - Format::HevcMp4 => "HEVC intra · MP4 · picture and sound", | 7869 | + Format::HevcMp4 => "HEVC intra · MP4", |
| 7509 | - Format::Wav => "16-bit PCM · WAV · timeline audio only", | 7870 | + // The three whose codec *is* their box: naming it twice would be the |
| 7510 | - Format::Flac => "FLAC · lossless · timeline audio only", | 7871 | + // only field on this line that says nothing. |
| 7511 | - Format::Mp3 => "MP3 · 256 kbps · timeline audio only", | 7872 | + Format::Wav => "16-bit PCM · WAV", |
| 7873 | + Format::Flac => "FLAC · lossless", | ||
| 7874 | + Format::Mp3 => "MP3 · 256 kbps", | ||
| 7512 | } | 7875 | } |
| 7513 | } | 7876 | } |
| 7514 | 7877 | ||
| 7515 | -/// The row a format is picked by, which is what a refusal calls it: `MP4`, not | 7878 | +/// The row a format is picked by, which is what a refusal calls it: the codec, |
| 7516 | -/// the `mkv` an AV1 file is named with. | 7879 | +/// since the container is a row of its own now -- `AV1`, not the `mkv` such a |
| 7880 | +/// file is named with. | ||
| 7517 | fn format_label(format: Format) -> &'static str { | 7881 | fn format_label(format: Format) -> &'static str { |
| 7518 | FORMATS | 7882 | FORMATS |
| 7519 | .iter() | 7883 | .iter() |
| 7520 | - .find(|(row, ..)| *row == Some(format)) | 7884 | + .find(|(row, ..)| row.contains(&format)) |
| 7521 | .map_or("EXPORT", |(_, _, label, _)| *label) | 7885 | .map_or("EXPORT", |(_, _, label, _)| *label) |
| 7522 | } | 7886 | } |
| 7523 | 7887 | ||
| @@ -8483,18 +8847,20 @@ mod tests { | |||
| 8483 | use super::{ | 8847 | use super::{ |
| 8484 | ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, | 8848 | ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, |
| 8485 | EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, | 8849 | EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, |
| 8486 | - EQ_TICKS, EXPORT_ROWS_H, FORMATS, Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, | 8850 | + EQ_TICKS, ESCAPE, EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, FORMATS, Format, HEADER_GAP, |
| 8487 | - HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H, | 8851 | + HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, |
| 8488 | - LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, | 8852 | + KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, |
| 8489 | - MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, | 8853 | + LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, |
| 8490 | - SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, | 8854 | + PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, |
| 8491 | - Speed, StreamInfo, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, | 8855 | + SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, VOLUME_W, Volume, WAVE_BPS, |
| 8492 | - can_add, cancels_export, clipboard_after_remove, color_snap, envelope, eq_spectrum, eq_x, | 8856 | + WAVE_COL, Wave, applicable, band_label, bitrate_refusal, can_add, cancels_export, |
| 8493 | - eq_y, export_path, export_settings, format_key, format_line, format_refusal, frac_along, | 8857 | + clipboard_after_remove, color_snap, containers, envelope, eq_spectrum, eq_x, eq_y, |
| 8494 | - frac_down, frame_at, histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, | 8858 | + estimated_mb, export_path, export_settings, format_key, format_line, format_refusal, |
| 8495 | - menu_at, normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, | 8859 | + fps_label, frac_along, frac_down, frame_at, histogram, is_bare_modifier, is_project, |
| 8496 | - scrub_due, show_label, silence_rate, snapped, source_tint, span_partner, speed_at, | 8860 | + keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h, |
| 8497 | - timecode, unseen_paths, unseen_sources, whole_take, width_frac, window_title, | 8861 | + project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped, |
| 8862 | + source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, unseen_paths, | ||
| 8863 | + unseen_sources, whole_take, width_frac, window_title, | ||
| 8498 | }; | 8864 | }; |
| 8499 | use super::{ | 8865 | use super::{ |
| 8500 | LaneKind, Repeat, View, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, library_rows, | 8866 | LaneKind, Repeat, View, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, library_rows, |
| @@ -10563,128 +10929,265 @@ mod tests { | |||
| 10563 | #[test] | 10929 | #[test] |
| 10564 | fn the_export_card_fits_the_smallest_window() { | 10930 | fn the_export_card_fits_the_smallest_window() { |
| 10565 | // Same 640x360 floor the keybindings card is measured against: the | 10931 | // Same 640x360 floor the keybindings card is measured against: the |
| 10566 | - // capped row list, the fixed-format line and the confirm button, under | 10932 | + // capped row list, the two summary lines and the confirm button, under |
| 10567 | // a title and a status line. | 10933 | // a title and a status line. |
| 10568 | let title = 17.; | 10934 | let title = 17.; |
| 10569 | let status = 28.; | 10935 | let status = 28.; |
| 10570 | - // Two lines of 11 px: the format line carries the encoders an export | 10936 | + // The head is one line of 11 px at this width -- every field of it, |
| 10571 | - // would open, which is what takes it past one at this width. | 10937 | + // worst case, is 71 characters against the 76 that fit. The tail is |
| 10572 | - let fixed = 30.; | 10938 | + // budgeted for two: the destination's name is the user's and a long one |
| 10573 | - let gaps = 4. * 2.; | 10939 | + // wraps. |
| 10940 | + let summary = 15. + 30.; | ||
| 10941 | + // Six children in the column, so five gaps. | ||
| 10942 | + let gaps = 5. * 2.; | ||
| 10574 | let padding = 24.; | 10943 | let padding = 24.; |
| 10575 | - assert!( | 10944 | + assert_eq!( |
| 10576 | - title + status + EXPORT_ROWS_H + fixed + CONTROL_H + 4. + gaps + padding <= 360., | 10945 | + EXPORT_FIXED_H, |
| 10577 | - "card too tall" | 10946 | + title + status + summary + CONTROL_H + 4. + gaps + padding |
| 10578 | ); | 10947 | ); |
| 10948 | + assert!(EXPORT_FIXED_H + EXPORT_ROWS_H <= 360., "card too tall"); | ||
| 10949 | + // The list grows with a window that has the room -- and never shrinks | ||
| 10950 | + // below the cap that made the floor fit, whatever arithmetic the window | ||
| 10951 | + // hands it. | ||
| 10952 | + let cap = |h: f32| (h - EXPORT_FIXED_H - 24.).max(EXPORT_ROWS_H); | ||
| 10953 | + assert_eq!(cap(360.), EXPORT_ROWS_H); | ||
| 10954 | + assert_eq!(cap(0.), EXPORT_ROWS_H); | ||
| 10955 | + assert!(cap(720.) > EXPORT_ROWS_H); | ||
| 10956 | + assert!(EXPORT_FIXED_H + cap(720.) <= 720.); | ||
| 10957 | + // ...and inside the 640 px floor with the scrim showing either side. | ||
| 10958 | + assert!(EXPORT_W + 2. * 12. <= 640.); | ||
| 10579 | // The cap is only honest if enough of the list is on screen to read as | 10959 | // The cap is only honest if enough of the list is on screen to read as |
| 10580 | - // one -- the destination and the first formats, not a slot. | 10960 | + // one -- and the whole format section is: its header and every codec |
| 10581 | - assert!(EXPORT_ROWS_H / KEYS_ROW_H >= 6.); | 10961 | + // row, so nothing that is picked *first* is behind a scroll. |
| 10582 | - // Clickable rows, so WCAG 2.5.8 binds them as it binds the panel's. | 10962 | + let codecs = FORMATS.iter().filter(|(row, ..)| !row.is_empty()).count(); |
| 10963 | + assert!(EXPORT_ROWS_H / KEYS_ROW_H >= 1. + codecs as f32); | ||
| 10964 | + // Clickable rows, so WCAG 2.5.8 binds them as it binds the panel's -- | ||
| 10965 | + // and the bitrate steppers are `HIT_MIN` squares sitting inside a row, | ||
| 10966 | + // which only fits while the row is at least as tall as one. | ||
| 10583 | assert!(KEYS_ROW_H >= HIT_MIN); | 10967 | assert!(KEYS_ROW_H >= HIT_MIN); |
| 10584 | assert!(CONTROL_H >= HIT_MIN); | 10968 | assert!(CONTROL_H >= HIT_MIN); |
| 10969 | + // The dimmed text on the card -- every refusal, every detail, every key | ||
| 10970 | + // in its column -- is body text on `SURFACE` and WCAG 1.4.3 binds it. | ||
| 10971 | + // A dimmed row is drawn in this ink rather than at an opacity, which is | ||
| 10972 | + // what a refusal used to be readable through. | ||
| 10973 | + assert!( | ||
| 10974 | + contrast(INK_DIM, SURFACE) >= 4.5, | ||
| 10975 | + "refusal ink {:.2}", | ||
| 10976 | + contrast(INK_DIM, SURFACE) | ||
| 10977 | + ); | ||
| 10978 | + // On the picked row that ink would only be 3.3:1 against the highlight, | ||
| 10979 | + // so the row it lands on lifts its key and detail to `INK`. | ||
| 10980 | + assert!(contrast(INK, SELECTED) >= 4.5); | ||
| 10981 | + assert!( | ||
| 10982 | + contrast(INK_DIM, SELECTED) < 4.5, | ||
| 10983 | + "the lift is still needed" | ||
| 10984 | + ); | ||
| 10585 | } | 10985 | } |
| 10586 | 10986 | ||
| 10587 | #[test] | 10987 | #[test] |
| 10588 | - fn every_format_row_is_offered_or_says_why_not() { | 10988 | + fn every_codec_row_is_offered_or_says_why_not() { |
| 10589 | - // The six this program can write are rows that pick. Four are named | 10989 | + // One row per codec, and the boxes it can go in are the container row's |
| 10590 | - // after their own extension, so a destination cannot disagree with its | 10990 | + // business: six rows that pick, two that say why they cannot. A codec |
| 10591 | - // bytes; the AV1 pair is named after codec *and* container, because the | 10991 | + // twice over (AV1 · MKV beside AV1 · MP4) was two rows asking the same |
| 10592 | - // same picture goes into either box and the row is the choice between | 10992 | + // question, and five picture rows above the fold is what the card was |
| 10593 | - // them. | 10993 | + // called unfriendly for. |
| 10594 | - let offered: Vec<Format> = FORMATS.iter().filter_map(|&(f, ..)| f).collect(); | 10994 | + let offered: Vec<&[Format]> = FORMATS |
| 10995 | + .iter() | ||
| 10996 | + .map(|&(row, ..)| row) | ||
| 10997 | + .filter(|row| !row.is_empty()) | ||
| 10998 | + .collect(); | ||
| 10595 | assert_eq!( | 10999 | assert_eq!( |
| 10596 | offered, | 11000 | offered, |
| 10597 | vec![ | 11001 | vec![ |
| 10598 | - Format::Mp4, | 11002 | + &[Format::Mp4][..], |
| 10599 | - Format::Av1, | 11003 | + &[Format::Av1, Format::Av1Mp4][..], |
| 10600 | - Format::Av1Mp4, | 11004 | + &[Format::Hevc, Format::HevcMp4][..], |
| 10601 | - Format::Hevc, | 11005 | + &[Format::Wav][..], |
| 10602 | - Format::HevcMp4, | 11006 | + &[Format::Flac][..], |
| 10603 | - Format::Wav, | 11007 | + &[Format::Mp3][..], |
| 10604 | - Format::Flac, | ||
| 10605 | - Format::Mp3 | ||
| 10606 | ] | 11008 | ] |
| 10607 | ); | 11009 | ); |
| 11010 | + // Every format the engine writes is on exactly one row: one the card | ||
| 11011 | + // cannot reach is one nobody can pick. | ||
| 11012 | + for format in [ | ||
| 11013 | + Format::Mp4, | ||
| 11014 | + Format::Av1, | ||
| 11015 | + Format::Av1Mp4, | ||
| 11016 | + Format::Hevc, | ||
| 11017 | + Format::HevcMp4, | ||
| 11018 | + Format::Wav, | ||
| 11019 | + Format::Flac, | ||
| 11020 | + Format::Mp3, | ||
| 11021 | + ] { | ||
| 11022 | + assert_eq!( | ||
| 11023 | + FORMATS | ||
| 11024 | + .iter() | ||
| 11025 | + .filter(|(row, ..)| row.contains(&format)) | ||
| 11026 | + .count(), | ||
| 11027 | + 1, | ||
| 11028 | + "{format:?}" | ||
| 11029 | + ); | ||
| 11030 | + } | ||
| 11031 | + // The boxes the container row offers, and what the extension of each is | ||
| 11032 | + // -- the destination follows the format, so these are what a file gets | ||
| 11033 | + // named with. | ||
| 11034 | + assert_eq!(containers(Format::Av1), [Format::Av1, Format::Av1Mp4]); | ||
| 11035 | + assert_eq!(containers(Format::HevcMp4), [Format::Hevc, Format::HevcMp4]); | ||
| 11036 | + assert_eq!(containers(Format::Mp3), [Format::Mp3]); | ||
| 10608 | assert_eq!(Format::Av1.ext(), "mkv"); | 11037 | assert_eq!(Format::Av1.ext(), "mkv"); |
| 10609 | assert_eq!(Format::Av1Mp4.ext(), "mp4"); | 11038 | assert_eq!(Format::Av1Mp4.ext(), "mp4"); |
| 10610 | assert_eq!(Format::Hevc.ext(), "mkv"); | 11039 | assert_eq!(Format::Hevc.ext(), "mkv"); |
| 10611 | assert_eq!(Format::HevcMp4.ext(), "mp4"); | 11040 | assert_eq!(Format::HevcMp4.ext(), "mp4"); |
| 10612 | - for (format, _, label, _) in FORMATS { | 11041 | + // The container key walks the row and wraps, and does nothing at all |
| 10613 | - match format { | 11042 | + // where there is only one box -- a stroke must not invent a choice the |
| 10614 | - Some(Format::Av1) => assert_eq!(label, "AV1 · MKV"), | 11043 | + // card is not offering. |
| 10615 | - Some(Format::Av1Mp4) => assert_eq!(label, "AV1 · MP4"), | 11044 | + assert_eq!(next_container(Format::Av1), Format::Av1Mp4); |
| 10616 | - Some(Format::Hevc) => assert_eq!(label, "HEVC · MKV"), | 11045 | + assert_eq!(next_container(Format::Av1Mp4), Format::Av1); |
| 10617 | - Some(Format::HevcMp4) => assert_eq!(label, "HEVC · MP4"), | 11046 | + assert_eq!(next_container(Format::Hevc), Format::HevcMp4); |
| 10618 | - Some(format) => assert_eq!(format.ext(), label.to_lowercase()), | 11047 | + assert_eq!(next_container(Format::Mp4), Format::Mp4); |
| 10619 | - // A refused format is a row with a reason, never a hidden one: | 11048 | + assert_eq!(next_container(Format::Wav), Format::Wav); |
| 10620 | - // an empty detail column would read as an oversight. | 11049 | + for (row, stroke, label, detail) in FORMATS { |
| 10621 | - None => assert!(!label.is_empty()), | 11050 | + assert!(!label.is_empty(), "a row with no name"); |
| 10622 | - } | 11051 | + // A refused row is a row with a reason, never a hidden one: an |
| 10623 | - } | 11052 | + // empty detail column would read as an oversight. |
| 10624 | - for (format, stroke, label, detail) in FORMATS { | ||
| 10625 | assert!(!detail.is_empty(), "{label} says nothing"); | 11053 | assert!(!detail.is_empty(), "{label} says nothing"); |
| 10626 | - // Only the picture formats leave the bitrate rows live -- the card | 11054 | + // Every row that can be picked has a key of its own, and no row |
| 10627 | - // dims them off exactly this. | 11055 | + // that cannot has one: the card is drivable without a pointer. |
| 10628 | - assert_eq!( | 11056 | + assert_eq!(!row.is_empty(), !stroke.is_empty(), "{label}"); |
| 10629 | - format.is_some_and(Format::has_video), | 11057 | + if let Some(&first) = row.first() { |
| 10630 | - matches!( | 11058 | + assert_eq!( |
| 10631 | - format, | 11059 | + format_key(stroke, first), |
| 10632 | - Some( | 11060 | + Some(first), |
| 10633 | - Format::Mp4 | Format::Av1 | Format::Av1Mp4 | Format::Hevc | Format::HevcMp4 | 11061 | + "{label} keys to itself" |
| 10634 | - ) | 11062 | + ); |
| 10635 | - ) | ||
| 10636 | - ); | ||
| 10637 | - // Every row that can be picked has a key of its own, and no two | ||
| 10638 | - // share one: the card is drivable without a pointer. | ||
| 10639 | - assert_eq!(format.is_some(), !stroke.is_empty(), "{label}"); | ||
| 10640 | - if !stroke.is_empty() { | ||
| 10641 | - assert_eq!(format_key(stroke), format, "{label} keys to itself"); | ||
| 10642 | assert!( | 11063 | assert!( |
| 10643 | stroke.parse::<u32>().is_err(), | 11064 | stroke.parse::<u32>().is_err(), |
| 10644 | "{label} takes a digit the bitrate needs" | 11065 | "{label} takes a digit the bitrate needs" |
| 10645 | ); | 11066 | ); |
| 11067 | + // Every box on one row is the same codec, so the quality rows | ||
| 11068 | + // do not change meaning when the container does. | ||
| 11069 | + assert!(row.iter().all(|f| f.has_video() == first.has_video())); | ||
| 11070 | + assert!( | ||
| 11071 | + row.iter() | ||
| 11072 | + .all(|f| bitrate_refusal(*f) == bitrate_refusal(first)) | ||
| 11073 | + ); | ||
| 10646 | } | 11074 | } |
| 10647 | } | 11075 | } |
| 11076 | + // No two rows share a key, and none of them is a stroke the card already | ||
| 11077 | + // answers to itself -- an ambiguous key is a key that picks the wrong | ||
| 11078 | + // thing on a card that has no other input. | ||
| 11079 | + let keys: Vec<&str> = FORMATS | ||
| 11080 | + .iter() | ||
| 11081 | + .map(|&(_, stroke, ..)| stroke) | ||
| 11082 | + .filter(|stroke| !stroke.is_empty()) | ||
| 11083 | + .collect(); | ||
| 11084 | + for (i, key) in keys.iter().enumerate() { | ||
| 11085 | + assert!(!keys[i + 1..].contains(key), "{key} picks two rows"); | ||
| 11086 | + assert!( | ||
| 11087 | + !["c", "q", "d", "g", "r", "enter", "backspace", ESCAPE].contains(key), | ||
| 11088 | + "{key} is already the card's own" | ||
| 11089 | + ); | ||
| 11090 | + } | ||
| 11091 | + assert_eq!( | ||
| 11092 | + format_key("a", Format::Mp4), | ||
| 11093 | + Some(Format::Av1Mp4), | ||
| 11094 | + "the box already chosen is kept" | ||
| 11095 | + ); | ||
| 11096 | + assert_eq!( | ||
| 11097 | + format_key("a", Format::Wav), | ||
| 11098 | + Some(Format::Av1), | ||
| 11099 | + "and a codec with no such box takes its first" | ||
| 11100 | + ); | ||
| 11101 | + assert_eq!(format_key("h", Format::Av1Mp4), Some(Format::HevcMp4)); | ||
| 11102 | + assert_eq!(format_key("p", Format::Mp4), Some(Format::Mp3)); | ||
| 11103 | + assert_eq!( | ||
| 11104 | + format_key("m", Format::Mp3), | ||
| 11105 | + Some(Format::Mp4), | ||
| 11106 | + "not MP3, which is p" | ||
| 11107 | + ); | ||
| 11108 | + assert_eq!( | ||
| 11109 | + format_key("x", Format::Mp4), | ||
| 11110 | + None, | ||
| 11111 | + "a stroke no row carries" | ||
| 11112 | + ); | ||
| 10648 | // The codec this program reads and cannot write is a row of its own, | 11113 | // The codec this program reads and cannot write is a row of its own, |
| 10649 | // refused by name rather than absent: VP9, because AV1 is the row that | 11114 | // refused by name rather than absent: VP9, because AV1 is the row that |
| 10650 | - // replaced it. HEVC used to be one beside it and is now two rows that | 11115 | + // replaced it. Its reason travels with it, in the row or in the footer |
| 10651 | - // pick -- an intra-only encoder is still an encoder. | 11116 | + // line that collects them -- either way it is on screen without a click. |
| 10652 | - for (label, word) in [("VP9", "superseded")] { | 11117 | + for (label, word) in [("VP9", "replaces it"), ("OGG", "no pure-Rust")] { |
| 10653 | - let (format, _, _, detail) = FORMATS | 11118 | + let (row, _, _, detail) = FORMATS |
| 10654 | .into_iter() | 11119 | .into_iter() |
| 10655 | - .find(|(_, _, row, _)| *row == label) | 11120 | + .find(|(_, _, name, _)| *name == label) |
| 10656 | .unwrap_or_else(|| panic!("{label} has no row")); | 11121 | .unwrap_or_else(|| panic!("{label} has no row")); |
| 10657 | - assert!(format.is_none(), "{label} is not offered"); | 11122 | + assert!(row.is_empty(), "{label} is not offered"); |
| 10658 | assert!(detail.contains(word), "{label}: {detail}"); | 11123 | assert!(detail.contains(word), "{label}: {detail}"); |
| 10659 | } | 11124 | } |
| 10660 | - // Both AV1 rows say they carry sound: the file used to be picture only, | 11125 | + // Both AV1 boxes say they carry sound: the file used to be picture only, |
| 10661 | - // and a row that still said so would be the lie a user plays the file | 11126 | + // and a line that still said so would be the lie a user plays the file |
| 10662 | - // to find out about. | 11127 | + // to find out about. HEVC says intra-only before anyone waits on one -- |
| 11128 | + // a file several times the size, which the disk would otherwise say. | ||
| 10663 | for format in [Format::Av1, Format::Av1Mp4] { | 11129 | for format in [Format::Av1, Format::Av1Mp4] { |
| 10664 | - let (_, _, _, detail) = FORMATS | 11130 | + assert!(format_line(format).starts_with("AV1 · ")); |
| 10665 | - .into_iter() | 11131 | + } |
| 10666 | - .find(|(f, ..)| *f == Some(format)) | ||
| 10667 | - .expect("an AV1 row"); | ||
| 10668 | - assert!(detail.contains("sound"), "{detail}"); | ||
| 10669 | - assert!(format_line(format).contains("picture and sound")); | ||
| 10670 | - } | ||
| 10671 | - // ...and both HEVC rows say what they are before a user waits on one: | ||
| 10672 | - // intra-only, which is a file several times the size of the AV1 above | ||
| 10673 | - // it. A row that hid that would be found out by the disk. | ||
| 10674 | for format in [Format::Hevc, Format::HevcMp4] { | 11132 | for format in [Format::Hevc, Format::HevcMp4] { |
| 10675 | - let (_, _, _, detail) = FORMATS | 11133 | + assert!(format_line(format).starts_with("HEVC intra · ")); |
| 11134 | + } | ||
| 11135 | + // The head names the box every format goes in, which is what the | ||
| 11136 | + // destination is then named after. | ||
| 11137 | + for format in [ | ||
| 11138 | + Format::Mp4, | ||
| 11139 | + Format::Av1, | ||
| 11140 | + Format::Av1Mp4, | ||
| 11141 | + Format::Hevc, | ||
| 11142 | + Format::HevcMp4, | ||
| 11143 | + ] { | ||
| 11144 | + assert!( | ||
| 11145 | + format_line(format).contains(&format.ext().to_uppercase()), | ||
| 11146 | + "{format:?}: {}", | ||
| 11147 | + format_line(format) | ||
| 11148 | + ); | ||
| 11149 | + } | ||
| 11150 | + // ...and it stays inside the one line the card budgets for it: the | ||
| 11151 | + // longest of them, with every field after it, against the 76 characters | ||
| 11152 | + // that fit at `EXPORT_W`. | ||
| 11153 | + let longest = summary_head( | ||
| 11154 | + Format::Hevc, | ||
| 11155 | + Some(((1920, 1080), 23.976)), | ||
| 11156 | + "AAC · SW encode (rusty_aac)", | ||
| 11157 | + ); | ||
| 11158 | + assert!( | ||
| 11159 | + longest.chars().count() <= 76, | ||
| 11160 | + "{longest} is {} long", | ||
| 11161 | + longest.chars().count() | ||
| 11162 | + ); | ||
| 11163 | + assert!( | ||
| 11164 | + FORMATS | ||
| 10676 | .into_iter() | 11165 | .into_iter() |
| 10677 | - .find(|(f, ..)| *f == Some(format)) | 11166 | + .any(|(row, _, _, detail)| row.contains(&Format::Hevc) && detail.contains("intra")) |
| 10678 | - .expect("an HEVC row"); | 11167 | + ); |
| 10679 | - assert!(detail.contains("intra-only"), "{detail}"); | 11168 | + // Only a picture encoder is given a bitrate, and the quality rows dim |
| 10680 | - assert!(format_line(format).contains("picture and sound")); | 11169 | + // with the reason for every format that is not one. |
| 10681 | - } | 11170 | + for format in [ |
| 10682 | - assert_eq!(format_key("a"), Some(Format::Av1), "the Matroska one"); | 11171 | + Format::Mp4, |
| 10683 | - assert_eq!(format_key("v"), Some(Format::Av1Mp4), "and the mp4 one"); | 11172 | + Format::Av1, |
| 10684 | - assert_eq!(format_key("h"), Some(Format::Hevc), "HEVC's Matroska"); | 11173 | + Format::Av1Mp4, |
| 10685 | - assert_eq!(format_key("x"), Some(Format::HevcMp4), "and its mp4"); | 11174 | + Format::Hevc, |
| 10686 | - assert_eq!(format_key("p"), Some(Format::Mp3)); | 11175 | + Format::HevcMp4, |
| 10687 | - assert_eq!(format_key("m"), Some(Format::Mp4), "not MP3, which is p"); | 11176 | + ] { |
| 11177 | + assert!( | ||
| 11178 | + format.has_video() && bitrate_refusal(format).is_none(), | ||
| 11179 | + "{format:?}" | ||
| 11180 | + ); | ||
| 11181 | + } | ||
| 11182 | + for format in [Format::Wav, Format::Flac, Format::Mp3] { | ||
| 11183 | + assert!(!format.has_video()); | ||
| 11184 | + assert!( | ||
| 11185 | + bitrate_refusal(format).is_some(), | ||
| 11186 | + "{format:?} dims silently" | ||
| 11187 | + ); | ||
| 11188 | + } | ||
| 11189 | + assert!(bitrate_refusal(Format::Wav).unwrap().contains("lossless")); | ||
| 11190 | + assert!(bitrate_refusal(Format::Mp3).unwrap().contains("256 kbps")); | ||
| 10688 | // The destination follows the format and keeps the stem, mp4 included. | 11191 | // The destination follows the format and keeps the stem, mp4 included. |
| 10689 | assert_eq!( | 11192 | assert_eq!( |
| 10690 | retarget(std::path::Path::new("/a/take.export.mp4"), Format::Wav), | 11193 | retarget(std::path::Path::new("/a/take.export.mp4"), Format::Wav), |
| @@ -10694,7 +11197,59 @@ mod tests { | |||
| 10694 | retarget(std::path::Path::new("/a/take.export.wav"), Format::Mp4), | 11197 | retarget(std::path::Path::new("/a/take.export.wav"), Format::Mp4), |
| 10695 | std::path::Path::new("/a/take.export.mp4") | 11198 | std::path::Path::new("/a/take.export.mp4") |
| 10696 | ); | 11199 | ); |
| 10697 | - assert!(format_line(Format::Flac).contains("audio only")); | 11200 | + assert!(format_line(Format::Flac).contains("lossless")); |
| 11201 | + } | ||
| 11202 | + | ||
| 11203 | + /// The one line the card is answerable for: what it says is on screen before | ||
| 11204 | + /// the button is pressed, and every field of it is one `ffprobe` reads back | ||
| 11205 | + /// off the file that comes out. | ||
| 11206 | + #[test] | ||
| 11207 | + fn the_summary_states_the_file_before_it_is_written() { | ||
| 11208 | + let head = summary_head(Format::Mp4, Some(((1920, 1080), 30.)), "AAC copy"); | ||
| 11209 | + for field in ["H.264", "MP4", "1920x1080", "30 fps", "AAC copy"] { | ||
| 11210 | + assert!(head.contains(field), "{field} missing from {head}"); | ||
| 11211 | + } | ||
| 11212 | + // The rate as a person writes it, and the ratio one spelled out rather | ||
| 11213 | + // than rounded to a rate nothing is written at. | ||
| 11214 | + assert_eq!(fps_label(30.), "30"); | ||
| 11215 | + assert_eq!(fps_label(24000. / 1001.), "23.976"); | ||
| 11216 | + assert_eq!(fps_label(29.97002997), "29.97"); | ||
| 11217 | + // A format with no picture states no size and no rate it does not write. | ||
| 11218 | + let audio = summary_head(Format::Wav, Some(((1920, 1080), 30.)), "PCM · SW (hound)"); | ||
| 11219 | + assert!( | ||
| 11220 | + !audio.contains("1920x1080") && !audio.contains("fps"), | ||
| 11221 | + "{audio}" | ||
| 11222 | + ); | ||
| 11223 | + assert!(audio.contains("PCM · SW (hound)")); | ||
| 11224 | + // ...and one with no sound on the timeline says that, rather than | ||
| 11225 | + // leaving the field out and reading as a file with sound in it. | ||
| 11226 | + assert!( | ||
| 11227 | + summary_head(Format::Mp4, Some(((640, 360), 25.)), "no sound to write") | ||
| 11228 | + .contains("no sound to write") | ||
| 11229 | + ); | ||
| 11230 | + // The tail: where it lands, about how big, and what will encode it -- | ||
| 11231 | + // never a guessed seat, and no seat at all for a format with no picture. | ||
| 11232 | + let tail = summary_tail( | ||
| 11233 | + Path::new("/a/take.export.mp4"), | ||
| 11234 | + Some(45), | ||
| 11235 | + Some("VA-API"), | ||
| 11236 | + true, | ||
| 11237 | + ); | ||
| 11238 | + assert!(tail.starts_with("take.export.mp4"), "{tail}"); | ||
| 11239 | + assert!( | ||
| 11240 | + tail.contains("≈ 45 MB") && tail.contains("VA-API"), | ||
| 11241 | + "{tail}" | ||
| 11242 | + ); | ||
| 11243 | + assert!(summary_tail(Path::new("/a/x.mp4"), None, None, true).contains("encoder …")); | ||
| 11244 | + assert!(!summary_tail(Path::new("/a/x.wav"), None, None, false).contains("encoder")); | ||
| 11245 | + assert!(!summary_tail(Path::new("/a/x.wav"), None, None, false).contains("MB")); | ||
| 11246 | + // 6 Mbps over a minute is 45 MB. `Auto` has no figure to estimate from | ||
| 11247 | + // and an empty timeline no length: neither invents one. | ||
| 11248 | + assert_eq!(estimated_mb(Some(6_000_000), 60.), Some(45)); | ||
| 11249 | + assert_eq!(estimated_mb(Some(2_000_000), 90.), Some(23)); | ||
| 11250 | + assert_eq!(estimated_mb(None, 60.), None); | ||
| 11251 | + assert_eq!(estimated_mb(Some(6_000_000), 0.), None); | ||
| 11252 | + assert_eq!(estimated_mb(Some(0), 60.), None); | ||
| 10698 | } | 11253 | } |
| 10699 | 11254 | ||
| 10700 | #[test] | 11255 | #[test] |
| @@ -11178,6 +11733,8 @@ fn main() { | |||
| 11178 | keymap: keymap.clone(), | 11733 | keymap: keymap.clone(), |
| 11179 | keys_open: false, | 11734 | keys_open: false, |
| 11180 | export_open: false, | 11735 | export_open: false, |
| 11736 | + export_grouped: true, | ||
| 11737 | + export_refusals_inline: false, | ||
| 11181 | eq_open: None, | 11738 | eq_open: None, |
| 11182 | // Replaced by the clip's own curve the moment the card | 11739 | // Replaced by the clip's own curve the moment the card |
| 11183 | // opens; nothing reads it before that. | 11740 | // opens; nothing reads it before that. |