diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index d9245b5..638603b 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -1836,6 +1836,17 @@ impl Player { "c" => self.cycle_export_picture(), "b" => self.cycle_audio_kbps(), "g" => self.cycle_encoder(cx), + // The Level row's own three, and they have to be *here*: + // this page counts as a card in [`Self::card_open`], so a + // stroke that falls through this branch is swallowed by the + // darkroom's modal guard rather than reaching the keymap -- + // `m` did nothing at all with the page up (caught in the + // harness, not by a guard). Same setter the keymap's + // [`ActionId::ToggleMute`]/`VolumeUp`/`VolumeDown` call, so + // the row cannot drift from the chord it wears. + "m" => self.set_volume(|volume| volume.muted = !volume.muted, cx), + "=" => self.set_volume(|volume| volume.step(true), cx), + "-" => self.set_volume(|volume| volume.step(false), cx), _ => return false, } return true; diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index a201713..adc84da 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2564,18 +2564,6 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { ActionId::Loop, "KEYS tab + key: the loop toggle left the band in cleanse round 2", ), - ( - ActionId::ToggleMute, - "KEYS tab + key: the monitoring cluster left the band in cleanse round 2", - ), - ( - ActionId::VolumeUp, - "KEYS tab + key: the monitoring cluster left the band in cleanse round 2", - ), - ( - ActionId::VolumeDown, - "KEYS tab + key: the monitoring cluster left the band in cleanse round 2", - ), ( ActionId::ClearRange, "KEYS tab + key: `I O ×` left the band in cleanse round 2 -- in and out \ @@ -3914,3 +3902,103 @@ fn no_region_root_wears_a_focus_ring() { } } } + + +/// The monitoring level's home. Cleanse round 2 took the mute button, the +/// `- +` pair and the slider off the time band on the promise that the level +/// "lives in Settings" (DESIGN 5) -- a promise nothing kept until this row, +/// which is why the volume trio sat in +/// [`every_action_has_a_darkroom_widget_home_or_explicit_owner`]'s exemption +/// list. A source scan, like every other guard on this page: the EDITOR +/// section carries the row, the row wears the mute chord (`m`), and the wheel +/// over it moves the level through the very actions the keys do -- no second +/// setter, no slider growing back. +#[test] +fn the_editor_section_owns_the_monitoring_level_row() { + let source = src_text("ui/settings_stance.rs"); + let editor_start = source + .find("fn editor_section(") + .expect("the editor section"); + let render_start = source + .find("pub(crate) fn render(") + .expect("the page's render fn"); + let editor_body = &source[editor_start..render_start]; + for needle in [ + "\"settings-level\"", + "\"Level\"", + "ActionId::ToggleMute", + "ActionId::VolumeUp", + "ActionId::VolumeDown", + ".on_scroll_wheel(", + ] { + assert!( + editor_body.contains(needle), + "the EDITOR section's Level row is missing {needle}" + ); + } + // The chord the row draws is the keymap's own, so the badge reads `m` + // wherever this test's reader looks for it. + assert_eq!( + crate::keymap::Keymap::defaults().chord(crate::ActionId::ToggleMute), + "m", + "the mute chord moved -- the Level row's badge is no longer `m`" + ); + // Muted reads as a word in the quieter ink, never as `0%`: the level is + // what unmuting comes back to and the row must not lie about it. + assert!( + editor_body.contains("\"muted\".to_string()"), + "the Level row must say `muted` rather than a number when silenced" + ); + // A readout, not a widget: the slider stayed dead (DESIGN 5). + assert!( + !editor_body.contains("volume_bar") && !editor_body.contains("drag_volume"), + "the level slider grew back in Settings" + ); + // The page counts as a card ([`Player::card_open`]), so the darkroom's + // modal guard eats every stroke this branch does not answer: without + // these three arms the row wears a chord that does nothing while the page + // is the visible thing on screen (what the first harness run showed). + let cards = src_text("player/cards.rs"); + let branch_start = cards + .find("if self.settings_open {") + .expect("the settings key branch"); + let branch = &cards[branch_start..(branch_start + 1600).min(cards.len())]; + for arm in ["\"m\" =>", "\"=\" =>", "\"-\" =>"] { + assert!( + branch.contains(arm), + "the settings key branch does not answer {arm} -- the Level row's \ + chord is swallowed by the modal guard while the page is up" + ); + } +} + +/// The wheel's own arithmetic: one notch is one key press (5%), and the count +/// stops at both ends rather than wrapping silence into full volume -- the +/// saturating pair [`Volume::step`] is written for. Pure, so it runs without +/// a window. +#[test] +fn the_level_wheel_steps_five_percent_and_clamps_at_both_ends() { + use crate::transport::Volume; + let mut volume = Volume::default(); + assert_eq!(volume.percent(), 100); + for expected in [95, 90, 85, 80] { + volume.step(false); + assert_eq!(volume.percent(), expected, "a notch down is 5%"); + } + for _ in 0..40 { + volume.step(false); + } + assert_eq!(volume.percent(), 0, "the level floors at silence"); + volume.step(false); + assert_eq!(volume.percent(), 0, "a notch below silence is silence"); + for _ in 0..40 { + volume.step(true); + } + assert_eq!(volume.percent(), 100, "the level ceilings at full"); + volume.step(true); + assert_eq!(volume.percent(), 100, "a notch above full is full"); + // Turning it down while muted is not what makes sound come out. + volume.muted = true; + volume.step(false); + assert!(volume.muted && volume.percent() == 95); +} diff --git a/crates/app/src/transport.rs b/crates/app/src/transport.rs index 1a327d5..ec974a5 100644 --- a/crates/app/src/transport.rs +++ b/crates/app/src/transport.rs @@ -77,12 +77,19 @@ impl Volume { f32::from(self.steps) / f32::from(Self::MAX_STEPS) } + /// The level as a number to read out, 0..=100 -- what the settings page's + /// Level row says (`100%`), the one place the level is written since the + /// time band lost its slider. + pub(crate) fn percent(self) -> u32 { + u32::from(self.steps) * 100 / u32::from(Self::MAX_STEPS) + } + /// What the button read before the mute state became a glyph and a colour /// ([`Player::toolbar`]): the guards still hold the wording to it, so it /// sits with them rather than in the binary. #[cfg(test)] pub(crate) fn label(self) -> String { - let percent = u32::from(self.steps) * 100 / u32::from(Self::MAX_STEPS); + let percent = self.percent(); if self.muted { format!("Muted {percent}%") } else { diff --git a/crates/app/src/ui/settings_stance.rs b/crates/app/src/ui/settings_stance.rs index 82a272f..a871388 100644 --- a/crates/app/src/ui/settings_stance.rs +++ b/crates/app/src/ui/settings_stance.rs @@ -406,6 +406,59 @@ fn editor_section(player: &Player, cx: &mut Context) -> impl IntoElement .flex_col() .gap(px(2.)) .child(section_head("EDITOR · this machine, this window")) + // The monitoring level, which lost its slider when the time band was + // cleansed (DESIGN §5 -- "the level lives in Settings"). A readout and + // not a widget: the number is spent rarely, so the wheel over the row + // moves it and `m` silences it, exactly what the keys already do + // ([`ActionId::VolumeUp`]/[`ActionId::VolumeDown`] reach the same + // setter while this page is up, since the settings key branch passes + // every stroke but its own three through to the keymap). Session-only: + // nothing in ~/.config/edith holds a level, and a muted window that + // stayed muted across a launch is a bug report, not a preference. + .child( + div() + .id("settings-level-wheel") + .flex_none() + .on_scroll_wheel(cx.listener( + |this, event: &ScrollWheelEvent, window, cx| { + let by = wheel_delta(event); + if by == 0. { + return; + } + // One notch is one press: the wheel lands on the same + // 5% grid the keys do, never a second finer one. + this.act( + if by > 0. { + ActionId::VolumeUp + } else { + ActionId::VolumeDown + }, + window, + cx, + ); + cx.stop_propagation(); + }, + )) + .child(row_full( + "settings-level", + "Level", + match player.volume.muted { + true => "muted".to_string(), + false => format!("{}%", player.volume.percent()), + }, + "Monitoring level -- the wheel over this row moves it 5% at a time; kept for this window, never written into a project", + Some(player.keymap.chord(ActionId::ToggleMute).into()), + None, + player, + cx.listener(|this, _: &ClickEvent, _, cx| { + this.set_volume(|volume| volume.muted = !volume.muted, cx) + }), + match player.volume.muted { + true => INK3(), + false => INK1(), + }, + )), + ) .child(row_keyed( "settings-proxies", "Proxies",