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 {
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
@@ -389,9 +389,10 @@ fn speed_at(permille: i32) -> Speed {
389 }389 }
390 390
391 /// The silence card's rows, in the order it lists them: how wide the apply391 /// 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 plays392+/// reaches, the threshold and the unit it is read in, the three durations a
393-/// at. What `silence_field` indexes and what [`Player::nudge_silence`] moves.393+/// scan is told, and the rate the speed-up plays at. What `silence_field`
394-const SILENCE_ROWS: usize = 6;394+/// indexes and what [`Player::nudge_silence`] moves.
395+const SILENCE_ROWS: usize = 7;
395 396
396 /// How wide a jumpcut reaches. A ripple used to be the whole timeline's397 /// How wide a jumpcut reaches. A ripple used to be the whole timeline's
397 /// business and nothing else; it is a *choice* now, because a podcast track's398 /// business and nothing else; it is a *choice* now, because a podcast track's
@@ -439,9 +440,12 @@ const SILENCE_DB_STEP: f32 = 1.;
439 const SILENCE_SECS_STEP: f64 = 0.05;440 const SILENCE_SECS_STEP: f64 = 0.05;
440 441
441 /// How far each of them may be pushed. UI decisions, all of them: the engine442 /// 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 silent443+/// takes any finite number, but a forgiveness of ten seconds finds nothing in a
443-/// and a forgiveness of ten seconds finds nothing in a talking head.444+/// talking head. The threshold reaches full scale, which calls a whole take
444-const SILENCE_DB_RANGE: (f32, f32) = (-80., -10.);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.);
445 const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.);449 const SILENCE_SECS_RANGE: (f64, f64) = (0., 5.);
446 450
447 /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows451 /// The speed-up rate is bounded *below* by real time: a "speed-up" that slows
@@ -688,6 +692,14 @@ struct Player {
688 /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own692 /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own
689 /// focus, since nothing in it takes gpui's (ledger:182).693 /// focus, since nothing in it takes gpui's (ledger:182).
690 silence_field: usize,694 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,
691 /// What the last scan found, in timeline frames: what the lane draws marks703 /// What the last scan found, in timeline frames: what the lane draws marks
692 /// over and what an apply acts on -- *exactly* the previewed set, never a704 /// over and what an apply acts on -- *exactly* the previewed set, never a
693 /// second scan at the moment of the press.705 /// second scan at the moment of the press.
@@ -1350,9 +1362,12 @@ impl Player {
1350 + steps as f32 * SILENCE_DB_STEP)1362 + steps as f32 * SILENCE_DB_STEP)
1351 .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1)1363 .clamp(SILENCE_DB_RANGE.0, SILENCE_DB_RANGE.1)
1352 }1364 }
1353- 2 => self.silence.min_silence = secs(self.silence.min_silence),1365+ // Two spellings of the same level, so either arrow flips it -- a
1354- 3 => self.silence.padding = secs(self.silence.padding),1366+ // ring of two, like the scope row's.
1355- 4 => self.silence.min_keep = secs(self.silence.min_keep),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),
1356 _ => {1371 _ => {
1357 self.silence_factor =1372 self.silence_factor =
1358 silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP)1373 silence_rate(i32::from(self.silence_factor.permille()) + steps * SPEED_STEP)
@@ -1505,6 +1520,29 @@ impl Player {
1505 || self.exporting().is_some()1520 || self.exporting().is_some()
1506 }1521 }
1507 1522
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+
1508 /// Opens the equalizer on the selected clip. Audio only, and it says so1546 /// Opens the equalizer on the selected clip. Audio only, and it says so
1509 /// rather than opening a card of bands that would reach nothing: a video1547 /// rather than opening a card of bands that would reach nothing: a video
1510 /// clip carries no sound of its own here (the sound is the audio lane's),1548 /// clip carries no sound of its own here (the sound is the audio lane's),
@@ -2792,9 +2830,19 @@ impl Render for Player {
2792 div()2830 div()
2793 .track_focus(&self.focus)2831 .track_focus(&self.focus)
2794 .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| {2832 .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| {
2795- // `is_held` filters auto-repeat, which would otherwise toggle2833+ let key = event.keystroke.key.as_str();
2796- // playback -- or cut the timeline -- many times a second.2834+ let ctrl = event.keystroke.modifiers.control;
2797- if event.is_held {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+ {
2798 return;2846 return;
2799 }2847 }
2800 // Any key retires the last message, whatever it was -- and owes2848 // Any key retires the last message, whatever it was -- and owes
@@ -2804,7 +2852,6 @@ impl Render for Player {
2804 if this.notice.take().is_some() {2852 if this.notice.take().is_some() {
2805 cx.notify();2853 cx.notify();
2806 }2854 }
2807- let key = event.keystroke.key.as_str();
2808 // A row is waiting for a stroke, and while it is, that stroke is2855 // A row is waiting for a stroke, and while it is, that stroke is
2809 // data: it means the binding and nothing else, which is why this2856 // data: it means the binding and nothing else, which is why this
2810 // answers before the export guard and before the keymap is2857 // answers before the export guard and before the keymap is
@@ -2813,7 +2860,7 @@ impl Render for Player {
2813 if key == ESCAPE {2860 if key == ESCAPE {
2814 this.rebinding = None;2861 this.rebinding = None;
2815 } else if !is_bare_modifier(key) {2862 } else if !is_bare_modifier(key) {
2816- this.capture(action, key, event.keystroke.modifiers.control);2863+ this.capture(action, key, ctrl);
2817 }2864 }
2818 cx.notify();2865 cx.notify();
2819 return;2866 return;
@@ -2822,7 +2869,7 @@ impl Render for Player {
2822 // control modifier set (the control code is mapped back), which2869 // control modifier set (the control code is mapped back), which
2823 // is why the keymap is keyed on the pair and never on the key2870 // is why the keymap is keyed on the pair and never on the key
2824 // alone.2871 // alone.
2825- let action = this.keymap.lookup(key, event.keystroke.modifiers.control);2872+ let action = this.keymap.lookup(key, ctrl);
2826 // An export is reading the edit list every other action here2873 // An export is reading the edit list every other action here
2827 // would change, so cancelling is the only one that means2874 // would change, so cancelling is the only one that means
2828 // anything until it is over.2875 // anything until it is over.
@@ -4658,9 +4705,19 @@ impl Player {
4658 fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {4705 fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
4659 let (lane, idx) = self.silence_open?;4706 let (lane, idx) = self.silence_open?;
4660 let cfg = self.silence;4707 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+ };
4661 let rows = [4714 let rows = [
4662 ("Apply to", self.silence_scope.label(&self.silence_lanes())),4715 ("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)")),
4664 (4721 (
4665 "Forgive quiet shorter than",4722 "Forgive quiet shorter than",
4666 format!("{:.2} s", cfg.min_silence),4723 format!("{:.2} s", cfg.min_silence),
@@ -4759,7 +4816,7 @@ impl Player {
4759 .text_size(px(11.))4816 .text_size(px(11.))
4760 .text_color(rgb(INK_DIM))4817 .text_color(rgb(INK_DIM))
4761 .child(4818 .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",
4763 ),4820 ),
4764 )4821 )
4765 .children(rows)4822 .children(rows)
@@ -6252,6 +6309,39 @@ fn cancels_export(key: &str, action: Option<ActionId>) -> bool {
6252 key == ESCAPE || action == Some(ActionId::CancelExport)6309 key == ESCAPE || action == Some(ActionId::CancelExport)
6253 }6310 }
6254 6311
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+
6255 /// The keys that are only ever half a chord. gpui delivers a lone modifier6345 /// The keys that are only ever half a chord. gpui delivers a lone modifier
6256 /// press as a keystroke of its own, and taking one as a binding would leave an6346 /// press as a keystroke of its own, and taking one as a binding would leave an
6257 /// action that fires the moment the user reaches for any chord that uses it --6347 /// action that fires the moment the user reaches for any chord that uses it --
@@ -6882,7 +6972,7 @@ mod tests {
6882 silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths,6972 silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths,
6883 nothing_to_play, unseen_sources, whole_take, width_frac, window_title,6973 nothing_to_play, unseen_sources, whole_take, width_frac, window_title,
6884 };6974 };
6885- use super::{LaneKind, file_name, file_uri, library_rows, unscannable};6975+ use super::{LaneKind, Repeat, file_name, file_uri, library_rows, repeats, unscannable};
6886 6976
6887 /// What the file manager is handed: the parts a path keeps as they are, and6977 /// What the file manager is handed: the parts a path keeps as they are, and
6888 /// the ones the bus would otherwise read as something else.6978 /// the ones the bus would otherwise read as something else.
@@ -8390,11 +8480,47 @@ mod tests {
8390 );8480 );
8391 }8481 }
8392 8482
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+
8393 #[test]8519 #[test]
8394 fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() {8520 fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() {
8395 // The same 640x360 floor, and this card starts below the header: a8521 // 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 two8522+ // title and a hint over its [`SILENCE_ROWS`] rows, the count line and
8397- // buttons.8523+ // the two buttons.
8398 let (title, hint, count) = (17., 17., 17.);8524 let (title, hint, count) = (17., 17., 17.);
8399 let gaps = 6. * 5.;8525 let gaps = 6. * 5.;
8400 let padding = 24.;8526 let padding = 24.;
@@ -9004,6 +9130,9 @@ fn main() {
9004 // one a person can widen on purpose.9130 // one a person can widen on purpose.
9005 silence_scope: Scope::Take,9131 silence_scope: Scope::Take,
9006 silence_field: 0,9132 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,
9007 silence_marks: Vec::new(),9136 silence_marks: Vec::new(),
9008 silence_levels: None,9137 silence_levels: None,
9009 color_open: None,9138 color_open: None,