Merge pull request #15613 from zfox23/SUI/newAudioProperties

Fix the janky audio output settings UI
This commit is contained in:
Zach Fox 2019-05-22 16:45:02 -07:00 committed by GitHub
commit 934ea76966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 140 additions and 57 deletions

View file

@ -68,21 +68,20 @@ Flickable {
SimplifiedControls.Slider {
id: peopleVolume
property real lastValueSent
anchors.left: parent.left
anchors.right: parent.right
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
value: AudioScriptingInterface.getAvatarGain()
value: AudioScriptingInterface.avatarGain
live: true
function updatePeopleGain(sliderValue) {
if (AudioScriptingInterface.getAvatarGain() !== sliderValue) {
AudioScriptingInterface.setAvatarGain(sliderValue);
if (AudioScriptingInterface.avatarGain !== sliderValue) {
AudioScriptingInterface.avatarGain = sliderValue;
}
}
onValueChanged: {
@ -97,22 +96,21 @@ Flickable {
SimplifiedControls.Slider {
id: environmentVolume
property real lastValueSent
anchors.left: parent.left
anchors.right: parent.right
Layout.topMargin: 2
height: 30
labelText: "Environment Volume"
from: -60.0
from: simplifiedUI.numericConstants.mutedValue
to: 20.0
defaultValue: 0.0
stepSize: 5.0
value: AudioScriptingInterface.getInjectorGain()
value: AudioScriptingInterface.serverInjectorGain
live: true
function updateEnvironmentGain(sliderValue) {
if (AudioScriptingInterface.getInjectorGain() !== sliderValue) {
AudioScriptingInterface.setInjectorGain(sliderValue);
AudioScriptingInterface.setLocalInjectorGain(sliderValue);
if (AudioScriptingInterface.serverInjectorGain !== sliderValue) {
AudioScriptingInterface.serverInjectorGain = sliderValue;
AudioScriptingInterface.localInjectorGain = sliderValue;
}
}
onValueChanged: {
@ -127,21 +125,20 @@ Flickable {
SimplifiedControls.Slider {
id: systemSoundVolume
property real lastValueSent
anchors.left: parent.left
anchors.right: parent.right
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
value: AudioScriptingInterface.getSystemInjectorGain()
value: AudioScriptingInterface.systemInjectorGain
live: true
function updateSystemGain(sliderValue) {
if (AudioScriptingInterface.getSystemInjectorGain() !== sliderValue) {
AudioScriptingInterface.setSystemInjectorGain(sliderValue);
if (AudioScriptingInterface.systemInjectorGain !== sliderValue) {
AudioScriptingInterface.systemInjectorGain = sliderValue;
}
}
onValueChanged: {

View file

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

View file

@ -203,7 +203,10 @@ Rectangle {
Image {
id: outputDeviceButton
property bool outputMuted: false
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
@ -228,9 +231,8 @@ Rectangle {
}
onClicked: {
Tablet.playSound(TabletEnums.ButtonClick);
outputDeviceButton.outputMuted = !outputDeviceButton.outputMuted;
if (outputDeviceButton.outputMuted && !AudioScriptingInterface.muted) {
if (!outputDeviceButton.outputMuted && !AudioScriptingInterface.muted) {
AudioScriptingInterface.muted = true;
}
@ -238,7 +240,7 @@ Rectangle {
"source": "SimplifiedTopBar.qml",
"method": "setOutputMuted",
"data": {
"outputMuted": outputDeviceButton.outputMuted
"outputMuted": !outputDeviceButton.outputMuted
}
});
}
@ -454,10 +456,6 @@ Rectangle {
}
break;
case "updateOutputMuted":
outputDeviceButton.outputMuted = message.data.outputMuted;
break;
case "updateStatusButton":
statusButton.currentStatus = message.data.currentStatus;
break;

View file

@ -400,10 +400,19 @@ void Audio::setReverbOptions(const AudioEffectOptions* options) {
}
void Audio::setAvatarGain(float gain) {
bool changed = false;
if (getAvatarGain() != gain) {
changed = true;
}
withWriteLock([&] {
// ask the NodeList to set the master avatar gain
DependencyManager::get<NodeList>()->setAvatarGain(QUuid(), gain);
});
if (changed) {
emit avatarGainChanged(gain);
}
}
float Audio::getAvatarGain() {
@ -413,10 +422,19 @@ float Audio::getAvatarGain() {
}
void Audio::setInjectorGain(float gain) {
bool changed = false;
if (getInjectorGain() != gain) {
changed = true;
}
withWriteLock([&] {
// ask the NodeList to set the audio injector gain
DependencyManager::get<NodeList>()->setInjectorGain(gain);
});
if (changed) {
emit serverInjectorGainChanged(gain);
}
}
float Audio::getInjectorGain() {
@ -426,6 +444,11 @@ float Audio::getInjectorGain() {
}
void Audio::setLocalInjectorGain(float gain) {
bool changed = false;
if (getLocalInjectorGain() != gain) {
changed = true;
}
withWriteLock([&] {
if (_localInjectorGain != gain) {
_localInjectorGain = gain;
@ -436,6 +459,11 @@ void Audio::setLocalInjectorGain(float gain) {
DependencyManager::get<AudioClient>()->setLocalInjectorGain(gain);
}
});
if (changed) {
emit localInjectorGainChanged(gain);
}
}
float Audio::getLocalInjectorGain() {
@ -445,6 +473,11 @@ float Audio::getLocalInjectorGain() {
}
void Audio::setSystemInjectorGain(float gain) {
bool changed = false;
if (getSystemInjectorGain() != gain) {
changed = true;
}
withWriteLock([&] {
if (_systemInjectorGain != gain) {
_systemInjectorGain = gain;
@ -455,6 +488,10 @@ void Audio::setSystemInjectorGain(float gain) {
DependencyManager::get<AudioClient>()->setSystemInjectorGain(gain);
}
});
if (changed) {
emit systemInjectorGainChanged(gain);
}
}
float Audio::getSystemInjectorGain() {

View file

@ -66,6 +66,10 @@ class Audio : public AudioScriptingInterface, protected ReadWriteLockable {
* @property {boolean} pushToTalkHMD - <code>true</code> if HMD push-to-talk is enabled, otherwise <code>false</code>.
* @property {boolean} pushingToTalk - <code>true</code> if the user is currently pushing-to-talk, otherwise
* <code>false</code>.
* @property {float} avatarGain - The gain (relative volume) that avatars' voices are played at. This gain is used at the server.
* @property {float} localInjectorGain - The gain (relative volume) that local injectors (local environment sounds) are played at.
* @property {float} serverInjectorGain - The gain (relative volume) that server injectors (server environment sounds) are played at. This gain is used at the server.
* @property {float} systemInjectorGain - The gain (relative volume) that system sounds are played at.
*
* @comment The following properties are from AudioScriptingInterface.h.
* @property {boolean} isStereoInput - <code>true</code> if the input audio is being used in stereo, otherwise
@ -90,6 +94,10 @@ class Audio : public AudioScriptingInterface, protected ReadWriteLockable {
Q_PROPERTY(bool pushToTalkDesktop READ getPTTDesktop WRITE setPTTDesktop NOTIFY pushToTalkDesktopChanged)
Q_PROPERTY(bool pushToTalkHMD READ getPTTHMD WRITE setPTTHMD NOTIFY pushToTalkHMDChanged)
Q_PROPERTY(bool pushingToTalk READ getPushingToTalk WRITE setPushingToTalk NOTIFY pushingToTalkChanged)
Q_PROPERTY(float avatarGain READ getAvatarGain WRITE setAvatarGain NOTIFY avatarGainChanged)
Q_PROPERTY(float localInjectorGain READ getLocalInjectorGain WRITE setLocalInjectorGain NOTIFY localInjectorGainChanged)
Q_PROPERTY(float serverInjectorGain READ getInjectorGain WRITE setInjectorGain NOTIFY serverInjectorGainChanged)
Q_PROPERTY(float systemInjectorGain READ getSystemInjectorGain WRITE setSystemInjectorGain NOTIFY systemInjectorGainChanged)
public:
static QString AUDIO;
@ -412,6 +420,38 @@ signals:
*/
void pushingToTalkChanged(bool talking);
/**jsdoc
* Triggered when the avatar gain changes.
* @function Audio.avatarGainChanged
* @param {float} gain - The new avatar gain value.
* @returns {Signal}
*/
void avatarGainChanged(float gain);
/**jsdoc
* Triggered when the local injector gain changes.
* @function Audio.localInjectorGainChanged
* @param {float} gain - The new local injector gain value.
* @returns {Signal}
*/
void localInjectorGainChanged(float gain);
/**jsdoc
* Triggered when the server injector gain changes.
* @function Audio.serverInjectorGainChanged
* @param {float} gain - The new server injector gain value.
* @returns {Signal}
*/
void serverInjectorGainChanged(float gain);
/**jsdoc
* Triggered when the system injector gain changes.
* @function Audio.systemInjectorGainChanged
* @param {float} gain - The new system injector gain value.
* @returns {Signal}
*/
void systemInjectorGainChanged(float gain);
public slots:
/**jsdoc

View file

@ -238,40 +238,39 @@ function updateOutputDeviceMutedOverlay(isMuted) {
}
var savedAvatarGain = Audio.getAvatarGain();
var savedInjectorGain = Audio.getInjectorGain();
var savedLocalInjectorGain = Audio.getLocalInjectorGain();
var savedSystemInjectorGain = Audio.getSystemInjectorGain();
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.getAvatarGain();
savedInjectorGain = Audio.getInjectorGain();
savedLocalInjectorGain = Audio.getLocalInjectorGain();
savedSystemInjectorGain = Audio.getSystemInjectorGain();
savedAvatarGain = Audio.avatarGain;
savedServerInjectorGain = Audio.serverInjectorGain;
savedLocalInjectorGain = Audio.localInjectorGain;
savedSystemInjectorGain = Audio.systemInjectorGain;
Audio.setAvatarGain(-60);
Audio.setInjectorGain(-60);
Audio.setLocalInjectorGain(-60);
Audio.setSystemInjectorGain(-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.setAvatarGain(savedAvatarGain);
if (savedInjectorGain === -60) {
savedInjectorGain = 0;
Audio.avatarGain = savedAvatarGain;
if (savedServerInjectorGain === MUTED_VALUE_DB) {
savedServerInjectorGain = 0;
}
Audio.setInjectorGain(savedInjectorGain);
if (savedLocalInjectorGain === -60) {
Audio.serverInjectorGain = savedServerInjectorGain;
if (savedLocalInjectorGain === MUTED_VALUE_DB) {
savedLocalInjectorGain = 0;
}
Audio.setLocalInjectorGain(savedLocalInjectorGain);
if (savedSystemInjectorGain === -60) {
Audio.localInjectorGain = savedLocalInjectorGain;
if (savedSystemInjectorGain === MUTED_VALUE_DB) {
savedSystemInjectorGain = 0;
}
Audio.setSystemInjectorGain(savedSystemInjectorGain);
Audio.systemInjectorGain = savedSystemInjectorGain;
}
}
@ -334,7 +333,10 @@ function onTopBarClosed() {
function isOutputMuted() {
return Audio.getAvatarGain() === -60 && Audio.getInjectorGain() === -60 && Audio.getLocalInjectorGain() === -60 && Audio.getSystemInjectorGain() === -60;
return Audio.avatarGain === MUTED_VALUE_DB &&
Audio.serverInjectorGain === MUTED_VALUE_DB &&
Audio.localInjectorGain === MUTED_VALUE_DB &&
Audio.systemInjectorGain === MUTED_VALUE_DB;
}
@ -370,15 +372,7 @@ function loadSimplifiedTopBar() {
// The eventbridge takes a nonzero time to initialize, so we have to wait a bit
// for the QML to load and for that to happen before updating the UI.
Script.setTimeout(function() {
topBarWindow.sendToQml({
"source": "simplifiedUI.js",
"method": "updateOutputMuted",
"data": {
"outputMuted": isOutputMuted()
}
});
Script.setTimeout(function() {
sendLocalStatusToQml();
}, WAIT_FOR_TOP_BAR_MS);
}
@ -469,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;
@ -501,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;
@ -551,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;