From 46ee148a69d345326f167bbb15665f5b277fcf12 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 22 May 2019 15:24:33 -0700 Subject: [PATCH] Fix a bug and remove magic numbers --- .../simplifiedUI/settingsApp/audio/Audio.qml | 6 +-- .../SimplifiedConstants.qml | 4 ++ .../simplifiedUI/topBar/SimplifiedTopBar.qml | 8 ++-- scripts/system/simplifiedUI/simplifiedUI.js | 37 +++++++++++++------ 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/interface/resources/qml/hifi/simplifiedUI/settingsApp/audio/Audio.qml b/interface/resources/qml/hifi/simplifiedUI/settingsApp/audio/Audio.qml index bb64e835d5..9ac72fa3cd 100644 --- a/interface/resources/qml/hifi/simplifiedUI/settingsApp/audio/Audio.qml +++ b/interface/resources/qml/hifi/simplifiedUI/settingsApp/audio/Audio.qml @@ -73,7 +73,7 @@ Flickable { Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin height: 30 labelText: "People Volume" - from: -60.0 + from: simplifiedUI.numericConstants.mutedValue to: 20.0 defaultValue: 0.0 stepSize: 5.0 @@ -101,7 +101,7 @@ Flickable { Layout.topMargin: 2 height: 30 labelText: "Environment Volume" - from: -60.0 + from: simplifiedUI.numericConstants.mutedValue to: 20.0 defaultValue: 0.0 stepSize: 5.0 @@ -130,7 +130,7 @@ Flickable { Layout.topMargin: 2 height: 30 labelText: "System Sound Volume" - from: -60.0 + from: simplifiedUI.numericConstants.mutedValue to: 20.0 defaultValue: 0.0 stepSize: 5.0 diff --git a/interface/resources/qml/hifi/simplifiedUI/simplifiedConstants/SimplifiedConstants.qml b/interface/resources/qml/hifi/simplifiedUI/simplifiedConstants/SimplifiedConstants.qml index 752c989500..1f628b041d 100644 --- a/interface/resources/qml/hifi/simplifiedUI/simplifiedConstants/SimplifiedConstants.qml +++ b/interface/resources/qml/hifi/simplifiedUI/simplifiedConstants/SimplifiedConstants.qml @@ -221,4 +221,8 @@ QtObject { } } } + + readonly property QtObject numericConstants: QtObject { + readonly property real mutedValue: -60.0 + } } diff --git a/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml b/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml index 1a85e6fbae..27a786ece2 100644 --- a/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml +++ b/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml @@ -203,8 +203,10 @@ Rectangle { Image { id: outputDeviceButton - property bool outputMuted: AudioScriptingInterface.avatarGain === -60 && - AudioScriptingInterface.serverInjectorGain === -60 && AudioScriptingInterface.localInjectorGain === -60 && AudioScriptingInterface.systemInjectorGain === -60 + property bool outputMuted: AudioScriptingInterface.avatarGain === simplifiedUI.numericConstants.mutedValue && + AudioScriptingInterface.serverInjectorGain === simplifiedUI.numericConstants.mutedValue && + AudioScriptingInterface.localInjectorGain === simplifiedUI.numericConstants.mutedValue && + AudioScriptingInterface.systemInjectorGain === simplifiedUI.numericConstants.mutedValue source: outputDeviceButton.outputMuted ? "./images/outputDeviceMuted.svg" : "./images/outputDeviceLoud.svg" anchors.centerIn: parent width: 20 @@ -230,7 +232,7 @@ Rectangle { onClicked: { Tablet.playSound(TabletEnums.ButtonClick); - if (outputDeviceButton.outputMuted && !AudioScriptingInterface.muted) { + if (!outputDeviceButton.outputMuted && !AudioScriptingInterface.muted) { AudioScriptingInterface.muted = true; } diff --git a/scripts/system/simplifiedUI/simplifiedUI.js b/scripts/system/simplifiedUI/simplifiedUI.js index d55663edab..351372613b 100644 --- a/scripts/system/simplifiedUI/simplifiedUI.js +++ b/scripts/system/simplifiedUI/simplifiedUI.js @@ -242,33 +242,32 @@ var savedAvatarGain = Audio.avatarGain; var savedServerInjectorGain = Audio.serverInjectorGain; var savedLocalInjectorGain = Audio.localInjectorGain; var savedSystemInjectorGain = Audio.systemInjectorGain; +var MUTED_VALUE_DB = -60; // This should always match `SimplifiedConstants.qml` -> numericConstants -> mutedValue! function setOutputMuted(outputMuted) { - updateOutputDeviceMutedOverlay(outputMuted); - if (outputMuted) { savedAvatarGain = Audio.avatarGain; savedServerInjectorGain = Audio.serverInjectorGain; savedLocalInjectorGain = Audio.localInjectorGain; savedSystemInjectorGain = Audio.systemInjectorGain; - Audio.avatarGain = -60; - Audio.serverInjectorGain = -60; - Audio.localInjectorGain = -60; - Audio.systemInjectorGain = -60; + Audio.avatarGain = MUTED_VALUE_DB; + Audio.serverInjectorGain = MUTED_VALUE_DB; + Audio.localInjectorGain = MUTED_VALUE_DB; + Audio.systemInjectorGain = MUTED_VALUE_DB; } else { - if (savedAvatarGain === -60) { + if (savedAvatarGain === MUTED_VALUE_DB) { savedAvatarGain = 0; } Audio.avatarGain = savedAvatarGain; - if (savedServerInjectorGain === -60) { + if (savedServerInjectorGain === MUTED_VALUE_DB) { savedServerInjectorGain = 0; } Audio.serverInjectorGain = savedServerInjectorGain; - if (savedLocalInjectorGain === -60) { + if (savedLocalInjectorGain === MUTED_VALUE_DB) { savedLocalInjectorGain = 0; } Audio.localInjectorGain = savedLocalInjectorGain; - if (savedSystemInjectorGain === -60) { + if (savedSystemInjectorGain === MUTED_VALUE_DB) { savedSystemInjectorGain = 0; } Audio.systemInjectorGain = savedSystemInjectorGain; @@ -334,7 +333,10 @@ function onTopBarClosed() { 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 SimplifiedStatusIndicator = Script.require("./simplifiedStatusIndicator/simplifiedStatusIndicator.js?" + Date.now()); var si; @@ -493,6 +500,10 @@ function startup() { Audio.mutedDesktopChanged.connect(onDesktopInputDeviceMutedChanged); Window.geometryChanged.connect(onGeometryChanged); HMD.displayModeChanged.connect(ensureFirstPersonCameraInHMD); + Audio.avatarGainChanged.connect(maybeUpdateOutputDeviceMutedOverlay); + Audio.localInjectorGainChanged.connect(maybeUpdateOutputDeviceMutedOverlay); + Audio.serverInjectorGainChanged.connect(maybeUpdateOutputDeviceMutedOverlay); + Audio.systemInjectorGainChanged.connect(maybeUpdateOutputDeviceMutedOverlay); oldShowAudioTools = AvatarInputs.showAudioTools; AvatarInputs.showAudioTools = false; @@ -543,6 +554,10 @@ function shutdown() { Audio.mutedDesktopChanged.disconnect(onDesktopInputDeviceMutedChanged); Window.geometryChanged.disconnect(onGeometryChanged); HMD.displayModeChanged.disconnect(ensureFirstPersonCameraInHMD); + Audio.avatarGainChanged.disconnect(maybeUpdateOutputDeviceMutedOverlay); + Audio.localInjectorGainChanged.disconnect(maybeUpdateOutputDeviceMutedOverlay); + Audio.serverInjectorGainChanged.disconnect(maybeUpdateOutputDeviceMutedOverlay); + Audio.systemInjectorGainChanged.disconnect(maybeUpdateOutputDeviceMutedOverlay); AvatarInputs.showAudioTools = oldShowAudioTools; AvatarInputs.showBubbleTools = oldShowBubbleTools;