Held keys run the sliders, silence speaks dB or dBFS up to full scale
Browse files at this commit7367dd23a5e429b0f6318f1e47ea15a6e7e8de62Parent: 88fbed0- feat
- held keys run the sliders, silence speaks dB or dBFS up to full scale
2 changed files +158 -21
- crates/app/src/keymap.rs +9 -1
- crates/app/src/main.rs +149 -20
crates/app/src/keymap.rsmodified+9 -1
| @@ -291,7 +291,15 @@ pub struct Fixed { | |||
| 291 | pub category: Category, | 291 | pub category: Category, |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | -pub const FIXED: [Fixed; 14] = [ | 294 | +pub const FIXED: [Fixed; 15] = [ |
| 295 | + // Not a chord at all but a way of pressing one, and the only place the | ||
| 296 | + // editor can say so: holding a key that moves a *value* runs it, and | ||
| 297 | + // holding anything else still does what one press did. | ||
| 298 | + Fixed { | ||
| 299 | + chord: "hold ← → ↑ ↓", | ||
| 300 | + label: "Run a card's slider, or the volume keys, while held", | ||
| 301 | + category: Category::View, | ||
| 302 | + }, | ||
| 295 | Fixed { | 303 | Fixed { |
| 296 | chord: "esc", | 304 | chord: "esc", |
| 297 | label: "Close this card or menu, or cancel a capture", | 305 | label: "Close this card or menu, or cancel a capture", |
crates/app/src/main.rsmodified+149 -20
| @@ -358,9 +358,10 @@ fn speed_at(permille: i32) -> Speed { | |||
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | /// The silence card's rows, in the order it lists them: how wide the apply | 360 | /// The silence card's rows, in the order it lists them: how wide the apply |
| 361 | -/// reaches, the four settings a scan is told, and the rate the speed-up plays | 361 | +/// reaches, the threshold and the unit it is read in, the three durations a |
| 362 | -/// at. What `silence_field` indexes and what [`Player::nudge_silence`] moves. | 362 | +/// scan is told, and the rate the speed-up plays at. What `silence_field` |
| 363 | -const SILENCE_ROWS: usize = 6; | 363 | +/// indexes and what [`Player::nudge_silence`] moves. |
| 364 | +const SILENCE_ROWS: usize = 7; | ||
| 364 | 365 | ||
| 365 | /// How wide a jumpcut reaches. A ripple used to be the whole timeline's | 366 | /// How wide a jumpcut reaches. A ripple used to be the whole timeline's |
| 366 | /// business and nothing else; it is a *choice* now, because a podcast track's | 367 | /// business and nothing else; it is a *choice* now, because a podcast track's |
| @@ -408,9 +409,12 @@ const SILENCE_DB_STEP: f32 = 1.; | |||
| 408 | const SILENCE_SECS_STEP: f64 = 0.05; | 409 | const SILENCE_SECS_STEP: f64 = 0.05; |
| 409 | 410 | ||
| 410 | /// How far each of them may be pushed. UI decisions, all of them: the engine | 411 | /// How far each of them may be pushed. UI decisions, all of them: the engine |
| 411 | -/// takes any finite number, but a threshold at 0 dBFS calls a whole take silent | 412 | +/// takes any finite number, but a forgiveness of ten seconds finds nothing in a |
| 412 | -/// and a forgiveness of ten seconds finds nothing in a talking head. | 413 | +/// talking head. The threshold reaches full scale, which calls a whole take |
| 413 | -const SILENCE_DB_RANGE: (f32, f32) = (-80., -10.); | 414 | +/// silent -- that is a thing someone may want to ask for (the preview on the |
| 415 | +/// lane says what it would cost before anything is cut), so the top is 0 rather | ||
| 416 | +/// than a number this card picked for them. | ||
| 417 | +const SILENCE_DB_RANGE: (f32, f32) = (-80., 0.); | ||
| 414 | const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.); | 418 | const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.); |
| 415 | 419 | ||
| 416 | /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows | 420 | /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows |
| @@ -652,6 +656,14 @@ struct Player { | |||
| 652 | /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own | 656 | /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own |
| 653 | /// focus, since nothing in it takes gpui's (ledger:182). | 657 | /// focus, since nothing in it takes gpui's (ledger:182). |
| 654 | silence_field: usize, | 658 | silence_field: usize, |
| 659 | + /// Whether the threshold is *labelled* dBFS or dB. Display only, and the | ||
| 660 | + /// number is the same either way: the setting is a level below full scale, | ||
| 661 | + /// so 0 is the loudest sample a file can hold and -40 is forty decibels | ||
| 662 | + /// under it -- "dBFS" names that reference out loud, "dB" leaves it unsaid. | ||
| 663 | + /// No conversion is hiding behind the row (there is no reference here worth | ||
| 664 | + /// inventing, and a made-up SPL would be a lie about what was measured); | ||
| 665 | + /// what it changes is which of the two spellings a person reads. | ||
| 666 | + silence_dbfs: bool, | ||
| 655 | /// What the last scan found, in timeline frames: what the lane draws marks | 667 | /// What the last scan found, in timeline frames: what the lane draws marks |
| 656 | /// over and what an apply acts on -- *exactly* the previewed set, never a | 668 | /// over and what an apply acts on -- *exactly* the previewed set, never a |
| 657 | /// second scan at the moment of the press. | 669 | /// second scan at the moment of the press. |
| @@ -1314,9 +1326,12 @@ impl Player { | |||
| 1314 | + steps as f32 * SILENCE_DB_STEP) | 1326 | + steps as f32 * SILENCE_DB_STEP) |
| 1315 | .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1) | 1327 | .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1) |
| 1316 | } | 1328 | } |
| 1317 | - 2 => self.silence.min_silence = secs(self.silence.min_silence), | 1329 | + // Two spellings of the same level, so either arrow flips it -- a |
| 1318 | - 3 => self.silence.padding = secs(self.silence.padding), | 1330 | + // ring of two, like the scope row's. |
| 1319 | - 4 => self.silence.min_keep = secs(self.silence.min_keep), | 1331 | + 2 => self.silence_dbfs = !self.silence_dbfs, |
| 1332 | + 3 => self.silence.min_silence = secs(self.silence.min_silence), | ||
| 1333 | + 4 => self.silence.padding = secs(self.silence.padding), | ||
| 1334 | + 5 => self.silence.min_keep = secs(self.silence.min_keep), | ||
| 1320 | _ => { | 1335 | _ => { |
| 1321 | self.silence_factor = | 1336 | self.silence_factor = |
| 1322 | silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP) | 1337 | silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP) |
| @@ -1469,6 +1484,29 @@ impl Player { | |||
| 1469 | || self.exporting().is_some() | 1484 | || self.exporting().is_some() |
| 1470 | } | 1485 | } |
| 1471 | 1486 | ||
| 1487 | + /// Which of [`Repeat`]'s three the window is in, for the hold gate at the | ||
| 1488 | + /// top of the key handler. Not [`Player::modal`]: that asks whether an | ||
| 1489 | + /// overlay is up at all, and here the cards with sliders in them are | ||
| 1490 | + /// exactly the ones that answer differently from the keys menu and the | ||
| 1491 | + /// export card. | ||
| 1492 | + fn repeat_scope(&self) -> Repeat { | ||
| 1493 | + if self.rebinding.is_some() | ||
| 1494 | + || self.keys_open | ||
| 1495 | + || self.export_open | ||
| 1496 | + || self.exporting().is_some() | ||
| 1497 | + { | ||
| 1498 | + Repeat::Nothing | ||
| 1499 | + } else if self.eq_open.is_some() | ||
| 1500 | + || self.color_open.is_some() | ||
| 1501 | + || self.speed_open.is_some() | ||
| 1502 | + || self.silence_open.is_some() | ||
| 1503 | + { | ||
| 1504 | + Repeat::Card | ||
| 1505 | + } else { | ||
| 1506 | + Repeat::Keymap | ||
| 1507 | + } | ||
| 1508 | + } | ||
| 1509 | + | ||
| 1472 | /// Opens the equalizer on the selected clip. Audio only, and it says so | 1510 | /// Opens the equalizer on the selected clip. Audio only, and it says so |
| 1473 | /// rather than opening a card of bands that would reach nothing: a video | 1511 | /// rather than opening a card of bands that would reach nothing: a video |
| 1474 | /// clip carries no sound of its own here (the sound is the audio lane's), | 1512 | /// clip carries no sound of its own here (the sound is the audio lane's), |
| @@ -2714,9 +2752,19 @@ impl Render for Player { | |||
| 2714 | div() | 2752 | div() |
| 2715 | .track_focus(&self.focus) | 2753 | .track_focus(&self.focus) |
| 2716 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { | 2754 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| { |
| 2717 | - // `is_held` filters auto-repeat, which would otherwise toggle | 2755 | + let key = event.keystroke.key.as_str(); |
| 2718 | - // playback -- or cut the timeline -- many times a second. | 2756 | + let ctrl = event.keystroke.modifiers.control; |
| 2719 | - if event.is_held { | 2757 | + // `is_held` is the auto-repeat, and a value is the one thing |
| 2758 | + // worth running on it: a held arrow on a card moves the slider | ||
| 2759 | + // it picked, and a held volume key runs the volume. Everything | ||
| 2760 | + // else is filtered exactly as it always was -- a repeat that | ||
| 2761 | + // toggled playback, or cut the timeline, many times a second is | ||
| 2762 | + // what this guard is for, and a row waiting for a stroke takes | ||
| 2763 | + // none of it either (it would bind the key, then fire what it | ||
| 2764 | + // just bound). See [`repeats`]. | ||
| 2765 | + if event.is_held | ||
| 2766 | + && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl)) | ||
| 2767 | + { | ||
| 2720 | return; | 2768 | return; |
| 2721 | } | 2769 | } |
| 2722 | // Any key retires the last message, whatever it was -- and owes | 2770 | // Any key retires the last message, whatever it was -- and owes |
| @@ -2726,7 +2774,6 @@ impl Render for Player { | |||
| 2726 | if this.notice.take().is_some() { | 2774 | if this.notice.take().is_some() { |
| 2727 | cx.notify(); | 2775 | cx.notify(); |
| 2728 | } | 2776 | } |
| 2729 | - let key = event.keystroke.key.as_str(); | ||
| 2730 | // A row is waiting for a stroke, and while it is, that stroke is | 2777 | // A row is waiting for a stroke, and while it is, that stroke is |
| 2731 | // data: it means the binding and nothing else, which is why this | 2778 | // data: it means the binding and nothing else, which is why this |
| 2732 | // answers before the export guard and before the keymap is | 2779 | // answers before the export guard and before the keymap is |
| @@ -2735,7 +2782,7 @@ impl Render for Player { | |||
| 2735 | if key == ESCAPE { | 2782 | if key == ESCAPE { |
| 2736 | this.rebinding = None; | 2783 | this.rebinding = None; |
| 2737 | } else if !is_bare_modifier(key) { | 2784 | } else if !is_bare_modifier(key) { |
| 2738 | - this.capture(action, key, event.keystroke.modifiers.control); | 2785 | + this.capture(action, key, ctrl); |
| 2739 | } | 2786 | } |
| 2740 | cx.notify(); | 2787 | cx.notify(); |
| 2741 | return; | 2788 | return; |
| @@ -2744,7 +2791,7 @@ impl Render for Player { | |||
| 2744 | // control modifier set (the control code is mapped back), which | 2791 | // control modifier set (the control code is mapped back), which |
| 2745 | // is why the keymap is keyed on the pair and never on the key | 2792 | // is why the keymap is keyed on the pair and never on the key |
| 2746 | // alone. | 2793 | // alone. |
| 2747 | - let action = this.keymap.lookup(key, event.keystroke.modifiers.control); | 2794 | + let action = this.keymap.lookup(key, ctrl); |
| 2748 | // An export is reading the edit list every other action here | 2795 | // An export is reading the edit list every other action here |
| 2749 | // would change, so cancelling is the only one that means | 2796 | // would change, so cancelling is the only one that means |
| 2750 | // anything until it is over. | 2797 | // anything until it is over. |
| @@ -4548,9 +4595,19 @@ impl Player { | |||
| 4548 | fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | 4595 | fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { |
| 4549 | let (lane, idx) = self.silence_open?; | 4596 | let (lane, idx) = self.silence_open?; |
| 4550 | let cfg = self.silence; | 4597 | let cfg = self.silence; |
| 4598 | + // The unit is a label, never a conversion: the threshold is a level | ||
| 4599 | + // below full scale whichever of the two the row says (`silence_dbfs`). | ||
| 4600 | + let unit = match self.silence_dbfs { | ||
| 4601 | + true => "dBFS", | ||
| 4602 | + false => "dB", | ||
| 4603 | + }; | ||
| 4551 | let rows = [ | 4604 | let rows = [ |
| 4552 | ("Apply to", self.silence_scope.label(&self.silence_lanes())), | 4605 | ("Apply to", self.silence_scope.label(&self.silence_lanes())), |
| 4553 | - ("Silence is under", format!("{:.0} dBFS", cfg.threshold_db)), | 4606 | + ( |
| 4607 | + "Silence is under", | ||
| 4608 | + format!("{:.0} {unit}", cfg.threshold_db), | ||
| 4609 | + ), | ||
| 4610 | + ("Level read in", format!("{unit} (0 = full scale)")), | ||
| 4554 | ( | 4611 | ( |
| 4555 | "Forgive quiet shorter than", | 4612 | "Forgive quiet shorter than", |
| 4556 | format!("{:.2} s", cfg.min_silence), | 4613 | format!("{:.2} s", cfg.min_silence), |
| @@ -4649,7 +4706,7 @@ impl Player { | |||
| 4649 | .text_size(px(11.)) | 4706 | .text_size(px(11.)) |
| 4650 | .text_color(rgb(INK_DIM)) | 4707 | .text_color(rgb(INK_DIM)) |
| 4651 | .child( | 4708 | .child( |
| 4652 | - "↑↓ picks a setting, ←→ moves it — the marks on the lane are what would go; esc closes", | 4709 | + "↑↓ picks a setting, ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes", |
| 4653 | ), | 4710 | ), |
| 4654 | ) | 4711 | ) |
| 4655 | .children(rows) | 4712 | .children(rows) |
| @@ -6142,6 +6199,39 @@ fn cancels_export(key: &str, action: Option<ActionId>) -> bool { | |||
| 6142 | key == ESCAPE || action == Some(ActionId::CancelExport) | 6199 | key == ESCAPE || action == Some(ActionId::CancelExport) |
| 6143 | } | 6200 | } |
| 6144 | 6201 | ||
| 6202 | +/// Where a held key would land, which is the whole of what auto-repeat has to | ||
| 6203 | +/// know. [`Player::repeat_scope`] answers it from the same state the handler | ||
| 6204 | +/// walks below itself. | ||
| 6205 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
| 6206 | +enum Repeat { | ||
| 6207 | + /// A card with values in it owns the keyboard: equalizer, colour, speed or | ||
| 6208 | + /// silence. Its arrows are sliders. | ||
| 6209 | + Card, | ||
| 6210 | + /// Nobody does, so the keymap answers -- and only one pair of its actions | ||
| 6211 | + /// is a value being moved rather than a thing being done once. | ||
| 6212 | + Keymap, | ||
| 6213 | + /// A stroke is being captured, an export is running, or an overlay with no | ||
| 6214 | + /// value in it is up. Nothing there is worth a repeat. | ||
| 6215 | + Nothing, | ||
| 6216 | +} | ||
| 6217 | + | ||
| 6218 | +/// Whether a *held* stroke means it again. One press is always one action; a | ||
| 6219 | +/// hold is only ever a value running, so this is what tells the two apart. | ||
| 6220 | +/// | ||
| 6221 | +/// The cards' arrows, because that is what every one of them moves a slider | ||
| 6222 | +/// with -- and only the arrows, so the equalizer's `r` cannot flatten five | ||
| 6223 | +/// bands forty times a second and the silence card's `enter` cannot cut forty | ||
| 6224 | +/// places again on the next tick. Outside a card the volume pair and nothing | ||
| 6225 | +/// else: play, cut, delete, save, export and every other binding is a one-shot, | ||
| 6226 | +/// exactly as it was when the handler filtered every held key alike. | ||
| 6227 | +fn repeats(scope: Repeat, key: &str, action: Option<ActionId>) -> bool { | ||
| 6228 | + match scope { | ||
| 6229 | + Repeat::Card => matches!(key, "up" | "down" | "left" | "right"), | ||
| 6230 | + Repeat::Keymap => matches!(action, Some(ActionId::VolumeUp | ActionId::VolumeDown)), | ||
| 6231 | + Repeat::Nothing => false, | ||
| 6232 | + } | ||
| 6233 | +} | ||
| 6234 | + | ||
| 6145 | /// The keys that are only ever half a chord. gpui delivers a lone modifier | 6235 | /// The keys that are only ever half a chord. gpui delivers a lone modifier |
| 6146 | /// press as a keystroke of its own, and taking one as a binding would leave an | 6236 | /// press as a keystroke of its own, and taking one as a binding would leave an |
| 6147 | /// action that fires the moment the user reaches for any chord that uses it -- | 6237 | /// action that fires the moment the user reaches for any chord that uses it -- |
| @@ -6718,7 +6808,7 @@ mod tests { | |||
| 6718 | silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths, | 6808 | silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths, |
| 6719 | unseen_sources, whole_take, width_frac, window_title, | 6809 | unseen_sources, whole_take, width_frac, window_title, |
| 6720 | }; | 6810 | }; |
| 6721 | - use super::{LaneKind, file_name, file_uri, library_rows, unscannable}; | 6811 | + use super::{LaneKind, Repeat, file_name, file_uri, library_rows, repeats, unscannable}; |
| 6722 | 6812 | ||
| 6723 | /// What the file manager is handed: the parts a path keeps as they are, and | 6813 | /// What the file manager is handed: the parts a path keeps as they are, and |
| 6724 | /// the ones the bus would otherwise read as something else. | 6814 | /// the ones the bus would otherwise read as something else. |
| @@ -8226,11 +8316,47 @@ mod tests { | |||
| 8226 | ); | 8316 | ); |
| 8227 | } | 8317 | } |
| 8228 | 8318 | ||
| 8319 | + /// The hold gate: a value runs, everything else still means one press one | ||
| 8320 | + /// action -- which is the whole invariant the blanket `is_held` filter used | ||
| 8321 | + /// to carry on its own. | ||
| 8322 | + #[test] | ||
| 8323 | + fn a_held_key_moves_a_value_and_nothing_else() { | ||
| 8324 | + use keymap::ActionId; | ||
| 8325 | + // A card's four arrows, whichever card it is. | ||
| 8326 | + for key in ["up", "down", "left", "right"] { | ||
| 8327 | + assert!(repeats(Repeat::Card, key, None), "{key} on a card"); | ||
| 8328 | + } | ||
| 8329 | + // The card's own one-shots: flatten every band, cut forty places, play | ||
| 8330 | + // them fast, close. None of them on a hold. | ||
| 8331 | + for key in ["r", "enter", "f", "1", "escape"] { | ||
| 8332 | + assert!(!repeats(Repeat::Card, key, None), "{key} on a card"); | ||
| 8333 | + } | ||
| 8334 | + // Outside a card the keymap answers, and only the volume pair is a | ||
| 8335 | + // value being moved. | ||
| 8336 | + assert!(repeats(Repeat::Keymap, "up", Some(ActionId::VolumeUp))); | ||
| 8337 | + assert!(repeats(Repeat::Keymap, "down", Some(ActionId::VolumeDown))); | ||
| 8338 | + for action in ActionId::ALL { | ||
| 8339 | + let held = repeats(Repeat::Keymap, "k", Some(action)); | ||
| 8340 | + assert_eq!( | ||
| 8341 | + held, | ||
| 8342 | + matches!(action, ActionId::VolumeUp | ActionId::VolumeDown), | ||
| 8343 | + "{action:?} on a hold" | ||
| 8344 | + ); | ||
| 8345 | + } | ||
| 8346 | + // An arrow with nothing bound to it moves nothing on the timeline. | ||
| 8347 | + assert!(!repeats(Repeat::Keymap, "left", None)); | ||
| 8348 | + // And a stroke being captured, an export, or the overlays: nothing at | ||
| 8349 | + // all, or the hold would bind a key and then fire what it just bound. | ||
| 8350 | + for key in ["up", "left", "escape", "5"] { | ||
| 8351 | + assert!(!repeats(Repeat::Nothing, key, Some(ActionId::VolumeUp))); | ||
| 8352 | + } | ||
| 8353 | + } | ||
| 8354 | + | ||
| 8229 | #[test] | 8355 | #[test] |
| 8230 | fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() { | 8356 | fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() { |
| 8231 | // The same 640x360 floor, and this card starts below the header: a | 8357 | // The same 640x360 floor, and this card starts below the header: a |
| 8232 | - // title and a hint over its five rows, the count line and the two | 8358 | + // title and a hint over its [`SILENCE_ROWS`] rows, the count line and |
| 8233 | - // buttons. | 8359 | + // the two buttons. |
| 8234 | let (title, hint, count) = (17., 17., 17.); | 8360 | let (title, hint, count) = (17., 17., 17.); |
| 8235 | let gaps = 6. * 5.; | 8361 | let gaps = 6. * 5.; |
| 8236 | let padding = 24.; | 8362 | let padding = 24.; |
| @@ -8728,6 +8854,9 @@ fn main() { | |||
| 8728 | // one a person can widen on purpose. | 8854 | // one a person can widen on purpose. |
| 8729 | silence_scope: Scope::Take, | 8855 | silence_scope: Scope::Take, |
| 8730 | silence_field: 0, | 8856 | silence_field: 0, |
| 8857 | + // The reference named, which is what the card said before | ||
| 8858 | + // there was a choice about it. | ||
| 8859 | + silence_dbfs: true, | ||
| 8731 | silence_marks: Vec::new(), | 8860 | silence_marks: Vec::new(), |
| 8732 | silence_levels: None, | 8861 | silence_levels: None, |
| 8733 | color_open: None, | 8862 | color_open: None, |