From 7be55a2199838863bd853134035cfde2ccf241e4 Mon Sep 17 00:00:00 2001 From: Vasily Date: Sun, 12 Jan 2020 00:24:19 +0100 Subject: [PATCH] Move remaining PttController items into AudioTabController --- build_scripts/qt/sources.pri | 2 - src/tabcontrollers/AudioTabController.cpp | 104 ++++++++++++++++++++ src/tabcontrollers/AudioTabController.h | 51 ++++++++-- src/tabcontrollers/PttController.cpp | 111 ---------------------- src/tabcontrollers/PttController.h | 68 ------------- 5 files changed, 145 insertions(+), 191 deletions(-) delete mode 100644 src/tabcontrollers/PttController.cpp delete mode 100644 src/tabcontrollers/PttController.h diff --git a/build_scripts/qt/sources.pri b/build_scripts/qt/sources.pri index cc484b6..818e52d 100644 --- a/build_scripts/qt/sources.pri +++ b/build_scripts/qt/sources.pri @@ -8,7 +8,6 @@ SOURCES += src/main.cpp\ src/tabcontrollers/StatisticsTabController.cpp \ src/tabcontrollers/SteamVRTabController.cpp \ src/tabcontrollers/UtilitiesTabController.cpp \ - src/tabcontrollers/PttController.cpp \ src/tabcontrollers/VideoTabController.cpp \ src/utils/ChaperoneUtils.cpp \ src/openvr/openvr_init.cpp \ @@ -33,7 +32,6 @@ HEADERS += src/overlaycontroller.h \ src/tabcontrollers/UtilitiesTabController.h \ src/tabcontrollers/VideoTabController.h \ src/tabcontrollers/AudioManager.h \ - src/tabcontrollers/PttController.h \ src/keyboard_input/keyboard_input.h \ src/media_keys/media_keys.h \ src/utils/Matrix.h \ diff --git a/src/tabcontrollers/AudioTabController.cpp b/src/tabcontrollers/AudioTabController.cpp index c3acdeb..bdf63eb 100644 --- a/src/tabcontrollers/AudioTabController.cpp +++ b/src/tabcontrollers/AudioTabController.cpp @@ -1316,4 +1316,108 @@ void AudioTabController::shutdown() LOG( INFO ) << "Audio Tab Controller Has Shut Down"; } +bool AudioTabController::pttEnabled() const +{ + return m_pttEnabled; +} + +bool AudioTabController::pttActive() const +{ + return m_pttActive; +} + +bool AudioTabController::pttShowNotification() const +{ + return m_pttShowNotification; +} + +void AudioTabController::reloadPttConfig() +{ + std::lock_guard lock( eventLoopMutex ); + auto settings = OverlayController::appSettings(); + settings->beginGroup( getSettingsName() ); + setPttEnabled( + settings->value( "pttEnabled", false ).toBool(), true, false ); + setPttShowNotification( + settings->value( "pttShowNotification", true ).toBool(), true, false ); + settings->endGroup(); +} + +void AudioTabController::savePttConfig() +{ + auto settings = OverlayController::appSettings(); + settings->beginGroup( getSettingsName() ); + settings->setValue( "pttEnabled", pttEnabled() ); + settings->setValue( "pttShowNotification", pttShowNotification() ); + settings->endGroup(); +} + +void AudioTabController::startPtt() +{ + m_pttActive = true; + onPttStart(); + if ( m_pttShowNotification + && getNotificationOverlayHandle() != vr::k_ulOverlayHandleInvalid ) + { + vr::VROverlay()->ShowOverlay( getNotificationOverlayHandle() ); + } + emit pttActiveChanged( m_pttActive ); +} + +void AudioTabController::stopPtt() +{ + m_pttActive = false; + onPttStop(); + if ( m_pttShowNotification + && getNotificationOverlayHandle() != vr::k_ulOverlayHandleInvalid ) + { + vr::VROverlay()->HideOverlay( getNotificationOverlayHandle() ); + } + emit pttActiveChanged( m_pttActive ); +} + +void AudioTabController::setPttEnabled( bool value, bool notify, bool save ) +{ + std::lock_guard lock( eventLoopMutex ); + if ( value != m_pttEnabled ) + { + m_pttEnabled = value; + if ( value ) + { + onPttEnabled(); + } + else + { + onPttDisabled(); + } + if ( notify ) + { + emit pttEnabledChanged( value ); + } + if ( save ) + { + savePttConfig(); + } + } +} + +void AudioTabController::setPttShowNotification( bool value, + bool notify, + bool save ) +{ + std::lock_guard lock( eventLoopMutex ); + if ( value != m_pttShowNotification ) + { + m_pttShowNotification = value; + if ( notify ) + { + emit pttShowNotificationChanged( value ); + } + if ( save ) + { + savePttConfig(); + } + } +} + } // namespace advsettings diff --git a/src/tabcontrollers/AudioTabController.h b/src/tabcontrollers/AudioTabController.h index ce60f1f..d7c24d1 100644 --- a/src/tabcontrollers/AudioTabController.h +++ b/src/tabcontrollers/AudioTabController.h @@ -1,9 +1,9 @@ - #pragma once +#include +#include + #include "AudioManager.h" -#include "PttController.h" -#include #include "../utils/FrameRateUtils.h" class QQuickWindow; @@ -29,7 +29,7 @@ struct AudioProfile bool defaultProfile = false; }; -class AudioTabController : public PttController +class AudioTabController : public QObject { Q_OBJECT Q_PROPERTY( int playbackDeviceIndex READ playbackDeviceIndex WRITE @@ -58,6 +58,12 @@ class AudioTabController : public PttController Q_PROPERTY( bool recordingOverride READ recordingOverride WRITE setRecordingOverride NOTIFY recordingOverrideChanged ) + Q_PROPERTY( bool pttEnabled READ pttEnabled WRITE setPttEnabled NOTIFY + pttEnabledChanged ) + Q_PROPERTY( bool pttActive READ pttActive NOTIFY pttActiveChanged ) + Q_PROPERTY( bool pttShowNotification READ pttShowNotification WRITE + setPttShowNotification NOTIFY pttShowNotificationChanged ) + private: vr::VROverlayHandle_t m_ulNotificationOverlayHandle = vr::k_ulOverlayHandleInvalid; @@ -81,21 +87,27 @@ private: unsigned settingsUpdateCounter = 0; + bool m_pttEnabled = false; + bool m_pttActive = false; + bool m_pttShowNotification = false; + std::unique_ptr audioManager; std::vector> m_recordingDevices; std::vector> m_playbackDevices; std::string lastMirrorDevId; - QString getSettingsName() override + std::recursive_mutex eventLoopMutex; + + QString getSettingsName() { return "audioSettings"; } - void onPttStart() override; - void onPttStop() override; - void onPttEnabled() override; - void onPttDisabled() override; + void onPttStart(); + void onPttStop(); + void onPttEnabled(); + void onPttDisabled(); - virtual vr::VROverlayHandle_t getNotificationOverlayHandle() override + virtual vr::VROverlayHandle_t getNotificationOverlayHandle() { return m_ulNotificationOverlayHandle; } @@ -167,6 +179,16 @@ public: void onDeviceStateChanged(); void shutdown(); + bool pttEnabled() const; + bool pttActive() const; + bool pttShowNotification() const; + + void startPtt(); + void stopPtt(); + + void reloadPttConfig(); + void savePttConfig(); + public slots: void setMirrorVolume( float value, bool notify = true ); void setMirrorMuted( bool value, bool notify = true ); @@ -189,6 +211,11 @@ public slots: void setAudioProfileDefault( bool value, bool notify = true ); + void setPttEnabled( bool value, bool notify = true, bool save = true ); + void setPttShowNotification( bool value, + bool notify = true, + bool save = true ); + signals: void playbackDeviceIndexChanged( int index ); @@ -213,5 +240,9 @@ signals: void recordingOverrideChanged(); void defaultProfileDisplay(); + + void pttEnabledChanged( bool value ); + void pttActiveChanged( bool value ); + void pttShowNotificationChanged( bool value ); }; } // namespace advsettings diff --git a/src/tabcontrollers/PttController.cpp b/src/tabcontrollers/PttController.cpp deleted file mode 100644 index 26a76cf..0000000 --- a/src/tabcontrollers/PttController.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "PttController.h" -#include -#include -#include "../overlaycontroller.h" - -// application namespace -namespace advsettings -{ -bool PttController::pttEnabled() const -{ - return m_pttEnabled; -} - -bool PttController::pttActive() const -{ - return m_pttActive; -} - -bool PttController::pttShowNotification() const -{ - return m_pttShowNotification; -} - -void PttController::reloadPttConfig() -{ - std::lock_guard lock( eventLoopMutex ); - auto settings = OverlayController::appSettings(); - settings->beginGroup( getSettingsName() ); - setPttEnabled( - settings->value( "pttEnabled", false ).toBool(), true, false ); - setPttShowNotification( - settings->value( "pttShowNotification", true ).toBool(), true, false ); - settings->endGroup(); -} - -void PttController::savePttConfig() -{ - auto settings = OverlayController::appSettings(); - settings->beginGroup( getSettingsName() ); - settings->setValue( "pttEnabled", pttEnabled() ); - settings->setValue( "pttShowNotification", pttShowNotification() ); - settings->endGroup(); -} - -void PttController::startPtt() -{ - m_pttActive = true; - onPttStart(); - if ( m_pttShowNotification - && getNotificationOverlayHandle() != vr::k_ulOverlayHandleInvalid ) - { - vr::VROverlay()->ShowOverlay( getNotificationOverlayHandle() ); - } - emit pttActiveChanged( m_pttActive ); -} - -void PttController::stopPtt() -{ - m_pttActive = false; - onPttStop(); - if ( m_pttShowNotification - && getNotificationOverlayHandle() != vr::k_ulOverlayHandleInvalid ) - { - vr::VROverlay()->HideOverlay( getNotificationOverlayHandle() ); - } - emit pttActiveChanged( m_pttActive ); -} - -void PttController::setPttEnabled( bool value, bool notify, bool save ) -{ - std::lock_guard lock( eventLoopMutex ); - if ( value != m_pttEnabled ) - { - m_pttEnabled = value; - if ( value ) - { - onPttEnabled(); - } - else - { - onPttDisabled(); - } - if ( notify ) - { - emit pttEnabledChanged( value ); - } - if ( save ) - { - savePttConfig(); - } - } -} - -void PttController::setPttShowNotification( bool value, bool notify, bool save ) -{ - std::lock_guard lock( eventLoopMutex ); - if ( value != m_pttShowNotification ) - { - m_pttShowNotification = value; - if ( notify ) - { - emit pttShowNotificationChanged( value ); - } - if ( save ) - { - savePttConfig(); - } - } -} - -} // namespace advsettings diff --git a/src/tabcontrollers/PttController.h b/src/tabcontrollers/PttController.h deleted file mode 100644 index 703ff13..0000000 --- a/src/tabcontrollers/PttController.h +++ /dev/null @@ -1,68 +0,0 @@ - -#pragma once - -#include -#include -#include -#include -#include -#include - -class QQuickWindow; -// application namespace -namespace advsettings -{ -// forward declaration -class OverlayController; - -class PttController : public QObject -{ - Q_OBJECT - Q_PROPERTY( bool pttEnabled READ pttEnabled WRITE setPttEnabled NOTIFY - pttEnabledChanged ) - Q_PROPERTY( bool pttActive READ pttActive NOTIFY pttActiveChanged ) - Q_PROPERTY( bool pttShowNotification READ pttShowNotification WRITE - setPttShowNotification NOTIFY pttShowNotificationChanged ) - -protected: - bool m_pttEnabled = false; - bool m_pttActive = false; - bool m_pttShowNotification = false; - -protected: - virtual QString getSettingsName() = 0; - virtual void onPttStart() {} - virtual void onPttStop() {} - virtual void onPttEnabled() {} - virtual void onPttDisabled() {} - - virtual vr::VROverlayHandle_t getNotificationOverlayHandle() - { - return vr::k_ulOverlayHandleInvalid; - } - std::recursive_mutex eventLoopMutex; - -public: - bool pttEnabled() const; - bool pttActive() const; - bool pttShowNotification() const; - - void startPtt(); - void stopPtt(); - - void reloadPttConfig(); - void savePttConfig(); - -public slots: - void setPttEnabled( bool value, bool notify = true, bool save = true ); - void setPttShowNotification( bool value, - bool notify = true, - bool save = true ); - -signals: - void pttEnabledChanged( bool value ); - void pttActiveChanged( bool value ); - void pttShowNotificationChanged( bool value ); -}; - -} // namespace advsettings