1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 06:42:54 +08:00
osu-lazer/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

145 lines
5.3 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-20 13:56:04 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Utils;
using osu.Game.Beatmaps.Timing;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Beatmaps.ControlPoints
{
2022-06-20 13:56:04 +08:00
public class TimingControlPoint : ControlPoint, IEquatable<TimingControlPoint>
{
2017-05-23 13:11:37 +08:00
/// <summary>
/// The time signature at this control point.
/// </summary>
public readonly Bindable<TimeSignature> TimeSignatureBindable = new Bindable<TimeSignature>(TimeSignature.SimpleQuadruple);
/// <summary>
/// Whether the first bar line of this control point is ignored.
/// </summary>
public readonly BindableBool OmitFirstBarLineBindable = new BindableBool();
/// <summary>
/// Default length of a beat in milliseconds. Used whenever there is no beatmap or track playing.
/// </summary>
private const double default_beat_length = 60000.0 / 60.0;
2021-04-14 18:39:27 +08:00
public override Color4 GetRepresentingColour(OsuColour colours) => colours.Orange1;
public static readonly TimingControlPoint DEFAULT = new TimingControlPoint
{
2020-07-18 11:03:49 +08:00
BeatLengthBindable =
{
Value = default_beat_length,
Disabled = true
},
OmitFirstBarLineBindable = { Disabled = true },
TimeSignatureBindable = { Disabled = true }
};
/// <summary>
/// The time signature at this control point.
/// </summary>
public TimeSignature TimeSignature
{
get => TimeSignatureBindable.Value;
set => TimeSignatureBindable.Value = value;
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// Whether the first bar line of this control point is ignored.
/// </summary>
public bool OmitFirstBarLine
{
get => OmitFirstBarLineBindable.Value;
set => OmitFirstBarLineBindable.Value = value;
}
public const double DEFAULT_BEAT_LENGTH = 1000;
2017-05-23 13:11:37 +08:00
/// <summary>
/// The beat length at this control point.
/// </summary>
public readonly BindableDouble BeatLengthBindable = new BindableDouble(DEFAULT_BEAT_LENGTH)
{
MinValue = 6,
MaxValue = 60000
};
2018-04-13 17:19:50 +08:00
2019-10-30 17:44:07 +08:00
/// <summary>
/// The beat length at this control point.
/// </summary>
public double BeatLength
{
get => BeatLengthBindable.Value;
set => BeatLengthBindable.Value = value;
}
2018-04-13 17:19:50 +08:00
2019-10-28 11:31:38 +08:00
/// <summary>
/// The BPM at this control point.
/// </summary>
public double BPM => 60000 / BeatLength;
2020-04-17 16:04:09 +08:00
// Timing points are never redundant as they can change the time signature.
2022-06-20 15:52:01 +08:00
public override bool IsRedundant(ControlPoint? existing) => false;
public override void CopyFrom(ControlPoint other)
{
TimeSignature = ((TimingControlPoint)other).TimeSignature;
OmitFirstBarLine = ((TimingControlPoint)other).OmitFirstBarLine;
BeatLength = ((TimingControlPoint)other).BeatLength;
base.CopyFrom(other);
}
2022-06-20 13:56:04 +08:00
public override bool Equals(ControlPoint? other)
=> other is TimingControlPoint otherTimingControlPoint
&& Equals(otherTimingControlPoint);
public bool Equals(TimingControlPoint? other)
=> base.Equals(other)
&& TimeSignature.Equals(other.TimeSignature)
&& OmitFirstBarLine == other.OmitFirstBarLine
2022-06-20 13:56:04 +08:00
&& BeatLength.Equals(other.BeatLength);
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), TimeSignature, BeatLength, OmitFirstBarLine);
public List<HitObject> HitObjectsInTimingRange(IBeatmap beatmap)
{
// If the first group, we grab all hitobjects prior to the next, if the last group, we grab all remaining hitobjects
double startTime = beatmap.ControlPointInfo.TimingPoints.Any(x => x.Time < Time) ? Time : double.MinValue;
double endTime = beatmap.ControlPointInfo.TimingPoints.FirstOrDefault(x => x.Time > Time)?.Time ?? double.MaxValue;
return beatmap.HitObjects.Where(x => Precision.AlmostBigger(x.StartTime, startTime) && Precision.DefinitelyBigger(endTime, x.StartTime)).ToList();
}
public void AdjustHitObjectOffset(IBeatmap beatmap, double adjust)
{
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap))
{
hitObject.StartTime += adjust;
}
}
2024-06-09 17:27:53 +08:00
public void SetHitObjectBPM(IBeatmap beatmap, double oldBeatLength)
{
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap))
{
2024-06-09 17:27:53 +08:00
double beat = (hitObject.StartTime - Time) / oldBeatLength;
2024-06-09 17:27:53 +08:00
hitObject.StartTime = (beat * BeatLength) + Time;
if (hitObject is not IHasRepeats && hitObject is IHasDuration hitObjectWithDuration)
2024-06-09 17:27:53 +08:00
hitObjectWithDuration.Duration *= BeatLength / oldBeatLength;
}
}
}
2018-01-05 19:21:19 +08:00
}