mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-04 02:20:46 +02:00
Add AudioDevice.deviceChanged() signal and use to update audio menu
This commit is contained in:
parent
e488e841b7
commit
22347dd794
5 changed files with 38 additions and 1 deletions
|
@ -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
|
// 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() {
|
function scriptEnding() {
|
||||||
Menu.removeMenu("Tools > Audio");
|
Menu.removeMenu("Tools > Audio");
|
||||||
|
|
|
@ -99,6 +99,15 @@ Audio::Audio() :
|
||||||
|
|
||||||
// Initialize GVerb
|
// Initialize GVerb
|
||||||
initGverb();
|
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() {
|
void Audio::reset() {
|
||||||
|
@ -1106,3 +1115,15 @@ qint64 Audio::AudioOutputIODevice::readData(char * data, qint64 maxSize) {
|
||||||
|
|
||||||
return bytesWritten;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -177,6 +177,7 @@ public slots:
|
||||||
signals:
|
signals:
|
||||||
bool muteToggled();
|
bool muteToggled();
|
||||||
void inputReceived(const QByteArray& inputSamples);
|
void inputReceived(const QByteArray& inputSamples);
|
||||||
|
void deviceChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Audio();
|
Audio();
|
||||||
|
@ -275,6 +276,10 @@ private:
|
||||||
AudioIOStats _stats;
|
AudioIOStats _stats;
|
||||||
|
|
||||||
AudioNoiseGate _inputGate;
|
AudioNoiseGate _inputGate;
|
||||||
|
|
||||||
|
QVector<QString> _inputDevices;
|
||||||
|
QVector<QString> _outputDevices;
|
||||||
|
void checkDevices();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ AudioDeviceScriptingInterface* AudioDeviceScriptingInterface::getInstance() {
|
||||||
AudioDeviceScriptingInterface::AudioDeviceScriptingInterface() {
|
AudioDeviceScriptingInterface::AudioDeviceScriptingInterface() {
|
||||||
connect(DependencyManager::get<Audio>().data(), &Audio::muteToggled,
|
connect(DependencyManager::get<Audio>().data(), &Audio::muteToggled,
|
||||||
this, &AudioDeviceScriptingInterface::muteToggled);
|
this, &AudioDeviceScriptingInterface::muteToggled);
|
||||||
|
connect(DependencyManager::get<Audio>().data(), &Audio::deviceChanged,
|
||||||
|
this, &AudioDeviceScriptingInterface::deviceChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) {
|
bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void muteToggled();
|
void muteToggled();
|
||||||
|
void deviceChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AudioDeviceScriptingInterface_h
|
#endif // hifi_AudioDeviceScriptingInterface_h
|
||||||
|
|
Loading…
Reference in a new issue