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

Add and consume sample bank constants

This commit is contained in:
Dean Herbert 2022-10-19 20:34:41 +09:00
parent 31f499a950
commit 579d5b51eb
9 changed files with 51 additions and 40 deletions

View File

@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Catch.Tests
NewCombo = i % 8 == 0, NewCombo = i % 8 == 0,
Samples = new List<HitSampleInfo>(new[] Samples = new List<HitSampleInfo>(new[]
{ {
new HitSampleInfo(HitSampleInfo.HIT_NORMAL, "normal", volume: 100) new HitSampleInfo(HitSampleInfo.HIT_NORMAL, HitSampleInfo.BANK_NORMAL, volume: 100)
}) })
}); });
} }

View File

@ -181,7 +181,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
{ {
if (slider is null) return; if (slider is null) return;
slider.SampleControlPoint.SampleBank = "soft"; slider.SampleControlPoint.SampleBank = HitSampleInfo.BANK_SOFT;
slider.SampleControlPoint.SampleVolume = 70; slider.SampleControlPoint.SampleVolume = 70;
sample = new HitSampleInfo("hitwhistle"); sample = new HitSampleInfo("hitwhistle");
slider.Samples.Add(sample); slider.Samples.Add(sample);
@ -207,7 +207,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
AddAssert("sliders have hitsounds", hasHitsounds); AddAssert("sliders have hitsounds", hasHitsounds);
bool hasHitsounds() => sample is not null && bool hasHitsounds() => sample is not null &&
EditorBeatmap.HitObjects.All(o => o.SampleControlPoint.SampleBank == "soft" && EditorBeatmap.HitObjects.All(o => o.SampleControlPoint.SampleBank == HitSampleInfo.BANK_SOFT &&
o.SampleControlPoint.SampleVolume == 70 && o.SampleControlPoint.SampleVolume == 70 &&
o.Samples.Contains(sample)); o.Samples.Contains(sample));
} }

View File

@ -206,17 +206,17 @@ namespace osu.Game.Tests.Beatmaps.Formats
var soundPoint = controlPoints.SamplePointAt(0); var soundPoint = controlPoints.SamplePointAt(0);
Assert.AreEqual(956, soundPoint.Time); Assert.AreEqual(956, soundPoint.Time);
Assert.AreEqual("soft", soundPoint.SampleBank); Assert.AreEqual(HitSampleInfo.BANK_SOFT, soundPoint.SampleBank);
Assert.AreEqual(60, soundPoint.SampleVolume); Assert.AreEqual(60, soundPoint.SampleVolume);
soundPoint = controlPoints.SamplePointAt(53373); soundPoint = controlPoints.SamplePointAt(53373);
Assert.AreEqual(53373, soundPoint.Time); Assert.AreEqual(53373, soundPoint.Time);
Assert.AreEqual("soft", soundPoint.SampleBank); Assert.AreEqual(HitSampleInfo.BANK_SOFT, soundPoint.SampleBank);
Assert.AreEqual(60, soundPoint.SampleVolume); Assert.AreEqual(60, soundPoint.SampleVolume);
soundPoint = controlPoints.SamplePointAt(119637); soundPoint = controlPoints.SamplePointAt(119637);
Assert.AreEqual(119637, soundPoint.Time); Assert.AreEqual(119637, soundPoint.Time);
Assert.AreEqual("soft", soundPoint.SampleBank); Assert.AreEqual(HitSampleInfo.BANK_SOFT, soundPoint.SampleBank);
Assert.AreEqual(80, soundPoint.SampleVolume); Assert.AreEqual(80, soundPoint.SampleVolume);
var effectPoint = controlPoints.EffectPointAt(0); var effectPoint = controlPoints.EffectPointAt(0);
@ -261,10 +261,10 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.That(controlPoints.EffectPointAt(2500).KiaiMode, Is.False); Assert.That(controlPoints.EffectPointAt(2500).KiaiMode, Is.False);
Assert.That(controlPoints.EffectPointAt(3500).KiaiMode, Is.True); Assert.That(controlPoints.EffectPointAt(3500).KiaiMode, Is.True);
Assert.That(controlPoints.SamplePointAt(500).SampleBank, Is.EqualTo("drum")); Assert.That(controlPoints.SamplePointAt(500).SampleBank, Is.EqualTo(HitSampleInfo.BANK_DRUM));
Assert.That(controlPoints.SamplePointAt(1500).SampleBank, Is.EqualTo("drum")); Assert.That(controlPoints.SamplePointAt(1500).SampleBank, Is.EqualTo(HitSampleInfo.BANK_DRUM));
Assert.That(controlPoints.SamplePointAt(2500).SampleBank, Is.EqualTo("normal")); Assert.That(controlPoints.SamplePointAt(2500).SampleBank, Is.EqualTo(HitSampleInfo.BANK_NORMAL));
Assert.That(controlPoints.SamplePointAt(3500).SampleBank, Is.EqualTo("drum")); Assert.That(controlPoints.SamplePointAt(3500).SampleBank, Is.EqualTo(HitSampleInfo.BANK_DRUM));
Assert.That(controlPoints.TimingPointAt(500).BeatLength, Is.EqualTo(500).Within(0.1)); Assert.That(controlPoints.TimingPointAt(500).BeatLength, Is.EqualTo(500).Within(0.1));
Assert.That(controlPoints.TimingPointAt(1500).BeatLength, Is.EqualTo(500).Within(0.1)); Assert.That(controlPoints.TimingPointAt(1500).BeatLength, Is.EqualTo(500).Within(0.1));

