From 4aa6b0e97a3a71180654c8f2f20432f30631e671 Mon Sep 17 00:00:00 2001 From: Scott Doxey Date: Tue, 21 Jan 2025 14:01:38 -0500 Subject: [PATCH 1/2] Simplified bpm data structure. --- RhythmGameUtilities.Tests/UtilitiesTest.cs | 26 +++++------- RhythmGameUtilities/Scripts/Utilities.cs | 21 +++++----- RhythmGameUtilities/Structs/Tempo.cs | 16 ++++++++ UnityPackage/Editor/Tests/UtilitiesTest.cs | 26 +++++------- UnityPackage/Scripts/Utilities.cs | 21 +++++----- UnityPackage/Structs/Tempo.cs | 16 ++++++++ include/RhythmGameUtilities/Parsers.hpp | 18 ++++---- include/RhythmGameUtilities/Structs/Tempo.h | 13 ++++++ include/RhythmGameUtilities/Utilities.hpp | 29 +++++++++---- .../RhythmGameUtilities/UtilitiesInternal.hpp | 41 +++++++++---------- tests/RhythmGameUtilities/Utilities.cpp | 9 ++-- .../RhythmGameUtilities/UtilitiesInternal.cpp | 35 ++++------------ 12 files changed, 150 insertions(+), 121 deletions(-) create mode 100644 RhythmGameUtilities/Structs/Tempo.cs create mode 100644 UnityPackage/Structs/Tempo.cs create mode 100644 include/RhythmGameUtilities/Structs/Tempo.h diff --git a/RhythmGameUtilities.Tests/UtilitiesTest.cs b/RhythmGameUtilities.Tests/UtilitiesTest.cs index 1248f85..6bf5b7b 100644 --- a/RhythmGameUtilities.Tests/UtilitiesTest.cs +++ b/RhythmGameUtilities.Tests/UtilitiesTest.cs @@ -22,15 +22,12 @@ public void TestConvertSecondsToTicks() const int seconds = 5; const int resolution = 192; - var bpmChanges = new Dictionary + var bpmChanges = new[] { - { 0, 88000 }, - { 3840, 112000 }, - { 9984, 89600 }, - { 22272, 112000 }, - { 33792, 111500 }, - { 34560, 112000 }, - { 42240, 111980 } + new Tempo { Position = 0, BPM = 88000 }, new Tempo { Position = 3840, BPM = 112000 }, + new Tempo { Position = 9984, BPM = 89600 }, new Tempo { Position = 22272, BPM = 112000 }, + new Tempo { Position = 33792, BPM = 111500 }, new Tempo { Position = 34560, BPM = 112000 }, + new Tempo { Position = 42240, BPM = 111980 } }; var timeSignatureChanges = new[] { new TimeSignature { Position = 0, Numerator = 4, Denominator = 2 } }; @@ -60,15 +57,12 @@ public void TestCalculateBeatBars() const int resolution = 192; const int timeSignature = 4; - var bpmChanges = new Dictionary + var bpmChanges = new Tempo[] { - { 0, 88000 }, - { 3840, 112000 }, - { 9984, 89600 }, - { 22272, 112000 }, - { 33792, 111500 }, - { 34560, 112000 }, - { 42240, 111980 } + new() { Position = 0, BPM = 88000 }, new() { Position = 3840, BPM = 112000 }, + new() { Position = 9984, BPM = 89600 }, new() { Position = 22272, BPM = 112000 }, + new() { Position = 33792, BPM = 111500 }, new() { Position = 34560, BPM = 112000 }, + new() { Position = 42240, BPM = 111980 } }; var beatBars = Utilities.CalculateBeatBars(bpmChanges, resolution, timeSignature, true); diff --git a/RhythmGameUtilities/Scripts/Utilities.cs b/RhythmGameUtilities/Scripts/Utilities.cs index a2674b2..d93127d 100644 --- a/RhythmGameUtilities/Scripts/Utilities.cs +++ b/RhythmGameUtilities/Scripts/Utilities.cs @@ -13,8 +13,8 @@ internal static class UtilitiesInternal public static extern float ConvertTickToPosition(int tick, int resolution); [DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)] - public static extern int ConvertSecondsToTicksInternal(float seconds, int resolution, int[] bpmChangesKeys, - int[] bpmChangesValues, int bpmChangesSize, TimeSignature[] timeSignatures, int timeSignaturesSize); + public static extern int ConvertSecondsToTicksInternal(float seconds, int resolution, Tempo[] bpmChanges, + int bpmChangesSize, TimeSignature[] timeSignatures, int timeSignaturesSize); [DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)] public static extern bool IsOnTheBeat(int bpm, float currentTime, float delta); @@ -26,8 +26,8 @@ public static extern int ConvertSecondsToTicksInternal(float seconds, int resolu public static extern float CalculateAccuracyRatio(int position, int currentPosition, int delta); [DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CalculateBeatBarsInternal(int[] bpmChangesKeys, - int[] bpmChangesValues, int bpmChangesSize, int resolution, int ts, + public static extern IntPtr CalculateBeatBarsInternal(Tempo[] bpmChanges, int bpmChangesSize, int resolution, + int ts, bool includeHalfNotes, out int size); } @@ -56,11 +56,11 @@ public static float ConvertTickToPosition(int tick, int resolution) /// The resolution of the song. /// All BPM changes within the song. /// All time signature changes within the song. - public static int ConvertSecondsToTicks(float seconds, int resolution, Dictionary bpmChanges, + public static int ConvertSecondsToTicks(float seconds, int resolution, Tempo[] bpmChanges, TimeSignature[] timeSignatureChanges) { - return UtilitiesInternal.ConvertSecondsToTicksInternal(seconds, resolution, bpmChanges.Keys.ToArray(), - bpmChanges.Values.ToArray(), bpmChanges.Count, timeSignatureChanges, timeSignatureChanges.Length); + return UtilitiesInternal.ConvertSecondsToTicksInternal(seconds, resolution, bpmChanges, bpmChanges.Length, + timeSignatureChanges, timeSignatureChanges.Length); } /// @@ -86,12 +86,11 @@ public static int RoundUpToTheNearestMultiplier(int value, int multiplier) return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier); } - public static BeatBar[] CalculateBeatBars(Dictionary bpmChanges, int resolution = 192, int ts = 4, + public static BeatBar[] CalculateBeatBars(Tempo[] bpmChanges, int resolution = 192, int ts = 4, bool includeHalfNotes = true) { - - var ptrArray = UtilitiesInternal.CalculateBeatBarsInternal(bpmChanges.Keys.ToArray(), - bpmChanges.Values.ToArray(), bpmChanges.Count, resolution, ts, includeHalfNotes, + var ptrArray = UtilitiesInternal.CalculateBeatBarsInternal(bpmChanges, bpmChanges.Length, resolution, ts, + includeHalfNotes, out var size); var beatBarSize = Marshal.SizeOf(typeof(BeatBar)); diff --git a/RhythmGameUtilities/Structs/Tempo.cs b/RhythmGameUtilities/Structs/Tempo.cs new file mode 100644 index 0000000..7fdaea2 --- /dev/null +++ b/RhythmGameUtilities/Structs/Tempo.cs @@ -0,0 +1,16 @@ +using System.Runtime.InteropServices; + +namespace RhythmGameUtilities +{ + + [StructLayout(LayoutKind.Sequential)] + public struct Tempo + { + + public int Position; + + public int BPM; + + } + +} diff --git a/UnityPackage/Editor/Tests/UtilitiesTest.cs b/UnityPackage/Editor/Tests/UtilitiesTest.cs index 1248f85..6bf5b7b 100644 --- a/UnityPackage/Editor/Tests/UtilitiesTest.cs +++ b/UnityPackage/Editor/Tests/UtilitiesTest.cs @@ -22,15 +22,12 @@ public void TestConvertSecondsToTicks() const int seconds = 5; const int resolution = 192; - var bpmChanges = new Dictionary + var bpmChanges = new[] { - { 0, 88000 }, - { 3840, 112000 }, - { 9984, 89600 }, - { 22272, 112000 }, - { 33792, 111500 }, - { 34560, 112000 }, - { 42240, 111980 } + new Tempo { Position = 0, BPM = 88000 }, new Tempo { Position = 3840, BPM = 112000 }, + new Tempo { Position = 9984, BPM = 89600 }, new Tempo { Position = 22272, BPM = 112000 }, + new Tempo { Position = 33792, BPM = 111500 }, new Tempo { Position = 34560, BPM = 112000 }, + new Tempo { Position = 42240, BPM = 111980 } }; var timeSignatureChanges = new[] { new TimeSignature { Position = 0, Numerator = 4, Denominator = 2 } }; @@ -60,15 +57,12 @@ public void TestCalculateBeatBars() const int resolution = 192; const int timeSignature = 4; - var bpmChanges = new Dictionary + var bpmChanges = new Tempo[] { - { 0, 88000 }, - { 3840, 112000 }, - { 9984, 89600 }, - { 22272, 112000 }, - { 33792, 111500 }, - { 34560, 112000 }, - { 42240, 111980 } + new() { Position = 0, BPM = 88000 }, new() { Position = 3840, BPM = 112000 }, + new() { Position = 9984, BPM = 89600 }, new() { Position = 22272, BPM = 112000 }, + new() { Position = 33792, BPM = 111500 }, new() { Position = 34560, BPM = 112000 }, + new() { Position = 42240, BPM = 111980 } }; var beatBars = Utilities.CalculateBeatBars(bpmChanges, resolution, timeSignature, true); diff --git a/UnityPackage/Scripts/Utilities.cs b/UnityPackage/Scripts/Utilities.cs index a2674b2..d93127d 100644 --- a/UnityPackage/Scripts/Utilities.cs +++ b/UnityPackage/Scripts/Utilities.cs @@ -13,8 +13,8 @@ internal static class UtilitiesInternal public static extern float ConvertTickToPosition(int tick, int resolution); [DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)] - public static extern int ConvertSecondsToTicksInternal(float seconds, int resolution, int[] bpmChangesKeys, - int[] bpmChangesValues, int bpmChangesSize, TimeSignature[] timeSignatures, int timeSignaturesSize); + public static extern int ConvertSecondsToTicksInternal(float seconds, int resolution, Tempo[] bpmChanges, + int bpmChangesSize, TimeSignature[] timeSignatures, int timeSignaturesSize); [DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)] public static extern bool IsOnTheBeat(int bpm, float currentTime, float delta); @@ -26,8 +26,8 @@ public static extern int ConvertSecondsToTicksInternal(float seconds, int resolu public static extern float CalculateAccuracyRatio(int position, int currentPosition, int delta); [DllImport("libRhythmGameUtilities", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CalculateBeatBarsInternal(int[] bpmChangesKeys, - int[] bpmChangesValues, int bpmChangesSize, int resolution, int ts, + public static extern IntPtr CalculateBeatBarsInternal(Tempo[] bpmChanges, int bpmChangesSize, int resolution, + int ts, bool includeHalfNotes, out int size); } @@ -56,11 +56,11 @@ public static float ConvertTickToPosition(int tick, int resolution) /// The resolution of the song. /// All BPM changes within the song. /// All time signature changes within the song. - public static int ConvertSecondsToTicks(float seconds, int resolution, Dictionary bpmChanges, + public static int ConvertSecondsToTicks(float seconds, int resolution, Tempo[] bpmChanges, TimeSignature[] timeSignatureChanges) { - return UtilitiesInternal.ConvertSecondsToTicksInternal(seconds, resolution, bpmChanges.Keys.ToArray(), - bpmChanges.Values.ToArray(), bpmChanges.Count, timeSignatureChanges, timeSignatureChanges.Length); + return UtilitiesInternal.ConvertSecondsToTicksInternal(seconds, resolution, bpmChanges, bpmChanges.Length, + timeSignatureChanges, timeSignatureChanges.Length); } /// @@ -86,12 +86,11 @@ public static int RoundUpToTheNearestMultiplier(int value, int multiplier) return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier); } - public static BeatBar[] CalculateBeatBars(Dictionary bpmChanges, int resolution = 192, int ts = 4, + public static BeatBar[] CalculateBeatBars(Tempo[] bpmChanges, int resolution = 192, int ts = 4, bool includeHalfNotes = true) { - - var ptrArray = UtilitiesInternal.CalculateBeatBarsInternal(bpmChanges.Keys.ToArray(), - bpmChanges.Values.ToArray(), bpmChanges.Count, resolution, ts, includeHalfNotes, + var ptrArray = UtilitiesInternal.CalculateBeatBarsInternal(bpmChanges, bpmChanges.Length, resolution, ts, + includeHalfNotes, out var size); var beatBarSize = Marshal.SizeOf(typeof(BeatBar)); diff --git a/UnityPackage/Structs/Tempo.cs b/UnityPackage/Structs/Tempo.cs new file mode 100644 index 0000000..7fdaea2 --- /dev/null +++ b/UnityPackage/Structs/Tempo.cs @@ -0,0 +1,16 @@ +using System.Runtime.InteropServices; + +namespace RhythmGameUtilities +{ + + [StructLayout(LayoutKind.Sequential)] + public struct Tempo + { + + public int Position; + + public int BPM; + + } + +} diff --git a/include/RhythmGameUtilities/Parsers.hpp b/include/RhythmGameUtilities/Parsers.hpp index 5ee41dd..bafdf2f 100644 --- a/include/RhythmGameUtilities/Parsers.hpp +++ b/include/RhythmGameUtilities/Parsers.hpp @@ -10,6 +10,7 @@ #include "Enums/TypeCode.h" #include "Structs/Note.h" +#include "Structs/Tempo.h" #include "Structs/TimeSignature.h" #include "Common.hpp" @@ -108,7 +109,7 @@ std::map ParseMetaDataFromChartSection( std::vector ParseTimeSignaturesFromChartSection( std::vector>> section) { - auto timeSignatures = std::vector(); + auto timeSignaturesChanges = std::vector(); for (auto &line : section) { @@ -119,27 +120,30 @@ std::vector ParseTimeSignaturesFromChartSection( auto denominator = line.second.size() > 2 ? std::stoi(line.second.at(2)) : 2; - timeSignatures.push_back({position, numerator, denominator}); + timeSignaturesChanges.push_back({position, numerator, denominator}); } } - return timeSignatures; + return timeSignaturesChanges; } -std::map ParseBpmFromChartSection( +std::vector ParseBpmFromChartSection( std::vector>> section) { - auto bpm = std::map(); + auto bpmChanges = std::vector(); for (auto &line : section) { if (line.second.front() == ToString(TypeCode::BPM_Marker)) { - bpm.insert({std::stoi(line.first), std::stoi(line.second.at(1))}); + auto position = std::stoi(line.first); + auto bpm = std::stoi(line.second.at(1)); + + bpmChanges.push_back({position, bpm}); } } - return bpm; + return bpmChanges; } std::vector ParseNotesFromChartSection( diff --git a/include/RhythmGameUtilities/Structs/Tempo.h b/include/RhythmGameUtilities/Structs/Tempo.h new file mode 100644 index 0000000..6b21171 --- /dev/null +++ b/include/RhythmGameUtilities/Structs/Tempo.h @@ -0,0 +1,13 @@ +#pragma once + +namespace RhythmGameUtilities +{ + +struct Tempo +{ + int Position; + + int BPM; +}; + +} // namespace RhythmGameUtilities diff --git a/include/RhythmGameUtilities/Utilities.hpp b/include/RhythmGameUtilities/Utilities.hpp index fc5060f..74d3d13 100644 --- a/include/RhythmGameUtilities/Utilities.hpp +++ b/include/RhythmGameUtilities/Utilities.hpp @@ -8,6 +8,7 @@ #include "Structs/BeatBar.h" #include "Structs/Note.h" +#include "Structs/Tempo.h" #include "Structs/TimeSignature.h" #include "Common.hpp" @@ -34,7 +35,7 @@ const float SECONDS_PER_MINUTE = 60.0f; */ int ConvertSecondsToTicks(float seconds, int resolution, - std::map bpmChanges, + std::vector bpmChanges, std::vector timeSignatureChanges) { auto bpmIterator = bpmChanges.begin(); @@ -43,13 +44,13 @@ int ConvertSecondsToTicks(float seconds, int resolution, auto totalTicks = 0; auto remainingSeconds = seconds; auto previousTick = 0; - auto previousBPM = bpmIterator->second / 1000.0; + auto previousBPM = bpmIterator->BPM / 1000.0; auto previousTimeSignature = timeSignatureIterator->Numerator; while (remainingSeconds > 0) { int nextBPMChange = - bpmIterator != bpmChanges.end() ? bpmIterator->first : INT_MAX; + bpmIterator != bpmChanges.end() ? bpmIterator->Position : INT_MAX; int nextTimeSignatureChange = timeSignatureIterator != timeSignatureChanges.end() @@ -74,7 +75,7 @@ int ConvertSecondsToTicks(float seconds, int resolution, if (nextChangeTick == nextBPMChange) { - previousBPM = bpmIterator->second / 1000.0; + previousBPM = bpmIterator->BPM / 1000.0; ++bpmIterator; } @@ -122,13 +123,20 @@ GenerateAdjacentKeyPairs(std::map keyValuePairs) return adjacentKeyPairs; } -std::vector CalculateBeatBars(std::map bpmChanges, +std::vector CalculateBeatBars(std::vector bpmChanges, int resolution, int ts, bool includeHalfNotes) { std::vector beatBars; - auto keyValuePairs = GenerateAdjacentKeyPairs(bpmChanges); + std::map bpmChangePositions; + + for (const auto &bpmChange : bpmChanges) + { + bpmChangePositions[bpmChange.Position] = bpmChange.BPM; + } + + auto keyValuePairs = GenerateAdjacentKeyPairs(bpmChangePositions); for (const auto &keyValuePair : keyValuePairs) { @@ -137,12 +145,15 @@ std::vector CalculateBeatBars(std::map bpmChanges, for (auto tick = startTick; tick < endTick; tick += resolution) { - beatBars.push_back({tick, bpmChanges[startTick]}); + + auto position = tick; + auto bpm = bpmChangePositions[startTick]; + + beatBars.push_back({tick, bpm}); if (includeHalfNotes && tick != endTick) { - beatBars.push_back( - {tick + resolution / 2, bpmChanges[startTick]}); + beatBars.push_back({tick + resolution / 2, bpm}); } } } diff --git a/include/RhythmGameUtilities/UtilitiesInternal.hpp b/include/RhythmGameUtilities/UtilitiesInternal.hpp index 50aa4b8..037b6c5 100644 --- a/include/RhythmGameUtilities/UtilitiesInternal.hpp +++ b/include/RhythmGameUtilities/UtilitiesInternal.hpp @@ -3,6 +3,7 @@ #include #include "Structs/BeatBar.h" +#include "Structs/Tempo.h" #include "Structs/TimeSignature.h" #include "Utilities.hpp" @@ -18,45 +19,43 @@ namespace RhythmGameUtilities extern "C" { - PACKAGE_API int ConvertSecondsToTicksInternal(float seconds, int resolution, - int *bpmChangesKeys, - int *bpmChangesValues, - int bpmChangesSize, - TimeSignature *timeSignatures, - int timeSignaturesSize) + PACKAGE_API int ConvertSecondsToTicksInternal( + float seconds, int resolution, Tempo *bpmChanges, int bpmChangesSize, + TimeSignature *timeSignaturesChanges, int timeSignaturesChangesSize) { - std::map bpmChanges; + std::vector bpmChangesVector; for (auto i = 0; i < bpmChangesSize; i += 1) { - bpmChanges[bpmChangesKeys[i]] = bpmChangesValues[i]; + bpmChangesVector.push_back(bpmChanges[i]); } - std::vector timeSignatureChanges; + std::vector timeSignatureChangesVector; - for (auto i = 0; i < timeSignaturesSize; i += 1) + for (auto i = 0; i < timeSignaturesChangesSize; i += 1) { - timeSignatureChanges.push_back(timeSignatures[i]); + timeSignatureChangesVector.push_back(timeSignaturesChanges[i]); } - return ConvertSecondsToTicks(seconds, resolution, bpmChanges, - timeSignatureChanges); + return ConvertSecondsToTicks(seconds, resolution, bpmChangesVector, + timeSignatureChangesVector); } - PACKAGE_API BeatBar * - CalculateBeatBarsInternal(int *bpmChangesKeys, int *bpmChangesValues, - int bpmChangesSize, int resolution, int ts, - bool includeHalfNotes, int *outSize) + PACKAGE_API BeatBar *CalculateBeatBarsInternal(Tempo *bpmChanges, + int bpmChangesSize, + int resolution, int ts, + bool includeHalfNotes, + int *outSize) { - auto bpmChanges = std::map(); + std::vector bpmChangesVector; for (auto i = 0; i < bpmChangesSize; i += 1) { - bpmChanges[bpmChangesKeys[i]] = bpmChangesValues[i]; + bpmChangesVector.push_back(bpmChanges[i]); } - auto internalBeatBars = - CalculateBeatBars(bpmChanges, resolution, ts, includeHalfNotes); + auto internalBeatBars = CalculateBeatBars(bpmChangesVector, resolution, + ts, includeHalfNotes); *outSize = internalBeatBars.size(); diff --git a/tests/RhythmGameUtilities/Utilities.cpp b/tests/RhythmGameUtilities/Utilities.cpp index 64dd5f1..807a10d 100644 --- a/tests/RhythmGameUtilities/Utilities.cpp +++ b/tests/RhythmGameUtilities/Utilities.cpp @@ -3,6 +3,7 @@ #include #include +#include "RhythmGameUtilities/Structs/Tempo.h" #include "RhythmGameUtilities/Structs/TimeSignature.h" #include "RhythmGameUtilities/Utilities.hpp" @@ -18,7 +19,7 @@ void testConvertTickToPosition() void testConvertSecondsToTicks() { - std::map bpmChanges = { + std::vector bpmChanges = { {0, 88000}, {3840, 112000}, {9984, 89600}, {22272, 112000}, {33792, 111500}, {34560, 112000}, {42240, 111980}}; @@ -72,11 +73,11 @@ void testRoundUpToTheNearestMultiplier() void testGenerateAdjacentKeyPairs() { - std::map bpmChanges = { + std::map bpmChangePositions = { {0, 88000}, {3840, 112000}, {9984, 89600}, {22272, 112000}, {33792, 111500}, {34560, 112000}, {42240, 111980}}; - auto adjacentKeyPairs = GenerateAdjacentKeyPairs(bpmChanges); + auto adjacentKeyPairs = GenerateAdjacentKeyPairs(bpmChangePositions); assert(adjacentKeyPairs.size() == 6); assert(adjacentKeyPairs[0] == std::make_tuple(0, 3840)); @@ -87,7 +88,7 @@ void testGenerateAdjacentKeyPairs() void testCalculateBeatBars() { - std::map bpmChanges = { + std::vector bpmChanges = { {0, 88000}, {3840, 112000}, {9984, 89600}, {22272, 112000}, {33792, 111500}, {34560, 112000}, {42240, 111980}}; diff --git a/tests/RhythmGameUtilities/UtilitiesInternal.cpp b/tests/RhythmGameUtilities/UtilitiesInternal.cpp index a309aa9..a9d6cf5 100644 --- a/tests/RhythmGameUtilities/UtilitiesInternal.cpp +++ b/tests/RhythmGameUtilities/UtilitiesInternal.cpp @@ -3,55 +3,38 @@ #include #include +#include "RhythmGameUtilities/Structs/Tempo.h" +#include "RhythmGameUtilities/Structs/TimeSignature.h" + #include "RhythmGameUtilities/UtilitiesInternal.hpp" using namespace RhythmGameUtilities; void testConvertSecondsToTicksInternal() { - std::map bpmChanges = { + std::vector bpmChanges = { {0, 88000}, {3840, 112000}, {9984, 89600}, {22272, 112000}, {33792, 111500}, {34560, 112000}, {42240, 111980}}; std::vector timeSignatureChanges = {{0, 4, 2}}; - std::vector bpmChangesKeys; - std::vector bpmChangesValues; - - for (const auto &[key, value] : bpmChanges) - { - bpmChangesKeys.push_back(key); - bpmChangesValues.push_back(value); - } - assert(1408 == ConvertSecondsToTicksInternal( - 5, 192, &bpmChangesKeys[0], &bpmChangesValues[0], - bpmChanges.size(), &timeSignatureChanges[0], - timeSignatureChanges.size())); + 5, 192, &bpmChanges[0], bpmChanges.size(), + &timeSignatureChanges[0], timeSignatureChanges.size())); std::cout << "."; } void testCalculateBeatBarsInternal() { - std::map bpmChanges = { + std::vector bpmChanges = { {0, 88000}, {3840, 112000}, {9984, 89600}, {22272, 112000}, {33792, 111500}, {34560, 112000}, {42240, 111980}}; - std::vector bpmChangesKeys; - std::vector bpmChangesValues; - - for (const auto &[key, value] : bpmChanges) - { - bpmChangesKeys.push_back(key); - bpmChangesValues.push_back(value); - } - int *outSize; - auto beatBars = - CalculateBeatBarsInternal(&bpmChangesKeys[0], &bpmChangesValues[0], - bpmChanges.size(), 192, 4, true, outSize); + auto beatBars = CalculateBeatBarsInternal(&bpmChanges[0], bpmChanges.size(), + 192, 4, true, outSize); assert(*outSize == 440); From b7d7e67bcd42294f32d177fb33f3de5d26382132 Mon Sep 17 00:00:00 2001 From: Scott Doxey Date: Thu, 23 Jan 2025 23:55:44 -0500 Subject: [PATCH 2/2] Renamed variable. --- tests/RhythmGameUtilities/Utilities.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/RhythmGameUtilities/Utilities.cpp b/tests/RhythmGameUtilities/Utilities.cpp index 807a10d..de41221 100644 --- a/tests/RhythmGameUtilities/Utilities.cpp +++ b/tests/RhythmGameUtilities/Utilities.cpp @@ -73,11 +73,11 @@ void testRoundUpToTheNearestMultiplier() void testGenerateAdjacentKeyPairs() { - std::map bpmChangePositions = { + std::map bpmChanges = { {0, 88000}, {3840, 112000}, {9984, 89600}, {22272, 112000}, {33792, 111500}, {34560, 112000}, {42240, 111980}}; - auto adjacentKeyPairs = GenerateAdjacentKeyPairs(bpmChangePositions); + auto adjacentKeyPairs = GenerateAdjacentKeyPairs(bpmChanges); assert(adjacentKeyPairs.size() == 6); assert(adjacentKeyPairs[0] == std::make_tuple(0, 3840));