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