mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Initial implementation (deadlocks still occurring in Audio.cpp)
This commit is contained in:
parent
29d5574d93
commit
23e8a8bed4
7 changed files with 302 additions and 12 deletions
|
@ -148,6 +148,25 @@ Rectangle {
|
|||
checked = Qt.binding(function() { return AudioScriptingInterface.noiseReduction; }); // restore binding
|
||||
}
|
||||
}
|
||||
AudioControls.CheckBox {
|
||||
spacing: muteMic.spacing
|
||||
text: qsTr("Push To Talk");
|
||||
checked: isVR ? AudioScriptingInterface.pushToTalkHMD : AudioScriptingInterface.pushToTalkDesktop;
|
||||
onClicked: {
|
||||
if (isVR) {
|
||||
AudioScriptingInterface.pushToTalkHMD = checked;
|
||||
} else {
|
||||
AudioScriptingInterface.pushToTalkDesktop = checked;
|
||||
}
|
||||
checked = Qt.binding(function() {
|
||||
if (isVR) {
|
||||
return AudioScriptingInterface.pushToTalkHMD;
|
||||
} else {
|
||||
return AudioScriptingInterface.pushToTalkDesktop;
|
||||
}
|
||||
}); // restore binding
|
||||
}
|
||||
}
|
||||
AudioControls.CheckBox {
|
||||
spacing: muteMic.spacing
|
||||
text: qsTr("Show audio level meter");
|
||||
|
|
|
@ -11,10 +11,13 @@
|
|||
|
||||
import QtQuick 2.5
|
||||
import QtGraphicalEffects 1.0
|
||||
import stylesUit 1.0
|
||||
|
||||
import TabletScriptingInterface 1.0
|
||||
|
||||
Rectangle {
|
||||
HifiConstants { id: hifi; }
|
||||
|
||||
readonly property var level: AudioScriptingInterface.inputLevel;
|
||||
|
||||
property bool gated: false;
|
||||
|
@ -131,9 +134,9 @@ Rectangle {
|
|||
Item {
|
||||
id: status;
|
||||
|
||||
readonly property string color: AudioScriptingInterface.muted ? colors.muted : colors.unmuted;
|
||||
readonly property string color: (AudioScriptingInterface.pushingToTalk && AudioScriptingInterface.muted) ? hifi.colors.blueHighlight : AudioScriptingInterface.muted ? colors.muted : colors.unmuted;
|
||||
|
||||
visible: AudioScriptingInterface.muted;
|
||||
visible: AudioScriptingInterface.pushingToTalk || AudioScriptingInterface.muted;
|
||||
|
||||
anchors {
|
||||
left: parent.left;
|
||||
|
@ -152,7 +155,7 @@ Rectangle {
|
|||
|
||||
color: parent.color;
|
||||
|
||||
text: AudioScriptingInterface.muted ? "MUTED" : "MUTE";
|
||||
text: AudioScriptingInterface.pushToTalk ? (AudioScriptingInterface.pushingToTalk ? "SPEAKING" : "PUSH TO TALK") : (AudioScriptingInterface.muted ? "MUTED" : "MUTE");
|
||||
font.pointSize: 12;
|
||||
}
|
||||
|
||||
|
|
|
@ -1431,6 +1431,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
|||
});
|
||||
connect(this, &Application::activeDisplayPluginChanged,
|
||||
reinterpret_cast<scripting::Audio*>(audioScriptingInterface.data()), &scripting::Audio::onContextChanged);
|
||||
connect(this, &Application::pushedToTalk,
|
||||
reinterpret_cast<scripting::Audio*>(audioScriptingInterface.data()), &scripting::Audio::handlePushedToTalk);
|
||||
}
|
||||
|
||||
// Create the rendering engine. This can be slow on some machines due to lots of
|
||||
|
@ -4195,6 +4197,10 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
}
|
||||
break;
|
||||
|
||||
case Qt::Key_T:
|
||||
emit pushedToTalk(true);
|
||||
break;
|
||||
|
||||
case Qt::Key_P: {
|
||||
if (!isShifted && !isMeta && !isOption && !event->isAutoRepeat()) {
|
||||
AudioInjectorOptions options;
|
||||
|
@ -4300,6 +4306,12 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
|
|||
if (_keyboardMouseDevice->isActive()) {
|
||||
_keyboardMouseDevice->keyReleaseEvent(event);
|
||||
}
|
||||
|
||||
switch (event->key()) {
|
||||
case Qt::Key_T:
|
||||
emit pushedToTalk(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::focusOutEvent(QFocusEvent* event) {
|
||||
|
@ -5243,6 +5255,9 @@ void Application::loadSettings() {
|
|||
}
|
||||
}
|
||||
|
||||
auto audioScriptingInterface = reinterpret_cast<scripting::Audio*>(DependencyManager::get<AudioScriptingInterface>().data());
|
||||
audioScriptingInterface->loadData();
|
||||
|
||||
getMyAvatar()->loadData();
|
||||
_settingsLoaded = true;
|
||||
}
|
||||
|
@ -5252,6 +5267,9 @@ void Application::saveSettings() const {
|
|||
DependencyManager::get<AudioClient>()->saveSettings();
|
||||
DependencyManager::get<LODManager>()->saveSettings();
|
||||
|
||||
auto audioScriptingInterface = reinterpret_cast<scripting::Audio*>(DependencyManager::get<AudioScriptingInterface>().data());
|
||||
audioScriptingInterface->saveData();
|
||||
|
||||
Menu::getInstance()->saveSettings();
|
||||
getMyAvatar()->saveData();
|
||||
PluginManager::getInstance()->saveSettings();
|
||||
|
|
|
@ -358,6 +358,8 @@ signals:
|
|||
|
||||
void miniTabletEnabledChanged(bool enabled);
|
||||
|
||||
void pushedToTalk(bool enabled);
|
||||
|
||||
public slots:
|
||||
QVector<EntityItemID> pasteEntities(float x, float y, float z);
|
||||
bool exportEntities(const QString& filename, const QVector<QUuid>& entityIDs, const glm::vec3* givenOffset = nullptr);
|
||||
|
|
|
@ -63,26 +63,163 @@ void Audio::stopRecording() {
|
|||
}
|
||||
|
||||
bool Audio::isMuted() const {
|
||||
return resultWithReadLock<bool>([&] {
|
||||
return _isMuted;
|
||||
});
|
||||
bool isHMD = qApp->isHMDMode();
|
||||
if (isHMD) {
|
||||
return getMutedHMD();
|
||||
}
|
||||
else {
|
||||
return getMutedDesktop();
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::setMuted(bool isMuted) {
|
||||
withWriteLock([&] {
|
||||
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));
|
||||
}
|
||||
if (changed) {
|
||||
emit mutedChanged(isMuted);
|
||||
emit desktopMutedChanged(isMuted);
|
||||
}
|
||||
}
|
||||
|
||||
bool Audio::getMutedDesktop() const {
|
||||
return resultWithReadLock<bool>([&] {
|
||||
return _desktopMuted;
|
||||
});
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
if (changed) {
|
||||
emit mutedChanged(isMuted);
|
||||
emit hmdMutedChanged(isMuted);
|
||||
}
|
||||
}
|
||||
|
||||
bool Audio::getMutedHMD() const {
|
||||
return resultWithReadLock<bool>([&] {
|
||||
return _hmdMuted;
|
||||
});
|
||||
}
|
||||
|
||||
bool Audio::getPTT() {
|
||||
bool isHMD = qApp->isHMDMode();
|
||||
if (isHMD) {
|
||||
return getPTTHMD();
|
||||
}
|
||||
else {
|
||||
return getPTTDesktop();
|
||||
}
|
||||
}
|
||||
|
||||
bool Audio::getPushingToTalk() const {
|
||||
return resultWithReadLock<bool>([&] {
|
||||
return _pushingToTalk;
|
||||
});
|
||||
}
|
||||
|
||||
void Audio::setPTT(bool enabled) {
|
||||
bool isHMD = qApp->isHMDMode();
|
||||
if (isHMD) {
|
||||
setPTTHMD(enabled);
|
||||
}
|
||||
else {
|
||||
setPTTDesktop(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::setPTTDesktop(bool enabled) {
|
||||
bool changed = false;
|
||||
withWriteLock([&] {
|
||||
if (_isMuted != isMuted) {
|
||||
_isMuted = isMuted;
|
||||
auto client = DependencyManager::get<AudioClient>().data();
|
||||
QMetaObject::invokeMethod(client, "setMuted", Q_ARG(bool, isMuted), Q_ARG(bool, false));
|
||||
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 (changed) {
|
||||
emit mutedChanged(isMuted);
|
||||
emit pushToTalkChanged(enabled);
|
||||
emit pushToTalkDesktopChanged(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
bool Audio::getPTTDesktop() const {
|
||||
return resultWithReadLock<bool>([&] {
|
||||
return _pttDesktop;
|
||||
});
|
||||
}
|
||||
|
||||
void Audio::setPTTHMD(bool enabled) {
|
||||
bool changed = false;
|
||||
withWriteLock([&] {
|
||||
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 (changed) {
|
||||
emit pushToTalkChanged(enabled);
|
||||
emit pushToTalkHMDChanged(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
bool Audio::getPTTHMD() const {
|
||||
return resultWithReadLock<bool>([&] {
|
||||
return _pttHMD;
|
||||
});
|
||||
}
|
||||
|
||||
void Audio::saveData() {
|
||||
_desktopMutedSetting.set(getMutedDesktop());
|
||||
_hmdMutedSetting.set(getMutedHMD());
|
||||
_pttDesktopSetting.set(getPTTDesktop());
|
||||
_pttHMDSetting.set(getPTTHMD());
|
||||
}
|
||||
|
||||
void Audio::loadData() {
|
||||
_desktopMuted = _desktopMutedSetting.get();
|
||||
_hmdMuted = _hmdMutedSetting.get();
|
||||
_pttDesktop = _pttDesktopSetting.get();
|
||||
_pttHMD = _pttHMDSetting.get();
|
||||
}
|
||||
|
||||
bool Audio::noiseReductionEnabled() const {
|
||||
return resultWithReadLock<bool>([&] {
|
||||
return _enableNoiseReduction;
|
||||
|
@ -179,11 +316,32 @@ void Audio::onContextChanged() {
|
|||
changed = true;
|
||||
}
|
||||
});
|
||||
if (isHMD) {
|
||||
setMuted(getMutedHMD());
|
||||
}
|
||||
else {
|
||||
setMuted(getMutedDesktop());
|
||||
}
|
||||
if (changed) {
|
||||
emit contextChanged(isHMD ? Audio::HMD : Audio::DESKTOP);
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::handlePushedToTalk(bool enabled) {
|
||||
if (getPTT()) {
|
||||
if (enabled) {
|
||||
setMuted(false);
|
||||
}
|
||||
else {
|
||||
setMuted(true);
|
||||
}
|
||||
if (_pushingToTalk != enabled) {
|
||||
_pushingToTalk = enabled;
|
||||
emit pushingToTalkChanged(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::setReverb(bool enable) {
|
||||
withWriteLock([&] {
|
||||
DependencyManager::get<AudioClient>()->setReverb(enable);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#ifndef hifi_scripting_Audio_h
|
||||
#define hifi_scripting_Audio_h
|
||||
|
||||
#include <functional>
|
||||
#include "AudioScriptingInterface.h"
|
||||
#include "AudioDevices.h"
|
||||
#include "AudioEffectOptions.h"
|
||||
|
@ -19,6 +20,9 @@
|
|||
#include "AudioFileWav.h"
|
||||
#include <shared/ReadWriteLockable.h>
|
||||
|
||||
using MutedGetter = std::function<bool()>;
|
||||
using MutedSetter = std::function<void(bool)>;
|
||||
|
||||
namespace scripting {
|
||||
|
||||
class Audio : public AudioScriptingInterface, protected ReadWriteLockable {
|
||||
|
@ -63,6 +67,12 @@ class Audio : public AudioScriptingInterface, protected ReadWriteLockable {
|
|||
Q_PROPERTY(bool clipping READ isClipping NOTIFY clippingChanged)
|
||||
Q_PROPERTY(QString context READ getContext NOTIFY contextChanged)
|
||||
Q_PROPERTY(AudioDevices* devices READ getDevices NOTIFY nop)
|
||||
Q_PROPERTY(bool desktopMuted READ getMutedDesktop WRITE setMutedDesktop NOTIFY desktopMutedChanged)
|
||||
Q_PROPERTY(bool hmdMuted READ getMutedHMD WRITE setMutedHMD NOTIFY hmdMutedChanged)
|
||||
Q_PROPERTY(bool pushToTalk READ getPTT WRITE setPTT NOTIFY pushToTalkChanged);
|
||||
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 NOTIFY pushingToTalkChanged)
|
||||
|
||||
public:
|
||||
static QString AUDIO;
|
||||
|
@ -82,6 +92,25 @@ public:
|
|||
|
||||
void showMicMeter(bool show);
|
||||
|
||||
// Mute setting setters and getters
|
||||
void setMutedDesktop(bool isMuted);
|
||||
bool getMutedDesktop() const;
|
||||
void setMutedHMD(bool isMuted);
|
||||
bool getMutedHMD() const;
|
||||
void setPTT(bool enabled);
|
||||
bool getPTT();
|
||||
bool getPushingToTalk() const;
|
||||
|
||||
// Push-To-Talk setters and getters
|
||||
void setPTTDesktop(bool enabled);
|
||||
bool getPTTDesktop() const;
|
||||
void setPTTHMD(bool enabled);
|
||||
bool getPTTHMD() const;
|
||||
|
||||
// Settings handlers
|
||||
void saveData();
|
||||
void loadData();
|
||||
|
||||
/**jsdoc
|
||||
* @function Audio.setInputDevice
|
||||
* @param {object} device
|
||||
|
@ -193,6 +222,46 @@ signals:
|
|||
*/
|
||||
void mutedChanged(bool isMuted);
|
||||
|
||||
/**jsdoc
|
||||
* Triggered when desktop audio input is muted or unmuted.
|
||||
* @function Audio.desktopMutedChanged
|
||||
* @param {boolean} isMuted - <code>true</code> if the audio input is muted for desktop mode, otherwise <code>false</code>.
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void desktopMutedChanged(bool isMuted);
|
||||
|
||||
/**jsdoc
|
||||
* Triggered when HMD audio input is muted or unmuted.
|
||||
* @function Audio.hmdMutedChanged
|
||||
* @param {boolean} isMuted - <code>true</code> if the audio input is muted for HMD mode, otherwise <code>false</code>.
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void hmdMutedChanged(bool isMuted);
|
||||
|
||||
/**
|
||||
* Triggered when Push-to-Talk has been enabled or disabled.
|
||||
* @function Audio.pushToTalkChanged
|
||||
* @param {boolean} enabled - <code>true</code> if Push-to-Talk is enabled, otherwise <code>false</code>.
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void pushToTalkChanged(bool enabled);
|
||||
|
||||
/**
|
||||
* Triggered when Push-to-Talk has been enabled or disabled for desktop mode.
|
||||
* @function Audio.pushToTalkDesktopChanged
|
||||
* @param {boolean} enabled - <code>true</code> if Push-to-Talk is emabled for Desktop mode, otherwise <code>false</code>.
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void pushToTalkDesktopChanged(bool enabled);
|
||||
|
||||
/**
|
||||
* Triggered when Push-to-Talk has been enabled or disabled for HMD mode.
|
||||
* @function Audio.pushToTalkHMDChanged
|
||||
* @param {boolean} enabled - <code>true</code> if Push-to-Talk is emabled for HMD mode, otherwise <code>false</code>.
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void pushToTalkHMDChanged(bool enabled);
|
||||
|
||||
/**jsdoc
|
||||
* Triggered when the audio input noise reduction is enabled or disabled.
|
||||
* @function Audio.noiseReductionChanged
|
||||
|
@ -237,6 +306,14 @@ signals:
|
|||
*/
|
||||
void contextChanged(const QString& context);
|
||||
|
||||
/**jsdoc
|
||||
* Triggered when pushing to talk.
|
||||
* @function Audio.pushingToTalkChanged
|
||||
* @param {boolean} talking - <code>true</code> if broadcasting with PTT, <code>false</code> otherwise.
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void pushingToTalkChanged(bool talking);
|
||||
|
||||
public slots:
|
||||
|
||||
/**jsdoc
|
||||
|
@ -245,6 +322,8 @@ public slots:
|
|||
*/
|
||||
void onContextChanged();
|
||||
|
||||
void handlePushedToTalk(bool enabled);
|
||||
|
||||
private slots:
|
||||
void setMuted(bool muted);
|
||||
void enableNoiseReduction(bool enable);
|
||||
|
@ -260,11 +339,19 @@ private:
|
|||
float _inputVolume { 1.0f };
|
||||
float _inputLevel { 0.0f };
|
||||
bool _isClipping { false };
|
||||
bool _isMuted { false };
|
||||
bool _enableNoiseReduction { true }; // Match default value of AudioClient::_isNoiseGateEnabled.
|
||||
bool _contextIsHMD { false };
|
||||
AudioDevices* getDevices() { return &_devices; }
|
||||
AudioDevices _devices;
|
||||
Setting::Handle<bool> _desktopMutedSetting{ QStringList { Audio::AUDIO, "desktopMuted" }, true };
|
||||
Setting::Handle<bool> _hmdMutedSetting{ QStringList { Audio::AUDIO, "hmdMuted" }, true };
|
||||
Setting::Handle<bool> _pttDesktopSetting{ QStringList { Audio::AUDIO, "pushToTalkDesktop" }, false };
|
||||
Setting::Handle<bool> _pttHMDSetting{ QStringList { Audio::AUDIO, "pushToTalkHMD" }, false };
|
||||
bool _desktopMuted{ true };
|
||||
bool _hmdMuted{ false };
|
||||
bool _pttDesktop{ false };
|
||||
bool _pttHMD{ false };
|
||||
bool _pushingToTalk{ false };
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -28,6 +28,9 @@ var UNMUTE_ICONS = {
|
|||
};
|
||||
|
||||
function onMuteToggled() {
|
||||
if (Audio.pushingToTalk) {
|
||||
return;
|
||||
}
|
||||
if (Audio.muted) {
|
||||
button.editProperties(MUTE_ICONS);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue