Skip to content

Commit

Permalink
Merge pull request #18448 from frenzibyte/editor-metronome-rate
Browse files Browse the repository at this point in the history
Fix metronome speed not adjusted on different playback rates
  • Loading branch information
peppy authored May 28, 2022
2 parents 4f2910c + 2fac710 commit 62266c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions osu.Game/Screens/Edit/Timing/MetronomeDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers;
Expand All @@ -28,6 +29,8 @@ public class MetronomeDisplay : BeatSyncedContainer
private Drawable weight;
private Drawable stick;

private IAdjustableClock metronomeClock;

[Resolved]
private OverlayColourProvider overlayColourProvider { get; set; }

Expand Down Expand Up @@ -192,6 +195,8 @@ private void load()
Y = -3,
},
};

Clock = new FramedClock(metronomeClock = new StopwatchClock(true));
}

private double beatLength;
Expand All @@ -216,6 +221,8 @@ protected override void Update()
if (BeatSyncSource.ControlPoints == null || BeatSyncSource.Clock == null)
return;

metronomeClock.Rate = IsBeatSyncedWithTrack ? BeatSyncSource.Clock.Rate : 1;

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

if (beatLength != timingPoint.BeatLength)
Expand Down
10 changes: 10 additions & 0 deletions osu.Game/Tests/Visual/EditorClockTestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
Expand All @@ -24,6 +25,8 @@ public abstract class EditorClockTestScene : OsuManualInputManagerTestScene
[Cached]
protected new readonly EditorClock Clock;

private readonly Bindable<double> frequencyAdjustment = new BindableDouble(1);

protected virtual bool ScrollUsingMouseWheel => true;

protected EditorClockTestScene()
Expand All @@ -44,14 +47,21 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
protected override void LoadComplete()
{
base.LoadComplete();

Beatmap.BindValueChanged(beatmapChanged, true);

AddSliderStep("editor clock rate", 0.0, 2.0, 1.0, v => frequencyAdjustment.Value = v);
}

private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e)
{
e.OldValue?.Track.RemoveAdjustment(AdjustableProperty.Frequency, frequencyAdjustment);

Clock.Beatmap = e.NewValue.Beatmap;
Clock.ChangeSource(e.NewValue.Track);
Clock.ProcessFrame();

e.NewValue.Track.AddAdjustment(AdjustableProperty.Frequency, frequencyAdjustment);
}

protected override void Update()
Expand Down

0 comments on commit 62266c7

Please sign in to comment.