The custom bitrate reaches fifty, and the wheel takes it there
Browse files at this commitdadd2f4b8755ea49091a4d4d2e2502b686ce9926Parent: a24eb7e- feat
- the custom bitrate reaches fifty, and the wheel takes it there
3 changed files +113 -38
- crates/app/src/main.rs +67 -32
- crates/app/src/ui/cards.rs +15 -1
- crates/engine/src/export.rs +31 -5
crates/app/src/main.rsmodified+67 -32
| @@ -2167,17 +2167,7 @@ impl Player { | |||
| 2167 | /// because that probe *is* the bed's x-to-time mapping ([`HEADER_W`]) and | 2167 | /// because that probe *is* the bed's x-to-time mapping ([`HEADER_W`]) and |
| 2168 | /// every lane is drawn through the same one. | 2168 | /// every lane is drawn through the same one. |
| 2169 | fn timeline_wheel(&mut self, event: &ScrollWheelEvent, cx: &mut Context<Self>) { | 2169 | fn timeline_wheel(&mut self, event: &ScrollWheelEvent, cx: &mut Context<Self>) { |
| 2170 | - let (dx, dy) = match event.delta { | 2170 | + let d = wheel_delta(event); |
| 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 | - }; | ||
| 2181 | if d == 0. { | 2171 | if d == 0. { |
| 2182 | return; | 2172 | return; |
| 2183 | } | 2173 | } |
| @@ -5583,7 +5573,7 @@ impl Player { | |||
| 5583 | 5573 | ||
| 5584 | /// The custom bitrate by pointer: the typed digits were the only control in | 5574 | /// The custom bitrate by pointer: the typed digits were the only control in |
| 5585 | /// this card a mouse could not reach. Clamped to the range the row states | 5575 | /// 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 -- |
| 5587 | /// a stepper that moves a number nobody is using would move nothing. | 5577 | /// a stepper that moves a number nobody is using would move nothing. |
| 5588 | fn nudge_mbps(&mut self, step: i32) { | 5578 | fn nudge_mbps(&mut self, step: i32) { |
| 5589 | self.custom_mbps = | 5579 | self.custom_mbps = |
| @@ -5591,6 +5581,27 @@ impl Player { | |||
| 5591 | self.quality = Quality::Custom; | 5581 | self.quality = Quality::Custom; |
| 5592 | } | 5582 | } |
| 5593 | 5583 | ||
| 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 | + | ||
| 5594 | /// Opens the custom bitrate's field on the number the row is carrying, and | 5605 | /// Opens the custom bitrate's field on the number the row is carrying, and |
| 5595 | /// picks the row while it is at it: a field typed into is the row being | 5606 | /// picks the row while it is at it: a field typed into is the row being |
| 5596 | /// chosen, and a number nobody is using would be a number typed at nothing. | 5607 | /// chosen, and a number nobody is using would be a number typed at nothing. |
| @@ -8070,7 +8081,7 @@ impl Quality { | |||
| 8070 | match self { | 8081 | match self { |
| 8071 | Quality::Auto => "from the picture size and frame rate".to_string(), | 8082 | Quality::Auto => "from the picture size and frame rate".to_string(), |
| 8072 | Quality::Custom => { | 8083 | 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}") |
| 8074 | } | 8085 | } |
| 8075 | other => format!( | 8086 | other => format!( |
| 8076 | "{} Mbps", | 8087 | "{} Mbps", |
| @@ -8616,7 +8627,7 @@ fn retarget(path: &std::path::Path, format: Format) -> PathBuf { | |||
| 8616 | /// The card's rows as the engine takes them. `Auto` leaves the bitrate to the | 8627 | /// The card's rows as the engine takes them. `Auto` leaves the bitrate to the |
| 8617 | /// exporter, which derives it from the picture; the fixed rows are figures that | 8628 | /// exporter, which derives it from the picture; the fixed rows are figures that |
| 8618 | /// hold from 720p to 1080p, and a typed one is passed exactly as typed -- the | 8629 | /// 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 |
| 8620 | /// must not clamp it a second time and disagree about where the edge is. | 8631 | /// must not clamp it a second time and disagree about where the edge is. |
| 8621 | /// | 8632 | /// |
| 8622 | /// The bitrate travels even for an audio format, where the engine ignores it: | 8633 | /// The bitrate travels even for an audio format, where the engine ignores it: |
| @@ -8652,12 +8663,17 @@ fn export_settings( | |||
| 8652 | } | 8663 | } |
| 8653 | 8664 | ||
| 8654 | /// What the engine will code an explicit bitrate at, in whole Mbps: outside | 8665 | /// 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 | 8666 | +/// this it clamps (`export.rs` `MIN_BITRATE`/`MAX_EXPLICIT_BITRATE`), so a |
| 8656 | -/// past either end would be written as a different one. The field refuses it | 8667 | +/// number typed past either end would be written as a different one. The field |
| 8657 | -/// instead of clamping quietly -- a card that changes the user's number without | 8668 | +/// refuses it instead of clamping quietly -- a card that changes the user's |
| 8658 | -/// saying so is the one thing a field like this must never do. | 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. | ||
| 8659 | const MBPS_MIN: u32 = 1; | 8675 | const MBPS_MIN: u32 = 1; |
| 8660 | -const MBPS_MAX: u32 = 20; | 8676 | +const MBPS_MAX: u32 = 50; |
| 8661 | 8677 | ||
| 8662 | /// How many digits the field takes. Two reach the ceiling; the third is there so | 8678 | /// How many digits the field takes. Two reach the ceiling; the third is there so |
| 8663 | /// a number *past* it can be typed whole and refused in its own words, rather | 8679 | /// 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 { | |||
| 9486 | f32::from(x - bounds.left()).clamp(0., f32::from(bounds.size.width).max(0.)) | 9502 | f32::from(x - bounds.left()).clamp(0., f32::from(bounds.size.width).max(0.)) |
| 9487 | } | 9503 | } |
| 9488 | 9504 | ||
| 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 | + | ||
| 9489 | /// The frame a dropped clip's head lands on: `raw`, unless one of `marks` is | 9521 | /// The frame a dropped clip's head lands on: `raw`, unless one of `marks` is |
| 9490 | /// within `tol` frames of where its head -- or its tail, `len` frames along -- | 9522 | /// within `tol` frames of where its head -- or its tail, `len` frames along -- |
| 9491 | /// would come to rest, in which case that edge wins. The snap every timeline | 9523 | /// would come to rest, in which case that edge wins. The snap every timeline |
| @@ -13460,13 +13492,16 @@ mod tests { | |||
| 13460 | format | 13492 | format |
| 13461 | ); | 13493 | ); |
| 13462 | } | 13494 | } |
| 13463 | - // Every fixed row sits inside the engine's clamp (export.rs:290), so no | 13495 | + // Every fixed row sits inside the engine's clamp |
| 13464 | - // row can promise a bitrate the exporter silently changes. | 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. | ||
| 13465 | for quality in Quality::ALL { | 13499 | 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); |
| 13467 | if let Some(bitrate) = settings.bitrate { | 13501 | if let Some(bitrate) = settings.bitrate { |
| 13468 | assert!( | 13502 | 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), | ||
| 13470 | "{quality:?} outside the engine clamp" | 13505 | "{quality:?} outside the engine clamp" |
| 13471 | ); | 13506 | ); |
| 13472 | } | 13507 | } |
| @@ -13539,29 +13574,29 @@ mod tests { | |||
| 13539 | assert_eq!(NumberEdit::new(0).text, ""); | 13574 | assert_eq!(NumberEdit::new(0).text, ""); |
| 13540 | 13575 | ||
| 13541 | // Out of range is refused *in words* and the digits stay put: clamping | 13576 | // 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. |
| 13543 | let mut edit = NumberEdit::new(0); | 13578 | let mut edit = NumberEdit::new(0); |
| 13544 | - for digit in [4, 5] { | 13579 | + for digit in [5, 5] { |
| 13545 | edit.digit(digit); | 13580 | edit.digit(digit); |
| 13546 | } | 13581 | } |
| 13547 | assert_eq!(edit.commit(), None); | 13582 | 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"); |
| 13549 | let refusal = edit.refusal.clone().expect("a refusal says why"); | 13584 | let refusal = edit.refusal.clone().expect("a refusal says why"); |
| 13550 | - assert!(refusal.contains("20"), "{refusal}"); | 13585 | + assert!(refusal.contains(&MBPS_MAX.to_string()), "{refusal}"); |
| 13551 | - assert!(edit.detail().starts_with("45▏"), "{}", edit.detail()); | 13586 | + assert!(edit.detail().starts_with("55▏"), "{}", edit.detail()); |
| 13552 | assert!(edit.detail().contains(&refusal)); | 13587 | assert!(edit.detail().contains(&refusal)); |
| 13553 | // And is fixable in place, which is the whole point of a field. | 13588 | // And is fixable in place, which is the whole point of a field. |
| 13554 | edit.backspace(); | 13589 | edit.backspace(); |
| 13555 | assert_eq!(edit.refusal, None, "the reason went with the digit"); | 13590 | 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)); |
| 13557 | 13592 | ||
| 13558 | // Empty, zero, and past the digit cap: each its own reason, none of | 13593 | // Empty, zero, and past the digit cap: each its own reason, none of |
| 13559 | // them silent. | 13594 | // them silent. |
| 13560 | assert!(commit_mbps("").is_err()); | 13595 | assert!(commit_mbps("").is_err()); |
| 13561 | assert!(commit_mbps("0").unwrap_err().contains("not a rate")); | 13596 | assert!(commit_mbps("0").unwrap_err().contains("not a rate")); |
| 13562 | assert_eq!(commit_mbps("1"), Ok(MBPS_MIN)); | 13597 | assert_eq!(commit_mbps("1"), Ok(MBPS_MIN)); |
| 13563 | - assert_eq!(commit_mbps("20"), Ok(MBPS_MAX)); | 13598 | + assert_eq!(commit_mbps("50"), Ok(MBPS_MAX)); |
| 13564 | - assert!(commit_mbps("21").is_err()); | 13599 | + assert!(commit_mbps("51").is_err()); |
| 13565 | let mut edit = NumberEdit::new(0); | 13600 | let mut edit = NumberEdit::new(0); |
| 13566 | for digit in [9, 9, 9, 9] { | 13601 | for digit in [9, 9, 9, 9] { |
| 13567 | edit.digit(digit); | 13602 | edit.digit(digit); |
| @@ -13587,7 +13622,7 @@ mod tests { | |||
| 13587 | assert_eq!(edit.text, (MBPS_MAX - 1).to_string()); | 13622 | assert_eq!(edit.text, (MBPS_MAX - 1).to_string()); |
| 13588 | // A step past a refused number clears the refusal with it. | 13623 | // A step past a refused number clears the refusal with it. |
| 13589 | let mut edit = NumberEdit::new(0); | 13624 | let mut edit = NumberEdit::new(0); |
| 13590 | - edit.digit(4); | 13625 | + edit.digit(5); |
| 13591 | edit.digit(5); | 13626 | edit.digit(5); |
| 13592 | assert_eq!(edit.commit(), None); | 13627 | assert_eq!(edit.commit(), None); |
| 13593 | edit.step(-1); | 13628 | edit.step(-1); |
crates/app/src/ui/cards.rsmodified+15 -1
| @@ -240,7 +240,21 @@ impl Player { | |||
| 240 | }, | 240 | }, |
| 241 | )); | 241 | )); |
| 242 | if quality == Quality::Custom { | 242 | 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)); | ||
| 244 | } | 258 | } |
| 245 | list.push(r.into_any_element()); | 259 | list.push(r.into_any_element()); |
| 246 | } | 260 | } |
crates/engine/src/export.rsmodified+31 -5
| @@ -107,6 +107,14 @@ const BITS_PER_PIXEL: f64 = 0.1; | |||
| 107 | const MIN_BITRATE: u64 = 1_000_000; | 107 | const MIN_BITRATE: u64 = 1_000_000; |
| 108 | const MAX_BITRATE: u64 = 20_000_000; | 108 | const MAX_BITRATE: u64 = 20_000_000; |
| 109 | 109 | ||
| 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 | + | ||
| 110 | /// The rates the sound may be coded at, smallest first -- what a front-end | 118 | /// The rates the sound may be coded at, smallest first -- what a front-end |
| 111 | /// offers and what [`ExportSettings::audio_kbps`] is clamped into. Every one of | 119 | /// offers and what [`ExportSettings::audio_kbps`] is clamped into. Every one of |
| 112 | /// them is a legal MPEG-1 Layer III value, so the MP3 path writes the figure it | 120 | /// 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 { | |||
| 456 | project.limiter().is_active() || project.audio_gains().iter().any(|&g| g != 1.0) | 464 | project.limiter().is_active() || project.audio_gains().iter().any(|&g| g != 1.0) |
| 457 | } | 465 | } |
| 458 | 466 | ||
| 459 | -/// The bitrate an export codes at: the caller's number through the same clamp | 467 | +/// The bitrate an export codes at: the caller's number clamped into what an |
| 460 | -/// as the computed one, for the reason [`Enc::open`] states. | 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. | ||
| 461 | fn bitrate_of(meta: &VideoMeta, settings: &ExportSettings) -> u64 { | 470 | fn bitrate_of(meta: &VideoMeta, settings: &ExportSettings) -> u64 { |
| 462 | - settings | 471 | + settings.bitrate.map_or_else( |
| 463 | - .bitrate | 472 | + || bitrate_for(meta), |
| 464 | - .map_or_else(|| bitrate_for(meta), |b| b.clamp(MIN_BITRATE, MAX_BITRATE)) | 473 | + |b| b.clamp(MIN_BITRATE, MAX_EXPLICIT_BITRATE), |
| 474 | + ) | ||
| 465 | } | 475 | } |
| 466 | 476 | ||
| 467 | /// The rate the sound codes at: the caller's pick clamped into the offered | 477 | /// The rate the sound codes at: the caller's pick clamped into the offered |
| @@ -3817,6 +3827,22 @@ mod tests { | |||
| 3817 | assert_eq!(bitrate_for(&meta(1280, 720, 30.0)), 2_764_800); | 3827 | assert_eq!(bitrate_for(&meta(1280, 720, 30.0)), 2_764_800); |
| 3818 | assert_eq!(bitrate_for(&meta(320, 240, 30.0)), MIN_BITRATE, "tiny"); | 3828 | assert_eq!(bitrate_for(&meta(320, 240, 30.0)), MIN_BITRATE, "tiny"); |
| 3819 | assert_eq!(bitrate_for(&meta(3840, 2160, 60.0)), MAX_BITRATE, "huge"); | 3829 | 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"); | ||
| 3820 | } | 3846 | } |
| 3821 | 3847 | ||
| 3822 | fn meta(width: u32, height: u32) -> VideoMeta { | 3848 | fn meta(width: u32, height: u32) -> VideoMeta { |