2020-07-26 21:09:12 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-11-02 13:39:01 +08:00
|
|
|
using System.Linq;
|
2020-11-02 13:24:17 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2020-07-26 21:09:12 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Audio
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Stores samples for the input drum.
|
|
|
|
/// The lifetime of the samples is adjusted so that they are only alive during the appropriate sample control point.
|
|
|
|
/// </summary>
|
|
|
|
public class DrumSampleContainer : LifetimeManagementContainer
|
|
|
|
{
|
|
|
|
private readonly ControlPointInfo controlPoints;
|
|
|
|
private readonly Dictionary<double, DrumSample> mappings = new Dictionary<double, DrumSample>();
|
|
|
|
|
2020-11-04 14:29:14 +08:00
|
|
|
private readonly IBindableList<SampleControlPoint> samplePoints = new BindableList<SampleControlPoint>();
|
2020-11-02 13:24:17 +08:00
|
|
|
|
2020-07-26 21:09:12 +08:00
|
|
|
public DrumSampleContainer(ControlPointInfo controlPoints)
|
|
|
|
{
|
|
|
|
this.controlPoints = controlPoints;
|
2020-11-02 13:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2020-11-04 14:29:14 +08:00
|
|
|
samplePoints.BindTo(controlPoints.SamplePoints);
|
2020-11-02 13:39:01 +08:00
|
|
|
samplePoints.BindCollectionChanged((_, __) => recreateMappings(), true);
|
2020-11-02 13:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void recreateMappings()
|
|
|
|
{
|
|
|
|
mappings.Clear();
|
|
|
|
ClearInternal();
|
2020-07-26 21:09:12 +08:00
|
|
|
|
2020-11-02 13:39:01 +08:00
|
|
|
SampleControlPoint[] points = samplePoints.Count == 0
|
|
|
|
? new[] { controlPoints.SamplePointAt(double.MinValue) }
|
|
|
|
: samplePoints.ToArray();
|
2020-07-26 21:09:12 +08:00
|
|
|
|
2020-11-02 13:39:01 +08:00
|
|
|
for (int i = 0; i < points.Length; i++)
|
2020-07-26 21:09:12 +08:00
|
|
|
{
|
2020-11-02 13:39:01 +08:00
|
|
|
var samplePoint = points[i];
|
2020-07-26 21:09:12 +08:00
|
|
|
|
|
|
|
var lifetimeStart = i > 0 ? samplePoint.Time : double.MinValue;
|
2020-11-02 13:39:01 +08:00
|
|
|
var lifetimeEnd = i + 1 < points.Length ? points[i + 1].Time : double.MaxValue;
|
2020-07-26 21:09:12 +08:00
|
|
|
|
2020-11-02 13:24:17 +08:00
|
|
|
AddInternal(mappings[samplePoint.Time] = new DrumSample(samplePoint)
|
2020-07-26 21:09:12 +08:00
|
|
|
{
|
2020-11-02 13:24:17 +08:00
|
|
|
LifetimeStart = lifetimeStart,
|
|
|
|
LifetimeEnd = lifetimeEnd
|
|
|
|
});
|
2020-07-26 21:09:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 13:24:17 +08:00
|
|
|
public DrumSample SampleAt(double time) => mappings[controlPoints.SamplePointAt(time).Time];
|
|
|
|
|
|
|
|
public class DrumSample : CompositeDrawable
|
2020-07-26 21:09:12 +08:00
|
|
|
{
|
2020-11-02 13:24:17 +08:00
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
|
|
public PausableSkinnableSound Centre { get; private set; }
|
|
|
|
public PausableSkinnableSound Rim { get; private set; }
|
|
|
|
|
|
|
|
private readonly SampleControlPoint samplePoint;
|
|
|
|
|
|
|
|
private Bindable<string> sampleBank;
|
|
|
|
private BindableNumber<int> sampleVolume;
|
|
|
|
|
|
|
|
public DrumSample(SampleControlPoint samplePoint)
|
2020-07-26 21:09:12 +08:00
|
|
|
{
|
2020-11-02 13:24:17 +08:00
|
|
|
this.samplePoint = samplePoint;
|
|
|
|
}
|
2020-07-26 21:09:12 +08:00
|
|
|
|
2020-11-02 13:24:17 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
sampleBank = samplePoint.SampleBankBindable.GetBoundCopy();
|
|
|
|
sampleBank.BindValueChanged(_ => recreate());
|
2020-07-26 21:09:12 +08:00
|
|
|
|
2020-11-02 13:24:17 +08:00
|
|
|
sampleVolume = samplePoint.SampleVolumeBindable.GetBoundCopy();
|
|
|
|
sampleVolume.BindValueChanged(_ => recreate());
|
|
|
|
|
|
|
|
recreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void recreate()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
Centre = new PausableSkinnableSound(samplePoint.GetSampleInfo()),
|
|
|
|
Rim = new PausableSkinnableSound(samplePoint.GetSampleInfo(HitSampleInfo.HIT_CLAP))
|
|
|
|
};
|
|
|
|
}
|
2020-07-26 21:09:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|