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