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
+98 -2
View File
@@ -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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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.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;
bool micMute = 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 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:
OverlayController* parent;
QQuickWindow* widget;
@@ -58,6 +67,9 @@ namespace advsettings {
bool m_micMuted = false;
bool m_micProximitySensorCanMute = false;
bool m_micReversePtt = false;
bool m_isDefaultAudioProfile = false;
//int m_defaultAudioProfileIndex = 2;
std::string m_defaultProfileName;
unsigned settingsUpdateCounter = 0;
@@ -84,6 +96,10 @@ namespace advsettings {
int getMirrorIndex(std::string str);
//void setPlaybackDeviceControl(int index, bool notify = true);
void removeDefaultProfile(QString name);
//void setAudioProfileDefaultIndex(int index);
//void setDefaultAudioProfileName(int index);
std::vector<AudioProfile> 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
+2
View File
@@ -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";
+1
View File
@@ -114,6 +114,7 @@ namespace advsettings {
void pttRightControllerEnabledChanged(bool value);
void pttProfilesUpdated();
void pttProfileAdded();
};
} // namespace advsettings