Skip to content

Commit

Permalink
Merge branch 'logging-track' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Apr 12, 2024
2 parents 3793a55 + 4822889 commit dd22735
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 25 deletions.
2 changes: 1 addition & 1 deletion osu.Game.Tests/Skins/TestSceneBeatmapSkinResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void TestRetrieveOggAudio()
AddAssert("sample is non-null", () => beatmap.Skin.GetSample(new SampleInfo(@"sample")) != null);
AddAssert("track is non-null", () =>
{
using (var track = beatmap.LoadTrack())
using (var track = beatmap.LoadTrack().GetUnderlyingTrack())
return track is not TrackVirtual;
});
}
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Tests/Visual/Audio/TestSceneAudioFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Game.Audio.Effects;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;

Expand All @@ -38,7 +39,7 @@ public partial class TestSceneAudioFilter : OsuTestScene
private void load(AudioManager audio)
{
beatmap = new WaveformTestBeatmap(audio);
track = beatmap.LoadTrack();
track = beatmap.LoadTrack().GetUnderlyingTrack();

Add(new FillFlowContainer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void TestAddAudioTrack()
AddUntilStep("wait for timeline load", () => Editor.ChildrenOfType<Timeline>().FirstOrDefault()?.IsLoaded == true);

AddStep("enter setup mode", () => InputManager.Key(Key.F4));
AddAssert("track is virtual", () => Beatmap.Value.Track is TrackVirtual);
AddAssert("track is virtual", () => Beatmap.Value.Track.GetUnderlyingTrack() is TrackVirtual);
AddAssert("switch track to real track", () =>
{
var setup = Editor.ChildrenOfType<SetupScreen>().First();
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tests/Visual/Editing/TimelineTestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected override void Update()
{
base.Update();

if (beatmap.Value.Track.IsLoaded)
if (beatmap.Value.Track.IsLoaded())
marker.X = (float)(editorClock.CurrentTime / beatmap.Value.Track.Length);
}
}
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Beatmaps/IWorkingBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public interface IWorkingBeatmap
/// <summary>
/// Retrieves the <see cref="Track"/> which this <see cref="IWorkingBeatmap"/> has loaded.
/// </summary>
Track Track { get; }
ITrack Track { get; }

/// <summary>
/// Constructs a playable <see cref="IBeatmap"/> from <see cref="Beatmap"/> using the applicable converters for a specific <see cref="RulesetInfo"/>.
Expand Down Expand Up @@ -118,7 +118,7 @@ public interface IWorkingBeatmap
/// outside of the game context.
/// </remarks>
/// <returns>A fresh track instance, which will also be available via <see cref="Track"/>.</returns>
Track LoadTrack();
ITrack LoadTrack();

/// <summary>
/// Returns the stream of the file from the given storage path.
Expand Down
194 changes: 189 additions & 5 deletions osu.Game/Beatmaps/WorkingBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
using JetBrains.Annotations;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics.Textures;
using osu.Framework.Logging;
using osu.Game.Rulesets;
Expand Down Expand Up @@ -45,7 +47,7 @@ public abstract class WorkingBeatmap : IWorkingBeatmap
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.
private ITrack track; // track is not Lazy as we allow transferring and loading multiple times.
private Waveform waveform; // waveform is also not Lazy as the track may change.

protected WorkingBeatmap(BeatmapInfo beatmapInfo, AudioManager audioManager)
Expand Down Expand Up @@ -103,9 +105,9 @@ public void CancelAsyncLoad()

public virtual bool TrackLoaded => track != null;

public Track LoadTrack()
public ITrack LoadTrack()
{
track = GetBeatmapTrack() ?? GetVirtualTrack(1000);
track = new LoggingTrack(GetBeatmapTrack() ?? GetVirtualTrack(1000));

// the track may have changed, recycle the current waveform.
waveform?.Dispose();
Expand All @@ -121,7 +123,7 @@ public void PrepareTrackForPreview(bool looping, double offsetFromPreviewPoint =

if (Track.RestartPoint == -1)
{
if (!Track.IsLoaded)
if (!Track.IsLoaded())
{
// force length to be populated (https://github.com/ppy/osu-framework/issues/4202)
Track.Seek(Track.CurrentTime);
Expand Down Expand Up @@ -153,7 +155,7 @@ public virtual bool TryTransferTrack([NotNull] WorkingBeatmap target)
/// This generally happens via MusicController when changing the global beatmap.
/// </summary>
[NotNull]
public Track Track
public ITrack Track
{
get
{
Expand Down Expand Up @@ -353,4 +355,186 @@ public BeatmapLoadTimeoutException(BeatmapInfo beatmapInfo)
}
}
}

/// <summary>
/// Temporary helper extension methods to aid in using <see cref="LoggingTrack"/> with minimal code damage.
/// </summary>
internal static class TrackExtensions
{
public static Track GetUnderlyingTrack(this ITrack track)
{
if (track is Track t)
return t;

if (track is LoggingTrack lt)
return lt.UnderlyingTrack;

return null;
}

public static bool IsLoaded(this ITrack track)
{
if (track is Track t)
return t.IsLoaded;

if (track is LoggingTrack lt)
return lt.UnderlyingTrack.IsLoaded;

return false;
}
}

/// <summary>
/// Temporary redirect class for logging purposes.
/// </summary>
internal class LoggingTrack : ITrack, IDisposable
{
public readonly Track UnderlyingTrack;

public LoggingTrack(Track underlyingTrack)
{
UnderlyingTrack = underlyingTrack;
}

public double CurrentTime => UnderlyingTrack.CurrentTime;

public void Reset()
{
UnderlyingTrack.Reset();
}

public void Start()
{
UnderlyingTrack.Start();
}

public void Stop()
{
UnderlyingTrack.Stop();
}

public bool Seek(double position)
{
Logger.Log($"{nameof(Seek)} on {UnderlyingTrack.GetType().ReadableName()} from {UnderlyingTrack.CurrentTime:N2} to {position:N2}");
return UnderlyingTrack.Seek(position);
}

public void ResetSpeedAdjustments()
{
UnderlyingTrack.ResetSpeedAdjustments();
}

public double Rate
{
get => UnderlyingTrack.Rate;
set => UnderlyingTrack.Rate = value;
}

public bool IsRunning => UnderlyingTrack.IsRunning;

public ChannelAmplitudes CurrentAmplitudes => UnderlyingTrack.CurrentAmplitudes;

public IBindable<double> AggregateVolume => UnderlyingTrack.AggregateVolume;

IBindable<double> IAggregateAudioAdjustment.AggregateVolume => UnderlyingTrack.AggregateVolume;

public IBindable<double> AggregateBalance => UnderlyingTrack.AggregateBalance;

public IBindable<double> AggregateFrequency => UnderlyingTrack.AggregateFrequency;

public IBindable<double> AggregateTempo => UnderlyingTrack.AggregateTempo;

public void BindAdjustments(IAggregateAudioAdjustment component)
{
UnderlyingTrack.BindAdjustments(component);
}

public void UnbindAdjustments(IAggregateAudioAdjustment component)
{
UnderlyingTrack.UnbindAdjustments(component);
}

void IAdjustableAudioComponent.AddAdjustment(AdjustableProperty type, IBindable<double> adjustBindable)
{
UnderlyingTrack.AddAdjustment(type, adjustBindable);
}

void IAdjustableAudioComponent.RemoveAdjustment(AdjustableProperty type, IBindable<double> adjustBindable)
{
UnderlyingTrack.RemoveAdjustment(type, adjustBindable);
}

public void AddAdjustment(AdjustableProperty type, IBindable<double> adjustBindable)
{
UnderlyingTrack.AddAdjustment(type, adjustBindable);
}

public void RemoveAdjustment(AdjustableProperty type, IBindable<double> adjustBindable)
{
UnderlyingTrack.RemoveAdjustment(type, adjustBindable);
}

public void RemoveAllAdjustments(AdjustableProperty type)
{
UnderlyingTrack.RemoveAllAdjustments(type);
}

public BindableNumber<double> Volume => UnderlyingTrack.Volume;

public BindableNumber<double> Balance => UnderlyingTrack.Balance;

public BindableNumber<double> Frequency => UnderlyingTrack.Frequency;

public BindableNumber<double> Tempo => UnderlyingTrack.Tempo;

public void Restart()
{
UnderlyingTrack.Restart();
}

public bool Looping
{
get => UnderlyingTrack.Looping;
set => UnderlyingTrack.Looping = value;
}

public bool IsDummyDevice => UnderlyingTrack.IsDummyDevice;

public double RestartPoint
{
get => UnderlyingTrack.RestartPoint;
set => UnderlyingTrack.RestartPoint = value;
}

public double Length
{
get => UnderlyingTrack.Length;
set => UnderlyingTrack.Length = value;
}

public int? Bitrate => UnderlyingTrack.Bitrate;

public bool IsReversed => UnderlyingTrack.IsReversed;

public bool HasCompleted => UnderlyingTrack.HasCompleted;

public bool IsLoaded => UnderlyingTrack.IsLoaded;

public event Action Completed
{
add => UnderlyingTrack.Completed += value;
remove => UnderlyingTrack.Completed -= value;
}

public event Action Failed
{
add => UnderlyingTrack.Failed += value;
remove => UnderlyingTrack.Failed -= value;
}

public void Dispose()
{
UnderlyingTrack.Dispose();
}
}
}
2 changes: 1 addition & 1 deletion osu.Game/Overlays/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private DrawableTrack getQueuedTrack()
{
// Important to keep this in its own method to avoid inadvertently capturing unnecessary variables in the callback.
// Can lead to leaks.
var queuedTrack = new DrawableTrack(current.LoadTrack());
var queuedTrack = new DrawableTrack(current.LoadTrack().GetUnderlyingTrack());
queuedTrack.Completed += onTrackCompleted;
return queuedTrack;
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Edit/Components/BottomBarContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class BottomBarContainer : Container

protected readonly IBindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();

protected readonly IBindable<Track> Track = new Bindable<Track>();
protected readonly IBindable<ITrack> Track = new Bindable<ITrack>();

protected readonly Drawable Background;
private readonly Container content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class TimelinePart<T> : Container<T> where T : Drawable
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; } = null!;

protected readonly IBindable<Track> Track = new Bindable<Track>();
protected readonly IBindable<ITrack> Track = new Bindable<ITrack>();

private readonly Container<T> content;

Expand Down Expand Up @@ -56,11 +56,13 @@ private void load(IBindable<WorkingBeatmap> beatmap, EditorClock clock)
private void updateRelativeChildSize()
{
// If the track is not loaded, assign a default sane length otherwise relative positioning becomes meaningless.
double trackLength = beatmap.Value.Track.IsLoaded ? beatmap.Value.Track.Length : 60000;
var track = beatmap.Value.Track.GetUnderlyingTrack();

double trackLength = track.IsLoaded ? track.Length : 60000;
content.RelativeChildSize = new Vector2((float)Math.Max(1, trackLength), 1);

// The track may not be loaded completely (only has a length once it is).
if (!beatmap.Value.Track.IsLoaded)
if (!track.IsLoaded)
Schedule(updateRelativeChildSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Timeline(Drawable userContent)

private double trackLengthForZoom;

private readonly IBindable<Track> track = new Bindable<Track>();
private readonly IBindable<ITrack> track = new Bindable<ITrack>();

[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours, OsuConfigManager config)
Expand Down
8 changes: 4 additions & 4 deletions osu.Game/Screens/Edit/EditorClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ namespace osu.Game.Screens.Edit
/// </summary>
public partial class EditorClock : CompositeComponent, IFrameBasedClock, IAdjustableClock, ISourceChangeableClock
{
public IBindable<Track> Track => track;
public IBindable<ITrack> Track => track;

private readonly Bindable<Track> track = new Bindable<Track>();
private readonly Bindable<ITrack> track = new Bindable<ITrack>();

public double TrackLength => track.Value?.IsLoaded == true ? track.Value.Length : 60000;
public double TrackLength => track.Value?.IsLoaded() == true ? track.Value.Length : 60000;

public ControlPointInfo ControlPointInfo => Beatmap.ControlPointInfo;

Expand Down Expand Up @@ -231,7 +231,7 @@ public void ProcessFrame()

public void ChangeSource(IClock source)
{
track.Value = source as Track;
track.Value = source as ITrack;
underlyingClock.ChangeSource(source);
}

Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Edit/Timing/WaveformComparisonDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void showFromTime(double time, bool animated)
private void regenerateDisplay(bool animated)
{
// Before a track is loaded, it won't have a valid length, which will break things.
if (!beatmap.Value.Track.IsLoaded)
if (!beatmap.Value.Track.IsLoaded())
{
Scheduler.AddOnce(regenerateDisplay, animated);
return;
Expand Down Expand Up @@ -305,7 +305,7 @@ internal partial class WaveformRow : CompositeDrawable
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;

private readonly IBindable<Track> track = new Bindable<Track>();
private readonly IBindable<ITrack> track = new Bindable<ITrack>();

public WaveformRow(bool isMainRow)
{
Expand Down
Loading

0 comments on commit dd22735

Please sign in to comment.