mirror of
https://github.com/overte-org/overte.git
synced 2025-06-22 18:41:11 +02:00
Move most of the logic to C++ model, speed up initialization. Reduce number of AudioClient blocking calls to minimum
This commit is contained in:
parent
7ab6909c77
commit
2d46f9d30e
7 changed files with 109 additions and 142 deletions
|
@ -162,7 +162,6 @@ Rectangle {
|
||||||
onCheckBoxClicked: {
|
onCheckBoxClicked: {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
AudioDevice.setInputDeviceAsync(devicename)
|
AudioDevice.setInputDeviceAsync(devicename)
|
||||||
Settings.setValue("audio_input_device", devicename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,7 +218,6 @@ Rectangle {
|
||||||
onCheckBoxClicked: {
|
onCheckBoxClicked: {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
AudioDevice.setOutputDeviceAsync(devicename)
|
AudioDevice.setOutputDeviceAsync(devicename)
|
||||||
Settings.setValue("audio_output_device", devicename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,21 +11,19 @@
|
||||||
|
|
||||||
#include "AudioClient.h"
|
#include "AudioClient.h"
|
||||||
#include "AudioDeviceScriptingInterface.h"
|
#include "AudioDeviceScriptingInterface.h"
|
||||||
|
#include "SettingsScriptingInterface.h"
|
||||||
|
|
||||||
AudioDeviceScriptingInterface* AudioDeviceScriptingInterface::getInstance() {
|
AudioDeviceScriptingInterface* AudioDeviceScriptingInterface::getInstance() {
|
||||||
static AudioDeviceScriptingInterface sharedInstance;
|
static AudioDeviceScriptingInterface sharedInstance;
|
||||||
return &sharedInstance;
|
return &sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList AudioDeviceScriptingInterface::inputAudioDevices() const
|
QStringList AudioDeviceScriptingInterface::inputAudioDevices() const {
|
||||||
{
|
return _inputAudioDevices;
|
||||||
return DependencyManager::get<AudioClient>()->getDeviceNames(QAudio::AudioInput).toList();;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList AudioDeviceScriptingInterface::outputAudioDevices() const
|
QStringList AudioDeviceScriptingInterface::outputAudioDevices() const {
|
||||||
{
|
return _outputAudioDevices;
|
||||||
return DependencyManager::get<AudioClient>()->getDeviceNames(QAudio::AudioOutput).toList();;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioDeviceScriptingInterface::muted()
|
bool AudioDeviceScriptingInterface::muted()
|
||||||
|
@ -44,6 +42,16 @@ AudioDeviceScriptingInterface::AudioDeviceScriptingInterface(): QAbstractListMod
|
||||||
this, &AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged, Qt::QueuedConnection);
|
this, &AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged, Qt::QueuedConnection);
|
||||||
//fill up model
|
//fill up model
|
||||||
onDeviceChanged();
|
onDeviceChanged();
|
||||||
|
//set up previously saved device
|
||||||
|
SettingsScriptingInterface *settings = SettingsScriptingInterface::getInstance();
|
||||||
|
const QString inDevice = settings->getValue("audio_input_device").toString();
|
||||||
|
if (inDevice != _currentInputDevice) {
|
||||||
|
setInputDeviceAsync(inDevice);
|
||||||
|
}
|
||||||
|
const QString outDevice = settings->getValue("audio_output_device").toString();
|
||||||
|
if (outDevice != _currentOutputDevice) {
|
||||||
|
setOutputDeviceAsync(outDevice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) {
|
bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) {
|
||||||
|
@ -64,6 +72,31 @@ bool AudioDeviceScriptingInterface::setOutputDevice(const QString& deviceName) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AudioDeviceScriptingInterface::setDeviceFromMenu(const QString &deviceMenuName) {
|
||||||
|
QAudio::Mode mode;
|
||||||
|
|
||||||
|
if (deviceMenuName.indexOf("for Output") != -1) {
|
||||||
|
mode = QAudio::AudioOutput;
|
||||||
|
} else if (deviceMenuName.indexOf("for Input") != -1) {
|
||||||
|
mode = QAudio::AudioInput;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ScriptingAudioDeviceInfo di: _devices) {
|
||||||
|
if (mode == di.mode && deviceMenuName.contains(di.name)) {
|
||||||
|
if (mode == QAudio::AudioOutput) {
|
||||||
|
setOutputDeviceAsync(di.name);
|
||||||
|
} else {
|
||||||
|
setInputDeviceAsync(di.name);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void AudioDeviceScriptingInterface::setInputDeviceAsync(const QString& deviceName) {
|
void AudioDeviceScriptingInterface::setInputDeviceAsync(const QString& deviceName) {
|
||||||
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "switchInputToAudioDevice",
|
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "switchInputToAudioDevice",
|
||||||
Qt::QueuedConnection,
|
Qt::QueuedConnection,
|
||||||
|
@ -167,38 +200,51 @@ QHash<int, QByteArray> AudioDeviceScriptingInterface::roleNames() const {
|
||||||
void AudioDeviceScriptingInterface::onDeviceChanged()
|
void AudioDeviceScriptingInterface::onDeviceChanged()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
_outputAudioDevices.clear();
|
||||||
_devices.clear();
|
_devices.clear();
|
||||||
const QString &outDevice = getOutputDevice();
|
_currentOutputDevice = getOutputDevice();
|
||||||
for (QString name: getOutputDevices()) {
|
for (QString name: getOutputDevices()) {
|
||||||
AudioDeviceInfo di;
|
ScriptingAudioDeviceInfo di;
|
||||||
di.name = name;
|
di.name = name;
|
||||||
di.selected = (name == outDevice);
|
di.selected = (name == _currentOutputDevice);
|
||||||
di.mode = QAudio::AudioOutput;
|
di.mode = QAudio::AudioOutput;
|
||||||
_devices.append(di);
|
_devices.append(di);
|
||||||
|
_outputAudioDevices.append(name);
|
||||||
}
|
}
|
||||||
const QString &inDevice = getInputDevice();
|
emit outputAudioDevicesChanged(_outputAudioDevices);
|
||||||
|
|
||||||
|
_inputAudioDevices.clear();
|
||||||
|
_currentInputDevice = getInputDevice();
|
||||||
for (QString name: getInputDevices()) {
|
for (QString name: getInputDevices()) {
|
||||||
AudioDeviceInfo di;
|
ScriptingAudioDeviceInfo di;
|
||||||
di.name = name;
|
di.name = name;
|
||||||
di.selected = (name == inDevice);
|
di.selected = (name == _currentInputDevice);
|
||||||
di.mode = QAudio::AudioInput;
|
di.mode = QAudio::AudioInput;
|
||||||
_devices.append(di);
|
_devices.append(di);
|
||||||
|
_inputAudioDevices.append(name);
|
||||||
}
|
}
|
||||||
|
emit inputAudioDevicesChanged(_inputAudioDevices);
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
emit deviceChanged();
|
emit deviceChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDeviceScriptingInterface::onCurrentInputDeviceChanged()
|
void AudioDeviceScriptingInterface::onCurrentInputDeviceChanged(const QString &name)
|
||||||
{
|
{
|
||||||
currentDeviceUpdate(getInputDevice(), QAudio::AudioInput);
|
currentDeviceUpdate(name, QAudio::AudioInput);
|
||||||
emit currentInputDeviceChanged();
|
//we got a signal that device changed. Save it now
|
||||||
|
SettingsScriptingInterface *settings = SettingsScriptingInterface::getInstance();
|
||||||
|
settings->setValue("audio_input_device", name);
|
||||||
|
emit currentInputDeviceChanged(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged()
|
void AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged(const QString &name)
|
||||||
{
|
{
|
||||||
currentDeviceUpdate(getOutputDevice(), QAudio::AudioOutput);
|
currentDeviceUpdate(name, QAudio::AudioOutput);
|
||||||
emit currentOutputDeviceChanged();
|
//we got a signal that device changed. Save it now
|
||||||
|
SettingsScriptingInterface *settings = SettingsScriptingInterface::getInstance();
|
||||||
|
settings->setValue("audio_output_device", name);
|
||||||
|
emit currentOutputDeviceChanged(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDeviceScriptingInterface::currentDeviceUpdate(const QString &name, QAudio::Mode mode)
|
void AudioDeviceScriptingInterface::currentDeviceUpdate(const QString &name, QAudio::Mode mode)
|
||||||
|
@ -207,7 +253,7 @@ void AudioDeviceScriptingInterface::currentDeviceUpdate(const QString &name, QAu
|
||||||
role.append(SelectedRole);
|
role.append(SelectedRole);
|
||||||
|
|
||||||
for (int i = 0; i < _devices.size(); i++) {
|
for (int i = 0; i < _devices.size(); i++) {
|
||||||
AudioDeviceInfo di = _devices.at(i);
|
ScriptingAudioDeviceInfo di = _devices.at(i);
|
||||||
if (di.mode != mode)
|
if (di.mode != mode)
|
||||||
continue;
|
continue;
|
||||||
if (di.selected && di.name != name ) {
|
if (di.selected && di.name != name ) {
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
class AudioEffectOptions;
|
class AudioEffectOptions;
|
||||||
|
|
||||||
struct AudioDeviceInfo {
|
struct ScriptingAudioDeviceInfo {
|
||||||
QString name;
|
QString name;
|
||||||
bool selected;
|
bool selected;
|
||||||
QAudio::Mode mode;
|
QAudio::Mode mode;
|
||||||
|
@ -52,13 +52,14 @@ public:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDeviceChanged();
|
void onDeviceChanged();
|
||||||
void onCurrentInputDeviceChanged();
|
void onCurrentInputDeviceChanged(const QString &name);
|
||||||
void onCurrentOutputDeviceChanged();
|
void onCurrentOutputDeviceChanged(const QString &name);
|
||||||
void currentDeviceUpdate(const QString &name, QAudio::Mode mode);
|
void currentDeviceUpdate(const QString &name, QAudio::Mode mode);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool setInputDevice(const QString& deviceName);
|
bool setInputDevice(const QString& deviceName);
|
||||||
bool setOutputDevice(const QString& deviceName);
|
bool setOutputDevice(const QString& deviceName);
|
||||||
|
bool setDeviceFromMenu(const QString& deviceMenuName);
|
||||||
|
|
||||||
QString getInputDevice();
|
QString getInputDevice();
|
||||||
QString getOutputDevice();
|
QString getOutputDevice();
|
||||||
|
@ -87,14 +88,20 @@ private:
|
||||||
signals:
|
signals:
|
||||||
void muteToggled();
|
void muteToggled();
|
||||||
void deviceChanged();
|
void deviceChanged();
|
||||||
void currentInputDeviceChanged();
|
void currentInputDeviceChanged(const QString &name);
|
||||||
void currentOutputDeviceChanged();
|
void currentOutputDeviceChanged(const QString &name);
|
||||||
void mutedChanged(bool muted);
|
void mutedChanged(bool muted);
|
||||||
void inputAudioDevicesChanged(QStringList inputAudioDevices);
|
void inputAudioDevicesChanged(QStringList inputAudioDevices);
|
||||||
void outputAudioDevicesChanged(QStringList outputAudioDevices);
|
void outputAudioDevicesChanged(QStringList outputAudioDevices);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<AudioDeviceInfo> _devices;
|
QVector<ScriptingAudioDeviceInfo> _devices;
|
||||||
|
|
||||||
|
QStringList _inputAudioDevices;
|
||||||
|
QStringList _outputAudioDevices;
|
||||||
|
|
||||||
|
QString _currentInputDevice;
|
||||||
|
QString _currentOutputDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AudioDeviceScriptingInterface_h
|
#endif // hifi_AudioDeviceScriptingInterface_h
|
||||||
|
|
|
@ -1375,7 +1375,7 @@ bool AudioClient::switchInputToAudioDevice(const QAudioDeviceInfo& inputDeviceIn
|
||||||
if (!inputDeviceInfo.isNull()) {
|
if (!inputDeviceInfo.isNull()) {
|
||||||
qCDebug(audioclient) << "The audio input device " << inputDeviceInfo.deviceName() << "is available.";
|
qCDebug(audioclient) << "The audio input device " << inputDeviceInfo.deviceName() << "is available.";
|
||||||
_inputAudioDeviceName = inputDeviceInfo.deviceName().trimmed();
|
_inputAudioDeviceName = inputDeviceInfo.deviceName().trimmed();
|
||||||
emit currentInputDeviceChanged();
|
emit currentInputDeviceChanged(_inputAudioDeviceName);
|
||||||
|
|
||||||
if (adjustedFormatForAudioDevice(inputDeviceInfo, _desiredInputFormat, _inputFormat)) {
|
if (adjustedFormatForAudioDevice(inputDeviceInfo, _desiredInputFormat, _inputFormat)) {
|
||||||
qCDebug(audioclient) << "The format to be used for audio input is" << _inputFormat;
|
qCDebug(audioclient) << "The format to be used for audio input is" << _inputFormat;
|
||||||
|
@ -1493,7 +1493,7 @@ bool AudioClient::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDevice
|
||||||
if (!outputDeviceInfo.isNull()) {
|
if (!outputDeviceInfo.isNull()) {
|
||||||
qCDebug(audioclient) << "The audio output device " << outputDeviceInfo.deviceName() << "is available.";
|
qCDebug(audioclient) << "The audio output device " << outputDeviceInfo.deviceName() << "is available.";
|
||||||
_outputAudioDeviceName = outputDeviceInfo.deviceName().trimmed();
|
_outputAudioDeviceName = outputDeviceInfo.deviceName().trimmed();
|
||||||
emit currentOutputDeviceChanged();
|
emit currentOutputDeviceChanged(_outputAudioDeviceName);
|
||||||
|
|
||||||
if (adjustedFormatForAudioDevice(outputDeviceInfo, _desiredOutputFormat, _outputFormat)) {
|
if (adjustedFormatForAudioDevice(outputDeviceInfo, _desiredOutputFormat, _outputFormat)) {
|
||||||
qCDebug(audioclient) << "The format to be used for audio output is" << _outputFormat;
|
qCDebug(audioclient) << "The format to be used for audio output is" << _outputFormat;
|
||||||
|
|
|
@ -238,8 +238,8 @@ signals:
|
||||||
|
|
||||||
void muteEnvironmentRequested(glm::vec3 position, float radius);
|
void muteEnvironmentRequested(glm::vec3 position, float radius);
|
||||||
|
|
||||||
void currentOutputDeviceChanged();
|
void currentOutputDeviceChanged(const QString &name);
|
||||||
void currentInputDeviceChanged();
|
void currentInputDeviceChanged(const QString &name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AudioClient();
|
AudioClient();
|
||||||
|
|
|
@ -24,6 +24,7 @@ class AudioScriptingInterface : public QObject, public Dependency {
|
||||||
SINGLETON_DEPENDENCY
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~AudioScriptingInterface() {}
|
||||||
void setLocalAudioInterface(AbstractAudioInterface* audioInterface) { _localAudioInterface = audioInterface; }
|
void setLocalAudioInterface(AbstractAudioInterface* audioInterface) { _localAudioInterface = audioInterface; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -17,18 +17,6 @@
|
||||||
|
|
||||||
const INPUT = "Input";
|
const INPUT = "Input";
|
||||||
const OUTPUT = "Output";
|
const OUTPUT = "Output";
|
||||||
function parseMenuItem(item) {
|
|
||||||
const USE = "Use ";
|
|
||||||
const FOR_INPUT = " for " + INPUT;
|
|
||||||
const FOR_OUTPUT = " for " + OUTPUT;
|
|
||||||
if (item.slice(0, USE.length) == USE) {
|
|
||||||
if (item.slice(-FOR_INPUT.length) == FOR_INPUT) {
|
|
||||||
return { device: item.slice(USE.length, -FOR_INPUT.length), mode: INPUT };
|
|
||||||
} else if (item.slice(-FOR_OUTPUT.length) == FOR_OUTPUT) {
|
|
||||||
return { device: item.slice(USE.length, -FOR_OUTPUT.length), mode: OUTPUT };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// VAR DEFINITIONS
|
// VAR DEFINITIONS
|
||||||
|
@ -36,13 +24,15 @@ function parseMenuItem(item) {
|
||||||
var debugPrintStatements = true;
|
var debugPrintStatements = true;
|
||||||
const INPUT_DEVICE_SETTING = "audio_input_device";
|
const INPUT_DEVICE_SETTING = "audio_input_device";
|
||||||
const OUTPUT_DEVICE_SETTING = "audio_output_device";
|
const OUTPUT_DEVICE_SETTING = "audio_output_device";
|
||||||
var audioDevicesList = [];
|
var audioDevicesList = []; // placeholder for menu items
|
||||||
var wasHmdActive = false; // assume it's not active to start
|
var wasHmdActive = false; // assume it's not active to start
|
||||||
var switchedAudioInputToHMD = false;
|
var switchedAudioInputToHMD = false;
|
||||||
var switchedAudioOutputToHMD = false;
|
var switchedAudioOutputToHMD = false;
|
||||||
var previousSelectedInputAudioDevice = "";
|
var previousSelectedInputAudioDevice = "";
|
||||||
var previousSelectedOutputAudioDevice = "";
|
var previousSelectedOutputAudioDevice = "";
|
||||||
var skipMenuEvents = true;
|
|
||||||
|
var interfaceInputDevice = "";
|
||||||
|
var interfaceOutputDevice = "";
|
||||||
|
|
||||||
//
|
//
|
||||||
// BEGIN FUNCTION DEFINITIONS
|
// BEGIN FUNCTION DEFINITIONS
|
||||||
|
@ -56,58 +46,37 @@ function debug() {
|
||||||
|
|
||||||
function setupAudioMenus() {
|
function setupAudioMenus() {
|
||||||
// menu events can be triggered asynchronously; skip them for 200ms to avoid recursion and false switches
|
// menu events can be triggered asynchronously; skip them for 200ms to avoid recursion and false switches
|
||||||
skipMenuEvents = true;
|
|
||||||
Script.setTimeout(function() { skipMenuEvents = false; }, 200);
|
|
||||||
|
|
||||||
removeAudioMenus();
|
removeAudioMenus();
|
||||||
|
|
||||||
// Setup audio input devices
|
// Setup audio input devices
|
||||||
Menu.addSeparator("Audio", "Input Audio Device");
|
Menu.addSeparator("Audio", "Input Audio Device");
|
||||||
var inputDevices = AudioDevice.getInputDevices();
|
|
||||||
var currentInputDevice = AudioDevice.getInputDevice()
|
var currentInputDevice = AudioDevice.getInputDevice()
|
||||||
for (var i = 0; i < inputDevices.length; i++) {
|
for (var i = 0; i < AudioDevice.inputAudioDevices.length; i++) {
|
||||||
var audioDeviceMenuString = "Use " + inputDevices[i] + " for Input";
|
var audioDeviceMenuString = "Use " + AudioDevice.inputAudioDevices[i] + " for Input";
|
||||||
Menu.addMenuItem({
|
Menu.addMenuItem({
|
||||||
menuName: "Audio",
|
menuName: "Audio",
|
||||||
menuItemName: audioDeviceMenuString,
|
menuItemName: audioDeviceMenuString,
|
||||||
isCheckable: true,
|
isCheckable: true,
|
||||||
isChecked: inputDevices[i] == currentInputDevice
|
isChecked: AudioDevice.inputAudioDevices[i] == currentInputDevice
|
||||||
});
|
});
|
||||||
audioDevicesList.push(audioDeviceMenuString);
|
audioDevicesList.push(audioDeviceMenuString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup audio output devices
|
// Setup audio output devices
|
||||||
Menu.addSeparator("Audio", "Output Audio Device");
|
Menu.addSeparator("Audio", "Output Audio Device");
|
||||||
var outputDevices = AudioDevice.getOutputDevices();
|
|
||||||
var currentOutputDevice = AudioDevice.getOutputDevice()
|
var currentOutputDevice = AudioDevice.getOutputDevice()
|
||||||
for (var i = 0; i < outputDevices.length; i++) {
|
for (var i = 0; i < AudioDevice.outputAudioDevices.length; i++) {
|
||||||
var audioDeviceMenuString = "Use " + outputDevices[i] + " for Output";
|
var audioDeviceMenuString = "Use " + AudioDevice.outputAudioDevices[i] + " for Output";
|
||||||
Menu.addMenuItem({
|
Menu.addMenuItem({
|
||||||
menuName: "Audio",
|
menuName: "Audio",
|
||||||
menuItemName: audioDeviceMenuString,
|
menuItemName: audioDeviceMenuString,
|
||||||
isCheckable: true,
|
isCheckable: true,
|
||||||
isChecked: outputDevices[i] == currentOutputDevice
|
isChecked: AudioDevice.outputAudioDevices[i] == currentOutputDevice
|
||||||
});
|
});
|
||||||
audioDevicesList.push(audioDeviceMenuString);
|
audioDevicesList.push(audioDeviceMenuString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkDeviceMismatch() {
|
|
||||||
var inputDeviceSetting = Settings.getValue(INPUT_DEVICE_SETTING);
|
|
||||||
var interfaceInputDevice = AudioDevice.getInputDevice();
|
|
||||||
if (interfaceInputDevice != inputDeviceSetting) {
|
|
||||||
debug("Input Setting & Device mismatch! Input SETTING: " + inputDeviceSetting + "Input DEVICE IN USE: " + interfaceInputDevice);
|
|
||||||
switchAudioDevice("Use " + inputDeviceSetting + " for Input");
|
|
||||||
}
|
|
||||||
|
|
||||||
var outputDeviceSetting = Settings.getValue(OUTPUT_DEVICE_SETTING);
|
|
||||||
var interfaceOutputDevice = AudioDevice.getOutputDevice();
|
|
||||||
if (interfaceOutputDevice != outputDeviceSetting) {
|
|
||||||
debug("Output Setting & Device mismatch! Output SETTING: " + outputDeviceSetting + "Output DEVICE IN USE: " + interfaceOutputDevice);
|
|
||||||
switchAudioDevice("Use " + outputDeviceSetting + " for Output");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeAudioMenus() {
|
function removeAudioMenus() {
|
||||||
Menu.removeSeparator("Audio", "Input Audio Device");
|
Menu.removeSeparator("Audio", "Input Audio Device");
|
||||||
Menu.removeSeparator("Audio", "Output Audio Device");
|
Menu.removeSeparator("Audio", "Output Audio Device");
|
||||||
|
@ -126,94 +95,41 @@ function removeAudioMenus() {
|
||||||
function onDevicechanged() {
|
function onDevicechanged() {
|
||||||
debug("System audio devices changed. Removing and replacing Audio Menus...");
|
debug("System audio devices changed. Removing and replacing Audio Menus...");
|
||||||
setupAudioMenus();
|
setupAudioMenus();
|
||||||
checkDeviceMismatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMenuEvent(audioDeviceMenuString) {
|
function onMenuEvent(audioDeviceMenuString) {
|
||||||
if (!skipMenuEvents) {
|
if (Menu.isOptionChecked(audioDeviceMenuString) &&
|
||||||
switchAudioDevice(audioDeviceMenuString);
|
(audioDeviceMenuString !== interfaceInputDevice &&
|
||||||
|
audioDeviceMenuString !== interfaceOutputDevice)) {
|
||||||
|
AudioDevice.setDeviceFromMenu(audioDeviceMenuString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCurrentDeviceChanged() {
|
function onCurrentDeviceChanged() {
|
||||||
debug("System audio device switched. ");
|
debug("System audio device switched. ");
|
||||||
var interfaceInputDevice = "Use " + AudioDevice.getInputDevice() + " for Input";
|
interfaceInputDevice = "Use " + AudioDevice.getInputDevice() + " for Input";
|
||||||
var interfaceOutputDevice = "Use " + AudioDevice.getOutputDevice() + " for Output";
|
interfaceOutputDevice = "Use " + AudioDevice.getOutputDevice() + " for Output";
|
||||||
for (var index = 0; index < audioDevicesList.length; index++) {
|
for (var index = 0; index < audioDevicesList.length; index++) {
|
||||||
if (audioDevicesList[index] === interfaceInputDevice ||
|
if (audioDevicesList[index] === interfaceInputDevice ||
|
||||||
audioDevicesList[index] === interfaceOutputDevice) {
|
audioDevicesList[index] === interfaceOutputDevice) {
|
||||||
|
if (Menu.isOptionChecked(audioDevicesList[index]) === false)
|
||||||
Menu.setIsOptionChecked(audioDevicesList[index], true);
|
Menu.setIsOptionChecked(audioDevicesList[index], true);
|
||||||
} else {
|
} else {
|
||||||
|
if (Menu.isOptionChecked(audioDevicesList[index]) === true)
|
||||||
Menu.setIsOptionChecked(audioDevicesList[index], false);
|
Menu.setIsOptionChecked(audioDevicesList[index], false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchAudioDevice(audioDeviceMenuString) {
|
|
||||||
// if the device is not plugged in, short-circuit
|
|
||||||
if (!~audioDevicesList.indexOf(audioDeviceMenuString)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var selection = parseMenuItem(audioDeviceMenuString);
|
|
||||||
if (!selection) {
|
|
||||||
debug("Invalid Audio audioDeviceMenuString! Doesn't end with 'for Input' or 'for Output'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// menu events can be triggered asynchronously; skip them for 200ms to avoid recursion and false switches
|
|
||||||
skipMenuEvents = true;
|
|
||||||
Script.setTimeout(function() { skipMenuEvents = false; }, 200);
|
|
||||||
|
|
||||||
var selectedDevice = selection.device;
|
|
||||||
if (selection.mode == INPUT) {
|
|
||||||
var currentInputDevice = AudioDevice.getInputDevice();
|
|
||||||
if (selectedDevice != currentInputDevice) {
|
|
||||||
debug("Switching audio INPUT device from " + currentInputDevice + " to " + selectedDevice);
|
|
||||||
Menu.setIsOptionChecked("Use " + currentInputDevice + " for Input", false);
|
|
||||||
if (AudioDevice.setInputDevice(selectedDevice)) {
|
|
||||||
Settings.setValue(INPUT_DEVICE_SETTING, selectedDevice);
|
|
||||||
Menu.setIsOptionChecked(audioDeviceMenuString, true);
|
|
||||||
} else {
|
|
||||||
debug("Error setting audio input device!")
|
|
||||||
Menu.setIsOptionChecked(audioDeviceMenuString, false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug("Selected input device is the same as the current input device!")
|
|
||||||
Settings.setValue(INPUT_DEVICE_SETTING, selectedDevice);
|
|
||||||
Menu.setIsOptionChecked(audioDeviceMenuString, true);
|
|
||||||
AudioDevice.setInputDevice(selectedDevice); // Still try to force-set the device (in case the user's trying to forcefully debug an issue)
|
|
||||||
}
|
|
||||||
} else if (selection.mode == OUTPUT) {
|
|
||||||
var currentOutputDevice = AudioDevice.getOutputDevice();
|
|
||||||
if (selectedDevice != currentOutputDevice) {
|
|
||||||
debug("Switching audio OUTPUT device from " + currentOutputDevice + " to " + selectedDevice);
|
|
||||||
Menu.setIsOptionChecked("Use " + currentOutputDevice + " for Output", false);
|
|
||||||
if (AudioDevice.setOutputDevice(selectedDevice)) {
|
|
||||||
Settings.setValue(OUTPUT_DEVICE_SETTING, selectedDevice);
|
|
||||||
Menu.setIsOptionChecked(audioDeviceMenuString, true);
|
|
||||||
} else {
|
|
||||||
debug("Error setting audio output device!")
|
|
||||||
Menu.setIsOptionChecked(audioDeviceMenuString, false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug("Selected output device is the same as the current output device!")
|
|
||||||
Settings.setValue(OUTPUT_DEVICE_SETTING, selectedDevice);
|
|
||||||
Menu.setIsOptionChecked(audioDeviceMenuString, true);
|
|
||||||
AudioDevice.setOutputDevice(selectedDevice); // Still try to force-set the device (in case the user's trying to forcefully debug an issue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function restoreAudio() {
|
function restoreAudio() {
|
||||||
if (switchedAudioInputToHMD) {
|
if (switchedAudioInputToHMD) {
|
||||||
debug("Switching back from HMD preferred audio input to: " + previousSelectedInputAudioDevice);
|
debug("Switching back from HMD preferred audio input to: " + previousSelectedInputAudioDevice);
|
||||||
switchAudioDevice("Use " + previousSelectedInputAudioDevice + " for Input");
|
AudioDevice.setInputDeviceAsync(previousSelectedInputAudioDevice)
|
||||||
switchedAudioInputToHMD = false;
|
switchedAudioInputToHMD = false;
|
||||||
}
|
}
|
||||||
if (switchedAudioOutputToHMD) {
|
if (switchedAudioOutputToHMD) {
|
||||||
debug("Switching back from HMD preferred audio output to: " + previousSelectedOutputAudioDevice);
|
debug("Switching back from HMD preferred audio output to: " + previousSelectedOutputAudioDevice);
|
||||||
switchAudioDevice("Use " + previousSelectedOutputAudioDevice + " for Output");
|
AudioDevice.setOutputDeviceAsync(previousSelectedOutputAudioDevice)
|
||||||
switchedAudioOutputToHMD = false;
|
switchedAudioOutputToHMD = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,7 +156,7 @@ function checkHMDAudio() {
|
||||||
debug("previousSelectedInputAudioDevice: " + previousSelectedInputAudioDevice);
|
debug("previousSelectedInputAudioDevice: " + previousSelectedInputAudioDevice);
|
||||||
if (hmdPreferredAudioInput != previousSelectedInputAudioDevice) {
|
if (hmdPreferredAudioInput != previousSelectedInputAudioDevice) {
|
||||||
switchedAudioInputToHMD = true;
|
switchedAudioInputToHMD = true;
|
||||||
switchAudioDevice("Use " + hmdPreferredAudioInput + " for Input");
|
AudioDevice.setInputDeviceAsync(hmdPreferredAudioInput)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hmdPreferredAudioOutput !== "") {
|
if (hmdPreferredAudioOutput !== "") {
|
||||||
|
@ -249,7 +165,7 @@ function checkHMDAudio() {
|
||||||
debug("previousSelectedOutputAudioDevice: " + previousSelectedOutputAudioDevice);
|
debug("previousSelectedOutputAudioDevice: " + previousSelectedOutputAudioDevice);
|
||||||
if (hmdPreferredAudioOutput != previousSelectedOutputAudioDevice) {
|
if (hmdPreferredAudioOutput != previousSelectedOutputAudioDevice) {
|
||||||
switchedAudioOutputToHMD = true;
|
switchedAudioOutputToHMD = true;
|
||||||
switchAudioDevice("Use " + hmdPreferredAudioOutput + " for Output");
|
AudioDevice.setOutputDeviceAsync(hmdPreferredAudioOutput)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -277,10 +193,9 @@ Script.setTimeout(function () {
|
||||||
Menu.menuItemEvent.connect(onMenuEvent);
|
Menu.menuItemEvent.connect(onMenuEvent);
|
||||||
debug("Setting up Audio I/O menu for the first time...");
|
debug("Setting up Audio I/O menu for the first time...");
|
||||||
setupAudioMenus();
|
setupAudioMenus();
|
||||||
checkDeviceMismatch();
|
|
||||||
debug("Checking HMD audio status...")
|
debug("Checking HMD audio status...")
|
||||||
checkHMDAudio();
|
checkHMDAudio();
|
||||||
}, 3000);
|
}, 300);
|
||||||
|
|
||||||
debug("Connecting scriptEnding()");
|
debug("Connecting scriptEnding()");
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
|
|
Loading…
Reference in a new issue