30 lines
1 KiB
C#
30 lines
1 KiB
C#
using System;
|
|
using JD.Application.Utils;
|
|
using JD.Audio.Annotations;
|
|
using JD.Audio.Sound;
|
|
using JD.Serialization;
|
|
|
|
namespace JDSongConverter.Utils
|
|
{
|
|
public static class UnitUtils
|
|
{
|
|
public static float TimeInBeats(this Tape tape, int beat, float offsetInSeconds)
|
|
{
|
|
if (tape.Extensions.unitConverter == null)
|
|
{
|
|
tape.Extensions.unitConverter = tape.TryGetWave().UnitConverter;
|
|
}
|
|
var timeInSec = tape.Extensions.unitConverter.TimeFromBeat(new BeatUnit(beat)).TotalSeconds;
|
|
return tape.Extensions.unitConverter.BeatFromTime(TimeSpan.FromSeconds(timeInSec + offsetInSeconds)).Value;
|
|
}
|
|
|
|
public static float TimeInBeats(this Tape tape, float timeInSeconds)
|
|
{
|
|
if (tape.Extensions.unitConverter == null)
|
|
{
|
|
tape.Extensions.unitConverter = tape.TryGetWave().UnitConverter;
|
|
}
|
|
return tape.Extensions.unitConverter.BeatFromTime(TimeSpan.FromSeconds(timeInSeconds)).Value;
|
|
}
|
|
}
|
|
}
|