Browse and listen to thousands of radio stations across the globe right from your terminal ๐ŸŒŽ ๐Ÿ“ป ๐ŸŽตโœจ
radio rust tokio web-radio command-line-tool tui
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

app: Volume

+51 -1
+51 -1
src/app.rs
··· 6 6 use std::{ 7 7 io, 8 8 ops::Range, 9 - process, 10 9 sync::{mpsc::Receiver, Arc, Mutex}, 11 10 thread, 12 11 time::{Duration, Instant}, ··· 31 30 pub genre: String, 32 31 pub description: String, 33 32 pub br: String, 33 + } 34 + 35 + /// Volume of the player. 36 + #[derive(Debug, Clone, PartialEq)] 37 + pub struct Volume { 38 + /// Raw volume. 39 + volume: f32, 40 + /// Is muted? 41 + is_muted: bool, 42 + } 43 + 44 + impl Volume { 45 + /// Create a new [`Volume`]. 46 + pub const fn new(volume: f32, is_muted: bool) -> Self { 47 + Self { volume, is_muted } 48 + } 49 + 50 + /// Get the current volume. Returns `0.0` if muted. 51 + pub const fn volume(&self) -> f32 { 52 + if self.is_muted { 53 + 0.0 54 + } else { 55 + 1.0 56 + } 57 + } 58 + 59 + /// Is volume muted? 60 + pub const fn is_muted(&self) -> bool { 61 + self.is_muted 62 + } 63 + 64 + /// Toggle mute. 65 + pub const fn toggle_mute(&mut self) { 66 + self.is_muted = !self.is_muted; 67 + } 68 + 69 + /// Change the volume by the given step. 70 + /// 71 + /// To increase the volume, use a positive step. To decrease the 72 + /// volume, use a negative step. 73 + pub const fn change_volume(&mut self, step: f32) { 74 + self.volume += step; 75 + // limit to 0 volume, no upper bound 76 + self.volume = self.volume.max(0.0); 77 + } 78 + } 79 + 80 + impl Default for Volume { 81 + fn default() -> Self { 82 + Self::new(1.0, false) 83 + } 34 84 } 35 85 36 86 pub enum CurrentDisplayMode {