diff --git a/connect/src/spirc.rs b/connect/src/spirc.rs index 8f3b81015..0d9c57fe8 100644 --- a/connect/src/spirc.rs +++ b/connect/src/spirc.rs @@ -1272,7 +1272,7 @@ impl SpircTask { } fn set_volume(&mut self, volume: u16) { - self.device.set_volume(volume as u32); + self.player.set_volume(volume as u32); self.mixer .set_volume(volume_to_mixer(volume, &self.config.volume_ctrl)); if let Some(cache) = self.session.cache() { diff --git a/playback/src/config.rs b/playback/src/config.rs index f8f028933..3144d86cb 100644 --- a/playback/src/config.rs +++ b/playback/src/config.rs @@ -128,6 +128,7 @@ pub struct PlayerConfig { pub normalisation_knee: f32, pub gapless: bool, pub passthrough: bool, + pub lms_connect_mode: bool, } impl Default for PlayerConfig { @@ -144,6 +145,7 @@ impl Default for PlayerConfig { normalisation_knee: 1.0, gapless: true, passthrough: false, + lms_connect_mode: false, } } } diff --git a/playback/src/player.rs b/playback/src/player.rs index 0127f00aa..e9652f9b7 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -82,6 +82,7 @@ enum PlayerCommand { Pause, Stop, Seek(u32), + Volume(u32), AddEventSender(mpsc::UnboundedSender), SetSinkEventCallback(Option), EmitVolumeSetEvent(u16), @@ -94,6 +95,12 @@ pub enum PlayerEvent { play_request_id: u64, track_id: SpotifyId, }, + Volume { + volume: u32 + }, + Seek { + position: u32 + }, // The player started working on playback of a track while it was in a stopped state. // This is always immediately followed up by a "Loading" or "Playing" event. Started { @@ -189,6 +196,8 @@ impl PlayerEvent { | Stopped { play_request_id, .. } => Some(*play_request_id), + //I'm not sure of that... + Volume { .. } | Seek { .. } => None, Changed { .. } | Preloading { .. } | VolumeSet { .. } => None, } } @@ -365,6 +374,10 @@ impl Player { pub fn seek(&self, position_ms: u32) { self.command(PlayerCommand::Seek(position_ms)); } + + pub fn set_volume(&self, volume: u32) { + self.command(PlayerCommand::Volume(volume)); + } pub fn get_player_event_channel(&self) -> PlayerEventChannel { let (event_sender, event_receiver) = mpsc::unbounded_channel(); @@ -1706,6 +1719,20 @@ impl PlayerInternal { }); } } + + fn handle_command_volume(&mut self, mut volume: u32) { + if volume > 0 { + volume = volume * 100 / std::u16::MAX as u32; + } else { + volume = 0; + } + + if volume > 100 { + volume = 100; + }; + + self.send_event(PlayerEvent::Volume { volume }); + } fn handle_command(&mut self, cmd: PlayerCommand) { debug!("command={:?}", cmd); @@ -1720,6 +1747,8 @@ impl PlayerInternal { PlayerCommand::Preload { track_id } => self.handle_command_preload(track_id), PlayerCommand::Seek(position_ms) => self.handle_command_seek(position_ms), + + PlayerCommand::Volume(volume) => self.handle_command_volume(volume), PlayerCommand::Play => self.handle_play(), @@ -1832,6 +1861,7 @@ impl ::std::fmt::Debug for PlayerCommand { PlayerCommand::Pause => f.debug_tuple("Pause").finish(), PlayerCommand::Stop => f.debug_tuple("Stop").finish(), PlayerCommand::Seek(position) => f.debug_tuple("Seek").field(&position).finish(), + PlayerCommand::Volume(volume) => f.debug_tuple("Volume").field(&volume).finish(), PlayerCommand::AddEventSender(_) => f.debug_tuple("AddEventSender").finish(), PlayerCommand::SetSinkEventCallback(_) => { f.debug_tuple("SetSinkEventCallback").finish()