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
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-10-16 03:58:34 +00:00
|
|
|
|
using System;
|
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.IO.Archives;
|
2020-11-13 08:51:01 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-05-21 17:21:00 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2020-02-05 09:14:44 +00:00
|
|
|
|
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
|
|
|
|
|
2020-11-13 08:51:01 +00:00
|
|
|
|
public WaveformTestBeatmap(AudioManager audioManager, RulesetInfo rulesetInfo = null)
|
|
|
|
|
: this(audioManager, new TestBeatmap(rulesetInfo ?? new OsuRuleset().RulesetInfo))
|
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
|
|
|
|
|
2023-06-08 07:17:44 +00:00
|
|
|
|
public override Texture GetBackground() => null;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
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
|
|
|
|
|
2021-08-15 16:38:01 +00:00
|
|
|
|
protected internal override ISkin GetSkin() => null;
|
2021-05-21 17:21:00 +00:00
|
|
|
|
|
2021-04-17 15:47:13 +00:00
|
|
|
|
public override Stream GetStream(string storagePath) => null;
|
|
|
|
|
|
2020-08-07 13:31:41 +00:00
|
|
|
|
protected override Track GetBeatmapTrack() => trackStore.Get(firstAudioFile);
|
2019-05-31 05:57:11 +00:00
|
|
|
|
|
2022-05-20 11:43:50 +00:00
|
|
|
|
public override bool TryTransferTrack(WorkingBeatmap target)
|
|
|
|
|
{
|
|
|
|
|
// Our track comes from a local track store that's disposed on finalizer,
|
|
|
|
|
// therefore it's unsafe to transfer it to another working beatmap.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 10:48:48 +00:00
|
|
|
|
private string firstAudioFile
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
using (var reader = getZipReader())
|
2020-10-16 03:58:34 +00:00
|
|
|
|
return reader.Filenames.First(f => f.EndsWith(".mp3", StringComparison.Ordinal));
|
2019-12-19 10:48:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-13 06:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|