diff --git a/advancedSettings.pro b/advancedSettings.pro index 02f2372..17c0b17 100644 --- a/advancedSettings.pro +++ b/advancedSettings.pro @@ -5,7 +5,7 @@ #------------------------------------------------- QT += core gui qml quick multimedia widgets -CONFIG += c++11 +CONFIG += c++14 DEFINES += ELPP_THREAD_SAFE ELPP_QT_LOGGING ELPP_NO_DEFAULT_LOG_FILE diff --git a/docs/building_for_windows.md b/docs/building_for_windows.md index bec9bab..f23731b 100644 --- a/docs/building_for_windows.md +++ b/docs/building_for_windows.md @@ -25,8 +25,10 @@ For pushing changes to the repo: Additionally, for fully building portable and installer release versions: 3. [7zip](https://www.7-zip.org/download.html) + 4. [Nullsoft Scriptable Install System (NSIS)](https://sourceforge.net/projects/nsis/) + ## Locations and Environment Variables diff --git a/src/res/qml/AudioPage.qml b/src/res/qml/AudioPage.qml index 774ef91..1d542ce 100644 --- a/src/res/qml/AudioPage.qml +++ b/src/res/qml/AudioPage.qml @@ -40,6 +40,7 @@ MyStackViewPage { onClosed: { if (okClicked) { AudioTabController.deleteAudioProfile(profileIndex) + pttProfileComboBox.currentIndex = 0 } } } @@ -79,6 +80,7 @@ MyStackViewPage { if (okClicked) { if (pttNewProfileName.text != "") { AudioTabController.addPttProfile(pttNewProfileName.text) + } else { audioMessageDialog.showMessage("Create New Profile", "ERROR: No name given.") } @@ -95,7 +97,7 @@ MyStackViewPage { id: audioNewProfileDialog dialogTitle: "Create New Audio Profile" dialogWidth: 600 - dialogHeight: 220 + dialogHeight: 300 dialogContentItem: ColumnLayout { RowLayout { Layout.topMargin: 16 @@ -116,6 +118,19 @@ MyStackViewPage { } } } + RowLayout { + Layout.topMargin: 16 + Layout.leftMargin: 16 + Layout.rightMargin: 16 + MyToggleButton { + id: audioDefaultProfileToggle + Layout.preferredWidth: 250 + text: "Make Default" + onCheckedChanged: { + AudioTabController.setAudioProfileDefault(checked, false) + } + } + } } onClosed: { if (okClicked) { @@ -365,10 +380,11 @@ MyStackViewPage { } } RowLayout { + MyToggleButton { id: audioPttShowNotificationToggle - Layout.leftMargin: 265 - text: "Show notification in HMD." + Layout.leftMargin: 350 + text: "Show notification in HMD" onCheckedChanged: { AudioTabController.setPttShowNotification(checked, false) } @@ -414,7 +430,6 @@ MyStackViewPage { onClicked: { if (audioProfileComboBox.currentIndex > 0) { AudioTabController.applyAudioProfile(audioProfileComboBox.currentIndex - 1) - audioProfileComboBox.currentIndex = 0 } } } @@ -447,7 +462,6 @@ MyStackViewPage { onClicked: { if (pttProfileComboBox.currentIndex > 0) { AudioTabController.applyPttProfile(pttProfileComboBox.currentIndex - 1) - pttProfileComboBox.currentIndex = 0 } } } @@ -558,6 +572,7 @@ MyStackViewPage { audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled audioPttShowNotificationToggle.checked = AudioTabController.pttShowNotification audioPttReverseToggle.checked = AudioTabController.micReversePtt + audioDefaultProfileToggle.checked = AudioTabController.audioProfileDefault componentCompleted = true } @@ -629,12 +644,22 @@ MyStackViewPage { onPttRightControllerEnabledChanged: { audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled } + onAudioProfileDefaultChanged: { + audioDefaultProfileToggle.checked = AudioTabController.audioProfileDefault + } onPttProfilesUpdated: { reloadPttProfiles() } - onAudioProfilesUpdated:{ + onAudioProfilesUpdated: { reloadAudioProfiles() } + onAudioProfileAdded:{ + audioProfileComboBox.currentIndex = AudioTabController.getAudioProfileCount() + } + onPttProfileAdded:{ + pttProfileComboBox.currentIndex = AudioTabController.getPttProfileCount() + } + onPlaybackDeviceListChanged: { var devs1 = [] @@ -707,7 +732,7 @@ MyStackViewPage { for (var i = 0; i < profileCount; i++) { profiles.push(AudioTabController.getAudioProfileName(i)) } - audioProfileComboBox.currentIndex = 0 + audioProfileComboBox.currentIndex = 0; audioProfileComboBox.model = profiles } } diff --git a/src/tabcontrollers/AudioTabController.cpp b/src/tabcontrollers/AudioTabController.cpp index 4998938..dd0feb8 100644 --- a/src/tabcontrollers/AudioTabController.cpp +++ b/src/tabcontrollers/AudioTabController.cpp @@ -51,7 +51,9 @@ void AudioTabController::initStage1() reloadPttProfiles(); reloadPttConfig(); reloadAudioProfiles(); + applyDefaultProfile(); reloadAudioSettings(); + eventLoopTick(); } @@ -63,6 +65,7 @@ void AudioTabController::initStage2( OverlayController* var_parent, std::string notifKey = std::string( OverlayController::applicationKey ) + ".pptnotification"; + vr::VROverlayError overlayError = vr::VROverlay()->CreateOverlay( notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle ); if ( overlayError == vr::VROverlayError_None ) @@ -152,6 +155,11 @@ bool AudioTabController::micReversePtt() const return m_micReversePtt; } +bool AudioTabController::audioProfileDefault() const +{ + return m_isDefaultAudioProfile; +} + void AudioTabController::eventLoopTick() { if ( !eventLoopMutex.try_lock() ) @@ -388,6 +396,19 @@ void AudioTabController::setMicReversePtt( bool value, bool notify ) } } +void AudioTabController::setAudioProfileDefault( bool value, bool notify ) +{ + std::lock_guard lock( eventLoopMutex ); + if ( value != m_isDefaultAudioProfile ) + { + m_isDefaultAudioProfile = value; + if ( notify ) + { + emit audioProfileDefaultChanged( value ); + } + } +} + void AudioTabController::onNewRecordingDevice() { findMicDeviceIndex( audioManager->getMicDevId() ); @@ -432,7 +453,7 @@ int AudioTabController::getPlaybackDeviceCount() QString AudioTabController::getPlaybackDeviceName( int index ) { - if ( index > 0 && static_cast( index ) < m_playbackDevices.size() ) + if ( index >= 0 && static_cast( index ) < m_playbackDevices.size() ) { return QString::fromStdString( m_playbackDevices[static_cast( index )].second ); @@ -450,7 +471,7 @@ int AudioTabController::getRecordingDeviceCount() QString AudioTabController::getRecordingDeviceName( int index ) { - if ( index > 0 && static_cast( index ) < m_playbackDevices.size() ) + if ( index >= 0 && static_cast( index ) < m_playbackDevices.size() ) { return QString::fromStdString( m_recordingDevices[static_cast( index )].second ); @@ -460,7 +481,6 @@ QString AudioTabController::getRecordingDeviceName( int index ) return ""; } } - int AudioTabController::playbackDeviceIndex() const { return m_playbackDeviceIndex; @@ -480,7 +500,7 @@ void AudioTabController::setPlaybackDeviceIndex( int index, bool notify ) { if ( index != m_playbackDeviceIndex ) { - if ( index > 0 + if ( index >= 0 && static_cast( index ) < m_playbackDevices.size() && index != m_mirrorDeviceIndex ) { @@ -540,7 +560,7 @@ void AudioTabController::setMirrorDeviceIndex( int index, bool notify ) audioManager->setMirrorDevice( "", notify ); } } - else if ( index > 0 + else if ( index >= 0 && static_cast( index ) < m_playbackDevices.size() && index != m_playbackDeviceIndex && index != m_mirrorDeviceIndex ) @@ -579,7 +599,7 @@ void AudioTabController::setMicDeviceIndex( int index, bool notify ) { if ( index != m_recordingDeviceIndex ) { - if ( index > 0 + if ( index >= 0 && static_cast( index ) < m_recordingDevices.size() ) { vr::EVRSettingsError vrSettingsError; @@ -726,7 +746,7 @@ void AudioTabController::reloadAudioProfiles() { settings->setArrayIndex( i ); audioProfiles.emplace_back(); - auto& entry = audioProfiles[static_cast( i )]; + auto& entry = audioProfiles[i]; entry.profileName = settings->value( "profileName" ).toString().toStdString(); entry.playbackName @@ -738,6 +758,8 @@ void AudioTabController::reloadAudioProfiles() entry.mirrorMute = settings->value( "mirrorMute", false ).toBool(); entry.mirrorVol = settings->value( "mirrorVol", 0.0 ).toFloat(); entry.micVol = settings->value( "micVol", 1.0 ).toFloat(); + entry.defaultProfile + = settings->value( "defaultProfile", false ).toBool(); } settings->endArray(); settings->endGroup(); @@ -776,6 +798,7 @@ void AudioTabController::saveAudioProfiles() settings->setValue( "mirrorMute", p.mirrorMute ); settings->setValue( "micVol", p.micVol ); settings->setValue( "mirrorVol", p.mirrorVol ); + settings->setValue( "defaultProfile", p.defaultProfile ); i++; } settings->endArray(); @@ -825,10 +848,18 @@ void AudioTabController::addAudioProfile( QString name ) profile->mirrorMute = m_mirrorMuted; profile->mirrorVol = m_mirrorVolume; profile->micVol = m_micVolume; + profile->defaultProfile = m_isDefaultAudioProfile; + if ( m_isDefaultAudioProfile ) + { + removeDefaultProfile( name ); + // to prevent confusion, resets checkbox + setAudioProfileDefault( false ); + } saveAudioProfiles(); OverlayController::appSettings()->sync(); emit audioProfilesUpdated(); + emit audioProfileAdded(); } /* @@ -847,6 +878,7 @@ 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]; @@ -854,6 +886,7 @@ void AudioTabController::applyAudioProfile( unsigned index ) int pInd = getPlaybackIndex( profile.playbackName ); // Needed to keep remembering when swtiching from mirror/main etc. + // TODO OPTI can possibly clean up logic to reduce overhead in future. setMicMuted( false, false ); setMirrorMuted( false, false ); @@ -872,6 +905,7 @@ void AudioTabController::applyAudioProfile( unsigned index ) setMirrorDeviceIndex( mInd, true ); setPlaybackDeviceIndex( pInd, true ); } + setMicDeviceIndex( getRecordingIndex( profile.micName ), true ); setMicMuted( profile.micMute, true ); setMirrorMuted( profile.mirrorMute, true ); @@ -920,17 +954,15 @@ QString AudioTabController::getAudioProfileName( unsigned index ) } /* - Name: getPlaybackIndex, getRecordingIndex, and getMirrorIndex - - input: string, of microphone/playback device name - output: integer for use In: setMicDeviceIndex(int,bool), - setMirrorDeviceIndex(int,bool) setPlayBackDeviceIndex(int,bool) - - description: Gets proper index value for selecting specific devices. +Name: getPlaybackIndex, getRecordingIndex, and getMirrorIndex +input: string, of microphone/playback device name +output: integer for use In: setMicDeviceIndex(int,bool), +setMirrorDeviceIndex(int,bool) setPlayBackDeviceIndex(int,bool) +description: Gets proper index value for selecting specific devices. */ int AudioTabController::getPlaybackIndex( std::string str ) { - // Unsigned to avoid two casts. i won't be negative because we only + // Unsigned to avoid two casts. it won't be negative because we only // increment it. for ( unsigned int i = 0; i < m_playbackDevices.size(); i++ ) { @@ -944,7 +976,7 @@ int AudioTabController::getPlaybackIndex( std::string str ) int AudioTabController::getRecordingIndex( std::string str ) { - // Unsigned to avoid two casts. i won't be negative because we only + // Unsigned to avoid two casts. it won't be negative because we only // increment it. for ( unsigned int i = 0; i < m_recordingDevices.size(); i++ ) { @@ -958,7 +990,7 @@ int AudioTabController::getRecordingIndex( std::string str ) int AudioTabController::getMirrorIndex( std::string str ) { - // Unsigned to avoid two casts. i won't be negative because we only + // Unsigned to avoid two casts. it won't be negative because we only // increment it. for ( unsigned int i = 0; i < m_playbackDevices.size(); i++ ) { @@ -970,8 +1002,51 @@ int AudioTabController::getMirrorIndex( std::string str ) return -1; } -/* ---------------------------*/ +/* +Name: removeDefaultProfile -/*----------------*/ +input: QString name - name of new default profile +output: none + +description: checks all profiles and removes any OTHERS that are set as default. +*/ +void AudioTabController::removeDefaultProfile( QString name ) +{ + AudioProfile* profile = nullptr; + for ( auto& p : audioProfiles ) + { + if ( p.profileName.compare( name.toStdString() ) != 0 ) + { + profile = &p; + profile->defaultProfile = false; + } + } +} + +/* +Name: applyDefaultProfile + +input: none +output: none + +description: checks all profiles and applies the one (if any) with the default +flag); +*/ + +void AudioTabController::applyDefaultProfile() +{ + for ( unsigned i = 0; i < audioProfiles.size(); i++ ) + { + auto& profile = audioProfiles[i]; + if ( profile.defaultProfile ) + { + applyAudioProfile( i ); + break; + } + } +} + +/* ---------------------------*/ +/*----------------------------*/ } // namespace advsettings diff --git a/src/tabcontrollers/AudioTabController.h b/src/tabcontrollers/AudioTabController.h index 0aed808..2402843 100644 --- a/src/tabcontrollers/AudioTabController.h +++ b/src/tabcontrollers/AudioTabController.h @@ -3,7 +3,6 @@ #include "AudioManager.h" #include "PttController.h" -//#include "AudioProfileController.h" #include class QQuickWindow; @@ -23,6 +22,7 @@ struct AudioProfile float micVol = 0.0; bool micMute = false; bool mirrorMute = false; + bool defaultProfile = false; }; class AudioTabController : public PttController @@ -32,17 +32,12 @@ class AudioTabController : public PttController setPlaybackDeviceIndex NOTIFY playbackDeviceIndexChanged ) Q_PROPERTY( int mirrorDeviceIndex READ mirrorDeviceIndex WRITE setMirrorDeviceIndex NOTIFY mirrorDeviceIndexChanged ) - // Q_PROPERTY(bool mirrorPresent READ mirrorPresent NOTIFY - // mirrorPresentChanged) Q_PROPERTY(QString mirrorDevName READ mirrorDevName - // NOTIFY mirrorDevNameChanged) Q_PROPERTY( float mirrorVolume READ mirrorVolume WRITE setMirrorVolume NOTIFY mirrorVolumeChanged ) Q_PROPERTY( bool mirrorMuted READ mirrorMuted WRITE setMirrorMuted NOTIFY mirrorMutedChanged ) Q_PROPERTY( int micDeviceIndex READ micDeviceIndex WRITE setMicDeviceIndex NOTIFY micDeviceIndexChanged ) - // Q_PROPERTY(bool micPresent READ micPresent NOTIFY micPresentChanged) - // Q_PROPERTY(QString micDevName READ micDevName NOTIFY micDevNameChanged) Q_PROPERTY( float micVolume READ micVolume WRITE setMicVolume NOTIFY micVolumeChanged ) Q_PROPERTY( @@ -52,6 +47,8 @@ class AudioTabController : public PttController micProximitySensorCanMuteChanged ) Q_PROPERTY( bool micReversePtt READ micReversePtt WRITE setMicReversePtt NOTIFY micReversePttChanged ) + Q_PROPERTY( bool audioProfileDefault READ audioProfileDefault WRITE + setAudioProfileDefault NOTIFY audioProfileDefaultChanged ) private: OverlayController* parent; @@ -71,6 +68,8 @@ private: bool m_micMuted = false; bool m_micProximitySensorCanMute = false; bool m_micReversePtt = false; + bool m_isDefaultAudioProfile = false; + std::string m_defaultProfileName; unsigned settingsUpdateCounter = 0; @@ -83,7 +82,6 @@ private: { return "audioSettings"; } - // QString getSettingsNameAudio() override { return "audioSettingsTest"; } void onPttStart() override; void onPttStop() override; void onPttEnabled() override; @@ -101,14 +99,14 @@ private: int getPlaybackIndex( std::string str ); int getRecordingIndex( std::string str ); int getMirrorIndex( std::string str ); - // void setPlaybackDeviceControl(int index, bool notify = true); + + void removeDefaultProfile( QString name ); std::vector audioProfiles; - // std::recursive_mutex eventLoopMutexAudio; public: void initStage1(); - void initStage2( OverlayController* parent, QQuickWindow* widget ); + void initStage2( OverlayController* var_parent, QQuickWindow* var_widget ); void reloadAudioSettings(); void saveAudioSettings(); @@ -126,9 +124,11 @@ public: bool micMuted() const; bool micProximitySensorCanMute() const; bool micReversePtt() const; + bool audioProfileDefault() const; void reloadAudioProfiles(); void saveAudioProfiles(); + Q_INVOKABLE void applyDefaultProfile(); Q_INVOKABLE int getPlaybackDeviceCount(); Q_INVOKABLE QString getPlaybackDeviceName( int index ); @@ -136,7 +136,6 @@ public: Q_INVOKABLE int getRecordingDeviceCount(); Q_INVOKABLE QString getRecordingDeviceName( int index ); - // TODO check if needed? Q_INVOKABLE unsigned getAudioProfileCount(); Q_INVOKABLE QString getAudioProfileName( unsigned index ); @@ -162,6 +161,8 @@ public slots: void applyAudioProfile( unsigned index ); void deleteAudioProfile( unsigned index ); + void setAudioProfileDefault( bool value, bool notify = true ); + signals: void playbackDeviceIndexChanged( int index ); @@ -179,6 +180,7 @@ signals: void recordingDeviceListChanged(); void audioProfilesUpdated(); + void audioProfileAdded(); + void audioProfileDefaultChanged( bool value ); }; - } // namespace advsettings diff --git a/src/tabcontrollers/PttController.cpp b/src/tabcontrollers/PttController.cpp index a904e4e..ae5d7e4 100644 --- a/src/tabcontrollers/PttController.cpp +++ b/src/tabcontrollers/PttController.cpp @@ -407,6 +407,7 @@ void PttController::addPttProfile( QString name ) savePttProfiles(); OverlayController::appSettings()->sync(); emit pttProfilesUpdated(); + emit pttProfileAdded(); } void PttController::applyPttProfile( unsigned index ) diff --git a/src/tabcontrollers/PttController.h b/src/tabcontrollers/PttController.h index 6032fc5..3ffc980 100644 --- a/src/tabcontrollers/PttController.h +++ b/src/tabcontrollers/PttController.h @@ -139,6 +139,7 @@ signals: void pttRightControllerEnabledChanged( bool value ); void pttProfilesUpdated(); + void pttProfileAdded(); }; } // namespace advsettings diff --git a/src/tabcontrollers/audiomanager/AudioManagerWindows.cpp b/src/tabcontrollers/audiomanager/AudioManagerWindows.cpp index 139c3b3..10e0f00 100644 --- a/src/tabcontrollers/audiomanager/AudioManagerWindows.cpp +++ b/src/tabcontrollers/audiomanager/AudioManagerWindows.cpp @@ -1,4 +1,4 @@ -#include "audiomanagerwindows.h" +#include "AudioManagerWindows.h" #include #include "easylogging++.h" #include "../AudioTabController.h"