Skip to content

Commit

Permalink
Add no_mixer alternative for volume control
Browse files Browse the repository at this point in the history
  • Loading branch information
Icelk committed Mar 6, 2023
1 parent fbcbeca commit ae28414
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static VOLUME_CONTROLLER_VALUES: &[&str] = &[
"alsa",
#[cfg(feature = "alsa_backend")]
"alsa_linear",
"none",
];

#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, StructOpt)]
Expand All @@ -90,6 +91,7 @@ pub enum VolumeController {
AlsaLinear,
#[serde(rename = "softvol")]
SoftVolume,
None,
}

impl FromStr for VolumeController {
Expand All @@ -100,6 +102,7 @@ impl FromStr for VolumeController {
"alsa" => Ok(VolumeController::Alsa),
"alsa_linear" => Ok(VolumeController::AlsaLinear),
"softvol" => Ok(VolumeController::SoftVolume),
"none" => Ok(VolumeController::None),
_ => unreachable!(),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod config;
mod dbus_mpris;
mod error;
mod main_loop;
mod no_mixer;
mod process;
mod setup;
mod utils;
Expand Down
23 changes: 23 additions & 0 deletions src/no_mixer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use librespot_playback::mixer::{AudioFilter, Mixer, MixerConfig};

pub struct NoMixer {}

impl Mixer for NoMixer {
fn open(_: Option<MixerConfig>) -> NoMixer {
NoMixer {}
}

fn start(&self) {}

fn stop(&self) {}

fn volume(&self) -> u16 {
0
}

fn set_volume(&self, _volume: u16) {}

fn get_audio_filter(&self) -> Option<Box<dyn AudioFilter + Send>> {
None
}
}
20 changes: 16 additions & 4 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLo
Box::new(|| Box::new(mixer::softmixer::SoftMixer::open(None)) as Box<dyn Mixer>)
as Box<dyn FnMut() -> Box<dyn Mixer>>
}
config::VolumeController::None => {
info!("Using no volume controller.");
Box::new(|| Box::new(crate::no_mixer::NoMixer::open(None)) as Box<dyn Mixer>)
as Box<dyn FnMut() -> Box<dyn Mixer>>
}
_ => {
info!("Using alsa volume controller.");
let linear = matches!(
Expand All @@ -53,10 +58,17 @@ pub(crate) fn initial_state(config: config::SpotifydConfig) -> main_loop::MainLo
};

#[cfg(not(feature = "alsa_backend"))]
let mut mixer = {
info!("Using software volume controller.");
Box::new(|| Box::new(mixer::softmixer::SoftMixer::open(None)) as Box<dyn Mixer>)
as Box<dyn FnMut() -> Box<dyn Mixer>>
let mut mixer = match config.volume_controller {
config::VolumeController::None => {
info!("Using no volume controller.");
Box::new(|| Box::new(crate::no_mixer::NoMixer::open(None)) as Box<dyn Mixer>)
as Box<dyn FnMut() -> Box<dyn Mixer>>
}
_ => {
info!("Using software volume controller.");
Box::new(|| Box::new(mixer::softmixer::SoftMixer::open(None)) as Box<dyn Mixer>)
as Box<dyn FnMut() -> Box<dyn Mixer>>
}
};

let cache = config.cache;
Expand Down

0 comments on commit ae28414

Please sign in to comment.