Rewrite waveform invalidation

This commit is contained in:
ansel 2022-12-22 15:59:51 +03:00
parent f2e8776529
commit d0645ce151
2 changed files with 14 additions and 11 deletions

View File

@ -34,8 +34,6 @@ public abstract class WorkingBeatmap : IWorkingBeatmap
// TODO: remove once the fallback lookup is not required (and access via `working.BeatmapInfo.Metadata` directly).
public BeatmapMetadata Metadata => BeatmapInfo.Metadata;
public Waveform Waveform => waveform.Value;
public Storyboard Storyboard => storyboard.Value;
public Texture Background => GetBackground(); // Texture uses ref counting, so we want to return a new instance every usage.
@ -48,7 +46,7 @@ public abstract class WorkingBeatmap : IWorkingBeatmap
private readonly object beatmapFetchLock = new object();
private Lazy<Waveform> waveform;
private Waveform waveform;
private readonly Lazy<Storyboard> storyboard;
private readonly Lazy<ISkin> skin;
private Track track; // track is not Lazy as we allow transferring and loading multiple times.
@ -60,7 +58,6 @@ protected WorkingBeatmap(BeatmapInfo beatmapInfo, AudioManager audioManager)
BeatmapInfo = beatmapInfo;
BeatmapSetInfo = beatmapInfo.BeatmapSet ?? new BeatmapSetInfo();
waveform = new Lazy<Waveform>(GetWaveform);
storyboard = new Lazy<Storyboard>(GetStoryboard);
skin = new Lazy<ISkin>(GetSkin);
}
@ -171,6 +168,18 @@ protected Track GetVirtualTrack(double emptyLength = 0)
#endregion
#region Waveform
public Waveform Waveform => waveform ??= GetWaveform();
/// <summary>
/// Reloads waveform of beatmap's track even if one is already cached.
/// </summary>
/// <returns>Newly loaded waveform.</returns>
public Waveform LoadWaveform() => waveform = GetWaveform();
#endregion
#region Beatmap
public virtual bool BeatmapLoaded => beatmapLoadTask?.IsCompleted ?? false;
@ -329,12 +338,6 @@ public virtual IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList<M
#endregion
public void InvalidateWaveform()
{
if (waveform.IsValueCreated)
waveform = new Lazy<Waveform>(GetWaveform);
}
public override string ToString() => BeatmapInfo.ToString();
public abstract Stream GetStream(string storagePath);

View File

@ -118,7 +118,7 @@ public bool ChangeAudioTrack(FileInfo source)
}
working.Value.Metadata.AudioFile = destination.Name;
working.Value.InvalidateWaveform();
working.Value.LoadWaveform();
editorBeatmap.SaveState();
music.ReloadCurrentTrack();