forge
Explore
Log in

Don't you dare go Hollow

🔀 merge(T12): long-press repeat + silence range/units

Browse files at this commit

18c86cb4ecfbe0f8fad78bbc9b75f11b337c71aeAhmet Kaan GümüşParent: 2f24ce37367dd2
crates/app/src/keymap.rsmodified+9 -1
@@ -291,7 +291,15 @@ pub struct Fixed {
291291 pub category: Category,
292292 }
293293
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+ },
295303 Fixed {
296304 chord: "esc",
297305 label: "Close this card or menu, or cancel a capture",
crates/app/src/main.rsmodified+149 -20
@@ -389,9 +389,10 @@ fn speed_at(permille: i32) -> Speed {
389389 }
390390
391391 /// The silence card's rows, in the order it lists them: how wide the apply
392-/// reaches, the four settings a scan is told, and the rate the speed-up plays
393-/// at. What `silence_field` indexes and what [`Player::nudge_silence`] moves.
394-const SILENCE_ROWS: usize = 6;
392+/// reaches, the threshold and the unit it is read in, the three durations a
393+/// scan is told, and the rate the speed-up plays at. What `silence_field`
394+/// indexes and what [`Player::nudge_silence`] moves.
395+const SILENCE_ROWS: usize = 7;
395396
396397 /// How wide a jumpcut reaches. A ripple used to be the whole timeline's
397398 /// business and nothing else; it is a *choice* now, because a podcast track's
@@ -439,9 +440,12 @@ const SILENCE_DB_STEP: f32 = 1.;
439440 const SILENCE_SECS_STEP: f64 = 0.05;
440441
441442 /// How far each of them may be pushed. UI decisions, all of them: the engine
442-/// takes any finite number, but a threshold at 0 dBFS calls a whole take silent
443-/// and a forgiveness of ten seconds finds nothing in a talking head.
444-const SILENCE_DB_RANGE: (f32, f32) = (-80., -10.);
443+/// takes any finite number, but a forgiveness of ten seconds finds nothing in a
444+/// talking head. The threshold reaches full scale, which calls a whole take
445+/// silent -- that is a thing someone may want to ask for (the preview on the
446+/// lane says what it would cost before anything is cut), so the top is 0 rather
447+/// than a number this card picked for them.
448+const SILENCE_DB_RANGE: (f32, f32) = (-80., 0.);
445449 const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.);
446450
447451 /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows
@@ -688,6 +692,14 @@ struct Player {
688692 /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own
689693 /// focus, since nothing in it takes gpui's (ledger:182).
690694 silence_field: usize,
695+ /// Whether the threshold is *labelled* dBFS or dB. Display only, and the
696+ /// number is the same either way: the setting is a level below full scale,
697+ /// so 0 is the loudest sample a file can hold and -40 is forty decibels
698+ /// under it -- "dBFS" names that reference out loud, "dB" leaves it unsaid.
699+ /// No conversion is hiding behind the row (there is no reference here worth
700+ /// inventing, and a made-up SPL would be a lie about what was measured);
701+ /// what it changes is which of the two spellings a person reads.
702+ silence_dbfs: bool,
691703 /// What the last scan found, in timeline frames: what the lane draws marks
692704 /// over and what an apply acts on -- *exactly* the previewed set, never a
693705 /// second scan at the moment of the press.
@@ -1350,9 +1362,12 @@ impl Player {
13501362 + steps as f32 * SILENCE_DB_STEP)
13511363 .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1)
13521364 }
1353- 2 => self.silence.min_silence = secs(self.silence.min_silence),
1354- 3 => self.silence.padding = secs(self.silence.padding),
1355- 4 => self.silence.min_keep = secs(self.silence.min_keep),
1365+ // Two spellings of the same level, so either arrow flips it -- a
1366+ // ring of two, like the scope row's.
1367+ 2 => self.silence_dbfs = !self.silence_dbfs,
1368+ 3 => self.silence.min_silence = secs(self.silence.min_silence),
1369+ 4 => self.silence.padding = secs(self.silence.padding),
1370+ 5 => self.silence.min_keep = secs(self.silence.min_keep),
13561371 _ => {
13571372 self.silence_factor =
13581373 silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP)
@@ -1505,6 +1520,29 @@ impl Player {
15051520 || self.exporting().is_some()
15061521 }
15071522
1523+ /// Which of [`Repeat`]'s three the window is in, for the hold gate at the
1524+ /// top of the key handler. Not [`Player::modal`]: that asks whether an
1525+ /// overlay is up at all, and here the cards with sliders in them are
1526+ /// exactly the ones that answer differently from the keys menu and the
1527+ /// export card.
1528+ fn repeat_scope(&self) -> Repeat {
1529+ if self.rebinding.is_some()
1530+ || self.keys_open
1531+ || self.export_open
1532+ || self.exporting().is_some()
1533+ {
1534+ Repeat::Nothing
1535+ } else if self.eq_open.is_some()
1536+ || self.color_open.is_some()
1537+ || self.speed_open.is_some()
1538+ || self.silence_open.is_some()
1539+ {
1540+ Repeat::Card
1541+ } else {
1542+ Repeat::Keymap
1543+ }
1544+ }
1545+
15081546 /// Opens the equalizer on the selected clip. Audio only, and it says so
15091547 /// rather than opening a card of bands that would reach nothing: a video
15101548 /// clip carries no sound of its own here (the sound is the audio lane's),
@@ -2792,9 +2830,19 @@ impl Render for Player {
27922830 div()
27932831 .track_focus(&self.focus)
27942832 .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| {
2795- // `is_held` filters auto-repeat, which would otherwise toggle
2796- // playback -- or cut the timeline -- many times a second.
2797- if event.is_held {
2833+ let key = event.keystroke.key.as_str();
2834+ let ctrl = event.keystroke.modifiers.control;
2835+ // `is_held` is the auto-repeat, and a value is the one thing
2836+ // worth running on it: a held arrow on a card moves the slider
2837+ // it picked, and a held volume key runs the volume. Everything
2838+ // else is filtered exactly as it always was -- a repeat that
2839+ // toggled playback, or cut the timeline, many times a second is
2840+ // what this guard is for, and a row waiting for a stroke takes
2841+ // none of it either (it would bind the key, then fire what it
2842+ // just bound). See [`repeats`].
2843+ if event.is_held
2844+ && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl))
2845+ {
27982846 return;
27992847 }
28002848 // Any key retires the last message, whatever it was -- and owes
@@ -2804,7 +2852,6 @@ impl Render for Player {
28042852 if this.notice.take().is_some() {
28052853 cx.notify();
28062854 }
2807- let key = event.keystroke.key.as_str();
28082855 // A row is waiting for a stroke, and while it is, that stroke is
28092856 // data: it means the binding and nothing else, which is why this
28102857 // answers before the export guard and before the keymap is
@@ -2813,7 +2860,7 @@ impl Render for Player {
28132860 if key == ESCAPE {
28142861 this.rebinding = None;
28152862 } else if !is_bare_modifier(key) {
2816- this.capture(action, key, event.keystroke.modifiers.control);
2863+ this.capture(action, key, ctrl);
28172864 }
28182865 cx.notify();
28192866 return;
@@ -2822,7 +2869,7 @@ impl Render for Player {
28222869 // control modifier set (the control code is mapped back), which
28232870 // is why the keymap is keyed on the pair and never on the key
28242871 // alone.
2825- let action = this.keymap.lookup(key, event.keystroke.modifiers.control);
2872+ let action = this.keymap.lookup(key, ctrl);
28262873 // An export is reading the edit list every other action here
28272874 // would change, so cancelling is the only one that means
28282875 // anything until it is over.
@@ -4658,9 +4705,19 @@ impl Player {
46584705 fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
46594706 let (lane, idx) = self.silence_open?;
46604707 let cfg = self.silence;
4708+ // The unit is a label, never a conversion: the threshold is a level
4709+ // below full scale whichever of the two the row says (`silence_dbfs`).
4710+ let unit = match self.silence_dbfs {
4711+ true => "dBFS",
4712+ false => "dB",
4713+ };
46614714 let rows = [
46624715 ("Apply to", self.silence_scope.label(&self.silence_lanes())),
4663- ("Silence is under", format!("{:.0} dBFS", cfg.threshold_db)),
4716+ (
4717+ "Silence is under",
4718+ format!("{:.0} {unit}", cfg.threshold_db),
4719+ ),
4720+ ("Level read in", format!("{unit} (0 = full scale)")),
46644721 (
46654722 "Forgive quiet shorter than",
46664723 format!("{:.2} s", cfg.min_silence),
@@ -4759,7 +4816,7 @@ impl Player {
47594816 .text_size(px(11.))
47604817 .text_color(rgb(INK_DIM))
47614818 .child(
4762- "↑↓ picks a setting, ←→ moves it — the marks on the lane are what would go; esc closes",
4819+ "↑↓ picks a setting, ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes",
47634820 ),
47644821 )
47654822 .children(rows)
@@ -6252,6 +6309,39 @@ fn cancels_export(key: &str, action: Option<ActionId>) -> bool {
62526309 key == ESCAPE || action == Some(ActionId::CancelExport)
62536310 }
62546311
6312+/// Where a held key would land, which is the whole of what auto-repeat has to
6313+/// know. [`Player::repeat_scope`] answers it from the same state the handler
6314+/// walks below itself.
6315+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
6316+enum Repeat {
6317+ /// A card with values in it owns the keyboard: equalizer, colour, speed or
6318+ /// silence. Its arrows are sliders.
6319+ Card,
6320+ /// Nobody does, so the keymap answers -- and only one pair of its actions
6321+ /// is a value being moved rather than a thing being done once.
6322+ Keymap,
6323+ /// A stroke is being captured, an export is running, or an overlay with no
6324+ /// value in it is up. Nothing there is worth a repeat.
6325+ Nothing,
6326+}
6327+
6328+/// Whether a *held* stroke means it again. One press is always one action; a
6329+/// hold is only ever a value running, so this is what tells the two apart.
6330+///
6331+/// The cards' arrows, because that is what every one of them moves a slider
6332+/// with -- and only the arrows, so the equalizer's `r` cannot flatten five
6333+/// bands forty times a second and the silence card's `enter` cannot cut forty
6334+/// places again on the next tick. Outside a card the volume pair and nothing
6335+/// else: play, cut, delete, save, export and every other binding is a one-shot,
6336+/// exactly as it was when the handler filtered every held key alike.
6337+fn repeats(scope: Repeat, key: &str, action: Option<ActionId>) -> bool {
6338+ match scope {
6339+ Repeat::Card => matches!(key, "up" | "down" | "left" | "right"),
6340+ Repeat::Keymap => matches!(action, Some(ActionId::VolumeUp | ActionId::VolumeDown)),
6341+ Repeat::Nothing => false,
6342+ }
6343+}
6344+
62556345 /// The keys that are only ever half a chord. gpui delivers a lone modifier
62566346 /// press as a keystroke of its own, and taking one as a binding would leave an
62576347 /// action that fires the moment the user reaches for any chord that uses it --
@@ -6882,7 +6972,7 @@ mod tests {
68826972 silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths,
68836973 nothing_to_play, unseen_sources, whole_take, width_frac, window_title,
68846974 };
6885- use super::{LaneKind, file_name, file_uri, library_rows, unscannable};
6975+ use super::{LaneKind, Repeat, file_name, file_uri, library_rows, repeats, unscannable};
68866976
68876977 /// What the file manager is handed: the parts a path keeps as they are, and
68886978 /// the ones the bus would otherwise read as something else.
@@ -8390,11 +8480,47 @@ mod tests {
83908480 );
83918481 }
83928482
8483+ /// The hold gate: a value runs, everything else still means one press one
8484+ /// action -- which is the whole invariant the blanket `is_held` filter used
8485+ /// to carry on its own.
8486+ #[test]
8487+ fn a_held_key_moves_a_value_and_nothing_else() {
8488+ use keymap::ActionId;
8489+ // A card's four arrows, whichever card it is.
8490+ for key in ["up", "down", "left", "right"] {
8491+ assert!(repeats(Repeat::Card, key, None), "{key} on a card");
8492+ }
8493+ // The card's own one-shots: flatten every band, cut forty places, play
8494+ // them fast, close. None of them on a hold.
8495+ for key in ["r", "enter", "f", "1", "escape"] {
8496+ assert!(!repeats(Repeat::Card, key, None), "{key} on a card");
8497+ }
8498+ // Outside a card the keymap answers, and only the volume pair is a
8499+ // value being moved.
8500+ assert!(repeats(Repeat::Keymap, "up", Some(ActionId::VolumeUp)));
8501+ assert!(repeats(Repeat::Keymap, "down", Some(ActionId::VolumeDown)));
8502+ for action in ActionId::ALL {
8503+ let held = repeats(Repeat::Keymap, "k", Some(action));
8504+ assert_eq!(
8505+ held,
8506+ matches!(action, ActionId::VolumeUp | ActionId::VolumeDown),
8507+ "{action:?} on a hold"
8508+ );
8509+ }
8510+ // An arrow with nothing bound to it moves nothing on the timeline.
8511+ assert!(!repeats(Repeat::Keymap, "left", None));
8512+ // And a stroke being captured, an export, or the overlays: nothing at
8513+ // all, or the hold would bind a key and then fire what it just bound.
8514+ for key in ["up", "left", "escape", "5"] {
8515+ assert!(!repeats(Repeat::Nothing, key, Some(ActionId::VolumeUp)));
8516+ }
8517+ }
8518+
83938519 #[test]
83948520 fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() {
83958521 // The same 640x360 floor, and this card starts below the header: a
8396- // title and a hint over its five rows, the count line and the two
8397- // buttons.
8522+ // title and a hint over its [`SILENCE_ROWS`] rows, the count line and
8523+ // the two buttons.
83988524 let (title, hint, count) = (17., 17., 17.);
83998525 let gaps = 6. * 5.;
84008526 let padding = 24.;
@@ -9004,6 +9130,9 @@ fn main() {
90049130 // one a person can widen on purpose.
90059131 silence_scope: Scope::Take,
90069132 silence_field: 0,
9133+ // The reference named, which is what the card said before
9134+ // there was a choice about it.
9135+ silence_dbfs: true,
90079136 silence_marks: Vec::new(),
90089137 silence_levels: None,
90099138 color_open: None,