Skip to content

Commit 14751e6

Browse files
Fix for review feedback
1 parent 6fc3b89 commit 14751e6

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

amplipi/ctrl.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,14 +850,16 @@ def set_vol():
850850
vol, vol_f, vol_f_delta, vol_min, or vol_max.
851851
"""
852852
# Field precedence: vol (db) > vol_delta > vol (float)
853-
# vol (db) is first in precedence yet last in the stack to cover the default case of a None volume change, but when it does have a value it overrides the other options
853+
# vol (db) is first in precedence yet last in the stack to cover the default case of no volume change
854854
if update.vol_delta_f is not None and update.vol is None:
855855
true_vol_f = zone.vol_f + zone.vol_f_overflow
856856
expected_vol_total = update.vol_delta_f + true_vol_f
857857
vol_f_new = utils.clamp(expected_vol_total, models.MIN_VOL_F, models.MAX_VOL_F)
858858

859859
vol_db = utils.vol_float_to_db(vol_f_new, zone.vol_min, zone.vol_max)
860-
zone.vol_f_overflow = 0 if models.MIN_VOL_F < expected_vol_total and expected_vol_total < models.MAX_VOL_F else utils.clamp((expected_vol_total - vol_f_new), models.MIN_VOL_F_OVERFLOW, models.MAX_VOL_F_OVERFLOW) # Clamp the remaining delta to be between -1 and 1
860+
zone.vol_f_overflow = 0 if models.MIN_VOL_F < expected_vol_total and expected_vol_total < models.MAX_VOL_F \
861+
else utils.clamp((expected_vol_total - vol_f_new), models.MIN_VOL_F_OVERFLOW, models.MAX_VOL_F_OVERFLOW)
862+
# Clamp the remaining delta to be between -1 and 1
861863

862864
elif update.vol_f is not None and update.vol is None:
863865
clamp_vol_f = utils.clamp(vol_f, 0, 1)
@@ -874,8 +876,8 @@ def set_vol():
874876
else:
875877
raise Exception('unable to update zone volume')
876878

877-
# If the change made vol f be between the min and max, delete the overflow
878-
# This is useful so that you can click wherever you want on the volume bar and expect it to end up there without rubberbanding back to whatever vol_f + vol_f_overflow value you'd otherwise be at
879+
# Reset the overflow when vol_f goes in bounds, there is no longer an overflow
880+
# Avoids reporting spurious volume oscillations
879881
zone.vol_f_overflow = 0 if vol_f_new != models.MIN_VOL_F and vol_f_new != models.MAX_VOL_F else zone.vol_f_overflow
880882

881883
# To avoid potential unwanted loud output:

web/src/App.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ export const useStatusStore = create((set, get) => ({
5050
applyPlayerVol(vol, zones, sourceId, (zone_id, new_vol) => {
5151
for (const i in s.status.zones) {
5252
if (s.status.zones[i].id === zone_id) {
53-
let true_vol = Math.round((new_vol + s.status.zones[i].vol_f_overflow) * 100) / 100;
54-
let clamped = Math.min(Math.max(true_vol, 0), 1);
53+
// Calculate out future vol_f and vol_f_overflow to match expected future API polled state
54+
let combined_vol = new_vol + s.status.zones[i].vol_f_overflow;
55+
let new_vol_f = Math.min(Math.max(combined_vol, 0), 1);
5556

56-
s.status.zones[i].vol_f = clamped;
57-
s.status.zones[i].vol_f_overflow = true_vol - clamped;
57+
s.status.zones[i].vol_f = new_vol_f;
58+
s.status.zones[i].vol_f_overflow = combined_vol - new_vol_f;
5859
}
5960
}
6061
});
@@ -72,7 +73,7 @@ export const useStatusStore = create((set, get) => ({
7273
}
7374
}
7475

75-
// Also update groups that consist entirely of affected zones
76+
// Mute groups if they are now completely muted
7677
for (const g of s.status.groups) {
7778
if (g.zones.every(zid => affectedZones.includes(zid))) {
7879
g.mute = mute;
@@ -174,7 +175,9 @@ export const useStatusStore = create((set, get) => ({
174175
const g = s.status.groups.filter((g) => g.id === groupId)[0];
175176
for (const i of g.zones) {
176177
s.skipUpdate = true;
177-
s.status.zones[i].vol_f = new_vol + s.status.zones[i].vol_f_overflow;
178+
// vol_f_overflow is set to 0 whenever vol_f is between 0 and 1, groups authoritatively set the volume so we reflect that here too
179+
s.status.zones[i].vol_f_overflow = 0;
180+
s.status.zones[i].vol_f = new_vol;
178181
}
179182

180183
updateGroupVols(s);
@@ -208,6 +211,7 @@ export const useStatusStore = create((set, get) => ({
208211
const updateGroupVols = (s) => {
209212
s.status.groups.forEach((g) => {
210213
if (g.zones.length > 1) {
214+
// Combine vol_f with vol_f_overflow to ensure the group volume slider moves at the same relative speed even when a zone overflows
211215
const vols = g.zones.map((id) => s.status.zones[id].vol_f + s.status.zones[id].vol_f_overflow);
212216
let calculated_vol = Math.min(...vols) * 0.5 + Math.max(...vols) * 0.5;
213217
g.vol_f = calculated_vol;

0 commit comments

Comments
 (0)