From de2b4cc8e38ab33d440e60d822d8833ba9602b8c Mon Sep 17 00:00:00 2001 From: fossedihelm Date: Thu, 7 Dec 2017 11:36:26 +0100 Subject: [PATCH] added comments and edited README --- README.md | 1 + src/main.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7a20ddc..f288d2b7 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ target/release/librespot --username USERNAME --cache CACHEDIR --name DEVICENAME | Option | | backend | Audio backend to use. Use '?' to list options | BACKEND | | Option | | device | Audio device to use. Use '?' to list options | DEVICE | | Option | | mixer | Mixer to use | MIXER | +| Option | | initial-volume | Initial volume in %, once connected [0-100] | VOLUME | Taken from here: https://github.com/ComlOnline/librespot/blob/master/src/main.rs#L88 diff --git a/src/main.rs b/src/main.rs index 6bc7d5df..c6208f2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,27 +135,32 @@ fn setup(args: &[String]) -> Setup { let mixer = mixer::find(mixer_name.as_ref()) .expect("Invalid mixer"); let initial_volume; + // check if initial-volume argument is present if matches.opt_present("initial-volume"){ + // check if value is a number if matches.opt_str("initial-volume").unwrap().parse::().is_ok(){ + // check if value is in [0-100] range, otherwise put the bound values if matches.opt_str("initial-volume").unwrap().parse::().unwrap() < 0 { initial_volume = 0 as i32; } else if matches.opt_str("initial-volume").unwrap().parse::().unwrap() > 100{ initial_volume = 0xFFFF as i32; } + // checks ok else{ initial_volume = matches.opt_str("initial-volume").unwrap().parse::().unwrap()* 0xFFFF as i32 / 100 ; } - } + // if value is not a number use default value (50%) else { initial_volume = 0x8000 as i32; } } + // if argument not present use default values (50%) else{ initial_volume = 0x8000 as i32; } - info!("Volume \"{}\" !", initial_volume); + debug!("Volume \"{}\" !", initial_volume); let name = matches.opt_str("name").unwrap(); let use_audio_cache = !matches.opt_present("disable-audio-cache");