diff --git a/README.md b/README.md index 9a477f7b..6e915e2c 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ username = USER password = PASS backend = alsa device = alsa_audio_device # Given by `aplay -L` +mixer = PCM volume-control = alsa # or softvol onstart = command_run_on_playback_start onstop = command_run_on_playback_stop diff --git a/src/alsa_mixer.rs b/src/alsa_mixer.rs index dbec8196..cf9e84a1 100644 --- a/src/alsa_mixer.rs +++ b/src/alsa_mixer.rs @@ -1,18 +1,18 @@ use librespot::mixer::{Mixer, AudioFilter}; use alsa; -pub struct AlsaMixer(pub String); +pub struct AlsaMixer {pub device: String, pub mixer: String} impl Mixer for AlsaMixer { fn open() -> AlsaMixer { - AlsaMixer("default".to_string()) + AlsaMixer { device: "default".to_string(), mixer: "Master".to_string() } } fn start(&self) {} fn stop(&self) {} fn volume(&self) -> u16 { - let selem_id = alsa::mixer::SelemId::new("Master", 0); - match alsa::mixer::Mixer::new(&self.0, false) + let selem_id = alsa::mixer::SelemId::new(&*self.mixer, 0); + match alsa::mixer::Mixer::new(&self.device, false) .ok() .as_ref() .and_then(|ref mixer| mixer.find_selem(&selem_id)) @@ -29,7 +29,7 @@ impl Mixer for AlsaMixer { _ => { error!( "Couldn't read volume from alsa device with name \"{}\".", - self.0 + self.device ); 0 } @@ -37,9 +37,9 @@ impl Mixer for AlsaMixer { } fn set_volume(&self, volume: u16) { - match alsa::mixer::Mixer::new(&self.0, false).ok().and_then( + match alsa::mixer::Mixer::new(&self.device, false).ok().and_then( |mixer| { - let selem_id = alsa::mixer::SelemId::new("Master", 0); + let selem_id = alsa::mixer::SelemId::new(&*self.mixer, 0); mixer.find_selem(&selem_id).and_then(|elem| { let (min, max) = elem.get_playback_volume_range(); diff --git a/src/cli.rs b/src/cli.rs index 6ea8f90d..65bcaff6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -19,6 +19,7 @@ pub fn command_line_argument_options() -> Options { opts.optopt("u", "username", "Spotify user name.", "USERNAME"); opts.optopt("p", "password", "Spotify password.", "PASSWORD"); opts.optopt("", "device", "Audio device, given by aplay -L.", "DEVICE"); + opts.optopt("", "mixer", "Audio mixer", "DEVICE"); opts.optopt("", "bitrate", "Any of 96, 160, and 320.", "DEVICE"); opts.optopt("", "pid", "Path to PID file.", "PID-FILE"); opts.optopt("", "device_name", "Name of this Spotify device.", "DEVICE"); diff --git a/src/config.rs b/src/config.rs index 94f0f1b8..4e0f9a5d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -40,6 +40,7 @@ pub struct SpotifydConfig { pub cache: Option, pub backend: Option, pub audio_device: Option, + pub mixer: Option, pub volume_controller: VolumeController, pub device_name: String, pub player_config: PlayerConfig, @@ -54,6 +55,7 @@ impl Default for SpotifydConfig { cache: None, backend: None, audio_device: None, + mixer: None, volume_controller: VolumeController::SoftVol, device_name: "Spotifyd".to_string(), player_config: PlayerConfig { @@ -137,6 +139,7 @@ pub fn get_config>(config_path: Option

, matches: &Matches) -> config.password = lookup("password"); config.backend = lookup("backend"); config.audio_device = lookup("device"); + config.mixer = lookup("mixer"); update( &mut config.volume_controller, lookup("volume-control").and_then(|s| VolumeController::from_str(&*s).ok()), diff --git a/src/main.rs b/src/main.rs index 698e2c51..66322372 100644 --- a/src/main.rs +++ b/src/main.rs @@ -242,7 +242,6 @@ fn main() { let player_config = config.player_config; let session_config = config.session_config; let backend = config.backend.clone(); - let audio_device = config.audio_device.clone(); let device_id = session_config.device_id.clone(); let discovery_stream = discovery( &handle, @@ -270,14 +269,16 @@ fn main() { Box> }; - let local_audio_device = audio_device.clone(); + let local_audio_device = config.audio_device.clone(); + let local_mixer = config.mixer.clone(); let mixer = match config.volume_controller { config::VolumeController::Alsa => { info!("Using alsa volume controller."); Box::new(move || { - Box::new(alsa_mixer::AlsaMixer( - local_audio_device.clone().unwrap_or("default".to_string()), - )) as Box + Box::new( alsa_mixer::AlsaMixer{ + device : local_audio_device.clone().unwrap_or("default".to_string()), + mixer : local_mixer.clone().unwrap_or("Master".to_string()), + }) as Box }) as Box Box> } config::VolumeController::SoftVol => { @@ -293,7 +294,7 @@ fn main() { connection, mixer, backend, - audio_device, + config.audio_device.clone(), ctrl_c(&handle).flatten_stream().boxed(), discovery_stream, cache,