laying groundwork for audio app + fixing deadlocks

This commit is contained in:
Wayne Chen 2019-03-06 11:00:09 -08:00 committed by Wayne Chen
parent 15d49fd9a9
commit 7cb17b2d6e
4 changed files with 69 additions and 57 deletions

View file

@ -134,7 +134,7 @@ Rectangle {
Item {
id: status;
readonly property string color: (AudioScriptingInterface.pushingToTalk && AudioScriptingInterface.muted) ? hifi.colors.blueHighlight : AudioScriptingInterface.muted ? colors.muted : colors.unmuted;
readonly property string color: AudioScriptingInterface.pushToTalk ? hifi.colors.blueHighlight : AudioScriptingInterface.muted ? colors.muted : colors.unmuted;
visible: AudioScriptingInterface.pushingToTalk || AudioScriptingInterface.muted;
@ -165,7 +165,7 @@ Rectangle {
verticalCenter: parent.verticalCenter;
}
width: 50;
width: AudioScriptingInterface.pushToTalk ? (AudioScriptingInterface.pushingToTalk ? 45: 30) : 50;
height: 4;
color: parent.color;
}
@ -176,7 +176,7 @@ Rectangle {
verticalCenter: parent.verticalCenter;
}
width: 50;
width: AudioScriptingInterface.pushToTalk ? (AudioScriptingInterface.pushingToTalk ? 45: 30) : 50;
height: 4;
color: parent.color;
}

View file

