Funkin/source/Conductor.hx

67 lines
1.6 KiB
Haxe
Raw Normal View History

2020-10-03 02:50:15 -04:00
package;
import Song.SwagSong;
2020-10-03 02:50:15 -04:00
/**
* ...
* @author
*/
typedef BPMChangeEvent =
{
var stepTime:Int;
var songTime:Float;
var bpm:Float;
}
2020-10-03 02:50:15 -04:00
class Conductor
{
public static var bpm:Float = 100;
2020-10-03 02:50:15 -04:00
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;
2020-10-24 05:19:13 -04:00
public static var lastSongPos:Float;
2020-10-03 02:50:15 -04:00
public static var offset:Float = 0;
2020-10-18 20:59:53 -04:00
public static var safeFrames:Int = 10;
2020-10-03 13:36:39 -04:00
public static var safeZoneOffset:Float = (safeFrames / 60) * 1000; // is calculated in create(), is safeFrames in milliseconds
public static var bpmChangeMap:Array<BPMChangeEvent> = [];
2021-06-22 15:54:53 -04:00
public function new() {}
2020-10-04 20:53:49 -04:00
public static function mapBPMChanges(song:SwagSong)
{
bpmChangeMap = [];
var curBPM:Float = song.bpm;
var totalSteps:Int = 0;
var totalPos:Float = 0;
2021-06-22 15:54:53 -04:00
for (i in 0...song.notes[PlayState.storyDifficulty].length)
{
2021-06-22 15:54:53 -04:00
if (song.notes[PlayState.storyDifficulty][i].changeBPM && song.notes[PlayState.storyDifficulty][i].bpm != curBPM)
{
2021-06-22 15:54:53 -04:00
curBPM = song.notes[PlayState.storyDifficulty][i].bpm;
var event:BPMChangeEvent = {
stepTime: totalSteps,
songTime: totalPos,
bpm: curBPM
};
bpmChangeMap.push(event);
}
2021-06-22 15:54:53 -04:00
var deltaSteps:Int = song.notes[PlayState.storyDifficulty][i].lengthInSteps;
totalSteps += deltaSteps;
totalPos += ((60 / curBPM) * 1000 / 4) * deltaSteps;
}
trace("new BPM map BUDDY " + bpmChangeMap);
}
public static function changeBPM(newBpm:Float)
2020-10-04 20:53:49 -04:00
{
bpm = newBpm;
crochet = ((60 / bpm) * 1000);
stepCrochet = crochet / 4;
}
2020-10-03 02:50:15 -04:00
}