Skip to content

Commit

Permalink
Added push-to-mute for microphone.
Browse files Browse the repository at this point in the history
  • Loading branch information
matzman666 committed Aug 8, 2017
1 parent 08c5b19 commit 0bc693c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
26 changes: 20 additions & 6 deletions bin/win64/res/qml/AudioPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,22 @@ MyStackViewPage {
}
}
}
MyToggleButton {
id: audioPttShowNotificationToggle
Layout.leftMargin: 265
text: "Show notification in HMD."
onCheckedChanged: {
AudioTabController.setPttShowNotification(checked, false)
RowLayout {
MyToggleButton {
id: audioPttShowNotificationToggle
Layout.leftMargin: 265
text: "Show notification in HMD."
onCheckedChanged: {
AudioTabController.setPttShowNotification(checked, false)
}
}
MyToggleButton {
id: audioPttReverseToggle
Layout.leftMargin: 118
text: "Push-to-Mute"
onClicked: {
AudioTabController.setMicReversePtt(checked, false)
}
}
}
RowLayout {
Expand Down Expand Up @@ -438,6 +448,7 @@ MyStackViewPage {
audioPttLeftControllerToggle.checked = AudioTabController.pttLeftControllerEnabled
audioPttRightControllerToggle.checked = AudioTabController.pttRightControllerEnabled
audioPttShowNotificationToggle.checked = AudioTabController.pttShowNotification
audioPttReverseToggle.checked = AudioTabController.micReversePtt
componentCompleted = true
}

Expand Down Expand Up @@ -491,6 +502,9 @@ MyStackViewPage {
onMicProximitySensorCanMuteChanged: {
audioMuteProximitySensorToggle.checked = AudioTabController.micProximitySensorCanMute
}
onMicReversePttChanged: {
audioPttReverseToggle.checked = AudioTabController.micReversePtt
}
onPttEnabledChanged: {
audioPttEnabledToggle.checked = AudioTabController.pttEnabled
}
Expand Down
42 changes: 39 additions & 3 deletions src/tabcontrollers/AudioTabController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ namespace advsettings {
auto settings = OverlayController::appSettings();
settings->beginGroup(getSettingsName());
setMicProximitySensorCanMute(settings->value("micProximitySensorCanMute", false).toBool(), false);
setMicReversePtt(settings->value("micReversePtt", false).toBool(), false);
settings->endGroup();
}

void AudioTabController::saveAudioSettings() {
auto settings = OverlayController::appSettings();
settings->beginGroup(getSettingsName());
settings->setValue("micProximitySensorCanMute", micProximitySensorCanMute());
settings->setValue("micReversePtt", micReversePtt());
settings->endGroup();
settings->sync();
}
Expand Down Expand Up @@ -100,6 +102,10 @@ namespace advsettings {
return m_micProximitySensorCanMute;
}

bool AudioTabController::micReversePtt() const {
return m_micReversePtt;
}

void AudioTabController::eventLoopTick() {
if (!eventLoopMutex.try_lock()) {
return;
Expand Down Expand Up @@ -155,15 +161,27 @@ namespace advsettings {
}

void AudioTabController::onPttStart() {
setMicMuted(false);
if (m_micReversePtt) {
setMicMuted(true);
} else {
setMicMuted(false);
}
}

void AudioTabController::onPttEnabled() {
setMicMuted(true);
if (m_micReversePtt) {
setMicMuted(false);
} else {
setMicMuted(true);
}
}

void AudioTabController::onPttStop() {
setMicMuted(true);
if (m_micReversePtt) {
setMicMuted(false);
} else {
setMicMuted(true);
}
}

void AudioTabController::onPttDisabled() {
Expand Down Expand Up @@ -233,6 +251,24 @@ namespace advsettings {
}
}

void AudioTabController::setMicReversePtt(bool value, bool notify) {
std::lock_guard<std::recursive_mutex> lock(eventLoopMutex);
if (value != m_micReversePtt) {
m_micReversePtt = value;
saveAudioSettings();
if (m_pttEnabled) {
if (m_pttActive) {
setMicMuted(value);
} else {
setMicMuted(!value);
}
}
if (notify) {
emit micReversePttChanged(value);
}
}
}

void AudioTabController::onNewRecordingDevice() {
findMicDeviceIndex(audioManager->getMicDevId());
}
Expand Down
5 changes: 5 additions & 0 deletions src/tabcontrollers/AudioTabController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace advsettings {
Q_PROPERTY(float micVolume READ micVolume WRITE setMicVolume NOTIFY micVolumeChanged)
Q_PROPERTY(bool micMuted READ micMuted WRITE setMicMuted NOTIFY micMutedChanged)
Q_PROPERTY(bool micProximitySensorCanMute READ micProximitySensorCanMute WRITE setMicProximitySensorCanMute NOTIFY micProximitySensorCanMuteChanged)
Q_PROPERTY(bool micReversePtt READ micReversePtt WRITE setMicReversePtt NOTIFY micReversePttChanged)

private:
OverlayController* parent;
Expand All @@ -44,6 +45,7 @@ namespace advsettings {
float m_micVolume = 1.0;
bool m_micMuted = false;
bool m_micProximitySensorCanMute = false;
bool m_micReversePtt = false;

unsigned settingsUpdateCounter = 0;

Expand Down Expand Up @@ -83,6 +85,7 @@ namespace advsettings {
float micVolume() const;
bool micMuted() const;
bool micProximitySensorCanMute() const;
bool micReversePtt() const;

Q_INVOKABLE int getPlaybackDeviceCount();
Q_INVOKABLE QString getPlaybackDeviceName(int index);
Expand All @@ -102,6 +105,7 @@ namespace advsettings {
void setMicVolume(float value, bool notify = true);
void setMicMuted(bool value, bool notify = true);
void setMicProximitySensorCanMute(bool value, bool notify = true);
void setMicReversePtt(bool value, bool notify = true);

void setPlaybackDeviceIndex(int value, bool notify = true);
void setMirrorDeviceIndex(int value, bool notify = true);
Expand All @@ -118,6 +122,7 @@ namespace advsettings {
void micVolumeChanged(float value);
void micMutedChanged(bool value);
void micProximitySensorCanMuteChanged(bool value);
void micReversePttChanged(bool value);

void playbackDeviceListChanged();
void recordingDeviceListChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/tabcontrollers/PttController.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace advsettings {
Q_PROPERTY(bool pttLeftControllerEnabled READ pttLeftControllerEnabled WRITE setPttLeftControllerEnabled NOTIFY pttLeftControllerEnabledChanged)
Q_PROPERTY(bool pttRightControllerEnabled READ pttRightControllerEnabled WRITE setPttRightControllerEnabled NOTIFY pttRightControllerEnabledChanged)

private:
protected:
bool m_pttEnabled = false;
bool m_pttActive = false;
bool m_pttShowNotification = false;
Expand Down

0 comments on commit 0bc693c

Please sign in to comment.