Skip to content

Commit

Permalink
Merge pull request #952 from agaertner/feature/mute-setting
Browse files Browse the repository at this point in the history
feat: mute when game is muted
  • Loading branch information
dlamkins authored Apr 10, 2024
2 parents 8ee73af + ae77190 commit 2ec54fe
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
24 changes: 17 additions & 7 deletions Blish HUD/GameServices/GameIntegration/AudioIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum Devices {

private const string APPLICATION_SETTINGS = "OverlayConfiguration";
private const string USEGAMEVOLUME_SETTINGS = "GameVolume";
private const string MUTEIFNOGAMEAUDIO_SETTINGS = "MuteIfNoGameAudio";
private const string VOLUME_SETTINGS = "Volume";
private const string DEVICE_SETTINGS = "OutputDevice";
private const int CHECK_INTERVAL = 250;
Expand All @@ -32,8 +33,9 @@ public enum Devices {
private SettingEntry<bool> _useGameVolume;
private SettingEntry<Devices> _deviceSetting;
private SettingEntry<float> _volumeSetting;
private SettingEntry<bool> _muteIfNoGameAudio;

private readonly AudioEndpointNotificationReceiver _audioEndpointNotificationReceiver;
private readonly AudioEndpointNotificationReceiver _audioEndpointNotificationReceiver;
private readonly List<(MMDevice AudioDevice, AudioMeterInformation MeterInformation)> _gw2AudioDevices = new List<(MMDevice AudioDevice, AudioMeterInformation MeterInformation)>();

private double _timeSinceCheck = 0;
Expand Down Expand Up @@ -62,8 +64,16 @@ internal AudioIntegration(GameIntegrationService service) : base(service) {

public override void Load() {
var audioSettings = GameService.Settings.RegisterRootSettingCollection(APPLICATION_SETTINGS);
_useGameVolume = audioSettings.DefineSetting(USEGAMEVOLUME_SETTINGS, true, () => Strings.GameServices.OverlayService.Setting_UseGameVolume_DisplayName, () => Strings.GameServices.OverlayService.Setting_UseGameVolume_Description);
_volumeSetting = audioSettings.DefineSetting(VOLUME_SETTINGS, MAX_VOLUME / 2, () => Strings.GameServices.OverlayService.Setting_Volume_DisplayName, () => Strings.GameServices.OverlayService.Setting_Volume_Description);
_useGameVolume = audioSettings.DefineSetting(USEGAMEVOLUME_SETTINGS, true,
() => Strings.GameServices.OverlayService.Setting_UseGameVolume_DisplayName,
() => Strings.GameServices.OverlayService.Setting_UseGameVolume_Description);
_volumeSetting = audioSettings.DefineSetting(VOLUME_SETTINGS, MAX_VOLUME / 2,
() => Strings.GameServices.OverlayService.Setting_Volume_DisplayName,
() => Strings.GameServices.OverlayService.Setting_Volume_Description);
_muteIfNoGameAudio = audioSettings.DefineSetting(MUTEIFNOGAMEAUDIO_SETTINGS, true,
() => Strings.GameServices.OverlayService.Setting_MuteIfNoGameAudio_DisplayName,
() => Strings.GameServices.OverlayService.Setting_MuteIfNoGameAudio_Description);

_volumeSetting.SetRange(0.0f, MAX_VOLUME);

_deviceSetting = audioSettings.DefineSetting(DEVICE_SETTINGS, Devices.Gw2OutputDevice, () => Strings.GameServices.OverlayService.Setting_AudioDevice_DisplayName, () => Strings.GameServices.OverlayService.Setting_AudioDevice_Description + " (This setting is temporarily disabled in this version)");
Expand Down Expand Up @@ -124,11 +134,11 @@ public override void Update(GameTime gameTime) {
}

private float GetVolume() {
if (_useGameVolume.Value) {
return CalculateAverageVolume();
float gameVol = CalculateAverageVolume();
if (_muteIfNoGameAudio.Value && gameVol < 0.0001f) {
return 0;
}

return _volumeSetting.Value;
return _useGameVolume.Value ? gameVol : _volumeSetting.Value;
}

private float CalculateAverageVolume() {
Expand Down
18 changes: 18 additions & 0 deletions Blish HUD/Strings/GameServices/OverlayService.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Blish HUD/Strings/GameServices/OverlayService.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,10 @@ Für die beste Erfahrung auf die selbe Taste wie im Spiel setzen.</value>
<data name="SelfUpdate_NewPrereleaseAvailable" xml:space="preserve">
<value>Neue Beta-Version verfügbar</value>
</data>
<data name="Setting_MuteIfNoGameAudio_Description" xml:space="preserve">
<value>Wenn aktiviert, schaltet Blish HUD die Lautstärke stumm, wenn das Spiel ebenfalls keinen Ton ausgibt.</value>
</data>
<data name="Setting_MuteIfNoGameAudio_DisplayName" xml:space="preserve">
<value>Stummschalten, wenn Guild Wars 2 stummgeschaltet wird.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Blish HUD/Strings/GameServices/OverlayService.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,10 @@ Guild Wars 2 et Blish HUD.</value>
<data name="SelfUpdate_NewPrereleaseAvailable" xml:space="preserve">
<value>Nouvelle version bêta disponible</value>
</data>
<data name="Setting_MuteIfNoGameAudio_Description" xml:space="preserve">
<value>Lorsque cette option est activée, Blish HUD se met en sourdine lorsque le jeu n'émet aucun son.</value>
</data>
<data name="Setting_MuteIfNoGameAudio_DisplayName" xml:space="preserve">
<value>Mute lorsque le jeu est en sourdine.</value>
</data>
</root>
9 changes: 6 additions & 3 deletions Blish HUD/Strings/GameServices/OverlayService.resx
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,13 @@ WARNING: Prerelease modules or Blish HUD versions may be unstable. By enabling
<data name="About_DiscordCallToAction1" xml:space="preserve">
<value>
The majority of Blish HUD's feedback, development, and other discussions take place in our</value>

</data>
<data name="About_DiscordCallToAction2" xml:space="preserve">
<value>Discord</value>

</data>
<data name="About_DiscordCallToAction3" xml:space="preserve">
<value> channel.
</value>

</data>
<data name="About_DiscordCallToAction_Question" xml:space="preserve">
<value>
Expand All @@ -324,4 +321,10 @@ participate in the conversation?</value>
<data name="SelfUpdate_NewPrereleaseAvailable" xml:space="preserve">
<value>New Prerelease Available</value>
</data>
<data name="Setting_MuteIfNoGameAudio_Description" xml:space="preserve">
<value>When enabled, Blish HUD will mute itself when the game does not emit any sound either.</value>
</data>
<data name="Setting_MuteIfNoGameAudio_DisplayName" xml:space="preserve">
<value>Mute when Game is muted.</value>
</data>
</root>

0 comments on commit 2ec54fe

Please sign in to comment.