mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2025-03-23 18:39:33 +00:00
Further conductor/bpm stuff
This commit is contained in:
parent
9ebb566b2a
commit
bb5ed65d27
|
@ -1,5 +1,6 @@
|
||||||
package funkin;
|
package funkin;
|
||||||
|
|
||||||
|
import flixel.util.FlxSignal;
|
||||||
import funkin.SongLoad.SwagSong;
|
import funkin.SongLoad.SwagSong;
|
||||||
import funkin.play.song.Song.SongDifficulty;
|
import funkin.play.song.Song.SongDifficulty;
|
||||||
import funkin.play.song.SongData.ConductorTimeChange;
|
import funkin.play.song.SongData.ConductorTimeChange;
|
||||||
|
@ -18,12 +19,12 @@ class Conductor
|
||||||
* The list of time changes in the song.
|
* The list of time changes in the song.
|
||||||
* There should be at least one time change (at the beginning of the song) to define the BPM.
|
* There should be at least one time change (at the beginning of the song) to define the BPM.
|
||||||
*/
|
*/
|
||||||
private static var timeChanges:Array<ConductorTimeChange> = [];
|
private static var timeChanges:Array<SongTimeChange> = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current time change.
|
* The current time change.
|
||||||
*/
|
*/
|
||||||
private static var currentTimeChange:ConductorTimeChange;
|
private static var currentTimeChange:SongTimeChange;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current position in the song in milliseconds.
|
* The current position in the song in milliseconds.
|
||||||
|
@ -81,12 +82,15 @@ class Conductor
|
||||||
return currentStep;
|
return currentStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static var beatHit(default, null):FlxSignal = new FlxSignal();
|
||||||
|
public static var stepHit(default, null):FlxSignal = new FlxSignal();
|
||||||
|
|
||||||
public static var lastSongPos:Float;
|
public static var lastSongPos:Float;
|
||||||
public static var visualOffset:Float = 0;
|
public static var visualOffset:Float = 0;
|
||||||
public static var audioOffset:Float = 0;
|
public static var audioOffset:Float = 0;
|
||||||
public static var offset:Float = 0;
|
public static var offset:Float = 0;
|
||||||
|
|
||||||
public function new()
|
private function new()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +124,30 @@ class Conductor
|
||||||
*/
|
*/
|
||||||
public static function update(songPosition:Float)
|
public static function update(songPosition:Float)
|
||||||
{
|
{
|
||||||
Conductor.songPosition = songPosition;
|
var oldBeat = currentBeat;
|
||||||
Conductor.bpm = Conductor.getLastBPMChange().bpm;
|
var oldStep = currentStep;
|
||||||
|
|
||||||
|
songPosition = songPosition;
|
||||||
|
bpm = Conductor.getLastBPMChange().bpm;
|
||||||
|
|
||||||
|
for (i in 0...timeChanges.length)
|
||||||
|
{
|
||||||
|
if (songPosition >= timeChanges[i].songTime)
|
||||||
|
currentTimeChange = timeChanges[i];
|
||||||
|
|
||||||
|
if (songPosition < timeChanges[i].songTime)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentStep = (currentTimeChange.beatTime * 4) + (songPosition - currentTimeChange.songTime) / stepCrochet;
|
||||||
|
currentBeat = Math.floor(currentStep / 4);
|
||||||
|
|
||||||
|
// FlxSignals are really cool.
|
||||||
|
if (currentStep != oldStep)
|
||||||
|
stepHit.dispatch();
|
||||||
|
|
||||||
|
if (currentBeat != oldBeat)
|
||||||
|
beatHit.dispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function mapBPMChanges(song:SwagSong)
|
public static function mapBPMChanges(song:SwagSong)
|
||||||
|
@ -157,23 +183,24 @@ class Conductor
|
||||||
|
|
||||||
timeChanges = [];
|
timeChanges = [];
|
||||||
|
|
||||||
for (songTimeChange in timeChanges)
|
for (currentTimeChange in timeChanges)
|
||||||
{
|
{
|
||||||
var prevTimeChange:ConductorTimeChange = timeChanges.length == 0 ? null : timeChanges[timeChanges.length - 1];
|
var prevTimeChange:SongTimeChange = timeChanges.length == 0 ? null : timeChanges[timeChanges.length - 1];
|
||||||
var currentTimeChange:ConductorTimeChange = cast songTimeChange;
|
|
||||||
|
|
||||||
if (prevTimeChange != null)
|
/*
|
||||||
{
|
if (prevTimeChange != null)
|
||||||
var deltaTime:Float = currentTimeChange.timeStamp - prevTimeChange.timeStamp;
|
{
|
||||||
var deltaSteps:Int = Math.round(deltaTime / (60 / prevTimeChange.bpm) * 1000 / 4);
|
var deltaTime:Float = currentTimeChange.timeStamp - prevTimeChange.timeStamp;
|
||||||
|
var deltaSteps:Int = Math.round(deltaTime / (60 / prevTimeChange.bpm) * 1000 / 4);
|
||||||
|
|
||||||
currentTimeChange.stepTime = prevTimeChange.stepTime + deltaSteps;
|
currentTimeChange.stepTime = prevTimeChange.stepTime + deltaSteps;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We know the time and steps of this time change is 0, since this is the first time change.
|
// We know the time and steps of this time change is 0, since this is the first time change.
|
||||||
currentTimeChange.stepTime = 0;
|
currentTimeChange.stepTime = 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
timeChanges.push(currentTimeChange);
|
timeChanges.push(currentTimeChange);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,37 +115,16 @@ class MusicBeatState extends FlxUIState
|
||||||
FlxG.resetState();
|
FlxG.resetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateBeat():Void
|
|
||||||
{
|
|
||||||
curBeat = Math.floor(curStep / 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function updateCurStep():Void
|
|
||||||
{
|
|
||||||
var lastChange:BPMChangeEvent = {
|
|
||||||
stepTime: 0,
|
|
||||||
songTime: 0,
|
|
||||||
bpm: 0
|
|
||||||
}
|
|
||||||
for (i in 0...Conductor.bpmChangeMap.length)
|
|
||||||
{
|
|
||||||
if (Conductor.songPosition >= Conductor.bpmChangeMap[i].songTime)
|
|
||||||
lastChange = Conductor.bpmChangeMap[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
curStep = lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stepHit():Bool
|
public function stepHit():Bool
|
||||||
{
|
{
|
||||||
var event = new SongTimeScriptEvent(ScriptEvent.SONG_STEP_HIT, curBeat, curStep);
|
var event = new SongTimeScriptEvent(ScriptEvent.SONG_STEP_HIT, Conductor.currentBeat, Conductor.currentStep);
|
||||||
|
|
||||||
dispatchEvent(event);
|
dispatchEvent(event);
|
||||||
|
|
||||||
if (event.eventCanceled)
|
if (event.eventCanceled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (curStep % 4 == 0)
|
if (Conductor.currentStep % 4 == 0)
|
||||||
beatHit();
|
beatHit();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -153,7 +132,7 @@ class MusicBeatState extends FlxUIState
|
||||||
|
|
||||||
public function beatHit():Bool
|
public function beatHit():Bool
|
||||||
{
|
{
|
||||||
var event = new SongTimeScriptEvent(ScriptEvent.SONG_BEAT_HIT, curBeat, curStep);
|
var event = new SongTimeScriptEvent(ScriptEvent.SONG_BEAT_HIT, Conductor.currentBeat, Conductor.currentStep);
|
||||||
|
|
||||||
dispatchEvent(event);
|
dispatchEvent(event);
|
||||||
|
|
||||||
|
|
|
@ -709,113 +709,6 @@ abstract SongTimeChange(RawSongTimeChange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract ConductorTimeChange(RawConductorTimeChange)
|
|
||||||
{
|
|
||||||
public function new(timeStamp:Float, beatTime:Int, bpm:Float, timeSignatureNum:Int = 4, timeSignatureDen:Int = 4, beatTuplets:Array<Int>)
|
|
||||||
{
|
|
||||||
this = {
|
|
||||||
t: timeStamp,
|
|
||||||
b: beatTime,
|
|
||||||
bpm: bpm,
|
|
||||||
n: timeSignatureNum,
|
|
||||||
d: timeSignatureDen,
|
|
||||||
bt: beatTuplets,
|
|
||||||
st: 0.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public var timeStamp(get, set):Float;
|
|
||||||
|
|
||||||
public function get_timeStamp():Float
|
|
||||||
{
|
|
||||||
return this.t;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_timeStamp(value:Float):Float
|
|
||||||
{
|
|
||||||
return this.t = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var beatTime(get, set):Int;
|
|
||||||
|
|
||||||
public function get_beatTime():Int
|
|
||||||
{
|
|
||||||
return this.b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_beatTime(value:Int):Int
|
|
||||||
{
|
|
||||||
return this.b = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var bpm(get, set):Float;
|
|
||||||
|
|
||||||
public function get_bpm():Float
|
|
||||||
{
|
|
||||||
return this.bpm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_bpm(value:Float):Float
|
|
||||||
{
|
|
||||||
return this.bpm = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var timeSignatureNum(get, set):Int;
|
|
||||||
|
|
||||||
public function get_timeSignatureNum():Int
|
|
||||||
{
|
|
||||||
return this.n;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_timeSignatureNum(value:Int):Int
|
|
||||||
{
|
|
||||||
return this.n = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var timeSignatureDen(get, set):Int;
|
|
||||||
|
|
||||||
public function get_timeSignatureDen():Int
|
|
||||||
{
|
|
||||||
return this.d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_timeSignatureDen(value:Int):Int
|
|
||||||
{
|
|
||||||
return this.d = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var beatTuplets(get, set):Array<Int>;
|
|
||||||
|
|
||||||
public function get_beatTuplets():Array<Int>
|
|
||||||
{
|
|
||||||
if (Std.isOfType(this.bt, Int))
|
|
||||||
{
|
|
||||||
return [this.bt];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return this.bt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_beatTuplets(value:Array<Int>):Array<Int>
|
|
||||||
{
|
|
||||||
return this.bt = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var stepTime(get, set):Float;
|
|
||||||
|
|
||||||
public function get_stepTime():Float
|
|
||||||
{
|
|
||||||
return this.st;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_stepTime(value:Float):Float
|
|
||||||
{
|
|
||||||
return this.st = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum abstract SongTimeFormat(String) from String to String
|
enum abstract SongTimeFormat(String) from String to String
|
||||||
{
|
{
|
||||||
var TICKS = "ticks";
|
var TICKS = "ticks";
|
||||||
|
|
Loading…
Reference in a new issue