finer control of global volume at low values

This commit is contained in:
Crispy 2023-01-28 21:58:30 +01:00
parent 39eedfc5f4
commit 2147fb910c

View file

@ -96,7 +96,7 @@ impl App {
self.sink.append(snoud); self.sink.append(snoud);
self.sink.play(); self.sink.play();
self.change_vol(0); self.sync_vol();
terminal::enable_raw_mode().unwrap(); terminal::enable_raw_mode().unwrap();
stdout().execute(Clear(ClearType::All)).unwrap(); stdout().execute(Clear(ClearType::All)).unwrap();
@ -116,7 +116,7 @@ impl App {
println!("Snoud - ambient sound player\r"); println!("Snoud - ambient sound player\r");
println!( println!(
"Master volume: {:3}%, {:10}\n\r", "Master volume: {:3}% {:10}\n\r",
self.volume, self.volume,
if self.playing { if self.playing {
"[Playing]" "[Playing]"
@ -158,8 +158,8 @@ impl App {
KeyCode::Left => self.channels[self.selected].change_vol(-10), KeyCode::Left => self.channels[self.selected].change_vol(-10),
KeyCode::Char('m') => self.channels[self.selected].mute(), KeyCode::Char('m') => self.channels[self.selected].mute(),
KeyCode::Char(' ') => self.mute(), KeyCode::Char(' ') => self.mute(),
KeyCode::Char('.') => self.change_vol(5), KeyCode::Char('.') => self.inc_vol(),
KeyCode::Char(',') => self.change_vol(-5), KeyCode::Char(',') => self.dec_vol(),
_ => (), _ => (),
} }
} }
@ -175,8 +175,26 @@ impl App {
self.selected = (self.selected + 1) % self.channels.len(); self.selected = (self.selected + 1) % self.channels.len();
} }
fn change_vol(&mut self, amount: i32) { fn inc_vol(&mut self) {
self.volume += amount; if self.volume < 15 {
self.volume += 1;
} else {
self.volume += 5;
}
self.sync_vol();
}
fn dec_vol(&mut self) {
if self.volume <= 15 {
self.volume -= 1;
} else {
self.volume -= 5;
}
self.sync_vol();
}
fn sync_vol(&mut self) {
self.volume = self.volume.clamp(0, 150);
self.sink.set_volume(self.volume as f32 / 100.0); self.sink.set_volume(self.volume as f32 / 100.0);
} }