From 967d0c3c72269e9fad90d090601c71a25a186ec5 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 20 Jul 2018 15:12:04 +0900 Subject: [PATCH 1/3] Adjust testcase --- .../Formats/LegacyBeatmapDecoderTest.cs | 18 +++++++++--------- ....osu => controlpoint-custom-samplebank.osu} | 0 ...-samples.osu => hitobject-file-samples.osu} | 0 3 files changed, 9 insertions(+), 9 deletions(-) rename osu.Game.Tests/Resources/{custom-samples.osu => controlpoint-custom-samplebank.osu} (100%) rename osu.Game.Tests/Resources/{custom-hitobject-samples.osu => hitobject-file-samples.osu} (100%) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index 2f5b4a13d9..6b72dc5733 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -214,10 +214,10 @@ public void TestDecodeBeatmapHitObjects() } [Test] - public void TestDecodeCustomSamples() + public void TestDecodeControlPointCustomSampleBank() { var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false }; - using (var resStream = Resource.OpenResource("custom-samples.osu")) + using (var resStream = Resource.OpenResource("controlpoint-custom-samplebank.osu")) using (var stream = new StreamReader(resStream)) { var hitObjects = decoder.Decode(stream).HitObjects; @@ -228,25 +228,25 @@ public void TestDecodeCustomSamples() Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[3]).LookupNames.First()); } - SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" }); + SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]); } [Test] - public void TestDecodeCustomHitObjectSamples() + public void TestDecodeHitObjectCustomSampleBank() { var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false }; - using (var resStream = Resource.OpenResource("custom-hitobject-samples.osu")) + using (var resStream = Resource.OpenResource("hitobject-custom-samplebank.osu")) using (var stream = new StreamReader(resStream)) { var hitObjects = decoder.Decode(stream).HitObjects; - Assert.AreEqual("hit_1.wav", hitObjects[0].Samples[0].LookupNames.First()); - Assert.AreEqual("hit_2.wav", hitObjects[1].Samples[0].LookupNames.First()); + Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[0]).LookupNames.First()); + Assert.AreEqual("hit_2.wav", getTestableSampleInfo(hitObjects[1]).LookupNames.First()); Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First()); - Assert.AreEqual("hit_1.wav", hitObjects[3].Samples[0].LookupNames.First()); + Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[3]).LookupNames.First()); } - SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" }); + SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]); } } } diff --git a/osu.Game.Tests/Resources/custom-samples.osu b/osu.Game.Tests/Resources/controlpoint-custom-samplebank.osu similarity index 100% rename from osu.Game.Tests/Resources/custom-samples.osu rename to osu.Game.Tests/Resources/controlpoint-custom-samplebank.osu diff --git a/osu.Game.Tests/Resources/custom-hitobject-samples.osu b/osu.Game.Tests/Resources/hitobject-file-samples.osu similarity index 100% rename from osu.Game.Tests/Resources/custom-hitobject-samples.osu rename to osu.Game.Tests/Resources/hitobject-file-samples.osu From de8d05bb0cbc64c80877ca2ee98a5388ff56c037 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 20 Jul 2018 15:12:21 +0900 Subject: [PATCH 2/3] Remove unnecessary setting of sample name to same value --- osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs index acccbcde46..18680f9985 100644 --- a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs @@ -40,7 +40,6 @@ public virtual SampleInfo ApplyTo(SampleInfo sampleInfo) { var newSampleInfo = sampleInfo.Clone(); newSampleInfo.Bank = sampleInfo.Bank ?? SampleBank; - newSampleInfo.Name = sampleInfo.Name; newSampleInfo.Volume = sampleInfo.Volume > 0 ? sampleInfo.Volume : SampleVolume; return newSampleInfo; } From c087a73f403c73bdfb428d4b5bd1880097da2df4 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 20 Jul 2018 15:12:44 +0900 Subject: [PATCH 3/3] Implement per-hitobject custom sample banks --- .../Formats/LegacyBeatmapDecoderTest.cs | 17 ++++++++ .../Resources/hitobject-custom-samplebank.osu | 13 ++++++ osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 2 +- .../Objects/Legacy/ConvertHitObjectParser.cs | 41 ++++++++++++++----- 4 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 osu.Game.Tests/Resources/hitobject-custom-samplebank.osu diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index 6b72dc5733..400380b407 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -240,6 +240,23 @@ public void TestDecodeHitObjectCustomSampleBank() { var hitObjects = decoder.Decode(stream).HitObjects; + Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First()); + Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[1]).LookupNames.First()); + Assert.AreEqual("normal-hitnormal3", getTestableSampleInfo(hitObjects[2]).LookupNames.First()); + } + + SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]); + } + + [Test] + public void TestDecodeHitObjectFileSamples() + { + var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false }; + using (var resStream = Resource.OpenResource("hitobject-file-samples.osu")) + using (var stream = new StreamReader(resStream)) + { + var hitObjects = decoder.Decode(stream).HitObjects; + Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[0]).LookupNames.First()); Assert.AreEqual("hit_2.wav", getTestableSampleInfo(hitObjects[1]).LookupNames.First()); Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First()); diff --git a/osu.Game.Tests/Resources/hitobject-custom-samplebank.osu b/osu.Game.Tests/Resources/hitobject-custom-samplebank.osu new file mode 100644 index 0000000000..56b1a8762f --- /dev/null +++ b/osu.Game.Tests/Resources/hitobject-custom-samplebank.osu @@ -0,0 +1,13 @@ +osu file format v14 + +[General] +SampleSet: Normal + +[TimingPoints] +2170,468.75,4,1,0,40,1,0 +3107,-100,4,1,2,40,0,0 + +[HitObjects] +255,193,2170,1,0,0:0:0:0: +256,191,3107,5,0,0:0:0:0: +255,193,4000,1,0,0:0:3:70: diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index 91c1c98438..76a3d75e36 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -188,7 +188,7 @@ public override SampleInfo ApplyTo(SampleInfo sampleInfo) { var baseInfo = base.ApplyTo(sampleInfo); - if (CustomSampleBank > 1) + if (string.IsNullOrEmpty(baseInfo.Suffix) && CustomSampleBank > 1) baseInfo.Suffix = CustomSampleBank.ToString(); return baseInfo; diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs index 48512a71c2..5de05a99cc 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs @@ -194,8 +194,8 @@ private void readCustomSampleBanks(string str, SampleBankInfo bankInfo) string[] split = str.Split(':'); - var bank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[0]); - var addbank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[1]); + var bank = (LegacyBeatmapDecoder.LegacySampleBank)int.Parse(split[0]); + var addbank = (LegacyBeatmapDecoder.LegacySampleBank)int.Parse(split[1]); string stringBank = bank.ToString().ToLower(); if (stringBank == @"none") @@ -207,6 +207,9 @@ private void readCustomSampleBanks(string str, SampleBankInfo bankInfo) bankInfo.Normal = stringBank; bankInfo.Add = stringAddBank; + if (split.Length > 2) + bankInfo.CustomSampleBank = int.Parse(split[2]); + if (split.Length > 3) bankInfo.Volume = int.Parse(split[3]); @@ -258,41 +261,45 @@ private List convertSoundType(LegacySoundType type, SampleBankInfo b var soundTypes = new List { - new SampleInfo + new LegacySampleInfo { Bank = bankInfo.Normal, Name = SampleInfo.HIT_NORMAL, - Volume = bankInfo.Volume + Volume = bankInfo.Volume, + CustomSampleBank = bankInfo.CustomSampleBank } }; if (type.HasFlag(LegacySoundType.Finish)) { - soundTypes.Add(new SampleInfo + soundTypes.Add(new LegacySampleInfo { Bank = bankInfo.Add, Name = SampleInfo.HIT_FINISH, - Volume = bankInfo.Volume + Volume = bankInfo.Volume, + CustomSampleBank = bankInfo.CustomSampleBank }); } if (type.HasFlag(LegacySoundType.Whistle)) { - soundTypes.Add(new SampleInfo + soundTypes.Add(new LegacySampleInfo { Bank = bankInfo.Add, Name = SampleInfo.HIT_WHISTLE, - Volume = bankInfo.Volume + Volume = bankInfo.Volume, + CustomSampleBank = bankInfo.CustomSampleBank }); } if (type.HasFlag(LegacySoundType.Clap)) { - soundTypes.Add(new SampleInfo + soundTypes.Add(new LegacySampleInfo { Bank = bankInfo.Add, Name = SampleInfo.HIT_CLAP, - Volume = bankInfo.Volume + Volume = bankInfo.Volume, + CustomSampleBank = bankInfo.CustomSampleBank }); } @@ -307,9 +314,23 @@ private class SampleBankInfo public string Add; public int Volume; + public int CustomSampleBank; + public SampleBankInfo Clone() => (SampleBankInfo)MemberwiseClone(); } + private class LegacySampleInfo : SampleInfo + { + public int CustomSampleBank + { + set + { + if (value > 1) + Suffix = value.ToString(); + } + } + } + private class FileSampleInfo : SampleInfo { public string Filename;