-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,076 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Ched.Core.Events; | ||
|
||
namespace Ched.Core | ||
{ | ||
/// <summary> | ||
/// BPM変更イベントからTick値に対応する時刻を求めるクラスです。 | ||
/// </summary> | ||
public class TimeCalculator | ||
{ | ||
protected int TicksPerBeat { get; } | ||
// 時間順ソート済み | ||
protected List<(int Tick, double Bpm, double Time)> BpmDefinitions { get; } = new List<(int Tick, double Bpm, double Time)>(); | ||
|
||
public TimeCalculator(int ticksPerBeat, IEnumerable<BpmChangeEvent> bpms) | ||
{ | ||
TicksPerBeat = ticksPerBeat; | ||
double time = 0; | ||
var ordered = bpms.OrderBy(p => p.Tick).ToList(); | ||
if (ordered[0].Tick != 0) throw new ArgumentException("Initial BpmChangeEvent was not found.", "bpms"); | ||
BpmDefinitions.Add((0, ordered[0].Bpm, 0)); | ||
for (int i = 1; i < ordered.Count; i++) | ||
{ | ||
time += GetDuration(ordered[i - 1].Bpm, ordered[i].Tick - ordered[i - 1].Tick); | ||
BpmDefinitions.Add((ordered[i].Tick, ordered[i].Bpm, time)); | ||
} | ||
} | ||
|
||
public double GetTimeFromTick(int tick) | ||
{ | ||
for (int i = BpmDefinitions.Count - 1; 0 <= i; i--) | ||
{ | ||
if (tick < BpmDefinitions[i].Tick) continue; | ||
return BpmDefinitions[i].Time + GetDuration(BpmDefinitions[i].Bpm, tick - BpmDefinitions[i].Tick); | ||
} | ||
// 負の時間は初期BPMで遡る | ||
return GetDuration(BpmDefinitions[0].Bpm, tick); | ||
} | ||
|
||
public int GetTickFromTime(double time) | ||
{ | ||
for (int i = BpmDefinitions.Count - 1; 0 <= i; i--) | ||
{ | ||
if (time < BpmDefinitions[i].Time) continue; | ||
return BpmDefinitions[i].Tick + GetDurationInTick(BpmDefinitions[i].Bpm, time - BpmDefinitions[i].Time); | ||
} | ||
// 負の時間は初期BPMで遡る | ||
return GetDurationInTick(BpmDefinitions[0].Bpm, time); | ||
} | ||
|
||
// => durationTick * (60 / bpm) / TicksPerBeat; | ||
protected double GetDuration(double bpm, int durationTick) => durationTick * 60 / bpm / TicksPerBeat; | ||
|
||
// => TicksPerBeat * duration * (bpm / 60) | ||
protected int GetDurationInTick(double bpm, double duration) => (int)(TicksPerBeat * duration * bpm / 60); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ched.Plugins | ||
{ | ||
public interface IDiagnosable | ||
{ | ||
void ReportDiagnostic(Diagnostic diagnostic); | ||
} | ||
|
||
public class Diagnostic | ||
{ | ||
public DiagnosticSeverity Severity { get; } | ||
public string Message { get; } | ||
|
||
public Diagnostic(DiagnosticSeverity severity, string message) | ||
{ | ||
Severity = severity; | ||
Message = message; | ||
} | ||
} | ||
|
||
public enum DiagnosticSeverity | ||
{ | ||
Hidden = 0, | ||
Information = 1, | ||
Warning = 2, | ||
Error = 3 | ||
} | ||
} |
Oops, something went wrong.