Add volume option to CLI args

This commit is contained in:
NGnius (Graham) 2022-02-03 17:04:01 -05:00
parent 5af9311887
commit 6411d40b96
3 changed files with 16 additions and 2 deletions

View file

@ -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<f32>,
}
pub fn parse() -> CliArgs {

View file

@ -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

View file

@ -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 {