From 4b424263cea47ae0ce168838362f4364c1954bf9 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 4 Apr 2017 13:11:04 +0900 Subject: [PATCH] Fully parse control points. --- .../Beatmaps/Formats/OsuLegacyDecoderTest.cs | 1 - osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 74 ++++++++++++++----- osu.Game/Beatmaps/Samples/HitSampleInfo.cs | 2 +- osu.Game/Beatmaps/Samples/SampleInfo.cs | 1 + osu.Game/Beatmaps/Timing/ControlPoint.cs | 3 + osu.Game/Database/BeatmapInfo.cs | 1 - 6 files changed, 61 insertions(+), 21 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs index 356fa5a6c1..3c1f4eaf45 100644 --- a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs @@ -55,7 +55,6 @@ namespace osu.Game.Tests.Beatmaps.Formats var beatmapInfo = decoder.Decode(new StreamReader(stream)).BeatmapInfo; Assert.AreEqual(0, beatmapInfo.AudioLeadIn); Assert.AreEqual(false, beatmapInfo.Countdown); - Assert.AreEqual(SampleSet.Soft, beatmapInfo.SampleSet); Assert.AreEqual(0.7f, beatmapInfo.StackLeniency); Assert.AreEqual(false, beatmapInfo.SpecialStyle); Assert.AreEqual(PlayMode.Osu, beatmapInfo.Mode); diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 748583606b..6139ed8ec6 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -31,6 +31,10 @@ namespace osu.Game.Beatmaps.Formats // TODO: Not sure how far back to go, or differences between versions } + private SampleSet defaultSampleSet; + private int defaultSampleVolume; + private bool samplesMatchPlaybackRate; + private readonly int beatmapVersion; public OsuLegacyDecoder() @@ -73,7 +77,13 @@ namespace osu.Game.Beatmaps.Formats beatmap.BeatmapInfo.Countdown = int.Parse(val) == 1; break; case @"SampleSet": - beatmap.BeatmapInfo.SampleSet = (SampleSet)Enum.Parse(typeof(SampleSet), val); + defaultSampleSet = (SampleSet)Enum.Parse(typeof(SampleSet), val); + break; + case @"SampleVolume": + defaultSampleVolume = int.Parse(val); + break; + case "SamplesMatchPlaybackRate": + samplesMatchPlaybackRate = val[0] == '1'; break; case @"StackLeniency": beatmap.BeatmapInfo.StackLeniency = float.Parse(val, NumberFormatInfo.InvariantInfo); @@ -203,28 +213,56 @@ namespace osu.Game.Beatmaps.Formats private void handleTimingPoints(Beatmap beatmap, string val) { - ControlPoint cp = null; - string[] split = val.Split(','); - if (split.Length > 2) + double time = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo); + double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo); + + TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple; + if (split.Length >= 3) + timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)int.Parse(split[2]); + + SampleSet sampleSet = defaultSampleSet; + if (split.Length >= 4) + sampleSet = (SampleSet)int.Parse(split[3]); + + SampleBank sampleBank = SampleBank.Default; + if (split.Length >= 5) + sampleBank = (SampleBank)int.Parse(split[4]); + + int sampleVolume = defaultSampleVolume; + if (split.Length >= 6) + sampleVolume = int.Parse(split[5]); + + bool timingChange = true; + if (split.Length >= 7) + timingChange = split[6][0] == '1'; + + bool kiaiMode = false; + bool omitFirstBarSignature = false; + if (split.Length >= 8) { - int effectFlags = split.Length > 7 ? Convert.ToInt32(split[7], NumberFormatInfo.InvariantInfo) : 0; - double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo); - cp = new ControlPoint - { - Time = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo), - BeatLength = beatLength > 0 ? beatLength : 0, - VelocityAdjustment = beatLength < 0 ? -beatLength / 100.0 : 1, - TimingChange = split.Length <= 6 || split[6][0] == '1', - KiaiMode = (effectFlags & 1) > 0, - OmitFirstBarLine = (effectFlags & 8) > 0, - TimeSignature = (TimeSignatures)int.Parse(split[2]) - }; + int effectFlags = int.Parse(split[7]); + kiaiMode = (effectFlags & 1) > 0; + omitFirstBarSignature = (effectFlags & 8) > 0; } - if (cp != null) - beatmap.TimingInfo.ControlPoints.Add(cp); + beatmap.TimingInfo.ControlPoints.Add(new ControlPoint + { + Time = time, + BeatLength = beatLength, + VelocityAdjustment = beatLength < 0 ? -beatLength / 100.0 : 1, + TimingChange = timingChange, + TimeSignature = timeSignature, + Sample = new SampleInfo + { + Bank = sampleBank, + Set = sampleSet, + Volume = sampleVolume + }, + KiaiMode = kiaiMode, + OmitFirstBarLine = omitFirstBarSignature + }); } private void handleColours(Beatmap beatmap, string key, string val, ref bool hasCustomColours) diff --git a/osu.Game/Beatmaps/Samples/HitSampleInfo.cs b/osu.Game/Beatmaps/Samples/HitSampleInfo.cs index c1cf1bd5e5..f5a5cc1bea 100644 --- a/osu.Game/Beatmaps/Samples/HitSampleInfo.cs +++ b/osu.Game/Beatmaps/Samples/HitSampleInfo.cs @@ -5,6 +5,6 @@ namespace osu.Game.Beatmaps.Samples { public class HitSampleInfo : SampleInfo { - public SampleType Type { get; set; } + public SampleType Type; } } diff --git a/osu.Game/Beatmaps/Samples/SampleInfo.cs b/osu.Game/Beatmaps/Samples/SampleInfo.cs index 5f9572c871..5b8f44d116 100644 --- a/osu.Game/Beatmaps/Samples/SampleInfo.cs +++ b/osu.Game/Beatmaps/Samples/SampleInfo.cs @@ -7,5 +7,6 @@ namespace osu.Game.Beatmaps.Samples { public SampleBank Bank; public SampleSet Set; + public int Volume; } } diff --git a/osu.Game/Beatmaps/Timing/ControlPoint.cs b/osu.Game/Beatmaps/Timing/ControlPoint.cs index 40320a88d7..00d3acba71 100644 --- a/osu.Game/Beatmaps/Timing/ControlPoint.cs +++ b/osu.Game/Beatmaps/Timing/ControlPoint.cs @@ -1,6 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Beatmaps.Samples; + namespace osu.Game.Beatmaps.Timing { public class ControlPoint @@ -11,6 +13,7 @@ namespace osu.Game.Beatmaps.Timing TimingChange = true, }; + public SampleInfo Sample; public TimeSignatures TimeSignature; public double Time; public double BeatLength; diff --git a/osu.Game/Database/BeatmapInfo.cs b/osu.Game/Database/BeatmapInfo.cs index 890623091d..e8ec8e500c 100644 --- a/osu.Game/Database/BeatmapInfo.cs +++ b/osu.Game/Database/BeatmapInfo.cs @@ -46,7 +46,6 @@ namespace osu.Game.Database // General public int AudioLeadIn { get; set; } public bool Countdown { get; set; } - public SampleSet SampleSet { get; set; } public float StackLeniency { get; set; } public bool SpecialStyle { get; set; } public PlayMode Mode { get; set; }