2019-01-24 16:43:03 +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.
2018-04-13 17:19:50 +08:00
2019-10-28 13:44:45 +08:00
using osu.Framework.Bindables ;
2018-04-13 17:19:50 +08:00
using osu.Game.Audio ;
namespace osu.Game.Beatmaps.ControlPoints
{
2019-10-25 16:00:56 +08:00
public class SampleControlPoint : ControlPoint
2018-04-13 17:19:50 +08:00
{
public const string DEFAULT_BANK = "normal" ;
/// <summary>
/// The default sample bank at this control point.
/// </summary>
2019-10-28 15:21:14 +08:00
public readonly Bindable < string > SampleBankBindable = new Bindable < string > ( DEFAULT_BANK ) { Default = DEFAULT_BANK } ;
2019-10-28 13:44:45 +08:00
/// <summary>
/// The speed multiplier at this control point.
/// </summary>
public string SampleBank
{
get = > SampleBankBindable . Value ;
set = > SampleBankBindable . Value = value ;
}
/// <summary>
/// The default sample bank at this control point.
/// </summary>
public readonly BindableInt SampleVolumeBindable = new BindableInt ( 100 )
{
MinValue = 0 ,
2019-10-28 15:21:14 +08:00
MaxValue = 100 ,
Default = 100
2019-10-28 13:44:45 +08:00
} ;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The default sample volume at this control point.
/// </summary>
2019-10-28 13:44:45 +08:00
public int SampleVolume
{
get = > SampleVolumeBindable . Value ;
set = > SampleVolumeBindable . Value = value ;
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// Create a SampleInfo based on the sample settings in this control point.
/// </summary>
/// <param name="sampleName">The name of the same.</param>
2019-06-30 20:58:30 +08:00
/// <returns>A populated <see cref="HitSampleInfo"/>.</returns>
public HitSampleInfo GetSampleInfo ( string sampleName = HitSampleInfo . HIT_NORMAL ) = > new HitSampleInfo
2018-04-13 17:19:50 +08:00
{
Bank = SampleBank ,
Name = sampleName ,
Volume = SampleVolume ,
} ;
2018-06-28 17:08:46 +08:00
2018-06-28 17:20:29 +08:00
/// <summary>
2019-06-30 20:58:30 +08:00
/// Applies <see cref="SampleBank"/> and <see cref="SampleVolume"/> to a <see cref="HitSampleInfo"/> if necessary, returning the modified <see cref="HitSampleInfo"/>.
2018-06-28 17:20:29 +08:00
/// </summary>
2019-06-30 20:58:30 +08:00
/// <param name="hitSampleInfo">The <see cref="HitSampleInfo"/>. This will not be modified.</param>
/// <returns>The modified <see cref="HitSampleInfo"/>. This does not share a reference with <paramref name="hitSampleInfo"/>.</returns>
public virtual HitSampleInfo ApplyTo ( HitSampleInfo hitSampleInfo )
2018-06-28 17:20:29 +08:00
{
2019-06-30 20:58:30 +08:00
var newSampleInfo = hitSampleInfo . Clone ( ) ;
newSampleInfo . Bank = hitSampleInfo . Bank ? ? SampleBank ;
newSampleInfo . Volume = hitSampleInfo . Volume > 0 ? hitSampleInfo . Volume : SampleVolume ;
2018-07-02 13:17:19 +08:00
return newSampleInfo ;
}
2018-06-28 17:20:29 +08:00
2019-10-25 16:00:56 +08:00
public override bool EquivalentTo ( ControlPoint other ) = >
other is SampleControlPoint otherTyped & &
2019-10-25 19:04:27 +08:00
string . Equals ( SampleBank , otherTyped . SampleBank ) & & SampleVolume = = otherTyped . SampleVolume ;
2018-04-13 17:19:50 +08:00
}
}