1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 05:13:21 +08:00

Remove Track access in Timeline

This commit is contained in:
Dean Herbert 2022-08-26 18:25:48 +09:00
parent 4b72e55770
commit cd90536e4b

View File

@ -5,7 +5,6 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -64,8 +63,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
/// </summary> /// </summary>
private bool trackWasPlaying; private bool trackWasPlaying;
private Track track;
/// <summary> /// <summary>
/// The timeline zoom level at a 1x zoom scale. /// The timeline zoom level at a 1x zoom scale.
/// </summary> /// </summary>
@ -93,6 +90,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private Bindable<float> waveformOpacity; private Bindable<float> waveformOpacity;
private double trackLengthForZoom;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours, OsuConfigManager config) private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours, OsuConfigManager config)
{ {
@ -144,9 +143,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Beatmap.BindValueChanged(b => Beatmap.BindValueChanged(b =>
{ {
waveform.Waveform = b.NewValue.Waveform; waveform.Waveform = b.NewValue.Waveform;
track = b.NewValue.Track;
setupTimelineZoom();
}, true); }, true);
Zoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom); Zoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom);
@ -185,8 +181,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private void updateWaveformOpacity() => private void updateWaveformOpacity() =>
waveform.FadeTo(WaveformVisible.Value ? waveformOpacity.Value : 0, 200, Easing.OutQuint); waveform.FadeTo(WaveformVisible.Value ? waveformOpacity.Value : 0, 200, Easing.OutQuint);
private float getZoomLevelForVisibleMilliseconds(double milliseconds) => Math.Max(1, (float)(track.Length / milliseconds));
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
@ -197,20 +191,21 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
// This needs to happen after transforms are updated, but before the scroll position is updated in base.UpdateAfterChildren // This needs to happen after transforms are updated, but before the scroll position is updated in base.UpdateAfterChildren
if (editorClock.IsRunning) if (editorClock.IsRunning)
scrollToTrackTime(); scrollToTrackTime();
}
private void setupTimelineZoom() if (editorClock.TrackLength != trackLengthForZoom)
{ {
if (!track.IsLoaded)
{
Scheduler.AddOnce(setupTimelineZoom);
return;
}
defaultTimelineZoom = getZoomLevelForVisibleMilliseconds(6000); defaultTimelineZoom = getZoomLevelForVisibleMilliseconds(6000);
float initialZoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom); float initialZoom = (float)(defaultTimelineZoom * editorBeatmap.BeatmapInfo.TimelineZoom);
SetupZoom(initialZoom, getZoomLevelForVisibleMilliseconds(10000), getZoomLevelForVisibleMilliseconds(500)); float minimumZoom = getZoomLevelForVisibleMilliseconds(10000);
float maximumZoom = getZoomLevelForVisibleMilliseconds(500);
SetupZoom(initialZoom, minimumZoom, maximumZoom);
float getZoomLevelForVisibleMilliseconds(double milliseconds) => Math.Max(1, (float)(editorClock.TrackLength / milliseconds));
trackLengthForZoom = editorClock.TrackLength;
}
} }
protected override bool OnScroll(ScrollEvent e) protected override bool OnScroll(ScrollEvent e)
@ -255,16 +250,13 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private void seekTrackToCurrent() private void seekTrackToCurrent()
{ {
if (!track.IsLoaded) double target = Current / Content.DrawWidth * editorClock.TrackLength;
return; editorClock.Seek(Math.Min(editorClock.TrackLength, target));
double target = Current / Content.DrawWidth * track.Length;
editorClock.Seek(Math.Min(track.Length, target));
} }
private void scrollToTrackTime() private void scrollToTrackTime()
{ {
if (!track.IsLoaded || track.Length == 0) if (editorClock.TrackLength == 0)
return; return;
// covers the case where the user starts playback after a drag is in progress. // covers the case where the user starts playback after a drag is in progress.
@ -272,7 +264,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
if (handlingDragInput) if (handlingDragInput)
editorClock.Stop(); editorClock.Stop();
ScrollTo((float)(editorClock.CurrentTime / track.Length) * Content.DrawWidth, false); ScrollTo((float)(editorClock.CurrentTime / editorClock.TrackLength) * Content.DrawWidth, false);
} }
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
@ -310,12 +302,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
/// <summary> /// <summary>
/// The total amount of time visible on the timeline. /// The total amount of time visible on the timeline.
/// </summary> /// </summary>
public double VisibleRange => track.Length / Zoom; public double VisibleRange => editorClock.TrackLength / Zoom;
public SnapResult FindSnappedPositionAndTime(Vector2 screenSpacePosition, SnapType snapType = SnapType.All) => public SnapResult FindSnappedPositionAndTime(Vector2 screenSpacePosition, SnapType snapType = SnapType.All) =>
new SnapResult(screenSpacePosition, beatSnapProvider.SnapTime(getTimeFromPosition(Content.ToLocalSpace(screenSpacePosition)))); new SnapResult(screenSpacePosition, beatSnapProvider.SnapTime(getTimeFromPosition(Content.ToLocalSpace(screenSpacePosition))));
private double getTimeFromPosition(Vector2 localPosition) => private double getTimeFromPosition(Vector2 localPosition) =>
(localPosition.X / Content.DrawWidth) * track.Length; (localPosition.X / Content.DrawWidth) * editorClock.TrackLength;
} }
} }