Skip to content

Commit

Permalink
Merge pull request #26222 from bdach/i-cannot-into-offsets
Browse files Browse the repository at this point in the history
Fix global audio offset suggestion feature not taking previous offset value into account
  • Loading branch information
peppy authored Dec 29, 2023
2 parents 2b81f4f + cdcb3ef commit 490c584
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
25 changes: 22 additions & 3 deletions osu.Game/Configuration/SessionAverageHitErrorTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Up @@ -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?>();

Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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()
{
Expand Down

0 comments on commit 490c584

Please sign in to comment.