Change pair<string, string> to custom type in AudioTabController

Explicitly named fields are more readable.
This commit is contained in:
Vasily
2020-01-18 00:17:28 +01:00
committed by username223
parent af572ee0b7
commit b6eaca6caa
6 changed files with 59 additions and 45 deletions
+20 -21
View File
@@ -412,7 +412,7 @@ 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 );
m_playbackDevices[static_cast<size_t>( index )].name() );
}
else
{
@@ -424,7 +424,7 @@ std::string AudioTabController::getPlaybackDeviceID( int index )
{
if ( index >= 0 && static_cast<size_t>( index ) < m_playbackDevices.size() )
{
return m_playbackDevices[static_cast<size_t>( index )].first;
return m_playbackDevices[static_cast<size_t>( index )].id();
}
else
{
@@ -447,7 +447,7 @@ std::string AudioTabController::getRecordingDeviceID( int index )
{
if ( index >= 0 && static_cast<size_t>( index ) < m_playbackDevices.size() )
{
return m_recordingDevices[static_cast<size_t>( index )].first;
return m_recordingDevices[static_cast<size_t>( index )].id();
}
else
{
@@ -461,7 +461,7 @@ QString AudioTabController::getRecordingDeviceName( int index )
if ( index >= 0 && static_cast<size_t>( index ) < m_playbackDevices.size() )
{
return QString::fromStdString(
m_recordingDevices[static_cast<size_t>( index )].second );
m_recordingDevices[static_cast<size_t>( index )].name() );
}
else
{
@@ -494,7 +494,7 @@ void AudioTabController::setPlaybackDeviceIndex( int index, bool notify )
{
// Code to only change the Device and not apply changes to SteamVR
audioManager->setPlaybackDevice(
m_playbackDevices[static_cast<size_t>( index )].first, notify );
m_playbackDevices[static_cast<size_t>( index )].id(), notify );
}
else if ( notify )
{
@@ -538,7 +538,7 @@ void AudioTabController::setMirrorDeviceIndex( int index, bool notify )
vr::VRSettings()->SetString(
vr::k_pch_audio_Section,
vr::k_pch_audio_PlaybackMirrorDevice_String,
m_playbackDevices[static_cast<size_t>( index )].first.c_str(),
m_playbackDevices[static_cast<size_t>( index )].id().c_str(),
&vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None )
{
@@ -553,7 +553,7 @@ void AudioTabController::setMirrorDeviceIndex( int index, bool notify )
{
vr::VRSettings()->Sync();
audioManager->setMirrorDevice(
m_playbackDevices[static_cast<size_t>( index )].first,
m_playbackDevices[static_cast<size_t>( index )].id(),
notify );
}
}
@@ -583,8 +583,7 @@ void AudioTabController::setMicDeviceIndex( int index, bool notify )
setMicMuted( false, true );
// code to just change Mic
audioManager->setMicDevice(
m_recordingDevices[static_cast<size_t>( index )].first,
notify );
m_recordingDevices[static_cast<size_t>( index )].id(), notify );
if ( tempProx )
{
setMicProximitySensorCanMute( true );
@@ -603,7 +602,7 @@ void AudioTabController::findPlaybackDeviceIndex( std::string id, bool notify )
bool deviceFound = false;
for ( auto d : m_playbackDevices )
{
if ( d.first.compare( id ) == 0 )
if ( d.id().compare( id ) == 0 )
{
deviceFound = true;
break;
@@ -629,7 +628,7 @@ void AudioTabController::findMirrorDeviceIndex( std::string id, bool notify )
bool deviceFound = false;
for ( auto d : m_playbackDevices )
{
if ( d.first.compare( id ) == 0 )
if ( d.id().compare( id ) == 0 )
{
deviceFound = true;
break;
@@ -655,7 +654,7 @@ void AudioTabController::findMicDeviceIndex( std::string id, bool notify )
bool deviceFound = false;
for ( auto d : m_recordingDevices )
{
if ( d.first.compare( id ) == 0 )
if ( d.id().compare( id ) == 0 )
{
deviceFound = true;
break;
@@ -1085,7 +1084,7 @@ int AudioTabController::getPlaybackIndex( std::string str )
// increment it.
for ( unsigned int i = 0; i < m_playbackDevices.size(); i++ )
{
if ( str.compare( m_playbackDevices[i].first ) == 0 )
if ( str.compare( m_playbackDevices[i].id() ) == 0 )
{
return static_cast<int>( i );
}
@@ -1099,7 +1098,7 @@ int AudioTabController::getRecordingIndex( std::string str )
// increment it.
for ( unsigned int i = 0; i < m_recordingDevices.size(); i++ )
{
if ( str.compare( m_recordingDevices[i].first ) == 0 )
if ( str.compare( m_recordingDevices[i].id() ) == 0 )
{
return static_cast<int>( i );
}
@@ -1113,7 +1112,7 @@ int AudioTabController::getMirrorIndex( std::string str )
// increment it.
for ( unsigned int i = 0; i < m_playbackDevices.size(); i++ )
{
if ( str.compare( m_playbackDevices[i].first ) == 0 )
if ( str.compare( m_playbackDevices[i].id() ) == 0 )
{
return static_cast<int>( i );
}
@@ -1137,7 +1136,7 @@ void AudioTabController::setDefaultPlayback( int index, bool notify )
vr::VRSettings()->SetString(
vr::k_pch_audio_Section,
vr::k_pch_audio_PlaybackDeviceOverrideName_String,
m_playbackDevices[static_cast<size_t>( index )].first.c_str(),
m_playbackDevices[static_cast<size_t>( index )].id().c_str(),
&vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None )
{
@@ -1151,7 +1150,7 @@ void AudioTabController::setDefaultPlayback( int index, bool notify )
{
vr::VRSettings()->Sync();
audioManager->setPlaybackDevice(
m_playbackDevices[static_cast<size_t>( index )].first, notify );
m_playbackDevices[static_cast<size_t>( index )].id(), notify );
}
}
@@ -1161,7 +1160,7 @@ void AudioTabController::setDefaultMic( int index, bool notify )
vr::VRSettings()->SetString(
vr::k_pch_audio_Section,
vr::k_pch_audio_RecordingDeviceOverrideName_String,
m_recordingDevices[static_cast<size_t>( index )].first.c_str(),
m_recordingDevices[static_cast<size_t>( index )].id().c_str(),
&vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None )
{
@@ -1175,7 +1174,7 @@ void AudioTabController::setDefaultMic( int index, bool notify )
{
vr::VRSettings()->Sync();
audioManager->setMicDevice(
m_recordingDevices[static_cast<size_t>( index )].first, notify );
m_recordingDevices[static_cast<size_t>( index )].id(), notify );
}
}
@@ -1208,7 +1207,7 @@ void AudioTabController::setDefaultMirror( int index, bool notify )
vr::VRSettings()->SetString(
vr::k_pch_audio_Section,
vr::k_pch_audio_PlaybackMirrorDevice_String,
m_playbackDevices[static_cast<size_t>( index )].first.c_str(),
m_playbackDevices[static_cast<size_t>( index )].id().c_str(),
&vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None )
{
@@ -1222,7 +1221,7 @@ void AudioTabController::setDefaultMirror( int index, bool notify )
{
vr::VRSettings()->Sync();
audioManager->setMirrorDevice(
m_playbackDevices[static_cast<size_t>( index )].first, notify );
m_playbackDevices[static_cast<size_t>( index )].id(), notify );
}
}
}
+2 -2
View File
@@ -91,8 +91,8 @@ private:
bool m_pttActive = false;
std::unique_ptr<AudioManager> audioManager;
std::vector<std::pair<std::string, std::string>> m_recordingDevices;
std::vector<std::pair<std::string, std::string>> m_playbackDevices;
std::vector<AudioDevice> m_recordingDevices;
std::vector<AudioDevice> m_playbackDevices;
std::string lastMirrorDevId;
std::recursive_mutex eventLoopMutex;
+25 -4
View File
@@ -8,6 +8,29 @@ namespace advsettings
{
class AudioTabController;
class AudioDevice
{
public:
AudioDevice( const std::string id, const std::string name )
: m_id( id ), m_name( name )
{
}
[[nodiscard]] std::string id() const noexcept
{
return m_id;
}
[[nodiscard]] std::string name() const noexcept
{
return m_name;
}
private:
const std::string m_id;
const std::string m_name;
};
class AudioManager
{
public:
@@ -39,10 +62,8 @@ public:
virtual bool getMicMuted() = 0;
virtual bool setMicMuted( bool value ) = 0;
virtual std::vector<std::pair<std::string, std::string>>
getRecordingDevices() = 0;
virtual std::vector<std::pair<std::string, std::string>>
getPlaybackDevices() = 0;
virtual std::vector<AudioDevice> getRecordingDevices() = 0;
virtual std::vector<AudioDevice> getPlaybackDevices() = 0;
};
} // namespace advsettings
@@ -36,10 +36,8 @@ public:
virtual bool getMicMuted() override;
virtual bool setMicMuted( bool value ) override;
virtual std::vector<std::pair<std::string, std::string>>
getRecordingDevices() override;
virtual std::vector<std::pair<std::string, std::string>>
getPlaybackDevices() override;
virtual std::vector<AudioDevice> getRecordingDevices() override;
virtual std::vector<AudioDevice> getPlaybackDevices() override;
};
} // namespace advsettings
@@ -354,14 +354,12 @@ bool AudioManagerWindows::setMicMuted( bool value )
return false;
}
std::vector<std::pair<std::string, std::string>>
AudioManagerWindows::getRecordingDevices()
std::vector<AudioDevice> AudioManagerWindows::getRecordingDevices()
{
return getDevices( audioDeviceEnumerator, eCapture );
}
std::vector<std::pair<std::string, std::string>>
AudioManagerWindows::getPlaybackDevices()
std::vector<AudioDevice> AudioManagerWindows::getPlaybackDevices()
{
return getDevices( audioDeviceEnumerator, eRender );
}
@@ -505,11 +503,11 @@ std::string AudioManagerWindows::getDeviceId( IMMDevice* device )
return "";
}
std::vector<std::pair<std::string, std::string>>
std::vector<AudioDevice>
AudioManagerWindows::getDevices( IMMDeviceEnumerator* deviceEnumerator,
EDataFlow dataFlow )
{
std::vector<std::pair<std::string, std::string>> retval;
std::vector<AudioDevice> retval;
IMMDeviceCollection* ppDevices = nullptr;
if ( deviceEnumerator->EnumAudioEndpoints(
dataFlow, DEVICE_STATE_ACTIVE, &ppDevices )
@@ -523,8 +521,8 @@ std::vector<std::pair<std::string, std::string>>
ppDevices->Item( i, &device );
if ( device )
{
retval.emplace_back( getDeviceId( device ),
getDeviceName( device ) );
retval.emplace_back( AudioDevice( getDeviceId( device ),
getDeviceName( device ) ) );
}
}
ppDevices->Release();
@@ -56,10 +56,8 @@ public:
virtual bool getMicMuted() override;
virtual bool setMicMuted( bool value ) override;
virtual std::vector<std::pair<std::string, std::string>>
getRecordingDevices() override;
virtual std::vector<std::pair<std::string, std::string>>
getPlaybackDevices() override;
virtual std::vector<AudioDevice> getRecordingDevices() override;
virtual std::vector<AudioDevice> getPlaybackDevices() override;
void deleteMirrorDevice();
@@ -91,8 +89,8 @@ private:
IAudioEndpointVolume* getAudioEndpointVolume( IMMDevice* device );
std::string getDeviceName( IMMDevice* device );
std::string getDeviceId( IMMDevice* device );
std::vector<std::pair<std::string, std::string>>
getDevices( IMMDeviceEnumerator* deviceEnumerator, EDataFlow dataFlow );
std::vector<AudioDevice> getDevices( IMMDeviceEnumerator* deviceEnumerator,
EDataFlow dataFlow );
};
} // namespace advsettings