Fix the janky audio output settings UI

This commit is contained in:
Zach Fox 2019-05-22 13:57:09 -07:00
parent ddb299a387
commit 3a4bf2e8f7
5 changed files with 104 additions and 46 deletions

View file

@ -68,7 +68,6 @@ Flickable {
SimplifiedControls.Slider {
id: peopleVolume
property real lastValueSent
anchors.left: parent.left
anchors.right: parent.right
Layout.topMargin: simplifiedUI.margins.settings.settingsGroupTopMargin
@ -78,11 +77,11 @@ Flickable {
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,7 +96,6 @@ Flickable {
SimplifiedControls.Slider {
id: environmentVolume
property real lastValueSent
anchors.left: parent.left
anchors.right: parent.right
Layout.topMargin: 2
@ -107,12 +105,12 @@ Flickable {
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,7 +125,6 @@ Flickable {
SimplifiedControls.Slider {
id: systemSoundVolume
property real lastValueSent
anchors.left: parent.left
anchors.right: parent.right
Layout.topMargin: 2
@ -137,11 +134,11 @@ Flickable {
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

@ -203,7 +203,8 @@ Rectangle {
Image {
id: outputDeviceButton
property bool outputMuted: false
property bool outputMuted: AudioScriptingInterface.avatarGain === -60 &&
AudioScriptingInterface.serverInjectorGain === -60 && AudioScriptingInterface.localInjectorGain === -60 && AudioScriptingInterface.systemInjectorGain === -60
source: outputDeviceButton.outputMuted ? "./images/outputDeviceMuted.svg" : "./images/outputDeviceLoud.svg"
anchors.centerIn: parent
width: 20
@ -228,7 +229,6 @@ Rectangle {
}
onClicked: {
Tablet.playSound(TabletEnums.ButtonClick);
outputDeviceButton.outputMuted = !outputDeviceButton.outputMuted;
if (outputDeviceButton.outputMuted && !AudioScriptingInterface.muted) {
AudioScriptingInterface.muted = true;
@ -238,7 +238,7 @@ Rectangle {
"source": "SimplifiedTopBar.qml",
"method": "setOutputMuted",
"data": {
"outputMuted": outputDeviceButton.outputMuted
"outputMuted": !outputDeviceButton.outputMuted
}
});
}
@ -454,10 +454,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

@ -90,6 +90,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 +416,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,40 @@ function updateOutputDeviceMutedOverlay(isMuted) {
}
var savedAvatarGain = Audio.getAvatarGain();
var savedInjectorGain = Audio.getInjectorGain();
var savedLocalInjectorGain = Audio.getLocalInjectorGain();
var savedSystemInjectorGain = Audio.getSystemInjectorGain();
var savedAvatarGain = Audio.avatarGain;
var savedInjectorGain = Audio.serverInjectorGain;
var savedLocalInjectorGain = Audio.localInjectorGain;
var savedSystemInjectorGain = Audio.systemInjectorGain;
function setOutputMuted(outputMuted) {
updateOutputDeviceMutedOverlay(outputMuted);
if (outputMuted) {
savedAvatarGain = Audio.getAvatarGain();
savedInjectorGain = Audio.getInjectorGain();
savedLocalInjectorGain = Audio.getLocalInjectorGain();
savedSystemInjectorGain = Audio.getSystemInjectorGain();
savedAvatarGain = Audio.avatarGain;
savedInjectorGain = Audio.serverInjectorGain;
savedLocalInjectorGain = Audio.localInjectorGain;
savedSystemInjectorGain = Audio.systemInjectorGain;
Audio.setAvatarGain(-60);
Audio.setInjectorGain(-60);
Audio.setLocalInjectorGain(-60);
Audio.setSystemInjectorGain(-60);
Audio.avatarGain = -60;
Audio.serverInjectorGain = -60;
Audio.localInjectorGain = -60;
Audio.systemInjectorGain = -60;
} else {
if (savedAvatarGain === -60) {
savedAvatarGain = 0;
}
Audio.setAvatarGain(savedAvatarGain);
Audio.avatarGain = savedAvatarGain;
if (savedInjectorGain === -60) {
savedInjectorGain = 0;
}
Audio.setInjectorGain(savedInjectorGain);
Audio.serverInjectorGain = savedInjectorGain;
if (savedLocalInjectorGain === -60) {
savedLocalInjectorGain = 0;
}
Audio.setLocalInjectorGain(savedLocalInjectorGain);
Audio.localInjectorGain = savedLocalInjectorGain;
if (savedSystemInjectorGain === -60) {
savedSystemInjectorGain = 0;
}
Audio.setSystemInjectorGain(savedSystemInjectorGain);
Audio.systemInjectorGain = savedSystemInjectorGain;
}
}
@ -334,7 +334,7 @@ function onTopBarClosed() {
function isOutputMuted() {
return Audio.getAvatarGain() === -60 && Audio.getInjectorGain() === -60 && Audio.getLocalInjectorGain() === -60 && Audio.getSystemInjectorGain() === -60;
return Audio.avatarGain === -60 && Audio.serverInjectorGain === -60 && Audio.localInjectorGain === -60 && Audio.systemInjectorGain === -60;
}
@ -370,15 +370,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);
}