Skip to content

Commit 94d957b

Browse files
Remove debug flag, remove manual vol delta stuff
1 parent 9a155a3 commit 94d957b

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

amplipi/streams/airplay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _activate(self, vsrc: int):
130130
self.mpris = MPRIS(mpris_name, f'{src_config_folder}/metadata.txt')
131131

132132
vol_sync = f"{utils.get_folder('streams')}/shairport_volume_handler.py"
133-
vol_args = [sys.executable, vol_sync, mpris_name, str(self.id), "--debug"]
133+
vol_args = [sys.executable, vol_sync, mpris_name, str(self.id)]
134134
logger.info(f'{self.name}: starting vol synchronizer: {vol_args}')
135135
self.volume_process = subprocess.Popen(args=vol_args, stdout=self._log_file, stderr=self._log_file)
136136
except Exception as exc:

streams/shairport_volume_handler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,27 @@ def __init__(self, service_suffix: str):
2525
interface_name="org.mpris.MediaPlayer2.Player"
2626
)
2727
super().__init__()
28-
self.delta = 0.0
2928

3029
async def watch_vol(self):
3130
"""Watch the shairport mpris stream for volume changes and update amplipi volume info accordingly"""
3231
while True:
3332
try:
3433
if self.volume is not None and self.volume != self.mpris.Volume:
3534
self.logger.debug(f"Airplay volume changed from {self.volume} to {self.mpris.Volume}")
36-
self.delta += self.mpris.Volume - self.volume
3735
self.callback("stream_volume_changed")
3836
self.volume = float(self.mpris.Volume)
3937

4038
except Exception as e:
4139
self.logger.exception(f"Error: {e}")
4240
return
43-
sleep(1)
41+
sleep(0.1)
4442

4543
def set_vol(self, amplipi_volume: float, vol_set_point: float) -> float: # This has unused variable vol_set_point to keep up with the underlying StreamData.set_vol function schema
4644
"""Update Airplay's volume slider to match AmpliPi"""
4745
try:
4846
# Airplay does not allow external devices to set the volume of a users system
4947

50-
# Airplay no longer relies on the set point vol, but if we ever get rid of the self.delta path of the stream_volume_changed event this will be relevant again:
48+
# Airplay is a fully authoritative volume source, meaning it forces amplipi volume to equal its volume now. If that ever changes, this will be relevant:
5149
# There are two values this could realistically be returned and become the new vol_set_point, and they each have their own drawbacks:
5250

5351
# amplipi_volume: If amplipi_volume is the new set point, any changes to airplay volume will send the volume to an odd

streams/volume_synchronizer.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def __init__(self):
1818
self.callback: Callable
1919

2020
self.volume: float = None
21-
self.delta: Optional[float] = None
2221
self.logger: logging.Logger
2322

2423
self.thread: threading.Thread = threading.Thread(target=self.run_async_watch, daemon=True).start()
@@ -69,11 +68,11 @@ def set_vol(self, stream_volume: float, vol_set_point: float):
6968
if stream_volume is None:
7069
return vol_set_point
7170

72-
if abs(stream_volume - vol_set_point) <= 0.005:
71+
if abs(stream_volume - self.volume) <= 0.005:
7372
self.logger.debug("Ignored minor Stream -> AmpliPi change")
7473
return vol_set_point
7574

76-
delta = float(stream_volume - vol_set_point)
75+
delta = float(stream_volume - self.volume)
7776
return self.set_vol_delta(delta)
7877
except Exception as e:
7978
self.logger.exception(f"Exception: {e}")
@@ -129,13 +128,7 @@ def watcher_loop(self):
129128

130129
event = self.event_queue.get()
131130
if event == "stream_volume_changed":
132-
if self.stream.delta is not None:
133-
# Reduce race condition potential by decoupling the value from the variable
134-
delta = float(self.stream.delta)
135-
self.vol_set_point = self.amplipi.set_vol_delta(delta)
136-
self.stream.delta -= delta
137-
else:
138-
self.vol_set_point = self.amplipi.set_vol(self.stream.volume, self.vol_set_point)
131+
self.vol_set_point = self.amplipi.set_vol(self.stream.volume, self.vol_set_point)
139132
elif event == "amplipi_volume_changed":
140133
self.vol_set_point = self.stream.set_vol(self.amplipi.volume, self.vol_set_point)
141134
except queue.Empty:

0 commit comments

Comments
 (0)