Skip to content

Commit

Permalink
Propagate changes to global volume and backing volume
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkaufman committed Jan 6, 2021
1 parent 219b854 commit 992f8b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion html/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,10 +1375,17 @@ async function start_singing() {
var server_repeats = metadata["repeats"];
var server_bpr = metadata["bpr"];
var n_connected_users = metadata["n_connected_users"] || 0;
if (metadata["disableSongVideo"] != null){
if (metadata["disableSongVideo"] != null) {
disableSongVideo = metadata["disableSongVideo"];
update_video();
}
if (metadata["globalVolume"] != null) {
window.globalVolumeControl.value = metadata["globalVolume"];
}
if (metadata["backingVolume"] != null) {
window.backingVolumeControl.value = metadata["backingVolume"];
}


first_bucket_s = metadata["first_bucket"] || first_bucket_s;

Expand Down
11 changes: 11 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ def __init__(self, userid, name, last_heard_server_clock, delay_samples) -> None
self.send("bpr", state.bpr)
self.send("tracks", tracks)
self.send("first_bucket", state.first_bucket)
self.send("globalVolume",
scalar_to_friendly_volume(state.global_volume))
self.send("backingVolume",
scalar_to_friendly_volume(state.backing_volume))
if state.disable_song_video:
self.send("disableSongVideo", state.disable_song_video)
if state.song_start_clock:
Expand Down Expand Up @@ -719,16 +723,23 @@ def friendly_volume_to_scalar(volume):
# https://www.dr-lex.be/info-stuff/volumecontrols.html
return math.exp(6.908 * volume) / 1000

def scalar_to_friendly_volume(scalar):
if scalar < 0.0001:
return 0
return math.log(scalar * 1000)/6.908

# Handle special operations that do not require a user (although they may
# optionally support one), but can be done server-to-server as well.
def handle_special(query_params, server_clock, user=None, client_read_clock=None):
volume = query_params.get("volume", None)
if volume:
state.global_volume = friendly_volume_to_scalar(float(volume))
sendall("globalVolume", scalar_to_friendly_volume(state.global_volume))

backing_volume = query_params.get("backing_volume", None)
if backing_volume:
state.backing_volume = friendly_volume_to_scalar(float(backing_volume))
sendall("backingVolume", scalar_to_friendly_volume(state.backing_volume))

msg_chats = query_params.get("chat", None)
if msg_chats:
Expand Down

0 comments on commit 992f8b6

Please sign in to comment.