From 992f8b6cb003ad6087a23a105c3c577dce7afeac Mon Sep 17 00:00:00 2001 From: Jeff Kaufman Date: Wed, 6 Jan 2021 12:31:57 +0000 Subject: [PATCH] Propagate changes to global volume and backing volume --- html/demo.js | 9 ++++++++- server.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/html/demo.js b/html/demo.js index 8b3672e..e18635a 100644 --- a/html/demo.js +++ b/html/demo.js @@ -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; diff --git a/server.py b/server.py index e29777e..d7911b0 100755 --- a/server.py +++ b/server.py @@ -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: @@ -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: