Fix a bug and remove magic numbers

This commit is contained in:
Zach Fox 2019-05-22 15:24:33 -07:00
parent 7a88c8362b
commit 46ee148a69
4 changed files with 38 additions and 17 deletions

View file

@ -73,7 +73,7 @@ Flickable {
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
height: 30 height: 30
labelText: "People Volume" labelText: "People Volume"
from: -60.0 from: simplifiedUI.numericConstants.mutedValue
to: 20.0 to: 20.0
defaultValue: 0.0 defaultValue: 0.0
stepSize: 5.0 stepSize: 5.0
@ -101,7 +101,7 @@ Flickable {
Layout.topMargin: 2 Layout.topMargin: 2
height: 30 height: 30
labelText: "Environment Volume" labelText: "Environment Volume"
from: -60.0 from: simplifiedUI.numericConstants.mutedValue
to: 20.0 to: 20.0
defaultValue: 0.0 defaultValue: 0.0
stepSize: 5.0 stepSize: 5.0
@ -130,7 +130,7 @@ Flickable {
Layout.topMargin: 2 Layout.topMargin: 2
height: 30 height: 30
labelText: "System Sound Volume" labelText: "System Sound Volume"
from: -60.0 from: simplifiedUI.numericConstants.mutedValue
to: 20.0 to: 20.0
defaultValue: 0.0 defaultValue: 0.0
stepSize: 5.0 stepSize: 5.0

View file

@ -221,4 +221,8 @@ QtObject {
} }
} }
} }
readonly property QtObject numericConstants: QtObject {
readonly property real mutedValue: -60.0
}
} }

View file

@ -203,8 +203,10 @@ Rectangle {
Image { Image {
id: outputDeviceButton id: outputDeviceButton
property bool outputMuted: AudioScriptingInterface.avatarGain === -60 && property bool outputMuted: AudioScriptingInterface.avatarGain === simplifiedUI.numericConstants.mutedValue &&
AudioScriptingInterface.serverInjectorGain === -60 && AudioScriptingInterface.localInjectorGain === -60 && AudioScriptingInterface.systemInjectorGain === -60 AudioScriptingInterface.serverInjectorGain === simplifiedUI.numericConstants.mutedValue &&
AudioScriptingInterface.localInjectorGain === simplifiedUI.numericConstants.mutedValue &&
AudioScriptingInterface.systemInjectorGain === simplifiedUI.numericConstants.mutedValue
source: outputDeviceButton.outputMuted ? "./images/outputDeviceMuted.svg" : "./images/outputDeviceLoud.svg" source: outputDeviceButton.outputMuted ? "./images/outputDeviceMuted.svg" : "./images/outputDeviceLoud.svg"
anchors.centerIn: parent anchors.centerIn: parent
width: 20 width: 20
@ -230,7 +232,7 @@ Rectangle {
onClicked: { onClicked: {
Tablet.playSound(TabletEnums.ButtonClick); Tablet.playSound(TabletEnums.ButtonClick);
if (outputDeviceButton.outputMuted && !AudioScriptingInterface.muted) { if (!outputDeviceButton.outputMuted && !AudioScriptingInterface.muted) {
AudioScriptingInterface.muted = true; AudioScriptingInterface.muted = true;
} }

View file

@ -242,33 +242,32 @@ var savedAvatarGain = Audio.avatarGain;
var savedServerInjectorGain = Audio.serverInjectorGain; var savedServerInjectorGain = Audio.serverInjectorGain;
var savedLocalInjectorGain = Audio.localInjectorGain; var savedLocalInjectorGain = Audio.localInjectorGain;
var savedSystemInjectorGain = Audio.systemInjectorGain; var savedSystemInjectorGain = Audio.systemInjectorGain;
var MUTED_VALUE_DB = -60; // This should always match `SimplifiedConstants.qml` -> numericConstants -> mutedValue!
function setOutputMuted(outputMuted) { function setOutputMuted(outputMuted) {
updateOutputDeviceMutedOverlay(outputMuted);
if (outputMuted) { if (outputMuted) {
savedAvatarGain = Audio.avatarGain; savedAvatarGain = Audio.avatarGain;
savedServerInjectorGain = Audio.serverInjectorGain; savedServerInjectorGain = Audio.serverInjectorGain;
savedLocalInjectorGain = Audio.localInjectorGain; savedLocalInjectorGain = Audio.localInjectorGain;
savedSystemInjectorGain = Audio.systemInjectorGain; savedSystemInjectorGain = Audio.systemInjectorGain;
Audio.avatarGain = -60; Audio.avatarGain = MUTED_VALUE_DB;
Audio.serverInjectorGain = -60; Audio.serverInjectorGain = MUTED_VALUE_DB;
Audio.localInjectorGain = -60; Audio.localInjectorGain = MUTED_VALUE_DB;
Audio.systemInjectorGain = -60; Audio.systemInjectorGain = MUTED_VALUE_DB;
} else { } else {
if (savedAvatarGain === -60) { if (savedAvatarGain === MUTED_VALUE_DB) {
savedAvatarGain = 0; savedAvatarGain = 0;
} }
Audio.avatarGain = savedAvatarGain; Audio.avatarGain = savedAvatarGain;
if (savedServerInjectorGain === -60) { if (savedServerInjectorGain === MUTED_VALUE_DB) {
savedServerInjectorGain = 0; savedServerInjectorGain = 0;
} }
Audio.serverInjectorGain = savedServerInjectorGain; Audio.serverInjectorGain = savedServerInjectorGain;
if (savedLocalInjectorGain === -60) { if (savedLocalInjectorGain === MUTED_VALUE_DB) {
savedLocalInjectorGain = 0; savedLocalInjectorGain = 0;
} }
Audio.localInjectorGain = savedLocalInjectorGain; Audio.localInjectorGain = savedLocalInjectorGain;
if (savedSystemInjectorGain === -60) { if (savedSystemInjectorGain === MUTED_VALUE_DB) {
savedSystemInjectorGain = 0; savedSystemInjectorGain = 0;
} }
Audio.systemInjectorGain = savedSystemInjectorGain; Audio.systemInjectorGain = savedSystemInjectorGain;
@ -334,7 +333,10 @@ function onTopBarClosed() {
function isOutputMuted() { function isOutputMuted() {
return Audio.avatarGain === -60 && Audio.serverInjectorGain === -60 && Audio.localInjectorGain === -60 && Audio.systemInjectorGain === -60; return Audio.avatarGain === MUTED_VALUE_DB &&
Audio.serverInjectorGain === MUTED_VALUE_DB &&
Audio.localInjectorGain === MUTED_VALUE_DB &&
Audio.systemInjectorGain === MUTED_VALUE_DB;
} }
@ -461,6 +463,11 @@ function onStatusChanged() {
} }
function maybeUpdateOutputDeviceMutedOverlay() {
updateOutputDeviceMutedOverlay(isOutputMuted());
}
var simplifiedNametag = Script.require("./simplifiedNametag/simplifiedNametag.js?" + Date.now()); var simplifiedNametag = Script.require("./simplifiedNametag/simplifiedNametag.js?" + Date.now());
var SimplifiedStatusIndicator = Script.require("./simplifiedStatusIndicator/simplifiedStatusIndicator.js?" + Date.now()); var SimplifiedStatusIndicator = Script.require("./simplifiedStatusIndicator/simplifiedStatusIndicator.js?" + Date.now());
var si; var si;
@ -493,6 +500,10 @@ function startup() {
Audio.mutedDesktopChanged.connect(onDesktopInputDeviceMutedChanged); Audio.mutedDesktopChanged.connect(onDesktopInputDeviceMutedChanged);
Window.geometryChanged.connect(onGeometryChanged); Window.geometryChanged.connect(onGeometryChanged);
HMD.displayModeChanged.connect(ensureFirstPersonCameraInHMD); HMD.displayModeChanged.connect(ensureFirstPersonCameraInHMD);
Audio.avatarGainChanged.connect(maybeUpdateOutputDeviceMutedOverlay);
Audio.localInjectorGainChanged.connect(maybeUpdateOutputDeviceMutedOverlay);
Audio.serverInjectorGainChanged.connect(maybeUpdateOutputDeviceMutedOverlay);
Audio.systemInjectorGainChanged.connect(maybeUpdateOutputDeviceMutedOverlay);
oldShowAudioTools = AvatarInputs.showAudioTools; oldShowAudioTools = AvatarInputs.showAudioTools;
AvatarInputs.showAudioTools = false; AvatarInputs.showAudioTools = false;
@ -543,6 +554,10 @@ function shutdown() {
Audio.mutedDesktopChanged.disconnect(onDesktopInputDeviceMutedChanged); Audio.mutedDesktopChanged.disconnect(onDesktopInputDeviceMutedChanged);
Window.geometryChanged.disconnect(onGeometryChanged); Window.geometryChanged.disconnect(onGeometryChanged);
HMD.displayModeChanged.disconnect(ensureFirstPersonCameraInHMD); HMD.displayModeChanged.disconnect(ensureFirstPersonCameraInHMD);
Audio.avatarGainChanged.disconnect(maybeUpdateOutputDeviceMutedOverlay);
Audio.localInjectorGainChanged.disconnect(maybeUpdateOutputDeviceMutedOverlay);
Audio.serverInjectorGainChanged.disconnect(maybeUpdateOutputDeviceMutedOverlay);
Audio.systemInjectorGainChanged.disconnect(maybeUpdateOutputDeviceMutedOverlay);
AvatarInputs.showAudioTools = oldShowAudioTools; AvatarInputs.showAudioTools = oldShowAudioTools;
AvatarInputs.showBubbleTools = oldShowBubbleTools; AvatarInputs.showBubbleTools = oldShowBubbleTools;