2021-05-24 13:53:32 +00:00
|
|
|
use crate::config::VolumeCtrl;
|
|
|
|
|
|
|
|
pub mod mappings;
|
|
|
|
use self::mappings::MappedCtrl;
|
|
|
|
|
2018-02-26 01:50:41 +00:00
|
|
|
pub trait Mixer: Send {
|
2021-05-24 13:53:32 +00:00
|
|
|
fn open(config: MixerConfig) -> Self
|
2018-02-26 01:50:41 +00:00
|
|
|
where
|
|
|
|
Self: Sized;
|
2021-05-24 13:53:32 +00:00
|
|
|
|
2017-01-25 21:22:53 +00:00
|
|
|
fn set_volume(&self, volume: u16);
|
2017-01-20 19:39:05 +00:00
|
|
|
fn volume(&self) -> u16;
|
2021-05-24 13:53:32 +00:00
|
|
|
|
2019-10-08 09:31:18 +00:00
|
|
|
fn get_audio_filter(&self) -> Option<Box<dyn AudioFilter + Send>> {
|
2017-01-25 21:22:53 +00:00
|
|
|
None
|
2017-01-20 19:39:05 +00:00
|
|
|
}
|
2017-01-25 21:22:53 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 13:20:31 +00:00
|
|
|
pub trait AudioFilter {
|
2021-05-30 18:09:39 +00:00
|
|
|
fn modify_stream(&self, data: &mut [f64]);
|
2017-01-25 21:49:18 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 13:53:32 +00:00
|
|
|
pub mod softmixer;
|
|
|
|
use self::softmixer::SoftMixer;
|
|
|
|
|
2018-03-20 15:32:43 +00:00
|
|
|
#[cfg(feature = "alsa-backend")]
|
|
|
|
pub mod alsamixer;
|
|
|
|
#[cfg(feature = "alsa-backend")]
|
|
|
|
use self::alsamixer::AlsaMixer;
|
|
|
|
|
2018-09-11 16:53:18 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct MixerConfig {
|
2021-08-26 20:35:45 +00:00
|
|
|
pub device: String,
|
2021-05-24 13:53:32 +00:00
|
|
|
pub control: String,
|
2018-09-11 16:53:18 +00:00
|
|
|
pub index: u32,
|
2021-05-24 13:53:32 +00:00
|
|
|
pub volume_ctrl: VolumeCtrl,
|
2018-09-11 16:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for MixerConfig {
|
2019-10-08 09:31:18 +00:00
|
|
|
fn default() -> MixerConfig {
|
|
|
|
MixerConfig {
|
2021-08-26 20:35:45 +00:00
|
|
|
device: String::from("default"),
|
2021-05-24 13:53:32 +00:00
|
|
|
control: String::from("PCM"),
|
2019-10-08 09:31:18 +00:00
|
|
|
index: 0,
|
2021-05-24 13:53:32 +00:00
|
|
|
volume_ctrl: VolumeCtrl::default(),
|
2018-09-11 16:53:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 13:53:32 +00:00
|
|
|
pub type MixerFn = fn(MixerConfig) -> Box<dyn Mixer>;
|
2021-03-10 21:32:24 +00:00
|
|
|
|
2021-05-24 13:53:32 +00:00
|
|
|
fn mk_sink<M: Mixer + 'static>(config: MixerConfig) -> Box<dyn Mixer> {
|
|
|
|
Box::new(M::open(config))
|
2017-02-22 04:17:04 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 19:22:24 +00:00
|
|
|
pub const MIXERS: &[(&str, MixerFn)] = &[
|
|
|
|
(SoftMixer::NAME, mk_sink::<SoftMixer>), // default goes first
|
|
|
|
#[cfg(feature = "alsa-backend")]
|
|
|
|
(AlsaMixer::NAME, mk_sink::<AlsaMixer>),
|
|
|
|
];
|
|
|
|
|
2021-05-31 20:32:39 +00:00
|
|
|
pub fn find(name: Option<&str>) -> Option<MixerFn> {
|
2021-10-30 19:22:24 +00:00
|
|
|
if let Some(name) = name {
|
|
|
|
MIXERS
|
|
|
|
.iter()
|
|
|
|
.find(|mixer| name == mixer.0)
|
|
|
|
.map(|mixer| mixer.1)
|
|
|
|
} else {
|
|
|
|
MIXERS.first().map(|mixer| mixer.1)
|
2017-02-21 21:49:45 +00:00
|
|
|
}
|
|
|
|
}
|