From 3198346cc653992e6ca5ec50fceb4efdd064b212 Mon Sep 17 00:00:00 2001 From: Mattias Holmlund Date: Wed, 8 Mar 2017 21:48:34 +0100 Subject: [PATCH 1/2] New option --fixed-volume --- src/main.rs | 15 +++++++++++---- src/spirc.rs | 9 +++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index ab446b7e..676c9e5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,6 +77,7 @@ struct Setup { config: Config, credentials: Option, enable_discovery: bool, + fixed_volume: bool, } fn setup(args: &[String]) -> Setup { @@ -90,6 +91,7 @@ fn setup(args: &[String]) -> Setup { .optopt("u", "username", "Username to sign in with", "USERNAME") .optopt("p", "password", "Password", "PASSWORD") .optflag("", "disable-discovery", "Disable discovery mode") + .optflag("", "fixed-volume", "Always set volume to 100%") .optopt("", "backend", "Audio backend to use. Use '?' to list options", "BACKEND") .optopt("", "device", "Audio device to use. Use '?' to list options", "DEVICE") .optopt("", "mixer", "Mixer to use", "MIXER"); @@ -141,6 +143,7 @@ fn setup(args: &[String]) -> Setup { cached_credentials); let enable_discovery = !matches.opt_present("disable-discovery"); + let fixed_volume = matches.opt_present("fixed-volume"); let config = Config { user_agent: version::version_string(), @@ -160,6 +163,7 @@ fn setup(args: &[String]) -> Setup { credentials: credentials, device: device, enable_discovery: enable_discovery, + fixed_volume: fixed_volume, mixer: mixer, } } @@ -170,6 +174,7 @@ struct Main { backend: fn(Option) -> Box, device: Option, mixer: fn() -> Box, + fixed_volume: bool, handle: Handle, discovery: Option, @@ -188,7 +193,8 @@ impl Main { cache: Option, backend: fn(Option) -> Box, device: Option, - mixer: fn() -> Box) -> Main + mixer: fn() -> Box, + fixed_volume: bool) -> Main { Main { handle: handle.clone(), @@ -197,6 +203,7 @@ impl Main { backend: backend, device: device, mixer: mixer, + fixed_volume: fixed_volume, connect: Box::new(futures::future::empty()), discovery: None, @@ -256,7 +263,7 @@ impl Future for Main { (backend)(device) }); - let (spirc, spirc_task) = Spirc::new(session, player, mixer); + let (spirc, spirc_task) = Spirc::new(session, player, mixer, self.fixed_volume); self.spirc = Some(spirc); self.spirc_task = Some(spirc_task); @@ -298,9 +305,9 @@ fn main() { let handle = core.handle(); let args: Vec = std::env::args().collect(); - let Setup { backend, config, device, cache, enable_discovery, credentials, mixer } = setup(&args); + let Setup { backend, config, device, cache, enable_discovery, fixed_volume, credentials, mixer } = setup(&args); - let mut task = Main::new(handle, config.clone(), cache, backend, device, mixer); + let mut task = Main::new(handle, config.clone(), cache, backend, device, mixer, fixed_volume); if enable_discovery { task.discovery(); } diff --git a/src/spirc.rs b/src/spirc.rs index 411820e6..1a7cb3ab 100644 --- a/src/spirc.rs +++ b/src/spirc.rs @@ -18,6 +18,7 @@ use protocol::spirc::{PlayStatus, State, MessageType, Frame, DeviceState}; pub struct SpircTask { player: Player, mixer: Box, + fixed_volume: bool, sequence: SeqGenerator, @@ -111,7 +112,7 @@ fn initial_device_state(name: String, volume: u16) -> DeviceState { } impl Spirc { - pub fn new(session: Session, player: Player, mixer: Box) + pub fn new(session: Session, player: Player, mixer: Box, fixed_volume: bool) -> (Spirc, SpircTask) { debug!("new Spirc[{}]", session.session_id()); @@ -141,6 +142,7 @@ impl Spirc { let mut task = SpircTask { player: player, mixer: mixer, + fixed_volume: fixed_volume, sequence: SeqGenerator::new(1), @@ -359,8 +361,11 @@ impl SpircTask { MessageType::kMessageTypeVolume => { let volume = frame.get_volume(); self.device.set_volume(volume); - self.mixer.set_volume(frame.get_volume() as u16); + if !self.fixed_volume { + self.mixer.set_volume(frame.get_volume() as u16); + } self.notify(None); + } MessageType::kMessageTypeNotify => { From 498c60adfed6e77a137da982cd0f7e58ea1f7b46 Mon Sep 17 00:00:00 2001 From: Mattias Holmlund Date: Thu, 9 Mar 2017 18:58:29 +0100 Subject: [PATCH 2/2] Log volume changes --- src/spirc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/spirc.rs b/src/spirc.rs index 1a7cb3ab..f236d760 100644 --- a/src/spirc.rs +++ b/src/spirc.rs @@ -364,6 +364,7 @@ impl SpircTask { if !self.fixed_volume { self.mixer.set_volume(frame.get_volume() as u16); } + debug!("volume {}", volume); self.notify(None); }