Exemplo n.º 1
0
        public void TestDecodeBeatmapMetadata()
        {
            var decoder = new LegacyBeatmapDecoder();

            using (var resStream = TestResources.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
                using (var stream = new LineBufferedReader(resStream))
                {
                    var beatmap     = decoder.Decode(stream);
                    var beatmapInfo = beatmap.BeatmapInfo;
                    var metadata    = beatmap.Metadata;

                    Assert.AreEqual("Renatus", metadata.Title);
                    Assert.AreEqual("Renatus", metadata.TitleUnicode);
                    Assert.AreEqual("Soleily", metadata.Artist);
                    Assert.AreEqual("Soleily", metadata.ArtistUnicode);
                    Assert.AreEqual("Gamu", metadata.AuthorString);
                    Assert.AreEqual("Insane", beatmapInfo.Version);
                    Assert.AreEqual(string.Empty, metadata.Source);
                    Assert.AreEqual("MBC7 Unisphere 地球ヤバイEP Chikyu Yabai", metadata.Tags);
                    Assert.AreEqual(557821, beatmapInfo.OnlineBeatmapID);
                    Assert.AreEqual(241526, beatmapInfo.BeatmapSet.OnlineBeatmapSetID);
                }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads a .osu file first with a <see cref="LegacyBeatmapDecoder"/>, serializes the resulting <see cref="Beatmap"/> to JSON
        /// and then deserializes the result back into a <see cref="Beatmap"/> through an <see cref="JsonBeatmapDecoder"/>.
        /// </summary>
        /// <param name="filename">The .osu file to decode.</param>
        /// <param name="jsonDecoded">The <see cref="Beatmap"/> after being decoded by an <see cref="JsonBeatmapDecoder"/>.</param>
        /// <returns>The <see cref="Beatmap"/> after being decoded by an <see cref="LegacyBeatmapDecoder"/>.</returns>
        private Beatmap decode(string filename, out Beatmap jsonDecoded)
        {
            using (var stream = TestResources.OpenResource(filename))
                using (var sr = new LineBufferedReader(stream))
                {
                    var legacyDecoded = new LegacyBeatmapDecoder {
                        ApplyOffsets = false
                    }.Decode(sr);

                    using (var ms = new MemoryStream())
                        using (var sw = new StreamWriter(ms))
                            using (var sr2 = new LineBufferedReader(ms))
                            {
                                sw.Write(legacyDecoded.Serialize());
                                sw.Flush();

                                ms.Position = 0;

                                jsonDecoded = new JsonBeatmapDecoder().Decode(sr2);
                                return(legacyDecoded);
                            }
                }
        }
Exemplo n.º 3
0
        public void TestDecodeOverlappingTimingPoints()
        {
            var decoder = new LegacyBeatmapDecoder {
                ApplyOffsets = false
            };

            using (var resStream = TestResources.OpenResource("overlapping-control-points.osu"))
                using (var stream = new LineBufferedReader(resStream))
                {
                    var controlPoints = decoder.Decode(stream).ControlPointInfo;

                    Assert.That(controlPoints.TimingPoints.Count, Is.EqualTo(4));
                    Assert.That(controlPoints.DifficultyPoints.Count, Is.EqualTo(3));
                    Assert.That(controlPoints.EffectPoints.Count, Is.EqualTo(3));
                    Assert.That(controlPoints.SamplePoints.Count, Is.EqualTo(3));

                    Assert.That(controlPoints.DifficultyPointAt(500).SpeedMultiplier, Is.EqualTo(1.5).Within(0.1));
                    Assert.That(controlPoints.DifficultyPointAt(1500).SpeedMultiplier, Is.EqualTo(1.5).Within(0.1));
                    Assert.That(controlPoints.DifficultyPointAt(2500).SpeedMultiplier, Is.EqualTo(0.75).Within(0.1));
                    Assert.That(controlPoints.DifficultyPointAt(3500).SpeedMultiplier, Is.EqualTo(1.5).Within(0.1));

                    Assert.That(controlPoints.EffectPointAt(500).KiaiMode, Is.True);
                    Assert.That(controlPoints.EffectPointAt(1500).KiaiMode, Is.True);
                    Assert.That(controlPoints.EffectPointAt(2500).KiaiMode, Is.False);
                    Assert.That(controlPoints.EffectPointAt(3500).KiaiMode, Is.True);

                    Assert.That(controlPoints.SamplePointAt(500).SampleBank, Is.EqualTo("drum"));
                    Assert.That(controlPoints.SamplePointAt(1500).SampleBank, Is.EqualTo("drum"));
                    Assert.That(controlPoints.SamplePointAt(2500).SampleBank, Is.EqualTo("normal"));
                    Assert.That(controlPoints.SamplePointAt(3500).SampleBank, Is.EqualTo("drum"));

                    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(2500).BeatLength, Is.EqualTo(250).Within(0.1));
                    Assert.That(controlPoints.TimingPointAt(3500).BeatLength, Is.EqualTo(500).Within(0.1));
                }
        }
Exemplo n.º 4
0
        public void TestDecodeBeatmapGeneral()
        {
            var decoder = new LegacyBeatmapDecoder {
                ApplyOffsets = false
            };

            using (var resStream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
                using (var stream = new StreamReader(resStream))
                {
                    var beatmap     = decoder.Decode(stream);
                    var beatmapInfo = beatmap.BeatmapInfo;
                    var metadata    = beatmap.Metadata;

                    Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", metadata.AudioFile);
                    Assert.AreEqual(0, beatmapInfo.AudioLeadIn);
                    Assert.AreEqual(164471, metadata.PreviewTime);
                    Assert.IsFalse(beatmapInfo.Countdown);
                    Assert.AreEqual(0.7f, beatmapInfo.StackLeniency);
                    Assert.IsTrue(beatmapInfo.RulesetID == 0);
                    Assert.IsFalse(beatmapInfo.LetterboxInBreaks);
                    Assert.IsFalse(beatmapInfo.SpecialStyle);
                    Assert.IsFalse(beatmapInfo.WidescreenStoryboard);
                }
        }
Exemplo n.º 5
0
        public void TestDecodeBeatmapTimingPoints()
        {
            var decoder = new LegacyBeatmapDecoder {
                ApplyOffsets = false
            };

            using (var resStream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
                using (var stream = new StreamReader(resStream))
                {
                    var beatmap       = decoder.Decode(stream);
                    var controlPoints = beatmap.ControlPointInfo;

                    Assert.AreEqual(4, controlPoints.TimingPoints.Count);
                    var timingPoint = controlPoints.TimingPoints[0];
                    Assert.AreEqual(956, timingPoint.Time);
                    Assert.AreEqual(329.67032967033d, timingPoint.BeatLength);
                    Assert.AreEqual(TimeSignatures.SimpleQuadruple, timingPoint.TimeSignature);

                    Assert.AreEqual(5, controlPoints.DifficultyPoints.Count);
                    var difficultyPoint = controlPoints.DifficultyPoints[0];
                    Assert.AreEqual(116999, difficultyPoint.Time);
                    Assert.AreEqual(0.75000000000000189d, difficultyPoint.SpeedMultiplier);

                    Assert.AreEqual(34, controlPoints.SamplePoints.Count);
                    var soundPoint = controlPoints.SamplePoints[0];
                    Assert.AreEqual(956, soundPoint.Time);
                    Assert.AreEqual("soft", soundPoint.SampleBank);
                    Assert.AreEqual(60, soundPoint.SampleVolume);

                    Assert.AreEqual(8, controlPoints.EffectPoints.Count);
                    var effectPoint = controlPoints.EffectPoints[0];
                    Assert.AreEqual(53703, effectPoint.Time);
                    Assert.IsTrue(effectPoint.KiaiMode);
                    Assert.IsFalse(effectPoint.OmitFirstBarLine);
                }
        }
Exemplo n.º 6
0
        public void TestDecodeBeatmapTimingPoints()
        {
            var decoder = new LegacyBeatmapDecoder {
                ApplyOffsets = false
            };

            using (var resStream = TestResources.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
                using (var stream = new LineBufferedReader(resStream))
                {
                    var beatmap       = decoder.Decode(stream);
                    var controlPoints = beatmap.ControlPointInfo;

                    Assert.AreEqual(4, controlPoints.TimingPoints.Count);
                    Assert.AreEqual(5, controlPoints.DifficultyPoints.Count);
                    Assert.AreEqual(34, controlPoints.SamplePoints.Count);
                    Assert.AreEqual(8, controlPoints.EffectPoints.Count);

                    var timingPoint = controlPoints.TimingPointAt(0);
                    Assert.AreEqual(956, timingPoint.Time);
                    Assert.AreEqual(329.67032967033, timingPoint.BeatLength);
                    Assert.AreEqual(TimeSignatures.SimpleQuadruple, timingPoint.TimeSignature);

                    timingPoint = controlPoints.TimingPointAt(48428);
                    Assert.AreEqual(956, timingPoint.Time);
                    Assert.AreEqual(329.67032967033d, timingPoint.BeatLength);
                    Assert.AreEqual(TimeSignatures.SimpleQuadruple, timingPoint.TimeSignature);

                    timingPoint = controlPoints.TimingPointAt(119637);
                    Assert.AreEqual(119637, timingPoint.Time);
                    Assert.AreEqual(659.340659340659, timingPoint.BeatLength);
                    Assert.AreEqual(TimeSignatures.SimpleQuadruple, timingPoint.TimeSignature);

                    var difficultyPoint = controlPoints.DifficultyPointAt(0);
                    Assert.AreEqual(0, difficultyPoint.Time);
                    Assert.AreEqual(1.0, difficultyPoint.SpeedMultiplier);

                    difficultyPoint = controlPoints.DifficultyPointAt(48428);
                    Assert.AreEqual(0, difficultyPoint.Time);
                    Assert.AreEqual(1.0, difficultyPoint.SpeedMultiplier);

                    difficultyPoint = controlPoints.DifficultyPointAt(116999);
                    Assert.AreEqual(116999, difficultyPoint.Time);
                    Assert.AreEqual(0.75, difficultyPoint.SpeedMultiplier, 0.1);

                    var soundPoint = controlPoints.SamplePointAt(0);
                    Assert.AreEqual(956, soundPoint.Time);
                    Assert.AreEqual("soft", soundPoint.SampleBank);
                    Assert.AreEqual(60, soundPoint.SampleVolume);

                    soundPoint = controlPoints.SamplePointAt(53373);
                    Assert.AreEqual(53373, soundPoint.Time);
                    Assert.AreEqual("soft", soundPoint.SampleBank);
                    Assert.AreEqual(60, soundPoint.SampleVolume);

                    soundPoint = controlPoints.SamplePointAt(119637);
                    Assert.AreEqual(119637, soundPoint.Time);
                    Assert.AreEqual("soft", soundPoint.SampleBank);
                    Assert.AreEqual(80, soundPoint.SampleVolume);

                    var effectPoint = controlPoints.EffectPointAt(0);
                    Assert.AreEqual(0, effectPoint.Time);
                    Assert.IsFalse(effectPoint.KiaiMode);
                    Assert.IsFalse(effectPoint.OmitFirstBarLine);

                    effectPoint = controlPoints.EffectPointAt(53703);
                    Assert.AreEqual(53703, effectPoint.Time);
                    Assert.IsTrue(effectPoint.KiaiMode);
                    Assert.IsFalse(effectPoint.OmitFirstBarLine);

                    effectPoint = controlPoints.EffectPointAt(119637);
                    Assert.AreEqual(95901, effectPoint.Time);
                    Assert.IsFalse(effectPoint.KiaiMode);
                    Assert.IsFalse(effectPoint.OmitFirstBarLine);
                }
        }
Exemplo n.º 7
0
        public void TestDecodeStoryboardEvents()
        {
            var decoder = new LegacyBeatmapDecoder();

            using (var resStream = Resource.OpenResource("Himeringo - Yotsuya-san ni Yoroshiku (RLC) [Winber1's Extreme].osu"))
                using (var stream = new StreamReader(resStream))
                {
                    var storyboard = decoder.GetStoryboardDecoder().DecodeStoryboard(stream);

                    Assert.IsTrue(storyboard.HasDrawable);
                    Assert.AreEqual(4, storyboard.Layers.Count());

                    StoryboardLayer background = storyboard.Layers.FirstOrDefault(l => l.Depth == 3);
                    Assert.IsNotNull(background);
                    Assert.AreEqual(16, background.Elements.Count());
                    Assert.IsTrue(background.EnabledWhenFailing);
                    Assert.IsTrue(background.EnabledWhenPassing);
                    Assert.AreEqual("Background", background.Name);

                    StoryboardLayer fail = storyboard.Layers.FirstOrDefault(l => l.Depth == 2);
                    Assert.IsNotNull(fail);
                    Assert.AreEqual(0, fail.Elements.Count());
                    Assert.IsTrue(fail.EnabledWhenFailing);
                    Assert.IsFalse(fail.EnabledWhenPassing);
                    Assert.AreEqual("Fail", fail.Name);

                    StoryboardLayer pass = storyboard.Layers.FirstOrDefault(l => l.Depth == 1);
                    Assert.IsNotNull(pass);
                    Assert.AreEqual(0, pass.Elements.Count());
                    Assert.IsFalse(pass.EnabledWhenFailing);
                    Assert.IsTrue(pass.EnabledWhenPassing);
                    Assert.AreEqual("Pass", pass.Name);

                    StoryboardLayer foreground = storyboard.Layers.FirstOrDefault(l => l.Depth == 0);
                    Assert.IsNotNull(foreground);
                    Assert.AreEqual(151, foreground.Elements.Count());
                    Assert.IsTrue(foreground.EnabledWhenFailing);
                    Assert.IsTrue(foreground.EnabledWhenPassing);
                    Assert.AreEqual("Foreground", foreground.Name);

                    int spriteCount    = background.Elements.Count(x => x.GetType() == typeof(StoryboardSprite));
                    int animationCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardAnimation));
                    int sampleCount    = background.Elements.Count(x => x.GetType() == typeof(StoryboardSample));

                    Assert.AreEqual(15, spriteCount);
                    Assert.AreEqual(1, animationCount);
                    Assert.AreEqual(0, sampleCount);
                    Assert.AreEqual(background.Elements.Count(), spriteCount + animationCount + sampleCount);

                    var sprite = background.Elements.ElementAt(0) as StoryboardSprite;
                    Assert.NotNull(sprite);
                    Assert.IsTrue(sprite.HasCommands);
                    Assert.AreEqual(new Vector2(320, 240), sprite.InitialPosition);
                    Assert.IsTrue(sprite.IsDrawable);
                    Assert.AreEqual(Anchor.Centre, sprite.Origin);
                    Assert.AreEqual("SB/lyric/ja-21.png", sprite.Path);

                    var animation = background.Elements.ElementAt(12) as StoryboardAnimation;
                    Assert.NotNull(animation);
                    Assert.AreEqual(141175, animation.EndTime);
                    Assert.AreEqual(10, animation.FrameCount);
                    Assert.AreEqual(30, animation.FrameDelay);
                    Assert.IsTrue(animation.HasCommands);
                    Assert.AreEqual(new Vector2(320, 240), animation.InitialPosition);
                    Assert.IsTrue(animation.IsDrawable);
                    Assert.AreEqual(AnimationLoopType.LoopForever, animation.LoopType);
                    Assert.AreEqual(Anchor.Centre, animation.Origin);
                    Assert.AreEqual("SB/red jitter/red_0000.jpg", animation.Path);
                    Assert.AreEqual(78993, animation.StartTime);
                }
        }
Exemplo n.º 8
0
        static int Main(string[] args)
        {
            if (args == null)
            {
                Console.Write("Missing arguments: [inputMap.osu] [outputMap] {forceKeys}\n");
                return(1);
            }

            LegacyBeatmapDecoder legacyBeatmapDecoder = new LegacyBeatmapDecoder();
            IBeatmap             beatmap = null;


            try
            {
                using (StreamReader sr = new StreamReader(args[0]))
                {
                    try
                    {
                        beatmap = legacyBeatmapDecoder.Decode(sr);
                    }
                    catch (Exception e)
                    {
                        Console.Write("Could not convert input file:\n" + e);
                        return(1);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write("Could not read input file:\n" + e);
            }

            if (beatmap == null)
            {
                Console.Write("Failed");
                return(1);
            }

            IBeatmap convertedBeatmap = null;
            ManiaBeatmapConverter maniaBeatmapConverter = null;

            try
            {
                beatmap.BeatmapInfo.Ruleset = new OsuRuleset().RulesetInfo;
                maniaBeatmapConverter       = new ManiaBeatmapConverter(beatmap);

                // Third argument is optionnal and can force TargetColumns
                if (args.Length > 2)
                {
                    maniaBeatmapConverter.TargetColumns = Int32.Parse(args[2]);
                }

                convertedBeatmap = maniaBeatmapConverter.Convert();
            } catch (Exception e)
            {
                Console.Write("Could not convert input file:\n" + e);
                return(1);
            }

            int columns = maniaBeatmapConverter.TargetColumns;

            using (StreamWriter writer = new StreamWriter(args[1]))
            {
                writer.Write("[Difficulty]\n");
                writer.Write("CircleSize: " + columns + "\n");

                writer.Write("[HitObjects]\n");
                String current = "";
                foreach (ManiaHitObject maniaHitObject in convertedBeatmap.HitObjects)
                {
                    int columnPosition = (((maniaHitObject.Column) * (512 / columns)) + (256 / columns));
                    switch (maniaHitObject.GetType().Name)
                    {
                    case "Note":
                        current = columnPosition + ",192," + maniaHitObject.StartTime.ToString().Split(",")[0].Split(".")[0] + ",1,0,0:0:0:0:0\n";
                        break;

                    case "HoldNote":
                        current = columnPosition + ",192," + maniaHitObject.StartTime.ToString().Split(",")[0].Split(".")[0] + ",128,0," + (maniaHitObject as HoldNote).EndTime.ToString().Split(",")[0].Split(".")[0] + ":0:0:0:0\n";
                        break;
                    }
                    writer.Write(current);
                }
            }

            return(0);
        }