display selected profile + default profile added

This commit is contained in:
ykeara
2018-12-28 13:30:19 -06:00
parent b009cfa3e7
commit 541c82cbbf
5 changed files with 171 additions and 9 deletions
+42 -7
View File
@@ -40,6 +40,7 @@ MyStackViewPage {
onClosed: { onClosed: {
if (okClicked) { if (okClicked) {
AudioTabController.deleteAudioProfile(profileIndex) AudioTabController.deleteAudioProfile(profileIndex)
pttProfileComboBox.currentIndex = 0
} }
} }
} }
@@ -79,6 +80,7 @@ MyStackViewPage {
if (okClicked) { if (okClicked) {
if (pttNewProfileName.text != "") { if (pttNewProfileName.text != "") {
AudioTabController.addPttProfile(pttNewProfileName.text) AudioTabController.addPttProfile(pttNewProfileName.text)
} else { } else {
audioMessageDialog.showMessage("Create New Profile", "ERROR: No name given.") audioMessageDialog.showMessage("Create New Profile", "ERROR: No name given.")
} }
@@ -95,7 +97,7 @@ MyStackViewPage {
id: audioNewProfileDialog id: audioNewProfileDialog
dialogTitle: "Create New Audio Profile" dialogTitle: "Create New Audio Profile"
dialogWidth: 600 dialogWidth: 600
dialogHeight: 220 dialogHeight: 300
dialogContentItem: ColumnLayout { dialogContentItem: ColumnLayout {
RowLayout { RowLayout {
Layout.topMargin: 16 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: { onClosed: {
if (okClicked) { if (okClicked) {
@@ -365,10 +380,11 @@ MyStackViewPage {
} }
} }
RowLayout { RowLayout {
MyToggleButton { MyToggleButton {
id: audioPttShowNotificationToggle id: audioPttShowNotificationToggle
Layout.leftMargin: 265 Layout.leftMargin: 350
text: "Show notification in HMD." text: "Show notification in HMD"
onCheckedChanged: { onCheckedChanged: {
AudioTabController.setPttShowNotification(checked, false) AudioTabController.setPttShowNotification(checked, false)
} }
@@ -414,7 +430,8 @@ MyStackViewPage {
onClicked: { onClicked: {
if (audioProfileComboBox.currentIndex > 0) { if (audioProfileComboBox.currentIndex > 0) {
AudioTabController.applyAudioProfile(audioProfileComboBox.currentIndex - 1) AudioTabController.applyAudioProfile(audioProfileComboBox.currentIndex - 1)
audioProfileComboBox.currentIndex = 0 //TODO ?
//audioProfileComboBox.currentIndex = 0
} }
} }
} }
@@ -447,7 +464,7 @@ MyStackViewPage {
onClicked: { onClicked: {
if (pttProfileComboBox.currentIndex > 0) { if (pttProfileComboBox.currentIndex > 0) {
AudioTabController.applyPttProfile(pttProfileComboBox.currentIndex - 1) AudioTabController.applyPttProfile(pttProfileComboBox.currentIndex - 1)
pttProfileComboBox.currentIndex = 0 //pttProfileComboBox.currentIndex = 0
} }
} }
} }
@@ -558,6 +575,9 @@ MyStackViewPage {
audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled
audioPttShowNotificationToggle.checked = AudioTabController.pttShowNotification audioPttShowNotificationToggle.checked = AudioTabController.pttShowNotification
audioPttReverseToggle.checked = AudioTabController.micReversePtt audioPttReverseToggle.checked = AudioTabController.micReversePtt
audioDefaultProfileToggle.checked = AudioTabController.audioProfileDefault
//audioProfileComboBox.currentIndex = AudioTabController.audioProfileDefaultIndex + 1
//AudioTabController.applyDefaultProfile()
componentCompleted = true componentCompleted = true
} }
@@ -629,12 +649,27 @@ MyStackViewPage {
onPttRightControllerEnabledChanged: { onPttRightControllerEnabledChanged: {
audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled
} }
onAudioProfileDefaultChanged: {
audioDefaultProfileToggle.checked = AudioTabController.audioProfileDefault
}
onPttProfilesUpdated: { onPttProfilesUpdated: {
reloadPttProfiles() reloadPttProfiles()
} }
onAudioProfilesUpdated:{ onAudioProfilesUpdated: {
reloadAudioProfiles() reloadAudioProfiles()
} }
onAudioProfileAdded:{
audioProfileComboBox.currentIndex = AudioTabController.getAudioProfileCount()
//audioProfileComboBox.currentIndex = AudioTabController.audioProfileDefaultIndex+1
}
onPttProfileAdded:{
pttProfileComboBox.currentIndex = AudioTabController.getpttProfileCount()
}
//onAudioProfileDefaultIndexChanged: {
// audioProfileComboBox.currentIndex = AudioTabController.audioProfileDefaultIndex()
//}
onPlaybackDeviceListChanged: { onPlaybackDeviceListChanged: {
var devs1 = [] var devs1 = []
@@ -707,7 +742,7 @@ MyStackViewPage {
for (var i = 0; i < profileCount; i++) { for (var i = 0; i < profileCount; i++) {
profiles.push(AudioTabController.getAudioProfileName(i)) profiles.push(AudioTabController.getAudioProfileName(i))
} }
audioProfileComboBox.currentIndex = 0 audioProfileComboBox.currentIndex = 0;
audioProfileComboBox.model = profiles audioProfileComboBox.model = profiles
} }
} }
+98 -2
View File
@@ -39,7 +39,10 @@ namespace advsettings {
reloadPttProfiles(); reloadPttProfiles();
reloadPttConfig(); reloadPttConfig();
reloadAudioProfiles(); reloadAudioProfiles();
applyDefaultProfile();
reloadAudioSettings(); reloadAudioSettings();
eventLoopTick(); eventLoopTick();
} }
@@ -49,6 +52,7 @@ namespace advsettings {
this->widget = widget; this->widget = widget;
std::string notifKey = std::string(OverlayController::applicationKey) + ".pptnotification"; std::string notifKey = std::string(OverlayController::applicationKey) + ".pptnotification";
vr::VROverlayError overlayError = vr::VROverlay()->CreateOverlay(notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle); vr::VROverlayError overlayError = vr::VROverlay()->CreateOverlay(notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle);
if (overlayError == vr::VROverlayError_None) { if (overlayError == vr::VROverlayError_None) {
std::string notifIconPath = QApplication::applicationDirPath().toStdString() + "/res/qml/ptt_notification.png"; std::string notifIconPath = QApplication::applicationDirPath().toStdString() + "/res/qml/ptt_notification.png";
@@ -115,6 +119,10 @@ namespace advsettings {
return m_micReversePtt; return m_micReversePtt;
} }
bool AudioTabController::audioProfileDefault() const {
return m_isDefaultAudioProfile;
}
void AudioTabController::eventLoopTick() { void AudioTabController::eventLoopTick() {
if (!eventLoopMutex.try_lock()) { if (!eventLoopMutex.try_lock()) {
return; return;
@@ -278,6 +286,18 @@ namespace advsettings {
} }
} }
void AudioTabController::setAudioProfileDefault(bool value, bool notify) {
std::lock_guard<std::recursive_mutex> lock(eventLoopMutex);
if (value != m_isDefaultAudioProfile) {
m_isDefaultAudioProfile = value;
//TODO ????
// ?? saveAudioSettings();
if (notify) {
emit audioProfileDefaultChanged(value);
}
}
}
void AudioTabController::onNewRecordingDevice() { void AudioTabController::onNewRecordingDevice() {
findMicDeviceIndex(audioManager->getMicDevId()); 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); 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) { if (vrSettingsError != vr::VRSettingsError_None) {
LOG(WARNING) << "Could not write \"" << vr::k_pch_audio_OnPlaybackDevice_String << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError); LOG(WARNING) << "Could not write \"" << vr::k_pch_audio_OnPlaybackDevice_String << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
} else { }
else {
vr::VRSettings()->Sync(); vr::VRSettings()->Sync();
audioManager->setPlaybackDevice(m_playbackDevices[index].first, notify); audioManager->setPlaybackDevice(m_playbackDevices[index].first, notify);
} }
} else if (notify) { }
else if (notify) {
emit playbackDeviceIndexChanged(m_playbackDeviceIndex); emit playbackDeviceIndexChanged(m_playbackDeviceIndex);
} }
} }
@@ -506,6 +528,7 @@ namespace advsettings {
entry.mirrorMute = settings->value("mirrorMute", false).toBool(); entry.mirrorMute = settings->value("mirrorMute", false).toBool();
entry.mirrorVol = settings->value("mirrorVol", 0.0).toFloat(); entry.mirrorVol = settings->value("mirrorVol", 0.0).toFloat();
entry.micVol = settings->value("micVol", 1.0).toFloat(); entry.micVol = settings->value("micVol", 1.0).toFloat();
entry.defaultProfile = settings->value("defaultProfile", false).toBool();
} }
settings->endArray(); settings->endArray();
settings->endGroup(); settings->endGroup();
@@ -539,6 +562,7 @@ namespace advsettings {
settings->setValue("mirrorMute", p.mirrorMute); settings->setValue("mirrorMute", p.mirrorMute);
settings->setValue("micVol", p.micVol); settings->setValue("micVol", p.micVol);
settings->setValue("mirrorVol", p.mirrorVol); settings->setValue("mirrorVol", p.mirrorVol);
settings->setValue("defaultProfile", p.defaultProfile);
i++; i++;
} }
settings->endArray(); settings->endArray();
@@ -582,10 +606,17 @@ namespace advsettings {
profile->mirrorMute = m_mirrorMuted; profile->mirrorMute = m_mirrorMuted;
profile->mirrorVol = m_mirrorVolume; profile->mirrorVol = m_mirrorVolume;
profile->micVol = m_micVolume; profile->micVol = m_micVolume;
profile->defaultProfile = m_isDefaultAudioProfile;
if (m_isDefaultAudioProfile) {
removeDefaultProfile(name);
//to prevent confusion, resets checkbox
setAudioProfileDefault(false);
}
saveAudioProfiles(); saveAudioProfiles();
OverlayController::appSettings()->sync(); OverlayController::appSettings()->sync();
emit audioProfilesUpdated(); emit audioProfilesUpdated();
emit audioProfileAdded();
} }
@@ -604,6 +635,7 @@ namespace advsettings {
*/ */
//TODO Remembers Mirror Volume when switching to main volume. //TODO Remembers Mirror Volume when switching to main volume.
void AudioTabController::applyAudioProfile(unsigned index) { void AudioTabController::applyAudioProfile(unsigned index) {
std::lock_guard<std::recursive_mutex> lock(eventLoopMutex);
if (index < audioProfiles.size()) { if (index < audioProfiles.size()) {
auto& profile = audioProfiles[index]; auto& profile = audioProfiles[index];
int mInd = getMirrorIndex(profile.mirrorName); int mInd = getMirrorIndex(profile.mirrorName);
@@ -624,6 +656,8 @@ namespace advsettings {
setMirrorDeviceIndex(mInd, true); setMirrorDeviceIndex(mInd, true);
setPlaybackDeviceIndex(pInd, true); setPlaybackDeviceIndex(pInd, true);
} }
setMicDeviceIndex(getRecordingIndex(profile.micName), true); setMicDeviceIndex(getRecordingIndex(profile.micName), true);
setMicMuted(profile.micMute, true); setMicMuted(profile.micMute, true);
setMirrorMuted(profile.mirrorMute, true); setMirrorMuted(profile.mirrorMute, true);
@@ -650,6 +684,8 @@ namespace advsettings {
if (index < audioProfiles.size()) { if (index < audioProfiles.size()) {
auto pos = audioProfiles.begin() + index; auto pos = audioProfiles.begin() + index;
audioProfiles.erase(pos); audioProfiles.erase(pos);
//OverlayController::appSettings()->remove("audioProfiles\\" + ind);
//I think I don't need?
saveAudioProfiles(); saveAudioProfiles();
OverlayController::appSettings()->sync(); OverlayController::appSettings()->sync();
emit audioProfilesUpdated(); emit audioProfilesUpdated();
@@ -686,6 +722,7 @@ namespace advsettings {
} }
int AudioTabController::getRecordingIndex(std::string str) { int AudioTabController::getRecordingIndex(std::string str) {
std::lock_guard<std::recursive_mutex> lock(eventLoopMutex);
for (int i = 0; i < m_recordingDevices.size(); i++) { for (int i = 0; i < m_recordingDevices.size(); i++) {
if (str.compare(m_recordingDevices[i].second) == 0) { if (str.compare(m_recordingDevices[i].second) == 0) {
return i; return i;
@@ -703,6 +740,65 @@ namespace advsettings {
return -1; 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.size(); i++){
auto& profile = audioProfiles[i];
if (profile.defaultProfile) {
applyAudioProfile(i);
//setAudioProfileDefaultIndex(i);
//setDefaultAudioProfileName(i);
//emit audioProfileDefaultIndexChanged();
break;
}
}
}
/*int AudioTabController::audioProfileDefaultIndex() const {
return m_defaultAudioProfileIndex;
}
void AudioTabController::setAudioProfileDefaultIndex(int index) {
m_defaultAudioProfileIndex = index;
m_defaultAudioProfileIndex = 2;
}
*/
/* ---------------------------*/ /* ---------------------------*/
/*----------------*/ /*----------------*/
+28
View File
@@ -22,6 +22,7 @@ namespace advsettings {
float micVol = 0.0; float micVol = 0.0;
bool micMute = false; bool micMute = false;
bool mirrorMute = false; bool mirrorMute = false;
bool defaultProfile = false;
}; };
@@ -41,6 +42,14 @@ namespace advsettings {
Q_PROPERTY(bool micProximitySensorCanMute READ micProximitySensorCanMute WRITE setMicProximitySensorCanMute NOTIFY micProximitySensorCanMuteChanged) Q_PROPERTY(bool micProximitySensorCanMute READ micProximitySensorCanMute WRITE setMicProximitySensorCanMute NOTIFY micProximitySensorCanMuteChanged)
Q_PROPERTY(bool micReversePtt READ micReversePtt WRITE setMicReversePtt NOTIFY micReversePttChanged) Q_PROPERTY(bool micReversePtt READ micReversePtt WRITE setMicReversePtt NOTIFY micReversePttChanged)
Q_PROPERTY(bool audioProfileDefault READ audioProfileDefault WRITE setAudioProfileDefault NOTIFY audioProfileDefaultChanged)
//To display default profile
//Q_PROPERTY(bool audioProfileDefaultIndex READ audioProfileDefaultIndex NOTIFY audioProfileDefaultIndexChanged)
private: private:
OverlayController* parent; OverlayController* parent;
QQuickWindow* widget; QQuickWindow* widget;
@@ -58,6 +67,9 @@ namespace advsettings {
bool m_micMuted = false; bool m_micMuted = false;
bool m_micProximitySensorCanMute = false; bool m_micProximitySensorCanMute = false;
bool m_micReversePtt = false; bool m_micReversePtt = false;
bool m_isDefaultAudioProfile = false;
//int m_defaultAudioProfileIndex = 2;
std::string m_defaultProfileName;
unsigned settingsUpdateCounter = 0; unsigned settingsUpdateCounter = 0;
@@ -84,6 +96,10 @@ namespace advsettings {
int getMirrorIndex(std::string str); int getMirrorIndex(std::string str);
//void setPlaybackDeviceControl(int index, bool notify = true); //void setPlaybackDeviceControl(int index, bool notify = true);
void removeDefaultProfile(QString name);
//void setAudioProfileDefaultIndex(int index);
//void setDefaultAudioProfileName(int index);
std::vector<AudioProfile> audioProfiles; std::vector<AudioProfile> audioProfiles;
//std::recursive_mutex eventLoopMutexAudio; //std::recursive_mutex eventLoopMutexAudio;
@@ -109,9 +125,12 @@ namespace advsettings {
bool micMuted() const; bool micMuted() const;
bool micProximitySensorCanMute() const; bool micProximitySensorCanMute() const;
bool micReversePtt() const; bool micReversePtt() const;
bool audioProfileDefault() const;
//int audioProfileDefaultIndex() const;
void reloadAudioProfiles(); void reloadAudioProfiles();
void saveAudioProfiles(); void saveAudioProfiles();
Q_INVOKABLE void applyDefaultProfile();
Q_INVOKABLE int getPlaybackDeviceCount(); Q_INVOKABLE int getPlaybackDeviceCount();
Q_INVOKABLE QString getPlaybackDeviceName(int index); Q_INVOKABLE QString getPlaybackDeviceName(int index);
@@ -123,11 +142,14 @@ namespace advsettings {
Q_INVOKABLE unsigned getAudioProfileCount(); Q_INVOKABLE unsigned getAudioProfileCount();
Q_INVOKABLE QString getAudioProfileName(unsigned index); Q_INVOKABLE QString getAudioProfileName(unsigned index);
void onNewRecordingDevice(); void onNewRecordingDevice();
void onNewPlaybackDevice(); void onNewPlaybackDevice();
void onNewMirrorDevice(); void onNewMirrorDevice();
void onDeviceStateChanged(); void onDeviceStateChanged();
public slots: public slots:
void setMirrorVolume(float value, bool notify = true); void setMirrorVolume(float value, bool notify = true);
void setMirrorMuted(bool value, bool notify = true); void setMirrorMuted(bool value, bool notify = true);
@@ -145,6 +167,8 @@ namespace advsettings {
void applyAudioProfile(unsigned index); void applyAudioProfile(unsigned index);
void deleteAudioProfile(unsigned index); void deleteAudioProfile(unsigned index);
void setAudioProfileDefault(bool value, bool notify = true);
signals: signals:
void playbackDeviceIndexChanged(int index); void playbackDeviceIndexChanged(int index);
@@ -162,6 +186,10 @@ namespace advsettings {
void recordingDeviceListChanged(); void recordingDeviceListChanged();
void audioProfilesUpdated(); void audioProfilesUpdated();
void audioProfileAdded();
//void defaultAudioProfileApplied();
//void audioProfileDefaultIndexChanged();
void audioProfileDefaultChanged(bool value);
}; };
} // namespace advsettings } // namespace advsettings
+2
View File
@@ -268,6 +268,7 @@ namespace advsettings {
savePttProfiles(); savePttProfiles();
OverlayController::appSettings()->sync(); OverlayController::appSettings()->sync();
emit pttProfilesUpdated(); emit pttProfilesUpdated();
emit pttProfileAdded();
} }
void PttController::applyPttProfile(unsigned index) { void PttController::applyPttProfile(unsigned index) {
@@ -403,6 +404,7 @@ namespace advsettings {
} }
} }
void logControllerState(const vr::VRControllerState_t& state, const std::string& prefix) { void logControllerState(const vr::VRControllerState_t& state, const std::string& prefix) {
if (state.ulButtonPressed & vr::ButtonMaskFromId(vr::k_EButton_ApplicationMenu)) { if (state.ulButtonPressed & vr::ButtonMaskFromId(vr::k_EButton_ApplicationMenu)) {
LOG(INFO) << prefix << vr::VRSystem()->GetButtonIdNameFromEnum(vr::k_EButton_ApplicationMenu) << " pressed"; LOG(INFO) << prefix << vr::VRSystem()->GetButtonIdNameFromEnum(vr::k_EButton_ApplicationMenu) << " pressed";
+1
View File
@@ -114,6 +114,7 @@ namespace advsettings {
void pttRightControllerEnabledChanged(bool value); void pttRightControllerEnabledChanged(bool value);
void pttProfilesUpdated(); void pttProfilesUpdated();
void pttProfileAdded();
}; };
} // namespace advsettings } // namespace advsettings