From 84d5be7771f6ebb004e15b3eeb3f5433deada376 Mon Sep 17 00:00:00 2001 From: ykeara Date: Thu, 2 May 2019 11:29:49 -0500 Subject: [PATCH] Fixes Various Audio Issues. (#185) * perf graph overlay/checkbox added * added toggle Chaperone action * toggle chaperone non-functional * fixed chaperone toggle action const to once * Added Proximity Sensor Action back-end, not implemented via logic Until fixed by valve * added default WMR controller profile * formated * formated steamvrtabcontroller.h * fixed un-intended change * fixed audio profile Bug w/ changed devices * fixed name being used as param instead of ID * fixed loop logic in saveAudioProfile * audio profile fix WIP defaults OVR integration * fixed profile Saves, delete logic and mirror logic needed * fixed QML format, added TODO message * Fixed Audio Profile Behavior * fixed qml reference error * audiodeviceselector changed qml * Removed some comments --- src/overlaycontroller.cpp | 4 +- .../device_selector/AudioDeviceSelector.qml | 2 +- .../dialog_boxes/AudioDeleteProfileDialog.qml | 5 +- .../dialog_boxes/PttDeleteProfileDialog.qml | 4 + src/tabcontrollers/AudioTabController.cpp | 291 ++++++++++++++---- src/tabcontrollers/AudioTabController.h | 12 + 6 files changed, 262 insertions(+), 56 deletions(-) diff --git a/src/overlaycontroller.cpp b/src/overlaycontroller.cpp index dddf612..e668650 100644 --- a/src/overlaycontroller.cpp +++ b/src/overlaycontroller.cpp @@ -736,7 +736,8 @@ void OverlayController::mainEventLoop() m_moveCenterTabController.shutdown(); // Un-mute mic before Exiting VR, as it is set at system level Not // Vr level. - m_audioTabController.setMicMuted( false, false ); + // m_audioTabController.setMicMuted( false, false ); + m_audioTabController.shutdown(); m_chaperoneTabController.shutdown(); Shutdown(); QApplication::exit(); @@ -857,7 +858,6 @@ void OverlayController::mainEventLoop() m_settingsTabController.eventLoopTick(); m_reviveTabController.eventLoopTick(); m_audioTabController.eventLoopTick(); - // TODO do I need loop for vide? if ( m_ulOverlayThumbnailHandle != vr::k_ulOverlayHandleInvalid ) { diff --git a/src/res/qml/audio_page/device_selector/AudioDeviceSelector.qml b/src/res/qml/audio_page/device_selector/AudioDeviceSelector.qml index c2d0f67..c99a5d2 100644 --- a/src/res/qml/audio_page/device_selector/AudioDeviceSelector.qml +++ b/src/res/qml/audio_page/device_selector/AudioDeviceSelector.qml @@ -21,7 +21,7 @@ RowLayout { Layout.preferredWidth: 850 onActivated: { if (deviceIndex >= 0) { - AudioTabController.setPlaybackDeviceIndex(deviceIndex, false) + AudioTabController.setPlaybackDeviceIndex(deviceIndex) } setShownAudioDevice(index) } diff --git a/src/res/qml/audio_page/dialog_boxes/AudioDeleteProfileDialog.qml b/src/res/qml/audio_page/dialog_boxes/AudioDeleteProfileDialog.qml index 10f4ffc..e36d2b6 100644 --- a/src/res/qml/audio_page/dialog_boxes/AudioDeleteProfileDialog.qml +++ b/src/res/qml/audio_page/dialog_boxes/AudioDeleteProfileDialog.qml @@ -6,13 +6,16 @@ import "../../common" MyDialogOkCancelPopup { id: audioDeleteProfileDialog + dialogWidth: 600 + dialogHeight: 300 + y: -300 + x: 100 property int profileIndex: -1 dialogTitle: "Delete Profile" dialogText: "Do you really want to delete this audio profile?" onClosed: { if (okClicked) { AudioTabController.deleteAudioProfile(profileIndex) - pttProfileComboBox.currentIndex = 0 } } } diff --git a/src/res/qml/audio_page/dialog_boxes/PttDeleteProfileDialog.qml b/src/res/qml/audio_page/dialog_boxes/PttDeleteProfileDialog.qml index 71d2157..9966e1b 100644 --- a/src/res/qml/audio_page/dialog_boxes/PttDeleteProfileDialog.qml +++ b/src/res/qml/audio_page/dialog_boxes/PttDeleteProfileDialog.qml @@ -8,6 +8,10 @@ MyDialogOkCancelPopup { id: pttDeleteProfileDialog property int profileIndex: -1 dialogTitle: "Delete Profile" + dialogWidth: 600 + dialogHeight: 300 + y: -300 + x: 100 dialogText: "Do you really want to delete this ptt profile?" onClosed: { if (okClicked) { diff --git a/src/tabcontrollers/AudioTabController.cpp b/src/tabcontrollers/AudioTabController.cpp index dd393a7..1a6276f 100644 --- a/src/tabcontrollers/AudioTabController.cpp +++ b/src/tabcontrollers/AudioTabController.cpp @@ -51,7 +51,7 @@ void AudioTabController::initStage1() reloadPttProfiles(); reloadPttConfig(); reloadAudioProfiles(); - applyDefaultProfile(); + // applyDefaultProfile(); reloadAudioSettings(); eventLoopTick(); @@ -467,11 +467,42 @@ QString AudioTabController::getPlaybackDeviceName( int index ) } } +std::string AudioTabController::getPlaybackDeviceID( int index ) +{ + if ( index >= 0 && static_cast( index ) < m_playbackDevices.size() ) + { + return m_playbackDevices[static_cast( index )].first; + } + else + { + LOG( ERROR ) << "Playback Device does not have a unique id"; + return ""; + } +} + +std::string AudioTabController::getMirrorDeviceID( int index ) +{ + return getPlaybackDeviceID( index ); +} + int AudioTabController::getRecordingDeviceCount() { return static_cast( m_recordingDevices.size() ); } +std::string AudioTabController::getRecordingDeviceID( int index ) +{ + if ( index >= 0 && static_cast( index ) < m_playbackDevices.size() ) + { + return m_recordingDevices[static_cast( index )].first; + } + else + { + LOG( ERROR ) << "Recording Device does not have a unique id"; + return ""; + } +} + QString AudioTabController::getRecordingDeviceName( int index ) { if ( index >= 0 && static_cast( index ) < m_playbackDevices.size() ) @@ -484,6 +515,7 @@ QString AudioTabController::getRecordingDeviceName( int index ) return ""; } } + int AudioTabController::playbackDeviceIndex() const { return m_playbackDeviceIndex; @@ -507,28 +539,9 @@ void AudioTabController::setPlaybackDeviceIndex( int index, bool notify ) && static_cast( 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[static_cast( 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[static_cast( index )].first, - notify ); - } + // Code to only change the Device and not apply changes to SteamVR + audioManager->setPlaybackDevice( + m_playbackDevices[static_cast( index )].first, notify ); } else if ( notify ) { @@ -605,27 +618,10 @@ void AudioTabController::setMicDeviceIndex( int index, bool notify ) if ( index >= 0 && static_cast( 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( 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[static_cast( index )].first, - notify ); - } + // code to just change Mic + audioManager->setMicDevice( + m_recordingDevices[static_cast( index )].first, + notify ); } else if ( notify ) { @@ -763,6 +759,11 @@ void AudioTabController::reloadAudioProfiles() entry.micVol = settings->value( "micVol", 1.0 ).toFloat(); entry.defaultProfile = settings->value( "defaultProfile", false ).toBool(); + entry.mirrorID = settings->value( "mirrorID" ).toString().toStdString(); + entry.recordingID + = settings->value( "recordingID" ).toString().toStdString(); + entry.playbackID + = settings->value( "playbackID" ).toString().toStdString(); } settings->endArray(); settings->endGroup(); @@ -802,6 +803,12 @@ void AudioTabController::saveAudioProfiles() settings->setValue( "micVol", p.micVol ); settings->setValue( "mirrorVol", p.mirrorVol ); settings->setValue( "defaultProfile", p.defaultProfile ); + + settings->setValue( "playbackID", + QString::fromStdString( p.playbackID ) ); + settings->setValue( "mirrorID", QString::fromStdString( p.mirrorID ) ); + settings->setValue( "recordingID", + QString::fromStdString( p.recordingID ) ); i++; } settings->endArray(); @@ -852,8 +859,16 @@ void AudioTabController::addAudioProfile( QString name ) profile->mirrorVol = m_mirrorVolume; profile->micVol = m_micVolume; profile->defaultProfile = m_isDefaultAudioProfile; + + profile->playbackID = getPlaybackDeviceID( m_playbackDeviceIndex ); + profile->mirrorID = getMirrorDeviceID( m_mirrorDeviceIndex ); + profile->recordingID = getRecordingDeviceID( m_recordingDeviceIndex ); + if ( m_isDefaultAudioProfile ) { + setDefaultMic( m_recordingDeviceIndex ); + setDefaultPlayback( m_playbackDeviceIndex ); + removeOtherDefaultProfiles( name ); setAudioProfileDefault( false ); @@ -877,15 +892,15 @@ other: none Description: Applies the required logic to activate the audio profile. */ -// TODO Remembers Mirror Volume when switching to main volume. + void AudioTabController::applyAudioProfile( unsigned index ) { std::lock_guard lock( eventLoopMutex ); if ( index < audioProfiles.size() ) { auto& profile = audioProfiles[index]; - int mInd = getMirrorIndex( profile.mirrorName ); - int pInd = getPlaybackIndex( profile.playbackName ); + int mInd = getMirrorIndex( profile.mirrorID ); + int pInd = getPlaybackIndex( profile.playbackID ); // Needed to keep remembering when swtiching from mirror/main etc. // TODO OPTI can possibly clean up logic to reduce overhead in future. @@ -908,7 +923,7 @@ void AudioTabController::applyAudioProfile( unsigned index ) setPlaybackDeviceIndex( pInd, true ); } - setMicDeviceIndex( getRecordingIndex( profile.micName ), true ); + setMicDeviceIndex( getRecordingIndex( profile.recordingID ), true ); setMicMuted( profile.micMute, true ); setMirrorMuted( profile.mirrorMute, true ); setMicVolume( profile.micVol, true ); @@ -934,6 +949,46 @@ void AudioTabController::deleteAudioProfile( unsigned index ) if ( index < audioProfiles.size() ) { auto pos = audioProfiles.begin() + index; + // Remove PlayBack and Mic from Steam API Mirror Is handled @ shutdown + // This is necessary because Mirror Device does not appear to be handled + // via native windows api. + if ( audioProfiles.at( index ).defaultProfile ) + { + vr::EVRSettingsError vrSettingsError; + vr::VRSettings()->RemoveKeyInSection( + vr::k_pch_audio_Section, + vr::k_pch_audio_OnPlaybackDevice_String, + &vrSettingsError ); + if ( vrSettingsError != vr::VRSettingsError_None ) + { + LOG( WARNING ) + << "Could not remove \"" + << vr::k_pch_audio_OnPlaybackDevice_String << "\" setting: " + << vr::VRSettings()->GetSettingsErrorNameFromEnum( + vrSettingsError ); + } + else + { + vr::VRSettings()->Sync(); + } + + vr::VRSettings()->RemoveKeyInSection( + vr::k_pch_audio_Section, + vr::k_pch_audio_OnRecordDevice_String, + &vrSettingsError ); + if ( vrSettingsError != vr::VRSettingsError_None ) + { + LOG( WARNING ) + << "Could not remove \"" + << vr::k_pch_audio_OnRecordDevice_String << "\" setting: " + << vr::VRSettings()->GetSettingsErrorNameFromEnum( + vrSettingsError ); + } + else + { + vr::VRSettings()->Sync(); + } + } audioProfiles.erase( pos ); saveAudioProfiles(); OverlayController::appSettings()->sync(); @@ -957,7 +1012,7 @@ QString AudioTabController::getAudioProfileName( unsigned index ) /* Name: getPlaybackIndex, getRecordingIndex, and getMirrorIndex -input: string, of microphone/playback device name +input: string, of microphone/playback device ID output: integer for use In: setMicDeviceIndex(int,bool), setMirrorDeviceIndex(int,bool) setPlayBackDeviceIndex(int,bool) description: Gets proper index value for selecting specific devices. @@ -968,7 +1023,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].second ) == 0 ) + if ( str.compare( m_playbackDevices[i].first ) == 0 ) { return static_cast( i ); } @@ -982,7 +1037,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].second ) == 0 ) + if ( str.compare( m_recordingDevices[i].first ) == 0 ) { return static_cast( i ); } @@ -996,7 +1051,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].second ) == 0 ) + if ( str.compare( m_playbackDevices[i].first ) == 0 ) { return static_cast( i ); } @@ -1004,6 +1059,112 @@ int AudioTabController::getMirrorIndex( std::string str ) return -1; } +/* + Name: setDefaultPlayback/Mirror/Mic + + input int index = index of m_playbackDevices to set + + description: sets the SteamVR "on launch" audio options + + NOTE: We Assume Index passed is good, and valid +*/ + +void AudioTabController::setDefaultPlayback( int index, bool notify ) +{ + vr::EVRSettingsError vrSettingsError; + vr::VRSettings()->SetString( + vr::k_pch_audio_Section, + vr::k_pch_audio_OnPlaybackDevice_String, + m_playbackDevices[static_cast( 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[static_cast( index )].first, notify ); + } +} + +void AudioTabController::setDefaultMic( int index, bool notify ) +{ + vr::EVRSettingsError vrSettingsError; + vr::VRSettings()->SetString( + vr::k_pch_audio_Section, + vr::k_pch_audio_OnRecordDevice_String, + m_recordingDevices[static_cast( 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[static_cast( index )].first, notify ); + } +} + +void AudioTabController::setDefaultMirror( int index, bool notify ) +{ + if ( index == -1 ) + { + vr::EVRSettingsError vrSettingsError; + vr::VRSettings()->RemoveKeyInSection( + vr::k_pch_audio_Section, + vr::k_pch_audio_OnPlaybackMirrorDevice_String, + &vrSettingsError ); + if ( vrSettingsError != vr::VRSettingsError_None ) + { + LOG( WARNING ) << "Could not remove \"" + << vr::k_pch_audio_OnPlaybackMirrorDevice_String + << "\" setting: " + << vr::VRSettings()->GetSettingsErrorNameFromEnum( + vrSettingsError ); + } + else + { + vr::VRSettings()->Sync(); + audioManager->setMirrorDevice( "", notify ); + } + } + else + { + vr::EVRSettingsError vrSettingsError; + vr::VRSettings()->SetString( + vr::k_pch_audio_Section, + vr::k_pch_audio_OnPlaybackMirrorDevice_String, + m_playbackDevices[static_cast( 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[static_cast( index )].first, notify ); + } + } +} + /* Name: removeOtherDefaultProfiles @@ -1057,4 +1218,30 @@ int AudioTabController::getDefaultAudioProfileIndex() /* ---------------------------*/ /*----------------------------*/ +void AudioTabController::shutdown() +{ + setMicMuted( false, false ); + std::string mID; + bool hasDefaultProfile = false; + for ( unsigned i = 0; i < audioProfiles.size(); i++ ) + { + auto& profile = audioProfiles[i]; + if ( profile.defaultProfile ) + { + mID = profile.mirrorID; + hasDefaultProfile = true; + break; + } + } + if ( hasDefaultProfile ) + { + setMirrorDeviceIndex( getMirrorIndex( mID ) ); + } + else + { + setMirrorDeviceIndex( -1 ); + } + LOG( INFO ) << "Audio Tab Controller Has Shut Down"; +} + } // namespace advsettings diff --git a/src/tabcontrollers/AudioTabController.h b/src/tabcontrollers/AudioTabController.h index 9c0f269..fe5945d 100644 --- a/src/tabcontrollers/AudioTabController.h +++ b/src/tabcontrollers/AudioTabController.h @@ -18,6 +18,9 @@ struct AudioProfile std::string playbackName; std::string mirrorName; std::string micName; + std::string recordingID; + std::string playbackID; + std::string mirrorID; float mirrorVol = 0.0; float micVol = 0.0; bool micMute = false; @@ -103,6 +106,14 @@ private: void removeOtherDefaultProfiles( QString name ); + std::string getPlaybackDeviceID( int index ); + std::string getMirrorDeviceID( int index ); + std::string getRecordingDeviceID( int index ); + + void setDefaultPlayback( int index, bool notify = true ); + void setDefaultMirror( int index, bool notify = true ); + void setDefaultMic( int index, bool notify = true ); + std::vector audioProfiles; public: @@ -147,6 +158,7 @@ public: void onNewPlaybackDevice(); void onNewMirrorDevice(); void onDeviceStateChanged(); + void shutdown(); public slots: void setMirrorVolume( float value, bool notify = true );