1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-28 08:02:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Editing/TestSceneWaveform.cs
2022-06-17 16:37:17 +09:00

119 lines
3.7 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Threading;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Osu;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Editing
{
[TestFixture]
public class TestSceneWaveform : OsuTestScene
{
private IWorkingBeatmap waveformBeatmap;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
waveformBeatmap = new WaveformTestBeatmap(audio);
}
[TestCase(1f)]
[TestCase(1f / 2)]
[TestCase(1f / 4)]
[TestCase(1f / 8)]
[TestCase(1f / 16)]
[TestCase(0f)]
public void TestResolution(float resolution)
{
TestWaveformGraph graph = null;
AddStep("add graph", () =>
{
Child = new Container
{
RelativeSizeAxes = Axes.X,
Height = 100,
Children = new Drawable[]
{
graph = new TestWaveformGraph
{
RelativeSizeAxes = Axes.Both,
Resolution = resolution,
Waveform = waveformBeatmap.Waveform,
},
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.75f
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = $"Resolution: {resolution:0.00}"
}
}
}
}
};
});
AddUntilStep("wait for load", () => graph.Loaded.IsSet);
}
[Test]
public void TestDefaultBeatmap()
{
TestWaveformGraph graph = null;
AddStep("add graph", () =>
{
Child = new Container
{
RelativeSizeAxes = Axes.X,
Height = 100,
Child = graph = new TestWaveformGraph
{
RelativeSizeAxes = Axes.Both,
Waveform = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).Waveform,
},
};
});
AddUntilStep("wait for load", () => graph.Loaded.IsSet);
}
public class TestWaveformGraph : WaveformGraph
{
public readonly ManualResetEventSlim Loaded = new ManualResetEventSlim();
protected override void OnWaveformRegenerated(Waveform waveform)
{
base.OnWaveformRegenerated(waveform);
Loaded.Set();
}
}
}
}