The card says what file it is about to write
Browse files at this commit3fbef63f6e195e6a042280768c6a64b1098e5bf8Parent: 303919e- feat
- the card says what file it is about to write
2 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
| @@ -317,7 +317,7 @@ pub struct Fixed { | |||
| 317 | pub category: Category, | 317 | pub category: Category, |
| 318 | } | 318 | } |
| 319 | 319 | ||
| 320 | -pub const FIXED: [Fixed; 16] = [ | 320 | +pub const FIXED: [Fixed; 21] = [ |
| 321 | // Not a chord at all but a way of pressing one, and the only place the | 321 | // Not a chord at all but a way of pressing one, and the only place the |
| 322 | // editor can say so: holding a key that moves a *value* runs it, and | 322 | // editor can say so: holding a key that moves a *value* runs it, and |
| 323 | // holding anything else still does what one press did. | 323 | // holding anything else still does what one press did. |
| @@ -337,9 +337,38 @@ pub const FIXED: [Fixed; 16] = [ | |||
| 337 | category: Category::File, | 337 | category: Category::File, |
| 338 | }, | 338 | }, |
| 339 | Fixed { | 339 | Fixed { |
| 340 | - chord: "m / a / v / h / x / w / f / p", | 340 | + chord: "m / a / h / w / f / p", |
| 341 | - label: "Pick the export format: MP4, AV1 in MKV, AV1 in MP4, HEVC in MKV, \ | 341 | + label: "Pick the export codec: H.264, AV1, HEVC, WAV, FLAC or MP3", |
| 342 | - HEVC in MP4, WAV, FLAC or MP3", | 342 | + category: Category::File, |
| 343 | + }, | ||
| 344 | + // The rest of the export card's own rows, each on the letter its row is | ||
| 345 | + // named after. They shadow the clip keys of the same letter while the card | ||
| 346 | + // is up, exactly as its digits shadow nothing and its arrows would: a modal | ||
| 347 | + // card owns the keyboard, and cutting a clip under it is not a thing that | ||
| 348 | + // can happen anyway. | ||
| 349 | + Fixed { | ||
| 350 | + chord: "c", | ||
| 351 | + label: "Switch the export container: Matroska or MP4", | ||
| 352 | + category: Category::File, | ||
| 353 | + }, | ||
| 354 | + Fixed { | ||
| 355 | + chord: "q", | ||
| 356 | + label: "Step through the export quality rows", | ||
| 357 | + category: Category::File, | ||
| 358 | + }, | ||
| 359 | + Fixed { | ||
| 360 | + chord: "d", | ||
| 361 | + label: "Choose where the export is written", | ||
| 362 | + category: Category::File, | ||
| 363 | + }, | ||
| 364 | + Fixed { | ||
| 365 | + chord: "g", | ||
| 366 | + label: "Export card: sections or one flat list", | ||
| 367 | + category: Category::File, | ||
| 368 | + }, | ||
| 369 | + Fixed { | ||
| 370 | + chord: "r", | ||
| 371 | + label: "Export card: the formats with no encoder as rows or as one line", | ||
| 343 | category: Category::File, | 372 | category: Category::File, |
| 344 | }, | 373 | }, |
| 345 | Fixed { | 374 | Fixed { |
crates/app/src/main.rsmodified+839 -282
| @@ -116,10 +116,28 @@ const KEYS_ROW_H: f32 = HIT_MIN; | |||
| 116 | /// keeps the card inside the smallest window no matter how many actions the | 116 | /// keeps the card inside the smallest window no matter how many actions the |
| 117 | /// editor grows -- ten rows fit here, and the eleventh is a scroll away. | 117 | /// editor grows -- ten rows fit here, and the eleventh is a scroll away. |
| 118 | const KEYS_ROWS_H: f32 = 10. * KEYS_ROW_H; | 118 | const KEYS_ROWS_H: f32 = 10. * KEYS_ROW_H; |
| 119 | -/// The same for the export card, which carries a fixed-format line and a button | 119 | +/// The same for the export card, which carries two summary lines and a button |
| 120 | -/// under its list and so has less room: destination, ten formats and five | 120 | +/// under its list and so has less room: a section header, six codecs, the |
| 121 | -/// qualities are fifteen rows, eight of them on screen. | 121 | +/// container, five qualities and the destination are more rows than a 360 px |
| 122 | +/// window holds. Eight on screen, which is the whole format section and its | ||
| 123 | +/// header -- what a user picks first is never behind a scroll. | ||
| 122 | const EXPORT_ROWS_H: f32 = 8. * KEYS_ROW_H; | 124 | const EXPORT_ROWS_H: f32 = 8. * KEYS_ROW_H; |
| 125 | +/// The export card is wider than the keybindings one: its rows carry a key, a | ||
| 126 | +/// name *and* what the choice means, and the two summary lines under them state | ||
| 127 | +/// the whole file. At `KEYS_W` every one of those wrapped to two lines, which is | ||
| 128 | +/// the card the user called unfriendly. Still inside the 640 px floor with the | ||
| 129 | +/// scrim showing either side of it. | ||
| 130 | +const EXPORT_W: f32 = 420.; | ||
| 131 | +/// The column the key of a row is printed in, wide enough for `0–9`: every row | ||
| 132 | +/// in the export card says what picks it, so the card is drivable by keyboard | ||
| 133 | +/// without a legend to memorise. | ||
| 134 | +const EXPORT_KEY_W: f32 = 26.; | ||
| 135 | +/// Everything in the export card that is *not* the row list: the title, the | ||
| 136 | +/// status line, the head and tail of the summary, the button, the gaps between | ||
| 137 | +/// them and the padding around the lot. What the list may be is the window | ||
| 138 | +/// minus this -- and never less than [`EXPORT_ROWS_H`], which is the number | ||
| 139 | +/// that makes the card fit the 360 px floor. | ||
| 140 | +const EXPORT_FIXED_H: f32 = 17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.; | ||
| 123 | /// The menu a right-click on a clip opens: wide enough for the longest label | 141 | /// The menu a right-click on a clip opens: wide enough for the longest label |
| 124 | /// beside the stroke that does the same thing, with the click targets `HIT_MIN` | 142 | /// beside the stroke that does the same thing, with the click targets `HIT_MIN` |
| 125 | /// binds like every other list here. | 143 | /// binds like every other list here. |
| @@ -714,6 +732,15 @@ struct Player { | |||
| 714 | /// time -- opening either closes the other, since both are the whole window | 732 | /// time -- opening either closes the other, since both are the whole window |
| 715 | /// and two stacked scrims say nothing about which one is listening. | 733 | /// and two stacked scrims say nothing about which one is listening. |
| 716 | export_open: bool, | 734 | export_open: bool, |
| 735 | + /// How the card lays its rows out, and where the formats this program | ||
| 736 | + /// cannot write are said. Two shapes of the same card, kept behind `g` and | ||
| 737 | + /// `r` so the choice between them can be made by looking at both rather | ||
| 738 | + /// than by argument: sections with headers against one flat list, and a | ||
| 739 | + /// collapsed "cannot write" footer against a dimmed row each. The defaults | ||
| 740 | + /// are grouped and collapsed -- the five dead rows used to eat the fold. | ||
| 741 | + /// Not persisted: this is a look, not a setting. | ||
| 742 | + export_grouped: bool, | ||
| 743 | + export_refusals_inline: bool, | ||
| 717 | /// Which quality row the card has picked, and the megabits typed against | 744 | /// Which quality row the card has picked, and the megabits typed against |
| 718 | /// the custom one. Kept across closes, so a second export offers what the | 745 | /// the custom one. Kept across closes, so a second export offers what the |
| 719 | /// first one chose. | 746 | /// first one chose. |
| @@ -3114,6 +3141,38 @@ impl Player { | |||
| 3114 | self.export_path = retarget(&self.export_path, format); | 3141 | self.export_path = retarget(&self.export_path, format); |
| 3115 | } | 3142 | } |
| 3116 | 3143 | ||
| 3144 | + /// The container row: the same codec in the other box, which retargets the | ||
| 3145 | + /// destination exactly as picking a codec does -- and does nothing at all | ||
| 3146 | + /// for a codec with only one box, so the stroke cannot invent a choice the | ||
| 3147 | + /// card is not offering. | ||
| 3148 | + fn cycle_container(&mut self) { | ||
| 3149 | + self.set_format(next_container(self.format)); | ||
| 3150 | + } | ||
| 3151 | + | ||
| 3152 | + /// The quality rows by keyboard, wrapping. Refused by name where the format | ||
| 3153 | + /// has no bitrate to pick: a key that silently does nothing is the card | ||
| 3154 | + /// looking broken. | ||
| 3155 | + fn cycle_quality(&mut self) { | ||
| 3156 | + if let Some(why) = bitrate_refusal(self.format) { | ||
| 3157 | + self.notice = Some(why.into()); | ||
| 3158 | + return; | ||
| 3159 | + } | ||
| 3160 | + let at = Quality::ALL | ||
| 3161 | + .iter() | ||
| 3162 | + .position(|&q| q == self.quality) | ||
| 3163 | + .unwrap_or(0); | ||
| 3164 | + self.quality = Quality::ALL[(at + 1) % Quality::ALL.len()]; | ||
| 3165 | + } | ||
| 3166 | + | ||
| 3167 | + /// The custom bitrate by pointer: the typed digits were the only control in | ||
| 3168 | + /// this card a mouse could not reach. Clamped to the range the row states | ||
| 3169 | + /// (the engine's own 1..20 Mbps), and picking the row is part of the step -- | ||
| 3170 | + /// a stepper that moves a number nobody is using would move nothing. | ||
| 3171 | + fn nudge_mbps(&mut self, step: i32) { | ||
| 3172 | + self.custom_mbps = (self.custom_mbps as i32 + step).clamp(1, 20) as u32; | ||
| 3173 | + self.quality = Quality::Custom; | ||
| 3174 | + } | ||
| 3175 | + | ||
| 3117 | /// The card's Destination row: the desktop's save dialog, on a background | 3176 | /// The card's Destination row: the desktop's save dialog, on a background |
| 3118 | /// thread like the import chooser -- the user may sit in it and the window | 3177 | /// thread like the import chooser -- the user may sit in it and the window |
| 3119 | /// behind must not freeze. No chooser at all leaves the default path, which | 3178 | /// behind must not freeze. No chooser at all leaves the default path, which |
| @@ -3352,16 +3411,35 @@ impl Render for Player { | |||
| 3352 | // The card's own button, by keyboard: the one thing in | 3411 | // The card's own button, by keyboard: the one thing in |
| 3353 | // it that writes a file must not be pointer-only either. | 3412 | // it that writes a file must not be pointer-only either. |
| 3354 | this.start_export(cx); | 3413 | this.start_export(cx); |
| 3355 | - } else if let Some(format) = format_key(key) { | 3414 | + } else if let Some(format) = format_key(key, this.format) { |
| 3356 | - // The format rows by their initial, so the card can be | 3415 | + // The codec rows by their own letter, so the card can be |
| 3357 | // driven without a mouse -- the same card-local input | 3416 | // driven without a mouse -- the same card-local input |
| 3358 | // the typed bitrate is, and for the same reason: a | 3417 | // the typed bitrate is, and for the same reason: a |
| 3359 | // choice reachable only by pointer is not reachable by | 3418 | // choice reachable only by pointer is not reachable by |
| 3360 | // everyone. Not a keymap binding: it means nothing | 3419 | // everyone. Not a keymap binding: it means nothing |
| 3361 | // outside this card, exactly like the digits. | 3420 | // outside this card, exactly like the digits. |
| 3362 | this.set_format(format); | 3421 | this.set_format(format); |
| 3422 | + } else if key == "c" { | ||
| 3423 | + this.cycle_container(); | ||
| 3424 | + } else if key == "q" { | ||
| 3425 | + this.cycle_quality(); | ||
| 3426 | + } else if key == "d" { | ||
| 3427 | + // The save dialog, which was the one row here a | ||
| 3428 | + // keyboard could not open. | ||
| 3429 | + this.pick_destination(cx); | ||
| 3430 | + } else if key == "g" { | ||
| 3431 | + this.export_grouped = !this.export_grouped; | ||
| 3432 | + } else if key == "r" { | ||
| 3433 | + this.export_refusals_inline = !this.export_refusals_inline; | ||
| 3363 | } else if let Ok(digit) = key.parse::<u32>() { | 3434 | } else if let Ok(digit) = key.parse::<u32>() { |
| 3364 | - this.custom_mbps = push_digit(this.custom_mbps, digit); | 3435 | + let next = push_digit(this.custom_mbps, digit); |
| 3436 | + // A refused third digit says so: it used to be dropped | ||
| 3437 | + // in silence, which left the card showing a number the | ||
| 3438 | + // user had already typed past. | ||
| 3439 | + if next == this.custom_mbps && this.custom_mbps > 0 { | ||
| 3440 | + this.notice = Some("1–20 Mbps — a third digit is refused".into()); | ||
| 3441 | + } | ||
| 3442 | + this.custom_mbps = next; | ||
| 3365 | this.quality = Quality::Custom; | 3443 | this.quality = Quality::Custom; |
| 3366 | } else if key == "backspace" { | 3444 | } else if key == "backspace" { |
| 3367 | this.custom_mbps /= 10; | 3445 | this.custom_mbps /= 10; |
| @@ -3699,7 +3777,7 @@ impl Render for Player { | |||
| 3699 | // Last, so they are over everything -- they take no room in the | 3777 | // Last, so they are over everything -- they take no room in the |
| 3700 | // column, and only one of the two is ever up. | 3778 | // column, and only one of the two is ever up. |
| 3701 | .children(self.keys_overlay(cx)) | 3779 | .children(self.keys_overlay(cx)) |
| 3702 | - .children(self.export_card(cx)) | 3780 | + .children(self.export_card(window.viewport_size(), cx)) |
| 3703 | .children(self.eq_card(cx)) | 3781 | .children(self.eq_card(cx)) |
| 3704 | .children(self.color_card(cx)) | 3782 | .children(self.color_card(cx)) |
| 3705 | .children(self.speed_card(cx)) | 3783 | .children(self.speed_card(cx)) |
| @@ -4681,16 +4759,33 @@ impl Player { | |||
| 4681 | ) | 4759 | ) |
| 4682 | } | 4760 | } |
| 4683 | 4761 | ||
| 4684 | - /// What an export is going to be, before there is one: the destination, the | 4762 | + /// What an export is going to be, before there is one: the codec, the box |
| 4685 | - /// quality rows, and the two things that are not a choice at all. The same | 4763 | + /// it goes into, the bitrate, where it lands -- and, above the button, the |
| 4686 | - /// scrim, width and row shape as the keybindings overlay -- two cards of | 4764 | + /// two lines that state the file all of that adds up to. The same scrim and |
| 4687 | - /// different builds over one window read as two different programs -- and | 4765 | + /// row shape as the keybindings overlay (two cards of different builds over |
| 4688 | - /// the same plain divs, so the root keeps the keyboard and a typed digit | 4766 | + /// one window read as two different programs) and the same plain divs, so |
| 4689 | - /// reaches the custom row. | 4767 | + /// the root keeps the keyboard and a typed digit reaches the custom row. |
| 4690 | - fn export_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | 4768 | + /// |
| 4769 | + /// Every row carries the key that picks it, so the card is drivable end to | ||
| 4770 | + /// end without a pointer *and* without a legend to memorise -- and every | ||
| 4771 | + /// row is clickable, the bitrate's steppers included, so it is drivable end | ||
| 4772 | + /// to end without a keyboard as well. | ||
| 4773 | + /// | ||
| 4774 | + /// Two shapes of it, behind `g` and `r`: sections against one flat list, | ||
| 4775 | + /// and the codecs with no encoder collapsed into a footer against a dimmed | ||
| 4776 | + /// row each. Grouped and collapsed is what opens. | ||
| 4777 | + fn export_card( | ||
| 4778 | + &self, | ||
| 4779 | + viewport: Size<Pixels>, | ||
| 4780 | + cx: &mut Context<Self>, | ||
| 4781 | + ) -> Option<impl IntoElement> { | ||
| 4691 | if !self.export_open { | 4782 | if !self.export_open { |
| 4692 | return None; | 4783 | return None; |
| 4693 | } | 4784 | } |
| 4785 | + // The cap is what keeps the card inside the smallest window; a taller | ||
| 4786 | + // one gets a taller list rather than a scroll past empty space, and the | ||
| 4787 | + // card is still only as tall as the rows it has. | ||
| 4788 | + let rows_h = (f32::from(viewport.height) - EXPORT_FIXED_H - 24.).max(EXPORT_ROWS_H); | ||
| 4694 | let row = |id: (&'static str, usize)| { | 4789 | let row = |id: (&'static str, usize)| { |
| 4695 | div() | 4790 | div() |
| 4696 | .id(id) | 4791 | .id(id) |
| @@ -4707,70 +4802,261 @@ impl Player { | |||
| 4707 | // A row that cannot be picked is dimmed and takes no click, exactly as | 4802 | // A row that cannot be picked is dimmed and takes no click, exactly as |
| 4708 | // an inapplicable item in the clip menu is: it still says its piece. | 4803 | // an inapplicable item in the clip menu is: it still says its piece. |
| 4709 | let live = |d: Stateful<Div>, enabled: bool| { | 4804 | let live = |d: Stateful<Div>, enabled: bool| { |
| 4710 | - d.when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | 4805 | + d.when(!enabled, |d| { |
| 4711 | - .when(enabled, |d| d.cursor_pointer().hover(|s| s.bg(rgb(HOVER)))) | 4806 | + d.cursor_not_allowed().text_color(rgb(INK_DIM)) |
| 4807 | + }) | ||
| 4808 | + .when(enabled, |d| d.cursor_pointer().hover(|s| s.bg(rgb(HOVER)))) | ||
| 4712 | }; | 4809 | }; |
| 4713 | - // The formats first: the quality rows below are *video* bitrate, so | 4810 | + // A row as this card writes them: the mark saying which one is picked, |
| 4714 | - // which file is being written decides whether they mean anything. | 4811 | + // the key that picks it, its name, and what the choice means. The mark |
| 4715 | - // An mp4 this timeline cannot be written as reads exactly like the | 4812 | + // is a glyph and not only a colour -- a background alone is gone the |
| 4716 | - // formats there is no encoder for: dimmed, unclickable, and carrying its | 4813 | + // moment a hover lands on the row, and invisible to anyone who cannot |
| 4717 | - // own reason instead of the detail line. | 4814 | + // tell the two greys apart (WCAG 1.4.1). |
| 4718 | - let formats: Vec<_> = FORMATS | 4815 | + let entry = |id: (&'static str, usize), |
| 4719 | - .into_iter() | 4816 | + key: &str, |
| 4720 | - .enumerate() | 4817 | + label: SharedString, |
| 4721 | - .map(|(i, (format, _, label, detail))| { | 4818 | + detail: SharedString, |
| 4722 | - // Per row, because the two picture formats are refused by | 4819 | + picked: bool, |
| 4723 | - // different things: an audio-only timeline greys both, a second | 4820 | + enabled: bool| { |
| 4724 | - // audio lane only the mp4. | 4821 | + // The small print of a picked row sits on the highlight, where the |
| 4725 | - let refused = format | 4822 | + // dim ink is only 3.3:1 -- the row it lands on lifts it (WCAG |
| 4726 | - .zip(self.session.as_ref()) | 4823 | + // 1.4.3, and the fit test pins both numbers). |
| 4727 | - .and_then(|(f, s)| format_refusal(s, f)); | 4824 | + let ink = match picked { |
| 4728 | - let blocked = refused.is_some(); | 4825 | + true => INK, |
| 4729 | - let detail: SharedString = match &refused { | 4826 | + false => INK_DIM, |
| 4730 | - Some(why) => why.clone().into(), | 4827 | + }; |
| 4731 | - None => detail.into(), | 4828 | + live(row(id), enabled) |
| 4732 | - }; | 4829 | + .when(picked, |d| d.bg(rgb(SELECTED))) |
| 4733 | - let picked = format == Some(self.format) && !blocked; | 4830 | + .child( |
| 4734 | - let format = format.filter(|_| !blocked); | 4831 | + div() |
| 4735 | - live(row(("format", i)), format.is_some()) | 4832 | + .flex() |
| 4736 | - .when(picked, |d| d.bg(rgb(SELECTED))) | 4833 | + .flex_none() |
| 4737 | - .when_some(format, |d, format| { | 4834 | + .items_center() |
| 4738 | - d.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 4835 | + .gap(px(8.)) |
| 4739 | - this.set_format(format); | 4836 | + .child(div().w(px(10.)).child(match picked { |
| 4740 | - cx.notify(); | 4837 | + true => "✓", |
| 4838 | + false => " ", | ||
| 4741 | })) | 4839 | })) |
| 4742 | - }) | 4840 | + .child( |
| 4743 | - .child(label) | 4841 | + div() |
| 4744 | - .child( | 4842 | + .w(px(EXPORT_KEY_W)) |
| 4745 | - div() | 4843 | + .text_size(px(11.)) |
| 4746 | - .text_size(px(11.)) | 4844 | + .text_color(rgb(ink)) |
| 4747 | - .text_color(rgb(INK_DIM)) | 4845 | + .child(SharedString::from(key.to_string())), |
| 4748 | - .child(detail), | 4846 | + ) |
| 4847 | + .child(label), | ||
| 4848 | + ) | ||
| 4849 | + // Wraps rather than runs off the row: a refusal is the longest | ||
| 4850 | + // thing in this column and the half of it past the edge is the | ||
| 4851 | + // half that says what to do instead. | ||
| 4852 | + .child( | ||
| 4853 | + div() | ||
| 4854 | + .min_w(px(0.)) | ||
| 4855 | + .flex_shrink() | ||
| 4856 | + .text_size(px(11.)) | ||
| 4857 | + .text_color(rgb(ink)) | ||
| 4858 | + .child(detail), | ||
| 4859 | + ) | ||
| 4860 | + }; | ||
| 4861 | + let header = |text: &'static str| { | ||
| 4862 | + div() | ||
| 4863 | + .flex_none() | ||
| 4864 | + .px(px(6.)) | ||
| 4865 | + .pt(px(4.)) | ||
| 4866 | + .text_size(px(10.)) | ||
| 4867 | + .text_color(rgb(INK_DIM)) | ||
| 4868 | + .child(text) | ||
| 4869 | + .into_any_element() | ||
| 4870 | + }; | ||
| 4871 | + let mut list: Vec<AnyElement> = Vec::new(); | ||
| 4872 | + if self.export_grouped { | ||
| 4873 | + list.push(header("FORMAT")); | ||
| 4874 | + } | ||
| 4875 | + // The codecs first: which one is being written decides whether every | ||
| 4876 | + // row under it means anything. One a *this* timeline cannot be written | ||
| 4877 | + // as (an audio-only edit, for a picture codec) reads exactly like one | ||
| 4878 | + // there is no encoder for -- dimmed, unclickable, and carrying its own | ||
| 4879 | + // reason where its detail was, with nothing to click to find that out. | ||
| 4880 | + let mut refusals: Vec<String> = Vec::new(); | ||
| 4881 | + for (i, (boxes, key, label, detail)) in FORMATS.into_iter().enumerate() { | ||
| 4882 | + let format = same_box(boxes, self.format); | ||
| 4883 | + let refused = format | ||
| 4884 | + .zip(self.session.as_ref()) | ||
| 4885 | + .and_then(|(f, s)| format_refusal(s, f)); | ||
| 4886 | + // A codec with no encoder here at all is the other kind of refusal, | ||
| 4887 | + // and the one the footer collects: it can never become pickable, so | ||
| 4888 | + // a row each is dead rows above the fold. | ||
| 4889 | + if format.is_none() { | ||
| 4890 | + refusals.push(format!("{label} — {detail}")); | ||
| 4891 | + if !self.export_refusals_inline { | ||
| 4892 | + continue; | ||
| 4893 | + } | ||
| 4894 | + } | ||
| 4895 | + let detail: SharedString = match &refused { | ||
| 4896 | + Some(why) => why.clone().into(), | ||
| 4897 | + None => detail.into(), | ||
| 4898 | + }; | ||
| 4899 | + let format = format.filter(|_| refused.is_none()); | ||
| 4900 | + let mut r = entry( | ||
| 4901 | + ("format", i), | ||
| 4902 | + key, | ||
| 4903 | + label.into(), | ||
| 4904 | + detail, | ||
| 4905 | + boxes.contains(&self.format), | ||
| 4906 | + format.is_some(), | ||
| 4907 | + ); | ||
| 4908 | + if let Some(format) = format { | ||
| 4909 | + r = r.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 4910 | + this.set_format(format); | ||
| 4911 | + cx.notify(); | ||
| 4912 | + })); | ||
| 4913 | + } | ||
| 4914 | + list.push(r.into_any_element()); | ||
| 4915 | + } | ||
| 4916 | + if self.export_grouped { | ||
| 4917 | + list.push(header("DETAILS")); | ||
| 4918 | + } | ||
| 4919 | + // The container, and only where the picked codec has more than one box: | ||
| 4920 | + // a row offering a single choice reads as a choice. | ||
| 4921 | + let boxes = containers(self.format); | ||
| 4922 | + if boxes.len() > 1 { | ||
| 4923 | + let next = next_container(self.format); | ||
| 4924 | + list.push( | ||
| 4925 | + entry( | ||
| 4926 | + ("container", 0), | ||
| 4927 | + "c", | ||
| 4928 | + "Container".into(), | ||
| 4929 | + format!( | ||
| 4930 | + "{} — c for {}", | ||
| 4931 | + self.format.ext().to_uppercase(), | ||
| 4932 | + next.ext().to_uppercase() | ||
| 4749 | ) | 4933 | ) |
| 4750 | - }) | 4934 | + .into(), |
| 4751 | - .collect(); | 4935 | + false, |
| 4752 | - let video = self.format.has_video(); | 4936 | + true, |
| 4753 | - let rows: Vec<_> = Quality::ALL | 4937 | + ) |
| 4754 | - .into_iter() | 4938 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { |
| 4755 | - .enumerate() | 4939 | + this.cycle_container(); |
| 4756 | - .map(|(i, quality)| { | 4940 | + cx.notify(); |
| 4757 | - live(row(("quality", i)), video) | 4941 | + })) |
| 4758 | - .when(video && self.quality == quality, |d| d.bg(rgb(SELECTED))) | 4942 | + .into_any_element(), |
| 4759 | - .when(video, |d| { | 4943 | + ); |
| 4760 | - d.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 4944 | + } |
| 4945 | + match bitrate_refusal(self.format) { | ||
| 4946 | + // One dimmed row carrying the reason, rather than five rows of a | ||
| 4947 | + // figure that will not be written: the quality rows are the | ||
| 4948 | + // *picture's* bitrate, and this file has no picture in it. | ||
| 4949 | + Some(why) => list.push( | ||
| 4950 | + entry( | ||
| 4951 | + ("quality", 0), | ||
| 4952 | + "q", | ||
| 4953 | + "Quality".into(), | ||
| 4954 | + why.into(), | ||
| 4955 | + false, | ||
| 4956 | + false, | ||
| 4957 | + ) | ||
| 4958 | + .into_any_element(), | ||
| 4959 | + ), | ||
| 4960 | + None => { | ||
| 4961 | + for (i, quality) in Quality::ALL.into_iter().enumerate() { | ||
| 4962 | + let mut r = entry( | ||
| 4963 | + ("quality", i), | ||
| 4964 | + match quality { | ||
| 4965 | + // The one row a key does not step to but types | ||
| 4966 | + // into, which is what its key column says. | ||
| 4967 | + Quality::Custom => "0–9", | ||
| 4968 | + _ => "q", | ||
| 4969 | + }, | ||
| 4970 | + quality.label().into(), | ||
| 4971 | + quality.detail(self.custom_mbps).into(), | ||
| 4972 | + self.quality == quality, | ||
| 4973 | + true, | ||
| 4974 | + ) | ||
| 4975 | + .on_click(cx.listener( | ||
| 4976 | + move |this, _: &ClickEvent, _, cx| { | ||
| 4761 | this.quality = quality; | 4977 | this.quality = quality; |
| 4762 | cx.notify(); | 4978 | cx.notify(); |
| 4763 | - })) | 4979 | + }, |
| 4764 | - }) | 4980 | + )); |
| 4765 | - .child(quality.label()) | 4981 | + if quality == Quality::Custom { |
| 4766 | - .child( | 4982 | + r = r.child(self.mbps_steppers(cx)); |
| 4767 | - div() | 4983 | + } |
| 4768 | - .text_size(px(11.)) | 4984 | + list.push(r.into_any_element()); |
| 4769 | - .text_color(rgb(INK_DIM)) | 4985 | + } |
| 4770 | - .child(quality.detail(self.custom_mbps)), | 4986 | + } |
| 4771 | - ) | 4987 | + } |
| 4772 | - }) | 4988 | + let destination = entry( |
| 4773 | - .collect(); | 4989 | + ("destination", 0), |
| 4990 | + "d", | ||
| 4991 | + "Destination".into(), | ||
| 4992 | + file_name(&self.export_path).into(), | ||
| 4993 | + false, | ||
| 4994 | + true, | ||
| 4995 | + ) | ||
| 4996 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))) | ||
| 4997 | + .into_any_element(); | ||
| 4998 | + match self.export_grouped { | ||
| 4999 | + true => list.push(destination), | ||
| 5000 | + // Flat: the same rows with no headers over them, and the | ||
| 5001 | + // destination back at the top where the card used to open with it. | ||
| 5002 | + false => list.insert(0, destination), | ||
| 5003 | + } | ||
| 5004 | + if !self.export_refusals_inline && !refusals.is_empty() { | ||
| 5005 | + // Last, and one line: the reason travels with the name (a footer | ||
| 5006 | + // that only listed them would be the "why not?" the rows exist to | ||
| 5007 | + // answer), but nothing here can ever be picked, so it sits under | ||
| 5008 | + // every row that can rather than above them. | ||
| 5009 | + list.push( | ||
| 5010 | + div() | ||
| 5011 | + .flex_none() | ||
| 5012 | + .px(px(6.)) | ||
| 5013 | + .py(px(2.)) | ||
| 5014 | + .text_size(px(11.)) | ||
| 5015 | + .text_color(rgb(INK_DIM)) | ||
| 5016 | + .child(format!("cannot write: {}", refusals.join(" · "))) | ||
| 5017 | + .into_any_element(), | ||
| 5018 | + ); | ||
| 5019 | + } | ||
| 5020 | + // What the rows add up to, which is the one thing that has to be right: | ||
| 5021 | + // codec, box, size, rate, sound, where it goes and about how big. Two | ||
| 5022 | + // lines, outside the scrolling list, so it is on screen whatever the | ||
| 5023 | + // list is scrolled to and whatever is picked. | ||
| 5024 | + let picture = self | ||
| 5025 | + .session | ||
| 5026 | + .as_ref() | ||
| 5027 | + .map(|s| (s.resolution(), s.meta().frame_rate)); | ||
| 5028 | + let audio = self | ||
| 5029 | + .session | ||
| 5030 | + .as_ref() | ||
| 5031 | + .map_or("", |s| s.planned_audio(self.format)); | ||
| 5032 | + let settings = export_settings(self.quality, self.custom_mbps, self.format); | ||
| 5033 | + let mb = estimated_mb( | ||
| 5034 | + settings.bitrate.filter(|_| self.format.has_video()), | ||
| 5035 | + self.session | ||
| 5036 | + .as_ref() | ||
| 5037 | + .map_or(0., PlaybackSession::timeline_duration), | ||
| 5038 | + ); | ||
| 5039 | + let head = summary_head(self.format, picture, audio); | ||
| 5040 | + let tail = summary_tail( | ||
| 5041 | + &self.export_path, | ||
| 5042 | + mb, | ||
| 5043 | + self.export_seat.and_then(|(.., seat)| seat), | ||
| 5044 | + self.format.has_video(), | ||
| 5045 | + ); | ||
| 5046 | + // The button says the refusal *before* it is pressed: the picked codec | ||
| 5047 | + // can go invalid one edit after it was picked (a cleared video lane), | ||
| 5048 | + // and a button that looks ready until it is pressed is the lie the | ||
| 5049 | + // dimmed rows above it are there to avoid. | ||
| 5050 | + let blocked = self | ||
| 5051 | + .session | ||
| 5052 | + .as_ref() | ||
| 5053 | + .and_then(|s| format_refusal(s, self.format)); | ||
| 5054 | + let action: SharedString = match &blocked { | ||
| 5055 | + Some(why) => { | ||
| 5056 | + format!("Cannot export — {}", why.split(" — ").next().unwrap_or(why)).into() | ||
| 5057 | + } | ||
| 5058 | + None => "Export".into(), | ||
| 5059 | + }; | ||
| 4774 | Some( | 5060 | Some( |
| 4775 | div() | 5061 | div() |
| 4776 | .absolute() | 5062 | .absolute() |
| @@ -4784,7 +5070,7 @@ impl Player { | |||
| 4784 | }) | 5070 | }) |
| 4785 | .child( | 5071 | .child( |
| 4786 | div() | 5072 | div() |
| 4787 | - .w(px(KEYS_W)) | 5073 | + .w(px(EXPORT_W)) |
| 4788 | .flex() | 5074 | .flex() |
| 4789 | .flex_col() | 5075 | .flex_col() |
| 4790 | .gap(px(2.)) | 5076 | .gap(px(2.)) |
| @@ -4794,7 +5080,9 @@ impl Player { | |||
| 4794 | .child(div().flex_none().px(px(6.)).child("Export")) | 5080 | .child(div().flex_none().px(px(6.)).child("Export")) |
| 4795 | // The status line, where a refusal from the save dialog | 5081 | // The status line, where a refusal from the save dialog |
| 4796 | // lands: the notice bar it would otherwise take is under | 5082 | // lands: the notice bar it would otherwise take is under |
| 4797 | - // the scrim. | 5083 | + // the scrim. The keys are on the rows, so this says how |
| 5084 | + // the card as a whole is answered rather than listing | ||
| 5085 | + // them a second time. | ||
| 4798 | .child( | 5086 | .child( |
| 4799 | div() | 5087 | div() |
| 4800 | .flex_none() | 5088 | .flex_none() |
| @@ -4802,56 +5090,33 @@ impl Player { | |||
| 4802 | .text_size(px(11.)) | 5090 | .text_size(px(11.)) |
| 4803 | .text_color(rgb(INK_DIM)) | 5091 | .text_color(rgb(INK_DIM)) |
| 4804 | .child(self.notice.clone().unwrap_or_else(|| { | 5092 | .child(self.notice.clone().unwrap_or_else(|| { |
| 4805 | - "pick a format (m/a/v/h/x/w/f/p), then Export — esc closes" | 5093 | + "the keys are on the rows · enter exports · esc closes · \ |
| 5094 | + g/r change the layout" | ||
| 4806 | .into() | 5095 | .into() |
| 4807 | })), | 5096 | })), |
| 4808 | ) | 5097 | ) |
| 4809 | // Capped and scrolling like the keybindings list: the | 5098 | // Capped and scrolling like the keybindings list: the |
| 4810 | - // destination, ten formats and five qualities are more | 5099 | + // rows are more than a 360 px window has room for, and |
| 4811 | - // rows than a 360 px window has room for, and it is the | 5100 | + // it is the list that scrolls, never the card that |
| 4812 | - // list that scrolls, never the card that grows. | 5101 | + // grows -- the summary and the button below stay put. |
| 4813 | .child( | 5102 | .child( |
| 4814 | div() | 5103 | div() |
| 4815 | .id("export-rows") | 5104 | .id("export-rows") |
| 4816 | .flex() | 5105 | .flex() |
| 4817 | .flex_col() | 5106 | .flex_col() |
| 4818 | .gap(px(2.)) | 5107 | .gap(px(2.)) |
| 4819 | - .max_h(px(EXPORT_ROWS_H)) | 5108 | + .max_h(px(rows_h)) |
| 4820 | .overflow_y_scroll() | 5109 | .overflow_y_scroll() |
| 4821 | - .child( | 5110 | + .children(list), |
| 4822 | - live(row(("destination", 0)), true) | ||
| 4823 | - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 4824 | - this.pick_destination(cx) | ||
| 4825 | - })) | ||
| 4826 | - .child("Destination") | ||
| 4827 | - .child( | ||
| 4828 | - div() | ||
| 4829 | - .text_size(px(11.)) | ||
| 4830 | - .text_color(rgb(INK_DIM)) | ||
| 4831 | - .child(file_name(&self.export_path)), | ||
| 4832 | - ), | ||
| 4833 | - ) | ||
| 4834 | - .children(formats) | ||
| 4835 | - .children(rows), | ||
| 4836 | ) | 5111 | ) |
| 4837 | - // What the picked row really writes. `moov` last is the | 5112 | + .child(div().flex_none().px(px(6.)).text_size(px(11.)).child(head)) |
| 4838 | - // muxer's own shape -- an mp4 is playable only once it | ||
| 4839 | - // is finished. The project's resolution is on the same | ||
| 4840 | - // line because it *is* what the file comes out at, | ||
| 4841 | - // whatever size the media on the timeline are: this is | ||
| 4842 | - // the one place the number is shown, and ctrl+r is what | ||
| 4843 | - // changes it. | ||
| 4844 | .child( | 5113 | .child( |
| 4845 | div() | 5114 | div() |
| 4846 | .flex_none() | 5115 | .flex_none() |
| 4847 | .px(px(6.)) | 5116 | .px(px(6.)) |
| 4848 | .text_size(px(11.)) | 5117 | .text_size(px(11.)) |
| 4849 | .text_color(rgb(INK_DIM)) | 5118 | .text_color(rgb(INK_DIM)) |
| 4850 | - .child(export_line( | 5119 | + .child(tail), |
| 4851 | - self.format, | ||
| 4852 | - self.session.as_ref(), | ||
| 4853 | - self.export_seat.and_then(|(.., seat)| seat), | ||
| 4854 | - )), | ||
| 4855 | ) | 5120 | ) |
| 4856 | .child( | 5121 | .child( |
| 4857 | div() | 5122 | div() |
| @@ -4862,7 +5127,10 @@ impl Player { | |||
| 4862 | .items_center() | 5127 | .items_center() |
| 4863 | .justify_center() | 5128 | .justify_center() |
| 4864 | .rounded(px(3.)) | 5129 | .rounded(px(3.)) |
| 4865 | - .bg(rgb(SELECTED)) | 5130 | + .bg(rgb(match blocked.is_some() { |
| 5131 | + true => CHROME, | ||
| 5132 | + false => SELECTED, | ||
| 5133 | + })) | ||
| 4866 | .cursor_pointer() | 5134 | .cursor_pointer() |
| 4867 | .hover(|s| s.bg(rgb(HOVER))) | 5135 | .hover(|s| s.bg(rgb(HOVER))) |
| 4868 | .on_click( | 5136 | .on_click( |
| @@ -4870,12 +5138,42 @@ impl Player { | |||
| 4870 | this.start_export(cx) | 5138 | this.start_export(cx) |
| 4871 | }), | 5139 | }), |
| 4872 | ) | 5140 | ) |
| 4873 | - .child("Export"), | 5141 | + .child(action), |
| 4874 | ), | 5142 | ), |
| 4875 | ), | 5143 | ), |
| 4876 | ) | 5144 | ) |
| 4877 | } | 5145 | } |
| 4878 | 5146 | ||
| 5147 | + /// The custom bitrate's two pointer buttons. The typed digits were the last | ||
| 5148 | + /// control in this card a mouse could not reach at all -- and a number that | ||
| 5149 | + /// can only be typed is a number a hand on the pointer has to leave the | ||
| 5150 | + /// card to change. `HIT_MIN` square, like every other target here. | ||
| 5151 | + fn mbps_steppers(&self, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 5152 | + let step = |id: &'static str, label: &'static str, by: i32, cx: &mut Context<Self>| { | ||
| 5153 | + div() | ||
| 5154 | + .id(id) | ||
| 5155 | + .flex() | ||
| 5156 | + .w(px(HIT_MIN)) | ||
| 5157 | + .h(px(HIT_MIN)) | ||
| 5158 | + .items_center() | ||
| 5159 | + .justify_center() | ||
| 5160 | + .rounded(px(3.)) | ||
| 5161 | + .bg(rgb(CHROME)) | ||
| 5162 | + .cursor_pointer() | ||
| 5163 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 5164 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 5165 | + this.nudge_mbps(by); | ||
| 5166 | + cx.notify(); | ||
| 5167 | + })) | ||
| 5168 | + .child(label) | ||
| 5169 | + }; | ||
| 5170 | + div() | ||
| 5171 | + .flex() | ||
| 5172 | + .gap(px(4.)) | ||
| 5173 | + .child(step("mbps-down", "−", -1, cx)) | ||
| 5174 | + .child(step("mbps-up", "+", 1, cx)) | ||
| 5175 | + } | ||
| 5176 | + | ||
| 4879 | /// The equalizer of one audio clip: its frequency response drawn as a | 5177 | /// The equalizer of one audio clip: its frequency response drawn as a |
| 4880 | /// curve, a handle per band sitting on it, and a row that flattens them | 5178 | /// curve, a handle per band sitting on it, and a row that flattens them |
| 4881 | /// all. The curve is the clip's actual filter (`EqParams::response_db` | 5179 | /// all. The curve is the clip's actual filter (`EqParams::response_db` |
| @@ -6954,58 +7252,97 @@ impl Quality { | |||
| 6954 | /// for. AAC is not a row at all: it is what both containers' sound *is*, never a | 7252 | /// for. AAC is not a row at all: it is what both containers' sound *is*, never a |
| 6955 | /// file of its own. | 7253 | /// file of its own. |
| 6956 | /// | 7254 | /// |
| 6957 | -/// AV1 is two rows because a codec and a container are two choices: the same | 7255 | +/// A codec is one row, and the boxes it can be written into are the row's |
| 6958 | -/// picture and the same AAC track go into a Matroska file or into an mp4, and | 7256 | +/// containers: the same AV1 picture and the same AAC track go into a Matroska |
| 6959 | -/// which one a user needs is about what has to play the file, not about the | 7257 | +/// file or into an mp4, and which one a user needs is about what has to play |
| 6960 | -/// encode. HEVC is two rows for the same reason. | 7258 | +/// the file, not about the encode. So the container is asked *once*, in a row |
| 6961 | -const FORMATS: [(Option<Format>, &str, &str, &str); 10] = [ | 7259 | +/// of its own, and only where there is more than one to ask about -- five |
| 6962 | - (Some(Format::Mp4), "m", "MP4", "H.264 picture + AAC sound"), | 7260 | +/// picture rows to read past were four of them saying the same codec twice. |
| 7261 | +const FORMATS: [(&[Format], &str, &str, &str); 8] = [ | ||
| 6963 | ( | 7262 | ( |
| 6964 | - Some(Format::Av1), | 7263 | + &[Format::Mp4], |
| 6965 | - "a", | 7264 | + "m", |
| 6966 | - "AV1 · MKV", | 7265 | + "H.264", |
| 6967 | - "AV1 picture + AAC sound in .mkv", | 7266 | + "plays everywhere · AAC sound · MP4 only", |
| 6968 | ), | 7267 | ), |
| 6969 | ( | 7268 | ( |
| 6970 | - Some(Format::Av1Mp4), | 7269 | + &[Format::Av1, Format::Av1Mp4], |
| 6971 | - "v", | 7270 | + "a", |
| 6972 | - "AV1 · MP4", | 7271 | + "AV1", |
| 6973 | - "the same AV1 picture and sound in .mp4", | 7272 | + "smallest file for the picture · AAC sound", |
| 6974 | ), | 7273 | ), |
| 6975 | ( | 7274 | ( |
| 6976 | - Some(Format::Hevc), | 7275 | + &[Format::Hevc, Format::HevcMp4], |
| 6977 | "h", | 7276 | "h", |
| 6978 | - "HEVC · MKV", | 7277 | + "HEVC", |
| 6979 | - "intra-only HEVC + AAC in .mkv — large files", | 7278 | + "intra-only, every frame a cut point — large files", |
| 6980 | - ), | ||
| 6981 | - ( | ||
| 6982 | - Some(Format::HevcMp4), | ||
| 6983 | - "x", | ||
| 6984 | - "HEVC · MP4", | ||
| 6985 | - "the same intra-only HEVC and sound in .mp4", | ||
| 6986 | ), | 7279 | ), |
| 6987 | - (Some(Format::Wav), "w", "WAV", "16-bit PCM — audio only"), | 7280 | + (&[Format::Wav], "w", "WAV", "16-bit PCM — audio only"), |
| 6988 | - (Some(Format::Flac), "f", "FLAC", "lossless — audio only"), | 7281 | + (&[Format::Flac], "f", "FLAC", "lossless — audio only"), |
| 6989 | ( | 7282 | ( |
| 6990 | - Some(Format::Mp3), | 7283 | + &[Format::Mp3], |
| 6991 | "p", | 7284 | "p", |
| 6992 | "MP3", | 7285 | "MP3", |
| 6993 | "MPEG-1 Layer III, 256 kbps — audio only", | 7286 | "MPEG-1 Layer III, 256 kbps — audio only", |
| 6994 | ), | 7287 | ), |
| 6995 | - (None, "", "OGG", "no pure-Rust Vorbis or Opus encoder"), | 7288 | + (&[], "", "OGG", "no pure-Rust Vorbis or Opus encoder"), |
| 6996 | - (None, "", "VP9", "superseded by AV1, which is the row above"), | 7289 | + (&[], "", "VP9", "AV1 above replaces it"), |
| 6997 | ]; | 7290 | ]; |
| 6998 | 7291 | ||
| 6999 | -/// The format a key picks while the export card is up. A letter of the row's | 7292 | +/// The codec row a key picks, landed in the container already chosen: pressing |
| 7000 | -/// own name, spelled out in the table rather than taken from the initial: `MP4` | 7293 | +/// `a` after an mp4 gives AV1 *in mp4*, because a box decided once is not a |
| 7001 | -/// and `MP3` share one, and so do the two AV1 containers, so an initial cannot | 7294 | +/// question again. A letter of the row's own name, spelled out in the table |
| 7002 | -/// tell six rows apart. Never a digit -- those are the bitrate's. `None` for | 7295 | +/// rather than taken from the initial (`MP4` and `MP3` share one). Never a |
| 7003 | -/// everything else, the rows that cannot be picked included. | 7296 | +/// digit -- those are the bitrate's. `None` for every other stroke, the rows |
| 7004 | -fn format_key(key: &str) -> Option<Format> { | 7297 | +/// that cannot be picked included. |
| 7298 | +fn format_key(key: &str, current: Format) -> Option<Format> { | ||
| 7005 | FORMATS | 7299 | FORMATS |
| 7006 | .into_iter() | 7300 | .into_iter() |
| 7007 | .filter(|(_, stroke, ..)| !stroke.is_empty() && stroke.eq_ignore_ascii_case(key)) | 7301 | .filter(|(_, stroke, ..)| !stroke.is_empty() && stroke.eq_ignore_ascii_case(key)) |
| 7008 | - .find_map(|(format, ..)| format) | 7302 | + .find_map(|(row, ..)| same_box(row, current)) |
| 7303 | +} | ||
| 7304 | + | ||
| 7305 | +/// The boxes one codec may be written into, in the order its container row | ||
| 7306 | +/// cycles them. Empty for a codec this program cannot write at all. | ||
| 7307 | +fn containers(format: Format) -> &'static [Format] { | ||
| 7308 | + FORMATS | ||
| 7309 | + .into_iter() | ||
| 7310 | + .map(|(row, ..)| row) | ||
| 7311 | + .find(|row| row.contains(&format)) | ||
| 7312 | + .unwrap_or(&[]) | ||
| 7313 | +} | ||
| 7314 | + | ||
| 7315 | +/// This row's format under the container `current` is already in, or the row's | ||
| 7316 | +/// first when it has no such box: an AV1 picked from a WAV lands in Matroska, | ||
| 7317 | +/// and picked from an mp4 stays in the mp4. | ||
| 7318 | +fn same_box(row: &[Format], current: Format) -> Option<Format> { | ||
| 7319 | + row.iter() | ||
| 7320 | + .copied() | ||
| 7321 | + .find(|f| f.ext() == current.ext()) | ||
| 7322 | + .or_else(|| row.first().copied()) | ||
| 7323 | +} | ||
| 7324 | + | ||
| 7325 | +/// The next box for the same codec, wrapping -- what the container row's key | ||
| 7326 | +/// does. The format itself for a codec with only one, so the stroke cannot | ||
| 7327 | +/// change what it is not offering. | ||
| 7328 | +fn next_container(format: Format) -> Format { | ||
| 7329 | + let row = containers(format); | ||
| 7330 | + let at = row.iter().position(|&f| f == format).unwrap_or(0); | ||
| 7331 | + row.get((at + 1) % row.len().max(1)) | ||
| 7332 | + .copied() | ||
| 7333 | + .unwrap_or(format) | ||
| 7334 | +} | ||
| 7335 | + | ||
| 7336 | +/// Why the quality rows say nothing about this format, or `None` where they | ||
| 7337 | +/// decide the picture. Only a picture encoder is given a bitrate here: the two | ||
| 7338 | +/// lossless audio formats have none to give and MP3 is written at one fixed | ||
| 7339 | +/// figure, so a live row over either would be a control that changes nothing. | ||
| 7340 | +fn bitrate_refusal(format: Format) -> Option<&'static str> { | ||
| 7341 | + match format { | ||
| 7342 | + Format::Wav | Format::Flac => Some("lossless audio — no bitrate to pick"), | ||
| 7343 | + Format::Mp3 => Some("MP3 is written at a fixed 256 kbps"), | ||
| 7344 | + _ => None, | ||
| 7345 | + } | ||
| 7009 | } | 7346 | } |
| 7010 | 7347 | ||
| 7011 | /// What one of the colour card's own strokes does. Its keys are card-local -- | 7348 | /// What one of the colour card's own strokes does. Its keys are card-local -- |
| @@ -7140,57 +7477,84 @@ fn next_resolution(current: (u32, u32), native: (u32, u32)) -> (u32, u32) { | |||
| 7140 | sizes[at.map_or(0, |at| (at + 1) % sizes.len())] | 7477 | sizes[at.map_or(0, |at| (at + 1) % sizes.len())] |
| 7141 | } | 7478 | } |
| 7142 | 7479 | ||
| 7143 | -/// [`format_line`] plus the project's resolution, which is what a video export | 7480 | +/// The first of the two lines the card keeps above its button: what will be |
| 7144 | -/// is written at however many sizes the media on the timeline are. Only for the | 7481 | +/// *inside* the file. [`format_line`]'s codec and box, then the project's own |
| 7145 | -/// formats that carry a picture -- a WAV has no resolution to state. | 7482 | +/// picture size and rate -- which is what a video export is written at however |
| 7146 | -fn export_line( | 7483 | +/// many sizes and rates the media on the timeline are -- and last what the |
| 7147 | - format: Format, | 7484 | +/// sound will be, or that there is none. Every field here is one `ffprobe` |
| 7148 | - session: Option<&PlaybackSession>, | 7485 | +/// reads back off the finished file, so the line is checkable rather than a |
| 7149 | - seat: Option<&'static str>, | 7486 | +/// promise. |
| 7150 | -) -> String { | 7487 | +fn summary_head(format: Format, picture: Option<((u32, u32), f64)>, audio: &str) -> String { |
| 7151 | - let line = format_line(format); | 7488 | + let line = match picture.filter(|_| format.has_video()) { |
| 7152 | - // What it will really be encoded by, on the same line: the picture's seat | 7489 | + Some(((w, h), fps)) => { |
| 7153 | - // as the probe found it (`…` until it lands, never a guess) and the sound's, | 7490 | + format!("{} · {w}x{h} · {} fps", format_line(format), fps_label(fps)) |
| 7154 | - // which is decided without opening anything. Both are what a running export | 7491 | + } |
| 7155 | - // then names on its progress line, from the same two functions. | 7492 | + None => format_line(format).to_string(), |
| 7156 | - let encoders = match session { | ||
| 7157 | - Some(session) => join_detail( | ||
| 7158 | - seat.unwrap_or(match format.has_video() { | ||
| 7159 | - true => "encoder …", | ||
| 7160 | - false => "", | ||
| 7161 | - }), | ||
| 7162 | - session.planned_audio(format), | ||
| 7163 | - ), | ||
| 7164 | - None => String::new(), | ||
| 7165 | }; | 7493 | }; |
| 7166 | - match session.filter(|_| format.has_video()) { | 7494 | + join_detail(&line, audio) |
| 7167 | - Some(session) => { | 7495 | +} |
| 7168 | - let (w, h) = session.resolution(); | 7496 | + |
| 7169 | - format!("{line} · project {w}x{h} · {encoders}") | 7497 | +/// The second: where it lands, roughly how big, and what will encode the |
| 7170 | - } | 7498 | +/// picture -- the seat as the probe found it (`…` until it lands, never a |
| 7171 | - None => join_detail(line, &encoders), | 7499 | +/// guess), which is what the running export then names on its progress line. |
| 7500 | +fn summary_tail(path: &Path, mb: Option<u64>, seat: Option<&'static str>, video: bool) -> String { | ||
| 7501 | + let size = mb.map_or_else(String::new, |mb| format!("≈ {mb} MB")); | ||
| 7502 | + let seat = match (video, seat) { | ||
| 7503 | + (true, Some(seat)) => seat, | ||
| 7504 | + (true, None) => "encoder …", | ||
| 7505 | + (false, _) => "", | ||
| 7506 | + }; | ||
| 7507 | + join_detail(&join_detail(&file_name(path), &size), seat) | ||
| 7508 | +} | ||
| 7509 | + | ||
| 7510 | +/// A frame rate as a person writes it: `30`, not `30.000`, and `23.976` for the | ||
| 7511 | +/// rate that is a ratio. | ||
| 7512 | +fn fps_label(fps: f64) -> String { | ||
| 7513 | + match (fps - fps.round()).abs() < 0.001 { | ||
| 7514 | + true => format!("{fps:.0}"), | ||
| 7515 | + false => format!("{fps:.3}") | ||
| 7516 | + .trim_end_matches('0') | ||
| 7517 | + .trim_end_matches('.') | ||
| 7518 | + .to_string(), | ||
| 7172 | } | 7519 | } |
| 7173 | } | 7520 | } |
| 7174 | 7521 | ||
| 7522 | +/// About how big a *chosen* bitrate makes the file: the picture's megabits over | ||
| 7523 | +/// the timeline's length. `None` for `Auto`, whose figure is the encoder's to | ||
| 7524 | +/// decide, and for a format with no bitrate at all -- a number nobody picked is | ||
| 7525 | +/// not an estimate. The sound and the container's own overhead are not in it, | ||
| 7526 | +/// which is why the card says "≈". | ||
| 7527 | +fn estimated_mb(bitrate: Option<u64>, duration: f64) -> Option<u64> { | ||
| 7528 | + let bitrate = bitrate.filter(|&b| b > 0 && duration > 0.)?; | ||
| 7529 | + Some((bitrate as f64 * duration / 8e6).round() as u64) | ||
| 7530 | +} | ||
| 7531 | + | ||
| 7532 | +/// What is in the file and what box it is in, which is the head of the summary. | ||
| 7533 | +/// Terse on purpose: the fields after it (size, rate, sound) are what the line | ||
| 7534 | +/// is *for*, and a head that spent its width on prose used to push the whole | ||
| 7535 | +/// summary onto a second line -- what each codec means is on its row. | ||
| 7175 | fn format_line(format: Format) -> &'static str { | 7536 | fn format_line(format: Format) -> &'static str { |
| 7176 | match format { | 7537 | match format { |
| 7177 | - Format::Mp4 => "H.264 · MP4 · moov at end", | 7538 | + Format::Mp4 => "H.264 · MP4", |
| 7178 | - Format::Av1 => "AV1 · Matroska · picture and sound", | 7539 | + Format::Av1 => "AV1 · MKV", |
| 7179 | - Format::Av1Mp4 => "AV1 · MP4 · picture and sound", | 7540 | + Format::Av1Mp4 => "AV1 · MP4", |
| 7180 | - Format::Hevc => "HEVC intra · Matroska · picture and sound", | 7541 | + Format::Hevc => "HEVC intra · MKV", |
| 7181 | - Format::HevcMp4 => "HEVC intra · MP4 · picture and sound", | 7542 | + Format::HevcMp4 => "HEVC intra · MP4", |
| 7182 | - Format::Wav => "16-bit PCM · WAV · timeline audio only", | 7543 | + // The three whose codec *is* their box: naming it twice would be the |
| 7183 | - Format::Flac => "FLAC · lossless · timeline audio only", | 7544 | + // only field on this line that says nothing. |
| 7184 | - Format::Mp3 => "MP3 · 256 kbps · timeline audio only", | 7545 | + Format::Wav => "16-bit PCM · WAV", |
| 7546 | + Format::Flac => "FLAC · lossless", | ||
| 7547 | + Format::Mp3 => "MP3 · 256 kbps", | ||
| 7185 | } | 7548 | } |
| 7186 | } | 7549 | } |
| 7187 | 7550 | ||
| 7188 | -/// The row a format is picked by, which is what a refusal calls it: `MP4`, not | 7551 | +/// The row a format is picked by, which is what a refusal calls it: the codec, |
| 7189 | -/// the `mkv` an AV1 file is named with. | 7552 | +/// since the container is a row of its own now -- `AV1`, not the `mkv` such a |
| 7553 | +/// file is named with. | ||
| 7190 | fn format_label(format: Format) -> &'static str { | 7554 | fn format_label(format: Format) -> &'static str { |
| 7191 | FORMATS | 7555 | FORMATS |
| 7192 | .iter() | 7556 | .iter() |
| 7193 | - .find(|(row, ..)| *row == Some(format)) | 7557 | + .find(|(row, ..)| row.contains(&format)) |
| 7194 | .map_or("EXPORT", |(_, _, label, _)| *label) | 7558 | .map_or("EXPORT", |(_, _, label, _)| *label) |
| 7195 | } | 7559 | } |
| 7196 | 7560 | ||
| @@ -8156,18 +8520,20 @@ mod tests { | |||
| 8156 | use super::{ | 8520 | use super::{ |
| 8157 | ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, | 8521 | ACCENT, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, EQ_CURVE_STEPS, |
| 8158 | EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, | 8522 | EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_SPECTRUM_DB, |
| 8159 | - EQ_TICKS, EXPORT_ROWS_H, FORMATS, Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, | 8523 | + EQ_TICKS, ESCAPE, EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, FORMATS, Format, HEADER_GAP, |
| 8160 | - HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, LABEL_H, | 8524 | + HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, INK_DIM, KEYS_ROW_H, |
| 8161 | - LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, | 8525 | + KEYS_ROWS_H, KEYS_W, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LETTERBOX, LIBRARY_MAX_W, |
| 8162 | - MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, | 8526 | + LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, |
| 8163 | - SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, | 8527 | + PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, |
| 8164 | - Speed, StreamInfo, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, Wave, applicable, band_label, | 8528 | + SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, VOLUME_W, Volume, WAVE_BPS, |
| 8165 | - can_add, cancels_export, clipboard_after_remove, color_snap, envelope, eq_spectrum, eq_x, | 8529 | + WAVE_COL, Wave, applicable, band_label, bitrate_refusal, can_add, cancels_export, |
| 8166 | - eq_y, export_path, export_settings, format_key, format_line, format_refusal, frac_along, | 8530 | + clipboard_after_remove, color_snap, containers, envelope, eq_spectrum, eq_x, eq_y, |
| 8167 | - frac_down, frame_at, histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, | 8531 | + estimated_mb, export_path, export_settings, format_key, format_line, format_refusal, |
| 8168 | - menu_at, normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, | 8532 | + fps_label, frac_along, frac_down, frame_at, histogram, is_bare_modifier, is_project, |
| 8169 | - scrub_due, show_label, silence_rate, snapped, source_tint, span_partner, speed_at, | 8533 | + keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h, |
| 8170 | - timecode, unseen_paths, unseen_sources, whole_take, width_frac, window_title, | 8534 | + project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped, |
| 8535 | + source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, unseen_paths, | ||
| 8536 | + unseen_sources, whole_take, width_frac, window_title, | ||
| 8171 | }; | 8537 | }; |
| 8172 | use super::{ | 8538 | use super::{ |
| 8173 | LaneKind, Repeat, View, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, library_rows, | 8539 | LaneKind, Repeat, View, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, library_rows, |
| @@ -10231,128 +10597,265 @@ mod tests { | |||
| 10231 | #[test] | 10597 | #[test] |
| 10232 | fn the_export_card_fits_the_smallest_window() { | 10598 | fn the_export_card_fits_the_smallest_window() { |
| 10233 | // Same 640x360 floor the keybindings card is measured against: the | 10599 | // Same 640x360 floor the keybindings card is measured against: the |
| 10234 | - // capped row list, the fixed-format line and the confirm button, under | 10600 | + // capped row list, the two summary lines and the confirm button, under |
| 10235 | // a title and a status line. | 10601 | // a title and a status line. |
| 10236 | let title = 17.; | 10602 | let title = 17.; |
| 10237 | let status = 28.; | 10603 | let status = 28.; |
| 10238 | - // Two lines of 11 px: the format line carries the encoders an export | 10604 | + // The head is one line of 11 px at this width -- every field of it, |
| 10239 | - // would open, which is what takes it past one at this width. | 10605 | + // worst case, is 71 characters against the 76 that fit. The tail is |
| 10240 | - let fixed = 30.; | 10606 | + // budgeted for two: the destination's name is the user's and a long one |
| 10241 | - let gaps = 4. * 2.; | 10607 | + // wraps. |
| 10608 | + let summary = 15. + 30.; | ||
| 10609 | + // Six children in the column, so five gaps. | ||
| 10610 | + let gaps = 5. * 2.; | ||
| 10242 | let padding = 24.; | 10611 | let padding = 24.; |
| 10243 | - assert!( | 10612 | + assert_eq!( |
| 10244 | - title + status + EXPORT_ROWS_H + fixed + CONTROL_H + 4. + gaps + padding <= 360., | 10613 | + EXPORT_FIXED_H, |
| 10245 | - "card too tall" | 10614 | + title + status + summary + CONTROL_H + 4. + gaps + padding |
| 10246 | ); | 10615 | ); |
| 10616 | + assert!(EXPORT_FIXED_H + EXPORT_ROWS_H <= 360., "card too tall"); | ||
| 10617 | + // The list grows with a window that has the room -- and never shrinks | ||
| 10618 | + // below the cap that made the floor fit, whatever arithmetic the window | ||
| 10619 | + // hands it. | ||
| 10620 | + let cap = |h: f32| (h - EXPORT_FIXED_H - 24.).max(EXPORT_ROWS_H); | ||
| 10621 | + assert_eq!(cap(360.), EXPORT_ROWS_H); | ||
| 10622 | + assert_eq!(cap(0.), EXPORT_ROWS_H); | ||
| 10623 | + assert!(cap(720.) > EXPORT_ROWS_H); | ||
| 10624 | + assert!(EXPORT_FIXED_H + cap(720.) <= 720.); | ||
| 10625 | + // ...and inside the 640 px floor with the scrim showing either side. | ||
| 10626 | + assert!(EXPORT_W + 2. * 12. <= 640.); | ||
| 10247 | // The cap is only honest if enough of the list is on screen to read as | 10627 | // The cap is only honest if enough of the list is on screen to read as |
| 10248 | - // one -- the destination and the first formats, not a slot. | 10628 | + // one -- and the whole format section is: its header and every codec |
| 10249 | - assert!(EXPORT_ROWS_H / KEYS_ROW_H >= 6.); | 10629 | + // row, so nothing that is picked *first* is behind a scroll. |
| 10250 | - // Clickable rows, so WCAG 2.5.8 binds them as it binds the panel's. | 10630 | + let codecs = FORMATS.iter().filter(|(row, ..)| !row.is_empty()).count(); |
| 10631 | + assert!(EXPORT_ROWS_H / KEYS_ROW_H >= 1. + codecs as f32); | ||
| 10632 | + // Clickable rows, so WCAG 2.5.8 binds them as it binds the panel's -- | ||
| 10633 | + // and the bitrate steppers are `HIT_MIN` squares sitting inside a row, | ||
| 10634 | + // which only fits while the row is at least as tall as one. | ||
| 10251 | assert!(KEYS_ROW_H >= HIT_MIN); | 10635 | assert!(KEYS_ROW_H >= HIT_MIN); |
| 10252 | assert!(CONTROL_H >= HIT_MIN); | 10636 | assert!(CONTROL_H >= HIT_MIN); |
| 10637 | + // The dimmed text on the card -- every refusal, every detail, every key | ||
| 10638 | + // in its column -- is body text on `SURFACE` and WCAG 1.4.3 binds it. | ||
| 10639 | + // A dimmed row is drawn in this ink rather than at an opacity, which is | ||
| 10640 | + // what a refusal used to be readable through. | ||
| 10641 | + assert!( | ||
| 10642 | + contrast(INK_DIM, SURFACE) >= 4.5, | ||
| 10643 | + "refusal ink {:.2}", | ||
| 10644 | + contrast(INK_DIM, SURFACE) | ||
| 10645 | + ); | ||
| 10646 | + // On the picked row that ink would only be 3.3:1 against the highlight, | ||
| 10647 | + // so the row it lands on lifts its key and detail to `INK`. | ||
| 10648 | + assert!(contrast(INK, SELECTED) >= 4.5); | ||
| 10649 | + assert!( | ||
| 10650 | + contrast(INK_DIM, SELECTED) < 4.5, | ||
| 10651 | + "the lift is still needed" | ||
| 10652 | + ); | ||
| 10253 | } | 10653 | } |
| 10254 | 10654 | ||
| 10255 | #[test] | 10655 | #[test] |
| 10256 | - fn every_format_row_is_offered_or_says_why_not() { | 10656 | + fn every_codec_row_is_offered_or_says_why_not() { |
| 10257 | - // The six this program can write are rows that pick. Four are named | 10657 | + // One row per codec, and the boxes it can go in are the container row's |
| 10258 | - // after their own extension, so a destination cannot disagree with its | 10658 | + // business: six rows that pick, two that say why they cannot. A codec |
| 10259 | - // bytes; the AV1 pair is named after codec *and* container, because the | 10659 | + // twice over (AV1 · MKV beside AV1 · MP4) was two rows asking the same |
| 10260 | - // same picture goes into either box and the row is the choice between | 10660 | + // question, and five picture rows above the fold is what the card was |
| 10261 | - // them. | 10661 | + // called unfriendly for. |
| 10262 | - let offered: Vec<Format> = FORMATS.iter().filter_map(|&(f, ..)| f).collect(); | 10662 | + let offered: Vec<&[Format]> = FORMATS |
| 10663 | + .iter() | ||
| 10664 | + .map(|&(row, ..)| row) | ||
| 10665 | + .filter(|row| !row.is_empty()) | ||
| 10666 | + .collect(); | ||
| 10263 | assert_eq!( | 10667 | assert_eq!( |
| 10264 | offered, | 10668 | offered, |
| 10265 | vec![ | 10669 | vec![ |
| 10266 | - Format::Mp4, | 10670 | + &[Format::Mp4][..], |
| 10267 | - Format::Av1, | 10671 | + &[Format::Av1, Format::Av1Mp4][..], |
| 10268 | - Format::Av1Mp4, | 10672 | + &[Format::Hevc, Format::HevcMp4][..], |
| 10269 | - Format::Hevc, | 10673 | + &[Format::Wav][..], |
| 10270 | - Format::HevcMp4, | 10674 | + &[Format::Flac][..], |
| 10271 | - Format::Wav, | 10675 | + &[Format::Mp3][..], |
| 10272 | - Format::Flac, | ||
| 10273 | - Format::Mp3 | ||
| 10274 | ] | 10676 | ] |
| 10275 | ); | 10677 | ); |
| 10678 | + // Every format the engine writes is on exactly one row: one the card | ||
| 10679 | + // cannot reach is one nobody can pick. | ||
| 10680 | + for format in [ | ||
| 10681 | + Format::Mp4, | ||
| 10682 | + Format::Av1, | ||
| 10683 | + Format::Av1Mp4, | ||
| 10684 | + Format::Hevc, | ||
| 10685 | + Format::HevcMp4, | ||
| 10686 | + Format::Wav, | ||
| 10687 | + Format::Flac, | ||
| 10688 | + Format::Mp3, | ||
| 10689 | + ] { | ||
| 10690 | + assert_eq!( | ||
| 10691 | + FORMATS | ||
| 10692 | + .iter() | ||
| 10693 | + .filter(|(row, ..)| row.contains(&format)) | ||
| 10694 | + .count(), | ||
| 10695 | + 1, | ||
| 10696 | + "{format:?}" | ||
| 10697 | + ); | ||
| 10698 | + } | ||
| 10699 | + // The boxes the container row offers, and what the extension of each is | ||
| 10700 | + // -- the destination follows the format, so these are what a file gets | ||
| 10701 | + // named with. | ||
| 10702 | + assert_eq!(containers(Format::Av1), [Format::Av1, Format::Av1Mp4]); | ||
| 10703 | + assert_eq!(containers(Format::HevcMp4), [Format::Hevc, Format::HevcMp4]); | ||
| 10704 | + assert_eq!(containers(Format::Mp3), [Format::Mp3]); | ||
| 10276 | assert_eq!(Format::Av1.ext(), "mkv"); | 10705 | assert_eq!(Format::Av1.ext(), "mkv"); |
| 10277 | assert_eq!(Format::Av1Mp4.ext(), "mp4"); | 10706 | assert_eq!(Format::Av1Mp4.ext(), "mp4"); |
| 10278 | assert_eq!(Format::Hevc.ext(), "mkv"); | 10707 | assert_eq!(Format::Hevc.ext(), "mkv"); |
| 10279 | assert_eq!(Format::HevcMp4.ext(), "mp4"); | 10708 | assert_eq!(Format::HevcMp4.ext(), "mp4"); |
| 10280 | - for (format, _, label, _) in FORMATS { | 10709 | + // The container key walks the row and wraps, and does nothing at all |
| 10281 | - match format { | 10710 | + // where there is only one box -- a stroke must not invent a choice the |
| 10282 | - Some(Format::Av1) => assert_eq!(label, "AV1 · MKV"), | 10711 | + // card is not offering. |
| 10283 | - Some(Format::Av1Mp4) => assert_eq!(label, "AV1 · MP4"), | 10712 | + assert_eq!(next_container(Format::Av1), Format::Av1Mp4); |
| 10284 | - Some(Format::Hevc) => assert_eq!(label, "HEVC · MKV"), | 10713 | + assert_eq!(next_container(Format::Av1Mp4), Format::Av1); |
| 10285 | - Some(Format::HevcMp4) => assert_eq!(label, "HEVC · MP4"), | 10714 | + assert_eq!(next_container(Format::Hevc), Format::HevcMp4); |
| 10286 | - Some(format) => assert_eq!(format.ext(), label.to_lowercase()), | 10715 | + assert_eq!(next_container(Format::Mp4), Format::Mp4); |
| 10287 | - // A refused format is a row with a reason, never a hidden one: | 10716 | + assert_eq!(next_container(Format::Wav), Format::Wav); |
| 10288 | - // an empty detail column would read as an oversight. | 10717 | + for (row, stroke, label, detail) in FORMATS { |
| 10289 | - None => assert!(!label.is_empty()), | 10718 | + assert!(!label.is_empty(), "a row with no name"); |
| 10290 | - } | 10719 | + // A refused row is a row with a reason, never a hidden one: an |
| 10291 | - } | 10720 | + // empty detail column would read as an oversight. |
| 10292 | - for (format, stroke, label, detail) in FORMATS { | ||
| 10293 | assert!(!detail.is_empty(), "{label} says nothing"); | 10721 | assert!(!detail.is_empty(), "{label} says nothing"); |
| 10294 | - // Only the picture formats leave the bitrate rows live -- the card | 10722 | + // Every row that can be picked has a key of its own, and no row |
| 10295 | - // dims them off exactly this. | 10723 | + // that cannot has one: the card is drivable without a pointer. |
| 10296 | - assert_eq!( | 10724 | + assert_eq!(!row.is_empty(), !stroke.is_empty(), "{label}"); |
| 10297 | - format.is_some_and(Format::has_video), | 10725 | + if let Some(&first) = row.first() { |
| 10298 | - matches!( | 10726 | + assert_eq!( |
| 10299 | - format, | 10727 | + format_key(stroke, first), |
| 10300 | - Some( | 10728 | + Some(first), |
| 10301 | - Format::Mp4 | Format::Av1 | Format::Av1Mp4 | Format::Hevc | Format::HevcMp4 | 10729 | + "{label} keys to itself" |
| 10302 | - ) | 10730 | + ); |
| 10303 | - ) | ||
| 10304 | - ); | ||
| 10305 | - // Every row that can be picked has a key of its own, and no two | ||
| 10306 | - // share one: the card is drivable without a pointer. | ||
| 10307 | - assert_eq!(format.is_some(), !stroke.is_empty(), "{label}"); | ||
| 10308 | - if !stroke.is_empty() { | ||
| 10309 | - assert_eq!(format_key(stroke), format, "{label} keys to itself"); | ||
| 10310 | assert!( | 10731 | assert!( |
| 10311 | stroke.parse::<u32>().is_err(), | 10732 | stroke.parse::<u32>().is_err(), |
| 10312 | "{label} takes a digit the bitrate needs" | 10733 | "{label} takes a digit the bitrate needs" |
| 10313 | ); | 10734 | ); |
| 10735 | + // Every box on one row is the same codec, so the quality rows | ||
| 10736 | + // do not change meaning when the container does. | ||
| 10737 | + assert!(row.iter().all(|f| f.has_video() == first.has_video())); | ||
| 10738 | + assert!( | ||
| 10739 | + row.iter() | ||
| 10740 | + .all(|f| bitrate_refusal(*f) == bitrate_refusal(first)) | ||
| 10741 | + ); | ||
| 10314 | } | 10742 | } |
| 10315 | } | 10743 | } |
| 10744 | + // No two rows share a key, and none of them is a stroke the card already | ||
| 10745 | + // answers to itself -- an ambiguous key is a key that picks the wrong | ||
| 10746 | + // thing on a card that has no other input. | ||
| 10747 | + let keys: Vec<&str> = FORMATS | ||
| 10748 | + .iter() | ||
| 10749 | + .map(|&(_, stroke, ..)| stroke) | ||
| 10750 | + .filter(|stroke| !stroke.is_empty()) | ||
| 10751 | + .collect(); | ||
| 10752 | + for (i, key) in keys.iter().enumerate() { | ||
| 10753 | + assert!(!keys[i + 1..].contains(key), "{key} picks two rows"); | ||
| 10754 | + assert!( | ||
| 10755 | + !["c", "q", "d", "g", "r", "enter", "backspace", ESCAPE].contains(key), | ||
| 10756 | + "{key} is already the card's own" | ||
| 10757 | + ); | ||
| 10758 | + } | ||
| 10759 | + assert_eq!( | ||
| 10760 | + format_key("a", Format::Mp4), | ||
| 10761 | + Some(Format::Av1Mp4), | ||
| 10762 | + "the box already chosen is kept" | ||
| 10763 | + ); | ||
| 10764 | + assert_eq!( | ||
| 10765 | + format_key("a", Format::Wav), | ||
| 10766 | + Some(Format::Av1), | ||
| 10767 | + "and a codec with no such box takes its first" | ||
| 10768 | + ); | ||
| 10769 | + assert_eq!(format_key("h", Format::Av1Mp4), Some(Format::HevcMp4)); | ||
| 10770 | + assert_eq!(format_key("p", Format::Mp4), Some(Format::Mp3)); | ||
| 10771 | + assert_eq!( | ||
| 10772 | + format_key("m", Format::Mp3), | ||
| 10773 | + Some(Format::Mp4), | ||
| 10774 | + "not MP3, which is p" | ||
| 10775 | + ); | ||
| 10776 | + assert_eq!( | ||
| 10777 | + format_key("x", Format::Mp4), | ||
| 10778 | + None, | ||
| 10779 | + "a stroke no row carries" | ||
| 10780 | + ); | ||
| 10316 | // The codec this program reads and cannot write is a row of its own, | 10781 | // The codec this program reads and cannot write is a row of its own, |
| 10317 | // refused by name rather than absent: VP9, because AV1 is the row that | 10782 | // refused by name rather than absent: VP9, because AV1 is the row that |
| 10318 | - // replaced it. HEVC used to be one beside it and is now two rows that | 10783 | + // replaced it. Its reason travels with it, in the row or in the footer |
| 10319 | - // pick -- an intra-only encoder is still an encoder. | 10784 | + // line that collects them -- either way it is on screen without a click. |
| 10320 | - for (label, word) in [("VP9", "superseded")] { | 10785 | + for (label, word) in [("VP9", "replaces it"), ("OGG", "no pure-Rust")] { |
| 10321 | - let (format, _, _, detail) = FORMATS | 10786 | + let (row, _, _, detail) = FORMATS |
| 10322 | .into_iter() | 10787 | .into_iter() |
| 10323 | - .find(|(_, _, row, _)| *row == label) | 10788 | + .find(|(_, _, name, _)| *name == label) |
| 10324 | .unwrap_or_else(|| panic!("{label} has no row")); | 10789 | .unwrap_or_else(|| panic!("{label} has no row")); |
| 10325 | - assert!(format.is_none(), "{label} is not offered"); | 10790 | + assert!(row.is_empty(), "{label} is not offered"); |
| 10326 | assert!(detail.contains(word), "{label}: {detail}"); | 10791 | assert!(detail.contains(word), "{label}: {detail}"); |
| 10327 | } | 10792 | } |
| 10328 | - // Both AV1 rows say they carry sound: the file used to be picture only, | 10793 | + // Both AV1 boxes say they carry sound: the file used to be picture only, |
| 10329 | - // and a row that still said so would be the lie a user plays the file | 10794 | + // and a line that still said so would be the lie a user plays the file |
| 10330 | - // to find out about. | 10795 | + // to find out about. HEVC says intra-only before anyone waits on one -- |
| 10796 | + // a file several times the size, which the disk would otherwise say. | ||
| 10331 | for format in [Format::Av1, Format::Av1Mp4] { | 10797 | for format in [Format::Av1, Format::Av1Mp4] { |
| 10332 | - let (_, _, _, detail) = FORMATS | 10798 | + assert!(format_line(format).starts_with("AV1 · ")); |
| 10333 | - .into_iter() | 10799 | + } |
| 10334 | - .find(|(f, ..)| *f == Some(format)) | ||
| 10335 | - .expect("an AV1 row"); | ||
| 10336 | - assert!(detail.contains("sound"), "{detail}"); | ||
| 10337 | - assert!(format_line(format).contains("picture and sound")); | ||
| 10338 | - } | ||
| 10339 | - // ...and both HEVC rows say what they are before a user waits on one: | ||
| 10340 | - // intra-only, which is a file several times the size of the AV1 above | ||
| 10341 | - // it. A row that hid that would be found out by the disk. | ||
| 10342 | for format in [Format::Hevc, Format::HevcMp4] { | 10800 | for format in [Format::Hevc, Format::HevcMp4] { |
| 10343 | - let (_, _, _, detail) = FORMATS | 10801 | + assert!(format_line(format).starts_with("HEVC intra · ")); |
| 10802 | + } | ||
| 10803 | + // The head names the box every format goes in, which is what the | ||
| 10804 | + // destination is then named after. | ||
| 10805 | + for format in [ | ||
| 10806 | + Format::Mp4, | ||
| 10807 | + Format::Av1, | ||
| 10808 | + Format::Av1Mp4, | ||
| 10809 | + Format::Hevc, | ||
| 10810 | + Format::HevcMp4, | ||
| 10811 | + ] { | ||
| 10812 | + assert!( | ||
| 10813 | + format_line(format).contains(&format.ext().to_uppercase()), | ||
| 10814 | + "{format:?}: {}", | ||
| 10815 | + format_line(format) | ||
| 10816 | + ); | ||
| 10817 | + } | ||
| 10818 | + // ...and it stays inside the one line the card budgets for it: the | ||
| 10819 | + // longest of them, with every field after it, against the 76 characters | ||
| 10820 | + // that fit at `EXPORT_W`. | ||
| 10821 | + let longest = summary_head( | ||
| 10822 | + Format::Hevc, | ||
| 10823 | + Some(((1920, 1080), 23.976)), | ||
| 10824 | + "AAC · SW encode (rusty_aac)", | ||
| 10825 | + ); | ||
| 10826 | + assert!( | ||
| 10827 | + longest.chars().count() <= 76, | ||
| 10828 | + "{longest} is {} long", | ||
| 10829 | + longest.chars().count() | ||
| 10830 | + ); | ||
| 10831 | + assert!( | ||
| 10832 | + FORMATS | ||
| 10344 | .into_iter() | 10833 | .into_iter() |
| 10345 | - .find(|(f, ..)| *f == Some(format)) | 10834 | + .any(|(row, _, _, detail)| row.contains(&Format::Hevc) && detail.contains("intra")) |
| 10346 | - .expect("an HEVC row"); | 10835 | + ); |
| 10347 | - assert!(detail.contains("intra-only"), "{detail}"); | 10836 | + // Only a picture encoder is given a bitrate, and the quality rows dim |
| 10348 | - assert!(format_line(format).contains("picture and sound")); | 10837 | + // with the reason for every format that is not one. |
| 10349 | - } | 10838 | + for format in [ |
| 10350 | - assert_eq!(format_key("a"), Some(Format::Av1), "the Matroska one"); | 10839 | + Format::Mp4, |
| 10351 | - assert_eq!(format_key("v"), Some(Format::Av1Mp4), "and the mp4 one"); | 10840 | + Format::Av1, |
| 10352 | - assert_eq!(format_key("h"), Some(Format::Hevc), "HEVC's Matroska"); | 10841 | + Format::Av1Mp4, |
| 10353 | - assert_eq!(format_key("x"), Some(Format::HevcMp4), "and its mp4"); | 10842 | + Format::Hevc, |
| 10354 | - assert_eq!(format_key("p"), Some(Format::Mp3)); | 10843 | + Format::HevcMp4, |
| 10355 | - assert_eq!(format_key("m"), Some(Format::Mp4), "not MP3, which is p"); | 10844 | + ] { |
| 10845 | + assert!( | ||
| 10846 | + format.has_video() && bitrate_refusal(format).is_none(), | ||
| 10847 | + "{format:?}" | ||
| 10848 | + ); | ||
| 10849 | + } | ||
| 10850 | + for format in [Format::Wav, Format::Flac, Format::Mp3] { | ||
| 10851 | + assert!(!format.has_video()); | ||
| 10852 | + assert!( | ||
| 10853 | + bitrate_refusal(format).is_some(), | ||
| 10854 | + "{format:?} dims silently" | ||
| 10855 | + ); | ||
| 10856 | + } | ||
| 10857 | + assert!(bitrate_refusal(Format::Wav).unwrap().contains("lossless")); | ||
| 10858 | + assert!(bitrate_refusal(Format::Mp3).unwrap().contains("256 kbps")); | ||
| 10356 | // The destination follows the format and keeps the stem, mp4 included. | 10859 | // The destination follows the format and keeps the stem, mp4 included. |
| 10357 | assert_eq!( | 10860 | assert_eq!( |
| 10358 | retarget(std::path::Path::new("/a/take.export.mp4"), Format::Wav), | 10861 | retarget(std::path::Path::new("/a/take.export.mp4"), Format::Wav), |
| @@ -10362,7 +10865,59 @@ mod tests { | |||
| 10362 | retarget(std::path::Path::new("/a/take.export.wav"), Format::Mp4), | 10865 | retarget(std::path::Path::new("/a/take.export.wav"), Format::Mp4), |
| 10363 | std::path::Path::new("/a/take.export.mp4") | 10866 | std::path::Path::new("/a/take.export.mp4") |
| 10364 | ); | 10867 | ); |
| 10365 | - assert!(format_line(Format::Flac).contains("audio only")); | 10868 | + assert!(format_line(Format::Flac).contains("lossless")); |
| 10869 | + } | ||
| 10870 | + | ||
| 10871 | + /// The one line the card is answerable for: what it says is on screen before | ||
| 10872 | + /// the button is pressed, and every field of it is one `ffprobe` reads back | ||
| 10873 | + /// off the file that comes out. | ||
| 10874 | + #[test] | ||
| 10875 | + fn the_summary_states_the_file_before_it_is_written() { | ||
| 10876 | + let head = summary_head(Format::Mp4, Some(((1920, 1080), 30.)), "AAC copy"); | ||
| 10877 | + for field in ["H.264", "MP4", "1920x1080", "30 fps", "AAC copy"] { | ||
| 10878 | + assert!(head.contains(field), "{field} missing from {head}"); | ||
| 10879 | + } | ||
| 10880 | + // The rate as a person writes it, and the ratio one spelled out rather | ||
| 10881 | + // than rounded to a rate nothing is written at. | ||
| 10882 | + assert_eq!(fps_label(30.), "30"); | ||
| 10883 | + assert_eq!(fps_label(24000. / 1001.), "23.976"); | ||
| 10884 | + assert_eq!(fps_label(29.97002997), "29.97"); | ||
| 10885 | + // A format with no picture states no size and no rate it does not write. | ||
| 10886 | + let audio = summary_head(Format::Wav, Some(((1920, 1080), 30.)), "PCM · SW (hound)"); | ||
| 10887 | + assert!( | ||
| 10888 | + !audio.contains("1920x1080") && !audio.contains("fps"), | ||
| 10889 | + "{audio}" | ||
| 10890 | + ); | ||
| 10891 | + assert!(audio.contains("PCM · SW (hound)")); | ||
| 10892 | + // ...and one with no sound on the timeline says that, rather than | ||
| 10893 | + // leaving the field out and reading as a file with sound in it. | ||
| 10894 | + assert!( | ||
| 10895 | + summary_head(Format::Mp4, Some(((640, 360), 25.)), "no sound to write") | ||
| 10896 | + .contains("no sound to write") | ||
| 10897 | + ); | ||
| 10898 | + // The tail: where it lands, about how big, and what will encode it -- | ||
| 10899 | + // never a guessed seat, and no seat at all for a format with no picture. | ||
| 10900 | + let tail = summary_tail( | ||
| 10901 | + Path::new("/a/take.export.mp4"), | ||
| 10902 | + Some(45), | ||
| 10903 | + Some("VA-API"), | ||
| 10904 | + true, | ||
| 10905 | + ); | ||
| 10906 | + assert!(tail.starts_with("take.export.mp4"), "{tail}"); | ||
| 10907 | + assert!( | ||
| 10908 | + tail.contains("≈ 45 MB") && tail.contains("VA-API"), | ||
| 10909 | + "{tail}" | ||
| 10910 | + ); | ||
| 10911 | + assert!(summary_tail(Path::new("/a/x.mp4"), None, None, true).contains("encoder …")); | ||
| 10912 | + assert!(!summary_tail(Path::new("/a/x.wav"), None, None, false).contains("encoder")); | ||
| 10913 | + assert!(!summary_tail(Path::new("/a/x.wav"), None, None, false).contains("MB")); | ||
| 10914 | + // 6 Mbps over a minute is 45 MB. `Auto` has no figure to estimate from | ||
| 10915 | + // and an empty timeline no length: neither invents one. | ||
| 10916 | + assert_eq!(estimated_mb(Some(6_000_000), 60.), Some(45)); | ||
| 10917 | + assert_eq!(estimated_mb(Some(2_000_000), 90.), Some(23)); | ||
| 10918 | + assert_eq!(estimated_mb(None, 60.), None); | ||
| 10919 | + assert_eq!(estimated_mb(Some(6_000_000), 0.), None); | ||
| 10920 | + assert_eq!(estimated_mb(Some(0), 60.), None); | ||
| 10366 | } | 10921 | } |
| 10367 | 10922 | ||
| 10368 | #[test] | 10923 | #[test] |
| @@ -10846,6 +11401,8 @@ fn main() { | |||
| 10846 | keymap: keymap.clone(), | 11401 | keymap: keymap.clone(), |
| 10847 | keys_open: false, | 11402 | keys_open: false, |
| 10848 | export_open: false, | 11403 | export_open: false, |
| 11404 | + export_grouped: true, | ||
| 11405 | + export_refusals_inline: false, | ||
| 10849 | eq_open: None, | 11406 | eq_open: None, |
| 10850 | // Replaced by the clip's own curve the moment the card | 11407 | // Replaced by the clip's own curve the moment the card |
| 10851 | // opens; nothing reads it before that. | 11408 | // opens; nothing reads it before that. |