Skip to content

Commit f59fa78

Browse files
committed
Add mixer config option.
1 parent acbec88 commit f59fa78

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ username = USER
3838
password = PASS
3939
backend = alsa
4040
device = alsa_audio_device # Given by `aplay -L`
41+
mixer = PCM
4142
volume-control = alsa # or softvol
4243
onstart = command_run_on_playback_start
4344
onstop = command_run_on_playback_stop

src/alsa_mixer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use librespot::mixer::{Mixer, AudioFilter};
22
use alsa;
33

4-
pub struct AlsaMixer(pub String);
4+
pub struct AlsaMixer {pub device: String, pub mixer: String}
55

66
impl Mixer for AlsaMixer {
77
fn open() -> AlsaMixer {
8-
AlsaMixer("default".to_string())
8+
AlsaMixer { device: "default".to_string(), mixer: "Master".to_string() }
99
}
1010
fn start(&self) {}
1111
fn stop(&self) {}
1212

1313
fn volume(&self) -> u16 {
14-
let selem_id = alsa::mixer::SelemId::new("Master", 0);
15-
match alsa::mixer::Mixer::new(&self.0, false)
14+
let selem_id = alsa::mixer::SelemId::new(&*self.mixer, 0);
15+
match alsa::mixer::Mixer::new(&self.device, false)
1616
.ok()
1717
.as_ref()
1818
.and_then(|ref mixer| mixer.find_selem(&selem_id))
@@ -29,17 +29,17 @@ impl Mixer for AlsaMixer {
2929
_ => {
3030
error!(
3131
"Couldn't read volume from alsa device with name \"{}\".",
32-
self.0
32+
self.device
3333
);
3434
0
3535
}
3636
}
3737
}
3838

3939
fn set_volume(&self, volume: u16) {
40-
match alsa::mixer::Mixer::new(&self.0, false).ok().and_then(
40+
match alsa::mixer::Mixer::new(&self.device, false).ok().and_then(
4141
|mixer| {
42-
let selem_id = alsa::mixer::SelemId::new("Master", 0);
42+
let selem_id = alsa::mixer::SelemId::new(&*self.mixer, 0);
4343
mixer.find_selem(&selem_id).and_then(|elem| {
4444
let (min, max) = elem.get_playback_volume_range();
4545

src/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn command_line_argument_options() -> Options {
1919
opts.optopt("u", "username", "Spotify user name.", "USERNAME");
2020
opts.optopt("p", "password", "Spotify password.", "PASSWORD");
2121
opts.optopt("", "device", "Audio device, given by aplay -L.", "DEVICE");
22+
opts.optopt("", "mixer", "Audio mixer", "DEVICE");
2223
opts.optopt("", "bitrate", "Any of 96, 160, and 320.", "DEVICE");
2324
opts.optopt("", "pid", "Path to PID file.", "PID-FILE");
2425
opts.optopt("", "device_name", "Name of this Spotify device.", "DEVICE");

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct SpotifydConfig {
4040
pub cache: Option<Cache>,
4141
pub backend: Option<String>,
4242
pub audio_device: Option<String>,
43+
pub mixer: Option<String>,
4344
pub volume_controller: VolumeController,
4445
pub device_name: String,
4546
pub player_config: PlayerConfig,
@@ -54,6 +55,7 @@ impl Default for SpotifydConfig {
5455
cache: None,
5556
backend: None,
5657
audio_device: None,
58+
mixer: None,
5759
volume_controller: VolumeController::SoftVol,
5860
device_name: "Spotifyd".to_string(),
5961
player_config: PlayerConfig {
@@ -137,6 +139,7 @@ pub fn get_config<P: AsRef<Path>>(config_path: Option<P>, matches: &Matches) ->
137139
config.password = lookup("password");
138140
config.backend = lookup("backend");
139141
config.audio_device = lookup("device");
142+
config.mixer = lookup("mixer");
140143
update(
141144
&mut config.volume_controller,
142145
lookup("volume-control").and_then(|s| VolumeController::from_str(&*s).ok()),

src/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ fn main() {
242242
let player_config = config.player_config;
243243
let session_config = config.session_config;
244244
let backend = config.backend.clone();
245-
let audio_device = config.audio_device.clone();
246245
let device_id = session_config.device_id.clone();
247246
let discovery_stream = discovery(
248247
&handle,
@@ -270,14 +269,16 @@ fn main() {
270269
Box<futures::Future<Item = Session, Error = io::Error>>
271270
};
272271

273-
let local_audio_device = audio_device.clone();
272+
let local_audio_device = config.audio_device.clone();
273+
let local_mixer = config.mixer.clone();
274274
let mixer = match config.volume_controller {
275275
config::VolumeController::Alsa => {
276276
info!("Using alsa volume controller.");
277277
Box::new(move || {
278-
Box::new(alsa_mixer::AlsaMixer(
279-
local_audio_device.clone().unwrap_or("default".to_string()),
280-
)) as Box<Mixer>
278+
Box::new( alsa_mixer::AlsaMixer{
279+
device : local_audio_device.clone().unwrap_or("default".to_string()),
280+
mixer : local_mixer.clone().unwrap_or("Master".to_string()),
281+
}) as Box<Mixer>
281282
}) as Box<FnMut() -> Box<Mixer>>
282283
}
283284
config::VolumeController::SoftVol => {
@@ -293,7 +294,7 @@ fn main() {
293294
connection,
294295
mixer,
295296
backend,
296-
audio_device,
297+
config.audio_device.clone(),
297298
ctrl_c(&handle).flatten_stream().boxed(),
298299
discovery_stream,
299300
cache,

0 commit comments

Comments
 (0)