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:
@@ -308,24 +308,24 @@ namespace advsettings {
|
||||
}
|
||||
|
||||
int AudioTabController::getPlaybackDeviceCount() {
|
||||
return (int)m_playbackDevices.size();
|
||||
return static_cast<int>(m_playbackDevices.size());
|
||||
}
|
||||
|
||||
QString AudioTabController::getPlaybackDeviceName(int index) {
|
||||
if (index < m_playbackDevices.size()) {
|
||||
return QString::fromStdString(m_playbackDevices[index].second);
|
||||
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();
|
||||
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);
|
||||
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) {
|
||||
} 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[index].first.c_str(), &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()) {
|
||||
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[index].first.c_str(), &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);
|
||||
audioManager->setMicDevice(m_recordingDevices[static_cast<size_t>(index)].first, notify);
|
||||
}
|
||||
} else if (notify) {
|
||||
emit micDeviceIndexChanged(m_recordingDeviceIndex);
|
||||
@@ -497,7 +503,7 @@ namespace advsettings {
|
||||
for (int i = 0; i < profileCount; i++) {
|
||||
settings->setArrayIndex(i);
|
||||
audioProfiles.emplace_back();
|
||||
auto& entry = audioProfiles[i];
|
||||
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,7 +534,7 @@ namespace advsettings {
|
||||
auto settings = OverlayController::appSettings();
|
||||
settings->beginGroup(getSettingsName());
|
||||
settings->beginWriteArray("audioProfiles");
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
for (auto& p : audioProfiles) {
|
||||
settings->setArrayIndex(i);
|
||||
settings->setValue("profileName", QString::fromStdString(p.profileName));
|
||||
@@ -658,7 +664,7 @@ namespace advsettings {
|
||||
|
||||
|
||||
unsigned AudioTabController::getAudioProfileCount() {
|
||||
return (unsigned)audioProfiles.size();
|
||||
return static_cast<unsigned int>(audioProfiles.size());
|
||||
}
|
||||
|
||||
QString AudioTabController::getAudioProfileName(unsigned index) {
|
||||
@@ -677,27 +683,30 @@ 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++) {
|
||||
//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 i;
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return m_playbackDeviceIndex;
|
||||
}
|
||||
|
||||
int AudioTabController::getRecordingIndex(std::string str) {
|
||||
for (int i = 0; i < m_recordingDevices.size(); i++) {
|
||||
//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 i;
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return m_recordingDeviceIndex;
|
||||
}
|
||||
|
||||
int AudioTabController::getMirrorIndex(std::string str) {
|
||||
for (int i = 0; i < m_playbackDevices.size(); 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 i;
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user