mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Select mixer dynamically
This commit is contained in:
parent
464e85e285
commit
6df2af0ac9
2 changed files with 15 additions and 5 deletions
13
src/main.rs
13
src/main.rs
|
@ -18,8 +18,7 @@ use librespot::audio_backend::{self, BACKENDS};
|
||||||
use librespot::cache::{Cache, DefaultCache, NoCache};
|
use librespot::cache::{Cache, DefaultCache, NoCache};
|
||||||
use librespot::player::Player;
|
use librespot::player::Player;
|
||||||
use librespot::session::{Bitrate, Config, Session};
|
use librespot::session::{Bitrate, Config, Session};
|
||||||
use librespot::mixer::softmixer::SoftMixer;
|
use librespot::mixer::{self, Mixer};
|
||||||
use librespot::mixer::Mixer;
|
|
||||||
|
|
||||||
use librespot::version;
|
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("u", "username", "Username to sign in with", "USERNAME")
|
||||||
.optopt("p", "password", "Password", "PASSWORD")
|
.optopt("p", "password", "Password", "PASSWORD")
|
||||||
.optopt("", "backend", "Audio backend to use. Use '?' to list options", "BACKEND")
|
.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..]) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
|
@ -123,14 +123,17 @@ fn setup(args: &[String]) -> (Session, Player, Box<Mixer + Send>) {
|
||||||
matches.opt_str("password"));
|
matches.opt_str("password"));
|
||||||
session.login(credentials).unwrap();
|
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 device_name = matches.opt_str("device");
|
||||||
let player = Player::new(session.clone(), move || {
|
let player = Player::new(session.clone(), move || {
|
||||||
(backend)(device_name.as_ref().map(AsRef::as_ref))
|
(backend)(device_name.as_ref().map(AsRef::as_ref))
|
||||||
});
|
});
|
||||||
|
|
||||||
(session, player, Box::new(mixer))
|
(session, player, mixer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -16,4 +16,11 @@ pub trait Mixer {
|
||||||
|
|
||||||
pub trait StreamEditor {
|
pub trait StreamEditor {
|
||||||
fn modify_stream<'a>(&self, data: &'a [i16]) -> Cow<'a, [i16]>;
|
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,
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue