diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index dd2f508..bc8f03b 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -116,11 +116,28 @@ impl ExportPreset { } } + /// The key that picks this row, none of the sixteen the card's other rows + /// already own (`n`, the digits, the codec row's `m/a/h/w/f/p/o`, and + /// `c/q/b/e/d/g/r/s`): a letter out of the name itself where its initial is + /// one of those (`smaLl`, `masTer`, `aUdio`), and a free one where every + /// letter in the name already belongs to another row (`Web`'s w, e and b + /// all are). `Custom` shares Advanced's own `s` -- the row does exactly what + /// that key already does, not a second name for a third thing. + pub(crate) fn key(self) -> &'static str { + match self { + ExportPreset::Web => "v", + ExportPreset::Small => "l", + ExportPreset::Master => "t", + ExportPreset::AudioOnly => "u", + ExportPreset::Custom => "s", + } + } + pub(crate) fn detail(self) -> &'static str { match self { ExportPreset::Web => "H.264 · MP4 · medium quality — plays everywhere", ExportPreset::Small => "AV1 · MP4 · low quality — smallest file", - ExportPreset::Master => "H.264 · MP4 · high quality — for re-editing later", + ExportPreset::Master => "HEVC · MP4 · high quality — intra-only, for re-editing later", ExportPreset::AudioOnly => "FLAC — lossless sound, no picture", ExportPreset::Custom => "pick a codec, quality and the rest below", } @@ -133,7 +150,10 @@ impl ExportPreset { match self { ExportPreset::Web => Some((Format::Mp4, Quality::Medium)), ExportPreset::Small => Some((Format::Av1Mp4, Quality::Low)), - ExportPreset::Master => Some((Format::Mp4, Quality::High)), + // HEVC, not H.264: a master is for cutting again later, and HEVC's + // intra-only rows say why that is the one that keeps its promise -- + // every frame already a cut point, where H.264's are not. + ExportPreset::Master => Some((Format::HevcMp4, Quality::High)), ExportPreset::AudioOnly => Some((Format::Flac, Quality::Auto)), ExportPreset::Custom => None, } diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 9e79c2b..abf6eea 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -438,7 +438,19 @@ fn codec_chord() -> String { .join(" / ") } -pub static FIXED: std::sync::LazyLock<[Fixed; 30]> = std::sync::LazyLock::new(|| { +/// The preset row's keys, from [`crate::ExportPreset::key`] -- `Custom` +/// excepted, which shares Advanced's own `s` and so is that row's line, not a +/// second one here. +fn preset_chord() -> String { + crate::ExportPreset::ALL + .into_iter() + .filter(|p| *p != crate::ExportPreset::Custom) + .map(|p| p.key()) + .collect::>() + .join(" / ") +} + +pub static FIXED: std::sync::LazyLock<[Fixed; 32]> = std::sync::LazyLock::new(|| { [ // Not a chord at all but a way of pressing one, and the only place the // 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(|| category: Category::File, reach: Reach::Click("destination"), }, + Fixed { + chord: preset_chord(), + label: "Pick an export bundle: Web, Small file, Master or Audio only", + category: Category::File, + reach: Reach::Click("preset"), + }, + Fixed { + chord: "s".into(), + label: "Export card: open or close the Advanced pane", + category: Category::File, + reach: Reach::Click("export-advanced"), + }, Fixed { chord: "g".into(), label: "Export card: sections or one flat list", diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 2ccb721..c1229cf 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -773,9 +773,12 @@ fn main() { // Empty until the first frame is pumped, which draws as a // flat line rather than as a shape nothing measured. histogram: [[0; HIST_BINS]; 3], - // What an export is until someone says otherwise: the - // bitrate the picture asks for. - quality: Quality::Auto, + // What an export is until someone says otherwise: the Web + // bundle, so `ExportPreset::from_state` opens on a real + // preset rather than a `Custom` nobody picked -- `Auto` + // paired with `Format::default()`'s MP4 matched no bundle + // at all. + quality: Quality::Medium, custom_mbps: 0, mbps_edit: None, // ...and the rate the sound has always been written at. diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 2305026..4a46262 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -314,8 +314,10 @@ impl Player { /// A format row was clicked. The destination follows it at once -- a WAV /// written to a path ending in `.mp4` is a file every player will lie - /// about -- keeping whatever stem the save dialog last left there. - pub(crate) fn set_format(&mut self, format: Format) { + /// about -- keeping whatever stem the save dialog last left there. `false` + /// on a refusal, so a caller that has more than the format to write (a + /// preset's own quality) knows not to write the rest of it either. + pub(crate) fn set_format(&mut self, format: Format) -> bool { // The one door both the row and its initial go through, so a format the // card greys out cannot be picked by keyboard either. if let Some(why) = self @@ -324,10 +326,28 @@ impl Player { .and_then(|session| format_refusal(session, format)) { self.notify_user(format!("NOT {} — {why}", format_label(format)).into()); - return; + return false; } self.format = format; self.export_path = retarget(&self.export_path, format); + true + } + + /// A preset row, by click or by its own key. `Custom` opens the pane where + /// the codec and the quality are picked apart and changes nothing itself; + /// the rest are exactly the bundle they name -- and nothing at all on a + /// refusal, because [`set_format`](Self::set_format) already fired the + /// banner and a quality written after it declined would be a row that + /// looks picked over a format that was not. + pub(crate) fn pick_preset(&mut self, preset: ExportPreset) { + match preset.bundle() { + Some((format, quality)) => { + if self.set_format(format) { + self.quality = quality; + } + } + None => self.export_advanced_open = true, + } } /// The container row: the same codec in the other box, which retargets the diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index 66b87ae..22cf23f 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -255,6 +255,15 @@ impl Render for Player { // The save dialog, which was the one row here a // keyboard could not open. this.pick_destination(cx); + } else if let Some(preset) = ExportPreset::ALL + .into_iter() + .find(|p| p.key() == key) + // `Custom` shares `s` with Advanced below, which already + // handles that key -- reaching it here too would only + // race the same assignment against itself. + .filter(|p| *p != ExportPreset::Custom) + { + this.pick_preset(preset); } else if key == "g" { this.export_grouped = !this.export_grouped; } else if key == "r" { diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index efa4c23..5e5a197 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -1421,3 +1421,59 @@ fn the_export_estimate_answers_a_bar_that_went_backwards_with_a_guess() { ); } } + +/// The primary pane's own round trip: every bundle's format-and-quality lands +/// back on the preset that named it, so the row a person picked is the row +/// the card shows picked. `Custom` is the one preset `bundle` names nothing +/// for, and the one every pair outside the other four's must fall back to. +#[test] +fn every_preset_bundle_round_trips_through_from_state() { + for preset in ExportPreset::ALL { + match preset.bundle() { + Some((format, quality)) => { + assert_eq!(ExportPreset::from_state(format, quality), preset); + } + None => assert_eq!(preset, ExportPreset::Custom), + } + } + // A pair no bundle names -- the launch default before this batch's fix -- + // reads as `Custom`, not as whichever preset happens to be first. + assert_eq!( + ExportPreset::from_state(Format::Mp4, Quality::Auto), + ExportPreset::Custom + ); + // Master's bundle is HEVC/High, not H.264: an intra-only master is the one + // that keeps its own "for re-editing later" detail true. + assert_eq!( + ExportPreset::Master.bundle(), + Some((Format::HevcMp4, Quality::High)) + ); +} + +/// The primary pane's own refusal: a bundle whose format this timeline cannot +/// write reads exactly as a codec row does -- the reason in place of the +/// detail, and no format-and-quality pair to land wrong once a click on a +/// dimmed row is ignored. +#[test] +fn a_preset_over_a_picture_this_timeline_has_none_of_carries_the_codec_refusal() { + let mut session = + PlaybackSession::open(asset("test_tone.mp3")).expect("a song is a timeline"); + session.set_gain(0.0); + let path = session.sources()[0].path.clone(); + session.seek(1.0); + session + .place_stream_at(1.0, &path, 0, Some(Lane::A1)) + .expect("its own file is on this timeline"); + assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture"); + + for preset in [ExportPreset::Web, ExportPreset::Small, ExportPreset::Master] { + let (format, _) = preset.bundle().expect("a real bundle"); + assert!( + format_refusal(&session, format).is_some(), + "{preset:?}'s bundle is a picture format this audio-only timeline must refuse" + ); + } + // Audio only's bundle is FLAC, which has no picture to refuse. + let (audio_format, _) = ExportPreset::AudioOnly.bundle().expect("a real bundle"); + assert_eq!(format_refusal(&session, audio_format), None); +} diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index cef1de3..c48785b 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -13,7 +13,7 @@ use super::{ ACCENT_PRIMARY, AUDIO_KBPS, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, - EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, EncoderSeat, FORMATS, + EXPORT_FIXED_H, EXPORT_ROWS_H, EXPORT_W, Enable, EncoderSeat, ExportPreset, FORMATS, Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index c1b2dc0..aa8b0c9 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -141,26 +141,32 @@ impl Player { list.push(destination); let current_preset = ExportPreset::from_state(self.format, self.quality); for (i, preset) in ExportPreset::ALL.into_iter().enumerate() { + // A bundle whose format this timeline refuses (an audio-only edit + // against Web, Small or Master) is the same kind of row the codec + // rows already carry: dimmed, unclickable, its reason in place of + // the detail -- not bright and pickable over a click that would + // only bounce off `set_format`'s own guard. + let refusal = preset + .bundle() + .and_then(|(format, _)| self.session.as_ref().and_then(|s| format_refusal(s, format))); + let detail: SharedString = match &refusal { + Some(why) => why.clone().into(), + None => preset.detail().into(), + }; let mut r = entry( ("preset", i), - "", + preset.key(), preset.label().into(), - preset.detail().into(), + detail, preset == current_preset, - true, + refusal.is_none(), ); - r = r.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - match preset.bundle() { - Some((format, quality)) => { - this.set_format(format); - this.quality = quality; - } - // Custom sets nothing -- it only opens the pane where the - // codec and the quality are picked apart. - None => this.export_advanced_open = true, - } - cx.notify(); - })); + if refusal.is_none() { + r = r.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.pick_preset(preset); + cx.notify(); + })); + } list.push(r.into_any_element()); } let advanced_detail = match self.export_advanced_open { @@ -601,9 +607,19 @@ impl Player { SharedString::from(format!("Custom bitrate {}", edit.detail())) } (None, Some(notice)) => notice.clone(), - (None, None) => "the keys are on the rows · enter exports · \ - a click away or esc closes · g/r change the layout" - .into(), + // `g`/`r` only do anything once Advanced is + // open -- they moved off the front pane with + // the rows they reshape -- so a shut pane + // advertises `s` instead of a pair of keys + // with nothing on screen for them to touch. + (None, None) => match self.export_advanced_open { + true => "the keys are on the rows · enter exports · \ + a click away or esc closes · g/r change the layout" + .into(), + false => "the keys are on the rows · enter exports · \ + a click away or esc closes · s for Advanced" + .into(), + }, }), ) // Capped and scrolling like the keybindings list: the