Add volume option to CLI args
This commit is contained in:
parent
5af9311887
commit
6411d40b96
3 changed files with 16 additions and 2 deletions
|
@ -18,6 +18,10 @@ pub struct CliArgs {
|
||||||
/// In REPL mode, the prompt to display
|
/// In REPL mode, the prompt to display
|
||||||
#[clap(long, default_value_t = String::from("|"))]
|
#[clap(long, default_value_t = String::from("|"))]
|
||||||
pub prompt: String,
|
pub prompt: String,
|
||||||
|
|
||||||
|
/// The volume at which to playback audio, out of 1.0
|
||||||
|
#[clap(long)]
|
||||||
|
pub volume: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse() -> CliArgs {
|
pub fn parse() -> CliArgs {
|
||||||
|
|
|
@ -58,6 +58,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
// build playback controller
|
// build playback controller
|
||||||
let script_file2 = script_file.clone();
|
let script_file2 = script_file.clone();
|
||||||
|
let volume = args.volume.clone();
|
||||||
let player_builder = move || {
|
let player_builder = move || {
|
||||||
let script_reader = io::BufReader::new(
|
let script_reader = io::BufReader::new(
|
||||||
std::fs::File::open(&script_file2)
|
std::fs::File::open(&script_file2)
|
||||||
|
@ -65,7 +66,11 @@ fn main() {
|
||||||
);
|
);
|
||||||
let runner = MpsRunner::with_stream(script_reader);
|
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 {
|
if let Some(playlist_file) = &args.playlist {
|
||||||
// generate playlist
|
// generate playlist
|
||||||
|
|
|
@ -35,10 +35,15 @@ pub fn repl(args: CliArgs) {
|
||||||
terminal.c_lflag &= !termios::ICANON; // no echo and canonical mode
|
terminal.c_lflag &= !termios::ICANON; // no echo and canonical mode
|
||||||
termios::tcsetattr(0, termios::TCSANOW, &mut terminal).unwrap();*/
|
termios::tcsetattr(0, termios::TCSANOW, &mut terminal).unwrap();*/
|
||||||
let (writer, reader) = channel_io();
|
let (writer, reader) = channel_io();
|
||||||
|
let volume = args.volume.clone();
|
||||||
let player_builder = move || {
|
let player_builder = move || {
|
||||||
let runner = MpsRunner::with_stream(reader);
|
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);
|
let mut state = ReplState::new(writer);
|
||||||
if let Some(playlist_file) = &args.playlist {
|
if let Some(playlist_file) = &args.playlist {
|
||||||
|
|
Loading…
Reference in a new issue