audio profiles no logic re-org

This commit is contained in:
ykeara
2018-12-20 23:42:53 -06:00
parent 78f411e9df
commit 25e24c04af
5 changed files with 168 additions and 177 deletions
@@ -1,107 +0,0 @@
#include "AudioProfileController.h"
#include <QQuickWindow>
#include <QApplication>
#include "../overlaycontroller.h"
// application namespace
namespace advsettings {
//TODO DOCS/verify / other parts
void AudioProfileController::reloadAudioProfiles() {
audioProfiles.clear();
auto settings = OverlayController::appSettings();
settings->beginGroup(getSettingsName());
auto profileCount = settings->beginReadArray("audioProfiles");
for (int i = 0; i < profileCount; i++) {
settings->setArrayIndex(i);
audioProfiles.emplace_back();
auto& entry = audioProfiles[i];
entry.profileName = settings->value("profileName").toString().toStdString();
}
settings->endArray();
settings->endGroup();
}
void AudioProfileController::saveAudioProfiles() {
auto settings = OverlayController::appSettings();
settings->beginGroup(getSettingsName());
settings->beginWriteArray("audioProfiles");
unsigned i = 0;
for (auto& p : audioProfiles) {
settings->setArrayIndex(i);
settings->setValue("profileName", QString::fromStdString(p.profileName));
i++;
}
settings->endArray();
settings->endGroup();
}
void AudioProfileController::addAudioProfile(QString name) {
AudioProfile* profile = nullptr;
for (auto& p : audioProfiles) {
if (p.profileName.compare(name.toStdString()) == 0) {
profile = &p;
break;
}
}
if (!profile) {
auto i = audioProfiles.size();
audioProfiles.emplace_back();
profile = &audioProfiles[i];
}
profile->profileName = name.toStdString();
saveAudioProfiles();
OverlayController::appSettings()->sync();
emit audioProfilesUpdated();
}
void AudioProfileController::applyAudioProfile(unsigned index) {
//DO i need?
std::lock_guard<std::recursive_mutex> lock(eventLoopMutexAudio);
if (index < audioProfiles.size()) {
auto& profile = audioProfiles[index];
//TODO apply logic here
//setPttShowNotification(profile.showNotification);
}
}
void AudioProfileController::deleteAudioProfile(unsigned index) {
if (index < audioProfiles.size()) {
auto pos = audioProfiles.begin() + index;
audioProfiles.erase(pos);
saveAudioProfiles();
OverlayController::appSettings()->sync();
emit audioProfilesUpdated();
}
}
unsigned AudioProfileController::getAudioProfileCount() {
return (unsigned)audioProfiles.size();
}
QString AudioProfileController::getAudioProfileName(unsigned index) {
if (index < audioProfiles.size()) {
return QString::fromStdString(audioProfiles[index].profileName);
}
return "";
}
/*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";
}
}
*/
}
//namespace advconfig
@@ -1,67 +0,0 @@
#pragma once
#include <QObject>
#include <QString>
#include <QVariant>
#include <string>
#include <mutex>
#include <openvr.h>
#include "PttController.h"
//#include "AudioTabController.h"
class QQuickWindow;
// application namespace
namespace advsettings {
// forward declaration
class OverlayController;
struct AudioProfile {
std::string profileName;
std::string playbackName;
std::string mirrorName;
std::string micName;
float mirrorVol = 0.0;
float micVol = 0.0;
bool micMute = false;
bool mirrorMute = false;
//TODO all the settings!!! huehue
//bool showNotification = false;
};
class AudioProfileController : public PttController {
Q_OBJECT
//Q_PROPERTY(bool pttActive READ pttActive NOTIFY pttActiveChanged)
//NEED TO DOUBLE CHECK THIS IS CORRECT!?
protected:
std::vector<AudioProfile> audioProfiles;
protected:
virtual QString getSettingsName() = 0;
//may have to change to prevent issues
std::recursive_mutex eventLoopMutexAudio;
public:
void reloadAudioProfiles();
void saveAudioProfiles();
//TODO
Q_INVOKABLE unsigned getAudioProfileCount();
Q_INVOKABLE QString getAudioProfileName(unsigned index);
public slots:
void addAudioProfile(QString name);
void applyAudioProfile(unsigned index);
void deleteAudioProfile(unsigned index);
signals:
void audioProfilesUpdated();
};
} // namespace advsettings
+133
View File
@@ -69,6 +69,138 @@ namespace advsettings {
}
}
/*AUDIO PROFILE FUNCTIONS
The functions in this section pertain to saving the Audio settings.
Saved Settings Include:
Playback Device
Mirror Device
Mirror Vol
Microphone
Microphone Volume
Profile Name
*/
void AudioTabController::reloadAudioProfiles() {
audioProfiles.clear();
auto settings = OverlayController::appSettings();
settings->beginGroup(getSettingsName());
auto profileCount = settings->beginReadArray("audioProfiles");
for (int i = 0; i < profileCount; i++) {
settings->setArrayIndex(i);
audioProfiles.emplace_back();
auto& entry = audioProfiles[i];
entry.profileName = settings->value("profileName").toString().toStdString();
entry.playbackName = settings->value("playbackName").toString().toStdString();
}
settings->endArray();
settings->endGroup();
}
void AudioTabController::saveAudioProfiles() {
auto settings = OverlayController::appSettings();
settings->beginGroup(getSettingsName());
settings->beginWriteArray("audioProfiles");
unsigned i = 0;
for (auto& p : audioProfiles) {
settings->setArrayIndex(i);
settings->setValue("profileName", QString::fromStdString(p.profileName));
settings->setValue("playbackName", QString::fromStdString(p.playbackName));
i++;
}
settings->endArray();
settings->endGroup();
}
void AudioTabController::addAudioProfile(QString name) {
AudioProfile* profile = nullptr;
for (auto& p : audioProfiles) {
if (p.profileName.compare(name.toStdString()) == 0) {
profile = &p;
break;
}
}
if (!profile) {
auto i = audioProfiles.size();
audioProfiles.emplace_back();
profile = &audioProfiles[i];
}
profile->profileName = name.toStdString();
profile->playbackName = getPlaybackDeviceName(m_playbackDeviceIndex).toStdString();
saveAudioProfiles();
OverlayController::appSettings()->sync();
emit audioProfilesUpdated();
}
//TODO playback DevicE INDEX FIND UGHU
void AudioTabController::applyAudioProfile(unsigned index) {
//DO i need?
//std::lock_guard<std::recursive_mutex> lock(eventLoopMutex);
if (index < audioProfiles.size()) {
auto& profile = audioProfiles[index];
setPlaybackDeviceIndex(findPlaybackDeviceIndex(profile.playbackName, true), true);
//TODO apply logic here
//setPttShowNotification(profile.showNotification);
//reloadAudioProfiles();
}
}
void AudioTabController::deleteAudioProfile(unsigned index) {
if (index < audioProfiles.size()) {
auto pos = audioProfiles.begin() + index;
audioProfiles.erase(pos);
saveAudioProfiles();
OverlayController::appSettings()->sync();
emit audioProfilesUpdated();
}
}
unsigned AudioTabController::getAudioProfileCount() {
return (unsigned)audioProfiles.size();
}
QString AudioTabController::getAudioProfileName(unsigned index) {
if (index < audioProfiles.size()) {
return QString::fromStdString(audioProfiles[index].profileName);
}
return "";
}
/* ---------------------------*/
/*Playback Switch*/
void AudioTabController::setPlaybackDeviceControl(int index, bool notify) {
if (index < m_playbackDevices.size() && index != m_mirrorDeviceIndex) {
vr::EVRSettingsError 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) {
LOG(WARNING) << "Could not write \"" << vr::k_pch_audio_OnPlaybackDevice_String << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
}
else {
vr::VRSettings()->Sync();
audioManager->setPlaybackDevice(m_playbackDevices[index].first, notify);
emit playbackDeviceIndexChanged(m_playbackDeviceIndex);
}
}
else if (notify) {
emit playbackDeviceIndexChanged(m_playbackDeviceIndex);
}
}
/*----------------*/
void AudioTabController::reloadAudioSettings() {
std::lock_guard<std::recursive_mutex> lock(eventLoopMutex);
auto settings = OverlayController::appSettings();
@@ -348,6 +480,7 @@ namespace advsettings {
if (index != m_playbackDeviceIndex) {
if (index < m_playbackDevices.size() && index != m_mirrorDeviceIndex) {
vr::EVRSettingsError vrSettingsError;
//Applys Audio Switch IN VR
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);
+35 -2
View File
@@ -3,7 +3,7 @@
#include "AudioManager.h"
#include "PttController.h"
#include "AudioProfileController.h"
//#include "AudioProfileController.h"
#include <memory>
class QQuickWindow;
@@ -13,8 +13,21 @@ namespace advsettings {
// forward declaration
class OverlayController;
struct AudioProfile {
std::string profileName;
std::string playbackName;
std::string mirrorName;
std::string micName;
float mirrorVol = 0.0;
float micVol = 0.0;
bool micMute = false;
bool mirrorMute = false;
//TODO all the settings!!! huehue
//bool showNotification = false;
};
class AudioTabController : public AudioProfileController {
class AudioTabController : public PttController {
Q_OBJECT
Q_PROPERTY(int playbackDeviceIndex READ playbackDeviceIndex WRITE setPlaybackDeviceIndex NOTIFY playbackDeviceIndexChanged)
Q_PROPERTY(int mirrorDeviceIndex READ mirrorDeviceIndex WRITE setMirrorDeviceIndex NOTIFY mirrorDeviceIndexChanged)
@@ -68,7 +81,14 @@ namespace advsettings {
void findMirrorDeviceIndex(std::string id, bool notify = true);
void findMicDeviceIndex(std::string id, bool notify = true);
void setPlaybackDeviceControl(int index, bool notify = true);
std::vector<AudioProfile> audioProfiles;
//std::recursive_mutex eventLoopMutexAudio;
public:
void initStage1();
void initStage2(OverlayController* parent, QQuickWindow* widget);
@@ -89,12 +109,19 @@ namespace advsettings {
bool micProximitySensorCanMute() const;
bool micReversePtt() const;
void reloadAudioProfiles();
void saveAudioProfiles();
Q_INVOKABLE int getPlaybackDeviceCount();
Q_INVOKABLE QString getPlaybackDeviceName(int index);
Q_INVOKABLE int getRecordingDeviceCount();
Q_INVOKABLE QString getRecordingDeviceName(int index);
//TODO check if needed?
Q_INVOKABLE unsigned getAudioProfileCount();
Q_INVOKABLE QString getAudioProfileName(unsigned index);
void onNewRecordingDevice();
void onNewPlaybackDevice();
void onNewMirrorDevice();
@@ -113,6 +140,10 @@ namespace advsettings {
void setMirrorDeviceIndex(int value, bool notify = true);
void setMicDeviceIndex(int value, bool notify = true);
void addAudioProfile(QString name);
void applyAudioProfile(unsigned index);
void deleteAudioProfile(unsigned index);
signals:
void playbackDeviceIndexChanged(int index);
@@ -128,6 +159,8 @@ namespace advsettings {
void playbackDeviceListChanged();
void recordingDeviceListChanged();
void audioProfilesUpdated();
};
} // namespace advsettings
-1
View File
@@ -239,7 +239,6 @@ namespace advsettings {
}
void PttController::addPttProfile(QString name) {
int a = 0;
PttProfile* profile = nullptr;
for (auto& p : pttProfiles) {
if (p.profileName.compare(name.toStdString()) == 0) {