Merge pull request #4181 from ctrlaltdavid/20276

CR for Job #20276 - Add Scripting Support for changes in Audio Devices
This commit is contained in:
Brad Hefta-Gaub 2015-01-27 19:36:17 -08:00
commit 347c74ebae
5 changed files with 38 additions and 1 deletions

View file

@ -98,8 +98,16 @@ function setupAudioMenus() {
}
}
function onDevicechanged() {
Menu.removeMenu("Tools > Audio");
setupAudioMenus();
}
// Have a small delay before the menu's get setup and the audio devices can switch to the last selected ones
Script.setTimeout(function() { setupAudioMenus(); }, 5000);
Script.setTimeout(function () {
AudioDevice.deviceChanged.connect(onDevicechanged);
setupAudioMenus();
}, 5000);
function scriptEnding() {
Menu.removeMenu("Tools > Audio");

View file

@ -106,6 +106,15 @@ Audio::Audio() :
// Initialize GVerb
initGverb();
const qint64 DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000;
_inputDevices = getDeviceNames(QAudio::AudioInput);
_outputDevices = getDeviceNames(QAudio::AudioOutput);
QTimer* updateTimer = new QTimer(this);
connect(updateTimer, &QTimer::timeout, this, &Audio::checkDevices);
updateTimer->start(DEVICE_CHECK_INTERVAL_MSECS);
}
void Audio::reset() {
@ -1116,6 +1125,18 @@ qint64 Audio::AudioOutputIODevice::readData(char * data, qint64 maxSize) {
return bytesWritten;
}
void Audio::checkDevices() {
QVector<QString> inputDevices = getDeviceNames(QAudio::AudioInput);
QVector<QString> outputDevices = getDeviceNames(QAudio::AudioOutput);
if (inputDevices != _inputDevices || outputDevices != _outputDevices) {
_inputDevices = inputDevices;
_outputDevices = outputDevices;
emit deviceChanged();
}
}
void Audio::loadSettings() {
_receivedAudioStream.loadSettings();

View file

@ -178,6 +178,7 @@ public slots:
signals:
bool muteToggled();
void inputReceived(const QByteArray& inputSamples);
void deviceChanged();
protected:
Audio();
@ -276,6 +277,10 @@ private:
AudioIOStats _stats;
AudioNoiseGate _inputGate;
QVector<QString> _inputDevices;
QVector<QString> _outputDevices;
void checkDevices();
};

View file

@ -21,6 +21,8 @@ AudioDeviceScriptingInterface* AudioDeviceScriptingInterface::getInstance() {
AudioDeviceScriptingInterface::AudioDeviceScriptingInterface() {
connect(DependencyManager::get<Audio>().data(), &Audio::muteToggled,
this, &AudioDeviceScriptingInterface::muteToggled);
connect(DependencyManager::get<Audio>().data(), &Audio::deviceChanged,
this, &AudioDeviceScriptingInterface::deviceChanged);
}
bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) {

View file

@ -49,6 +49,7 @@ private:
signals:
void muteToggled();
void deviceChanged();
};
#endif // hifi_AudioDeviceScriptingInterface_h