40 lines
No EOL
1 KiB
C#
40 lines
No EOL
1 KiB
C#
using System;
|
|
|
|
namespace JD.Serialization
|
|
{
|
|
/// <summary>
|
|
/// Responsible of converting from beat value to frame value.
|
|
/// </summary>
|
|
public class FrameConverter
|
|
{
|
|
public const int FramePerBeat = 24;
|
|
|
|
/// <summary>
|
|
/// Videos are always 25 frames per seconds.
|
|
/// </summary>
|
|
public static readonly TimeSpan VideoFrameDuration = TimeSpan.FromSeconds(1f / 25f);
|
|
|
|
public static float TimeFromFrame(float frame)
|
|
{
|
|
return frame/FramePerBeat;
|
|
}
|
|
|
|
public static float FrameFromTime(float time)
|
|
{
|
|
return time*FramePerBeat;
|
|
}
|
|
|
|
public static int FrameFromTimeInteger(float time)
|
|
{
|
|
return (int) Math.Round(FrameFromTime(time));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes a time in time unit and snaps it to a integer frame.
|
|
/// </summary>
|
|
public static float SnapTimeToFrame(float time)
|
|
{
|
|
return TimeFromFrame(FrameFromTimeInteger(time));
|
|
}
|
|
}
|
|
} |