Skip to content

Commit

Permalink
Merge pull request #955 from agaertner/feature/volume-changed-event
Browse files Browse the repository at this point in the history
feat: add VolumeChanged event
  • Loading branch information
dlamkins authored Apr 14, 2024
2 parents 34fe88b + d0b3847 commit c683f12
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Blish HUD/GameServices/GameIntegration/AudioIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Blish_HUD.GameIntegration {
public sealed class AudioIntegration : ServiceModule<GameIntegrationService> {
private static readonly Logger Logger = Logger.GetLogger<AudioIntegration>();

public event EventHandler<ValueEventArgs<float>> VolumeChanged;

public enum Devices {
[Description("GW2 Output Device")]
Gw2OutputDevice,
Expand Down Expand Up @@ -42,14 +44,21 @@ public enum Devices {
private double _timeSinceAudioDeviceUpdate = 0;

private float? _volume;

/// <summary>
/// This either provides an estimated volume level for the application
/// based on the volumes levels exhibited by the game
/// or
/// the set volume in settings.
/// </summary>
public float Volume => _volume ??= GetVolume();
public float Volume {
get => _volume ??= GetVolume();
private set {
if (Math.Abs(_volume.GetValueOrDefault() - value) > 0.0001f) {
VolumeChanged?.Invoke(this, new ValueEventArgs<float>(value));
}
_volume = value;
}
}

/// <summary>
/// Current used AudioDevice. This either the same as GW2 is using
Expand Down Expand Up @@ -123,7 +132,7 @@ public override void Update(GameTime gameTime) {
Logger.Debug(e, "Getting meter volume failed.");
}

_volume = null;
this.Volume = GetVolume();
}

if (_timeSinceAudioDeviceUpdate > AUDIO_DEVICE_UPDATE_INTERVAL) {
Expand Down

0 comments on commit c683f12

Please sign in to comment.