app: unmute the review player and add a volume control

rune starts a video muted and the review never told it otherwise, so every
recording played silent however loud its audio track was. The player now
unmutes at eight tenths, and the transport bar has Mute/Unmute and a
slider beside the clock.

The level carries from one recording to the next, since a viewer sets it
once.
This commit is contained in:
vhaudiquet committed 2026-11-18 19:48:22 +01:00
1 parent 543b489b11
commit 1e7e9dfc41
2 files changed
+91 -2

No files matched your search

+78 -1
View File
@@ -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<Timeline>,
@@ -25,10 +24,38 @@ pub struct Review {
pub highlights: Vec<Highlight>,
pub export: Option<Receiver<Result<String, String>>>,
pub export_note: Option<String>,
/// 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<String>,
}
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(
+13 -1
View File
@@ -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<String>,
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;