The export card's presets pick their own bundle, not the codec row's leftovers
Browse files at this commit4b9270483d06292978cef9d953758a45c6c79729Parent: 0d1aa32- fix
- the export card's presets pick their own bundle, not the codec row's leftovers
8 changed files +176 -28
- crates/app/src/export_ui.rs +22 -2
- crates/app/src/keymap.rs +25 -1
- crates/app/src/main.rs +6 -3
- crates/app/src/player/export.rs +23 -3
- crates/app/src/render.rs +9 -0
- crates/app/src/tests/cards.rs +56 -0
- crates/app/src/tests/mod.rs +1 -1
- crates/app/src/ui/cards.rs +34 -18
crates/app/src/export_ui.rsmodified+22 -2
| @@ -116,11 +116,28 @@ impl ExportPreset { | |||
| 116 | } | 116 | } |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | + /// The key that picks this row, none of the sixteen the card's other rows | ||
| 120 | + /// already own (`n`, the digits, the codec row's `m/a/h/w/f/p/o`, and | ||
| 121 | + /// `c/q/b/e/d/g/r/s`): a letter out of the name itself where its initial is | ||
| 122 | + /// one of those (`smaLl`, `masTer`, `aUdio`), and a free one where every | ||
| 123 | + /// letter in the name already belongs to another row (`Web`'s w, e and b | ||
| 124 | + /// all are). `Custom` shares Advanced's own `s` -- the row does exactly what | ||
| 125 | + /// that key already does, not a second name for a third thing. | ||
| 126 | + pub(crate) fn key(self) -> &'static str { | ||
| 127 | + match self { | ||
| 128 | + ExportPreset::Web => "v", | ||
| 129 | + ExportPreset::Small => "l", | ||
| 130 | + ExportPreset::Master => "t", | ||
| 131 | + ExportPreset::AudioOnly => "u", | ||
| 132 | + ExportPreset::Custom => "s", | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + | ||
| 119 | pub(crate) fn detail(self) -> &'static str { | 136 | pub(crate) fn detail(self) -> &'static str { |
| 120 | match self { | 137 | match self { |
| 121 | ExportPreset::Web => "H.264 · MP4 · medium quality — plays everywhere", | 138 | ExportPreset::Web => "H.264 · MP4 · medium quality — plays everywhere", |
| 122 | ExportPreset::Small => "AV1 · MP4 · low quality — smallest file", | 139 | ExportPreset::Small => "AV1 · MP4 · low quality — smallest file", |
| 123 | - ExportPreset::Master => "H.264 · MP4 · high quality — for re-editing later", | 140 | + ExportPreset::Master => "HEVC · MP4 · high quality — intra-only, for re-editing later", |
| 124 | ExportPreset::AudioOnly => "FLAC — lossless sound, no picture", | 141 | ExportPreset::AudioOnly => "FLAC — lossless sound, no picture", |
| 125 | ExportPreset::Custom => "pick a codec, quality and the rest below", | 142 | ExportPreset::Custom => "pick a codec, quality and the rest below", |
| 126 | } | 143 | } |
| @@ -133,7 +150,10 @@ impl ExportPreset { | |||
| 133 | match self { | 150 | match self { |
| 134 | ExportPreset::Web => Some((Format::Mp4, Quality::Medium)), | 151 | ExportPreset::Web => Some((Format::Mp4, Quality::Medium)), |
| 135 | ExportPreset::Small => Some((Format::Av1Mp4, Quality::Low)), | 152 | ExportPreset::Small => Some((Format::Av1Mp4, Quality::Low)), |
| 136 | - ExportPreset::Master => Some((Format::Mp4, Quality::High)), | 153 | + // HEVC, not H.264: a master is for cutting again later, and HEVC's |
| 154 | + // intra-only rows say why that is the one that keeps its promise -- | ||
| 155 | + // every frame already a cut point, where H.264's are not. | ||
| 156 | + ExportPreset::Master => Some((Format::HevcMp4, Quality::High)), | ||
| 137 | ExportPreset::AudioOnly => Some((Format::Flac, Quality::Auto)), | 157 | ExportPreset::AudioOnly => Some((Format::Flac, Quality::Auto)), |
| 138 | ExportPreset::Custom => None, | 158 | ExportPreset::Custom => None, |
| 139 | } | 159 | } |
crates/app/src/keymap.rsmodified+25 -1
| @@ -438,7 +438,19 @@ fn codec_chord() -> String { | |||
| 438 | .join(" / ") | 438 | .join(" / ") |
| 439 | } | 439 | } |
| 440 | 440 | ||
| 441 | -pub static FIXED: std::sync::LazyLock<[Fixed; 30]> = std::sync::LazyLock::new(|| { | 441 | +/// The preset row's keys, from [`crate::ExportPreset::key`] -- `Custom` |
| 442 | +/// excepted, which shares Advanced's own `s` and so is that row's line, not a | ||
| 443 | +/// second one here. | ||
| 444 | +fn preset_chord() -> String { | ||
| 445 | + crate::ExportPreset::ALL | ||
| 446 | + .into_iter() | ||
| 447 | + .filter(|p| *p != crate::ExportPreset::Custom) | ||
| 448 | + .map(|p| p.key()) | ||
| 449 | + .collect::<Vec<_>>() | ||
| 450 | + .join(" / ") | ||
| 451 | +} | ||
| 452 | + | ||
| 453 | +pub static FIXED: std::sync::LazyLock<[Fixed; 32]> = std::sync::LazyLock::new(|| { | ||
| 442 | [ | 454 | [ |
| 443 | // Not a chord at all but a way of pressing one, and the only place the | 455 | // Not a chord at all but a way of pressing one, and the only place the |
| 444 | // editor can say so: holding a key that moves a *value* runs it, and | 456 | // editor can say so: holding a key that moves a *value* runs it, and |
| @@ -517,6 +529,18 @@ pub static FIXED: std::sync::LazyLock<[Fixed; 30]> = std::sync::LazyLock::new(|| | |||
| 517 | category: Category::File, | 529 | category: Category::File, |
| 518 | reach: Reach::Click("destination"), | 530 | reach: Reach::Click("destination"), |
| 519 | }, | 531 | }, |
| 532 | + Fixed { | ||
| 533 | + chord: preset_chord(), | ||
| 534 | + label: "Pick an export bundle: Web, Small file, Master or Audio only", | ||
| 535 | + category: Category::File, | ||
| 536 | + reach: Reach::Click("preset"), | ||
| 537 | + }, | ||
| 538 | + Fixed { | ||
| 539 | + chord: "s".into(), | ||
| 540 | + label: "Export card: open or close the Advanced pane", | ||
| 541 | + category: Category::File, | ||
| 542 | + reach: Reach::Click("export-advanced"), | ||
| 543 | + }, | ||
| 520 | Fixed { | 544 | Fixed { |
| 521 | chord: "g".into(), | 545 | chord: "g".into(), |
| 522 | label: "Export card: sections or one flat list", | 546 | label: "Export card: sections or one flat list", |
crates/app/src/main.rsmodified+6 -3
| @@ -773,9 +773,12 @@ fn main() { | |||
| 773 | // Empty until the first frame is pumped, which draws as a | 773 | // Empty until the first frame is pumped, which draws as a |
| 774 | // flat line rather than as a shape nothing measured. | 774 | // flat line rather than as a shape nothing measured. |
| 775 | histogram: [[0; HIST_BINS]; 3], | 775 | histogram: [[0; HIST_BINS]; 3], |
| 776 | - // What an export is until someone says otherwise: the | 776 | + // What an export is until someone says otherwise: the Web |
| 777 | - // bitrate the picture asks for. | 777 | + // bundle, so `ExportPreset::from_state` opens on a real |
| 778 | - quality: Quality::Auto, | 778 | + // preset rather than a `Custom` nobody picked -- `Auto` |
| 779 | + // paired with `Format::default()`'s MP4 matched no bundle | ||
| 780 | + // at all. | ||
| 781 | + quality: Quality::Medium, | ||
| 779 | custom_mbps: 0, | 782 | custom_mbps: 0, |
| 780 | mbps_edit: None, | 783 | mbps_edit: None, |
| 781 | // ...and the rate the sound has always been written at. | 784 | // ...and the rate the sound has always been written at. |
crates/app/src/player/export.rsmodified+23 -3
| @@ -314,8 +314,10 @@ impl Player { | |||
| 314 | 314 | ||
| 315 | /// A format row was clicked. The destination follows it at once -- a WAV | 315 | /// A format row was clicked. The destination follows it at once -- a WAV |
| 316 | /// written to a path ending in `.mp4` is a file every player will lie | 316 | /// written to a path ending in `.mp4` is a file every player will lie |
| 317 | - /// about -- keeping whatever stem the save dialog last left there. | 317 | + /// about -- keeping whatever stem the save dialog last left there. `false` |
| 318 | - pub(crate) fn set_format(&mut self, format: Format) { | 318 | + /// on a refusal, so a caller that has more than the format to write (a |
| 319 | + /// preset's own quality) knows not to write the rest of it either. | ||
| 320 | + pub(crate) fn set_format(&mut self, format: Format) -> bool { | ||
| 319 | // The one door both the row and its initial go through, so a format the | 321 | // The one door both the row and its initial go through, so a format the |
| 320 | // card greys out cannot be picked by keyboard either. | 322 | // card greys out cannot be picked by keyboard either. |
| 321 | if let Some(why) = self | 323 | if let Some(why) = self |
| @@ -324,10 +326,28 @@ impl Player { | |||
| 324 | .and_then(|session| format_refusal(session, format)) | 326 | .and_then(|session| format_refusal(session, format)) |
| 325 | { | 327 | { |
| 326 | self.notify_user(format!("NOT {} — {why}", format_label(format)).into()); | 328 | self.notify_user(format!("NOT {} — {why}", format_label(format)).into()); |
| 327 | - return; | 329 | + return false; |
| 328 | } | 330 | } |
| 329 | self.format = format; | 331 | self.format = format; |
| 330 | self.export_path = retarget(&self.export_path, format); | 332 | self.export_path = retarget(&self.export_path, format); |
| 333 | + true | ||
| 334 | + } | ||
| 335 | + | ||
| 336 | + /// A preset row, by click or by its own key. `Custom` opens the pane where | ||
| 337 | + /// the codec and the quality are picked apart and changes nothing itself; | ||
| 338 | + /// the rest are exactly the bundle they name -- and nothing at all on a | ||
| 339 | + /// refusal, because [`set_format`](Self::set_format) already fired the | ||
| 340 | + /// banner and a quality written after it declined would be a row that | ||
| 341 | + /// looks picked over a format that was not. | ||
| 342 | + pub(crate) fn pick_preset(&mut self, preset: ExportPreset) { | ||
| 343 | + match preset.bundle() { | ||
| 344 | + Some((format, quality)) => { | ||
| 345 | + if self.set_format(format) { | ||
| 346 | + self.quality = quality; | ||
| 347 | + } | ||
| 348 | + } | ||
| 349 | + None => self.export_advanced_open = true, | ||
| 350 | + } | ||
| 331 | } | 351 | } |
| 332 | 352 | ||
| 333 | /// The container row: the same codec in the other box, which retargets the | 353 | /// The container row: the same codec in the other box, which retargets the |
crates/app/src/render.rsmodified+9 -0
| @@ -255,6 +255,15 @@ impl Render for Player { | |||
| 255 | // The save dialog, which was the one row here a | 255 | // The save dialog, which was the one row here a |
| 256 | // keyboard could not open. | 256 | // keyboard could not open. |
| 257 | this.pick_destination(cx); | 257 | this.pick_destination(cx); |
| 258 | + } else if let Some(preset) = ExportPreset::ALL | ||
| 259 | + .into_iter() | ||
| 260 | + .find(|p| p.key() == key) | ||
| 261 | + // `Custom` shares `s` with Advanced below, which already | ||
| 262 | + // handles that key -- reaching it here too would only | ||
| 263 | + // race the same assignment against itself. | ||
| 264 | + .filter(|p| *p != ExportPreset::Custom) | ||
| 265 | + { | ||
| 266 | + this.pick_preset(preset); | ||
| 258 | } else if key == "g" { | 267 | } else if key == "g" { |
| 259 | this.export_grouped = !this.export_grouped; | 268 | this.export_grouped = !this.export_grouped; |
| 260 | } else if key == "r" { | 269 | } else if key == "r" { |
crates/app/src/tests/cards.rsmodified+56 -0
| @@ -1421,3 +1421,59 @@ fn the_export_estimate_answers_a_bar_that_went_backwards_with_a_guess() { | |||
| 1421 | ); | 1421 | ); |
| 1422 | } | 1422 | } |
| 1423 | } | 1423 | } |
| 1424 | + | ||
| 1425 | +/// The primary pane's own round trip: every bundle's format-and-quality lands | ||
| 1426 | +/// back on the preset that named it, so the row a person picked is the row | ||
| 1427 | +/// the card shows picked. `Custom` is the one preset `bundle` names nothing | ||
| 1428 | +/// for, and the one every pair outside the other four's must fall back to. | ||
| 1429 | +#[test] | ||
| 1430 | +fn every_preset_bundle_round_trips_through_from_state() { | ||
| 1431 | + for preset in ExportPreset::ALL { | ||
| 1432 | + match preset.bundle() { | ||
| 1433 | + Some((format, quality)) => { | ||
| 1434 | + assert_eq!(ExportPreset::from_state(format, quality), preset); | ||
| 1435 | + } | ||
| 1436 | + None => assert_eq!(preset, ExportPreset::Custom), | ||
| 1437 | + } | ||
| 1438 | + } | ||
| 1439 | + // A pair no bundle names -- the launch default before this batch's fix -- | ||
| 1440 | + // reads as `Custom`, not as whichever preset happens to be first. | ||
| 1441 | + assert_eq!( | ||
| 1442 | + ExportPreset::from_state(Format::Mp4, Quality::Auto), | ||
| 1443 | + ExportPreset::Custom | ||
| 1444 | + ); | ||
| 1445 | + // Master's bundle is HEVC/High, not H.264: an intra-only master is the one | ||
| 1446 | + // that keeps its own "for re-editing later" detail true. | ||
| 1447 | + assert_eq!( | ||
| 1448 | + ExportPreset::Master.bundle(), | ||
| 1449 | + Some((Format::HevcMp4, Quality::High)) | ||
| 1450 | + ); | ||
| 1451 | +} | ||
| 1452 | + | ||
| 1453 | +/// The primary pane's own refusal: a bundle whose format this timeline cannot | ||
| 1454 | +/// write reads exactly as a codec row does -- the reason in place of the | ||
| 1455 | +/// detail, and no format-and-quality pair to land wrong once a click on a | ||
| 1456 | +/// dimmed row is ignored. | ||
| 1457 | +#[test] | ||
| 1458 | +fn a_preset_over_a_picture_this_timeline_has_none_of_carries_the_codec_refusal() { | ||
| 1459 | + let mut session = | ||
| 1460 | + PlaybackSession::open(asset("test_tone.mp3")).expect("a song is a timeline"); | ||
| 1461 | + session.set_gain(0.0); | ||
| 1462 | + let path = session.sources()[0].path.clone(); | ||
| 1463 | + session.seek(1.0); | ||
| 1464 | + session | ||
| 1465 | + .place_stream_at(1.0, &path, 0, Some(Lane::A1)) | ||
| 1466 | + .expect("its own file is on this timeline"); | ||
| 1467 | + assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture"); | ||
| 1468 | + | ||
| 1469 | + for preset in [ExportPreset::Web, ExportPreset::Small, ExportPreset::Master] { | ||
| 1470 | + let (format, _) = preset.bundle().expect("a real bundle"); | ||
| 1471 | + assert!( | ||
| 1472 | + format_refusal(&session, format).is_some(), | ||
| 1473 | + "{preset:?}'s bundle is a picture format this audio-only timeline must refuse" | ||
| 1474 | + ); | ||
| 1475 | + } | ||
| 1476 | + // Audio only's bundle is FLAC, which has no picture to refuse. | ||
| 1477 | + let (audio_format, _) = ExportPreset::AudioOnly.bundle().expect("a real bundle"); | ||
| 1478 | + assert_eq!(format_refusal(&session, audio_format), None); | ||
| 1479 | +} | ||
crates/app/src/tests/mod.rsmodified+1 -1
| @@ -13,7 +13,7 @@ use super::{ | |||
| 13 | ACCENT_PRIMARY, AUDIO_KBPS, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, | 13 | ACCENT_PRIMARY, AUDIO_KBPS, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, |
| 14 | EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, | 14 | EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, |
| 15 | EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, | 15 | EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, |
| 16 | - EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, EncoderSeat, FORMATS, | 16 | + EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, EncoderSeat, ExportPreset, FORMATS, |
| 17 | Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, | 17 | Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, |
| 18 | KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, | 18 | KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, |
| 19 | LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, | 19 | LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, |
crates/app/src/ui/cards.rsmodified+34 -18
| @@ -141,26 +141,32 @@ impl Player { | |||
| 141 | list.push(destination); | 141 | list.push(destination); |
| 142 | let current_preset = ExportPreset::from_state(self.format, self.quality); | 142 | let current_preset = ExportPreset::from_state(self.format, self.quality); |
| 143 | for (i, preset) in ExportPreset::ALL.into_iter().enumerate() { | 143 | for (i, preset) in ExportPreset::ALL.into_iter().enumerate() { |
| 144 | + // A bundle whose format this timeline refuses (an audio-only edit | ||
| 145 | + // against Web, Small or Master) is the same kind of row the codec | ||
| 146 | + // rows already carry: dimmed, unclickable, its reason in place of | ||
| 147 | + // the detail -- not bright and pickable over a click that would | ||
| 148 | + // only bounce off `set_format`'s own guard. | ||
| 149 | + let refusal = preset | ||
| 150 | + .bundle() | ||
| 151 | + .and_then(|(format, _)| self.session.as_ref().and_then(|s| format_refusal(s, format))); | ||
| 152 | + let detail: SharedString = match &refusal { | ||
| 153 | + Some(why) => why.clone().into(), | ||
| 154 | + None => preset.detail().into(), | ||
| 155 | + }; | ||
| 144 | let mut r = entry( | 156 | let mut r = entry( |
| 145 | ("preset", i), | 157 | ("preset", i), |
| 146 | - "", | 158 | + preset.key(), |
| 147 | preset.label().into(), | 159 | preset.label().into(), |
| 148 | - preset.detail().into(), | 160 | + detail, |
| 149 | preset == current_preset, | 161 | preset == current_preset, |
| 150 | - true, | 162 | + refusal.is_none(), |
| 151 | ); | 163 | ); |
| 152 | - r = r.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 164 | + if refusal.is_none() { |
| 153 | - match preset.bundle() { | 165 | + r = r.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { |
| 154 | - Some((format, quality)) => { | 166 | + this.pick_preset(preset); |
| 155 | - this.set_format(format); | 167 | + cx.notify(); |
| 156 | - this.quality = quality; | 168 | + })); |
| 157 | - } | 169 | + } |
| 158 | - // Custom sets nothing -- it only opens the pane where the | ||
| 159 | - // codec and the quality are picked apart. | ||
| 160 | - None => this.export_advanced_open = true, | ||
| 161 | - } | ||
| 162 | - cx.notify(); | ||
| 163 | - })); | ||
| 164 | list.push(r.into_any_element()); | 170 | list.push(r.into_any_element()); |
| 165 | } | 171 | } |
| 166 | let advanced_detail = match self.export_advanced_open { | 172 | let advanced_detail = match self.export_advanced_open { |
| @@ -601,9 +607,19 @@ impl Player { | |||
| 601 | SharedString::from(format!("Custom bitrate {}", edit.detail())) | 607 | SharedString::from(format!("Custom bitrate {}", edit.detail())) |
| 602 | } | 608 | } |
| 603 | (None, Some(notice)) => notice.clone(), | 609 | (None, Some(notice)) => notice.clone(), |
| 604 | - (None, None) => "the keys are on the rows · enter exports · \ | 610 | + // `g`/`r` only do anything once Advanced is |
| 605 | - a click away or esc closes · g/r change the layout" | 611 | + // open -- they moved off the front pane with |
| 606 | - .into(), | 612 | + // the rows they reshape -- so a shut pane |
| 613 | + // advertises `s` instead of a pair of keys | ||
| 614 | + // with nothing on screen for them to touch. | ||
| 615 | + (None, None) => match self.export_advanced_open { | ||
| 616 | + true => "the keys are on the rows · enter exports · \ | ||
| 617 | + a click away or esc closes · g/r change the layout" | ||
| 618 | + .into(), | ||
| 619 | + false => "the keys are on the rows · enter exports · \ | ||
| 620 | + a click away or esc closes · s for Advanced" | ||
| 621 | + .into(), | ||
| 622 | + }, | ||
| 607 | }), | 623 | }), |
| 608 | ) | 624 | ) |
| 609 | // Capped and scrolling like the keybindings list: the | 625 | // Capped and scrolling like the keybindings list: the |