This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
forked from FunkinCrew/Funkin
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Conductor.hx
109 lines (83 loc) · 2.64 KB
/
Conductor.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package game;
import game.Song.SwagSong;
using StringTools;
typedef BPMChangeEvent =
{
var stepTime:Int;
var songTime:Float;
var bpm:Float;
}
typedef TimeScaleChangeEvent =
{
var stepTime:Int;
var songTime:Float;
var timeScale:Array<Int>;
}
class Conductor
{
public static var bpm:Float = 100;
public static var crochet:Float = ((60 / bpm) * 1000); // beats in milliseconds
public static var stepCrochet:Float = crochet / 4; // steps in milliseconds
public static var songPosition:Float;
public static var lastSongPos:Float;
public static var offset:Float = 0;
public static var safeFrames:Int = 10;
public static var safeZoneOffset:Float = Math.floor((safeFrames / 60) * 1000); // is calculated in create(), is safeFrames in milliseconds
public static var bpmChangeMap:Array<BPMChangeEvent> = [];
public static var timeScaleChangeMap:Array<TimeScaleChangeEvent> = [];
public static var timeScale:Array<Int> = [4, 4];
public static var stepsPerSection:Int = 16;
public function new()
{
}
public static function recalculateStuff(?multi:Float = 1)
{
safeZoneOffset = Math.floor((safeFrames / 60) * 1000) * multi;
crochet = ((60 / bpm) * 1000);
stepCrochet = crochet / timeScale[1];
stepsPerSection = Math.floor((16 / timeScale[1]) * timeScale[0]);
}
public static function mapBPMChanges(song:SwagSong, ?songMultiplier:Float = 1.0) // also maps time signature changes cuz frick u
{
bpmChangeMap = [];
timeScaleChangeMap = [];
var curBPM:Float = song.bpm;
var curTimeScale:Array<Int> = timeScale;
var totalSteps:Int = 0;
var totalPos:Float = 0;
for (i in 0...song.notes.length)
{
if (song.notes[i].changeBPM && song.notes[i].bpm != curBPM)
{
curBPM = song.notes[i].bpm;
var event:BPMChangeEvent = {
stepTime: totalSteps,
songTime: totalPos,
bpm: curBPM
};
bpmChangeMap.push(event);
}
if (song.notes[i].changeTimeScale
&& song.notes[i].timeScale[0] != curTimeScale[0]
&& song.notes[i].timeScale[1] != curTimeScale[1])
{
curTimeScale = song.notes[i].timeScale;
var event:TimeScaleChangeEvent = {
stepTime: totalSteps,
songTime: totalPos,
timeScale: curTimeScale
};
timeScaleChangeMap.push(event);
}
var deltaSteps:Int = Math.floor((16 / curTimeScale[1]) * curTimeScale[0]);
totalSteps += deltaSteps;
totalPos += ((60 / curBPM) * 1000 / curTimeScale[0]) * deltaSteps;
}
recalculateStuff(songMultiplier);
}
public static function changeBPM(newBpm:Float, ?multi:Float = 1)
{
bpm = newBpm;
recalculateStuff(multi);
}
}