Skip to content

Commit

Permalink
Merge pull request #31342 from minetoblend/feature/speedy-metronome
Browse files Browse the repository at this point in the history
Speed up metronome in timing screen when pressing control key
  • Loading branch information
bdach authored Dec 31, 2024
2 parents b09a34c + 0641d2b commit 929173c
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions osu.Game/Screens/Edit/Timing/MetronomeDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Framework.Timing;
using osu.Framework.Utils;
Expand Down Expand Up @@ -41,6 +42,9 @@ public partial class MetronomeDisplay : BeatSyncedContainer
[Resolved]
private OverlayColourProvider overlayColourProvider { get; set; } = null!;

[Resolved]
private BindableBeatDivisor beatDivisor { get; set; } = null!;

public bool EnableClicking
{
get => metronomeTick.EnableClicking;
Expand Down Expand Up @@ -222,7 +226,7 @@ private void load(AudioManager audio)
Clock = new FramedClock(metronomeClock = new StopwatchClock(true));
}

private double beatLength;
private double effectiveBeatLength;

private TimingControlPoint timingPoint = null!;

Expand All @@ -232,11 +236,26 @@ private void load(AudioManager audio)

private ScheduledDelegate? latchDelegate;

private bool spedUp;

private int computeSpedUpDivisor()
{
if (!spedUp)
return 1;

if (beatDivisor.Value % 3 == 0)
return 3;
if (beatDivisor.Value % 2 == 0)
return 2;

return 1;
}

protected override void LoadComplete()
{
base.LoadComplete();

interpolatedBpm.BindValueChanged(bpm => bpmText.Text = bpm.NewValue.ToLocalisableString());
interpolatedBpm.BindValueChanged(_ => bpmText.Text = interpolatedBpm.Value.ToLocalisableString());
}

protected override void Update()
Expand All @@ -250,16 +269,20 @@ protected override void Update()

timingPoint = BeatSyncSource.ControlPoints.TimingPointAt(BeatSyncSource.Clock.CurrentTime);

if (beatLength != timingPoint.BeatLength)
Divisor = metronomeTick.Divisor = computeSpedUpDivisor();

if (effectiveBeatLength != timingPoint.BeatLength / Divisor)
{
beatLength = timingPoint.BeatLength;
effectiveBeatLength = timingPoint.BeatLength / Divisor;

EarlyActivationMilliseconds = timingPoint.BeatLength / 2;

float bpmRatio = (float)Interpolation.ApplyEasing(Easing.OutQuad, Math.Clamp((timingPoint.BPM - 30) / 480, 0, 1));
double effectiveBpm = 60000 / effectiveBeatLength;

float bpmRatio = (float)Interpolation.ApplyEasing(Easing.OutQuad, Math.Clamp((effectiveBpm - 30) / 480, 0, 1));

weight.MoveToY((float)Interpolation.Lerp(0.1f, 0.83f, bpmRatio), 600, Easing.OutQuint);
this.TransformBindableTo(interpolatedBpm, (int)Math.Round(timingPoint.BPM), 600, Easing.OutQuint);
this.TransformBindableTo(interpolatedBpm, (int)Math.Round(effectiveBpm), 600, Easing.OutQuint);
}

if (!BeatSyncSource.Clock.IsRunning && isSwinging)
Expand Down Expand Up @@ -305,17 +328,33 @@ protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint,
float currentAngle = swing.Rotation;
float targetAngle = currentAngle > 0 ? -angle : angle;

swing.RotateTo(targetAngle, beatLength, Easing.InOutQuad);
swing.RotateTo(targetAngle, effectiveBeatLength, Easing.InOutQuad);
}

private void onTickPlayed()
{
// Originally, this flash only occurred when the pendulum correctly passess the centre.
// Mappers weren't happy with the metronome tick not playing immediately after starting playback
// so now this matches the actual tick sample.
stick.FlashColour(overlayColourProvider.Content1, beatLength, Easing.OutQuint);
stick.FlashColour(overlayColourProvider.Content1, effectiveBeatLength, Easing.OutQuint);
}

protected override bool OnKeyDown(KeyDownEvent e)
{
updateDivisorFromKey(e);

return base.OnKeyDown(e);
}

protected override void OnKeyUp(KeyUpEvent e)
{
base.OnKeyUp(e);

updateDivisorFromKey(e);
}

private void updateDivisorFromKey(UIEvent e) => spedUp = e.ControlPressed;

private partial class MetronomeTick : BeatSyncedContainer
{
public bool EnableClicking;
Expand Down

0 comments on commit 929173c

Please sign in to comment.