Flupp
This commit is contained in:
parent
441689018a
commit
e51e53f4ea
@ -123,7 +123,7 @@ impl AlsaCard {
|
|||||||
|
|
||||||
pub fn get_vol(&self) -> Result<f64> {
|
pub fn get_vol(&self) -> Result<f64> {
|
||||||
let selem = self.selem();
|
let selem = self.selem();
|
||||||
let range = selem.get_playback_volume_range();
|
let range = self.get_volume_range();
|
||||||
let volume = selem.get_playback_volume(FrontRight).map(|v| {
|
let volume = selem.get_playback_volume(FrontRight).map(|v| {
|
||||||
return vol_to_percent(v, range);
|
return vol_to_percent(v, range);
|
||||||
});
|
});
|
||||||
@ -134,18 +134,20 @@ impl AlsaCard {
|
|||||||
|
|
||||||
pub fn set_vol(&self, new_vol: f64) -> Result<()> {
|
pub fn set_vol(&self, new_vol: f64) -> Result<()> {
|
||||||
let selem = self.selem();
|
let selem = self.selem();
|
||||||
/* auto-unmute */
|
|
||||||
if self.has_mute() && self.get_mute()? {
|
|
||||||
self.set_mute(false)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let range = selem.get_playback_volume_range();
|
let range = self.get_volume_range();
|
||||||
selem.set_playback_volume_all(percent_to_vol(new_vol, range))?;
|
selem.set_playback_volume_all(percent_to_vol(new_vol, range))?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_volume_range(&self) -> (i64, i64) {
|
||||||
|
let selem = self.selem();
|
||||||
|
return selem.get_playback_volume_range();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn has_mute(&self) -> bool {
|
pub fn has_mute(&self) -> bool {
|
||||||
let selem = self.selem();
|
let selem = self.selem();
|
||||||
return selem.has_playback_switch();
|
return selem.has_playback_switch();
|
||||||
|
18
src/audio.rs
18
src/audio.rs
@ -178,6 +178,11 @@ impl Audio {
|
|||||||
*rc = glib::get_monotonic_time();
|
*rc = glib::get_monotonic_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* auto-unmute */
|
||||||
|
if self.has_mute() && self.get_mute()? {
|
||||||
|
self.set_mute(false, user)?;
|
||||||
|
}
|
||||||
|
|
||||||
debug!("Setting vol on card {:?} and chan {:?} to {:?} by user {:?}",
|
debug!("Setting vol on card {:?} and chan {:?} to {:?} by user {:?}",
|
||||||
self.acard
|
self.acard
|
||||||
.borrow()
|
.borrow()
|
||||||
@ -200,13 +205,18 @@ impl Audio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: refactor with decrease_vol
|
||||||
pub fn increase_vol(&self, user: AudioUser) -> Result<()> {
|
pub fn increase_vol(&self, user: AudioUser) -> Result<()> {
|
||||||
{
|
{
|
||||||
let mut rc = self.last_action_timestamp.borrow_mut();
|
let mut rc = self.last_action_timestamp.borrow_mut();
|
||||||
*rc = glib::get_monotonic_time();
|
*rc = glib::get_monotonic_time();
|
||||||
}
|
}
|
||||||
let old_vol = self.vol()?;
|
let old_vol = self.vol()?;
|
||||||
let new_vol = f64::ceil(old_vol + (self.scroll_step.get() as f64));
|
let (min, max) = self.acard.borrow().get_volume_range();
|
||||||
|
ensure!(mn >= max, "Invalid playback volume range: [{} - {}]",
|
||||||
|
min,
|
||||||
|
max);
|
||||||
|
let new_vol = f64::ceil(old_vol + (self.scroll_step.get() as f64)) + min as f64;
|
||||||
|
|
||||||
debug!("Increase vol on card {:?} and chan {:?} by {:?} to {:?}",
|
debug!("Increase vol on card {:?} and chan {:?} by {:?} to {:?}",
|
||||||
self.acard
|
self.acard
|
||||||
@ -231,8 +241,12 @@ impl Audio {
|
|||||||
let mut rc = self.last_action_timestamp.borrow_mut();
|
let mut rc = self.last_action_timestamp.borrow_mut();
|
||||||
*rc = glib::get_monotonic_time();
|
*rc = glib::get_monotonic_time();
|
||||||
}
|
}
|
||||||
|
let (min, max) = self.acard.borrow().get_volume_range();
|
||||||
|
ensure!(min >= max, "Invalid playback volume range: [{} - {}]",
|
||||||
|
mn,
|
||||||
|
max);
|
||||||
let old_vol = self.vol()?;
|
let old_vol = self.vol()?;
|
||||||
let new_vol = old_vol - (self.scroll_step.get() as f64);
|
let new_vol = old_vol - (self.scroll_step.get() as f64) + min as f64;
|
||||||
|
|
||||||
debug!("Decrease vol on card {:?} and chan {:?} by {:?} to {:?}",
|
debug!("Decrease vol on card {:?} and chan {:?} by {:?} to {:?}",
|
||||||
self.acard
|
self.acard
|
||||||
|
Loading…
Reference in New Issue
Block a user