2022-05-23 18:52:01 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2023-01-06 08:46:49 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2022-05-23 18:52:01 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Audio;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2022-05-31 15:15:53 +08:00
|
|
|
using osu.Game.Graphics;
|
2022-05-23 18:52:01 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Timing
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
internal partial class WaveformComparisonDisplay : CompositeDrawable
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
|
|
|
private const int total_waveforms = 8;
|
|
|
|
|
2022-05-31 15:15:53 +08:00
|
|
|
private const float corner_radius = LabelledDrawable<Drawable>.CORNER_RADIUS;
|
|
|
|
|
2022-05-23 18:52:01 +08:00
|
|
|
private readonly BindableNumber<double> beatLength = new BindableDouble();
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
|
|
|
|
2022-05-23 20:00:21 +08:00
|
|
|
[Resolved]
|
|
|
|
private EditorBeatmap editorBeatmap { get; set; } = null!;
|
|
|
|
|
2022-05-23 18:52:01 +08:00
|
|
|
[Resolved]
|
2022-05-23 19:01:25 +08:00
|
|
|
private Bindable<ControlPointGroup?> selectedGroup { get; set; } = null!;
|
2022-05-23 18:52:01 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private EditorClock editorClock { get; set; } = null!;
|
|
|
|
|
|
|
|
private TimingControlPoint timingPoint = TimingControlPoint.DEFAULT;
|
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
private double displayedTime;
|
2022-05-23 18:52:01 +08:00
|
|
|
|
2022-05-23 20:00:21 +08:00
|
|
|
private double selectedGroupStartTime;
|
|
|
|
private double selectedGroupEndTime;
|
|
|
|
|
2022-05-25 18:25:23 +08:00
|
|
|
private readonly IBindableList<ControlPointGroup> controlPointGroups = new BindableList<ControlPointGroup>();
|
2022-05-23 19:01:25 +08:00
|
|
|
|
2022-05-31 15:15:53 +08:00
|
|
|
private readonly BindableBool displayLocked = new BindableBool();
|
|
|
|
|
|
|
|
private LockedOverlay lockedOverlay = null!;
|
|
|
|
|
2022-05-23 18:52:01 +08:00
|
|
|
public WaveformComparisonDisplay()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2022-05-31 15:15:53 +08:00
|
|
|
CornerRadius = corner_radius;
|
2022-05-23 18:52:01 +08:00
|
|
|
Masking = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
for (int i = 0; i < total_waveforms; i++)
|
|
|
|
{
|
2022-05-31 17:09:26 +08:00
|
|
|
AddInternal(new WaveformRow(i == total_waveforms / 2)
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
Height = 1f / total_waveforms,
|
|
|
|
Y = (float)i / total_waveforms,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Colour = Color4.White,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = 3,
|
|
|
|
});
|
|
|
|
|
2022-05-31 15:15:53 +08:00
|
|
|
AddInternal(lockedOverlay = new LockedOverlay());
|
|
|
|
|
2022-05-23 20:00:21 +08:00
|
|
|
selectedGroup.BindValueChanged(_ => updateTimingGroup(), true);
|
|
|
|
|
2022-05-25 18:25:23 +08:00
|
|
|
controlPointGroups.BindTo(editorBeatmap.ControlPointInfo.Groups);
|
2022-06-24 20:25:23 +08:00
|
|
|
controlPointGroups.BindCollectionChanged((_, _) => updateTimingGroup());
|
2022-05-23 20:00:21 +08:00
|
|
|
|
2023-10-05 21:55:23 +08:00
|
|
|
beatLength.BindValueChanged(_ => Scheduler.AddOnce(regenerateDisplay, true), true);
|
2022-05-31 15:15:53 +08:00
|
|
|
|
|
|
|
displayLocked.BindValueChanged(locked =>
|
|
|
|
{
|
2022-06-01 15:05:29 +08:00
|
|
|
if (locked.NewValue)
|
|
|
|
lockedOverlay.Show();
|
|
|
|
else
|
|
|
|
lockedOverlay.Hide();
|
2022-05-31 15:15:53 +08:00
|
|
|
}, true);
|
2022-05-23 18:52:01 +08:00
|
|
|
}
|
|
|
|
|
2022-05-23 20:00:21 +08:00
|
|
|
private void updateTimingGroup()
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
|
|
|
beatLength.UnbindBindings();
|
2022-05-23 20:00:21 +08:00
|
|
|
|
|
|
|
var tcp = selectedGroup.Value?.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
|
|
|
|
|
|
|
|
if (tcp == null)
|
|
|
|
{
|
|
|
|
timingPoint = new TimingControlPoint();
|
2022-06-01 15:01:34 +08:00
|
|
|
// During movement of a control point's offset, this clause can be hit momentarily,
|
|
|
|
// as moving a control point is implemented by removing it and inserting it at the new time.
|
2022-05-31 15:59:19 +08:00
|
|
|
// We don't want to reset the `selectedGroupStartTime` here as we rely on having the
|
2022-06-01 15:01:34 +08:00
|
|
|
// last value to update the waveform display below.
|
2022-05-31 15:59:19 +08:00
|
|
|
selectedGroupEndTime = beatmap.Value.Track.Length;
|
2022-05-23 20:00:21 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
timingPoint = tcp;
|
2022-05-23 18:52:01 +08:00
|
|
|
beatLength.BindTo(timingPoint.BeatLengthBindable);
|
2022-05-23 20:00:21 +08:00
|
|
|
|
2022-05-31 15:59:19 +08:00
|
|
|
double? newStartTime = selectedGroup.Value?.Time;
|
2022-05-31 17:17:08 +08:00
|
|
|
double? offsetChange = newStartTime - selectedGroupStartTime;
|
2022-05-23 20:00:21 +08:00
|
|
|
|
|
|
|
var nextGroup = editorBeatmap.ControlPointInfo.TimingPoints
|
2022-06-20 15:53:03 +08:00
|
|
|
.SkipWhile(g => !ReferenceEquals(g, tcp))
|
2022-05-23 20:00:21 +08:00
|
|
|
.Skip(1)
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
2022-05-31 15:59:19 +08:00
|
|
|
selectedGroupStartTime = newStartTime ?? 0;
|
|
|
|
selectedGroupEndTime = nextGroup?.Time ?? beatmap.Value.Track.Length;
|
2022-05-31 17:17:08 +08:00
|
|
|
|
|
|
|
if (newStartTime.HasValue && offsetChange.HasValue)
|
|
|
|
{
|
|
|
|
// The offset of the selected point may have changed.
|
|
|
|
// This handles the case the user has locked the view and expects the display to update with this change.
|
|
|
|
showFromTime(displayedTime + offsetChange.Value, true);
|
|
|
|
}
|
2022-05-23 18:52:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e) => true;
|
|
|
|
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
|
|
|
{
|
2022-05-31 15:32:02 +08:00
|
|
|
if (!displayLocked.Value)
|
|
|
|
{
|
|
|
|
float trackLength = (float)beatmap.Value.Track.Length;
|
2023-01-06 21:35:39 +08:00
|
|
|
int totalBeatsAvailable = (int)((trackLength - timingPoint.Time) / timingPoint.BeatLength);
|
2022-05-23 18:52:01 +08:00
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
Scheduler.AddOnce(showFromBeat, (int)(e.MousePosition.X / DrawWidth * totalBeatsAvailable));
|
|
|
|
}
|
2022-05-23 18:52:01 +08:00
|
|
|
|
|
|
|
return base.OnMouseMove(e);
|
|
|
|
}
|
|
|
|
|
2022-05-31 15:15:53 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
displayLocked.Toggle();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-23 18:52:01 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
if (!IsHovered && !displayLocked.Value)
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
2022-05-24 13:33:05 +08:00
|
|
|
int currentBeat = (int)Math.Floor((editorClock.CurrentTimeAccurate - selectedGroupStartTime) / timingPoint.BeatLength);
|
2022-05-23 18:52:01 +08:00
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
showFromBeat(currentBeat);
|
2022-05-23 18:52:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
private void showFromBeat(int beatIndex) =>
|
2022-05-31 17:05:38 +08:00
|
|
|
showFromTime(selectedGroupStartTime + beatIndex * timingPoint.BeatLength, false);
|
2022-05-31 15:32:02 +08:00
|
|
|
|
2022-05-31 17:05:38 +08:00
|
|
|
private void showFromTime(double time, bool animated)
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
2022-05-31 15:32:02 +08:00
|
|
|
if (displayedTime == time)
|
2022-05-24 13:33:05 +08:00
|
|
|
return;
|
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
displayedTime = time;
|
2023-10-05 21:55:23 +08:00
|
|
|
Scheduler.AddOnce(regenerateDisplay, animated);
|
2022-05-31 15:32:02 +08:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:05:38 +08:00
|
|
|
private void regenerateDisplay(bool animated)
|
2022-05-31 15:32:02 +08:00
|
|
|
{
|
2023-10-05 13:58:50 +08:00
|
|
|
// Before a track is loaded, it won't have a valid length, which will break things.
|
|
|
|
if (!beatmap.Value.Track.IsLoaded)
|
2023-10-05 21:55:23 +08:00
|
|
|
{
|
|
|
|
Scheduler.AddOnce(regenerateDisplay, animated);
|
2023-10-05 13:58:50 +08:00
|
|
|
return;
|
2023-10-05 21:55:23 +08:00
|
|
|
}
|
2023-10-05 13:58:50 +08:00
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
double index = (displayedTime - selectedGroupStartTime) / timingPoint.BeatLength;
|
2022-05-31 15:15:53 +08:00
|
|
|
|
2022-05-24 13:33:05 +08:00
|
|
|
// Chosen as a pretty usable number across all BPMs.
|
|
|
|
// Optimally we'd want this to scale with the BPM in question, but performing
|
|
|
|
// scaling of the display is both expensive in resampling, and decreases usability
|
|
|
|
// (as it is harder to track the waveform when making realtime adjustments).
|
2022-05-23 18:52:01 +08:00
|
|
|
const float visible_width = 300;
|
|
|
|
|
|
|
|
float trackLength = (float)beatmap.Value.Track.Length;
|
|
|
|
float scale = trackLength / visible_width;
|
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
const int start_offset = total_waveforms / 2;
|
|
|
|
|
2022-05-23 20:00:21 +08:00
|
|
|
// Start displaying from before the current beat
|
2022-05-31 15:32:02 +08:00
|
|
|
index -= start_offset;
|
2022-05-23 20:00:21 +08:00
|
|
|
|
2022-05-23 20:32:55 +08:00
|
|
|
foreach (var row in InternalChildren.OfType<WaveformRow>())
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
|
|
|
// offset to the required beat index.
|
2022-05-31 15:32:02 +08:00
|
|
|
double time = selectedGroupStartTime + index * timingPoint.BeatLength;
|
2022-05-23 20:00:21 +08:00
|
|
|
|
2023-12-26 16:44:49 +08:00
|
|
|
float offset = (float)(time - visible_width / 2 + Editor.WAVEFORM_VISUAL_OFFSET) / trackLength * scale;
|
2022-05-23 18:52:01 +08:00
|
|
|
|
2022-05-23 20:32:55 +08:00
|
|
|
row.Alpha = time < selectedGroupStartTime || time > selectedGroupEndTime ? 0.2f : 1;
|
2022-05-31 17:05:38 +08:00
|
|
|
row.WaveformOffsetTo(-offset, animated);
|
2022-05-23 20:32:55 +08:00
|
|
|
row.WaveformScale = new Vector2(scale, 1);
|
2022-05-31 15:32:02 +08:00
|
|
|
row.BeatIndex = (int)Math.Floor(index);
|
2022-05-23 18:52:01 +08:00
|
|
|
|
2022-05-31 15:32:02 +08:00
|
|
|
index++;
|
|
|
|
}
|
2022-05-23 18:52:01 +08:00
|
|
|
}
|
2022-05-23 20:32:55 +08:00
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
internal partial class LockedOverlay : CompositeDrawable
|
2022-05-31 15:15:53 +08:00
|
|
|
{
|
|
|
|
private OsuSpriteText text = null!;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = corner_radius;
|
|
|
|
BorderColour = colours.Red;
|
|
|
|
BorderThickness = 3;
|
|
|
|
Alpha = 0;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
AlwaysPresent = true,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = colours.Red,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
text = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Colour = colours.GrayF,
|
|
|
|
Text = "Locked",
|
|
|
|
Margin = new MarginPadding(5),
|
|
|
|
Shadow = false,
|
|
|
|
Font = OsuFont.Default.With(size: 12, weight: FontWeight.SemiBold),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-01 15:05:29 +08:00
|
|
|
public override void Show()
|
2022-05-31 15:15:53 +08:00
|
|
|
{
|
2022-06-01 15:05:29 +08:00
|
|
|
this.FadeIn(100, Easing.OutQuint);
|
2022-05-31 15:15:53 +08:00
|
|
|
|
|
|
|
text
|
2022-06-01 15:05:29 +08:00
|
|
|
.FadeIn().Then().Delay(600)
|
|
|
|
.FadeOut().Then().Delay(600)
|
2022-05-31 15:15:53 +08:00
|
|
|
.Loop();
|
|
|
|
}
|
2022-06-01 15:05:29 +08:00
|
|
|
|
|
|
|
public override void Hide()
|
|
|
|
{
|
|
|
|
this.FadeOut(100, Easing.OutQuint);
|
|
|
|
}
|
2022-05-31 15:15:53 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
internal partial class WaveformRow : CompositeDrawable
|
2022-05-23 20:32:55 +08:00
|
|
|
{
|
2022-05-31 17:09:26 +08:00
|
|
|
private readonly bool isMainRow;
|
2022-05-23 20:32:55 +08:00
|
|
|
private OsuSpriteText beatIndexText = null!;
|
|
|
|
private WaveformGraph waveformGraph = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
2023-01-06 08:46:49 +08:00
|
|
|
[Resolved]
|
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
|
|
|
|
|
|
|
private readonly IBindable<Track> track = new Bindable<Track>();
|
|
|
|
|
2022-05-31 17:09:26 +08:00
|
|
|
public WaveformRow(bool isMainRow)
|
|
|
|
{
|
|
|
|
this.isMainRow = isMainRow;
|
|
|
|
}
|
|
|
|
|
2022-05-23 20:32:55 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2023-01-06 08:46:49 +08:00
|
|
|
private void load(EditorClock clock)
|
2022-05-23 20:32:55 +08:00
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2022-05-31 17:09:26 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = colourProvider.Background3,
|
|
|
|
Alpha = isMainRow ? 1 : 0,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-05-23 20:32:55 +08:00
|
|
|
waveformGraph = new WaveformGraph
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
Waveform = beatmap.Value.Waveform,
|
|
|
|
Resolution = 1,
|
|
|
|
|
|
|
|
BaseColour = colourProvider.Colour0,
|
|
|
|
LowColour = colourProvider.Colour1,
|
|
|
|
MidColour = colourProvider.Colour2,
|
|
|
|
HighColour = colourProvider.Colour4,
|
|
|
|
},
|
|
|
|
beatIndexText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
Colour = colourProvider.Content2
|
|
|
|
}
|
|
|
|
};
|
2023-01-06 08:46:49 +08:00
|
|
|
|
|
|
|
track.BindTo(clock.Track);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
track.ValueChanged += _ => waveformGraph.Waveform = beatmap.Value.Waveform;
|
2022-05-23 20:32:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public int BeatIndex { set => beatIndexText.Text = value.ToString(); }
|
|
|
|
public Vector2 WaveformScale { set => waveformGraph.Scale = value; }
|
2022-05-31 17:05:38 +08:00
|
|
|
|
|
|
|
public void WaveformOffsetTo(float value, bool animated) =>
|
|
|
|
this.TransformTo(nameof(waveformOffset), value, animated ? 300 : 0, Easing.OutQuint);
|
|
|
|
|
|
|
|
private float waveformOffset
|
|
|
|
{
|
|
|
|
get => waveformGraph.X;
|
|
|
|
set => waveformGraph.X = value;
|
|
|
|
}
|
2022-05-23 20:32:55 +08:00
|
|
|
}
|
2022-05-23 18:52:01 +08:00
|
|
|
}
|
|
|
|
}
|