mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 07:22:43 +02:00
Make stereo interface async
This commit is contained in:
parent
29ff47c6fb
commit
4a4c0d132e
5 changed files with 36 additions and 19 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1426,6 +1426,8 @@ bool AudioClient::setIsStereoInput(bool isStereoInput) {
|
|||
|
||||
// restart the input device
|
||||
switchInputToAudioDevice(_inputDeviceInfo);
|
||||
|
||||
emit isStereoInputChanged(_isStereoInput);
|
||||
}
|
||||
|
||||
return stereoInputChanged;
|
||||
|
|
|
@ -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*)
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue