mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 19:02:55 +02:00
Cleanup dead code, fix startup behavior
This commit is contained in:
parent
4ad36ccec9
commit
aeabfe84f0
3 changed files with 43 additions and 91 deletions
|
@ -136,15 +136,9 @@ void Audio::setReverbOptions(const AudioEffectOptions* options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::setInputDevice(const QAudioDeviceInfo& device) {
|
void Audio::setInputDevice(const QAudioDeviceInfo& device) {
|
||||||
auto client = DependencyManager::get<AudioClient>();
|
_devices.chooseInputDevice(device);
|
||||||
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
|
||||||
Q_ARG(QAudio::Mode, QAudio::AudioInput),
|
|
||||||
Q_ARG(const QAudioDeviceInfo&, device));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::setOutputDevice(const QAudioDeviceInfo& device) {
|
void Audio::setOutputDevice(const QAudioDeviceInfo& device) {
|
||||||
auto client = DependencyManager::get<AudioClient>();
|
_devices.chooseOutputDevice(device);
|
||||||
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
|
||||||
Q_ARG(QAudio::Mode, QAudio::AudioOutput),
|
|
||||||
Q_ARG(const QAudioDeviceInfo&, device));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,61 +59,17 @@ QVariant AudioDeviceList::data(const QModelIndex& index, int role) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioDeviceList::setData(const QModelIndex& index, const QVariant& value, int role) {
|
|
||||||
if (!index.isValid() || index.row() >= _devices.size() || role != Qt::CheckStateRole) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only allow switching to a new device, not deactivating an in-use device
|
|
||||||
auto selected = value.toBool();
|
|
||||||
if (!selected) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return setDevice(index.row(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AudioDeviceList::setDevice(int row, bool fromUser) {
|
|
||||||
bool success = false;
|
|
||||||
auto& device = _devices[row];
|
|
||||||
_userSelection = fromUser;
|
|
||||||
|
|
||||||
// skip if already selected
|
|
||||||
if (!device.selected) {
|
|
||||||
auto client = DependencyManager::get<AudioClient>();
|
|
||||||
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
|
||||||
Q_ARG(QAudio::Mode, _mode),
|
|
||||||
Q_ARG(const QAudioDeviceInfo&, device.info));
|
|
||||||
}
|
|
||||||
|
|
||||||
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, 0));
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AudioDeviceList::resetDevice(bool contextIsHMD, const QString& device) {
|
void AudioDeviceList::resetDevice(bool contextIsHMD, const QString& device) {
|
||||||
bool success { false };
|
auto client = DependencyManager::get<AudioClient>().data();
|
||||||
|
auto deviceName = getSetting(contextIsHMD, _mode).get();
|
||||||
// try to set the last selected device
|
bool switchResult = false;
|
||||||
if (!device.isNull()) {
|
QMetaObject::invokeMethod(client, "switchAudioDevice", Qt::BlockingQueuedConnection,
|
||||||
auto i = 0;
|
Q_RETURN_ARG(bool, switchResult),
|
||||||
for (; i < rowCount(); ++i) {
|
Q_ARG(QAudio::Mode, _mode), Q_ARG(QString, deviceName));
|
||||||
if (device == _devices[i].info.deviceName()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i < rowCount()) {
|
|
||||||
success = setDevice(i, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the selection failed - reset it
|
|
||||||
if (!success) {
|
|
||||||
emit deviceSelected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to set to the default device for this mode
|
// try to set to the default device for this mode
|
||||||
if (!success) {
|
if (!switchResult) {
|
||||||
auto client = DependencyManager::get<AudioClient>().data();
|
|
||||||
if (contextIsHMD) {
|
if (contextIsHMD) {
|
||||||
QString deviceName;
|
QString deviceName;
|
||||||
if (_mode == QAudio::AudioInput) {
|
if (_mode == QAudio::AudioInput) {
|
||||||
|
@ -144,11 +100,6 @@ void AudioDeviceList::onDeviceChanged(const QAudioDeviceInfo& device) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_userSelection) {
|
|
||||||
_userSelection = false;
|
|
||||||
emit deviceSelected(_selectedDevice, oldDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
emit deviceChanged(_selectedDevice);
|
emit deviceChanged(_selectedDevice);
|
||||||
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, 0));
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, 0));
|
||||||
}
|
}
|
||||||
|
@ -183,13 +134,6 @@ AudioDevices::AudioDevices(bool& contextIsHMD) : _contextIsHMD(contextIsHMD) {
|
||||||
_outputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioOutput));
|
_outputs.onDeviceChanged(client->getActiveAudioDevice(QAudio::AudioOutput));
|
||||||
_inputs.onDevicesChanged(client->getAudioDevices(QAudio::AudioInput));
|
_inputs.onDevicesChanged(client->getAudioDevices(QAudio::AudioInput));
|
||||||
_outputs.onDevicesChanged(client->getAudioDevices(QAudio::AudioOutput));
|
_outputs.onDevicesChanged(client->getAudioDevices(QAudio::AudioOutput));
|
||||||
|
|
||||||
connect(&_inputs, &AudioDeviceList::deviceSelected, [&](const QAudioDeviceInfo& device, const QAudioDeviceInfo& previousDevice) {
|
|
||||||
onDeviceSelected(QAudio::AudioInput, device, previousDevice);
|
|
||||||
});
|
|
||||||
connect(&_outputs, &AudioDeviceList::deviceSelected, [&](const QAudioDeviceInfo& device, const QAudioDeviceInfo& previousDevice) {
|
|
||||||
onDeviceSelected(QAudio::AudioOutput, device, previousDevice);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDevices::onContextChanged(const QString& context) {
|
void AudioDevices::onContextChanged(const QString& context) {
|
||||||
|
@ -245,22 +189,40 @@ void AudioDevices::onDeviceChanged(QAudio::Mode mode, const QAudioDeviceInfo& de
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDevices::onDevicesChanged(QAudio::Mode mode, const QList<QAudioDeviceInfo>& devices) {
|
void AudioDevices::onDevicesChanged(QAudio::Mode mode, const QList<QAudioDeviceInfo>& devices) {
|
||||||
static bool initialized { false };
|
static std::once_flag once;
|
||||||
auto initialize = [&]{
|
|
||||||
if (initialized) {
|
|
||||||
onContextChanged(QString());
|
|
||||||
} else {
|
|
||||||
initialized = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (mode == QAudio::AudioInput) {
|
if (mode == QAudio::AudioInput) {
|
||||||
_inputs.onDevicesChanged(devices);
|
_inputs.onDevicesChanged(devices);
|
||||||
static std::once_flag inputFlag;
|
|
||||||
std::call_once(inputFlag, initialize);
|
|
||||||
} else { // if (mode == QAudio::AudioOutput)
|
} else { // if (mode == QAudio::AudioOutput)
|
||||||
_outputs.onDevicesChanged(devices);
|
_outputs.onDevicesChanged(devices);
|
||||||
static std::once_flag outputFlag;
|
}
|
||||||
std::call_once(outputFlag, initialize);
|
std::call_once(once, [&] { onContextChanged(QString()); });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AudioDevices::chooseInputDevice(const QAudioDeviceInfo& device) {
|
||||||
|
auto client = DependencyManager::get<AudioClient>();
|
||||||
|
bool success = false;
|
||||||
|
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
||||||
|
Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(bool, success),
|
||||||
|
Q_ARG(QAudio::Mode, QAudio::AudioInput),
|
||||||
|
Q_ARG(const QAudioDeviceInfo&, device));
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
onDeviceSelected(QAudio::AudioInput, device, _inputs._selectedDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioDevices::chooseOutputDevice(const QAudioDeviceInfo& device) {
|
||||||
|
auto client = DependencyManager::get<AudioClient>();
|
||||||
|
bool success = false;
|
||||||
|
QMetaObject::invokeMethod(client.data(), "switchAudioDevice",
|
||||||
|
Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(bool, success),
|
||||||
|
Q_ARG(QAudio::Mode, QAudio::AudioOutput),
|
||||||
|
Q_ARG(const QAudioDeviceInfo&, device));
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
onDeviceSelected(QAudio::AudioOutput, device, _outputs._selectedDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,14 +37,11 @@ public:
|
||||||
|
|
||||||
// get/set devices through a QML ListView
|
// get/set devices through a QML ListView
|
||||||
QVariant data(const QModelIndex& index, int role) const override;
|
QVariant data(const QModelIndex& index, int role) const override;
|
||||||
bool setData(const QModelIndex& index, const QVariant &value, int role) override;
|
|
||||||
|
|
||||||
// reset device to the last selected device in this context, or the default
|
// reset device to the last selected device in this context, or the default
|
||||||
void resetDevice(bool contextIsHMD, const QString& device);
|
void resetDevice(bool contextIsHMD, const QString& device);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceSelected(const QAudioDeviceInfo& device = QAudioDeviceInfo(),
|
|
||||||
const QAudioDeviceInfo& previousDevice = QAudioDeviceInfo());
|
|
||||||
void deviceChanged(const QAudioDeviceInfo& device);
|
void deviceChanged(const QAudioDeviceInfo& device);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -54,12 +51,9 @@ private slots:
|
||||||
private:
|
private:
|
||||||
friend class AudioDevices;
|
friend class AudioDevices;
|
||||||
|
|
||||||
bool setDevice(int index, bool fromUser);
|
|
||||||
|
|
||||||
static QHash<int, QByteArray> _roles;
|
static QHash<int, QByteArray> _roles;
|
||||||
static Qt::ItemFlags _flags;
|
static Qt::ItemFlags _flags;
|
||||||
bool _userSelection { false };
|
const QAudio::Mode _mode;
|
||||||
QAudio::Mode _mode;
|
|
||||||
QAudioDeviceInfo _selectedDevice;
|
QAudioDeviceInfo _selectedDevice;
|
||||||
QList<AudioDevice> _devices;
|
QList<AudioDevice> _devices;
|
||||||
};
|
};
|
||||||
|
@ -73,6 +67,8 @@ class AudioDevices : public QObject {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioDevices(bool& contextIsHMD);
|
AudioDevices(bool& contextIsHMD);
|
||||||
|
void chooseInputDevice(const QAudioDeviceInfo& device);
|
||||||
|
void chooseOutputDevice(const QAudioDeviceInfo& device);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void nop();
|
void nop();
|
||||||
|
|
Loading…
Reference in a new issue