From 541c82cbbf846f6ca9f8fdd9ac050e5c9278d332 Mon Sep 17 00:00:00 2001 From: ykeara Date: Fri, 28 Dec 2018 13:30:19 -0600 Subject: [PATCH] display selected profile + default profile added --- src/res/qml/AudioPage.qml | 49 +++++++++-- src/tabcontrollers/AudioTabController.cpp | 100 +++++++++++++++++++++- src/tabcontrollers/AudioTabController.h | 28 ++++++ src/tabcontrollers/PttController.cpp | 2 + src/tabcontrollers/PttController.h | 1 + 5 files changed, 171 insertions(+), 9 deletions(-) diff --git a/src/res/qml/AudioPage.qml b/src/res/qml/AudioPage.qml index 774ef91..09da120 100644 --- a/src/res/qml/AudioPage.qml +++ b/src/res/qml/AudioPage.qml @@ -40,6 +40,7 @@ MyStackViewPage { onClosed: { if (okClicked) { AudioTabController.deleteAudioProfile(profileIndex) + pttProfileComboBox.currentIndex = 0 } } } @@ -79,6 +80,7 @@ MyStackViewPage { if (okClicked) { if (pttNewProfileName.text != "") { AudioTabController.addPttProfile(pttNewProfileName.text) + } else { audioMessageDialog.showMessage("Create New Profile", "ERROR: No name given.") } @@ -95,7 +97,7 @@ MyStackViewPage { id: audioNewProfileDialog dialogTitle: "Create New Audio Profile" dialogWidth: 600 - dialogHeight: 220 + dialogHeight: 300 dialogContentItem: ColumnLayout { RowLayout { Layout.topMargin: 16 @@ -116,6 +118,19 @@ MyStackViewPage { } } } + RowLayout { + Layout.topMargin: 16 + Layout.leftMargin: 16 + Layout.rightMargin: 16 + MyToggleButton { + id: audioDefaultProfileToggle + Layout.preferredWidth: 250 + text: "Make Default" + onCheckedChanged: { + AudioTabController.setAudioProfileDefault(checked, false) + } + } + } } onClosed: { if (okClicked) { @@ -365,10 +380,11 @@ MyStackViewPage { } } RowLayout { + MyToggleButton { id: audioPttShowNotificationToggle - Layout.leftMargin: 265 - text: "Show notification in HMD." + Layout.leftMargin: 350 + text: "Show notification in HMD" onCheckedChanged: { AudioTabController.setPttShowNotification(checked, false) } @@ -414,7 +430,8 @@ MyStackViewPage { onClicked: { if (audioProfileComboBox.currentIndex > 0) { AudioTabController.applyAudioProfile(audioProfileComboBox.currentIndex - 1) - audioProfileComboBox.currentIndex = 0 + //TODO ? + //audioProfileComboBox.currentIndex = 0 } } } @@ -447,7 +464,7 @@ MyStackViewPage { onClicked: { if (pttProfileComboBox.currentIndex > 0) { AudioTabController.applyPttProfile(pttProfileComboBox.currentIndex - 1) - pttProfileComboBox.currentIndex = 0 + //pttProfileComboBox.currentIndex = 0 } } } @@ -558,6 +575,9 @@ MyStackViewPage { audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled audioPttShowNotificationToggle.checked = AudioTabController.pttShowNotification audioPttReverseToggle.checked = AudioTabController.micReversePtt + audioDefaultProfileToggle.checked = AudioTabController.audioProfileDefault + //audioProfileComboBox.currentIndex = AudioTabController.audioProfileDefaultIndex + 1 + //AudioTabController.applyDefaultProfile() componentCompleted = true } @@ -629,12 +649,27 @@ MyStackViewPage { onPttRightControllerEnabledChanged: { audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled } + onAudioProfileDefaultChanged: { + audioDefaultProfileToggle.checked = AudioTabController.audioProfileDefault + } onPttProfilesUpdated: { reloadPttProfiles() } - onAudioProfilesUpdated:{ + onAudioProfilesUpdated: { reloadAudioProfiles() } + onAudioProfileAdded:{ + audioProfileComboBox.currentIndex = AudioTabController.getAudioProfileCount() + //audioProfileComboBox.currentIndex = AudioTabController.audioProfileDefaultIndex+1 + } + onPttProfileAdded:{ + pttProfileComboBox.currentIndex = AudioTabController.getpttProfileCount() + } + + //onAudioProfileDefaultIndexChanged: { + // audioProfileComboBox.currentIndex = AudioTabController.audioProfileDefaultIndex() + + //} onPlaybackDeviceListChanged: { var devs1 = [] @@ -707,7 +742,7 @@ MyStackViewPage { for (var i = 0; i < profileCount; i++) { profiles.push(AudioTabController.getAudioProfileName(i)) } - audioProfileComboBox.currentIndex = 0 + audioProfileComboBox.currentIndex = 0; audioProfileComboBox.model = profiles } } diff --git a/src/tabcontrollers/AudioTabController.cpp b/src/tabcontrollers/AudioTabController.cpp index 788abdb..9546ed9 100644 --- a/src/tabcontrollers/AudioTabController.cpp +++ b/src/tabcontrollers/AudioTabController.cpp @@ -39,7 +39,10 @@ namespace advsettings { reloadPttProfiles(); reloadPttConfig(); reloadAudioProfiles(); + applyDefaultProfile(); reloadAudioSettings(); + + eventLoopTick(); } @@ -49,6 +52,7 @@ namespace advsettings { this->widget = widget; std::string notifKey = std::string(OverlayController::applicationKey) + ".pptnotification"; + vr::VROverlayError overlayError = vr::VROverlay()->CreateOverlay(notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle); if (overlayError == vr::VROverlayError_None) { std::string notifIconPath = QApplication::applicationDirPath().toStdString() + "/res/qml/ptt_notification.png"; @@ -115,6 +119,10 @@ namespace advsettings { return m_micReversePtt; } + bool AudioTabController::audioProfileDefault() const { + return m_isDefaultAudioProfile; + } + void AudioTabController::eventLoopTick() { if (!eventLoopMutex.try_lock()) { return; @@ -278,6 +286,18 @@ namespace advsettings { } } + void AudioTabController::setAudioProfileDefault(bool value, bool notify) { + std::lock_guard lock(eventLoopMutex); + if (value != m_isDefaultAudioProfile) { + m_isDefaultAudioProfile = value; + //TODO ???? + // ?? saveAudioSettings(); + if (notify) { + emit audioProfileDefaultChanged(value); + } + } + } + void AudioTabController::onNewRecordingDevice() { findMicDeviceIndex(audioManager->getMicDevId()); } @@ -352,11 +372,13 @@ namespace advsettings { vr::VRSettings()->SetString(vr::k_pch_audio_Section, vr::k_pch_audio_OnPlaybackDevice_String, m_playbackDevices[index].first.c_str(), &vrSettingsError); if (vrSettingsError != vr::VRSettingsError_None) { LOG(WARNING) << "Could not write \"" << vr::k_pch_audio_OnPlaybackDevice_String << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError); - } else { + } + else { vr::VRSettings()->Sync(); audioManager->setPlaybackDevice(m_playbackDevices[index].first, notify); } - } else if (notify) { + } + else if (notify) { emit playbackDeviceIndexChanged(m_playbackDeviceIndex); } } @@ -506,6 +528,7 @@ namespace advsettings { entry.mirrorMute = settings->value("mirrorMute", false).toBool(); entry.mirrorVol = settings->value("mirrorVol", 0.0).toFloat(); entry.micVol = settings->value("micVol", 1.0).toFloat(); + entry.defaultProfile = settings->value("defaultProfile", false).toBool(); } settings->endArray(); settings->endGroup(); @@ -539,6 +562,7 @@ namespace advsettings { settings->setValue("mirrorMute", p.mirrorMute); settings->setValue("micVol", p.micVol); settings->setValue("mirrorVol", p.mirrorVol); + settings->setValue("defaultProfile", p.defaultProfile); i++; } settings->endArray(); @@ -582,10 +606,17 @@ namespace advsettings { profile->mirrorMute = m_mirrorMuted; profile->mirrorVol = m_mirrorVolume; profile->micVol = m_micVolume; + profile->defaultProfile = m_isDefaultAudioProfile; + if (m_isDefaultAudioProfile) { + removeDefaultProfile(name); + //to prevent confusion, resets checkbox + setAudioProfileDefault(false); + } saveAudioProfiles(); OverlayController::appSettings()->sync(); emit audioProfilesUpdated(); + emit audioProfileAdded(); } @@ -604,6 +635,7 @@ namespace advsettings { */ //TODO Remembers Mirror Volume when switching to main volume. void AudioTabController::applyAudioProfile(unsigned index) { + std::lock_guard lock(eventLoopMutex); if (index < audioProfiles.size()) { auto& profile = audioProfiles[index]; int mInd = getMirrorIndex(profile.mirrorName); @@ -624,6 +656,8 @@ namespace advsettings { setMirrorDeviceIndex(mInd, true); setPlaybackDeviceIndex(pInd, true); } + + setMicDeviceIndex(getRecordingIndex(profile.micName), true); setMicMuted(profile.micMute, true); setMirrorMuted(profile.mirrorMute, true); @@ -650,6 +684,8 @@ namespace advsettings { if (index < audioProfiles.size()) { auto pos = audioProfiles.begin() + index; audioProfiles.erase(pos); + //OverlayController::appSettings()->remove("audioProfiles\\" + ind); + //I think I don't need? saveAudioProfiles(); OverlayController::appSettings()->sync(); emit audioProfilesUpdated(); @@ -686,6 +722,7 @@ namespace advsettings { } int AudioTabController::getRecordingIndex(std::string str) { + std::lock_guard lock(eventLoopMutex); for (int i = 0; i < m_recordingDevices.size(); i++) { if (str.compare(m_recordingDevices[i].second) == 0) { return i; @@ -703,6 +740,65 @@ namespace advsettings { return -1; } + /* + Name: removeDefaultProfile + + input: QString name - name of new default profile + output: none + + description: checks all profiles and removes any OTHERS that are set as default. + */ + void AudioTabController::removeDefaultProfile(QString name) { + AudioProfile* profile = nullptr; + for (auto& p : audioProfiles) { + if (p.profileName.compare(name.toStdString()) != 0) { + profile = &p; + profile->defaultProfile = false; + } + } + + } + + /* + Name: applyDefaultProfile + + input: none + output: none + + description: checks all profiles and applies the one (if any) with the default flag); + */ + + + void AudioTabController::applyDefaultProfile() { + for(int i = 0; i audioProfiles; //std::recursive_mutex eventLoopMutexAudio; @@ -109,9 +125,12 @@ namespace advsettings { bool micMuted() const; bool micProximitySensorCanMute() const; bool micReversePtt() const; + bool audioProfileDefault() const; + //int audioProfileDefaultIndex() const; void reloadAudioProfiles(); void saveAudioProfiles(); + Q_INVOKABLE void applyDefaultProfile(); Q_INVOKABLE int getPlaybackDeviceCount(); Q_INVOKABLE QString getPlaybackDeviceName(int index); @@ -123,11 +142,14 @@ namespace advsettings { Q_INVOKABLE unsigned getAudioProfileCount(); Q_INVOKABLE QString getAudioProfileName(unsigned index); + void onNewRecordingDevice(); void onNewPlaybackDevice(); void onNewMirrorDevice(); void onDeviceStateChanged(); + + public slots: void setMirrorVolume(float value, bool notify = true); void setMirrorMuted(bool value, bool notify = true); @@ -145,6 +167,8 @@ namespace advsettings { void applyAudioProfile(unsigned index); void deleteAudioProfile(unsigned index); + void setAudioProfileDefault(bool value, bool notify = true); + signals: void playbackDeviceIndexChanged(int index); @@ -162,6 +186,10 @@ namespace advsettings { void recordingDeviceListChanged(); void audioProfilesUpdated(); + void audioProfileAdded(); + //void defaultAudioProfileApplied(); + //void audioProfileDefaultIndexChanged(); + void audioProfileDefaultChanged(bool value); }; } // namespace advsettings diff --git a/src/tabcontrollers/PttController.cpp b/src/tabcontrollers/PttController.cpp index 2fa0a30..b9fb13f 100644 --- a/src/tabcontrollers/PttController.cpp +++ b/src/tabcontrollers/PttController.cpp @@ -268,6 +268,7 @@ namespace advsettings { savePttProfiles(); OverlayController::appSettings()->sync(); emit pttProfilesUpdated(); + emit pttProfileAdded(); } void PttController::applyPttProfile(unsigned index) { @@ -403,6 +404,7 @@ namespace advsettings { } } + void logControllerState(const vr::VRControllerState_t& state, const std::string& prefix) { if (state.ulButtonPressed & vr::ButtonMaskFromId(vr::k_EButton_ApplicationMenu)) { LOG(INFO) << prefix << vr::VRSystem()->GetButtonIdNameFromEnum(vr::k_EButton_ApplicationMenu) << " pressed"; diff --git a/src/tabcontrollers/PttController.h b/src/tabcontrollers/PttController.h index cad777c..fd39c85 100644 --- a/src/tabcontrollers/PttController.h +++ b/src/tabcontrollers/PttController.h @@ -114,6 +114,7 @@ namespace advsettings { void pttRightControllerEnabledChanged(bool value); void pttProfilesUpdated(); + void pttProfileAdded(); }; } // namespace advsettings