2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2019-05-31 05:40:53 +00:00
|
|
|
|
using osu.Framework.Audio;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2019-09-09 22:43:30 +00:00
|
|
|
|
using osu.Game.IO;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
using osu.Game.IO.Archives;
|
2020-02-05 09:14:44 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
2019-01-28 09:19:57 +00:00
|
|
|
|
using osu.Game.Tests.Resources;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-05-15 09:32:29 +00:00
|
|
|
|
/// A <see cref="WorkingBeatmap"/> that is used for test scenes that include waveforms.
|
2018-06-13 06:09:03 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public class WaveformTestBeatmap : WorkingBeatmap
|
|
|
|
|
{
|
2020-02-05 09:14:44 +00:00
|
|
|
|
private readonly Beatmap beatmap;
|
2019-05-31 05:40:53 +00:00
|
|
|
|
private readonly ITrackStore trackStore;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
2019-05-31 05:40:53 +00:00
|
|
|
|
public WaveformTestBeatmap(AudioManager audioManager)
|
2020-02-05 09:14:44 +00:00
|
|
|
|
: this(audioManager, new WaveformBeatmap())
|
2018-06-13 06:09:03 +00:00
|
|
|
|
{
|
2020-02-05 09:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WaveformTestBeatmap(AudioManager audioManager, Beatmap beatmap)
|
|
|
|
|
: base(beatmap.BeatmapInfo, audioManager)
|
|
|
|
|
{
|
|
|
|
|
this.beatmap = beatmap;
|
2019-12-19 10:48:48 +00:00
|
|
|
|
trackStore = audioManager.GetTrackStore(getZipReader());
|
2018-06-13 06:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 08:01:41 +00:00
|
|
|
|
~WaveformTestBeatmap()
|
2018-06-13 06:09:03 +00:00
|
|
|
|
{
|
2020-02-10 08:01:41 +00:00
|
|
|
|
// Remove the track store from the audio manager
|
2019-05-31 05:40:53 +00:00
|
|
|
|
trackStore?.Dispose();
|
2018-06-13 06:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 09:14:44 +00:00
|
|
|
|
private static Stream getStream() => TestResources.GetTestBeatmapStream();
|
2019-12-20 09:07:39 +00:00
|
|
|
|
|
2020-02-05 09:14:44 +00:00
|
|
|
|
private static ZipArchiveReader getZipReader() => new ZipArchiveReader(getStream());
|
2019-12-20 09:07:39 +00:00
|
|
|
|
|
2020-02-05 09:14:44 +00:00
|
|
|
|
protected override IBeatmap GetBeatmap() => beatmap;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
|
|
|
|
protected override Texture GetBackground() => null;
|
|
|
|
|
|
2019-05-31 05:57:11 +00:00
|
|
|
|
protected override Waveform GetWaveform() => new Waveform(trackStore.GetStream(firstAudioFile));
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
2019-05-31 05:57:11 +00:00
|
|
|
|
protected override Track GetTrack() => trackStore.Get(firstAudioFile);
|
|
|
|
|
|
2019-12-19 10:48:48 +00:00
|
|
|
|
private string firstAudioFile
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
using (var reader = getZipReader())
|
|
|
|
|
return reader.Filenames.First(f => f.EndsWith(".mp3"));
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
2020-02-05 09:14:44 +00:00
|
|
|
|
private class WaveformBeatmap : TestBeatmap
|
2018-06-13 06:09:03 +00:00
|
|
|
|
{
|
2020-02-05 09:14:44 +00:00
|
|
|
|
public WaveformBeatmap()
|
|
|
|
|
: base(new CatchRuleset().RulesetInfo)
|
2019-12-19 10:48:48 +00:00
|
|
|
|
{
|
2020-02-05 09:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Beatmap CreateBeatmap()
|
|
|
|
|
{
|
|
|
|
|
using (var reader = getZipReader())
|
2019-12-19 10:48:48 +00:00
|
|
|
|
using (var beatmapStream = reader.GetStream(reader.Filenames.First(f => f.EndsWith(".osu"))))
|
|
|
|
|
using (var beatmapReader = new LineBufferedReader(beatmapStream))
|
|
|
|
|
return Decoder.GetDecoder<Beatmap>(beatmapReader).Decode(beatmapReader);
|
|
|
|
|
}
|
2018-06-13 06:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|