From 91ce808ef873c92daffd331e913a76192ce9346d Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Tue, 19 May 2020 00:05:32 +0200 Subject: [PATCH] support configuration of audio backend and backend device fixes #194 --- README.md | 2 ++ src/config.rs | 2 ++ src/main.rs | 6 ++++++ src/spotify.rs | 4 ++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d91cbf..276d5f9 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,8 @@ values are: * `use_nerdfont`: Turn nerdfont glyphs on/off * `theme`: Set a custom color palette (see below) +* `backend`: Audio backend to use, run `ncspot -h` for a list of devices +* `backend_device`: Audio device string to configure the backend * `audio_cache`: Enable or disable caching of audio files, on by default * `volnorm`: Enable or disable volume normalization, off by default diff --git a/src/config.rs b/src/config.rs index 28cb627..e951c46 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,6 +14,8 @@ pub struct Config { pub use_nerdfont: Option, pub saved_state: Option, pub audio_cache: Option, + pub backend: Option, + pub backend_device: Option, pub volnorm: Option, pub volnorm_pregain: Option, } diff --git a/src/main.rs b/src/main.rs index be04ec8..5b53989 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,7 @@ use cursive::Cursive; use librespot_core::authentication::Credentials; use librespot_core::cache::Cache; +use librespot_playback::audio_backend; mod album; mod artist; @@ -121,10 +122,15 @@ fn credentials_prompt(reset: bool) -> Credentials { } fn main() { + let backends = { + let backends: Vec<&str> = audio_backend::BACKENDS.iter().map(|b| b.0).collect(); + format!("Audio backends: {}", backends.join(", ")) + }; let matches = App::new("ncspot") .version(env!("CARGO_PKG_VERSION")) .author("Henrik Friedrichsen and contributors") .about("cross-platform ncurses Spotify client") + .after_help(&*backends) .arg( Arg::with_name("debug") .short("d") diff --git a/src/spotify.rs b/src/spotify.rs index d70634f..e5e3277 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -373,12 +373,12 @@ impl Spotify { let mixer = create_mixer(None); mixer.set_volume(volume); - let backend = audio_backend::find(None).unwrap(); + let backend = audio_backend::find(cfg.backend.clone()).unwrap(); let (player, _eventchannel) = Player::new( player_config, session.clone(), mixer.get_audio_filter(), - move || (backend)(None), + move || (backend)(cfg.backend_device), ); let worker = Worker::new(events, commands, session, player, mixer);