@ -66,32 +66,30 @@ bool Audio::isMuted() const {
bool isHMD = qApp->isHMDMode();
if (isHMD) {
return getMutedHMD();
}
else {
} else {
return getMutedDesktop();
}
}
void Audio::setMuted(bool isMuted) {
withWriteLock([&] {
bool isHMD = qApp->isHMDMode();
if (isHMD) {
setMutedHMD(isMuted);
}
else {
setMutedDesktop(isMuted);
}
});
bool isHMD = qApp->isHMDMode();
if (isHMD) {
setMutedHMD(isMuted);
} else {
setMutedDesktop(isMuted);
}
}
void Audio::setMutedDesktop(bool isMuted) {
bool changed = false;
if (_desktopMuted != isMuted) {
changed = true;
_desktopMuted = isMuted;
auto client = DependencyManager::get<AudioClient>().data();
QMetaObject::invokeMethod(client, "setMuted", Q_ARG(bool, isMuted), Q_ARG(bool, false));
}
withWriteLock([&] {
if (_desktopMuted != isMuted) {
changed = true;
_desktopMuted = isMuted;
auto client = DependencyManager::get<AudioClient>().data();
QMetaObject::invokeMethod(client, "setMuted", Q_ARG(bool, isMuted), Q_ARG(bool, false));
}
});
if (changed) {
emit mutedChanged(isMuted);
emit desktopMutedChanged(isMuted);
@ -106,12 +104,14 @@ bool Audio::getMutedDesktop() const {
void Audio::setMutedHMD(bool isMuted) {
bool changed = false;
if (_hmdMuted != isMuted) {
changed = true;
_hmdMuted = isMuted;
auto client = DependencyManager::get<AudioClient>().data();
QMetaObject::invokeMethod(client, "setMuted", Q_ARG(bool, isMuted), Q_ARG(bool, false));
}
withWriteLock([&] {
if (_hmdMuted != isMuted) {
changed = true;
_hmdMuted = isMuted;
auto client = DependencyManager::get<AudioClient>().data();
QMetaObject::invokeMethod(client, "setMuted", Q_ARG(bool, isMuted), Q_ARG(bool, false));
}
});
if (changed) {
emit mutedChanged(isMuted);
emit hmdMutedChanged(isMuted);
@ -128,12 +128,24 @@ bool Audio::getPTT() {
bool isHMD = qApp->isHMDMode();
if (isHMD) {
return getPTTHMD();
}
else {
} else {
return getPTTDesktop();
}
}
void scripting::Audio::setPushingToTalk(bool pushingToTalk) {
bool changed = false;
withWriteLock([&] {
if (_pushingToTalk != pushingToTalk) {
changed = true;
_pushingToTalk = pushingToTalk;
}
});
if (changed) {
emit pushingToTalkChanged(pushingToTalk);
}
}
bool Audio::getPushingToTalk() const {
return resultWithReadLock<bool>([&] {
return _pushingToTalk;
@ -144,8 +156,7 @@ void Audio::setPTT(bool enabled) {
bool isHMD = qApp->isHMDMode();
if (isHMD) {
setPTTHMD(enabled);
}
else {
} else {
setPTTDesktop(enabled);
}
}
@ -156,16 +167,16 @@ void Audio::setPTTDesktop(bool enabled) {
if (_pttDesktop != enabled) {
changed = true;
_pttDesktop = enabled;
if (!enabled) {
// Set to default behavior (unmuted for Desktop) on Push-To-Talk disable.
setMutedDesktop(true);
}
else {
// Should be muted when not pushing to talk while PTT is enabled.
setMutedDesktop(true);
}
}
});
if (!enabled) {
// Set to default behavior (unmuted for Desktop) on Push-To-Talk disable.
setMutedDesktop(true);
} else {
// Should be muted when not pushing to talk while PTT is enabled.
setMutedDesktop(true);
}
if (changed) {
emit pushToTalkChanged(enabled);
emit pushToTalkDesktopChanged(enabled);
@ -184,16 +195,16 @@ void Audio::setPTTHMD(bool enabled) {
if (_pttHMD != enabled) {
changed = true;
_pttHMD = enabled;
if (!enabled) {
// Set to default behavior (unmuted for HMD) on Push-To-Talk disable.
setMutedHMD(false);
}
else {
// Should be muted when not pushing to talk while PTT is enabled.
setMutedHMD(true);
}
}
});
if (!enabled) {
// Set to default behavior (unmuted for HMD) on Push-To-Talk disable.
setMutedHMD(false);
} else {
// Should be muted when not pushing to talk while PTT is enabled.
setMutedHMD(true);
}
if (changed) {
emit pushToTalkChanged(enabled);
emit pushToTalkHMDChanged(enabled);
@ -318,8 +329,7 @@ void Audio::onContextChanged() {
});
if (isHMD) {
setMuted(getMutedHMD());
}
else {
} else {
setMuted(getMutedDesktop());
}
if (changed) {
@ -331,14 +341,10 @@ void Audio::handlePushedToTalk(bool enabled) {
if (getPTT()) {
if (enabled) {
setMuted(false);
}
else {
} else {
setMuted(true);
}
if (_pushingToTalk != enabled) {
_pushingToTalk = enabled;
emit pushingToTalkChanged(enabled);
}
setPushingToTalk(enabled);
}
}

View file

@ -99,6 +99,7 @@ public:
bool getMutedHMD() const;
void setPTT(bool enabled);
bool getPTT();
void setPushingToTalk(bool pushingToTalk);
bool getPushingToTalk() const;
// Push-To-Talk setters and getters

View file

@ -26,12 +26,15 @@ var UNMUTE_ICONS = {
icon: "icons/tablet-icons/mic-unmute-i.svg",
activeIcon: "icons/tablet-icons/mic-unmute-a.svg"
};
var PTT_ICONS = {
icon: "icons/tablet-icons/mic-unmute-i.svg",
activeIcon: "icons/tablet-icons/mic-unmute-a.svg"
};
function onMuteToggled() {
if (Audio.pushingToTalk) {
return;
}
if (Audio.muted) {
button.editProperties(PTT_ICONS);
} else if (Audio.muted) {
button.editProperties(MUTE_ICONS);
} else {
button.editProperties(UNMUTE_ICONS);
@ -71,6 +74,7 @@ onMuteToggled();
button.clicked.connect(onClicked);
tablet.screenChanged.connect(onScreenChanged);
Audio.mutedChanged.connect(onMuteToggled);
Audio.pushingToTalkChanged.connect(onMuteToggled);
Script.scriptEnding.connect(function () {
if (onAudioScreen) {
@ -79,6 +83,7 @@ Script.scriptEnding.connect(function () {
button.clicked.disconnect(onClicked);
tablet.screenChanged.disconnect(onScreenChanged);
Audio.mutedChanged.disconnect(onMuteToggled);
Audio.pushingToTalkChanged.disconnect(onMuteToggled);
tablet.removeButton(button);
});