diff --git a/app/src/screens/review.rs b/app/src/screens/review.rs index 4a20f3e..7e08ec8 100644 --- a/app/src/screens/review.rs +++ b/app/src/screens/review.rs @@ -11,7 +11,6 @@ use crate::highlight::{self, Highlight}; use crate::history::{self, Outcome, Timeline}; use crate::ui::{self, Paint, body, heading}; -#[derive(Default)] pub struct Review { /// The opened recording, once its file has been read. pub game: Option, @@ -25,10 +24,38 @@ pub struct Review { pub highlights: Vec, pub export: Option>>, pub export_note: Option, + /// Player gain, 0 to 1. Rune starts a video muted, so the review unmutes its own player. + pub volume: f32, + pub muted: bool, pub error: Option, } impl Review { + /// A new player takes the volume and the mute the last one had: a viewer sets them once. + pub fn apply_sound(&self, player: &Player) { + player.set_volume(self.volume); + player.set_muted(self.muted); + } + + /// Set the gain from the transport bar. Sliding off zero is also how a viewer unmutes. + pub fn set_volume(&mut self, volume: f32) { + self.volume = volume.clamp(0.0, 1.0); + if self.volume > 0.0 { + self.muted = false; + } + if let Some(player) = &self.player { + player.set_volume(self.volume); + player.set_muted(self.muted); + } + } + + pub fn toggle_muted(&mut self) { + self.muted = !self.muted; + if let Some(player) = &self.player { + player.set_muted(self.muted); + } + } + fn playback(&mut self) { if let Some(player) = &self.player { if player.is_playing() { @@ -48,6 +75,28 @@ impl Review { } } +impl Default for Review { + fn default() -> Self { + Self { + game: None, + loading: false, + player: None, + time: 0.0, + duration: 0.0, + scrubber_width: 0.0, + highlights: Vec::new(), + show_details: false, + export: None, + export_note: None, + error: None, + // Rune plays a video muted, so the review has to unmute. Eight tenths leaves + // headroom, and the transport bar can change it. + volume: 0.8, + muted: false, + } + } +} + /// Open a recording in the review screen. /// /// Only the id travels here: the timeline with its events and raw responses is a large file @@ -91,6 +140,7 @@ pub fn show(app: &mut App, game: Timeline) { if let Some(waker) = &app.waker { player.set_waker(waker.clone()); } + app.review.apply_sound(&player); app.review.player = Some(player); } @@ -306,6 +356,32 @@ fn video_stage(app: &App, p: Paint) -> El { } } +/// Mute and gain. Rune plays a video muted until told otherwise, so these are the only way to +/// hear a recording; the settings carry over to the next one opened. +fn volume(app: &App, p: Paint) -> El { + let percent = (app.review.volume * 100.0).round() as u32; + let muted = app.review.muted || percent == 0; + row() + .key("volume") + .center_y() + .gap(space::S2) + .child(ui::button( + p, + "mute", + if muted { "Unmute" } else { "Mute" }, + false, + |app: &mut App| app.review.toggle_muted(), + )) + .child(ui::slider_width( + p, + "volume", + "Volume", + 110.0, + percent, + |app, value| app.review.set_volume(value as f32 / 100.0), + )) +} + /// Play/pause, the ten-second steps and the clock, with the highlights toggle on the other /// side: the list is one press away, not a column that always takes the clip's width. fn transport(app: &App, p: Paint) -> El { @@ -342,6 +418,7 @@ fn transport(app: &App, p: Paint) -> El { .font(type_::MONO_CAPTION) .color(p.muted()), ) + .child(volume(app, p)) .child(el().grow(1.0)); let bar = match &app.review.export_note { Some(note) => bar.child( diff --git a/app/src/ui.rs b/app/src/ui.rs index b6c2769..27eb4ac 100644 --- a/app/src/ui.rs +++ b/app/src/ui.rs @@ -203,9 +203,21 @@ pub fn slider( label: &'static str, value: u32, on_change: impl Fn(&mut App, u32) + Send + Sync + 'static, +) -> El { + slider_width(p, key, label, 180.0, value, on_change) +} + +/// [`slider`] at a given width, for the player bar where 180 points is too much. +pub fn slider_width( + p: Paint, + key: impl Into, + label: &'static str, + width: f32, + value: u32, + on_change: impl Fn(&mut App, u32) + Send + Sync + 'static, ) -> El { let key = key.into(); - let (w, h, k, bar) = (180.0, 22.0, 18.0, 4.0); + let (w, h, k, bar) = (width, 22.0, 18.0, 4.0); let travel = w - k; let v = (value.min(100) as f32 / 100.0).clamp(0.0, 1.0); let to_value = move |x: f32| (((x - k / 2.0) / travel).clamp(0.0, 1.0) * 100.0).round() as u32;