View File

@ -7,6 +7,7 @@ using System.Linq;
using Humanizer; using Humanizer;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -41,7 +42,7 @@ namespace osu.Game.Tests.Visual.Editing
Position = (OsuPlayfield.BASE_SIZE - new Vector2(100, 0)) / 2, Position = (OsuPlayfield.BASE_SIZE - new Vector2(100, 0)) / 2,
SampleControlPoint = new SampleControlPoint SampleControlPoint = new SampleControlPoint
{ {
SampleBank = "normal", SampleBank = HitSampleInfo.BANK_NORMAL,
SampleVolume = 80 SampleVolume = 80
} }
}); });
@ -52,7 +53,7 @@ namespace osu.Game.Tests.Visual.Editing
Position = (OsuPlayfield.BASE_SIZE + new Vector2(100, 0)) / 2, Position = (OsuPlayfield.BASE_SIZE + new Vector2(100, 0)) / 2,
SampleControlPoint = new SampleControlPoint SampleControlPoint = new SampleControlPoint
{ {
SampleBank = "soft", SampleBank = HitSampleInfo.BANK_SOFT,
SampleVolume = 60 SampleVolume = 60
} }
}); });
@ -70,7 +71,7 @@ namespace osu.Game.Tests.Visual.Editing
public void TestSingleSelection() public void TestSingleSelection()
{ {
clickSamplePiece(0); clickSamplePiece(0);
samplePopoverHasSingleBank("normal"); samplePopoverHasSingleBank(HitSampleInfo.BANK_NORMAL);
samplePopoverHasSingleVolume(80); samplePopoverHasSingleVolume(80);
dismissPopover(); dismissPopover();
@ -80,14 +81,14 @@ namespace osu.Game.Tests.Visual.Editing
AddStep("select first object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.First())); AddStep("select first object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.First()));
clickSamplePiece(1); clickSamplePiece(1);
samplePopoverHasSingleBank("soft"); samplePopoverHasSingleBank(HitSampleInfo.BANK_SOFT);
samplePopoverHasSingleVolume(60); samplePopoverHasSingleVolume(60);
setVolumeViaPopover(90); setVolumeViaPopover(90);
hitObjectHasSampleVolume(1, 90); hitObjectHasSampleVolume(1, 90);
setBankViaPopover("drum"); setBankViaPopover(HitSampleInfo.BANK_DRUM);
hitObjectHasSampleBank(1, "drum"); hitObjectHasSampleBank(1, HitSampleInfo.BANK_DRUM);
} }
[Test] [Test]
@ -136,27 +137,27 @@ namespace osu.Game.Tests.Visual.Editing
AddStep("unify sample bank", () => AddStep("unify sample bank", () =>
{ {
foreach (var h in EditorBeatmap.HitObjects) foreach (var h in EditorBeatmap.HitObjects)
h.SampleControlPoint.SampleBank = "soft"; h.SampleControlPoint.SampleBank = HitSampleInfo.BANK_SOFT;
}); });
AddStep("select both objects", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects)); AddStep("select both objects", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
clickSamplePiece(0); clickSamplePiece(0);
samplePopoverHasSingleBank("soft"); samplePopoverHasSingleBank(HitSampleInfo.BANK_SOFT);
dismissPopover(); dismissPopover();
clickSamplePiece(1); clickSamplePiece(1);
samplePopoverHasSingleBank("soft"); samplePopoverHasSingleBank(HitSampleInfo.BANK_SOFT);
setBankViaPopover(string.Empty); setBankViaPopover(string.Empty);
hitObjectHasSampleBank(0, "soft"); hitObjectHasSampleBank(0, HitSampleInfo.BANK_SOFT);
hitObjectHasSampleBank(1, "soft"); hitObjectHasSampleBank(1, HitSampleInfo.BANK_SOFT);
samplePopoverHasSingleBank("soft"); samplePopoverHasSingleBank(HitSampleInfo.BANK_SOFT);
setBankViaPopover("drum"); setBankViaPopover(HitSampleInfo.BANK_DRUM);
hitObjectHasSampleBank(0, "drum"); hitObjectHasSampleBank(0, HitSampleInfo.BANK_DRUM);
hitObjectHasSampleBank(1, "drum"); hitObjectHasSampleBank(1, HitSampleInfo.BANK_DRUM);
samplePopoverHasSingleBank("drum"); samplePopoverHasSingleBank(HitSampleInfo.BANK_DRUM);
} }
[Test] [Test]
@ -172,14 +173,14 @@ namespace osu.Game.Tests.Visual.Editing
samplePopoverHasIndeterminateBank(); samplePopoverHasIndeterminateBank();
setBankViaPopover(string.Empty); setBankViaPopover(string.Empty);
hitObjectHasSampleBank(0, "normal"); hitObjectHasSampleBank(0, HitSampleInfo.BANK_NORMAL);
hitObjectHasSampleBank(1, "soft"); hitObjectHasSampleBank(1, HitSampleInfo.BANK_SOFT);
samplePopoverHasIndeterminateBank(); samplePopoverHasIndeterminateBank();
setBankViaPopover("normal"); setBankViaPopover(HitSampleInfo.BANK_NORMAL);
hitObjectHasSampleBank(0, "normal"); hitObjectHasSampleBank(0, HitSampleInfo.BANK_NORMAL);
hitObjectHasSampleBank(1, "normal"); hitObjectHasSampleBank(1, HitSampleInfo.BANK_NORMAL);
samplePopoverHasSingleBank("normal"); samplePopoverHasSingleBank(HitSampleInfo.BANK_NORMAL);
} }
private void clickSamplePiece(int objectIndex) => AddStep($"click {objectIndex.ToOrdinalWords()} sample piece", () => private void clickSamplePiece(int objectIndex) => AddStep($"click {objectIndex.ToOrdinalWords()} sample piece", () =>

View File

@ -57,13 +57,13 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
StartTime = t += spacing, StartTime = t += spacing,
Samples = new[] { new HitSampleInfo(HitSampleInfo.HIT_NORMAL) }, Samples = new[] { new HitSampleInfo(HitSampleInfo.HIT_NORMAL) },
SampleControlPoint = new SampleControlPoint { SampleBank = "soft" }, SampleControlPoint = new SampleControlPoint { SampleBank = HitSampleInfo.BANK_SOFT },
}, },
new HitCircle new HitCircle
{ {
StartTime = t + spacing, StartTime = t + spacing,
Samples = new[] { new HitSampleInfo(HitSampleInfo.HIT_WHISTLE) }, Samples = new[] { new HitSampleInfo(HitSampleInfo.HIT_WHISTLE) },
SampleControlPoint = new SampleControlPoint { SampleBank = "soft" }, SampleControlPoint = new SampleControlPoint { SampleBank = HitSampleInfo.BANK_SOFT },
}, },
}); });

