diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index f9bfbdb..bc8f03b 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -80,6 +80,97 @@ impl Quality { } } +/// The primary pane's one row: the format-and-quality bundles most exports +/// actually are, named the way a person asks for one rather than by codec and +/// megabits apart. Every bundle is still exactly a [`Format`] and a +/// [`Quality`] the Advanced pane's own rows already know how to set -- this +/// is a shortcut to the pair, not a third setting kept beside them, so a +/// bundle picked here and a codec picked below never disagree about what is +/// in force. `Custom` sets nothing; it only opens the Advanced pane, for a +/// combination none of the bundles name. +#[derive(Clone, Copy, PartialEq, Debug)] +pub(crate) enum ExportPreset { + Web, + Small, + Master, + AudioOnly, + Custom, +} + +impl ExportPreset { + pub(crate) const ALL: [ExportPreset; 5] = [ + ExportPreset::Web, + ExportPreset::Small, + ExportPreset::Master, + ExportPreset::AudioOnly, + ExportPreset::Custom, + ]; + + pub(crate) fn label(self) -> &'static str { + match self { + ExportPreset::Web => "Web", + ExportPreset::Small => "Small file", + ExportPreset::Master => "Master", + ExportPreset::AudioOnly => "Audio only", + ExportPreset::Custom => "Custom", + } + } + + /// 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 => "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", + } + } + + /// The format and quality this bundle sets, or `None` for `Custom` -- + /// which changes nothing itself, it only opens the pane where the two are + /// set apart. + pub(crate) fn bundle(self) -> Option<(Format, Quality)> { + match self { + ExportPreset::Web => Some((Format::Mp4, Quality::Medium)), + ExportPreset::Small => Some((Format::Av1Mp4, Quality::Low)), + // 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, + } + } + + /// Which bundle the card's current format and quality already are, or + /// `Custom` where they match none of them -- so the primary pane always + /// says something true about what is actually going to be written rather + /// than defaulting to a bundle nobody picked. + pub(crate) fn from_state(format: Format, quality: Quality) -> ExportPreset { + ExportPreset::ALL + .into_iter() + .find(|p| p.bundle() == Some((format, quality))) + .unwrap_or(ExportPreset::Custom) + } +} + /// The export card's format rows: the key that picks one, its name, and what it /// writes -- or, where this program cannot write it, the reason it cannot. A /// format with no entry at all would read as an oversight, and a menu of three 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 2b5cd57..1946af9 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -416,6 +416,14 @@ struct Player { /// Not persisted: this is a look, not a setting. export_grouped: bool, export_refusals_inline: bool, + /// Whether the card's Advanced pane -- codec, container, quality, + /// sound, encoder, subtitles, this machine -- is open under the primary + /// pane's destination and preset rows. Closed by default: most exports + /// are one of the bundled presets, and the fifteen-odd rows under them + /// are what a person who is not one of those goes looking for, kept + /// behind one row rather than eaten by the fold. Not persisted, like the + /// two switches above it -- this is a look, not a setting. + export_advanced_open: bool, /// Which quality row the card has picked, and the megabits typed against /// the custom one. Kept across closes, so a second export offers what the /// first one chose. @@ -742,6 +750,7 @@ fn main() { export_open: false, export_grouped: true, export_refusals_inline: false, + export_advanced_open: false, eq_open: None, // Replaced by the clip's own curve the moment the card // opens; nothing reads it before that. @@ -780,9 +789,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 d7be444..6eac12b 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -376,8 +376,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 @@ -386,10 +388,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 bdb6570..f72a78d 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -255,10 +255,23 @@ 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" { this.export_refusals_inline = !this.export_refusals_inline; + } else if key == "s" { + // The Advanced pane, by keyboard: the primary pane's + // own row for it opens the same way a click does. + this.export_advanced_open = !this.export_advanced_open; } else if key == "n" { // The custom row's field, by keyboard. The digits used // to do this from anywhere in the card, which meant a 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 93b19ce..53ee26c 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 6f72c9f..aa8b0c9 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -121,6 +121,81 @@ impl Player { .into_any_element() }; let mut list: Vec = Vec::new(); + // The primary pane: destination first (the one thing every export + // needs regardless of what it is), then the bundles most exports + // actually are, then the button to the rest. Everything under it is + // exactly the codec, quality, sound and encoder rows the old flat + // card opened on -- a bundle here only sets the same two fields the + // Advanced pane's own Format and Quality rows set, so nothing here + // is a setting of its own to fall out of step with them. + let destination = entry( + ("destination", 0), + "d", + "Destination".into(), + file_name(&self.export_path).into(), + false, + true, + ) + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))) + .into_any_element(); + 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(), + detail, + preset == current_preset, + refusal.is_none(), + ); + 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 { + true => "codec, container, quality, sound, encoder, subtitles — s collapses them" + .to_string(), + false => "codec, container, quality, sound, encoder, subtitles — s for the rows" + .to_string(), + }; + list.push( + entry( + ("export-advanced", 0), + "s", + "Advanced".into(), + advanced_detail.into(), + self.export_advanced_open, + true, + ) + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { + this.export_advanced_open = !this.export_advanced_open; + cx.notify(); + })) + .into_any_element(), + ); + // Everything from here down is the Advanced pane: the codec, its + // container, the quality rows, sound, encoder, subtitles, the two + // display switches and what this machine can encode with -- all of + // it built exactly as the flat card built it, only not pushed at all + // while the pane is shut. + if self.export_advanced_open { if self.export_grouped { list.push(header("FORMAT")); } @@ -347,16 +422,6 @@ impl Player { ) .into_any_element(), ); - let destination = entry( - ("destination", 0), - "d", - "Destination".into(), - file_name(&self.export_path).into(), - false, - true, - ) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))) - .into_any_element(); // The card's own two layout switches. They were `g` and `r` and nothing // else, while the status line under the title advertised both of them: // a hand on the mouse read what they do and had nothing to press. @@ -396,12 +461,6 @@ impl Player { })) .into_any_element(), ); - match self.export_grouped { - true => list.push(destination), - // Flat: the same rows with no headers over them, and the - // destination back at the top where the card used to open with it. - false => list.insert(0, destination), - } if !self.export_refusals_inline && !refusals.is_empty() { // Last, and one line: the reason travels with the name (a footer // that only listed them would be the "why not?" the rows exist to @@ -442,6 +501,7 @@ impl Player { self.hw_caps.clone().unwrap_or_else(|| "asking…".into()) ))); list.push(note(format!("Built in: {}", engine::caps::software()))); + } // self.export_advanced_open // What the rows add up to, which is the one thing that has to be right: // codec, box, size, rate, sound, where it goes and about how big. Two // lines, outside the scrolling list, so it is on screen whatever the @@ -547,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