Make stereo interface async

This commit is contained in:
Atlante45 2018-06-18 17:25:38 -07:00
parent 29ff47c6fb
commit 4a4c0d132e
5 changed files with 36 additions and 19 deletions

View file

@ -129,12 +129,10 @@ Rectangle {
id: stereoMic
spacing: muteMic.spacing;
text: qsTr("Enable stereo input");
checked: AudioScriptingInterface.isStereoInput();
checked: AudioScriptingInterface.isStereoInput;
onClicked: {
var success = AudioScriptingInterface.setStereoInput(checked);
if (!success) {
checked = !checked;
}
AudioScriptingInterface.isStereoInput = checked;
checked = Qt.binding(function() { return AudioScriptingInterface.isStereoInput; }); // restore binding
}
}
}

View file

@ -1426,6 +1426,8 @@ bool AudioClient::setIsStereoInput(bool isStereoInput) {
// restart the input device
switchInputToAudioDevice(_inputDeviceInfo);
emit isStereoInputChanged(_isStereoInput);
}
return stereoInputChanged;

View file

@ -44,6 +44,9 @@ public slots:
virtual bool setIsStereoInput(bool stereo) = 0;
virtual bool isStereoInput() = 0;
signals:
void isStereoInputChanged(bool isStereo);
};
Q_DECLARE_METATYPE(AbstractAudioInterface*)

View file

@ -23,6 +23,21 @@ void registerAudioMetaTypes(QScriptEngine* engine) {
qScriptRegisterMetaType(engine, soundSharedPointerToScriptValue, soundSharedPointerFromScriptValue);
}
void AudioScriptingInterface::setLocalAudioInterface(AbstractAudioInterface* audioInterface) {
if (_localAudioInterface) {
disconnect(_localAudioInterface, &AbstractAudioInterface::isStereoInputChanged,
this, &AudioScriptingInterface::isStereoInputChanged);
}
_localAudioInterface = audioInterface;
if (_localAudioInterface) {
connect(_localAudioInterface, &AbstractAudioInterface::isStereoInputChanged,
this, &AudioScriptingInterface::isStereoInputChanged);
}
}
ScriptAudioInjector* AudioScriptingInterface::playSystemSound(SharedSoundPointer sound, const QVector3D& position) {
AudioInjectorOptions options;
options.position = glm::vec3(position.x(), position.y(), position.z());
@ -60,19 +75,10 @@ ScriptAudioInjector* AudioScriptingInterface::playSound(SharedSoundPointer sound
}
}
bool AudioScriptingInterface::setStereoInput(bool stereo) {
bool stereoInputChanged = false;
void AudioScriptingInterface::setStereoInput(bool stereo) {
if (_localAudioInterface) {
if (QThread::currentThread() != _localAudioInterface->thread()) {
// TODO: This can block the main thread which is not ideal, make this function and the UI calling it async
BLOCKING_INVOKE_METHOD(_localAudioInterface, "setIsStereoInput", Q_RETURN_ARG(bool, stereoInputChanged),
Q_ARG(bool, stereo));
} else {
stereoInputChanged = _localAudioInterface->setIsStereoInput(stereo);
}
QMetaObject::invokeMethod(_localAudioInterface, "setIsStereoInput", Q_ARG(bool, stereo));
}
return stereoInputChanged;
}
bool AudioScriptingInterface::isStereoInput() {

View file

@ -23,9 +23,11 @@ class AudioScriptingInterface : public QObject, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
Q_PROPERTY(bool isStereoInput READ isStereoInput WRITE setStereoInput NOTIFY isStereoInputChanged)
public:
virtual ~AudioScriptingInterface() {}
void setLocalAudioInterface(AbstractAudioInterface* audioInterface) { _localAudioInterface = audioInterface; }
void setLocalAudioInterface(AbstractAudioInterface* audioInterface);
protected:
AudioScriptingInterface() {}
@ -52,9 +54,8 @@ protected:
/**jsdoc
* @function Audio.setStereoInput
* @param {boolean} stereo
* @returns {boolean}
*/
Q_INVOKABLE bool setStereoInput(bool stereo);
Q_INVOKABLE void setStereoInput(bool stereo);
/**jsdoc
* @function Audio.isStereoInput
@ -114,6 +115,13 @@ signals:
*/
void inputReceived(const QByteArray& inputSamples);
/**jsdoc
* @function Audio.isStereoInputChanged
* @param {boolean} isStereo
* @returns {Signal}
*/
void isStereoInputChanged(bool isStereo);
private:
AbstractAudioInterface* _localAudioInterface { nullptr };
};