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
10 changes: 6 additions & 4 deletions Documentation/API/Utilities/IsOnTheBeat.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions RhythmGameUtilities/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -103,9 +103,10 @@ public static int ConvertSecondsToTicks(float seconds, int resolution, Dictionar
///
/// <param name="bpm">The base BPM for a song.</param>
/// <param name="currentTime">A timestamp to compare to the BPM.</param>
public static bool IsOnTheBeat(int bpm, float currentTime)
/// <param name="delta">The plus/minus delta to test the current time against.</param>
public static bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f)
{
return UtilitiesInternal.IsOnTheBeat(bpm, currentTime);
return UtilitiesInternal.IsOnTheBeat(bpm, currentTime, delta);
}

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions UnityPackage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions UnityPackage/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -103,9 +103,10 @@ public static int ConvertSecondsToTicks(float seconds, int resolution, Dictionar
///
/// <param name="bpm">The base BPM for a song.</param>
/// <param name="currentTime">A timestamp to compare to the BPM.</param>
public static bool IsOnTheBeat(int bpm, float currentTime)
/// <param name="delta">The plus/minus delta to test the current time against.</param>
public static bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f)
{
return UtilitiesInternal.IsOnTheBeat(bpm, currentTime);
return UtilitiesInternal.IsOnTheBeat(bpm, currentTime, delta);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions include/RhythmGameUtilities/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,20 @@ 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;

auto beatFraction = currentTime / beatInterval;

auto difference = std::abs(beatFraction - std::round(beatFraction));

auto result = difference < 0.05f;
auto result = difference < delta;

return result;
}
Expand Down