diff --git a/source/funkin/Conductor.hx b/source/funkin/Conductor.hx index 5af454e34..909dd789c 100644 --- a/source/funkin/Conductor.hx +++ b/source/funkin/Conductor.hx @@ -72,15 +72,15 @@ class Conductor static function get_measureLengthMs():Float { - return crochet * timeSignatureNumerator; + return beatLengthMs * timeSignatureNumerator; } /** * Duration of a beat in milliseconds. Calculated based on bpm. */ - public static var crochet(get, null):Float; + public static var beatLengthMs(get, null):Float; - static function get_crochet():Float + static function get_beatLengthMs():Float { return ((Constants.SECS_PER_MIN / bpm) * Constants.MS_PER_SEC); } @@ -88,11 +88,11 @@ class Conductor /** * Duration of a step (quarter) in milliseconds. Calculated based on bpm. */ - public static var stepCrochet(get, null):Float; + public static var stepLengthMs(get, null):Float; - static function get_stepCrochet():Float + static function get_stepLengthMs():Float { - return crochet / timeSignatureNumerator; + return beatLengthMs / timeSignatureNumerator; } public static var timeSignatureNumerator(get, null):Int; @@ -113,9 +113,21 @@ class Conductor return currentTimeChange.timeSignatureDen; } + public static var beatsPerMeasure(get, null):Float; + + static function get_beatsPerMeasure():Float + { + return timeSignatureNumerator / timeSignatureDenominator * 4; + } + + /** + * Current position in the song, in measures. + */ + public static var currentMeasure(default, null):Int; + /** * Current position in the song, in beats. - **/ + */ public static var currentBeat(default, null):Int; /** @@ -123,6 +135,16 @@ class Conductor */ public static var currentStep(default, null):Int; + /** + * Current position in the song, in measures and fractions of a measure. + */ + public static var currentMeasureTime(default, null):Float; + + /** + * Current position in the song, in beats and fractions of a measure. + */ + public static var currentBeatTime(default, null):Float; + /** * Current position in the song, in steps and fractions of a step. */ @@ -136,12 +158,11 @@ class Conductor public static var audioOffset:Float = 0; public static var offset:Float = 0; - // TODO: Add code to update this. public static var beatsPerMeasure(get, null):Int; static function get_beatsPerMeasure():Int { - return timeSignatureNumerator; + return stepsPerMeasure / Constants.STEPS_PER_BEAT; } public static var stepsPerMeasure(get, null):Int; @@ -149,7 +170,7 @@ class Conductor static function get_stepsPerMeasure():Int { // Is this always x4? - return timeSignatureNumerator * Constants.STEPS_PER_BEAT; + return timeSignatureNumerator / timeSignatureDenominator * Constants.STEPS_PER_BEAT * Constants.STEPS_PER_BEAT; } function new() {} @@ -202,16 +223,22 @@ class Conductor else if (currentTimeChange != null) { // roundDecimal prevents representing 8 as 7.9999999 - currentStepTime = FlxMath.roundDecimal((currentTimeChange.beatTime * 4) + (songPosition - currentTimeChange.timeStamp) / stepCrochet, 6); + currentStepTime = FlxMath.roundDecimal((currentTimeChange.beatTime * 4) + (songPosition - currentTimeChange.timeStamp) / stepLengthMs, 6); + currentBeatTime = currentStepTime / Constants.STEPS_PER_BEAT; + currentMeasureTime = currentStepTime / stepsPerMeasure; currentStep = Math.floor(currentStepTime); - currentBeat = Math.floor(currentStep / 4); + currentBeat = Math.floor(currentBeatTime); + currentMeasure = Math.floor(currentMeasureTime); } else { // Assume a constant BPM equal to the forced value. - currentStepTime = (songPosition / stepCrochet); + currentStepTime = FlxMath.roundDecimal((songPosition / stepLengthMs), 4); + currentBeatTime = currentStepTime / Constants.STEPS_PER_BEAT; + currentMeasureTime = currentStepTime / stepsPerMeasure; currentStep = Math.floor(currentStepTime); - currentBeat = Math.floor(currentStep / 4); + currentBeat = Math.floor(currentBeatTime); + currentMeasure = Math.floor(currentMeasureTime); } // FlxSignals are really cool. @@ -274,7 +301,7 @@ class Conductor if (timeChanges.length == 0) { // Assume a constant BPM equal to the forced value. - return Math.floor(ms / stepCrochet); + return Math.floor(ms / stepLengthMs); } else { @@ -295,7 +322,7 @@ class Conductor } } - resultStep += Math.floor((ms - lastTimeChange.timeStamp) / stepCrochet); + resultStep += Math.floor((ms - lastTimeChange.timeStamp) / stepLengthMs); return resultStep; } diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index 18e34c72b..8b50c29cf 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -1877,7 +1877,7 @@ class ChartEditorState extends HaxeUIState { // Handle extending the note as you drag. - // Since use Math.floor and stepCrochet here, the hold notes will be beat snapped. + // Since use Math.floor and stepLengthMs here, the hold notes will be beat snapped. var dragLengthSteps:Float = Math.floor((cursorMs - currentPlaceNoteData.time) / Conductor.stepLengthMs); // Without this, the newly placed note feels too short compared to the user's input. diff --git a/source/funkin/ui/story/StoryMenuState.hx b/source/funkin/ui/story/StoryMenuState.hx index 055db1f71..927bdc431 100644 --- a/source/funkin/ui/story/StoryMenuState.hx +++ b/source/funkin/ui/story/StoryMenuState.hx @@ -15,6 +15,7 @@ import funkin.modding.events.ScriptEventDispatcher; import funkin.play.PlayState; import funkin.play.PlayStatePlaylist; import funkin.play.song.Song; +import funkin.play.song.SongData.SongMetadata; import funkin.play.song.SongData.SongDataParser; import funkin.util.Constants; @@ -200,7 +201,7 @@ class StoryMenuState extends MusicBeatState { if (FlxG.sound.music == null || !FlxG.sound.music.playing) { - var freakyMenuMetadata:SongMetadata = SongData.parseMusicMetadata('freakyMenu'); + var freakyMenuMetadata:SongMetadata = SongDataParser.parseMusicMetadata('freakyMenu'); Conductor.mapTimeChanges(freakyMenuMetadata.timeChanges); FlxG.sound.playMusic(Paths.music('freakyMenu/freakyMenu'), 0);