using RhythmBase.Exceptions; namespace RhythmBase.Components { /// /// Beat range. /// public struct RDRange { /// /// Start beat. /// public RDBeat? Start { get; } /// /// End beat. /// public RDBeat? End { get; } /// /// Beat interval. /// public readonly float BeatInterval { get { bool flag = Start != null && End != null; float BeatInterval; if (flag) { BeatInterval = End!.Value.BeatOnly - Start!.Value.BeatOnly; } else { BeatInterval = float.PositiveInfinity; } return BeatInterval; } } /// /// Time interval. /// /// public readonly TimeSpan TimeInterval { get { bool flag = Start != null && End != null; TimeSpan TimeInterval; if (flag) { if (Start!.Value.BeatOnly == End!.Value.BeatOnly) { TimeInterval = TimeSpan.Zero; } else { TimeInterval = End.Value.TimeSpan - Start.Value.TimeSpan; } } else { TimeInterval = TimeSpan.MaxValue; } return TimeInterval; } } /// Start beat. /// End beat. public RDRange(RDBeat? start, RDBeat? end) { this = default; if (start != null && end != null && !((RDBeat)start).FromSameLevelOrNull((RDBeat)end)) { throw new RhythmBaseException("RDIndexes must come from the same RDLevel."); } if (start != null && end != null && start > end) { Start = end; End = start; } else { Start = start; End = end; } } /// /// Determines whether the specified beat is within the range. /// /// The beat to check. /// True if the beat is within the range; otherwise, false. public readonly bool Contains(RDBeat b) => (Start == null || Start < b) && (End == null || b < End); } }