Skip to content

Commit

Permalink
Fix feedback sound setting
Browse files Browse the repository at this point in the history
refs #25
  • Loading branch information
fredemmott committed Feb 16, 2021
1 parent b08fbfa commit b9411a4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Sources/BaseMuteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void BaseMuteAction::SendToPlugin(const nlohmann::json& payload) {
void BaseMuteAction::SettingsDidChange(
const MuteActionSettings& old_settings,
const MuteActionSettings& new_settings) {
mFeedbackSounds = new_settings.feedbackSounds;
if (old_settings.deviceID == new_settings.deviceID) {
return;
}
Expand Down Expand Up @@ -129,6 +130,10 @@ void BaseMuteAction::SettingsDidChange(
}));
}

bool BaseMuteAction::FeedbackSoundsEnabled() const {
return mFeedbackSounds;
}

void BaseMuteAction::RealDeviceDidChange() {
const auto device(GetRealDeviceID());
mMuteUnmuteCallbackHandle = std::move(AddAudioDeviceMuteUnmuteCallback(
Expand Down
2 changes: 2 additions & 0 deletions Sources/BaseMuteAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ class BaseMuteAction : public ESDActionWithExternalState<MuteActionSettings> {
virtual void MuteStateDidChange(bool isMuted) = 0;
virtual void KeyUp() final override;
std::string GetRealDeviceID() const;
virtual bool FeedbackSoundsEnabled() const;

private:
std::string mRealDeviceID;
std::unique_ptr<MuteCallbackHandle> mMuteUnmuteCallbackHandle;
std::unique_ptr<DefaultChangeCallbackHandle> mDefaultChangeCallbackHandle;
bool mFeedbackSounds;

void RealDeviceDidChange();
};
4 changes: 3 additions & 1 deletion Sources/MuteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void MuteAction::DoAction() {
return;
}
MuteAudioDevice(GetRealDeviceID());
PlayFeedbackSound();
if (FeedbackSoundsEnabled()) {
PlayFeedbackSound();
}
}

void MuteAction::PlayFeedbackSound() {
Expand Down
8 changes: 6 additions & 2 deletions Sources/ToggleMuteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ void ToggleMuteAction::DoAction() {
const auto device(GetRealDeviceID());
if (IsAudioDeviceMuted(device)) {
UnmuteAudioDevice(device);
UnmuteAction::PlayFeedbackSound();
if (FeedbackSoundsEnabled()) {
UnmuteAction::PlayFeedbackSound();
}
} else {
MuteAudioDevice(device);
MuteAction::PlayFeedbackSound();
if (FeedbackSoundsEnabled()) {
MuteAction::PlayFeedbackSound();
}
}
}
4 changes: 3 additions & 1 deletion Sources/UnmuteAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ void UnmuteAction::DoAction() {
return;
}
UnmuteAudioDevice(device);
PlayFeedbackSound();
if (FeedbackSoundsEnabled()) {
PlayFeedbackSound();
}
}

void UnmuteAction::PlayFeedbackSound() {
Expand Down

0 comments on commit b9411a4

Please sign in to comment.