Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global audio offset suggestion feature not taking previous offset value into account #26222

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions osu.Game/Configuration/SessionAverageHitErrorTracker.cs
Original file line number Diff line number Diff line change
@@ -17,11 +17,14 @@ namespace osu.Game.Configuration
[Cached]
public partial class SessionAverageHitErrorTracker : Component
{
public IBindableList<double> AverageHitErrorHistory => averageHitErrorHistory;
private readonly BindableList<double> averageHitErrorHistory = new BindableList<double>();
public IBindableList<DataPoint> AverageHitErrorHistory => averageHitErrorHistory;
private readonly BindableList<DataPoint> averageHitErrorHistory = new BindableList<DataPoint>();

private readonly Bindable<ScoreInfo?> latestScore = new Bindable<ScoreInfo?>();

[Resolved]
private OsuConfigManager configManager { get; set; } = null!;

[BackgroundDependencyLoader]
private void load(SessionStatics statics)
{
@@ -46,9 +49,25 @@ private void calculateAverageHitError(ScoreInfo? newScore)
// keep a sane maximum number of entries.
if (averageHitErrorHistory.Count >= 50)
averageHitErrorHistory.RemoveAt(0);
averageHitErrorHistory.Add(averageError);

double globalOffset = configManager.Get<double>(OsuSetting.AudioOffset);
averageHitErrorHistory.Add(new DataPoint(averageError, globalOffset));
}

public void ClearHistory() => averageHitErrorHistory.Clear();

public readonly struct DataPoint
{
public double AverageHitError { get; }
public double GlobalAudioOffset { get; }

public double SuggestedGlobalAudioOffset => GlobalAudioOffset - AverageHitError;

public DataPoint(double averageHitError, double globalOffset)
{
AverageHitError = averageHitError;
GlobalAudioOffset = globalOffset;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ public Bindable<double> Current

private readonly BindableNumberWithCurrent<double> current = new BindableNumberWithCurrent<double>();

private readonly IBindableList<double> averageHitErrorHistory = new BindableList<double>();
private readonly IBindableList<SessionAverageHitErrorTracker.DataPoint> averageHitErrorHistory = new BindableList<SessionAverageHitErrorTracker.DataPoint>();

private readonly Bindable<double?> suggestedOffset = new Bindable<double?>();

@@ -112,7 +112,7 @@ private void updateDisplay(object? _, NotifyCollectionChangedEventArgs e)
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (double average in e.NewItems!)
foreach (SessionAverageHitErrorTracker.DataPoint dataPoint in e.NewItems!)
{
notchContainer.ForEach(n => n.Alpha *= 0.95f);
notchContainer.Add(new Box
@@ -122,16 +122,16 @@ private void updateDisplay(object? _, NotifyCollectionChangedEventArgs e)
RelativePositionAxes = Axes.X,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
X = getXPositionForAverage(average)
X = getXPositionForOffset(dataPoint.SuggestedGlobalAudioOffset)
});
}

break;

case NotifyCollectionChangedAction.Remove:
foreach (double average in e.OldItems!)
foreach (SessionAverageHitErrorTracker.DataPoint dataPoint in e.OldItems!)
{
var notch = notchContainer.FirstOrDefault(n => n.X == getXPositionForAverage(average));
var notch = notchContainer.FirstOrDefault(n => n.X == getXPositionForOffset(dataPoint.SuggestedGlobalAudioOffset));
Debug.Assert(notch != null);
notchContainer.Remove(notch, true);
}
@@ -143,10 +143,10 @@ private void updateDisplay(object? _, NotifyCollectionChangedEventArgs e)
break;
}

suggestedOffset.Value = averageHitErrorHistory.Any() ? -averageHitErrorHistory.Average() : null;
suggestedOffset.Value = averageHitErrorHistory.Any() ? -averageHitErrorHistory.Average(dataPoint => dataPoint.SuggestedGlobalAudioOffset) : null;
}

private float getXPositionForAverage(double average) => (float)(Math.Clamp(-average, current.MinValue, current.MaxValue) / (2 * current.MaxValue));
private float getXPositionForOffset(double offset) => (float)(Math.Clamp(offset, current.MinValue, current.MaxValue) / (2 * current.MaxValue));

private void updateHintText()
{