Fix fader fidgeting volume jumps. Fixes #40

This commit is contained in:
Matthew Stratford 2020-10-27 22:15:44 +00:00
parent 529f86bcc6
commit 500005811c
No known key found for this signature in database
GPG key ID: 9E53C8B3F0B57395
2 changed files with 12 additions and 1 deletions

View file

@ -125,6 +125,10 @@ class Player extends ((PlayerEmitter as unknown) as { new (): EventEmitter }) {
}
}
getVolume() {
return this.volume;
}
setVolume(val: number) {
this.volume = val;
this._applyVolume();

View file

@ -666,7 +666,14 @@ export const setVolume = (
const state = getState().mixer.players[player];
const currentLevel = state.volume;
const currentGain = state.gain;
let currentGain = state.gain;
// If we can, use the engine's 'real' volume gain.
// This helps when we've interupted a previous fade, so the state gain won't be correct.
if (typeof audioEngine.players[player] !== "undefined") {
currentGain = audioEngine.players[player]!.getVolume();
}
const volumeTween = new Between(currentLevel, uiLevel)
.time(FADE_TIME_SECONDS * 1000)
.on("update", (val: number) => {