Add inactive volume ducking, rather than outright mute

This commit is contained in:
Dean Herbert
2018-01-31 16:57:26 +09:00
parent 97ae44f23c
commit 86f5c9d6f1
3 changed files with 9 additions and 13 deletions

View File

@ -39,7 +39,7 @@ namespace osu.Game.Configuration
}; };
// Audio // Audio
Set(OsuSetting.MuteWhenInactive, false); Set(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01);
Set(OsuSetting.MenuVoice, true); Set(OsuSetting.MenuVoice, true);
Set(OsuSetting.MenuMusic, true); Set(OsuSetting.MenuMusic, true);
@ -103,7 +103,7 @@ namespace osu.Game.Configuration
MouseDisableButtons, MouseDisableButtons,
MouseDisableWheel, MouseDisableWheel,
AudioOffset, AudioOffset,
MuteWhenInactive, VolumeInactive,
MenuMusic, MenuMusic,
MenuVoice, MenuVoice,
CursorRotation, CursorRotation,

View File

@ -19,6 +19,7 @@ using OpenTK;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Audio;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Threading; using osu.Framework.Threading;
@ -122,7 +123,7 @@ namespace osu.Game
Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First(); Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First();
Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0; Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;
muteWhenInactive = LocalConfig.GetBindable<bool>(OsuSetting.MuteWhenInactive); LocalConfig.BindWith(OsuSetting.VolumeInactive, inactiveDuckVolume);
} }
private ScheduledDelegate scoreLoad; private ScheduledDelegate scoreLoad;
@ -400,24 +401,19 @@ namespace osu.Game
return false; return false;
} }
private Bindable<bool> muteWhenInactive = new Bindable<bool>(); private readonly BindableDouble inactiveDuckVolume = new BindableDouble();
private bool wasMuted;
protected override void OnDeactivated() protected override void OnDeactivated()
{ {
base.OnDeactivated(); base.OnDeactivated();
if (muteWhenInactive) Audio.AddAdjustment(AdjustableProperty.Volume, inactiveDuckVolume);
{
wasMuted = volume.Muted;
volume.Muted = true;
}
} }
protected override void OnActivated() protected override void OnActivated()
{ {
base.OnActivated(); base.OnActivated();
if (IsLoaded && muteWhenInactive && !wasMuted) Audio.RemoveAdjustment(AdjustableProperty.Volume, inactiveDuckVolume);
volume.Muted = false;
} }
public bool OnReleased(GlobalAction action) => false; public bool OnReleased(GlobalAction action) => false;

View File

@ -18,9 +18,9 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
Children = new Drawable[] Children = new Drawable[]
{ {
new SettingsSlider<double> { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.1f }, new SettingsSlider<double> { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.1f },
new SettingsSlider<double> { LabelText = "Master (Window Inactive)", Bindable = config.GetBindable<double>(OsuSetting.VolumeInactive), KeyboardStep = 0.1f },
new SettingsSlider<double> { LabelText = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.1f }, new SettingsSlider<double> { LabelText = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.1f },
new SettingsSlider<double> { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.1f }, new SettingsSlider<double> { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.1f },
new SettingsCheckbox { LabelText = "Mute osu! when inactive", Bindable = config.GetBindable<bool>(OsuSetting.MuteWhenInactive) }
}; };
} }
} }