Fix warnings in AudioTabController
Mostly casts and unsigned to signed comparisons. Testing to ensure that the int isn't below 0. If it is, it can't be used in the array later anyway. After we're sure it isn't below 0 it's safe to static_cast<size_t>().
This commit is contained in:
@@ -55,10 +55,10 @@ namespace advsettings {
|
||||
if (QFile::exists(QString::fromStdString(notifIconPath))) {
|
||||
vr::VROverlay()->SetOverlayFromFile(m_ulNotificationOverlayHandle, notifIconPath.c_str());
|
||||
vr::VROverlay()->SetOverlayWidthInMeters(m_ulNotificationOverlayHandle, 0.02f);
|
||||
vr::HmdMatrix34_t notificationTransform = {
|
||||
1.0f, 0.0f, 0.0f, 0.12f,
|
||||
0.0f, 1.0f, 0.0f, 0.08f,
|
||||
0.0f, 0.0f, 1.0f, -0.3f
|
||||
vr::HmdMatrix34_t notificationTransform = {
|
||||
1.0f, 0.0f, 0.0f, 0.12f,
|
||||
0.0f, 1.0f, 0.0f, 0.08f,
|
||||
0.0f, 0.0f, 1.0f, -0.3f
|
||||
};
|
||||
vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative(m_ulNotificationOverlayHandle, vr::k_unTrackedDeviceIndex_Hmd, ¬ificationTransform);
|
||||
} else {
|
||||
@@ -307,25 +307,25 @@ namespace advsettings {
|
||||
emit recordingDeviceListChanged();
|
||||
}
|
||||
|
||||
int AudioTabController::getPlaybackDeviceCount() {
|
||||
return (int)m_playbackDevices.size();
|
||||
int AudioTabController::getPlaybackDeviceCount() {
|
||||
return static_cast<int>(m_playbackDevices.size());
|
||||
}
|
||||
|
||||
QString AudioTabController::getPlaybackDeviceName(int index) {
|
||||
if (index < m_playbackDevices.size()) {
|
||||
return QString::fromStdString(m_playbackDevices[index].second);
|
||||
QString AudioTabController::getPlaybackDeviceName(int index) {
|
||||
if (index > 0 && static_cast<size_t>(index) < m_playbackDevices.size()) {
|
||||
return QString::fromStdString(m_playbackDevices[static_cast<size_t>(index)].second);
|
||||
} else {
|
||||
return "<ERROR>";
|
||||
}
|
||||
}
|
||||
|
||||
int AudioTabController::getRecordingDeviceCount() {
|
||||
return (int)m_recordingDevices.size();
|
||||
int AudioTabController::getRecordingDeviceCount() {
|
||||
return static_cast<int>(m_recordingDevices.size());
|
||||
}
|
||||
|
||||
QString AudioTabController::getRecordingDeviceName(int index) {
|
||||
if (index < m_recordingDevices.size()) {
|
||||
return QString::fromStdString(m_recordingDevices[index].second);
|
||||
if (index > 0 && static_cast<size_t>(index) < m_playbackDevices.size()) {
|
||||
return QString::fromStdString(m_recordingDevices[static_cast<size_t>(index)].second);
|
||||
} else {
|
||||
return "<ERROR>";
|
||||
}
|
||||
@@ -346,15 +346,18 @@ namespace advsettings {
|
||||
|
||||
void AudioTabController::setPlaybackDeviceIndex(int index, bool notify) {
|
||||
if (index != m_playbackDeviceIndex) {
|
||||
if (index < m_playbackDevices.size() && index != m_mirrorDeviceIndex) {
|
||||
if (index > 0 && static_cast<size_t>(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);
|
||||
vr::VRSettings()->SetString(vr::k_pch_audio_Section,
|
||||
vr::k_pch_audio_OnPlaybackDevice_String,
|
||||
m_playbackDevices[static_cast<size_t>(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);
|
||||
vr::VRSettings()->Sync();
|
||||
audioManager->setPlaybackDevice(m_playbackDevices[static_cast<size_t>(index)].first, notify);
|
||||
}
|
||||
} else if (notify) {
|
||||
emit playbackDeviceIndexChanged(m_playbackDeviceIndex);
|
||||
@@ -373,14 +376,17 @@ namespace advsettings {
|
||||
vr::VRSettings()->Sync();
|
||||
audioManager->setMirrorDevice("", notify);
|
||||
}
|
||||
} else if (index < m_playbackDevices.size() && index != m_playbackDeviceIndex && index != m_mirrorDeviceIndex) {
|
||||
vr::EVRSettingsError vrSettingsError;
|
||||
vr::VRSettings()->SetString(vr::k_pch_audio_Section, vr::k_pch_audio_OnPlaybackMirrorDevice_String, m_playbackDevices[index].first.c_str(), &vrSettingsError);
|
||||
} else if (index > 0 && static_cast<size_t>(index) < m_playbackDevices.size() && index != m_playbackDeviceIndex && index != m_mirrorDeviceIndex) {
|
||||
vr::EVRSettingsError vrSettingsError;
|
||||
vr::VRSettings()->SetString(vr::k_pch_audio_Section,
|
||||
vr::k_pch_audio_OnPlaybackMirrorDevice_String,
|
||||
m_playbackDevices[static_cast<size_t>(index)].first.c_str(),
|
||||
&vrSettingsError);
|
||||
if (vrSettingsError != vr::VRSettingsError_None) {
|
||||
LOG(WARNING) << "Could not write \"" << vr::k_pch_audio_OnPlaybackMirrorDevice_String << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
|
||||
} else {
|
||||
vr::VRSettings()->Sync();
|
||||
audioManager->setMirrorDevice(m_playbackDevices[index].first, notify);
|
||||
audioManager->setMirrorDevice(m_playbackDevices[static_cast<size_t>(index)].first, notify);
|
||||
}
|
||||
} else if (notify) {
|
||||
emit mirrorDeviceIndexChanged(m_mirrorDeviceIndex);
|
||||
@@ -390,14 +396,14 @@ namespace advsettings {
|
||||
|
||||
void AudioTabController::setMicDeviceIndex(int index, bool notify) {
|
||||
if (index != m_recordingDeviceIndex) {
|
||||
if (index < m_recordingDevices.size()) {
|
||||
vr::EVRSettingsError vrSettingsError;
|
||||
vr::VRSettings()->SetString(vr::k_pch_audio_Section, vr::k_pch_audio_OnRecordDevice_String, m_recordingDevices[index].first.c_str(), &vrSettingsError);
|
||||
if (index > 0 && static_cast<size_t>(index) < m_recordingDevices.size()) {
|
||||
vr::EVRSettingsError vrSettingsError;
|
||||
vr::VRSettings()->SetString(vr::k_pch_audio_Section, vr::k_pch_audio_OnRecordDevice_String, m_recordingDevices[static_cast<size_t>(index)].first.c_str(), &vrSettingsError);
|
||||
if (vrSettingsError != vr::VRSettingsError_None) {
|
||||
LOG(WARNING) << "Could not write \"" << vr::k_pch_audio_OnRecordDevice_String << "\" setting: " << vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);
|
||||
} else {
|
||||
vr::VRSettings()->Sync();
|
||||
audioManager->setMicDevice(m_recordingDevices[index].first, notify);
|
||||
vr::VRSettings()->Sync();
|
||||
audioManager->setMicDevice(m_recordingDevices[static_cast<size_t>(index)].first, notify);
|
||||
}
|
||||
} else if (notify) {
|
||||
emit micDeviceIndexChanged(m_recordingDeviceIndex);
|
||||
@@ -496,8 +502,8 @@ namespace advsettings {
|
||||
auto profileCount = settings->beginReadArray("audioProfiles");
|
||||
for (int i = 0; i < profileCount; i++) {
|
||||
settings->setArrayIndex(i);
|
||||
audioProfiles.emplace_back();
|
||||
auto& entry = audioProfiles[i];
|
||||
audioProfiles.emplace_back();
|
||||
auto& entry = audioProfiles[static_cast<size_t>(i)];
|
||||
entry.profileName = settings->value("profileName").toString().toStdString();
|
||||
entry.playbackName = settings->value("playbackName").toString().toStdString();
|
||||
entry.micName = settings->value("micName").toString().toStdString();
|
||||
@@ -528,9 +534,9 @@ namespace advsettings {
|
||||
auto settings = OverlayController::appSettings();
|
||||
settings->beginGroup(getSettingsName());
|
||||
settings->beginWriteArray("audioProfiles");
|
||||
unsigned i = 0;
|
||||
for (auto& p : audioProfiles) {
|
||||
settings->setArrayIndex(i);
|
||||
int i = 0;
|
||||
for (auto& p : audioProfiles) {
|
||||
settings->setArrayIndex(i);
|
||||
settings->setValue("profileName", QString::fromStdString(p.profileName));
|
||||
settings->setValue("playbackName", QString::fromStdString(p.playbackName));
|
||||
settings->setValue("micName", QString::fromStdString(p.micName));
|
||||
@@ -657,9 +663,9 @@ namespace advsettings {
|
||||
}
|
||||
|
||||
|
||||
unsigned AudioTabController::getAudioProfileCount() {
|
||||
return (unsigned)audioProfiles.size();
|
||||
}
|
||||
unsigned AudioTabController::getAudioProfileCount() {
|
||||
return static_cast<unsigned int>(audioProfiles.size());
|
||||
}
|
||||
|
||||
QString AudioTabController::getAudioProfileName(unsigned index) {
|
||||
if (index < audioProfiles.size()) {
|
||||
@@ -676,28 +682,31 @@ namespace advsettings {
|
||||
|
||||
description: Gets proper index value for selecting specific devices.
|
||||
*/
|
||||
int AudioTabController::getPlaybackIndex(std::string str) {
|
||||
for (int i = 0; i < m_playbackDevices.size(); i++) {
|
||||
if (str.compare(m_playbackDevices[i].second)==0) {
|
||||
return i;
|
||||
int AudioTabController::getPlaybackIndex(std::string str) {
|
||||
//Unsigned to avoid two casts. i won't be negative because we only increment it.
|
||||
for (unsigned int i = 0; i < m_playbackDevices.size(); i++) {
|
||||
if (str.compare(m_playbackDevices[i].second)==0) {
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return m_playbackDeviceIndex;
|
||||
}
|
||||
|
||||
int AudioTabController::getRecordingIndex(std::string str) {
|
||||
for (int i = 0; i < m_recordingDevices.size(); i++) {
|
||||
if (str.compare(m_recordingDevices[i].second) == 0) {
|
||||
return i;
|
||||
int AudioTabController::getRecordingIndex(std::string str) {
|
||||
//Unsigned to avoid two casts. i won't be negative because we only increment it.
|
||||
for (unsigned int i = 0; i < m_recordingDevices.size(); i++) {
|
||||
if (str.compare(m_recordingDevices[i].second) == 0) {
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return m_recordingDeviceIndex;
|
||||
}
|
||||
|
||||
int AudioTabController::getMirrorIndex(std::string str) {
|
||||
for (int i = 0; i < m_playbackDevices.size(); i++) {
|
||||
if (str.compare(m_playbackDevices[i].second) == 0) {
|
||||
return i;
|
||||
//Unsigned to avoid two casts. i won't be negative because we only increment it.
|
||||
for (unsigned int i = 0; i < m_playbackDevices.size(); i++) {
|
||||
if (str.compare(m_playbackDevices[i].second) == 0) {
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user