1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 18:27:26 +08:00
osu-lazer/osu.Game/Beatmaps/WorkingBeatmap.cs

97 lines
2.7 KiB
C#
Raw Normal View History

//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.IO;
using osu.Framework.Audio.Track;
using osu.Game.Beatmaps.Formats;
using osu.Game.Beatmaps.IO;
using osu.Game.Database;
namespace osu.Game.Beatmaps
{
public class WorkingBeatmap : IDisposable
{
public readonly BeatmapInfo BeatmapInfo;
public readonly BeatmapSetInfo BeatmapSetInfo;
private readonly BeatmapDatabase database;
private ArchiveReader reader => database.GetReader(BeatmapSetInfo);
private Beatmap beatmap;
public Beatmap Beatmap
{
get
{
if (beatmap != null) return beatmap;
try
{
using (var stream = new StreamReader(reader.ReadFile(BeatmapInfo.Path)))
beatmap = BeatmapDecoder.GetDecoder(stream)?.Decode(stream);
}
catch { }
return beatmap;
}
set { beatmap = value; }
}
private AudioTrack track;
public AudioTrack Track
{
get
{
2016-10-28 18:55:48 +08:00
if (track != null) return track;
try
{
var trackData = reader.ReadFile(BeatmapInfo.Metadata.AudioFile);
2016-10-28 18:55:48 +08:00
if (trackData != null)
track = new AudioTrackBass(trackData);
}
2016-10-28 18:55:48 +08:00
catch { }
return track;
}
set { track = value; }
}
public WorkingBeatmap(Beatmap beatmap)
{
this.beatmap = beatmap;
}
public WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, BeatmapDatabase database)
{
2016-10-28 20:08:32 +08:00
this.BeatmapInfo = beatmapInfo;
this.BeatmapSetInfo = beatmapSetInfo;
this.database = database;
}
private bool isDisposed;
protected virtual void Dispose(bool disposing)
{
if (!isDisposed)
{
track?.Dispose();
reader?.Dispose();
isDisposed = true;
}
}
public void Dispose()
{
Dispose(true);
}
public void TransferTo(WorkingBeatmap working)
{
2016-10-28 20:08:32 +08:00
if (track != null && working.BeatmapInfo.Metadata.AudioFile == BeatmapInfo.Metadata.AudioFile && working.BeatmapInfo.BeatmapSet.Path == BeatmapInfo.BeatmapSet.Path)
working.track = track;
}
}
}