فهرست منبع

Select mixer dynamically

Daniel Romero 8 سال پیش
والد
کامیت
6df2af0ac9
2فایلهای تغییر یافته به همراه15 افزوده شده و 5 حذف شده
  1. 8 5
      src/main.rs
  2. 7 0
      src/mixer/mod.rs

+ 8 - 5
src/main.rs

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

+ 7 - 0
src/mixer/mod.rs

@@ -16,4 +16,11 @@ 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,
+  }
 }