// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Bindables; using osu.Game.Audio; using osu.Game.Graphics; using osuTK.Graphics; namespace osu.Game.Beatmaps.ControlPoints { /// /// Note that going forward, this control point type should always be assigned directly to HitObjects. /// public class SampleControlPoint : ControlPoint, IEquatable { public const string DEFAULT_BANK = HitSampleInfo.BANK_NORMAL; public static readonly SampleControlPoint DEFAULT = new SampleControlPoint { SampleBankBindable = { Disabled = true }, SampleVolumeBindable = { Disabled = true } }; public override Color4 GetRepresentingColour(OsuColour colours) => colours.Pink; /// /// The default sample bank at this control point. /// public readonly Bindable SampleBankBindable = new Bindable(DEFAULT_BANK) { Default = DEFAULT_BANK }; /// /// The default sample bank at this control point. /// public string SampleBank { get => SampleBankBindable.Value; set => SampleBankBindable.Value = value; } /// /// The default sample volume at this control point. /// public readonly BindableInt SampleVolumeBindable = new BindableInt(100) { MinValue = 0, MaxValue = 100, }; /// /// The default sample volume at this control point. /// public int SampleVolume { get => SampleVolumeBindable.Value; set => SampleVolumeBindable.Value = value; } /// /// Create a SampleInfo based on the sample settings in this control point. /// /// The name of the same. /// A populated . public HitSampleInfo GetSampleInfo(string sampleName = HitSampleInfo.HIT_NORMAL) => new HitSampleInfo(sampleName, SampleBank, volume: SampleVolume); /// /// Applies and to a if necessary, returning the modified . /// /// The . This will not be modified. /// The modified . This does not share a reference with . public virtual HitSampleInfo ApplyTo(HitSampleInfo hitSampleInfo) => hitSampleInfo.With(newBank: hitSampleInfo.Bank, newVolume: hitSampleInfo.Volume > 0 ? hitSampleInfo.Volume : SampleVolume); public override bool IsRedundant(ControlPoint? existing) => existing is SampleControlPoint existingSample && SampleBank == existingSample.SampleBank && SampleVolume == existingSample.SampleVolume; public override void CopyFrom(ControlPoint other) { SampleVolume = ((SampleControlPoint)other).SampleVolume; SampleBank = ((SampleControlPoint)other).SampleBank; base.CopyFrom(other); } public override bool Equals(ControlPoint? other) => other is SampleControlPoint otherSampleControlPoint && Equals(otherSampleControlPoint); public bool Equals(SampleControlPoint? other) => base.Equals(other) && SampleBank == other.SampleBank && SampleVolume == other.SampleVolume; public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), SampleBank, SampleVolume); } }