Skip to content

Commit 9a8c950

Browse files
committed
alsa mixer: add helpful suggestions for mixer and control values
1 parent 59482ed commit 9a8c950

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/alsa_mixer.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
use color_eyre::eyre::{self, Context, eyre};
1+
use alsa::device_name::HintIter;
2+
use color_eyre::{
3+
Section,
4+
eyre::{self, Context, eyre},
5+
};
26
use librespot_playback::mixer::{Mixer, MixerConfig};
37
use log::error;
48
use std::sync::{Arc, Mutex, MutexGuard};
59

10+
pub fn get_available_controls() -> alsa::Result<HintIter> {
11+
alsa::device_name::HintIter::new_str(None, "ctl")
12+
}
13+
614
pub struct AlsaMixer {
715
pub mixer: Arc<Mutex<alsa::Mixer>>,
816
pub config: MixerConfig,
@@ -20,6 +28,25 @@ impl AlsaMixer {
2028
self.config.control,
2129
self.config.device,
2230
)
31+
.with_suggestion(|| {
32+
format!(
33+
"maybe try one of the following for 'control':{}",
34+
lock.iter()
35+
.filter_map(|elem| {
36+
let selem = alsa::mixer::Selem::new(elem)?;
37+
if selem.has_playback_volume() {
38+
selem
39+
.get_id()
40+
.get_name()
41+
.ok()
42+
.map(|name| format!("\n- {name}"))
43+
} else {
44+
None
45+
}
46+
})
47+
.collect::<String>()
48+
)
49+
})
2350
})?;
2451
Ok(selem)
2552
}

src/setup.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ pub(crate) fn initial_state(
5353
control,
5454
index: 0,
5555
volume_ctrl,
56+
}).with_suggestion(|| {
57+
match alsa_mixer::get_available_controls() {
58+
Err(err) => format!("there are no controls available, maybe check that alsa is available: {err}"),
59+
Ok(controls) => {
60+
format!("maybe try one of the following as 'mixer':{}", controls.filter_map(|hint| hint.name.map(|name| format!("\n- {name}"))).collect::<String>())
61+
}
62+
}
5663
})?)
5764
}
5865
_ => {

0 commit comments

Comments
 (0)