1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 04:12:53 +08:00
osu-lazer/osu.Game/Screens/Edit/Compose/Components/BeatDivisorPresetCollection.cs

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

42 lines
1.4 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.
using System;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Screens.Edit.Compose.Components
{
public class BeatDivisorPresetCollection
{
public BeatDivisorType Type { get; }
public IReadOnlyList<int> Presets { get; }
private BeatDivisorPresetCollection(BeatDivisorType type, IEnumerable<int> presets)
{
Type = type;
Presets = presets.ToArray();
}
public static readonly BeatDivisorPresetCollection COMMON = new BeatDivisorPresetCollection(BeatDivisorType.Common, new[] { 1, 2, 4, 8, 16 });
public static readonly BeatDivisorPresetCollection TRIPLETS = new BeatDivisorPresetCollection(BeatDivisorType.Triplets, new[] { 1, 3, 6, 12 });
public static BeatDivisorPresetCollection Custom(int maxDivisor)
{
var presets = new List<int>();
for (int candidate = 1; candidate <= Math.Sqrt(maxDivisor); ++candidate)
{
if (maxDivisor % candidate != 0)
continue;
presets.Add(candidate);
presets.Add(maxDivisor / candidate);
}
return new BeatDivisorPresetCollection(BeatDivisorType.Custom, presets.Distinct().OrderBy(d => d));
}
}
}