From e5fd61080cfc8a34c981dd0537058d9fbfa95da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 9 Sep 2026 17:57:38 +0300 Subject: [PATCH] =?UTF-8?q?wip(export):=20moment=20rebuild,=20capped=20mid?= =?UTF-8?q?-work=20=E2=80=94=20NOT=20green?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/app/src/export_ui.rs | 464 ++++--------- crates/app/src/keymap.rs | 143 +--- crates/app/src/layout.rs | 11 +- crates/app/src/main.rs | 63 +- crates/app/src/menus.rs | 2 + crates/app/src/player/actions.rs | 2 +- crates/app/src/player/cards.rs | 35 +- crates/app/src/player/export.rs | 225 +++--- crates/app/src/subs.rs | 1 + crates/app/src/tests/cards.rs | 476 +++++-------- crates/app/src/tests/media.rs | 166 +---- crates/app/src/tests/mod.rs | 18 +- crates/app/src/ui/cards.rs | 1118 ++++++++---------------------- crates/app/src/ui/widgets.rs | 2 + 14 files changed, 816 insertions(+), 1910 deletions(-) diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index c4f9ddb..d8e7158 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -66,156 +66,6 @@ pub(crate) fn sample_rate_choices(current: Option) -> Vec { rows } -/// What the export card offers, top to bottom. Bitrate is the only thing the -/// encoder actually takes: the codec and the container are what this program -/// can write and nothing else, so the card states them rather than offering -/// them. -#[derive(Clone, Copy, PartialEq, Debug)] -pub(crate) enum Quality { - Exact, - Auto, - Low, - Medium, - High, - Custom, -} - -impl Quality { - pub(crate) const ALL: [Quality; 6] = [ - Quality::Exact, - Quality::Auto, - Quality::Low, - Quality::Medium, - Quality::High, - Quality::Custom, - ]; - - pub(crate) fn label(self) -> &'static str { - match self { - Quality::Exact => "Exact", - Quality::Auto => "Auto", - Quality::Low => "Low", - Quality::Medium => "Medium", - Quality::High => "High", - Quality::Custom => "Custom", - } - } - - /// The figure the row stands for, said in the units the row is chosen by. - pub(crate) fn detail(self, custom_mbps: u32) -> String { - match self { - // corner-cut: worded without naming the mechanism (which codec, - // which container) -- DESIGN.md §8 keeps a card's detail line a - // fact about the *output*, not an instruction about how to get - // there; [`exact_refusal`] is where the mechanism's own limits - // are said, once the row has actually been picked. - Quality::Exact => "input quality — copy where cuts allow".to_string(), - Quality::Auto => "from the picture size and frame rate".to_string(), - Quality::Custom => { - format!("{custom_mbps} Mbps — wheel or ± steps, n types one, {MBPS_MIN}–{MBPS_MAX}") - } - other => format!( - "{} Mbps", - export_settings(other, 0, Format::Mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto) - .bitrate - .unwrap_or_default() - / 1_000_000 - ), - } - } -} - -/// 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 => "no fixed codec or quality", - } - } - - /// 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 @@ -273,6 +123,10 @@ pub(crate) const FORMATS: [(&[Format], &str, &str, &str); 8] = [ /// The boxes one codec may be written into, in the order its container row /// cycles them. Empty for a codec this program cannot write at all. +/// Not on the export moment any more: the Settings surface is what shows +/// this (`ui::settings_stance`). Kept and named rather than deleted -- the +/// state and its setter are the same ones the moment used to drive. +#[allow(dead_code)] pub(crate) fn containers(format: Format) -> &'static [Format] { FORMATS .into_iter() @@ -284,6 +138,10 @@ pub(crate) fn containers(format: Format) -> &'static [Format] { /// This row's format under the container `current` is already in, or the row's /// first when it has no such box: an AV1 picked from a WAV lands in Matroska, /// and picked from an mp4 stays in the mp4. +/// Not on the export moment any more: the Settings surface is what shows +/// this (`ui::settings_stance`). Kept and named rather than deleted -- the +/// state and its setter are the same ones the moment used to drive. +#[allow(dead_code)] pub(crate) fn same_box(row: &[Format], current: Format) -> Option { row.iter() .copied() @@ -294,6 +152,10 @@ pub(crate) fn same_box(row: &[Format], current: Format) -> Option { /// The next box for the same codec, wrapping -- what the container row's key /// does. The format itself for a codec with only one, so the stroke cannot /// change what it is not offering. +/// Not on the export moment any more: the Settings surface is what shows +/// this (`ui::settings_stance`). Kept and named rather than deleted -- the +/// state and its setter are the same ones the moment used to drive. +#[allow(dead_code)] pub(crate) fn next_container(format: Format) -> Format { let row = containers(format); let at = row.iter().position(|&f| f == format).unwrap_or(0); @@ -302,26 +164,6 @@ pub(crate) fn next_container(format: Format) -> Format { .unwrap_or(format) } -/// Why the quality rows say nothing about this format, or `None` where they -/// decide the picture. Only a picture encoder is given a bitrate here: the two -/// lossless audio formats have none to give and MP3 is written at one fixed -/// figure, so a live row over either would be a control that changes nothing. -pub(crate) fn bitrate_refusal(format: Format) -> Option<&'static str> { - match format { - Format::Wav | Format::Flac => Some("lossless audio — no bitrate to pick"), - Format::Mp3 => Some("sound only — its rate is the Sound row"), - // The guard is the question and not a list of names: an audio format - // added without a line of its own above would otherwise show live - // quality rows over a file that has no picture to spend a bitrate on. - // OGG is exactly that format -- and it wants this sentence rather than - // one of its own, because its *Sound* row already says the Vorbis half - // ("quality-coded — Vorbis holds no rate to pick") and two rows saying - // the same thing is one of them wasted. - _ if !format.has_video() => Some("sound only — no picture to spend a bitrate on"), - _ => None, - } -} - /// What one of the colour card's own strokes does. Its keys are card-local -- /// they mean nothing outside it -- so they are a table here rather than keymap /// bindings, exactly as the export card's format initials are. Listed in @@ -680,6 +522,10 @@ pub(crate) fn encoder_choices(current: EncoderSeat) -> Vec { /// vendored AV1 encoder (2026-08-10), so the pick is theirs to make and the /// risk is theirs to be told about. `None` for every other pair, which is what /// keeps this from becoming a row nobody reads. +/// Not on the export moment any more: the Settings surface is what shows +/// this (`ui::settings_stance`). Kept and named rather than deleted -- the +/// state and its setter are the same ones the moment used to drive. +#[allow(dead_code)] pub(crate) fn av1_hw_warning(format: Format, seat: EncoderSeat) -> Option<&'static str> { (seat == EncoderSeat::Hardware && matches!(format, Format::Av1 | Format::Av1Mp4)) .then_some("AV1 on the GPU reset this machine's driver once — Software is the safe seat") @@ -731,45 +577,6 @@ pub(crate) fn next_resolution(current: (u32, u32), native: (u32, u32)) -> (u32, sizes[at.map_or(0, |at| (at + 1) % sizes.len())] } -/// The first of the two lines the card keeps above its button: what will be -/// *inside* the file. [`format_line`]'s codec and box, then the project's own -/// picture size and rate -- which is what a video export is written at however -/// many sizes and rates the media on the timeline are -- and last what the -/// sound will be, or that there is none. Every field here is one `ffprobe` -/// reads back off the finished file, so the line is checkable rather than a -/// promise. -pub(crate) fn summary_head( - format: Format, - picture: Option<((u32, u32), f64)>, - audio: &str, -) -> String { - let line = match picture.filter(|_| format.has_video()) { - Some(((w, h), fps)) => { - format!("{} · {w}x{h} · {} fps", format_line(format), fps_label(fps)) - } - None => format_line(format).to_string(), - }; - join_detail(&line, audio) -} - -/// The second: where it lands, roughly how big, and what will encode the -/// picture -- the seat as the probe found it (`…` until it lands, never a -/// guess), which is what the running export then names on its progress line. -pub(crate) fn summary_tail( - path: &Path, - bytes: Option, - seat: Option<&'static str>, - video: bool, -) -> String { - let size = bytes.map_or_else(String::new, |bytes| format!("≈ {}", size_label(bytes))); - let seat = match (video, seat) { - (true, Some(seat)) => seat, - (true, None) => "encoder …", - (false, _) => "", - }; - join_detail(&join_detail(&file_name(path), &size), seat) -} - /// A frame rate as a person writes it: `30`, not `30.000`, and `23.976` for the /// rate that is a ratio. pub(crate) fn fps_label(fps: f64) -> String { @@ -782,48 +589,26 @@ pub(crate) fn fps_label(fps: f64) -> String { } } -/// About how big a *chosen* bitrate makes the file: the picture's bits over the -/// timeline's length, in bytes -- the unit the line is written in is -/// [`size_label`]'s to pick. `None` for `Auto`, whose figure is the encoder's to -/// decide, and for a format with no bitrate at all -- a number nobody picked is -/// not an estimate. The sound and the container's own overhead are not in it, -/// which is why the card says "≈". -pub(crate) fn estimated_bytes(bitrate: Option, duration: f64) -> Option { - let bitrate = bitrate.filter(|&b| b > 0 && duration > 0.)?; - Some((bitrate as f64 * duration / 8.).round() as u64) +/// About how big the budget makes the file: every bit that is written -- +/// the picture's rate and the sound's -- over the exported range, in bytes. +/// The container's own overhead is not in it, which is why the row says "≈". +pub(crate) fn estimated_bytes(bps: u64, seconds: f64) -> u64 { + ((bps as f64) * seconds.max(0.) / 8.).round() as u64 } -/// A size in the largest unit that can state it, [`rate_scale`]'s rule: -/// megabytes for an export of any length, kilobytes below the one a whole -/// megabyte rounds away. A three second clip at the floor bitrate really is -/// 375 kB, and "≈ 0 MB" would be this line saying the file it is about to write -/// is empty -- the one thing the size field is there to deny. Never "0 kB" -/// either: an estimate that exists is at least a kilobyte of file. +/// A size as the budget row says it: gigabytes with two decimals once the +/// file is one, whole megabytes under that. Never a decimal megabyte -- the +/// estimate is an "≈" and a tenth of a megabyte is precision it does not have. pub(crate) fn size_label(bytes: u64) -> String { - match (bytes as f64 / 1e6).round() as u64 { - 0 => format!("{} kB", (bytes as f64 / 1e3).round().max(1.) as u64), - mb => format!("{mb} MB"), + match bytes >= 1_000_000_000 { + true => format!("{:.2} GB", bytes as f64 / 1e9), + false => format!("{} MB", (bytes as f64 / 1e6).round() as u64), } } -/// What is in the file and what box it is in, which is the head of the summary. -/// Terse on purpose: the fields after it (size, rate, sound) are what the line -/// is *for*, and a head that spent its width on prose used to push the whole -/// summary onto a second line -- what each codec means is on its row. -pub(crate) fn format_line(format: Format) -> &'static str { - match format { - Format::Mp4 => "H.264 · MP4", - Format::Av1 => "AV1 · MKV", - Format::Av1Mp4 => "AV1 · MP4", - Format::Hevc => "HEVC intra · MKV", - Format::HevcMp4 => "HEVC intra · MP4", - // The three whose codec *is* their box: naming it twice would be the - // only field on this line that says nothing. - Format::Wav => "16-bit PCM · WAV", - Format::Flac => "FLAC · lossless", - Format::Mp3 => "MP3 · lossy", - Format::Ogg => "Vorbis · OGG", - } +/// The budget itself, in Mbps to one decimal: the number the lever reads. +pub(crate) fn rate_label(bps: u64) -> String { + format!("{:.1}", bps as f64 / 1e6) } /// The row a format is picked by, which is what a refusal calls it: the codec, @@ -845,77 +630,127 @@ pub(crate) fn retarget(path: &std::path::Path, format: Format) -> PathBuf { path } -/// The card's rows as the engine takes them. `Auto` leaves the bitrate to the -/// exporter, which derives it from the picture; the fixed rows are figures that -/// hold from 720p to 1080p, and a typed one is passed exactly as typed -- the -/// engine clamps every explicit bitrate to 1..50 Mbps (`MAX_EXPLICIT_BITRATE`), so this -/// must not clamp it a second time and disagree about where the edge is. +/// The moment's one number as the engine takes it. The budget is always +/// explicit now -- the lever opens on the engine's own automatic figure +/// ([`auto_bps`]) rather than on nothing, so there is no "Auto" left to send +/// as `None` -- and the engine clamps it to `MIN_BITRATE..MAX_EXPLICIT_BITRATE` +/// exactly where [`BPS_MIN`]/[`BPS_MAX`] do, so neither can disagree about the +/// edges. /// /// The bitrate travels even for an audio format, where the engine ignores it: -/// one settings value, and a row the card has dimmed cannot have been changed. +/// one settings value, and a row the moment does not show cannot have been +/// changed. pub(crate) fn export_settings( - quality: Quality, - custom_mbps: u32, + bitrate: u64, format: Format, audio_kbps: u32, seat: EncoderSeat, ) -> ExportSettings { ExportSettings { format, - // Always travels, exactly as the picture's bitrate does above: the - // engine ignores it where nothing encodes the sound, and a row the card - // has dimmed cannot have been changed. audio_kbps: Some(audio_kbps), - bitrate: match quality { - // A copied span carries its source's own bits, and a fallback - // re-encode -- the only case `bitrate` reaches an encoder under - // Exact -- is the automatic figure ([`engine::export::run`]), - // not a preset's, so this asks for neither. - Quality::Exact | Quality::Auto => None, - Quality::Low => Some(2_000_000), - Quality::Medium => Some(6_000_000), - Quality::High => Some(12_000_000), - Quality::Custom => Some(u64::from(custom_mbps) * 1_000_000), - }, - exact: quality == Quality::Exact, - // The card's own row now ([`encoder_choices`]), kept with the project: - // it was a `VE_SW_ENC` env pin and nothing else, which is a switch - // nobody exporting a film would ever find. + bitrate: Some(bitrate), + // The copy path (the old `Quality::Exact`) is off this surface: the + // moment is one budget, and a copy is the absence of one. + // `engine::export` keeps the path and its own tests; nothing in the + // app asks for it. + exact: false, seat, - // The picked track is put on by `start_export`, which is the only - // caller that writes a file; the rest of them are asking about the - // bitrate and the format. subtitles: Vec::new(), - // Neither is a delivery setting: both belong to the stand-ins - // [`engine::proxy`] writes -- every frame a key frame costs bits - // nobody delivering wants, and a file kept in its source's colour - // space is one for this editor to read back rather than to hand - // anybody. intra_only: false, keep_source_colour: false, - // Set by `start_export`, which knows the player's mark; this helper is - // also asked for the estimate alone, which has no range to give. range: None, } } -/// What the engine will code an explicit bitrate at, in whole Mbps: outside -/// this it clamps (`export.rs` `MIN_BITRATE`/`MAX_EXPLICIT_BITRATE`), so a -/// number typed past either end would be written as a different one. The field -/// refuses it instead of clamping quietly -- a card that changes the user's -/// number without saying so is the one thing a field like this must never do. +/// The budget's bounds, the engine's own (`engine::export`'s `MIN_BITRATE` +/// and `MAX_EXPLICIT_BITRATE`): a number outside them would be written as a +/// different one, so the lever and the field clamp to exactly these. +pub(crate) const BPS_MIN: u64 = 1_000_000; +pub(crate) const BPS_MAX: u64 = 50_000_000; + +/// A wheel notch, and a notch with shift held: 0.1 and 1 Mbps. Fifty presses +/// is not a way across this range, and a tenth is the smallest step the row's +/// own readout can show. +pub(crate) const BPS_FINE: u64 = 100_000; +pub(crate) const BPS_COARSE: u64 = 1_000_000; + +/// The engine's automatic figure for a picture of this size and rate +/// (`engine::export`'s `BITS_PER_PIXEL` rule and the range it clamps the +/// derived number into), which is what the lever opens on before anybody has +/// chosen: a budget row reading 0 Mbps -- the old `custom_mbps: 0` default -- +/// was a promise to write an empty file. +const BITS_PER_PIXEL: f64 = 0.1; +const BPS_AUTO_MAX: u64 = 20_000_000; + +pub(crate) fn auto_bps(width: u32, height: u32, fps: f64) -> u64 { + let raw = f64::from(width) * f64::from(height) * fps * BITS_PER_PIXEL; + (raw as u64).clamp(BPS_MIN, BPS_AUTO_MAX) +} + +/// What was typed into the budget field, as a rate. Four ways to say one: +/// `850k` and `6.5M` are rates in their own units, a bare `6.5` is Mbps (the +/// unit the row reads in), and `1.2G` is a *file size* -- the one thing a +/// person actually wants to hit -- converted through the exported range and +/// the sound's own rate into the picture rate that lands there. /// -/// The ceiling was 20, which was never a limit of any encoder here: it was the -/// top of the range the exporter *derives* an automatic bitrate in, borrowed as -/// the cap on a typed one. A 1080p master or a 4K edit wants more than that, so -/// the asked-for rate has its own ceiling now and this is it. -pub(crate) const MBPS_MIN: u32 = 1; -pub(crate) const MBPS_MAX: u32 = 50; - -/// How many digits the field takes. Two reach the ceiling; the third is there so -/// a number *past* it can be typed whole and refused in its own words, rather -/// than being dropped keystroke by keystroke. -pub(crate) const MBPS_DIGITS: usize = 3; +/// Clamped to the engine's bounds rather than refused: the moment shows the +/// parsed number immediately, so a clamp is visible in the same keystroke. +/// `None` is only ever "that is not a number". +pub(crate) fn parse_budget(text: &str, seconds: f64, audio_bps: u64) -> Option { + let text = text.trim().to_ascii_lowercase(); + let text = text.trim_end_matches("bps").trim_end_matches('b').trim_end(); + let (digits, unit) = match text.chars().last()? { + c @ ('k' | 'm' | 'g') => (&text[..text.len() - c.len_utf8()], c), + _ => (text, 'm'), + }; + let n: f64 = digits.trim().parse().ok()?; + if !n.is_finite() || n <= 0. { + return None; + } + let bps = match unit { + 'k' => n * 1e3, + 'm' => n * 1e6, + _ => { + if seconds <= 0. { + return None; + } + (n * 1e9 * 8. / seconds) - audio_bps as f64 + } + }; + Some((bps.max(0.) as u64).clamp(BPS_MIN, BPS_MAX)) +} + +/// The faintest line on the moment: what the export resolved to on its own -- +/// the codec, the sound, whether it is the whole film or the marked span, and +/// which seat writes the picture. A readout, never a control: everything in it +/// is set in Settings now. +pub(crate) fn plan_line( + format: Format, + audio: &str, + marks: Option<&str>, + hardware: bool, +) -> String { + let mut parts: Vec = Vec::new(); + if format.has_video() { + parts.push(format_label(format).to_string()); + } + if !audio.is_empty() { + parts.push(audio.to_string()); + } + parts.push(match (marks, format.has_video()) { + (Some(marks), _) => format!("marks {marks}"), + (None, true) => "whole film".to_string(), + (None, false) => "sound only".to_string(), + }); + if format.has_video() { + parts.push(match hardware { + true => "GPU".to_string(), + false => "SW".to_string(), + }); + } + parts.join(" · ") +} /// A clip's share of the lane. A timeline with no length reads as one full-width /// box rather than as NaN, which gpui would carry into layout. @@ -932,41 +767,6 @@ pub(crate) const MBPS_DIGITS: usize = 3; /// cannot say what the timeline says (`export::copy_audio`), so none of them is /// a refusal any more -- and every video format carries the sound, so there is /// nothing here that is one format's alone. -/// Why the Exact row would refuse this project's own picked format right -/// now, asked before the button is pressed rather than minutes into a -/// worker -- [`engine::export::exact_refusal`] is the same gate `start` -/// checks again, so a caller here and the worker can never disagree about -/// whether Exact is honoured. `None` for every quality but `Exact` itself, -/// since nothing else has anything to refuse. -pub(crate) fn exact_refusal( - session: &PlaybackSession, - format: Format, - quality: Quality, -) -> Option { - if quality != Quality::Exact { - return None; - } - let (project, meta) = session.export_snapshot(); - let settings = export_settings(quality, 0, format, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto); - engine::export::exact_refusal(&project, &meta, &settings) -} - -/// Which format picking Exact should set, from the source's own codec -- -/// "the input's own quality" means the input's own codec, so this is what -/// `Player::pick_quality` derives the format from rather than leaving -/// whatever format a previous pick left behind. `None` for a codec Exact has -/// no copy path for at all (h264); the row itself still refuses through -/// [`exact_refusal`] in that case, since a mixed-source project can fail the -/// same way after the format is set. -pub(crate) fn exact_format(session: &PlaybackSession) -> Option { - let (_, meta) = session.export_snapshot(); - match meta.codec { - engine::demux::Codec::Hevc => Some(Format::Hevc), - engine::demux::Codec::Av1 => Some(Format::Av1), - _ => None, - } -} - pub(crate) fn format_refusal(session: &PlaybackSession, format: Format) -> Option { if !format.has_video() { return None; diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 1b43c31..31e330d 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -613,31 +613,7 @@ pub enum Reach { Gesture, } -/// The codec row's keys, from the export card's own table. Typed out here once, -/// it named six of the seven codecs the same row's label advertised -- OGG had -/// a key (`o`) that this card never said. -fn codec_chord() -> String { - crate::FORMATS - .iter() - .map(|(_, stroke, ..)| *stroke) - .filter(|stroke| !stroke.is_empty()) - .collect::>() - .join(" / ") -} - -/// 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; 35]> = std::sync::LazyLock::new(|| { +pub static FIXED: std::sync::LazyLock<[Fixed; 27]> = 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 @@ -665,50 +641,27 @@ pub static FIXED: std::sync::LazyLock<[Fixed; 35]> = std::sync::LazyLock::new(|| }, Fixed { chord: "n".into(), - label: "Open the custom export bitrate field — ↑↓ step it", - category: Category::File, - reach: Reach::Click("quality"), - }, - Fixed { - chord: "0–9".into(), - label: "Type into that field — nothing outside it", - category: Category::File, - reach: Reach::Click("mbps-up"), - }, - Fixed { - chord: codec_chord(), - label: "Pick the export codec: H.264, AV1, HEVC, WAV, FLAC, MP3 or OGG", - category: Category::File, - reach: Reach::Click("format"), - }, - // The rest of the export card's own rows, each on the letter its row is - // named after. They shadow the clip keys of the same letter while the card - // is up, exactly as its digits shadow nothing and its arrows would: a modal - // card owns the keyboard, and cutting a clip under it is not a thing that - // can happen anyway. - Fixed { - chord: "c".into(), - label: "Switch the export container: Matroska or MP4", + label: "Say the export budget: 850k, 6.5M, 6.5 or 1.2G of file", category: Category::File, - reach: Reach::Click("container"), + reach: Reach::Click("budget"), }, Fixed { - chord: "q".into(), - label: "Step through the export quality rows", + chord: "− / + / ← →".into(), + label: "Move the export budget — shift steps whole megabits", category: Category::File, - reach: Reach::Click("quality"), + reach: Reach::Click("budget-track"), }, Fixed { - chord: "b".into(), - label: "Step through the export sound bitrates", + chord: "0–9".into(), + label: "Type into an open field — the budget, or a clip's duration", category: Category::File, - reach: Reach::Click("sound"), + reach: Reach::Click("budget"), }, Fixed { - chord: "e".into(), - label: "Step the export encoder seat: Auto, Hardware or Software", + chord: "backspace".into(), + label: "Erase a character in the budget or duration field", category: Category::File, - reach: Reach::Click("encoder"), + reach: Reach::Click("budget"), }, Fixed { chord: "d".into(), @@ -716,42 +669,12 @@ pub static FIXED: std::sync::LazyLock<[Fixed; 35]> = 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", - category: Category::File, - reach: Reach::Click("export-layout"), - }, - Fixed { - chord: "r".into(), - label: "Export card: the formats with no encoder as rows or as one line", - category: Category::File, - reach: Reach::Click("export-refusals"), - }, Fixed { chord: "enter".into(), - label: "Start the export — or commit the bitrate field", + label: "Start the export — or take the budget being typed", category: Category::File, reach: Reach::Click("export-confirm"), }, - Fixed { - chord: "backspace".into(), - label: "Erase a digit in the bitrate field", - category: Category::File, - reach: Reach::Click("mbps-down"), - }, // The equalizer card's own input, for the same reason the export card has // its own: a band nothing but a drag can reach is a band half the users of // this editor cannot move at all. Card-local, so none of them is bindable. @@ -1772,46 +1695,6 @@ mod tests { assert_eq!(whole("edith-keys 1\n").chord(ActionId::Cut), "--"); } - /// The one row of [`FIXED`] that speaks for a whole table elsewhere: it - /// named six keys for seven codecs, and OGG's `o` was a stroke the card - /// never mentioned. The chord is generated from `FORMATS` now, and this - /// holds the *label* to the same table -- a codec added there with no name - /// in this row fails here rather than in a user's hands. - #[test] - fn the_codec_row_says_every_codec_the_export_card_offers() { - let row = super::FIXED - .iter() - .find(|f| f.label.starts_with("Pick the export codec")) - .expect("the codec row"); - let keys: Vec<&str> = row.chord.split(" / ").collect(); - for (boxes, stroke, label, _) in crate::FORMATS { - if stroke.is_empty() { - // A codec this program cannot write at all has no key and no - // business in this row. - assert!(boxes.is_empty(), "{label} has a box but no stroke"); - assert!(!keys.contains(&stroke)); - continue; - } - assert!( - keys.contains(&stroke), - "{label}'s key {stroke:?} is not in {:?}", - row.chord - ); - assert!( - row.label.contains(label), - "{label} is not named in {:?}", - row.label - ); - } - assert_eq!( - keys.len(), - crate::FORMATS - .iter() - .filter(|(_, s, ..)| !s.is_empty()) - .count() - ); - } - #[test] fn a_saved_keymap_comes_back_off_the_disk() { // Its own directory, never the real config one: this test writes. diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index 569952b..9dd4372 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -78,10 +78,14 @@ pub(crate) const KEYS_ROW_H: f32 = HIT_MIN; /// the whole file. At `KEYS_W` every one of those wrapped to two lines, which is /// the card the user called unfriendly. Still inside the 640 px floor with the /// scrim showing either side of it. +/// The export moment's height (the approved artboard's 200px): three rows, +/// never a scroll -- the card it replaced grew a capped, scrolling list. +pub(crate) const EXPORT_MOMENT_H: f32 = 200.; + pub(crate) const EXPORT_W: f32 = 420.; -/// The column the key of a row is printed in, wide enough for `0–9`: every row -/// in the export card says what picks it, so the card is drivable by keyboard -/// without a legend to memorise. + +/// The column a key is printed in, wide enough for `0-9` -- the width the +/// subtitle plan line is still measured against ([`SUB_PLAN_CHARS`]). pub(crate) const EXPORT_KEY_W: f32 = 26.; /// The menu a right-click on a clip opens: wide enough for the longest label /// beside the stroke that does the same thing, with the click targets `HIT_MIN` @@ -128,6 +132,7 @@ pub(crate) const LIST_CHAR_W: f32 = 6.; /// in front of the value. Not a track count -- what walks the Destination row /// off the bottom of the card is the *wrapping*, and thirty-five one-word /// labels wrap less than three long ones. +#[allow(dead_code)] // the subtitle plan line lives in Settings now pub(crate) const SUB_PLAN_CHARS: usize = (3. * (EXPORT_W - 12. - 12. - (10. + 8. + EXPORT_KEY_W + 8. + 9. * LIST_CHAR_W)) / LIST_CHAR_W) as usize; diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index c96667e..9366adf 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -539,36 +539,22 @@ struct Player { /// time -- opening either closes the other, since both are the whole window /// and two stacked scrims say nothing about which one is listening. export_open: bool, - /// How the card lays its rows out, and where the formats this program - /// cannot write are said. Two shapes of the same card, kept behind `g` and - /// `r` so the choice between them can be made by looking at both rather - /// than by argument: sections with headers against one flat list, and a - /// collapsed "cannot write" footer against a dimmed row each. The defaults - /// are grouped and collapsed -- the five dead rows used to eat the fold. - /// 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. - quality: Quality, - custom_mbps: u32, - /// The custom row's number *while it is being typed*, or `None` when nobody - /// is typing one. A field with a caret in it and not a key capture: digits - /// used to change the bitrate from anywhere in the card, with no caret to - /// say where they were landing and nothing to look at before the number - /// took effect. Nothing in this card takes gpui focus (the root keeps the - /// keyboard), so the field is a modal state on the player exactly as a - /// waiting rebind row is, and the root's handler is what types into it. - mbps_edit: Option, + /// The export budget, in bits per second -- the moment's one number, and + /// the only thing the encoder actually takes. Zero means nobody has + /// chosen: the lever then reads the engine's own automatic figure for + /// this picture ([`Player::budget_bps`]), which is what keeps it off the + /// "0 Mbps" the old `custom_mbps: 0` default put on screen. + custom_bps: u64, + /// The budget *while it is being typed*, or `None` when nobody is typing. + /// Free text and not digits: `850k`, `6.5M`, `6.5` and `1.2G` are all + /// ways of saying one budget ([`parse_budget`]). Nothing on this surface + /// takes gpui focus (the root keeps the keyboard), so the field is a + /// modal state on the player and the root's handler types into it. + budget_edit: Option, + /// The budget track's box, recorded at prepaint -- [`Self::color_bars`]' + /// own reason: a mouse listener is handed the window position only, and + /// [`frac_along`] is what turns it into a rate. + budget_bar: Rc>>, /// The Clip tab's transition duration row, the same way (DEBT #111): /// the anchor clip's frame count while it is being typed, `None` when /// nobody is. Opened on the row's own click, closed on the same field's @@ -978,9 +964,6 @@ fn main() { lanes_scroll: ScrollHandle::new(), eq_scroll: ScrollHandle::new(), export_open: false, - export_grouped: true, - export_refusals_inline: false, - export_advanced_open: false, eq_open: None, card_maximized: ui::dock_stance::load_maximized(), // Replaced by the clip's own curve the moment the card @@ -1030,14 +1013,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 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, + // Nobody has chosen a budget yet, which is not the same + // as a budget of nothing: the lever opens on the engine's + // own automatic figure for the picture that is open. + custom_bps: 0, + budget_edit: None, + budget_bar: Rc::default(), transition_edit: None, // ...and the rate the sound has always been written at. audio_kbps: DEFAULT_AUDIO_KBPS, diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index e933aac..8c0a488 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -70,6 +70,7 @@ pub(crate) enum Pick { Fit(Lane, usize), /// What the export's *sound* is coded at. Opened from the card's Sound row, /// which is the only place it means anything. + #[allow(dead_code)] // opened from Settings now AudioRate, /// Which HDR-to-SDR rendition the project is watched and exported in /// ([`engine::tonemap::Preset`]). Opened from the panel, beside the two @@ -82,6 +83,7 @@ pub(crate) enum Pick { /// Which encoder an export writes the picture with /// ([`engine::export::EncoderSeat`]). Opened from the card's Encoder row, /// which is the only place it means anything. + #[allow(dead_code)] // opened from Settings now Encoder, } diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 53851c5..8b990da 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -443,7 +443,7 @@ impl Player { // A number being typed is a value under the arrows, exactly as a card's // slider is -- so a held arrow runs it. Asked before the export card // below, which otherwise repeats nothing. - if self.mbps_edit.is_some() { + if self.budget_edit.is_some() { Repeat::Card } else if self.keys_open || self.export_open || self.exporting().is_some() { Repeat::Nothing diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index c48163a..b455f25 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -1314,9 +1314,9 @@ impl Player { self.keys_open = false; self.settings_open = false; self.export_open = false; - // The two things typed *into* the export card go with it: a field left - // open would take the next keystroke for a card that is gone. - self.mbps_edit = None; + // The two things typed *into* the export moment go with it: a field + // left open would take the next keystroke for a card that is gone. + self.budget_edit = None; self.picker = None; self.eq_open = None; self.eq_dragging = false; @@ -1788,29 +1788,12 @@ impl Player { } return true; } - // The export card's custom bitrate field: the mouse door is the - // steppers and the row's own click (`Player::edit_mbps`), but the - // `0–9`/backspace/enter/esc chords `keymap::FIXED` already - // advertises need a keyboard door too, or a hand with no mouse - // could open the field and never fill it in. - if self.export_open { - if let Some(edit) = &mut self.mbps_edit { - if key == ESCAPE { - self.mbps_edit = None; - } else if key == "enter" { - if let Some(mbps) = edit.commit() { - self.custom_mbps = mbps; - self.mbps_edit = None; - } - } else if key == "backspace" { - edit.backspace(); - } else if let Ok(digit) = key.parse::() { - edit.digit(digit); - } else { - return false; - } - return true; - } + // The export moment: its own chords, and every other stroke + // swallowed while it is up -- a chord this surface consumes must + // never also reach the room's keymap underneath it + // ([`Player::export_moment_key`]). + if self.export_moment_key(key, shift, cx) { + return true; } false } diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index ae1ed39..e823ad5 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -1,7 +1,6 @@ //! What is cached about the media and the machine, and the export the //! two of them decide. -use crate::ui::widgets::NumberEdit; use crate::*; impl Player { @@ -353,8 +352,7 @@ impl Player { return; }; let settings = export_settings( - self.quality, - self.custom_mbps, + self.budget_bps(), self.format, self.audio_kbps, self.encoder_seat(), @@ -460,18 +458,19 @@ impl Player { // was waiting in. Nor may a half-typed number: the card opens on the // bitrate it will write, never on digits left behind by a closed one. self.keys_open = false; - self.mbps_edit = None; + self.budget_edit = None; cx.notify(); } - /// 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. `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. + /// A format row, from Settings. 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. + /// `false` on a refusal, so a caller with more than the format to write + /// knows not to write the rest of it either. + #[allow(dead_code)] // shown by Settings now, not by the moment 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. + // The one door both the row and its initial go through, so a format + // the room greys out cannot be picked by keyboard either. if let Some(why) = self .session .as_ref() @@ -485,46 +484,11 @@ impl Player { 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, - } - } - - /// A quality row, by click or by its own key (`Custom` goes through - /// [`Self::edit_mbps`] instead). Exact is the one row that is also a - /// format decision -- "the input's own quality" means the input's own - /// codec, so picking it derives the container from the source rather - /// than leaving whatever format a previous pick left behind for - /// [`exact_refusal`] to refuse minutes later. A source this cannot copy - /// (h264, mixed sources) leaves the format alone; the row itself - /// ([`crate::ui::cards`]'s quality list) already says why. - pub(crate) fn pick_quality(&mut self, quality: Quality) { - self.quality = quality; - if quality != Quality::Exact { - return; - } - let Some(format) = self.session.as_ref().and_then(exact_format) else { - return; - }; - self.set_format(format); - } - /// The container row: the same codec in the other box, which retargets the /// destination exactly as picking a codec does -- and does nothing at all /// for a codec with only one box, so the stroke cannot invent a choice the /// card is not offering. + #[allow(dead_code)] // shown by Settings now, not by the moment pub(crate) fn cycle_container(&mut self) { self.set_format(next_container(self.format)); } @@ -561,51 +525,134 @@ impl Player { } } - /// The custom bitrate by pointer: the typed digits were the only control in - /// this card a mouse could not reach. Clamped to the range the row states - /// (the engine's own 1..50 Mbps), and picking the row is part of the step -- - /// a stepper that moves a number nobody is using would move nothing. - pub(crate) fn nudge_mbps(&mut self, step: i32) { - self.custom_mbps = - (self.custom_mbps as i32 + step).clamp(MBPS_MIN as i32, MBPS_MAX as i32) as u32; - self.quality = Quality::Custom; + /// The budget in force: what was chosen, or -- before anybody has chosen + /// -- the engine's own automatic figure for the picture that is open + /// ([`auto_bps`], its `BITS_PER_PIXEL` rule). Never zero, which is the + /// whole point: the lever it feeds is a promise about the file. + pub(crate) fn budget_bps(&self) -> u64 { + if self.custom_bps > 0 { + return self.custom_bps; + } + self.session.as_ref().map_or(BPS_MIN * 6, |s| { + let (w, h) = s.resolution(); + auto_bps(w, h, s.meta().frame_rate) + }) } - /// The same number under the wheel, one step a notch, up for more: fifty - /// presses of a stepper is not a way to reach the top of this range, and the - /// wheel is what this editor already moves a value with (the timeline's - /// zoom and scroll are the same gesture). Hold-to-run stays the keyboard's, - /// as it is on every other card here -- a button that repeats while held is - /// not a thing this program has. - /// - /// It moves the *field* while one is open, exactly as ↑↓ do, so the two - /// ways in never disagree about which number is being changed. - pub(crate) fn wheel_mbps(&mut self, event: &ScrollWheelEvent) { + /// What the sound costs over the same span, in bits per second -- the + /// other half of "how big is it": zero for a format that writes no sound + /// and for a timeline that has none. + pub(crate) fn audio_bps(&self) -> u64 { + match self.audio_rate_refusal().is_none() { + true => u64::from(self.audio_kbps) * 1_000, + false => 0, + } + } + + /// How many seconds of film the export writes: the marked span where + /// there is one, the whole timeline otherwise. The size on the budget row + /// is this times the rate. + pub(crate) fn export_seconds(&self) -> f64 { + self.session.as_ref().map_or(0., |s| match self.range { + Some((start, end)) => f64::from(end - start) / s.meta().frame_rate, + None => s.timeline_duration(), + }) + } + + /// The lever by `steps` notches -- a tenth of a Mbps each, a whole Mbps + /// with shift. Clamped to the engine's own bounds, so the number on the + /// row is the number the encoder is given. + pub(crate) fn nudge_budget(&mut self, steps: i32, coarse: bool) { + let step = i64::from(steps) + * match coarse { + true => BPS_COARSE as i64, + false => BPS_FINE as i64, + }; + let at = self.budget_bps() as i64 + step; + self.custom_bps = (at.max(0) as u64).clamp(BPS_MIN, BPS_MAX); + } + + /// The same number under the wheel, a notch a step, up for more -- the + /// gesture this editor already moves a value with. Shift takes whole + /// megabits: fifty tenths is not a way across this range. + pub(crate) fn wheel_budget(&mut self, event: &ScrollWheelEvent) { let by = wheel_delta(event); if by == 0. { return; } - let by = by.signum() as i32; - match &mut self.mbps_edit { - Some(edit) => edit.step(by), - None => self.nudge_mbps(by), + self.nudge_budget(by.signum() as i32, event.modifiers.shift); + } + + /// A press or a drag on the track, read against the box the last paint + /// recorded ([`Self::budget_bar`]): linear across the engine's range, + /// which is what the fill and the knob draw. + pub(crate) fn drag_budget(&mut self, x: Pixels) { + let along = frac_along(x, self.budget_bar.get()); + let span = (BPS_MAX - BPS_MIN) as f32; + self.custom_bps = (BPS_MIN as f32 + along * span).round() as u64; + self.custom_bps = self.custom_bps.clamp(BPS_MIN, BPS_MAX); + } + + /// Opens the budget's field, empty: `n` is a way to *say* a budget + /// (`850k`, `6.5M`, `6.5`, `1.2G` of file), not a way to edit digits, and + /// the number in force is still on the row until enter takes the new one. + pub(crate) fn edit_budget(&mut self) { + self.budget_edit = Some(String::new()); + } + + /// Takes what was typed, or says nothing and keeps the field open: a + /// number that parses is clamped into the engine's range (and shown + /// clamped, in the same keystroke), and one that does not is left to be + /// fixed in place. + pub(crate) fn commit_budget(&mut self) { + let Some(text) = self.budget_edit.clone() else { + return; + }; + let (seconds, audio) = (self.export_seconds(), self.audio_bps()); + if let Some(bps) = parse_budget(&text, seconds, audio) { + self.custom_bps = bps; + self.budget_edit = None; } } - /// Opens the custom bitrate's field on the number the row is carrying, and - /// picks the row while it is at it: a field typed into is the row being - /// chosen, and a number nobody is using would be a number typed at nothing. - /// Nothing is committed here -- until enter, the card still exports at the - /// bitrate it had. - pub(crate) fn edit_mbps(&mut self) { - self.quality = Quality::Custom; - self.mbps_edit = Some(NumberEdit::new( - self.custom_mbps, - MBPS_MIN, - MBPS_MAX, - MBPS_DIGITS, - "Mbps", - )); + /// Every stroke the moment answers, and the reason it answers *all* of + /// them: a chord this surface consumes must never also reach the room's + /// keymap underneath it (the shipped defect where `n` opened the field + /// *and* toggled the timeline snap). While the moment is up it owns the + /// keyboard -- `d`, `n`, `e`/`↵`, `−`/`+`/arrows, escape do their thing, + /// and everything else is swallowed rather than falling through. + /// + /// Escape retreats one step at a time (DESIGN.md:146): the field first, + /// the moment second. + pub(crate) fn export_moment_key(&mut self, key: &str, shift: bool, cx: &mut Context) -> bool { + if !self.export_open { + return false; + } + if let Some(text) = &mut self.budget_edit { + match key { + ESCAPE => self.budget_edit = None, + "enter" => self.commit_budget(), + "backspace" => { + text.pop(); + } + "up" | "right" => self.nudge_budget(1, shift), + "down" | "left" => self.nudge_budget(-1, shift), + // One character a stroke, which is all a rate is made of. + k if k.chars().count() == 1 => text.push_str(k), + _ => {} + } + return true; + } + match key { + ESCAPE => self.close_card(), + "d" => self.pick_destination(cx), + "n" => self.edit_budget(), + "e" | "enter" => self.start_export(cx), + "up" | "right" | "+" | "=" => self.nudge_budget(1, shift), + "down" | "left" | "-" => self.nudge_budget(-1, shift), + _ => {} + } + true } /// The card's Destination row: the desktop's save dialog, on a background @@ -683,6 +730,7 @@ impl Player { /// That list in the card's words ([`subtitle_plan`]): what travels, and the /// reason beside every track that does not -- including the ones /// [`Self::export_subs`] filtered out before the engine ever saw them. + #[allow(dead_code)] // shown by Settings now, not by the moment pub(crate) fn subtitle_line(&self) -> String { let Some(session) = self.session.as_ref() else { return "none".to_string(); @@ -709,8 +757,7 @@ impl Player { return; } let mut settings = export_settings( - self.quality, - self.custom_mbps, + self.budget_bps(), self.format, self.audio_kbps, self.encoder_seat(), @@ -745,14 +792,6 @@ impl Player { cx.notify(); return; } - // Exact asks the same question format_refusal just did, for the same - // reason: the row can be picked, then the cut or the format changed - // under it, and this is the fence with a keystroke to blame. - if let Some(why) = exact_refusal(session, self.format, self.quality) { - self.notify_user(format!("NOT EXPORTED — {why}").into()); - cx.notify(); - return; - } session.pause(); self.export = Some(session.export_to_with(&self.export_path, &settings)); // The clock starts with the worker, not with the first repaint that diff --git a/crates/app/src/subs.rs b/crates/app/src/subs.rs index 7e8776e..2fa9962 100644 --- a/crates/app/src/subs.rs +++ b/crates/app/src/subs.rs @@ -426,6 +426,7 @@ pub(crate) fn subtitle_detail(track: &engine::subtitle::SubtitleTrack) -> String /// string verbatim, would say it correctly meanwhile. Upgrade path: reasons out /// of `planned_subtitles` as data rather than as one sentence, which is an /// engine change. +#[allow(dead_code)] // read by `Player::subtitle_line`, which Settings shows pub(crate) fn subtitle_plan( plan: String, tracks: &[engine::subtitle::SubtitleTrack], diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index cf1bec1..8fb4361 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -875,83 +875,167 @@ fn the_volume_stops_at_both_ends() { } #[test] -fn a_quality_row_is_the_bitrate_it_promises() { - // Auto is the one row that says nothing: the exporter derives it, and - // a number typed against the custom row must not leak into it. - let mp4 = Format::Mp4; - assert_eq!( - export_settings(Quality::Auto, 7, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).bitrate, - None - ); - assert_eq!( - export_settings(Quality::Low, 0, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).bitrate, - Some(2_000_000) - ); - assert_eq!( - export_settings( - Quality::Medium, - 0, - mp4, - DEFAULT_AUDIO_KBPS, - EncoderSeat::Auto - ) - .bitrate, - Some(6_000_000) - ); - assert_eq!( - export_settings(Quality::High, 0, mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).bitrate, - Some(12_000_000) - ); - // Megabits as typed, and as the row says it back. - assert_eq!( - export_settings( - Quality::Custom, - 7, - mp4, - DEFAULT_AUDIO_KBPS, - EncoderSeat::Auto - ) - .bitrate, - Some(7_000_000) - ); - assert_eq!(Quality::Low.detail(0), "2 Mbps"); - // The picked format travels, or the card's rows would be a picture of a +fn the_budget_is_the_one_number_the_engine_gets() { + // One explicit rate, always: the Auto/Low/Medium/High/Exact ladder is + // gone, so there is nothing left that sends `None` and lets the encoder + // pick a figure the row never showed. + let settings = export_settings(6_500_000, Format::Mp4, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto); + assert_eq!(settings.bitrate, Some(6_500_000)); + assert!(!settings.exact, "the copy path is off this surface"); + assert_eq!(settings.audio_kbps, Some(DEFAULT_AUDIO_KBPS)); + assert_eq!(settings.seat, EncoderSeat::Auto); + // The picked format travels, or the moment would be a picture of a // choice the engine never hears about. for format in [Format::Mp4, Format::Wav, Format::Flac] { assert_eq!( - export_settings( - Quality::Auto, - 0, - format, - DEFAULT_AUDIO_KBPS, - EncoderSeat::Auto - ) - .format, + export_settings(BPS_MIN, format, DEFAULT_AUDIO_KBPS, EncoderSeat::Auto).format, format ); } - // Every fixed row sits inside the engine's clamp - // (`MAX_EXPLICIT_BITRATE`), so no row can promise a bitrate the exporter - // silently changes -- the ceiling row included, which is the one a - // raised cap could have walked out past. - for quality in Quality::ALL { - let settings = export_settings( - quality, - MBPS_MAX, - mp4, - DEFAULT_AUDIO_KBPS, - EncoderSeat::Auto, - ); - if let Some(bitrate) = settings.bitrate { - assert!( - (u64::from(MBPS_MIN) * 1_000_000..=u64::from(MBPS_MAX) * 1_000_000) - .contains(&bitrate), - "{quality:?} outside the engine clamp" - ); + // The lever's bounds are the engine's own (`MIN_BITRATE`, + // `MAX_EXPLICIT_BITRATE`), so no reachable number is silently rewritten. + assert_eq!(BPS_MIN, 1_000_000); + assert_eq!(BPS_MAX, 50_000_000); + // The default the lever opens on is the engine's automatic figure for + // the picture that is open -- never the 0 Mbps the old `custom_mbps: 0` + // put on screen. + assert_eq!(auto_bps(1920, 1080, 30.), 6_220_800); + assert!(auto_bps(320, 240, 30.) >= BPS_MIN, "a tiny picture floors"); + assert!(auto_bps(7680, 4320, 60.) <= 20_000_000, "and a huge one caps"); + for bps in [auto_bps(1920, 1080, 30.), auto_bps(320, 240, 24.)] { + assert!((BPS_MIN..=BPS_MAX).contains(&bps)); + } +} + +#[test] +fn a_budget_is_said_four_ways_and_lands_inside_the_engines_range() { + // A minute of film with 256 kbps of sound under it: the span and the + // sound are what a *size* has to be converted through. + let (seconds, audio) = (60., 256_000); + // A rate in its own units, and a bare number in the row's (Mbps). + assert_eq!(parse_budget("6.5M", seconds, audio), Some(6_500_000)); + assert_eq!(parse_budget("6.5", seconds, audio), Some(6_500_000)); + assert_eq!(parse_budget("6.5 mbps", seconds, audio), Some(6_500_000)); + assert_eq!(parse_budget("12M", seconds, audio), Some(12_000_000)); + // 850 kbps is under the engine's floor, so it lands *on* the floor -- + // clamped, and shown clamped in the same keystroke. + assert_eq!(parse_budget("850k", seconds, audio), Some(BPS_MIN)); + assert_eq!(parse_budget("2500k", seconds, audio), Some(2_500_000)); + // `G` is a target file size: 1.2 GB over a minute is 160 Mbit/s of file, + // less the sound -- past the ceiling, so the ceiling is what is written. + assert_eq!(parse_budget("1.2G", seconds, audio), Some(BPS_MAX)); + // ...and over an hour of film the same size is a rate that fits: the + // sound's own bits come out of it, which is why it is not 2.67 Mbps. + let hour = parse_budget("1.2G", 3600., audio).expect("a size over an hour"); + assert_eq!(hour, (1.2e9 * 8. / 3600.) as u64 - audio); + // A size with no film to spread it over is not a rate. + assert_eq!(parse_budget("1.2G", 0., audio), None); + // Everything else is refused rather than guessed at, and the field stays + // open on it. + for text in ["", " ", "abc", "-4", "0", "M", "6.5.5"] { + assert_eq!(parse_budget(text, seconds, audio), None, "{text}"); + } + // Whatever is typed, what comes out is inside the engine's clamp. + for text in ["1k", "999G", "50M", "51M", "0.5"] { + if let Some(bps) = parse_budget(text, seconds, audio) { + assert!((BPS_MIN..=BPS_MAX).contains(&bps), "{text} -> {bps}"); } - // The seat travels exactly as it was picked, and an unpicked project - // exports on the seat this machine has. - assert_eq!(settings.seat, EncoderSeat::Auto); + } +} + +#[test] +fn the_budget_lever_steps_by_a_tenth_and_a_whole_megabit() { + // A notch is 0.1 Mbps and a notch with shift is 1 -- the readout has one + // decimal, so the fine step is the smallest move it can show. + assert_eq!(BPS_FINE, 100_000); + assert_eq!(BPS_COARSE, 1_000_000); + assert_eq!(rate_label(6_000_000 + BPS_FINE), "6.1"); + assert_eq!(rate_label(6_000_000 + BPS_COARSE), "7.0"); + // Fifty notches of the coarse step crosses the whole range, which is + // what a wheel is for; the fine one would take five hundred. + assert_eq!((BPS_MAX - BPS_MIN) / BPS_COARSE, 49); + // The step arithmetic itself, as `Player::nudge_budget` does it: a + // saturating walk that stops at both ends rather than wrapping. + let step = |at: u64, steps: i32, coarse: bool| { + let by = i64::from(steps) * if coarse { BPS_COARSE } else { BPS_FINE } as i64; + ((at as i64 + by).max(0) as u64).clamp(BPS_MIN, BPS_MAX) + }; + assert_eq!(step(6_000_000, 5, false), 6_500_000); + assert_eq!(step(6_000_000, -1, true), 5_000_000); + assert_eq!(step(BPS_MIN, -9, true), BPS_MIN, "the floor holds"); + assert_eq!(step(BPS_MAX, 9, true), BPS_MAX, "and so does the ceiling"); +} + +/// The moment itself, read off its own source: three rows, no scrolling +/// list, no second pane, and exactly one boxed chip in the room (DESIGN §4). +/// A source scan, like the stance guards above it -- this binary has no +/// `TestAppContext` to render a card and measure it. +#[test] +fn the_export_moment_is_three_rows_one_chip_and_no_list() { + let body = fn_body("export_card"); + assert!( + !body.contains("overflow_y_scroll"), + "the export moment scrolls again -- it is three rows and a fixed height" + ); + assert_eq!( + body.matches(".border_1()").count(), + 2, + "one border for the plate and one for the chip: §4's single boxed chip" + ); + for gone in ["Advanced", "preset", "Quality", "Subtitles", "GPU: ", "Built in"] { + assert!(!body.contains(gone), "the old card's {gone} is still here"); + } + // Its three rows, each reachable by pointer as well as by chord. + for id in ["destination", "budget", "budget-track", "export-confirm"] { + assert!(body.contains(&format!("\"{id}\"")), "{id} is on no row"); + } + // 200px, and it fits the smallest window this editor draws with the + // room's own chrome above and below it. + assert_eq!(EXPORT_MOMENT_H, 200.); + assert!(EXPORT_MOMENT_H + crate::ui::stance::TIME_BAND_H + CONTROL_H <= 360.); + // The clickable rows are `HIT_MIN` tall (WCAG 2.5.8) -- the track is + // drawn 1px and grabbed a whole row. + assert!(KEYS_ROW_H >= HIT_MIN); +} + +/// The shipped defect: a chord the export surface answers (`n`) also reached +/// the room's keymap under it and toggled the timeline snap. The fix is that +/// the moment owns the keyboard while it is up -- every stroke is consumed, +/// and escape retreats one step at a time (the field, then the moment). +#[test] +fn a_chord_the_export_moment_answers_never_reaches_the_room() { + // The leak was real: `n` is the room's own snap chord. + let keymap = keymap::Keymap::defaults(); + assert_eq!(keymap.display(keymap::ActionId::ToggleSnap), "n"); + // One door, and it is asked *before* the stance's modal guard. + let cards = src_text("player/cards.rs"); + assert!( + cards.contains("if self.export_moment_key(key, shift, cx)"), + "param_card_key no longer routes the moment's own strokes" + ); + let body = fn_body("export_moment_key"); + let (guard, rest) = body + .split_once("return false;") + .expect("the one early out is `the moment is not open`"); + assert!( + guard.contains("!self.export_open"), + "the only way out of this handler must be that no moment is up" + ); + assert!( + !rest.contains("return false"), + "a stroke fell through to the room's keymap again -- that is the `n` \ + toggling snap defect" + ); + // Escape retreats one step at a time (DESIGN.md:146): the field is + // closed inside the typing branch, the moment only once it is shut. + let (typing, closed) = rest + .split_once("return true;") + .expect("the typing branch returns before the chords below it"); + assert!(typing.contains("self.budget_edit = None"), "esc leaves the field"); + assert!(closed.contains("self.close_card()"), "then esc closes the moment"); + // Its chords, all of them consumed here rather than by the keymap. + for chord in ["\"d\"", "\"n\"", "\"e\"", "\"enter\"", "\"up\"", "\"down\""] { + assert!(closed.contains(chord), "{chord} is not the moment's own"); } } @@ -972,7 +1056,7 @@ fn the_sound_row_carries_its_rate_into_both_kinds_of_file() { for format in [Format::Mp4, Format::Av1, Format::Hevc, Format::Mp3] { for kbps in AUDIO_KBPS { assert_eq!( - export_settings(Quality::Auto, 0, format, kbps, EncoderSeat::Auto).audio_kbps, + export_settings(BPS_MIN, format, kbps, EncoderSeat::Auto).audio_kbps, Some(kbps), "{format:?} at {kbps} kbps" ); @@ -994,105 +1078,6 @@ fn the_sound_row_carries_its_rate_into_both_kinds_of_file() { assert!(audio_rate_choices(7).iter().all(|(.., picked)| !picked)); } -/// The shape [`NumberEdit`] is opened in for a bitrate: `(value, MBPS_MIN, -/// MBPS_MAX, MBPS_DIGITS, "Mbps")`, same as `Player::edit_mbps`. -fn mbps_edit(value: u32) -> NumberEdit { - NumberEdit::new(value, MBPS_MIN, MBPS_MAX, MBPS_DIGITS, "Mbps") -} - -#[test] -fn a_typed_bitrate_is_a_field_and_not_a_key_capture() { - // It opens on the number in force, so backspace edits that number - // rather than the field starting empty over a bitrate still being used. - let mut edit = mbps_edit(12); - assert_eq!(edit.text, "12"); - edit.backspace(); - edit.digit(8); - assert_eq!(edit.text, "18"); - assert_eq!(edit.commit(), Some(18)); - // A card nobody has typed a number into opens empty: zero is not a - // bitrate anyone chose. - assert_eq!(mbps_edit(0).text, ""); - - // Out of range is refused *in words* and the digits stay put: clamping - // 55 to 50 would write a bitrate the user never typed. - let mut edit = mbps_edit(0); - for digit in [5, 5] { - edit.digit(digit); - } - assert_eq!(edit.commit(), None); - assert_eq!(edit.text, "55", "a refusal keeps what was typed"); - let refusal = edit.refusal.clone().expect("a refusal says why"); - assert!(refusal.contains(&MBPS_MAX.to_string()), "{refusal}"); - assert!(edit.detail().starts_with("55▏"), "{}", edit.detail()); - assert!(edit.detail().contains(&refusal)); - // And is fixable in place, which is the whole point of a field. - edit.backspace(); - assert_eq!(edit.refusal, None, "the reason went with the digit"); - assert_eq!(edit.commit(), Some(5)); - - // Empty, zero, and past the digit cap: each its own reason, none of - // them silent -- asserted on the widget itself, the door the card uses. - let mut edit = mbps_edit(0); - assert_eq!(edit.commit(), None, "empty is not a number"); - let mut edit = mbps_edit(0); - edit.digit(0); - assert_eq!(edit.commit(), None); - assert!( - edit.refusal - .clone() - .expect("zero says why") - .contains("0 is not a value") - ); - assert_eq!(mbps_edit(MBPS_MIN).commit(), Some(MBPS_MIN)); - assert_eq!(mbps_edit(MBPS_MAX).commit(), Some(MBPS_MAX)); - let mut edit = mbps_edit(0); - for digit in [5, 1] { - edit.digit(digit); - } - assert_eq!(edit.commit(), None, "51 is past the ceiling"); - let mut edit = mbps_edit(0); - for digit in [9, 9, 9, 9] { - edit.digit(digit); - } - assert_eq!(edit.text, "999", "the cap holds"); - assert!(edit.refusal.is_some(), "and says it is holding"); - // Never past what a u64 bitrate can be built from -- the committed - // number is the only one that reaches the engine, and it is bounded. - assert!(u64::from(MBPS_MAX) * 1_000_000 < u64::from(u32::MAX)); - assert_eq!(MBPS_DIGITS, 3); - - // The arrows step inside the range and stop at both ends: a walk - // through the legal numbers, never a way out of them. - let mut edit = mbps_edit(0); - edit.step(1); - assert_eq!(edit.text, MBPS_MIN.to_string(), "empty starts at the floor"); - edit.step(-1); - assert_eq!(edit.text, MBPS_MIN.to_string()); - let mut edit = mbps_edit(MBPS_MAX); - edit.step(1); - assert_eq!(edit.text, MBPS_MAX.to_string()); - edit.step(-1); - assert_eq!(edit.text, (MBPS_MAX - 1).to_string()); - // A step past a refused number clears the refusal with it. - let mut edit = mbps_edit(0); - edit.digit(5); - edit.digit(5); - assert_eq!(edit.commit(), None); - edit.step(-1); - assert_eq!(edit.refusal, None); - assert_eq!(edit.text, MBPS_MAX.to_string(), "back inside the range"); - - // The hint the field shows when there is nothing to refuse names both - // ways out of it. - let detail = mbps_edit(6).detail(); - assert!( - detail.contains("enter") && detail.contains("esc"), - "{detail}" - ); - assert!(detail.starts_with("6▏"), "{detail}"); -} - /// DEBT #111: the transition duration row's field is the same [`NumberEdit`] /// opened `(frames, 0, cap, ..)`, the shape [`Player::edit_transition`] /// builds it in -- but it clamps on commit instead of refusing, because the @@ -1505,78 +1490,6 @@ fn the_sample_rate_list_marks_source_with_nothing_picked() { assert!(picked[2].3); } -#[test] -fn the_export_card_fits_the_smallest_window() { - // Same 640x360 floor the keybindings card is measured against: the - // capped row list, the two summary lines and the confirm button, under - // a title and a status line. - let title = 17.; - let status = 28.; - // The head is one line of 11 px at this width -- every field of it, - // worst case, is 71 characters against the 76 that fit. The tail is - // budgeted for two: the destination's name is the user's and a long one - // wraps. - let summary = 15. + 30.; - // Six children in the column, so five gaps. - let gaps = 5. * 2.; - let padding = 24.; - assert_eq!( - (17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.), - title + status + summary + CONTROL_H + 4. + gaps + padding - ); - assert!( - (17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.) + (8. * KEYS_ROW_H) <= 360., - "card too tall" - ); - // The list grows with a window that has the room -- and never shrinks - // below the cap that made the floor fit, whatever arithmetic the window - // hands it. - let cap = |h: f32| { - (h - (17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.) - 24.).max(8. * KEYS_ROW_H) - }; - assert_eq!(cap(360.), (8. * KEYS_ROW_H)); - assert_eq!(cap(0.), (8. * KEYS_ROW_H)); - assert!(cap(720.) > (8. * KEYS_ROW_H)); - assert!((17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.) + cap(720.) <= 720.); - // ...and inside the 640 px floor with the scrim showing either side. - assert!(EXPORT_W + 2. * 12. <= 640.); - // The cap is only honest if enough of the list is on screen to read as - // one -- and the whole format section is: its header and every codec - // row, so nothing that is picked *first* is behind a scroll. - let codecs = FORMATS.iter().filter(|(row, ..)| !row.is_empty()).count(); - assert!((8. * KEYS_ROW_H) / KEYS_ROW_H >= 1. + codecs as f32); - // Clickable rows, so WCAG 2.5.8 binds them as it binds the panel's -- - // and the bitrate steppers are `HIT_MIN` squares sitting inside a row, - // which only fits while the row is at least as tall as one. - assert!(KEYS_ROW_H >= HIT_MIN); - assert!(CONTROL_H >= HIT_MIN); - // The dimmed text on the card -- every refusal, every detail, every key - // in its column -- is body text on `BG_RAISED` and WCAG 1.4.3 binds it. - // A dimmed row is drawn in this ink rather than at an opacity, which is - // what a refusal used to be readable through. - // Every palette, not the one in force: a family is picked at runtime - // now (`ui::theme`), so a floor met by one of them and missed by the - // other is a window somebody is looking at. - for id in crate::ui::theme::PaletteId::ALL { - let p = id.palette(); - assert!( - contrast(p.FG_SECONDARY, p.BG_RAISED) >= 4.5, - "{id:?}: refusal ink {:.2}", - contrast(p.FG_SECONDARY, p.BG_RAISED) - ); - // ...and on the picked row, where the highlight is the accent at - // surface brightness. Both inks clear 4.5:1 on it now -- the row still - // lifts its key and detail to `FG_PRIMARY`, as emphasis rather than as - // the rescue it used to be. - assert!(contrast(p.FG_PRIMARY, p.BG_SELECTED) >= 4.5, "{id:?}"); - assert!( - contrast(p.FG_SECONDARY, p.BG_SELECTED) >= 4.5, - "{id:?}: refusal ink on the picked row {:.2}", - contrast(p.FG_SECONDARY, p.BG_SELECTED) - ); - } -} - /// The progress line's two clocks, driven the way a repaint drives them: /// steady work, a stall where hardware hands over to software, then steady /// work again. The estimate may not whipsaw, may not vanish once it has @@ -1682,85 +1595,6 @@ 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); -} - -/// Picking Exact must derive the container from the source's own codec -/// rather than leave whatever format was already picked -- an HEVC or AV1 -/// source lands on its own copy-capable Matroska format, and a source Exact -/// has no copy path for at all (h264) leaves `exact_format` with nothing to -/// set, so the row's own [`exact_refusal`] is what a click on it would see. -#[test] -fn exact_derives_its_format_from_the_source_codec() { - let hevc = PlaybackSession::open(asset("test_hevc.mkv")).expect("an hevc fixture"); - assert_eq!(crate::exact_format(&hevc), Some(Format::Hevc)); - - let av1 = PlaybackSession::open(asset("test_av1.mkv")).expect("an av1 fixture"); - assert_eq!(crate::exact_format(&av1), Some(Format::Av1)); - - let h264 = PlaybackSession::open(asset("test_h264.mkv")).expect("an h264 fixture"); - assert_eq!(h264.export_snapshot().1.codec, engine::demux::Codec::H264); - assert_eq!(crate::exact_format(&h264), None); - // No copy path for h264 at any format -- the row's own refusal is what a - // click on Exact would still show, since `exact_format` sets nothing and - // the format is left at whatever it already was (Mp4's own refusal, or - // Hevc's if the pane was left there from an earlier pick). - assert!(crate::exact_refusal(&h264, Format::Mp4, Quality::Exact).is_some()); - assert!(crate::exact_refusal(&h264, Format::Hevc, Quality::Exact).is_some()); -} - /// The stacking-scrims bug: opening the speed card while the colour card was /// up left both up at once, because each `open_*` cleared a different /// hand-picked subset of the other flags rather than all of them. The fix is diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index aae29af..3c0af40 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -609,10 +609,6 @@ fn every_codec_row_is_offered_or_says_why_not() { // Every box on one row is the same codec, so the quality rows // do not change meaning when the container does. assert!(row.iter().all(|f| f.has_video() == first.has_video())); - assert!( - row.iter() - .all(|f| bitrate_refusal(*f) == bitrate_refusal(first)) - ); } } // No two rows share a key, and none of them is a stroke the card already @@ -651,79 +647,11 @@ fn every_codec_row_is_offered_or_says_why_not() { detail.contains("rusty_vorbis"), "the row names the encoder like every other live one: {detail}" ); - // Both AV1 boxes say they carry sound: the file used to be picture only, - // and a line that still said so would be the lie a user plays the file - // to find out about. HEVC says intra-only before anyone waits on one -- - // a file several times the size, which the disk would otherwise say. - for format in [Format::Av1, Format::Av1Mp4] { - assert!(format_line(format).starts_with("AV1 · ")); - } - for format in [Format::Hevc, Format::HevcMp4] { - assert!(format_line(format).starts_with("HEVC intra · ")); - } - // The head names the box every format goes in, which is what the - // destination is then named after. - for format in [ - Format::Mp4, - Format::Av1, - Format::Av1Mp4, - Format::Hevc, - Format::HevcMp4, - ] { - assert!( - format_line(format).contains(&format.ext().to_uppercase()), - "{format:?}: {}", - format_line(format) - ); - } - // ...and it stays inside the one line the card budgets for it: the - // longest of them, with every field after it, against the 76 characters - // that fit at `EXPORT_W`. - let longest = summary_head( - Format::Hevc, - Some(((1920, 1080), 23.976)), - "AAC · SW encode (rusty_aac)", - ); - assert!( - longest.chars().count() <= 76, - "{longest} is {} long", - longest.chars().count() - ); assert!( FORMATS .into_iter() .any(|(row, _, _, detail)| row.contains(&Format::Hevc) && detail.contains("intra")) ); - // Only a picture encoder is given a bitrate, and the quality rows dim - // with the reason for every format that is not one. - for format in [ - Format::Mp4, - Format::Av1, - Format::Av1Mp4, - Format::Hevc, - Format::HevcMp4, - ] { - assert!( - format.has_video() && bitrate_refusal(format).is_none(), - "{format:?}" - ); - } - for format in [Format::Wav, Format::Flac, Format::Mp3] { - assert!(!format.has_video()); - assert!( - bitrate_refusal(format).is_some(), - "{format:?} dims silently" - ); - } - assert!(bitrate_refusal(Format::Wav).unwrap().contains("lossless")); - // MP3 has a rate and it is the *Sound* row's: the quality rows are the - // picture's, and this refusal used to claim a fixed 256 kbps that the - // Sound row can now change under it. - assert!(bitrate_refusal(Format::Mp3).unwrap().contains("Sound row")); - assert!( - !format_line(Format::Mp3).contains("256"), - "the summary states a rate the Sound row can change under it" - ); // The destination follows the format and keeps the stem, mp4 included. assert_eq!( retarget(std::path::Path::new("/a/take.export.mp4"), Format::Wav), @@ -733,79 +661,47 @@ fn every_codec_row_is_offered_or_says_why_not() { retarget(std::path::Path::new("/a/take.export.wav"), Format::Mp4), std::path::Path::new("/a/take.export.mp4") ); - assert!(format_line(Format::Flac).contains("lossless")); } -/// The one line the card is answerable for: what it says is on screen before -/// the button is pressed, and every field of it is one `ffprobe` reads back -/// off the file that comes out. +/// What the budget row says about the file before it is written: the size a +/// rate makes over a span, in the unit the row states it in. #[test] -fn the_summary_states_the_file_before_it_is_written() { - let head = summary_head(Format::Mp4, Some(((1920, 1080), 30.)), "AAC copy"); - for field in ["H.264", "MP4", "1920x1080", "30 fps", "AAC copy"] { - assert!(head.contains(field), "{field} missing from {head}"); - } +fn the_budget_row_states_the_size_before_it_is_written() { // The rate as a person writes it, and the ratio one spelled out rather // than rounded to a rate nothing is written at. assert_eq!(fps_label(30.), "30"); assert_eq!(fps_label(24000. / 1001.), "23.976"); assert_eq!(fps_label(29.97002997), "29.97"); - // A format with no picture states no size and no rate it does not write. - let audio = summary_head(Format::Wav, Some(((1920, 1080), 30.)), "PCM · SW (hound)"); - assert!( - !audio.contains("1920x1080") && !audio.contains("fps"), - "{audio}" - ); - assert!(audio.contains("PCM · SW (hound)")); - // ...and one with no sound on the timeline says that, rather than - // leaving the field out and reading as a file with sound in it. - assert!( - summary_head(Format::Mp4, Some(((640, 360), 25.)), "no sound to write") - .contains("no sound to write") - ); - // The tail: where it lands, about how big, and what will encode it -- - // never a guessed seat, and no seat at all for a format with no picture. - let tail = summary_tail( - Path::new("/a/take.export.mp4"), - Some(45_000_000), - Some("VA-API"), - true, - ); - assert!(tail.starts_with("take.export.mp4"), "{tail}"); - assert!( - tail.contains("≈ 45 MB") && tail.contains("VA-API"), - "{tail}" - ); - assert!(summary_tail(Path::new("/a/x.mp4"), None, None, true).contains("encoder …")); - assert!(!summary_tail(Path::new("/a/x.wav"), None, None, false).contains("encoder")); - assert!(!summary_tail(Path::new("/a/x.wav"), None, None, false).contains("MB")); - // 6 Mbps over a minute is 45 MB. `Auto` has no figure to estimate from - // and an empty timeline no length: neither invents one. - assert_eq!(estimated_bytes(Some(6_000_000), 60.), Some(45_000_000)); - assert_eq!(estimated_bytes(Some(2_000_000), 90.), Some(22_500_000)); - assert_eq!(estimated_bytes(None, 60.), None); - assert_eq!(estimated_bytes(Some(6_000_000), 0.), None); - assert_eq!(estimated_bytes(Some(0), 60.), None); - // ...and a short one is not nothing. Three seconds at the floor - // bitrate is 375 kB, which used to round to the "≈ 0 MB" this line - // exists to never say -- the shortest export a frame can make is - // still a real file with a real size. - let short = estimated_bytes(Some(1_000_000), 3.).expect("a rate and a length"); - assert_eq!(size_label(short), "375 kB"); - let frame = summary_tail( - Path::new("/a/x.mp4"), - estimated_bytes(Some(1_000_000), 1. / 60.), - None, - true, - ); + // 6 Mbps over a minute is 45 MB -- and the sound rides in the same + // number, because it is in the same file. + assert_eq!(estimated_bytes(6_000_000, 60.), 45_000_000); + assert_eq!(estimated_bytes(6_000_000 + 256_000, 60.), 46_920_000); + assert_eq!(estimated_bytes(2_000_000, 90.), 22_500_000); + // Nothing to write is nothing to estimate, and never a negative span. + assert_eq!(estimated_bytes(6_000_000, 0.), 0); + assert_eq!(estimated_bytes(6_000_000, -3.), 0); + // Whole megabytes under a gigabyte, two decimals over it: the estimate + // is an "≈" and a tenth of a megabyte is precision it does not have. + assert_eq!(size_label(45_000_000), "45 MB"); + assert_eq!(size_label(999_999_999), "1000 MB"); + assert_eq!(size_label(1_000_000_000), "1.00 GB"); + assert_eq!(size_label(1_240_000_000), "1.24 GB"); + // The lever's own readout, one decimal, in the unit it is moved in. + assert_eq!(rate_label(6_000_000), "6.0"); + assert_eq!(rate_label(6_500_000), "6.5"); + assert_eq!(rate_label(BPS_MIN), "1.0"); + // The faintest line: what resolved, never a control -- and it says the + // marked span where there is one rather than "whole film". + let line = plan_line(Format::Mp4, "AAC 256 kbps", None, true); + assert_eq!(line, "H.264 · AAC 256 kbps · whole film · GPU"); + assert!(plan_line(Format::Mp4, "AAC", None, false).ends_with("SW")); assert!( - frame.contains("≈ 2 kB") && !frame.contains("0 MB") && !frame.contains("0 kB"), - "{frame}" + plan_line(Format::Mp4, "AAC", Some("00:00:04:00–00:00:12:00"), true) + .contains("marks 00:00:04:00–00:00:12:00") ); - // The boundary reads in the unit that can state it, either side. - assert_eq!(size_label(999_600), "1 MB"); - assert_eq!(size_label(499_000), "499 kB"); - assert_eq!(size_label(1), "1 kB"); + // A sound-only export names no picture codec and no seat to write it on. + let sound = plan_line(Format::Flac, "FLAC", None, true); + assert_eq!(sound, "FLAC · sound only"); } /// Which cue is on screen when: the whole of what the overlay decides, and diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 822d724..b93dc75 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -13,24 +13,24 @@ use super::{ ACCENT_PRIMARY, AUDIO_KBPS, BG_RAISED, 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_DONE, EXPORT_W, Enable, - EncoderSeat, ExportPreset, FORMATS, Format, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, + EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, Enable, + BPS_COARSE, BPS_FINE, BPS_MAX, BPS_MIN, EXPORT_MOMENT_H, EncoderSeat, FORMATS, Format, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, KEYS_ROW_H, KEYS_W, KeyRow, LABEL_H, LANE_H, LANES_MAX, LATE_RESYNC, LIBRARY_MAX_W, - LIBRARY_MIN_W, Lane, MB_FLOOR, MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MENU_ITEMS, MENU_PAD, - MENU_ROW_H, MENU_W, NO_FILE, NOTICES_MAX, NumberEdit, OVERLAID, PANEL_H, Quality, RESYNC_GAP, + LIBRARY_MIN_W, Lane, MB_FLOOR, MENU_ITEMS, MENU_PAD, + MENU_ROW_H, MENU_W, NO_FILE, NOTICES_MAX, NumberEdit, OVERLAID, PANEL_H, RESYNC_GAP, ROW_ITEMS, RULER_HIT_H, RowCtx, RowItem, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_PLAN_CHARS, Source, Speed, StreamInfo, TIMELINE_SHARE, Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, - WAVE_COLS_MAX, Wave, ZOOM_MIN_FRAMES, active_lane, band_label, bitrate_detail, bitrate_refusal, + WAVE_COLS_MAX, Wave, ZOOM_MIN_FRAMES, active_lane, auto_bps, band_label, bitrate_detail, clipboard_after_remove, color_snap, containers, enable, enable_lane, envelope, eq_card_w, eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, export_path, - export_settings, format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, + export_settings, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, keys_rows, lanes_h, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play, - notice_tone, panel_h, project_path, proxies_to_start, push_notice, px_below, retarget, + notice_tone, panel_h, parse_budget, plan_line, project_path, proxies_to_start, push_notice, px_below, retarget, row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label, - snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, - subtitle_plan, summary_head, summary_tail, timecode, timeline_fixed_h, tip_may_paint, + rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, + subtitle_plan, timecode, timeline_fixed_h, tip_may_paint, transport, typed, unseen_paths, unseen_sources, whole_take, window_title, }; diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index e91a18f..7653588 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -259,23 +259,32 @@ fn dark_ghost_button( }) } +/// Where an export lands, said the way the destination row says it: the +/// directory under `~` where it is one, so the row is a place a person +/// recognises rather than an absolute path that will not fit on the line. +fn dest_dir(path: &Path) -> String { + let dir = path.parent().unwrap_or(path).to_string_lossy().to_string(); + match std::env::var("HOME") { + Ok(home) if !home.is_empty() && dir.starts_with(&home) => { + format!("~{}", &dir[home.len()..]) + } + _ => dir, + } +} + impl Player { - /// What an export is going to be, before there is one: the codec, the box - /// it goes into, the bitrate, where it lands -- and, above the button, the - /// two lines that state the file all of that adds up to. The same scrim and - /// row shape as the keybindings overlay (two cards of different builds over - /// one window read as two different programs) and the same plain divs, so - /// the root keeps the keyboard and the custom row's field is typed into - /// through it ([`NumberEdit`]). + /// The export moment (DESIGN §4/§8/§10, the approved artboard): three + /// lines, ~200px, no scroll, no sections and no prose. Where it lands + /// (`d` opens the save dialog), what it costs (one lever, read as a rate + /// and as a size), and what it resolved to on its own beside the one + /// boxed chip. /// - /// Every row carries the key that picks it, so the card is drivable end to - /// end without a pointer *and* without a legend to memorise -- and every - /// row is clickable, the bitrate's steppers included, so it is drivable end - /// to end without a keyboard as well. - /// - /// Two shapes of it, behind `g` and `r`: sections against one flat list, - /// and the codecs with no encoder collapsed into a footer against a dimmed - /// row each. Grouped and collapsed is what opens. + /// Everything the old card asked apart -- codec, container, sound rate, + /// encoder seat, the presets, the Advanced pane -- keeps its state and + /// its setters and is simply not on this surface: an export is one + /// decision, the budget, and the rest is a preference that belongs in + /// Settings (user 2026-09-09: "too complicated plus I can only give mbps + /// level bitrate"). pub(crate) fn export_card( &self, viewport: Size, @@ -284,673 +293,292 @@ impl Player { if !self.export_open { return None; } - // The cap is what keeps the card inside the smallest window; a taller - // one gets a taller list rather than a scroll past empty space, and the - // card is still only as tall as the rows it has. - // DESIGN §4: plate surface, mono for what the film says, ghost rows, - // one bordered chip for the commit action. - let ink_secondary = INK3(); - let bg_hover = DARK_RAISED(); - let bg_selected = DARK_RAISED(); - // Archivo for what the row *says as a verb* (its label), mono for - // what the film says through it (its detail/key) -- DESIGN §3. - let label_style = Some(type_scale::label( - type_scale::LABEL_ROW_PX, - gpui::FontWeight::MEDIUM, - )); - let mono_style = Some(type_scale::mono( - type_scale::CHORD_METADATA_MAX_PX, - gpui::FontWeight::MEDIUM, - )); - let head_style = Some(type_scale::head()); - let row = |id: (&'static str, usize)| { - div() - .id(id) - .flex() - // The floor, not the height: the destination's path wraps on a - // long name and must not paint over the row under it. Which it - // did: inside a capped, scrolling list a row shrinks to fit by - // default, so a wrapped detail was drawn over the row beneath - // it (the Sound row's "the source's own packets are copied…" - // over Subtitles). The list scrolls -- a row is as tall as what - // it has to say. - .flex_none() - .min_h(px(KEYS_ROW_H)) - .items_center() - .justify_between() - .gap(px(12.)) - .px(px(6.)) - .rounded(px(3.)) - }; - // A row that cannot be picked is dimmed and takes no click, exactly as - // an inapplicable item in the clip menu is: it still says its piece. - let live = |d: Stateful
, enabled: bool| { - d.when(!enabled, |d| { - d.cursor_not_allowed().text_color(rgb(ink_secondary)) - }) - .when(enabled, |d| { - d.cursor_pointer().hover(|s| s.bg(rgb(bg_hover))) - }) + let budget = self.budget_bps(); + let seconds = self.export_seconds(); + // Both halves of the file, which is what a person means by "how big": + // the picture's budget and the sound's own rate over the same span. + let bytes = estimated_bytes(budget + self.audio_bps(), seconds); + let fill = ((budget.saturating_sub(BPS_MIN)) as f32 / (BPS_MAX - BPS_MIN) as f32).clamp(0., 1.); + let name = file_name(&self.export_path); + let (stem, ext) = match name.rfind('.') { + Some(at) => name.split_at(at), + None => (name.as_str(), ""), }; - // A row as this card writes them: the mark saying which one is picked, - // the key that picks it, its name, and what the choice means. The mark - // is a glyph and not only a colour -- a background alone is gone the - // moment a hover lands on the row, and invisible to anyone who cannot - // tell the two greys apart (WCAG 1.4.1). - let entry = |id: (&'static str, usize), - key: &str, - label: SharedString, - detail: SharedString, - picked: bool, - enabled: bool| { - // The small print of a picked row sits on the highlight, where the - // dim ink is only 3.3:1 -- the row it lands on lifts it (WCAG - // 1.4.3, and the fit test pins both numbers). - // DESIGN §2's ink ladder, applied to a row rather than to a - // whole card (user 2026-08-21: the export card's "colors are not - // aligning a little so hard to read"). Two faults it fixes: the - // detail of a picked row was drawn BRIGHTER than the label it - // belongs to -- the loudest thing on the row was its small print - // -- and the resting rows' detail sat at `ink3` on `panel`, the - // metadata step, for text that is the row's actual content and - // has to be read at a glance. Label leads its row (`ink1` - // picked, `ink2` resting), detail follows one step behind - // (`ink2` picked, `ink2` resting -- never `ink3`, which stays - // for the key column and the summary's small print). - let ink = INK2(); - let label_ink = match picked { - true => INK1(), - false => INK2(), - }; - let key_ink = INK3(); - live(row(id), enabled) - .when(picked, |d| d.bg(rgb(bg_selected))) - .child( - div() - .flex() - .flex_none() - .items_center() - .gap(px(8.)) - .child(div().w(px(10.)).child(match picked { - true => "✓", - false => " ", - })) - .child( - div() - .w(px(EXPORT_KEY_W)) - .text_size(px(11.)) - .text_color(rgb(key_ink)) - .when_some(mono_style.clone(), |d, style| { - d.font(style.font).text_size(style.size) - }) - .child(SharedString::from(key.to_string())), - ) - .child( - // A fixed label column in the darkroom: the - // details are the long half and they wrap, so - // without one they start at a different x on - // every row and a wrapped line reads as if it - // began left of the label it belongs to. - div() - .map(|d| d.w(px(92.)).flex_none().text_color(rgb(label_ink))) - .when_some(label_style.clone(), |d, style| { - d.font(style.font).text_size(style.size) - }) - .child(label), - ), - ) - // Wraps rather than runs off the row: a refusal is the longest - // thing in this column and the half of it past the edge is the - // half that says what to do instead. - .child( - div() - .min_w(px(0.)) - .flex_shrink() - .text_size(px(11.)) - .text_color(rgb(ink)) - .when_some(mono_style.clone(), |d, style| { - d.font(style.font).text_size(style.size) - }) - .child(detail), + // The picture's own seat, as the probe found it -- `SW` until it says + // otherwise is a promise; `GPU` is what `planned_seats` measured. + let hardware = self + .export_seat + .as_ref() + .and_then(|(.., seats)| *seats) + .and_then(|(video, _)| video) + .is_some_and(|seat| seat.contains("VA-API") || seat.contains("GPU")); + let audio = self + .session + .as_ref() + .map_or("", |s| s.planned_audio(self.format, self.range.is_some())); + let marks = self.range.map(|(start, end)| { + format!( + "{}\u{2013}{}", + timecode(f64::from(start) / self.fps, self.fps), + timecode(f64::from(end) / self.fps, self.fps), + ) + }); + let plan = plan_line(self.format, audio, marks.as_deref(), hardware); + // The refusal the button used to carry, said before it is pressed and + // in the readout's own place: a few words and the chord that fixes it, + // never the sentence the old card wrapped over three lines. + let blocked = self + .session + .as_ref() + .and_then(|s| format_refusal(s, self.format)) + .map(|why| { + format!( + "{} — sound format in settings {}", + why.split(" — ").next().unwrap_or("cannot export"), + self.keymap.chord(ActionId::Settings) ) - }; - let header = |text: &'static str| { + }); + let chord = |key: &'static str| { div() .flex_none() - .px(px(6.)) - .pt(px(4.)) - .text_size(px(10.)) - .text_color(rgb(ink_secondary)) - .when_some(head_style.clone(), |d, style| { - d.font(style.font).text_size(style.size) - }) - .child(text) - .into_any_element() + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MIN_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(INK3())) + .child(key) }; - 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(), + // Row 1: the file. A readout -- `d` is the one way to change it, the + // desktop's own save dialog, exactly as the old row's `d` was. + let file_row = div() + .id("destination") + .flex_none() + .flex() + .items_baseline() + .gap(px(16.)) + .cursor_pointer() + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))) + .child( + div() + .flex_1() + .min_w(px(0.)) + .truncate() + .type_style(type_scale::mono(18., gpui::FontWeight::BOLD)) + .text_color(rgb(INK1())) + .child(stem.to_string()) + .child( + div() + .text_color(rgb(INK2())) + .child(ext.to_string()), + ), + ) + .child( + div() + .flex_none() + .flex() + .gap(px(10.)) + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MIN_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(INK3())) + .child(dest_dir(&self.export_path)) + .child("d"), ); - 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() + // Row 2: the budget. One lever, in bits per second, read as a rate and + // as a size -- the wheel moves it (shift by whole Mbps), `n` types one + // (`850k`, `6.5M`, `6.5`, `1.2G` of file), the track sets it by hand. + let reading: Vec = match &self.budget_edit { + Some(text) => { + let parsed = parse_budget(text, seconds, self.audio_bps()); + vec![ + div() + .type_style(type_scale::mono(18., gpui::FontWeight::BOLD)) + .text_color(rgb(INK1())) + .child(format!("{text}\u{258f}")) + .into_any_element(), + div() + .type_style(type_scale::mono(15., gpui::FontWeight::MEDIUM)) + .text_color(rgb(INK2())) + .child(match parsed { + Some(bps) => format!( + "{} Mbps ≈ {}", + rate_label(bps), + size_label(estimated_bytes(bps + self.audio_bps(), seconds)) + ), + None => "↵ takes it · esc leaves it".to_string(), + }) + .into_any_element(), + ] } + None => vec![ + div() + .flex() + .items_baseline() + .type_style(type_scale::mono(18., gpui::FontWeight::BOLD)) + .text_color(rgb(INK1())) + .child(rate_label(budget)) + .child( + div() + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MIN_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(INK2())) + .child(" Mbps"), + ) + .into_any_element(), + div() + .type_style(type_scale::mono(15., gpui::FontWeight::MEDIUM)) + .text_color(rgb(INK2())) + .child(format!("≈ {}", size_label(bytes))) + .into_any_element(), + ], }; - 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; + let budget_row = div() + .id("budget") + .flex_none() + .flex() + .flex_col() + .gap(px(10.)) + .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { + this.wheel_budget(event); + cx.stop_propagation(); 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")); - } - // The codecs first: which one is being written decides whether every - // row under it means anything. One a *this* timeline cannot be written - // as (an audio-only edit, for a picture codec) reads exactly like one - // there is no encoder for -- dimmed, unclickable, and carrying its own - // reason where its detail was, with nothing to click to find that out. - let mut refusals: Vec = Vec::new(); - for (i, (boxes, key, label, detail)) in FORMATS.into_iter().enumerate() { - let format = same_box(boxes, self.format); - let refused = format - .zip(self.session.as_ref()) - .and_then(|(f, s)| format_refusal(s, f)); - // A codec with no encoder here at all is the other kind of refusal, - // and the one the footer collects: it can never become pickable, so - // a row each is dead rows above the fold. - if format.is_none() { - refusals.push(format!("{label} — {detail}")); - if !self.export_refusals_inline { - continue; - } - } - let detail: SharedString = match &refused { - Some(why) => why.clone().into(), - None => detail.into(), - }; - let format = format.filter(|_| refused.is_none()); - let mut r = entry( - ("format", i), - key, - label.into(), - detail, - boxes.contains(&self.format), - format.is_some(), - ); - if let Some(format) = format { - r = r.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.set_format(format); - cx.notify(); - })); - } - list.push(r.into_any_element()); - } - if self.export_grouped { - list.push(header("DETAILS")); - } - // The container, and only where the picked codec has more than one box: - // a row offering a single choice reads as a choice. - let boxes = containers(self.format); - if boxes.len() > 1 { - let next = next_container(self.format); - list.push( - entry( - ("container", 0), - "c", - "Container".into(), - format!( - "{} — c for {}", - self.format.ext().to_uppercase(), - next.ext().to_uppercase() - ) - .into(), - false, - true, - ) + .child( + div() + .flex() + .items_baseline() + .gap(px(16.)) + .id("budget-read") + .cursor_pointer() .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - this.cycle_container(); + this.edit_budget(); cx.notify(); })) - .into_any_element(), - ); - } - match bitrate_refusal(self.format) { - // One dimmed row carrying the reason, rather than five rows of a - // figure that will not be written: the quality rows are the - // *picture's* bitrate, and this file has no picture in it. - Some(why) => list.push( - entry( - ("quality", 0), - "q", - "Quality".into(), - why.into(), - false, - false, + .children(reading) + .child(div().flex_1()) + .child(chord("n")), + ) + .child( + // 1px to look at, a whole row to grab (WCAG 2.5.8) -- the + // ruler's own split between what is drawn and what is hit. + div() + .id("budget-track") + .relative() + .h(px(KEYS_ROW_H)) + .cursor_pointer() + .child(bounds_probe(self.budget_bar.clone())) + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, event: &MouseDownEvent, _, cx| { + this.drag_budget(event.position.x); + cx.stop_propagation(); + cx.notify(); + }), ) - .into_any_element(), - ), - None => { - for (i, quality) in Quality::ALL.into_iter().enumerate() { - // The custom row is a field: `n` opens it, a click in it - // opens it too, and while it is open the row shows what is - // being typed with a caret in it rather than the number in - // force. The other four are picked whole. - let field = self - .mbps_edit - .as_ref() - .filter(|_| quality == Quality::Custom); - // Exact's own row carries whatever [`exact_refusal`] says of - // the format currently picked, whether or not Exact is the - // row in force -- the same reason `start_export` would give, - // said here instead of only after the button is pressed. - let exact_why = (quality == Quality::Exact) - .then(|| self.session.as_ref()) - .flatten() - .and_then(|s| exact_refusal(s, self.format, quality)); - let mut r = entry( - ("quality", i), - match quality { - Quality::Custom => "n", - _ => "q", - }, - quality.label().into(), - match (&exact_why, field) { - (Some(why), _) => why.clone().into(), - (None, Some(edit)) => edit.detail().into(), - (None, None) => quality.detail(self.custom_mbps).into(), - }, - self.quality == quality, - true, - ) - .on_click(cx.listener( - move |this, _: &ClickEvent, _, cx| { - match quality { - Quality::Custom => this.edit_mbps(), - _ => this.pick_quality(quality), - } - cx.notify(); - }, - )); - if quality == Quality::Custom { - // The wheel anywhere over the row moves the number, the - // buttons being one step each: the range is fifty wide - // now, and a number only a repeated press can walk to is - // a number nobody walks to. Swallowed, so the notch that - // moved the bitrate does not scroll the list under it as - // well -- one gesture, one thing changed. - r = r - .on_scroll_wheel(cx.listener( - |this, event: &ScrollWheelEvent, _, cx| { - this.wheel_mbps(event); - cx.stop_propagation(); - cx.notify(); - }, - )) - .child(self.mbps_steppers(cx)); + .on_mouse_move(cx.listener(|this, event: &MouseMoveEvent, _, cx| { + if event.pressed_button == Some(MouseButton::Left) { + this.drag_budget(event.position.x); + cx.notify(); } - list.push(r.into_any_element()); - } - } - } - // The other half of the file, and the one this card used to write at a - // fixed rate without saying so: what the *sound* is coded at, for every - // format that codes it -- the AAC inside a video export as much as an - // MP3. Four rates, so the pointer gets the *list* of them - // ([`Pick::AudioRate`]) rather than a button clicked round -- the - // resolution row's rule, and the key still steps as `ctrl+r` still - // does. Dimmed with the reason where this timeline has no rate to pick, - // like the quality rows are. - let sound = self.audio_rate_refusal(); - let mut r = entry( - ("sound", 0), - "b", - "Sound".into(), - match sound { - Some(why) => why.into(), - None => format!("{} kbps — b steps", self.audio_kbps).into(), - }, - false, - sound.is_none(), - ); - if sound.is_none() { - r = r.on_click(cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::AudioRate, event.position(), cx) - })); - } - list.push(r.into_any_element()); - // Which encoder writes the picture, which was an env pin and therefore - // no choice at all. Three seats, so the pointer gets the *list* of them - // ([`Pick::Encoder`]) and never a button clicked round -- the Sound - // row's rule, one row above. Only where there is a picture to encode: - // a WAV has no seat to pick and the row would be a question about - // nothing. - if self.format.has_video() { - let seat = self.encoder_seat(); - list.push( - entry( - ("encoder", 0), - "e", - "Encoder".into(), - format!("{} — e steps", encoder_label(seat)).into(), - false, - true, - ) - .on_click(cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::Encoder, event.position(), cx) })) - .into_any_element(), - ); - // ...and, under it, the one thing about that pick a person cannot - // know from the words in the list: this box's driver reset itself - // on the vendored AV1 encoder. A dimmed row and not a modal -- the - // pick is theirs, and the export runs. - if let Some(warning) = av1_hw_warning(self.format, seat) { - list.push( - entry( - ("encoder-av1", 0), - "", - "".into(), - warning.into(), - false, - false, - ) - .into_any_element(), - ); - } - } - // What happens to the subtitles on this timeline, in one line: how many - // are written into the file and under what names, or the reason each one - // is not. Which tracks travel is not a pick -- everything with a cue on - // the timeline goes ([`Player::export_subs`]) -- so the row says rather - // than offers, like the machine lines below. - // ...and the ones that do not travel are named here too, which they were - // not: `export_subs` had already filtered a track with no cue on *this* - // timeline out of the engine's sight, so the card said nothing about a - // row the list was still showing ([`subtitle_plan`]). - let plan = self.subtitle_line(); - // The row used to end in "click for in MKV" whenever the picture - // was going into an mp4, on the grounds that only Matroska carries a - // text track. An mp4 carries one now (`Mp4Muxer::write_subtitles` writes - // `tx3g`), so that was a refusal offering a way out of nothing: the - // container the card is already set to embeds them. The refusals left in - // `planned_subtitles` are the true ones -- a sound-only format has - // nowhere to put a track, and a PGS track is pictures whatever the box. - list.push( - entry( - ("subtitles", 0), - "", - "Subtitles".into(), - plan.into(), - false, - false, - ) - .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. - list.push( - entry( - ("export-layout", 0), - "g", - "Layout".into(), - match self.export_grouped { - true => "sections — g for one flat list".into(), - false => "one flat list — g for sections".into(), - }, - self.export_grouped, - true, - ) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - this.export_grouped = !this.export_grouped; - cx.notify(); - })) - .into_any_element(), - ); - list.push( - entry( - ("export-refusals", 0), - "r", - "Codecs with no encoder".into(), - match self.export_refusals_inline { - true => "a dimmed row each — r collapses them".into(), - false => "one line at the foot — r shows a row each".into(), - }, - self.export_refusals_inline, - true, - ) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - this.export_refusals_inline = !this.export_refusals_inline; - cx.notify(); - })) - .into_any_element(), + .child( + div() + .absolute() + .left_0() + .right_0() + .top(px(KEYS_ROW_H / 2.)) + .h(px(1.)) + .bg(rgb(DARK_HAIRLINE())), + ) + .child( + div() + .absolute() + .left_0() + .top(px(KEYS_ROW_H / 2.)) + .h(px(1.)) + .w(relative(fill)) + .bg(rgb(INK2())), + ) + .child( + div() + .absolute() + .left(relative(fill)) + .top(px(KEYS_ROW_H / 2. - 4.)) + .w(px(2.)) + .h(px(9.)) + .bg(rgb(INK1())), + ), ); - 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 - // answer), but nothing here can ever be picked, so it sits under - // every row that can rather than above them. - list.push( - div() - .flex_none() - .px(px(6.)) - .py(px(2.)) - .text_size(px(11.)) - .text_color(rgb(ink_secondary)) - .when_some(mono_style.clone(), |d, style| { - d.font(style.font).text_size(style.size) - }) - .child(format!("cannot write: {}", refusals.join(" · "))) - .into_any_element(), - ); - } - // What is doing the work, on this machine and in this build: the GPU - // half is asked of the driver through the plugin (a different answer on - // every machine, and "none" where there is no plugin at all), the build - // half is the crates that were compiled in. Last in the list, because it - // is what a user checks rather than what they pick -- and a listing - // rather than rows, since none of it can be clicked. - if self.export_grouped { - list.push(header("THIS MACHINE")); - } - let note = |text: String| { + // Row 3: what auto resolved to, in the faintest ink -- or, where the + // press would be refused, the refusal in its place -- and the one + // boxed chip in the room (§4). + let commit_row = div() + .flex_none() + .flex() + .items_center() + .gap(px(16.)) + .child( + div() + .flex_1() + .min_w(px(0.)) + .truncate() + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MIN_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(match blocked.is_some() { + true => STATUS_WARNING(), + false => INK4(), + })) + .child(blocked.clone().unwrap_or(plan)), + ) + .child( div() + .id("export-confirm") .flex_none() - .px(px(6.)) - .py(px(2.)) - .text_size(px(11.)) - .text_color(rgb(ink_secondary)) - .when_some(mono_style.clone(), |d, style| { - d.font(style.font).text_size(style.size) + .flex() + .items_center() + .justify_center() + .gap(px(10.)) + .h(px(32.)) + .px(px(22.)) + .rounded(px(3.)) + .border_1() + .border_color(rgb(match blocked.is_some() { + true => INK4(), + false => INK3(), + })) + .when(blocked.is_none(), |d| { + d.cursor_pointer().hover(|s| s.bg(rgb(DARK_RAISED()))) }) - .child(text) - .into_any_element() - }; - list.push(note(format!( - "GPU: {}", - 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 - // list is scrolled to and whatever is picked. - let picture = self - .session - .as_ref() - .map(|s| (s.resolution(), s.meta().frame_rate)); - // The probe's answer where it has one -- the export's own decision, - // sound included ([`engine::export::planned_seats`]) -- and the pure - // prediction from the format alone until it lands, which is the same - // line this card always showed. - let seats = self.export_seat.as_ref().and_then(|(.., seats)| *seats); - let audio = seats.map_or_else( - || { - self.session - .as_ref() - .map_or("", |s| s.planned_audio(self.format, self.range.is_some())) - }, - |(_, audio)| audio, - ); - let settings = export_settings( - self.quality, - self.custom_mbps, - self.format, - self.audio_kbps, - self.encoder_seat(), - ); - let size = estimated_bytes( - settings.bitrate.filter(|_| self.format.has_video()), - self.session.as_ref().map_or(0., |s| match self.range { - Some((start, end)) => f64::from(end - start) / s.meta().frame_rate, - None => s.timeline_duration(), - }), - ); - let head = summary_head(self.format, picture, audio); - let tail = summary_tail( - &self.export_path, - size, - seats.and_then(|(video, _)| video), - self.format.has_video(), - ); - // The button says the refusal *before* it is pressed: the picked codec - // can go invalid one edit after it was picked (a cleared video lane), - // and a button that looks ready until it is pressed is the lie the - // dimmed rows above it are there to avoid. - let blocked = self - .session - .as_ref() - .and_then(|s| format_refusal(s, self.format)); - let action: SharedString = match &blocked { - Some(why) => { - format!("Cannot export — {}", why.split(" — ").next().unwrap_or(why)).into() - } - None => "Export".into(), - }; - let status_line = match (&self.mbps_edit, self.notices.front()) { - // A field being typed into says so here as well as in its row: - // this line is outside the scrolling list and on screen at every - // window size, and at 360 px the custom row itself can be below - // the fold -- a number typed where it cannot be seen is the - // blind capture this field replaced. - (Some(edit), _) => SharedString::from(format!("Custom bitrate {}", edit.detail())), - (None, Some(notice)) => notice.clone(), - // `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. - // Short enough to read at a glance in the plate's own head row: - // the long four-clause sentence was 11px `ink3` mono across the - // whole sheet and read as noise above the rows it was meant to - // explain (user 2026-08-21: "hard to read"). - (None, None) => match self.export_advanced_open { - true => "↵ exports · esc closes · g/r layout".into(), - false => "↵ exports · esc closes · s Advanced".into(), - }, - }; - // The darkroom's own language, not the corner-card sheet the legacy - // tree drew before it was removed -- - // a plate (canvas-on-panel, §4), positioned over the bench+ - // ledger footprint it can sit over rather than centred over the - // whole window (§11 check 6: the picture stays uncovered). The - // click-catcher behind it is `size_full` so a click anywhere - // still closes the card exactly as the legacy scrim's does, but - // paints nothing (`SCRIM()` is deliberately not applied here) -- - // an invisible catcher changes zero picture pixels while a - // dimming one would still tint the screen it must never cover. - // The plate is the room's below-picture footprint, not a 340px - // corner card (user 2026-08-21: "export section is not aligning - // with our design"). Measured at 1280x720 the corner card's own - // max-height was ~9px taller than the footprint it had to fit - // in, so its scrolling row list collapsed to a single visible - // row: the presets, Advanced and every codec row under them were - // unreachable by pointer, and the long status sentence wrapped to - // three lines over the top of them. Two columns instead -- rows - // left, what-it-adds-up-to and the one bordered chip right -- - // inside the same bench+ledger footprint every menu already - // hangs in, so the picture stays uncovered (§11 check 6) and the - // list gets the whole height rather than a fraction of it. + .when(blocked.is_some(), |d| d.cursor_not_allowed()) + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.start_export(cx))) + .type_style(type_scale::label( + type_scale::LABEL_ROW_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(match blocked.is_some() { + true => INK4(), + false => INK1(), + })) + .child("Export") + .child( + div() + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MIN_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(INK3())) + .child(self.keymap.chord(ActionId::Export)), + ), + ); let floor = crate::ui::stance::below_picture_floor( f32::from(viewport.height), self.split_px(Split::Bench, viewport), ); - let summary = |text: SharedString, ink: u32| { - div() - .flex_none() - .px(px(6.)) - .type_style(type_scale::mono( - type_scale::CHORD_METADATA_MAX_PX, - gpui::FontWeight::MEDIUM, - )) - .text_color(rgb(ink)) - .child(text) - }; Some( div() .id("export-click-catcher") @@ -960,11 +588,9 @@ impl Player { .left_0() .right_0() .flex() + .items_end() // Below the time band, not merely below the picture: the - // transport and the Export chip that opened this card are - // on that band, and a sheet drawn over them hides the - // control the editor just pressed. The bench and the - // ledger are what this plate is allowed to cover. + // chip that opened this moment is on that band. .pt(px(floor + crate::ui::stance::TIME_BAND_H + 6.)) .pb(px(6.)) .px(px(6.)) @@ -981,140 +607,24 @@ impl Player { .id("export-plate") .flex_1() .min_w(px(0.)) + // The artboard is 784 wide; wider windows give the + // moment room, never a 2000px line of three words. + .max_w(px(EXPORT_W * 2.)) + .h(px(EXPORT_MOMENT_H)) .on_mouse_down(MouseButton::Left, swallow) .flex() .flex_col() - .gap(px(4.)) - .p(px(10.)) + .justify_between() + .pt(px(22.)) + .pb(px(20.)) + .px(px(28.)) .rounded(px(4.)) .bg(rgb(DARK_PANEL())) .border_1() .border_color(rgba(DARK_SEAM())) - .child( - div() - .flex_none() - .flex() - .items_baseline() - .justify_between() - .gap(px(12.)) - .px(px(6.)) - .child( - div() - .type_style(type_scale::head()) - .text_color(rgb(INK3())) - .child("EXPORT"), - ) - .child( - div() - .min_w(px(0.)) - .truncate() - .type_style(type_scale::mono( - type_scale::CHORD_METADATA_MAX_PX, - gpui::FontWeight::MEDIUM, - )) - .text_color(rgb(INK2())) - .child(status_line), - ), - ) - .child( - div() - .flex_1() - .min_h(px(0.)) - .flex() - .gap(px(10.)) - .child( - div() - .id("export-rows") - .flex_1() - .min_w(px(0.)) - .h_full() - .flex() - .flex_col() - .gap(px(2.)) - .overflow_y_scroll() - .children(list), - ) - .child( - div() - .flex_none() - .w(px(300.)) - .h_full() - .flex() - .flex_col() - .justify_end() - .gap(px(4.)) - .border_l_1() - .border_color(rgb(DARK_HAIRLINE())) - .pl(px(8.)) - .child(summary(head.into(), INK2())) - .children(self.range.map(|(start, end)| { - summary( - format!( - "RANGE {}\u{2013}{} ({})", - timecode(f64::from(start) / self.fps, self.fps), - timecode(f64::from(end) / self.fps, self.fps), - frames_timecode(end - start, self.fps), - ) - .into(), - INK3(), - ) - })) - .child(summary(tail.into(), INK3())) - // §4: "the single bordered chip in - // the whole room" -- ghosts - // everywhere else in this card, one - // border here, wearing its chord - // live off the keymap so a rebind - // cannot leave it stale. - .child( - div() - .id("export-confirm") - .mt(px(4.)) - .flex() - .items_center() - .justify_center() - .gap(px(6.)) - .h(px(CONTROL_H)) - .px(px(10.)) - .rounded(px(3.)) - .border_1() - .border_color(rgb(match blocked.is_some() { - true => INK4(), - false => INK2(), - })) - .when(blocked.is_none(), |d| d.cursor_pointer()) - .when(blocked.is_some(), |d| d.cursor_not_allowed()) - .hover(|s| s.bg(rgb(DARK_RAISED()))) - .on_click(cx.listener( - |this, _: &ClickEvent, _, cx| { - this.start_export(cx) - }, - )) - .type_style(type_scale::label( - type_scale::LABEL_ROW_PX, - gpui::FontWeight::MEDIUM, - )) - .text_color(rgb(match blocked.is_some() { - true => INK4(), - false => INK1(), - })) - .child(action) - .when(blocked.is_none(), |d| { - d.child( - div() - .type_style(type_scale::mono( - type_scale::CHORD_METADATA_MIN_PX, - gpui::FontWeight::MEDIUM, - )) - .text_color(rgb(INK3())) - .child( - self.keymap.chord(ActionId::Export), - ), - ) - }), - ), - ), - ) + .child(file_row) + .child(budget_row) + .child(commit_row) .into_any_element(), ) .into_any_element(), @@ -1271,36 +781,6 @@ impl Player { ) } - /// The custom bitrate's two pointer buttons. The typed digits were the last - /// control in this card a mouse could not reach at all -- and a number that - /// can only be typed is a number a hand on the pointer has to leave the - /// card to change. `HIT_MIN` square, like every other target here. - pub(crate) fn mbps_steppers(&self, cx: &mut Context) -> impl IntoElement { - let step = |id: &'static str, label: &'static str, by: i32, cx: &mut Context| { - div() - .id(id) - .flex() - .w(px(HIT_MIN)) - .h(px(HIT_MIN)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_PANEL())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.nudge_mbps(by); - cx.notify(); - })) - .child(label) - }; - div() - .flex() - .gap(px(4.)) - .child(step("mbps-down", "−", -1, cx)) - .child(step("mbps-up", "+", 1, cx)) - } - /// The equalizer of one audio clip: its frequency response drawn as a /// curve, a handle per band sitting on it, each band's own bell under the /// sum, and a row that reads and moves the picked band's three numbers. The diff --git a/crates/app/src/ui/widgets.rs b/crates/app/src/ui/widgets.rs index b0aaadb..ea73829 100644 --- a/crates/app/src/ui/widgets.rs +++ b/crates/app/src/ui/widgets.rs @@ -342,6 +342,7 @@ impl NumberEdit { /// first press up is the row's minimum and not a jump to some remembered /// value -- and stays inside the range, because a step is a walk through /// the legal numbers rather than a way out of them. + #[allow(dead_code)] // the budget field is free text; the transition row still types digits pub(crate) fn step(&mut self, by: i32) { let at = self .text @@ -359,6 +360,7 @@ impl NumberEdit { /// whose own stepper already clamps silently, use [`Self::commit_clamped`] /// instead -- refusing there would be a stricter rule than the mouse door /// enforces. + #[allow(dead_code)] // as above: `commit_clamped` is the transition row's door pub(crate) fn commit(&mut self) -> Option { match self.text.parse::() { Ok(v) if (self.min..=self.max).contains(&v) => {