From 8a2e4687b2d6085a0bae62294c87216cde6c70a4 Mon Sep 17 00:00:00 2001 From: MasterEric Date: Mon, 26 Sep 2022 17:18:19 -0400 Subject: [PATCH] Fixed TitleState not firing onBeat --- source/funkin/Conductor.hx | 33 ++++++++++++++++++++++------- source/funkin/TitleState.hx | 2 ++ source/funkin/play/PlayState.hx | 2 +- source/funkin/play/song/SongData.hx | 5 +++++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/source/funkin/Conductor.hx b/source/funkin/Conductor.hx index 1e2210d53..f5c17fc17 100644 --- a/source/funkin/Conductor.hx +++ b/source/funkin/Conductor.hx @@ -34,16 +34,21 @@ class Conductor /** * Beats per minute of the current song at the current time. */ - public static var bpm(get, null):Float = 100; + public static var bpm(get, null):Float; static function get_bpm():Float { + if (bpmOverride != null) + return bpmOverride; + if (currentTimeChange == null) return 100; return currentTimeChange.bpm; } + static var bpmOverride:Null = null; + // OLD, replaced with timeChanges. public static var bpmChangeMap:Array = []; @@ -111,23 +116,29 @@ class Conductor return lastChange; } + @:deprecated // Use loadSong with metadata files instead. public static function forceBPM(bpm:Float) { - // TODO: Get rid of this and use song metadata instead. - Conductor.bpm = bpm; + Conductor.bpmOverride = bpm; } /** * Update the conductor with the current song position. * BPM, current step, etc. will be re-calculated based on the song position. + * + * @param songPosition The current position in the song in milliseconds. + * Leave blank to use the FlxG.sound.music position. */ - public static function update(songPosition:Float) + public static function update(songPosition:Float = null) { + if (songPosition == null) + songPosition = (FlxG.sound.music != null) ? (FlxG.sound.music.time + Conductor.offset) : 0; + var oldBeat = currentBeat; var oldStep = currentStep; Conductor.songPosition = songPosition; - Conductor.bpm = Conductor.getLastBPMChange().bpm; + // Conductor.bpm = Conductor.getLastBPMChange().bpm; currentTimeChange = timeChanges[0]; for (i in 0...timeChanges.length) @@ -139,15 +150,21 @@ class Conductor break; } - if (currentTimeChange == null) + if (currentTimeChange == null && bpmOverride == null) { trace('WARNING: Conductor is broken, timeChanges is empty.'); } - else + else if (currentTimeChange != null) { currentStep = Math.floor((currentTimeChange.beatTime * 4) + (songPosition - currentTimeChange.timeStamp) / stepCrochet); currentBeat = Math.floor(currentStep / 4); } + else + { + // Assume a constant BPM equal to the forced value. + currentStep = Math.floor((songPosition) / stepCrochet); + currentBeat = Math.floor(currentStep / 4); + } // FlxSignals are really cool. if (currentStep != oldStep) @@ -157,6 +174,7 @@ class Conductor beatHit.dispatch(); } + @:deprecated // Switch to TimeChanges instead. public static function mapBPMChanges(song:SwagSong) { bpmChangeMap = []; @@ -181,7 +199,6 @@ class Conductor totalSteps += deltaSteps; totalPos += ((60 / curBPM) * 1000 / 4) * deltaSteps; } - trace("new BPM map BUDDY " + bpmChangeMap); } public static function mapTimeChanges(currentChart:SongDifficulty) diff --git a/source/funkin/TitleState.hx b/source/funkin/TitleState.hx index 6ecc6432e..245228379 100644 --- a/source/funkin/TitleState.hx +++ b/source/funkin/TitleState.hx @@ -259,6 +259,8 @@ class TitleState extends MusicBeatState FlxG.sound.music.pitch -= 0.5 * elapsed; #end + Conductor.update(); + /* if (FlxG.onMobile) { if (gfDance != null) diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index c7449b8d7..f57cf405b 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -1786,7 +1786,7 @@ class PlayState extends MusicBeatState // BPM might change between the current and target section but IDGAF FlxG.sound.music.time = Conductor.songPosition + (sec * 4 * (1000 * 60 / Conductor.bpm)); - Conductor.update(FlxG.sound.music.time + Conductor.offset); + Conductor.update(); resyncVocals(); } #end diff --git a/source/funkin/play/song/SongData.hx b/source/funkin/play/song/SongData.hx index db823ec8a..fed34ddf5 100644 --- a/source/funkin/play/song/SongData.hx +++ b/source/funkin/play/song/SongData.hx @@ -114,6 +114,11 @@ class SongDataParser } } + public static function listSongIds():Array + { + return [for (x in songCache.keys()) x]; + } + public static function parseSongMetadata(songId:String):Array { var result:Array = [];