mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-06 03:50:06 +02:00
Cache volume across restarts (#220)
* create Volume struct for use with Cache * add "volume" file to Cache * load cached volume on start, intial overrides cached overrides default * amend volume_to_mixer function to cache the volume on every change * pass cache to Spirc and SpircTask so volume_to_mixer has access * rustfmt changes * revert volume_to_mixer function and Spirc/SpircTask cache variable * Volume implements Copy, pass by value instead of reference * clamp volume to 100 if cached value exceeds limit * convert Volume to u16 internally, use float and round to convert hex->dec * convert initial_volume and ConnectConfig.volume to u16 as well * add cache_volume function to SpircTask * remove conversion to/from percentage on cached volume * consolidate device.set_volume, mixer.set_volume, and caching * streamline intial volume logic
This commit is contained in:
parent
21f1ccfb5a
commit
d40c0f50db
8 changed files with 84 additions and 26 deletions
18
src/main.rs
18
src/main.rs
|
@ -204,15 +204,22 @@ fn setup(args: &[String]) -> Setup {
|
|||
let mixer_name = matches.opt_str("mixer");
|
||||
let mixer = mixer::find(mixer_name.as_ref()).expect("Invalid mixer");
|
||||
|
||||
let use_audio_cache = !matches.opt_present("disable-audio-cache");
|
||||
|
||||
let cache = matches
|
||||
.opt_str("c")
|
||||
.map(|cache_location| Cache::new(PathBuf::from(cache_location), use_audio_cache));
|
||||
|
||||
let initial_volume = matches
|
||||
.opt_str("initial-volume")
|
||||
.map(|volume| {
|
||||
let volume = volume.parse::<i32>().unwrap();
|
||||
if volume < 0 || volume > 100 {
|
||||
let volume = volume.parse::<u16>().unwrap();
|
||||
if volume > 100 {
|
||||
panic!("Initial volume must be in the range 0-100");
|
||||
}
|
||||
volume * 0xFFFF / 100
|
||||
(volume as i32 * 0xFFFF / 100) as u16
|
||||
})
|
||||
.or_else(|| cache.as_ref().and_then(Cache::volume))
|
||||
.unwrap_or(0x8000);
|
||||
|
||||
let zeroconf_port = matches
|
||||
|
@ -221,11 +228,6 @@ fn setup(args: &[String]) -> Setup {
|
|||
.unwrap_or(0);
|
||||
|
||||
let name = matches.opt_str("name").unwrap();
|
||||
let use_audio_cache = !matches.opt_present("disable-audio-cache");
|
||||
|
||||
let cache = matches
|
||||
.opt_str("c")
|
||||
.map(|cache_location| Cache::new(PathBuf::from(cache_location), use_audio_cache));
|
||||
|
||||
let credentials = {
|
||||
let cached_credentials = cache.as_ref().and_then(Cache::credentials);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue