forge
Explore
Log in

Don't you dare go Hollow

The custom bitrate reaches fifty, and the wheel takes it there

Browse files at this commit

dadd2f4b8755ea49091a4d4d2e2502b686ce9926Ahmet Kaan GümüşParent: a24eb7e
  • feat
    • the custom bitrate reaches fifty, and the wheel takes it there
Show full message
✨ feat(export): the custom bitrate reaches fifty, and the wheel takes it there

The ceiling was twenty, which was never an encoder's limit: it was the top
of the range the exporter *derives* an automatic bitrate in, borrowed as the
cap on a number a person typed. An asked-for rate has its own ceiling now
(MAX_EXPLICIT_BITRATE), and the card offers all of it.

And a range fifty wide is not a range a stepper walks: the wheel over the
custom row moves it, one step a notch, up for more -- the gesture the
timeline already zooms and scrolls with. It moves the field while one is
open, exactly as the arrows do, so the two ways in never disagree about
which number is being changed. Hold-to-run stays the keyboard's, as it is
on every other card here.
crates/app/src/main.rsmodified+67 -32
@@ -2167,17 +2167,7 @@ impl Player {
21672167 /// because that probe *is* the bed's x-to-time mapping ([`HEADER_W`]) and
21682168 /// every lane is drawn through the same one.
21692169 fn timeline_wheel(&mut self, event: &ScrollWheelEvent, cx: &mut Context<Self>) {
2170- let (dx, dy) = match event.delta {
2171- ScrollDelta::Lines(d) => (d.x, d.y),
2172- ScrollDelta::Pixels(d) => (f32::from(d.x), f32::from(d.y)),
2173- };
2174- // A tilt wheel's own axis counts as the same gesture: it is the
2175- // sideways scroll a mouse that has one sends, and this panel's sideways
2176- // is the only direction it has.
2177- let d = match dy == 0. {
2178- true => dx,
2179- false => dy,
2180- };
2170+ let d = wheel_delta(event);
21812171 if d == 0. {
21822172 return;
21832173 }
@@ -5583,7 +5573,7 @@ impl Player {
55835573
55845574 /// The custom bitrate by pointer: the typed digits were the only control in
55855575 /// this card a mouse could not reach. Clamped to the range the row states
5586- /// (the engine's own 1..20 Mbps), and picking the row is part of the step --
5576+ /// (the engine's own 1..50 Mbps), and picking the row is part of the step --
55875577 /// a stepper that moves a number nobody is using would move nothing.
55885578 fn nudge_mbps(&mut self, step: i32) {
55895579 self.custom_mbps =
@@ -5591,6 +5581,27 @@ impl Player {
55915581 self.quality = Quality::Custom;
55925582 }
55935583
5584+ /// The same number under the wheel, one step a notch, up for more: fifty
5585+ /// presses of a stepper is not a way to reach the top of this range, and the
5586+ /// wheel is what this editor already moves a value with (the timeline's
5587+ /// zoom and scroll are the same gesture). Hold-to-run stays the keyboard's,
5588+ /// as it is on every other card here -- a button that repeats while held is
5589+ /// not a thing this program has.
5590+ ///
5591+ /// It moves the *field* while one is open, exactly as ↑↓ do, so the two
5592+ /// ways in never disagree about which number is being changed.
5593+ fn wheel_mbps(&mut self, event: &ScrollWheelEvent) {
5594+ let by = wheel_delta(event);
5595+ if by == 0. {
5596+ return;
5597+ }
5598+ let by = by.signum() as i32;
5599+ match &mut self.mbps_edit {
5600+ Some(edit) => edit.step(by),
5601+ None => self.nudge_mbps(by),
5602+ }
5603+ }
5604+
55945605 /// Opens the custom bitrate's field on the number the row is carrying, and
55955606 /// picks the row while it is at it: a field typed into is the row being
55965607 /// chosen, and a number nobody is using would be a number typed at nothing.
@@ -8070,7 +8081,7 @@ impl Quality {
80708081 match self {
80718082 Quality::Auto => "from the picture size and frame rate".to_string(),
80728083 Quality::Custom => {
8073- format!("{custom_mbps} Mbps — n types a number, {MBPS_MIN}–{MBPS_MAX}")
8084+ format!("{custom_mbps} Mbps — wheel or ± steps, n types one, {MBPS_MIN}–{MBPS_MAX}")
80748085 }
80758086 other => format!(
80768087 "{} Mbps",
@@ -8616,7 +8627,7 @@ fn retarget(path: &std::path::Path, format: Format) -> PathBuf {
86168627 /// The card's rows as the engine takes them. `Auto` leaves the bitrate to the
86178628 /// exporter, which derives it from the picture; the fixed rows are figures that
86188629 /// hold from 720p to 1080p, and a typed one is passed exactly as typed -- the
8619-/// engine clamps every explicit bitrate to 1..20 Mbps (export.rs:290), so this
8630+/// engine clamps every explicit bitrate to 1..50 Mbps (`MAX_EXPLICIT_BITRATE`), so this
86208631 /// must not clamp it a second time and disagree about where the edge is.
86218632 ///
86228633 /// The bitrate travels even for an audio format, where the engine ignores it:
@@ -8652,12 +8663,17 @@ fn export_settings(
86528663 }
86538664
86548665 /// What the engine will code an explicit bitrate at, in whole Mbps: outside
8655-/// this it clamps (`export.rs` `MIN_BITRATE`/`MAX_BITRATE`), so a number typed
8656-/// past either end would be written as a different one. The field refuses it
8657-/// instead of clamping quietly -- a card that changes the user's number without
8658-/// saying so is the one thing a field like this must never do.
8666+/// this it clamps (`export.rs` `MIN_BITRATE`/`MAX_EXPLICIT_BITRATE`), so a
8667+/// number typed past either end would be written as a different one. The field
8668+/// refuses it instead of clamping quietly -- a card that changes the user's
8669+/// number without saying so is the one thing a field like this must never do.
8670+///
8671+/// The ceiling was 20, which was never a limit of any encoder here: it was the
8672+/// top of the range the exporter *derives* an automatic bitrate in, borrowed as
8673+/// the cap on a typed one. A 1080p master or a 4K edit wants more than that, so
8674+/// the asked-for rate has its own ceiling now and this is it.
86598675 const MBPS_MIN: u32 = 1;
8660-const MBPS_MAX: u32 = 20;
8676+const MBPS_MAX: u32 = 50;
86618677
86628678 /// How many digits the field takes. Two reach the ceiling; the third is there so
86638679 /// a number *past* it can be typed whole and refused in its own words, rather
@@ -9486,6 +9502,22 @@ fn px_along(x: Pixels, bounds: Bounds<Pixels>) -> f32 {
94869502 f32::from(x - bounds.left()).clamp(0., f32::from(bounds.size.width).max(0.))
94879503 }
94889504
9505+/// One turn of the wheel as a single number, positive for a turn *up*, in
9506+/// whatever units the device sends (a mouse counts lines, a touchpad pixels).
9507+/// A tilt wheel's own axis counts as the same gesture: it is the sideways
9508+/// scroll a mouse that has one sends, and the controls this drives have one
9509+/// direction each, so the two axes are one answer here.
9510+fn wheel_delta(event: &ScrollWheelEvent) -> f32 {
9511+ let (dx, dy) = match event.delta {
9512+ ScrollDelta::Lines(d) => (d.x, d.y),
9513+ ScrollDelta::Pixels(d) => (f32::from(d.x), f32::from(d.y)),
9514+ };
9515+ match dy == 0. {
9516+ true => dx,
9517+ false => dy,
9518+ }
9519+}
9520+
94899521 /// The frame a dropped clip's head lands on: `raw`, unless one of `marks` is
94909522 /// within `tol` frames of where its head -- or its tail, `len` frames along --
94919523 /// would come to rest, in which case that edge wins. The snap every timeline
@@ -13460,13 +13492,16 @@ mod tests {
1346013492 format
1346113493 );
1346213494 }
13463- // Every fixed row sits inside the engine's clamp (export.rs:290), so no
13464- // row can promise a bitrate the exporter silently changes.
13495+ // Every fixed row sits inside the engine's clamp
13496+ // (`MAX_EXPLICIT_BITRATE`), so no row can promise a bitrate the exporter
13497+ // silently changes -- the ceiling row included, which is the one a
13498+ // raised cap could have walked out past.
1346513499 for quality in Quality::ALL {
13466- let settings = export_settings(quality, 7, mp4, DEFAULT_AUDIO_KBPS);
13500+ let settings = export_settings(quality, MBPS_MAX, mp4, DEFAULT_AUDIO_KBPS);
1346713501 if let Some(bitrate) = settings.bitrate {
1346813502 assert!(
13469- (1_000_000..=20_000_000).contains(&bitrate),
13503+ (u64::from(MBPS_MIN) * 1_000_000..=u64::from(MBPS_MAX) * 1_000_000)
13504+ .contains(&bitrate),
1347013505 "{quality:?} outside the engine clamp"
1347113506 );
1347213507 }
@@ -13539,29 +13574,29 @@ mod tests {
1353913574 assert_eq!(NumberEdit::new(0).text, "");
1354013575
1354113576 // Out of range is refused *in words* and the digits stay put: clamping
13542- // 45 to 20 would write a bitrate the user never typed.
13577+ // 55 to 50 would write a bitrate the user never typed.
1354313578 let mut edit = NumberEdit::new(0);
13544- for digit in [4, 5] {
13579+ for digit in [5, 5] {
1354513580 edit.digit(digit);
1354613581 }
1354713582 assert_eq!(edit.commit(), None);
13548- assert_eq!(edit.text, "45", "a refusal keeps what was typed");
13583+ assert_eq!(edit.text, "55", "a refusal keeps what was typed");
1354913584 let refusal = edit.refusal.clone().expect("a refusal says why");
13550- assert!(refusal.contains("20"), "{refusal}");
13551- assert!(edit.detail().starts_with("45▏"), "{}", edit.detail());
13585+ assert!(refusal.contains(&MBPS_MAX.to_string()), "{refusal}");
13586+ assert!(edit.detail().starts_with("55▏"), "{}", edit.detail());
1355213587 assert!(edit.detail().contains(&refusal));
1355313588 // And is fixable in place, which is the whole point of a field.
1355413589 edit.backspace();
1355513590 assert_eq!(edit.refusal, None, "the reason went with the digit");
13556- assert_eq!(edit.commit(), Some(4));
13591+ assert_eq!(edit.commit(), Some(5));
1355713592
1355813593 // Empty, zero, and past the digit cap: each its own reason, none of
1355913594 // them silent.
1356013595 assert!(commit_mbps("").is_err());
1356113596 assert!(commit_mbps("0").unwrap_err().contains("not a rate"));
1356213597 assert_eq!(commit_mbps("1"), Ok(MBPS_MIN));
13563- assert_eq!(commit_mbps("20"), Ok(MBPS_MAX));
13564- assert!(commit_mbps("21").is_err());
13598+ assert_eq!(commit_mbps("50"), Ok(MBPS_MAX));
13599+ assert!(commit_mbps("51").is_err());
1356513600 let mut edit = NumberEdit::new(0);
1356613601 for digit in [9, 9, 9, 9] {
1356713602 edit.digit(digit);
@@ -13587,7 +13622,7 @@ mod tests {
1358713622 assert_eq!(edit.text, (MBPS_MAX - 1).to_string());
1358813623 // A step past a refused number clears the refusal with it.
1358913624 let mut edit = NumberEdit::new(0);
13590- edit.digit(4);
13625+ edit.digit(5);
1359113626 edit.digit(5);
1359213627 assert_eq!(edit.commit(), None);
1359313628 edit.step(-1);
crates/app/src/ui/cards.rsmodified+15 -1
@@ -240,7 +240,21 @@ impl Player {
240240 },
241241 ));
242242 if quality == Quality::Custom {
243- r = r.child(self.mbps_steppers(cx));
243+ // The wheel anywhere over the row moves the number, the
244+ // buttons being one step each: the range is fifty wide
245+ // now, and a number only a repeated press can walk to is
246+ // a number nobody walks to. Swallowed, so the notch that
247+ // moved the bitrate does not scroll the list under it as
248+ // well -- one gesture, one thing changed.
249+ r = r
250+ .on_scroll_wheel(cx.listener(
251+ |this, event: &ScrollWheelEvent, _, cx| {
252+ this.wheel_mbps(event);
253+ cx.stop_propagation();
254+ cx.notify();
255+ },
256+ ))
257+ .child(self.mbps_steppers(cx));
244258 }
245259 list.push(r.into_any_element());
246260 }
crates/engine/src/export.rsmodified+31 -5
@@ -107,6 +107,14 @@ const BITS_PER_PIXEL: f64 = 0.1;
107107 const MIN_BITRATE: u64 = 1_000_000;
108108 const MAX_BITRATE: u64 = 20_000_000;
109109
110+/// The ceiling on a bitrate somebody *asked* for, which is a different question
111+/// from where the derived one stops: [`MAX_BITRATE`] is the top of the automatic
112+/// figure's sane range, and a rate a person typed is not that program's guess to
113+/// bound. Nothing in either encoder objects to it -- the VA-API seat takes a
114+/// `u64` and the software ones a `u32`/`i32`, all of which hold this with room
115+/// -- so the old shared ceiling was only ever the auto range wearing two hats.
116+const MAX_EXPLICIT_BITRATE: u64 = 50_000_000;
117+
110118 /// The rates the sound may be coded at, smallest first -- what a front-end
111119 /// offers and what [`ExportSettings::audio_kbps`] is clamped into. Every one of
112120 /// them is a legal MPEG-1 Layer III value, so the MP3 path writes the figure it
@@ -456,12 +464,14 @@ fn mastered(project: &Project) -> bool {
456464 project.limiter().is_active() || project.audio_gains().iter().any(|&g| g != 1.0)
457465 }
458466
459-/// The bitrate an export codes at: the caller's number through the same clamp
460-/// as the computed one, for the reason [`Enc::open`] states.
467+/// The bitrate an export codes at: the caller's number clamped into what an
468+/// asked-for rate may be ([`MAX_EXPLICIT_BITRATE`]), the derived one where there
469+/// was none. Clamped rather than refused, for the reason [`Enc::open`] states.
461470 fn bitrate_of(meta: &VideoMeta, settings: &ExportSettings) -> u64 {
462- settings
463- .bitrate
464- .map_or_else(|| bitrate_for(meta), |b| b.clamp(MIN_BITRATE, MAX_BITRATE))
471+ settings.bitrate.map_or_else(
472+ || bitrate_for(meta),
473+ |b| b.clamp(MIN_BITRATE, MAX_EXPLICIT_BITRATE),
474+ )
465475 }
466476
467477 /// The rate the sound codes at: the caller's pick clamped into the offered
@@ -3817,6 +3827,22 @@ mod tests {
38173827 assert_eq!(bitrate_for(&meta(1280, 720, 30.0)), 2_764_800);
38183828 assert_eq!(bitrate_for(&meta(320, 240, 30.0)), MIN_BITRATE, "tiny");
38193829 assert_eq!(bitrate_for(&meta(3840, 2160, 60.0)), MAX_BITRATE, "huge");
3830+ // A rate somebody typed goes through untouched to its own ceiling, which
3831+ // is above where the derived one stops: the card offers 50 Mbps, and a
3832+ // second clamp here would write a file at a bitrate nobody picked.
3833+ let asked = |bps| {
3834+ bitrate_of(
3835+ &meta(1920, 1080, 30.0),
3836+ &ExportSettings {
3837+ bitrate: Some(bps),
3838+ ..Default::default()
3839+ },
3840+ )
3841+ };
3842+ assert_eq!(asked(50_000_000), 50_000_000, "the card's ceiling travels");
3843+ assert_eq!(asked(21_000_000), 21_000_000, "past the derived range");
3844+ assert_eq!(asked(999_000_000), MAX_EXPLICIT_BITRATE, "still bounded");
3845+ assert_eq!(asked(1), MIN_BITRATE, "and floored");
38203846 }
38213847
38223848 fn meta(width: u32, height: u32) -> VideoMeta {