1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 10:17:19 +08:00

Add other sample functions to SkinnableSound (#5728)

Add other sample functions to SkinnableSound

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2019-09-02 19:14:45 +09:00 committed by GitHub
commit d688aee258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Audio; using osu.Game.Audio;
@ -14,6 +15,9 @@ namespace osu.Game.Skinning
public class SkinnableSound : SkinReloadableDrawable public class SkinnableSound : SkinReloadableDrawable
{ {
private readonly ISampleInfo[] hitSamples; private readonly ISampleInfo[] hitSamples;
private List<(AdjustableProperty property, BindableDouble bindable)> adjustments;
private SampleChannel[] channels; private SampleChannel[] channels;
private AudioManager audio; private AudioManager audio;
@ -34,8 +38,39 @@ namespace osu.Game.Skinning
this.audio = audio; this.audio = audio;
} }
private bool looping;
public bool Looping
{
get => looping;
set
{
if (value == looping) return;
looping = value;
channels?.ForEach(c => c.Looping = looping);
}
}
public void Play() => channels?.ForEach(c => c.Play()); public void Play() => channels?.ForEach(c => c.Play());
public void Stop() => channels?.ForEach(c => c.Stop());
public void AddAdjustment(AdjustableProperty type, BindableDouble adjustBindable)
{
if (adjustments == null) adjustments = new List<(AdjustableProperty, BindableDouble)>();
adjustments.Add((type, adjustBindable));
channels?.ForEach(c => c.AddAdjustment(type, adjustBindable));
}
public void RemoveAdjustment(AdjustableProperty type, BindableDouble adjustBindable)
{
adjustments?.Remove((type, adjustBindable));
channels?.ForEach(c => c.RemoveAdjustment(type, adjustBindable));
}
public override bool IsPresent => Scheduler.HasPendingTasks; public override bool IsPresent => Scheduler.HasPendingTasks;
protected override void SkinChanged(ISkinSource skin, bool allowFallback) protected override void SkinChanged(ISkinSource skin, bool allowFallback)
@ -50,8 +85,15 @@ namespace osu.Game.Skinning
break; break;
if (ch != null) if (ch != null)
{
ch.Looping = looping;
ch.Volume.Value = s.Volume / 100.0; ch.Volume.Value = s.Volume / 100.0;
if (adjustments != null)
foreach (var adjustment in adjustments)
ch.AddAdjustment(adjustment.property, adjustment.bindable);
}
return ch; return ch;
}).Where(c => c != null).ToArray(); }).Where(c => c != null).ToArray();
} }