Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions RhythmGameUtilities/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -101,17 +102,48 @@ public static float InverseLerp(float a, float b, float v)
return UtilitiesInternal.InverseLerp(a, b, v);
}

public static List<int[]> GenerateAdjacentKeyPairs<T>(Dictionary<int, T> dictionary)
public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
bool includeHalfNotes = true)
{
var beatBars = new List<BeatBar>();

var keyValuePairs = GenerateAdjacentKeyPairs(bpmChanges);

foreach (var (startTick, endTick) in keyValuePairs)
{
for (var tick = startTick; tick <= endTick; tick += resolution)
{
beatBars.Add(new BeatBar
{
Position = tick, BPM = bpmChanges[startTick], TimeSignature = new[] { ts }
});

if (includeHalfNotes && tick != endTick)
{
beatBars.Add(new BeatBar
{
Position = tick + resolution / 2,
BPM = bpmChanges[startTick],
TimeSignature = new[] { ts }
});
}
}
}

return beatBars;
}

public static List<Tuple<T, T>> GenerateAdjacentKeyPairs<T>(Dictionary<T, T> dictionary)
{
var keys = dictionary.Keys.ToList();

keys.Sort();

var adjacentKeyPairs = new List<int[]>();
var adjacentKeyPairs = new List<Tuple<T, T>>();

for (var i = 0; i < keys.Count - 1; i += 1)
{
adjacentKeyPairs.Add(new[] { keys[i], keys[i + 1] });
adjacentKeyPairs.Add(new Tuple<T, T>(keys[i], keys[i + 1]));
}

return adjacentKeyPairs;
Expand Down
31 changes: 1 addition & 30 deletions RhythmGameUtilities/Structs/Song.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public List<BeatBar> BeatBars
{
if (_beatBars.Count == 0)
{
_beatBars = CalculateBeatBars(BPM);
_beatBars = Utilities.CalculateBeatBars(BPM);
}

return _beatBars;
Expand Down Expand Up @@ -198,35 +198,6 @@ public int[] GetCurrentTimeSignature(Note note)
return TimeSignatures.Last(item => item.Key <= note.Position).Value;
}

public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpm, int resolution = 192, int ts = 4,
bool includeHalfNotes = true)
{
var newBpm = new List<BeatBar>();

var keyValuePairs = Utilities.GenerateAdjacentKeyPairs(bpm);

foreach (var keys in keyValuePairs)
{
var startTick = keys[0];
var endTick = keys[1];

for (var tick = startTick; tick <= endTick; tick += resolution)
{
newBpm.Add(new BeatBar { Position = tick, BPM = bpm[startTick], TimeSignature = new[] { ts } });

if (includeHalfNotes && tick != endTick)
{
newBpm.Add(new BeatBar
{
Position = tick + resolution / 2, BPM = bpm[keys[0]], TimeSignature = new[] { 4 }
});
}
}
}

return newBpm;
}

}

}
38 changes: 35 additions & 3 deletions UnityPackage/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -101,17 +102,48 @@ public static float InverseLerp(float a, float b, float v)
return UtilitiesInternal.InverseLerp(a, b, v);
}

public static List<int[]> GenerateAdjacentKeyPairs<T>(Dictionary<int, T> dictionary)
public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
bool includeHalfNotes = true)
{
var beatBars = new List<BeatBar>();

var keyValuePairs = GenerateAdjacentKeyPairs(bpmChanges);

foreach (var (startTick, endTick) in keyValuePairs)
{
for (var tick = startTick; tick <= endTick; tick += resolution)
{
beatBars.Add(new BeatBar
{
Position = tick, BPM = bpmChanges[startTick], TimeSignature = new[] { ts }
});

if (includeHalfNotes && tick != endTick)
{
beatBars.Add(new BeatBar
{
Position = tick + resolution / 2,
BPM = bpmChanges[startTick],
TimeSignature = new[] { ts }
});
}
}
}

return beatBars;
}

public static List<Tuple<T, T>> GenerateAdjacentKeyPairs<T>(Dictionary<T, T> dictionary)
{
var keys = dictionary.Keys.ToList();

keys.Sort();

var adjacentKeyPairs = new List<int[]>();
var adjacentKeyPairs = new List<Tuple<T, T>>();

for (var i = 0; i < keys.Count - 1; i += 1)
{
adjacentKeyPairs.Add(new[] { keys[i], keys[i + 1] });
adjacentKeyPairs.Add(new Tuple<T, T>(keys[i], keys[i + 1]));
}

return adjacentKeyPairs;
Expand Down
31 changes: 1 addition & 30 deletions UnityPackage/Structs/Song.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public List<BeatBar> BeatBars
{
if (_beatBars.Count == 0)
{
_beatBars = CalculateBeatBars(BPM);
_beatBars = Utilities.CalculateBeatBars(BPM);
}

return _beatBars;
Expand Down Expand Up @@ -198,35 +198,6 @@ public int[] GetCurrentTimeSignature(Note note)
return TimeSignatures.Last(item => item.Key <= note.Position).Value;
}

public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpm, int resolution = 192, int ts = 4,
bool includeHalfNotes = true)
{
var newBpm = new List<BeatBar>();

var keyValuePairs = Utilities.GenerateAdjacentKeyPairs(bpm);

foreach (var keys in keyValuePairs)
{
var startTick = keys[0];
var endTick = keys[1];

for (var tick = startTick; tick <= endTick; tick += resolution)
{
newBpm.Add(new BeatBar { Position = tick, BPM = bpm[startTick], TimeSignature = new[] { ts } });

if (includeHalfNotes && tick != endTick)
{
newBpm.Add(new BeatBar
{
Position = tick + resolution / 2, BPM = bpm[keys[0]], TimeSignature = new[] { 4 }
});
}
}
}

return newBpm;
}

}

}