From 863ea9c976235f28c086fb50baf99b3f08099f13 Mon Sep 17 00:00:00 2001 From: ComlOnline Date: Tue, 30 Jan 2018 20:52:25 +0000 Subject: [PATCH 1/4] removed and optimised --- src/main.rs | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index 85131ee9..cccfb268 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,33 +132,19 @@ fn setup(args: &[String]) -> Setup { let mixer_name = matches.opt_str("mixer"); 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; + if matches.opt_present("initial-volume") && matches.opt_str("initial-volume").unwrap().parse::().is_ok() { + let iv = matches.opt_str("zeroconf-port").unwrap().parse::().unwrap(); + if iv => 0 && iv <= 100 { + initial_volume = iv * 0xFFFF as i32 / 100 ; + } else { + debug!("Volume needs to be a value from 0-100; set as 50%"); + initial_volume = 0x8000 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 { + } else { initial_volume = 0x8000 as i32; } - } - // if argument not present use default values (50%) - else{ - initial_volume = 0x8000 as i32; - } - debug!("Volume \"{}\" !", initial_volume); let name = matches.opt_str("name").unwrap(); let use_audio_cache = !matches.opt_present("disable-audio-cache"); From 46de5a704b08d42a8d57b62ef103f0529c0195af Mon Sep 17 00:00:00 2001 From: ComlOnline Date: Tue, 30 Jan 2018 21:30:37 +0000 Subject: [PATCH 2/4] Thats what I get for copypasta --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index cccfb268..45c5ec87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,8 +135,8 @@ fn setup(args: &[String]) -> Setup { let initial_volume; if matches.opt_present("initial-volume") && matches.opt_str("initial-volume").unwrap().parse::().is_ok() { - let iv = matches.opt_str("zeroconf-port").unwrap().parse::().unwrap(); - if iv => 0 && iv <= 100 { + let matches.opt_str("initial-volume").unwrap().parse::().unwrap(); + if 0 <= iv && iv <= 100 { initial_volume = iv * 0xFFFF as i32 / 100 ; } else { debug!("Volume needs to be a value from 0-100; set as 50%"); From 618eceb740113d25d58977f941e4a8ef2ce81481 Mon Sep 17 00:00:00 2001 From: ComlOnline Date: Tue, 30 Jan 2018 21:46:57 +0000 Subject: [PATCH 3/4] lost `iv -` due to previous --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 45c5ec87..499bb613 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,7 +135,7 @@ fn setup(args: &[String]) -> Setup { let initial_volume; if matches.opt_present("initial-volume") && matches.opt_str("initial-volume").unwrap().parse::().is_ok() { - let matches.opt_str("initial-volume").unwrap().parse::().unwrap(); + let iv = matches.opt_str("initial-volume").unwrap().parse::().unwrap(); if 0 <= iv && iv <= 100 { initial_volume = iv * 0xFFFF as i32 / 100 ; } else { From fddcbbcd8261563009436e9444275913317c0711 Mon Sep 17 00:00:00 2001 From: Sasha Hilton Date: Wed, 31 Jan 2018 00:05:54 +0100 Subject: [PATCH 4/4] Tidied up Syntax --- src/main.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 499bb613..1ca16165 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,19 +132,20 @@ fn setup(args: &[String]) -> Setup { let mixer_name = matches.opt_str("mixer"); let mixer = mixer::find(mixer_name.as_ref()) .expect("Invalid mixer"); - - let initial_volume; - if matches.opt_present("initial-volume") && matches.opt_str("initial-volume").unwrap().parse::().is_ok() { - let iv = matches.opt_str("initial-volume").unwrap().parse::().unwrap(); - if 0 <= iv && iv <= 100 { - initial_volume = iv * 0xFFFF as i32 / 100 ; - } else { - debug!("Volume needs to be a value from 0-100; set as 50%"); - initial_volume = 0x8000 as i32; + + let initial_volume: i32; + if matches.opt_present("initial-volume") && matches.opt_str("initial-volume").unwrap().parse::().is_ok() { + let iv = matches.opt_str("initial-volume").unwrap().parse::().unwrap(); + match iv { + iv if iv >= 0 && iv <= 100 => { initial_volume = iv * 0xFFFF / 100 } + _ => { + debug!("Volume needs to be a value from 0-100; set volume level to 50%"); + initial_volume = 0x8000; } - } else { - initial_volume = 0x8000 as i32; } + } else { + initial_volume = 0x8000; + } let name = matches.opt_str("name").unwrap(); let use_audio_cache = !matches.opt_present("disable-audio-cache");