From 7516681d9089ec783c8d7bdc1e1c8608efa53721 Mon Sep 17 00:00:00 2001 From: Scott Doxey Date: Fri, 25 Oct 2024 08:56:42 -0400 Subject: [PATCH] Added delta param to IsOnTheBeat method. --- Documentation/API/Utilities/IsOnTheBeat.md | 10 ++++++---- README.md | 10 ++++++---- RhythmGameUtilities/Scripts/Utilities.cs | 7 ++++--- UnityPackage/README.md | 10 ++++++---- UnityPackage/Scripts/Utilities.cs | 7 ++++--- include/RhythmGameUtilities/Utilities.hpp | 6 ++++-- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Documentation/API/Utilities/IsOnTheBeat.md b/Documentation/API/Utilities/IsOnTheBeat.md index a0e1081..005a42f 100644 --- a/Documentation/API/Utilities/IsOnTheBeat.md +++ b/Documentation/API/Utilities/IsOnTheBeat.md @@ -9,9 +9,10 @@ using System; using RhythmGameUtilities; const int bpm = 120; -const int currentTime = 10; +const float currentTime = 10f; +const float delta = 0.05f; -if (Utilities.IsOnTheBeat(bpm, currentTime)) +if (Utilities.IsOnTheBeat(bpm, currentTime, delta)) { Console.WriteLine("Is on the beat!"); } @@ -29,9 +30,10 @@ using namespace RhythmGameUtilities; int main() { const int bpm = 120; - const int currentTime = 10; + const float currentTime = 10f; + const float delta = 0.05f; - if (IsOnTheBeat(bpm, currentTime)) + if (IsOnTheBeat(bpm, currentTime, delta)) { std::cout << "Is on the beat!" << std::endl; } diff --git a/README.md b/README.md index e26744c..d2a3e63 100644 --- a/README.md +++ b/README.md @@ -773,9 +773,10 @@ using System; using RhythmGameUtilities; const int bpm = 120; -const int currentTime = 10; +const float currentTime = 10f; +const float delta = 0.05f; -if (Utilities.IsOnTheBeat(bpm, currentTime)) +if (Utilities.IsOnTheBeat(bpm, currentTime, delta)) { Console.WriteLine("Is on the beat!"); } @@ -793,9 +794,10 @@ using namespace RhythmGameUtilities; int main() { const int bpm = 120; - const int currentTime = 10; + const float currentTime = 10f; + const float delta = 0.05f; - if (IsOnTheBeat(bpm, currentTime)) + if (IsOnTheBeat(bpm, currentTime, delta)) { std::cout << "Is on the beat!" << std::endl; } diff --git a/RhythmGameUtilities/Scripts/Utilities.cs b/RhythmGameUtilities/Scripts/Utilities.cs index 316138e..3d88189 100644 --- a/RhythmGameUtilities/Scripts/Utilities.cs +++ b/RhythmGameUtilities/Scripts/Utilities.cs @@ -35,7 +35,7 @@ public static extern int ConvertSecondsToTicksInternal(float seconds, int resolu #elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX [DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)] #endif - public static extern bool IsOnTheBeat(int bpm, float currentTime); + public static extern bool IsOnTheBeat(int bpm, float currentTime, float delta); #if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN [DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)] @@ -103,9 +103,10 @@ public static int ConvertSecondsToTicks(float seconds, int resolution, Dictionar /// /// The base BPM for a song. /// A timestamp to compare to the BPM. - public static bool IsOnTheBeat(int bpm, float currentTime) + /// The plus/minus delta to test the current time against. + public static bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f) { - return UtilitiesInternal.IsOnTheBeat(bpm, currentTime); + return UtilitiesInternal.IsOnTheBeat(bpm, currentTime, delta); } /// diff --git a/UnityPackage/README.md b/UnityPackage/README.md index e26744c..d2a3e63 100644 --- a/UnityPackage/README.md +++ b/UnityPackage/README.md @@ -773,9 +773,10 @@ using System; using RhythmGameUtilities; const int bpm = 120; -const int currentTime = 10; +const float currentTime = 10f; +const float delta = 0.05f; -if (Utilities.IsOnTheBeat(bpm, currentTime)) +if (Utilities.IsOnTheBeat(bpm, currentTime, delta)) { Console.WriteLine("Is on the beat!"); } @@ -793,9 +794,10 @@ using namespace RhythmGameUtilities; int main() { const int bpm = 120; - const int currentTime = 10; + const float currentTime = 10f; + const float delta = 0.05f; - if (IsOnTheBeat(bpm, currentTime)) + if (IsOnTheBeat(bpm, currentTime, delta)) { std::cout << "Is on the beat!" << std::endl; } diff --git a/UnityPackage/Scripts/Utilities.cs b/UnityPackage/Scripts/Utilities.cs index 316138e..3d88189 100644 --- a/UnityPackage/Scripts/Utilities.cs +++ b/UnityPackage/Scripts/Utilities.cs @@ -35,7 +35,7 @@ public static extern int ConvertSecondsToTicksInternal(float seconds, int resolu #elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX [DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)] #endif - public static extern bool IsOnTheBeat(int bpm, float currentTime); + public static extern bool IsOnTheBeat(int bpm, float currentTime, float delta); #if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN [DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)] @@ -103,9 +103,10 @@ public static int ConvertSecondsToTicks(float seconds, int resolution, Dictionar /// /// The base BPM for a song. /// A timestamp to compare to the BPM. - public static bool IsOnTheBeat(int bpm, float currentTime) + /// The plus/minus delta to test the current time against. + public static bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f) { - return UtilitiesInternal.IsOnTheBeat(bpm, currentTime); + return UtilitiesInternal.IsOnTheBeat(bpm, currentTime, delta); } /// diff --git a/include/RhythmGameUtilities/Utilities.hpp b/include/RhythmGameUtilities/Utilities.hpp index 885049d..b41be16 100644 --- a/include/RhythmGameUtilities/Utilities.hpp +++ b/include/RhythmGameUtilities/Utilities.hpp @@ -169,10 +169,12 @@ extern "C" * * @param bpm The base BPM for a song. * @param currentTime A timestamp to compare to the BPM. + * @param delta The plus/minus delta to test the current time against. * @public */ - PACKAGE_API bool IsOnTheBeat(int bpm, float currentTime) + PACKAGE_API bool IsOnTheBeat(int bpm, float currentTime, + float delta = 0.05f) { auto beatInterval = SECONDS_PER_MINUTE / (float)bpm; @@ -180,7 +182,7 @@ extern "C" auto difference = std::abs(beatFraction - std::round(beatFraction)); - auto result = difference < 0.05f; + auto result = difference < delta; return result; }