View File

@ -19,11 +19,20 @@ namespace osu.Game.Audio
public const string HIT_FINISH = @"hitfinish"; public const string HIT_FINISH = @"hitfinish";
public const string HIT_CLAP = @"hitclap"; public const string HIT_CLAP = @"hitclap";
public const string BANK_NORMAL = @"normal";
public const string BANK_SOFT = @"soft";
public const string BANK_DRUM = @"drum";
/// <summary> /// <summary>
/// All valid sample addition constants. /// All valid sample addition constants.
/// </summary> /// </summary>
public static IEnumerable<string> AllAdditions => new[] { HIT_WHISTLE, HIT_FINISH, HIT_CLAP }; public static IEnumerable<string> AllAdditions => new[] { HIT_WHISTLE, HIT_FINISH, HIT_CLAP };
/// <summary>
/// All valid bank constants.
/// </summary>
public static IEnumerable<string> AllBanks => new[] { BANK_NORMAL, BANK_SOFT, BANK_DRUM };
/// <summary> /// <summary>
/// The name of the sample to load. /// The name of the sample to load.
/// </summary> /// </summary>

View File

@ -14,7 +14,7 @@ namespace osu.Game.Beatmaps.ControlPoints
/// </remarks> /// </remarks>
public class SampleControlPoint : ControlPoint, IEquatable<SampleControlPoint> public class SampleControlPoint : ControlPoint, IEquatable<SampleControlPoint>
{ {
public const string DEFAULT_BANK = "normal"; public const string DEFAULT_BANK = HitSampleInfo.BANK_NORMAL;
public static readonly SampleControlPoint DEFAULT = new SampleControlPoint public static readonly SampleControlPoint DEFAULT = new SampleControlPoint
{ {
@ -30,7 +30,7 @@ namespace osu.Game.Beatmaps.ControlPoints
public readonly Bindable<string> SampleBankBindable = new Bindable<string>(DEFAULT_BANK) { Default = DEFAULT_BANK }; public readonly Bindable<string> SampleBankBindable = new Bindable<string>(DEFAULT_BANK) { Default = DEFAULT_BANK };
/// <summary> /// <summary>
/// The speed multiplier at this control point. /// The sample bank at this control point.
/// </summary> /// </summary>
public string SampleBank public string SampleBank
{ {

View File

@ -10,6 +10,7 @@ using System.Linq;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Audio;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
@ -412,7 +413,7 @@ namespace osu.Game.Beatmaps.Formats
string stringSampleSet = sampleSet.ToString().ToLowerInvariant(); string stringSampleSet = sampleSet.ToString().ToLowerInvariant();
if (stringSampleSet == @"none") if (stringSampleSet == @"none")
stringSampleSet = @"normal"; stringSampleSet = HitSampleInfo.HIT_NORMAL;
if (timingChange) if (timingChange)
{ {

View File

@ -547,13 +547,13 @@ namespace osu.Game.Beatmaps.Formats
{ {
switch (sampleBank?.ToLowerInvariant()) switch (sampleBank?.ToLowerInvariant())
{ {
case "normal": case HitSampleInfo.BANK_NORMAL:
return LegacySampleBank.Normal; return LegacySampleBank.Normal;
case "soft": case HitSampleInfo.BANK_SOFT:
return LegacySampleBank.Soft; return LegacySampleBank.Soft;
case "drum": case HitSampleInfo.BANK_DRUM:
return LegacySampleBank.Drum; return LegacySampleBank.Drum;
default: default: