This commit is contained in:
Zach Pomerantz 2017-06-23 09:35:48 -04:00
parent 4bff925506
commit a82cc0ec09
2 changed files with 36 additions and 36 deletions

View file

@ -27,11 +27,11 @@ static Setting::Handle<QString> hmdInputDeviceSetting { QStringList { Audio::AUD
static Setting::Handle<QString> hmdOutputDeviceSetting { QStringList { Audio::AUDIO, Audio::HMD, "OUTPUT" }}; static Setting::Handle<QString> hmdOutputDeviceSetting { QStringList { Audio::AUDIO, Audio::HMD, "OUTPUT" }};
Setting::Handle<QString>& getSetting(bool contextIsHMD, QAudio::Mode mode) { Setting::Handle<QString>& getSetting(bool contextIsHMD, QAudio::Mode mode) {
if (mode == QAudio::AudioInput) { if (mode == QAudio::AudioInput) {
return contextIsHMD ? hmdInputDeviceSetting : desktopInputDeviceSetting; return contextIsHMD ? hmdInputDeviceSetting : desktopInputDeviceSetting;
} else { // if (mode == QAudio::AudioOutput) } else { // if (mode == QAudio::AudioOutput)
return contextIsHMD ? hmdOutputDeviceSetting : desktopOutputDeviceSetting; return contextIsHMD ? hmdOutputDeviceSetting : desktopOutputDeviceSetting;
} }
} }
QHash<int, QByteArray> AudioDeviceList::_roles { QHash<int, QByteArray> AudioDeviceList::_roles {
@ -55,38 +55,38 @@ QVariant AudioDeviceList::data(const QModelIndex& index, int role) const {
} }
bool AudioDeviceList::setData(const QModelIndex& index, const QVariant& value, int role) { bool AudioDeviceList::setData(const QModelIndex& index, const QVariant& value, int role) {
if (!index.isValid() || index.row() >= _devices.size() || role != Qt::CheckStateRole) { if (!index.isValid() || index.row() >= _devices.size() || role != Qt::CheckStateRole) {
return false; return false;
} }
// only allow switching to a new device, not deactivating an in-use device // only allow switching to a new device, not deactivating an in-use device
auto selected = value.toBool(); auto selected = value.toBool();
if (!selected) { if (!selected) {
return false; return false;
} }
return setDevice(index.row(), true); return setDevice(index.row(), true);
} }
bool AudioDeviceList::setDevice(int row, bool fromUser) { bool AudioDeviceList::setDevice(int row, bool fromUser) {
bool success = false; bool success = false;
auto& device = _devices[row]; auto& device = _devices[row];
// skip if already selected // skip if already selected
if (!device.selected) { if (!device.selected) {
auto client = DependencyManager::get<AudioClient>(); auto client = DependencyManager::get<AudioClient>();
QMetaObject::invokeMethod(client.data(), "switchAudioDevice", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(client.data(), "switchAudioDevice", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, success), Q_RETURN_ARG(bool, success),
Q_ARG(QAudio::Mode, _mode), Q_ARG(QAudio::Mode, _mode),
Q_ARG(const QAudioDeviceInfo&, device.info)); Q_ARG(const QAudioDeviceInfo&, device.info));
if (success) { if (success) {
device.selected = true; device.selected = true;
if (fromUser) { if (fromUser) {
emit deviceSelected(device.info, _selectedDevice); emit deviceSelected(device.info, _selectedDevice);
} }
emit deviceChanged(device.info); emit deviceChanged(device.info);
} }
} }
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, 0)); emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, 0));
@ -105,7 +105,7 @@ void AudioDeviceList::resetDevice(bool contextIsHMD, const QString& device) {
} }
} }
if (i < rowCount()) { if (i < rowCount()) {
success = setDevice(i, false); success = setDevice(i, false);
} }
// the selection failed - reset it // the selection failed - reset it
@ -193,8 +193,8 @@ AudioDevices::AudioDevices(bool& contextIsHMD) : _contextIsHMD(contextIsHMD) {
} }
void AudioDevices::onContextChanged(const QString& context) { void AudioDevices::onContextChanged(const QString& context) {
auto input = getSetting(_contextIsHMD, QAudio::AudioInput).get(); auto input = getSetting(_contextIsHMD, QAudio::AudioInput).get();
auto output = getSetting(_contextIsHMD, QAudio::AudioOutput).get(); auto output = getSetting(_contextIsHMD, QAudio::AudioOutput).get();
_inputs.resetDevice(_contextIsHMD, input); _inputs.resetDevice(_contextIsHMD, input);
_outputs.resetDevice(_contextIsHMD, output); _outputs.resetDevice(_contextIsHMD, output);
@ -203,7 +203,7 @@ void AudioDevices::onContextChanged(const QString& context) {
void AudioDevices::onDeviceSelected(QAudio::Mode mode, const QAudioDeviceInfo& device, const QAudioDeviceInfo& previousDevice) { void AudioDevices::onDeviceSelected(QAudio::Mode mode, const QAudioDeviceInfo& device, const QAudioDeviceInfo& previousDevice) {
QString deviceName = device.isNull() ? QString() : device.deviceName(); QString deviceName = device.isNull() ? QString() : device.deviceName();
auto& setting = getSetting(_contextIsHMD, mode); auto& setting = getSetting(_contextIsHMD, mode);
// check for a previous device // check for a previous device
auto wasDefault = setting.get().isNull(); auto wasDefault = setting.get().isNull();
@ -216,8 +216,8 @@ void AudioDevices::onDeviceSelected(QAudio::Mode mode, const QAudioDeviceInfo& d
QJsonObject data; QJsonObject data;
const QString MODE = "audio_mode"; const QString MODE = "audio_mode";
const QString INPUT = "INPUT"; const QString INPUT = "INPUT";
const QString OUTPUT = "OUTPUT"; data[MODE] = mode == QAudio::AudioInput ? INPUT : OUTPUT; const QString OUTPUT = "OUTPUT"; data[MODE] = mode == QAudio::AudioInput ? INPUT : OUTPUT;
const QString CONTEXT = "display_mode"; const QString CONTEXT = "display_mode";
data[CONTEXT] = _contextIsHMD ? Audio::HMD : Audio::DESKTOP; data[CONTEXT] = _contextIsHMD ? Audio::HMD : Audio::DESKTOP;

View file

@ -54,7 +54,7 @@ private slots:
private: private:
friend class AudioDevices; friend class AudioDevices;
bool setDevice(int index, bool fromUser); bool setDevice(int index, bool fromUser);
static QHash<int, QByteArray> _roles; static QHash<int, QByteArray> _roles;
static Qt::ItemFlags _flags; static Qt::ItemFlags _flags;