From c29ad8edf8731bbaf0d3189a2917b00b7f7cde33 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 30 Nov 2020 19:26:25 +0900 Subject: [PATCH] Better API for dealing with the contained drawable samples --- osu.Game/Skinning/SkinnableSound.cs | 39 +++++++++++-------- .../Drawables/DrawableStoryboardSample.cs | 4 +- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/osu.Game/Skinning/SkinnableSound.cs b/osu.Game/Skinning/SkinnableSound.cs index 46c2e4b749..23159e4fe1 100644 --- a/osu.Game/Skinning/SkinnableSound.cs +++ b/osu.Game/Skinning/SkinnableSound.cs @@ -11,6 +11,7 @@ using osu.Framework.Audio.Track; using osu.Framework.Bindables; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Audio; using osu.Framework.Graphics.Containers; using osu.Game.Audio; @@ -34,7 +35,13 @@ namespace osu.Game.Skinning /// protected bool PlayWhenZeroVolume => Looping; - protected readonly AudioContainer SamplesContainer; + /// + /// All raw s contained in this . + /// + [NotNull, ItemNotNull] + protected IEnumerable DrawableSamples => samplesContainer.Select(c => c.Sample).Where(s => s != null); + + private readonly AudioContainer samplesContainer; [Resolved] private ISampleStore sampleStore { get; set; } @@ -47,7 +54,7 @@ namespace osu.Game.Skinning /// public SkinnableSound() { - InternalChild = SamplesContainer = new AudioContainer(); + InternalChild = samplesContainer = new AudioContainer(); } /// @@ -105,7 +112,7 @@ namespace osu.Game.Skinning looping = value; - SamplesContainer.ForEach(c => c.Looping = looping); + samplesContainer.ForEach(c => c.Looping = looping); } } @@ -114,7 +121,7 @@ namespace osu.Game.Skinning /// public virtual void Play() { - SamplesContainer.ForEach(c => + samplesContainer.ForEach(c => { if (PlayWhenZeroVolume || c.AggregateVolume.Value > 0) c.Play(); @@ -126,7 +133,7 @@ namespace osu.Game.Skinning /// public virtual void Stop() { - SamplesContainer.ForEach(c => c.Stop()); + samplesContainer.ForEach(c => c.Stop()); } protected override void SkinChanged(ISkinSource skin, bool allowFallback) @@ -140,8 +147,8 @@ namespace osu.Game.Skinning bool wasPlaying = IsPlaying; // Remove all pooled samples (return them to the pool), and dispose the rest. - SamplesContainer.RemoveAll(s => s.IsInPool); - SamplesContainer.Clear(); + samplesContainer.RemoveAll(s => s.IsInPool); + samplesContainer.Clear(); foreach (var s in samples) { @@ -149,7 +156,7 @@ namespace osu.Game.Skinning sample.Looping = Looping; sample.Volume.Value = s.Volume / 100.0; - SamplesContainer.Add(sample); + samplesContainer.Add(sample); } if (wasPlaying) @@ -158,27 +165,27 @@ namespace osu.Game.Skinning #region Re-expose AudioContainer - public BindableNumber Volume => SamplesContainer.Volume; + public BindableNumber Volume => samplesContainer.Volume; - public BindableNumber Balance => SamplesContainer.Balance; + public BindableNumber Balance => samplesContainer.Balance; - public BindableNumber Frequency => SamplesContainer.Frequency; + public BindableNumber Frequency => samplesContainer.Frequency; - public BindableNumber Tempo => SamplesContainer.Tempo; + public BindableNumber Tempo => samplesContainer.Tempo; public void AddAdjustment(AdjustableProperty type, BindableNumber adjustBindable) - => SamplesContainer.AddAdjustment(type, adjustBindable); + => samplesContainer.AddAdjustment(type, adjustBindable); public void RemoveAdjustment(AdjustableProperty type, BindableNumber adjustBindable) - => SamplesContainer.RemoveAdjustment(type, adjustBindable); + => samplesContainer.RemoveAdjustment(type, adjustBindable); public void RemoveAllAdjustments(AdjustableProperty type) - => SamplesContainer.RemoveAllAdjustments(type); + => samplesContainer.RemoveAllAdjustments(type); /// /// Whether any samples are currently playing. /// - public bool IsPlaying => SamplesContainer.Any(s => s.Playing); + public bool IsPlaying => samplesContainer.Any(s => s.Playing); #endregion } diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardSample.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardSample.cs index 904af730de..218f051bf0 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardSample.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardSample.cs @@ -37,8 +37,8 @@ namespace osu.Game.Storyboards.Drawables foreach (var mod in mods.Value.OfType()) { - foreach (var sample in SamplesContainer) - mod.ApplyToSample(sample.Sample); + foreach (var sample in DrawableSamples) + mod.ApplyToSample(sample); } }