From 6411d40b96aa36598551017b2986fe6fdf757c62 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Thu, 3 Feb 2022 17:04:01 -0500 Subject: [PATCH] Add volume option to CLI args --- src/cli.rs | 4 ++++ src/main.rs | 7 ++++++- src/repl.rs | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index a26aa8e..ac2d3a3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -18,6 +18,10 @@ pub struct CliArgs { /// In REPL mode, the prompt to display #[clap(long, default_value_t = String::from("|"))] pub prompt: String, + + /// The volume at which to playback audio, out of 1.0 + #[clap(long)] + pub volume: Option, } pub fn parse() -> CliArgs { diff --git a/src/main.rs b/src/main.rs index c86a4ca..e3f4dc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,7 @@ fn main() { } // build playback controller let script_file2 = script_file.clone(); + let volume = args.volume.clone(); let player_builder = move || { let script_reader = io::BufReader::new( std::fs::File::open(&script_file2) @@ -65,7 +66,11 @@ fn main() { ); let runner = MpsRunner::with_stream(script_reader); - MpsPlayer::new(runner).unwrap() + let player = MpsPlayer::new(runner).unwrap(); + if let Some(vol) = volume { + player.set_volume(vol); + } + player }; if let Some(playlist_file) = &args.playlist { // generate playlist diff --git a/src/repl.rs b/src/repl.rs index f9c129e..2240fea 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -35,10 +35,15 @@ pub fn repl(args: CliArgs) { terminal.c_lflag &= !termios::ICANON; // no echo and canonical mode termios::tcsetattr(0, termios::TCSANOW, &mut terminal).unwrap();*/ let (writer, reader) = channel_io(); + let volume = args.volume.clone(); let player_builder = move || { let runner = MpsRunner::with_stream(reader); - MpsPlayer::new(runner).unwrap() + let player = MpsPlayer::new(runner).unwrap(); + if let Some(vol) = volume { + player.set_volume(vol); + } + player }; let mut state = ReplState::new(writer); if let Some(playlist_file) = &args.playlist {