Select mixer dynamically

This commit is contained in:
Daniel Romero 2017-01-25 22:49:18 +01:00
parent 464e85e285
commit 6df2af0ac9
2 changed files with 15 additions and 5 deletions

View file

@ -18,8 +18,7 @@ use librespot::audio_backend::{self, BACKENDS};
use librespot::cache::{Cache, DefaultCache, NoCache};
use librespot::player::Player;
use librespot::session::{Bitrate, Config, Session};
use librespot::mixer::softmixer::SoftMixer;
use librespot::mixer::Mixer;
use librespot::mixer::{self, Mixer};
use librespot::version;
@ -73,7 +72,8 @@ fn setup(args: &[String]) -> (Session, Player, Box<Mixer + Send>) {
.optopt("u", "username", "Username to sign in with", "USERNAME")
.optopt("p", "password", "Password", "PASSWORD")
.optopt("", "backend", "Audio backend to use. Use '?' to list options", "BACKEND")
.optopt("", "device", "Audio device to use. Use '?' to list options", "DEVICE");
.optopt("", "device", "Audio device to use. Use '?' to list options", "DEVICE")
.optopt("", "mixer", "Mixer to use", "MIXER");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
@ -123,14 +123,17 @@ fn setup(args: &[String]) -> (Session, Player, Box<Mixer + Send>) {
matches.opt_str("password"));
session.login(credentials).unwrap();
let mixer = SoftMixer::new();
let mixer_name = matches.opt_str("mixer").unwrap_or("SoftMixer".to_owned());
let mixer = mixer::find(&mixer_name).unwrap();
let device_name = matches.opt_str("device");
let player = Player::new(session.clone(), move || {
(backend)(device_name.as_ref().map(AsRef::as_ref))
});
(session, player, Box::new(mixer))
(session, player, mixer)
}
fn main() {

View file

@ -17,3 +17,10 @@ pub trait Mixer {
pub trait StreamEditor {
fn modify_stream<'a>(&self, data: &'a [i16]) -> Cow<'a, [i16]>;
}
pub fn find(s: &str) -> Option<Box<Mixer + Send>> {
match s {
"SoftMixer" => Some(Box::new(softmixer::SoftMixer::new())),
_ => None,
}
}